summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBundlerbot <bot@bundler.io>2019-07-05 11:15:42 +0000
committerBundlerbot <bot@bundler.io>2019-07-05 11:15:42 +0000
commitadf0e25fa23cbf1f62f40328a5f205f632dd6293 (patch)
tree0751cdd219589e344292a351e08dad92155bdc2a
parent138e8f8f6bb9ed14ce20b5c4ab4d54751c77e1e5 (diff)
parentca96316b97353b4344ba283be0051ef7e9d9a013 (diff)
downloadbundler-adf0e25fa23cbf1f62f40328a5f205f632dd6293.tar.gz
Merge #7225
7225: Clearer `MissingRevision` git errors r=deivid-rodriguez a=deivid-rodriguez ### What was the end-user problem that led to this PR? The problem was that sometimes we get the error "Revision xxxxxx does not exist in the repository https://github.com/my_user/my_repo. Maybe you misspelled?" ### What was your diagnosis of the problem? My diagnosis was that it's not always easy to troubleshoot this error, because you don't even know which git command failed in the first place. ### What is your fix for the problem, implemented in this PR? My fix is to also include in the error the command that originally failed. ### Why did you choose this fix out of the possible options? I chose this fix because I think it will help users with troubleshooting. Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
-rw-r--r--lib/bundler/source/git/git_proxy.rb18
-rw-r--r--spec/bundler/source/git/git_proxy_spec.rb10
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb
index f5af10f206..c383c5ecbb 100644
--- a/lib/bundler/source/git/git_proxy.rb
+++ b/lib/bundler/source/git/git_proxy.rb
@@ -26,7 +26,11 @@ module Bundler
end
class GitCommandError < GitError
+ attr_reader :command
+
def initialize(command, path = nil, extra_info = nil)
+ @command = command
+
msg = String.new
msg << "Git error: command `git #{command}` in directory #{SharedHelpers.pwd} has failed."
msg << "\n#{extra_info}" if extra_info
@@ -35,10 +39,10 @@ module Bundler
end
end
- class MissingGitRevisionError < GitError
- def initialize(ref, repo)
+ class MissingGitRevisionError < GitCommandError
+ def initialize(command, path, ref, repo)
msg = "Revision #{ref} does not exist in the repository #{repo}. Maybe you misspelled it?"
- super msg
+ super command, path, msg
end
end
@@ -63,8 +67,8 @@ module Bundler
begin
@revision ||= find_local_revision
- rescue GitCommandError
- raise MissingGitRevisionError.new(ref, URICredentialsFilter.credential_filtered_uri(uri))
+ rescue GitCommandError => e
+ raise MissingGitRevisionError.new(e.command, path, ref, URICredentialsFilter.credential_filtered_uri(uri))
end
@revision
@@ -135,8 +139,8 @@ module Bundler
begin
git "reset --hard #{@revision}"
- rescue GitCommandError
- raise MissingGitRevisionError.new(@revision, URICredentialsFilter.credential_filtered_uri(uri))
+ rescue GitCommandError => e
+ raise MissingGitRevisionError.new(e.command, path, @revision, URICredentialsFilter.credential_filtered_uri(uri))
end
if submodules
diff --git a/spec/bundler/source/git/git_proxy_spec.rb b/spec/bundler/source/git/git_proxy_spec.rb
index 016105ccde..c18490233d 100644
--- a/spec/bundler/source/git/git_proxy_spec.rb
+++ b/spec/bundler/source/git/git_proxy_spec.rb
@@ -128,16 +128,20 @@ RSpec.describe Bundler::Source::Git::GitProxy do
context "when given a SHA as a revision" do
let(:revision) { "abcd" * 10 }
+ let(:command) { "reset --hard #{revision}" }
it "fails gracefully when resetting to the revision fails" do
expect(subject).to receive(:git_retry).with(start_with("clone ")) { destination.mkpath }
expect(subject).to receive(:git_retry).with(start_with("fetch "))
- expect(subject).to receive(:git).with("reset --hard #{revision}").and_raise(Bundler::Source::Git::GitCommandError, "command")
+ expect(subject).to receive(:git).with(command).and_raise(Bundler::Source::Git::GitCommandError, command)
expect(subject).not_to receive(:git)
expect { subject.copy_to(destination, submodules) }.
- to raise_error(Bundler::Source::Git::MissingGitRevisionError,
- "Revision #{revision} does not exist in the repository #{uri}. Maybe you misspelled it?")
+ to raise_error(
+ Bundler::Source::Git::MissingGitRevisionError,
+ "Git error: command `git #{command}` in directory #{destination} has failed.\n" \
+ "Revision #{revision} does not exist in the repository #{uri}. Maybe you misspelled it?" \
+ )
end
end
end