lib/omnibus/fetchers/git_fetcher.rb in omnibus-5.5.0 vs lib/omnibus/fetchers/git_fetcher.rb in omnibus-5.6.0

- old
+ new

@@ -139,11 +139,13 @@ # Clone the +source_url+ into the +project_dir+. # # @return [void] # def git_clone - git("clone#{" --recursive" if clone_submodules?} #{source_url} .") + retry_block("git clone", [CommandTimeout, CommandFailed]) do + git("clone#{" --recursive" if clone_submodules?} #{source_url} .") + end end # # Checkout the +resolved_version+. # @@ -152,22 +154,28 @@ def git_checkout # We are hoping to perform a checkout with detached HEAD (that's the # default when a sha1 is provided). git older than 1.7.5 doesn't # support the --detach flag. git("checkout #{resolved_version} -f -q") - git("submodule update --recursive") if clone_submodules? + if clone_submodules? + retry_block("git submodule update", [CommandTimeout, CommandFailed]) do + git("submodule update --recursive") + end + end end # # Fetch the remote tags and refs, and reset to +resolved_version+. # # @return [void] # def git_fetch fetch_cmd = "fetch #{source_url} #{described_version}" fetch_cmd << " --recurse-submodules=on-demand" if clone_submodules? - git(fetch_cmd) + retry_block("git fetch", [CommandTimeout, CommandFailed]) do + git(fetch_cmd) + end end # # The current revision for the cloned checkout. # @@ -212,11 +220,10 @@ def git(command) shellout!("git -c core.autocrlf=false #{command}", cwd: project_dir) end # Class methods - public # Return the SHA1 corresponding to a ref as determined by the remote source. # # @return [String] # @@ -258,10 +265,13 @@ def self.revision_from_remote_reference(ref, source) # execute `git ls-remote` the trailing '*' does globbing. This # allows us to return the SHA of the tagged commit for annotated # tags. We take care to only return exact matches in # process_remote_list. - remote_list = shellout!("git ls-remote \"#{source[:git]}\" \"#{ref}*\"").stdout + remote_list = retry_block("git ls-remote", [CommandTimeout, CommandFailed]) do + shellout!("git ls-remote \"#{source[:git]}\" \"#{ref}*\"").stdout + end + commit_ref = dereference_annotated_tag(remote_list, ref) unless commit_ref raise UnresolvableGitReference.new(ref) end