From df20fcde8a6cc727eea91fff6d5994f6c45fd67a Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 3 Dec 2015 16:13:16 -0800 Subject: 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. --- lib/bundler/source/git/git_proxy.rb | 35 ++++++++++++++++++++++++++++++++--- 1 file 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) -- cgit v1.2.1