diff options
Diffstat (limited to 'lib/bundler/source/git/git_proxy.rb')
-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) |