Skip to content

Commit

Permalink
Add more explanation for unresolvable git refs
Browse files Browse the repository at this point in the history
* Clarify language.
* Show the command that we ran to resolve the branch/tag/whatever
* Add a hint about v1.2.3 vs. 1.2.3
* Use the ErrorReporter to show other relevant info.
  • Loading branch information
danielsdeleo authored and sethvargo committed Mar 4, 2014
1 parent ab5dd37 commit 6a69a3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/omnibus/exceptions.rb
Expand Up @@ -189,4 +189,7 @@ def to_s
E
end
end

class UnresolvableGitReference < RuntimeError
end
end
17 changes: 15 additions & 2 deletions lib/omnibus/fetchers/git_fetcher.rb
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.
#

require 'omnibus/exceptions'

module Omnibus
# Fetcher implementation for projects in git.
class GitFetcher < Fetcher
Expand Down Expand Up @@ -156,12 +158,23 @@ def revision_from_remote_reference(ref)
shell.run_command
shell.error!
commit_ref = process_remote_list(shell.stdout, ref)
fail 'Could not parse SHA reference' unless commit_ref

unless commit_ref
fail UnresolvableGitReference.new("Could not resolve `#{ref}' to a SHA.")
end
commit_ref
rescue UnresolvableGitReference => e # skip retries
ErrorReporter.new(e, self).explain(<<-E)
Command `#{cmd}' did not find a commit for reference `#{ref}'.
The tag or branch you're looking for doesn't exist on the remote repo.
If your project uses version tags like v1.2.3, include the 'v' in your
software's version.
E
raise
rescue Exception => e
if retries >= 3
ErrorReporter.new(e, self).explain("Failed to find any commits for the ref '#{ref}'")
raise
fail
else
# Deal with github failing all the time :(
time_to_sleep = 5 * (2**retries)
Expand Down

0 comments on commit 6a69a3d

Please sign in to comment.