Skip to content

Commit

Permalink
Merge pull request #6356 from rubygems/better-error-on-bad-ref
Browse files Browse the repository at this point in the history
Restore better error message when locked ref does not exist
  • Loading branch information
deivid-rodriguez committed Feb 10, 2023
2 parents a246c5e + c8e0243 commit 584ac4c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bundler/lib/bundler/source/git/git_proxy.rb
Expand Up @@ -139,8 +139,8 @@ def git_remote_fetch(args)
out, err, status = capture(command, path)
return out if status.success?

if err.include?("couldn't find remote ref")
raise MissingGitRevisionError.new(command_with_no_credentials, path, explicit_ref, credential_filtered_uri)
if err.include?("couldn't find remote ref") || err.include?("not our ref")
raise MissingGitRevisionError.new(command_with_no_credentials, path, commit || explicit_ref, credential_filtered_uri)
else
raise GitCommandError.new(command_with_no_credentials, path, err)
end
Expand Down Expand Up @@ -186,8 +186,6 @@ def depth
end

def refspec
commit = pinned_to_full_sha? ? ref : @revision

if commit
@commit_ref = "refs/#{commit}-sha"
return "#{commit}:#{@commit_ref}"
Expand All @@ -206,6 +204,10 @@ def refspec
"#{reference}:#{reference}"
end

def commit
@commit ||= pinned_to_full_sha? ? ref : @revision
end

def fully_qualified_ref
if branch
"refs/heads/#{branch}"
Expand Down
27 changes: 27 additions & 0 deletions bundler/spec/lock/git_spec.rb
Expand Up @@ -33,6 +33,33 @@
expect(err).to include("Revision bad does not exist in the repository")
end

it "prints a proper error when installing a Gemfile with a locked ref that does not exist" do
lockfile <<~L
GIT
remote: #{lib_path("foo-1.0")}
revision: #{"a" * 40}
specs:
foo (1.0)
GEM
remote: #{file_uri_for(gem_repo1)}/
specs:
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo!
BUNDLED WITH
#{Bundler::VERSION}
L

bundle "install", :raise_on_error => false

expect(err).to include("Revision #{"a" * 40} does not exist in the repository")
end

it "locks a git source to the current ref" do
update_git "foo"
bundle :install
Expand Down

0 comments on commit 584ac4c

Please sign in to comment.