[rubygems/rubygems] Fix another strange error when running bundle add in frozen mode

If there's a lockfile, but it's out of sync with the Gemfile because a
dependency has been deleted, and frozen mode is set, Bundler will print
the following strange error:

```
$ bundle add rake
, but the lockfile can't be updated because frozen mode is set

You have deleted from the Gemfile:
* rake (~> 13.2)

Run `bundle install` elsewhere and add the updated Gemfile to version control.
```

This commit changes the error to:

```
Some dependencies were deleted from your gemfile, but the lockfile can't be updated because frozen mode is set

You have deleted from the Gemfile:
* rake (~> 13.2)

Run `bundle install` elsewhere and add the updated Gemfile to version control.
```

https://github.com/rubygems/rubygems/commit/452da4048d
This commit is contained in:
David Rodríguez 2024-07-08 18:21:34 +02:00 committed by git
parent 7e612b7414
commit 133fec4ce9
2 changed files with 13 additions and 2 deletions

View File

@ -399,7 +399,7 @@ module Bundler
changed << "* #{name} from `#{lockfile_source_name}` to `#{gemfile_source_name}`"
end
reason = change_reason
reason = nothing_changed? ? "some dependencies were deleted from your gemfile" : change_reason
msg = String.new
msg << "#{reason.capitalize.strip}, but the lockfile can't be updated because frozen mode is set"
msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any?

View File

@ -388,7 +388,7 @@ RSpec.describe "install in deployment or frozen mode" do
expect(out).not_to include("* myrack-obama")
end
it "explodes if you remove a gem and don't check in the lockfile" do
it "explodes if you replace a gem and don't check in the lockfile" do
gemfile <<-G
source "https://gem.repo1"
gem "activesupport"
@ -402,6 +402,17 @@ RSpec.describe "install in deployment or frozen mode" do
expect(err).not_to include("You have changed in the Gemfile")
end
it "explodes if you remove a gem and don't check in the lockfile" do
gemfile 'source "https://gem.repo1"'
bundle "config set --local deployment true"
bundle :install, raise_on_error: false
expect(err).to include("Some dependencies were deleted")
expect(err).to include("frozen mode")
expect(err).to include("You have deleted from the Gemfile:\n* myrack")
expect(err).not_to include("You have changed in the Gemfile")
end
it "explodes if you add a source" do
gemfile <<-G
source "https://gem.repo1"