Class: Dapp::Dimg::GitRepo::Remote

Inherits:
Base
  • Object
show all
Defined in:
lib/dapp/dimg/git_repo/remote.rb

Constant Summary collapse

CACHE_VERSION =
4

Instance Attribute Summary collapse

Attributes inherited from Base

#dapp, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#commit_exists?, #empty?, #exclude_paths, #find_commit_id_by_message, #head_branch_name, #head_commit, #latest_branch_commit, #lookup_object, #remote_origin_url

Methods included from Helper::Trivia

#check_path?, #check_subpath?, #class_to_lowercase, class_to_lowercase, #delete_file, #ignore_path?, #ignore_path_base, #kwargs, #make_path, #path_checker, #search_file_upward

Constructor Details

#initialize(dapp, name, url:) ⇒ Remote

Returns a new instance of Remote.



19
20
21
22
23
# File 'lib/dapp/dimg/git_repo/remote.rb', line 19

def initialize(dapp, name, url:)
  super(dapp, name)

  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/dapp/dimg/git_repo/remote.rb', line 7

def url
  @url
end

Class Method Details

.get_or_create(dapp, name, url:) ⇒ Object



10
11
12
# File 'lib/dapp/dimg/git_repo/remote.rb', line 10

def get_or_create(dapp, name, url:)
  repositories[url] ||= new(dapp, name, url: url).tap(&:clone_and_fetch)
end

.repositoriesObject



14
15
16
# File 'lib/dapp/dimg/git_repo/remote.rb', line 14

def repositories
  @repositories ||= {}
end

Instance Method Details

#_rugged_credentialsObject

TODO remove



52
53
54
55
56
57
58
59
60
# File 'lib/dapp/dimg/git_repo/remote.rb', line 52

def _rugged_credentials # TODO remove
  @_rugged_credentials ||= begin
    if url_protocol(url) == :ssh
      host_with_user = url.split(':', 2).first
      username = host_with_user.split('@', 2).reverse.last
      Rugged::Credentials::SshKeyFromAgent.new(username: username)
    end
  end
end

#clone_and_fetchObject



66
67
68
# File 'lib/dapp/dimg/git_repo/remote.rb', line 66

def clone_and_fetch
  return ruby2go_method("CloneAndFetch")
end

#get_ruby2go_state_hashObject



39
40
41
42
43
44
45
# File 'lib/dapp/dimg/git_repo/remote.rb', line 39

def get_ruby2go_state_hash
  super.tap {|res|
    res["Url"] = @url.to_s
    res["ClonePath"] = dapp.build_path("remote_git_repo", CACHE_VERSION.to_s, dapp.consistent_uniq_slugify(name), url_protocol(url)).to_s # FIXME
    res["IsDryRun"] = dapp.dry_run?
  }
end

#lookup_commit(commit) ⇒ Object



70
71
72
73
74
# File 'lib/dapp/dimg/git_repo/remote.rb', line 70

def lookup_commit(commit)
  super
rescue Rugged::OdbError, TypeError => _e
  raise Error::Rugged, code: :commit_not_found_in_remote_git_repository, data: { commit: commit, url: url }
end

#pathObject



62
63
64
# File 'lib/dapp/dimg/git_repo/remote.rb', line 62

def path
  Pathname(dapp.build_path("remote_git_repo", CACHE_VERSION.to_s, dapp.consistent_uniq_slugify(name), url_protocol(url)).to_s)
end

#ruby2go_method(method, args_hash = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/dapp/dimg/git_repo/remote.rb', line 29

def ruby2go_method(method, args_hash={})
  res = dapp.ruby2go_git_repo(args_hash.merge("RemoteGitRepo" => JSON.dump(get_ruby2go_state_hash), "method" => method))

  raise res["error"] if res["error"]

  self.set_ruby2go_state_hash(JSON.load(res["data"]["RemoteGitRepo"]))

  res["data"]["result"]
end

#set_ruby2go_state_hash(state) ⇒ Object



47
48
49
50
# File 'lib/dapp/dimg/git_repo/remote.rb', line 47

def set_ruby2go_state_hash(state)
  super(state)
  @url = state["Url"]
end