diff options
author | Jesse Luehrs <jesse.luehrs@stripe.com> | 2015-12-03 16:13:16 -0800 |
---|---|---|
committer | Jesse Luehrs <jesse.luehrs@stripe.com> | 2015-12-03 16:13:16 -0800 |
commit | df20fcde8a6cc727eea91fff6d5994f6c45fd67a (patch) | |
tree | 2ce7d1065cdefdf3a5f585028ebe9879ad2da356 /lib/bundler/source | |
parent | f2035cc109212c36917cdf1f19beb168ab0e2ab0 (diff) | |
download | bundler-df20fcde8a6cc727eea91fff6d5994f6c45fd67a.tar.gz |
give a better error message when a remote ref no longer exists
if we can't find the given ref after fetching, try clearing the cache
ourselves and trying again. if we still can't find it, we know that it
actually just doesn't exist, so tell the user that.
Diffstat (limited to 'lib/bundler/source')
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index b8900888a9..3b52843f7e 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -27,6 +27,13 @@ module Bundler end end + class GitRevisionError < GitError + def initialize(ref, repo) + msg = "Revision #{ref} does not exist in the repository #{repo}. Maybe you misspelled it?" + super msg + end + end + # The GitProxy is responsible to interact with git repositories. # All actions required by the Git source is encapsulated in this # object. @@ -44,10 +51,22 @@ module Bundler end def revision - @revision ||= allowed_in_path do - msg = "Ref '#{ref}' was not found. Perhaps you mispelled it?" - git("rev-parse --verify #{ref}", true, msg).strip + return @revision if @revision + + begin + @revision ||= find_local_revision + rescue GitCommandError + Bundler.ui.info "Error finding #{ref} in #{path}: clearing the cache and trying again" + remove_cache + checkout + begin + @revision ||= find_local_revision + rescue GitCommandError + raise GitRevisionError.new(ref, uri) + end end + + @revision end def branch @@ -143,6 +162,16 @@ module Bundler false end + def remove_cache + FileUtils.rm_rf(path) + end + + def find_local_revision + allowed_in_path do + git("rev-parse --verify #{ref}", true).strip + end + end + # Escape the URI for git commands def uri_escaped_with_configured_credentials remote = configured_uri_for(uri) |