diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2018-03-10 18:35:06 -0800 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2018-03-10 19:45:16 -0800 |
commit | b721ddfc5c292749b0cc21f1ca4bc329ce8a6edf (patch) | |
tree | 361535e3b73c09f32ff3fb5c46070b2a8f7dc45c | |
parent | 007a1737f3d3ba678bc78d3fa101d61b3d6892db (diff) | |
download | bundler-segiddins/fail-gracefully-when-resetting-to-rev-fails.tar.gz |
[GitProxy] Fail gracefully when resetting to the given revision failssegiddins/fail-gracefully-when-resetting-to-rev-fails
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 7 | ||||
-rw-r--r-- | spec/bundler/source/git/git_proxy_spec.rb | 26 |
2 files changed, 31 insertions, 2 deletions
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index c56dda66ea..cd964f7e56 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -131,7 +131,12 @@ module Bundler # method 2 SharedHelpers.chdir(destination) do git_retry %(fetch --force --quiet --tags "#{path}") - git "reset --hard #{@revision}" + + begin + git "reset --hard #{@revision}" + rescue GitCommandError + raise MissingGitRevisionError.new(@revision, URICredentialsFilter.credential_filtered_uri(uri)) + end if submodules git_retry "submodule update --init --recursive" diff --git a/spec/bundler/source/git/git_proxy_spec.rb b/spec/bundler/source/git/git_proxy_spec.rb index d282a449a5..3a29c97461 100644 --- a/spec/bundler/source/git/git_proxy_spec.rb +++ b/spec/bundler/source/git/git_proxy_spec.rb @@ -1,8 +1,12 @@ # frozen_string_literal: true RSpec.describe Bundler::Source::Git::GitProxy do + let(:path) { Pathname("path") } let(:uri) { "https://github.com/bundler/bundler.git" } - subject { described_class.new(Pathname("path"), uri, "HEAD") } + let(:ref) { "HEAD" } + let(:revision) { nil } + let(:git_source) { nil } + subject { described_class.new(path, uri, ref, revision, git_source) } context "with configured credentials" do it "adds username and password to URI" do @@ -113,4 +117,24 @@ RSpec.describe Bundler::Source::Git::GitProxy do end end end + + describe "#copy_to" do + let(:destination) { tmpdir("copy_to_path") } + let(:submodules) { false } + + context "when given a SHA as a revision" do + let(:revision) { "abcd" * 10 } + + 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).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?") + end + end + end end |