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

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

Constant Summary collapse

CACHE_VERSION =
3

Instance Attribute Summary collapse

Attributes inherited from Base

#dapp, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#blobs_entries, #branch, #commit_exists?, #diff, #empty?, #exclude_paths, #find_commit_id_by_message, #head_commit, #ignore_patch?, #lookup_object, #nested_git_directories_patches, #patches, #remote_branches, #remote_origin_url, #remote_origin_url_protocol, #submodule_params, #submodule_url, #submodules, #submodules_git, #submodules_git_path, #submodules_params, #tags, #tracked_remote_repository?, #walker

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



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

def _rugged_credentials
  @_rugged_credentials ||= begin
    if remote_origin_url_protocol == :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

#_with_lock(&blk) ⇒ Object



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

def _with_lock(&blk)
  dapp.lock("remote_git_artifact.#{name}", default_timeout: 600, &blk)
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



35
36
37
38
39
40
41
# File 'lib/dapp/dimg/git_repo/remote.rb', line 35

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), remote_origin_url_protocol).to_s # FIXME
    res["IsDryRun"] = dapp.dry_run?
  }
end

#latest_branch_commit(branch) ⇒ Object



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

def latest_branch_commit(branch)
  git.ref("refs/remotes/#{branch_format(branch)}").tap do |ref|
    raise Error::Rugged, code: :branch_not_exist_in_remote_git_repository, data: { branch: branch, url: url } if ref.nil?
    break ref.target_id
  end
end

#latest_tag_commit(tag) ⇒ Object



77
78
79
80
81
82
# File 'lib/dapp/dimg/git_repo/remote.rb', line 77

def latest_tag_commit(tag)
  git.tags[tag].tap do |t|
    raise Error::Rugged, code: :tag_not_exist_in_remote_git_repository, data: { tag: tag, url: url } if t.nil?
    break t.target_id
  end
end

#lookup_commit(commit) ⇒ Object



84
85
86
87
88
# File 'lib/dapp/dimg/git_repo/remote.rb', line 84

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), remote_origin_url_protocol).to_s)
end

#raise_submodule_commit_not_found!(commit) ⇒ Object

Raises:



90
91
92
# File 'lib/dapp/dimg/git_repo/remote.rb', line 90

def raise_submodule_commit_not_found!(commit)
  raise Error::Rugged, code: :git_remote_submodule_commit_not_found, data: { commit: commit, url: url }
end

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



25
26
27
28
29
30
31
32
33
# File 'lib/dapp/dimg/git_repo/remote.rb', line 25

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



43
44
45
46
# File 'lib/dapp/dimg/git_repo/remote.rb', line 43

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