From 133fec4ce933e5a37de84c9c002bb998b4d8acb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 8 Jul 2024 18:21:34 +0200 Subject: [PATCH] [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 --- lib/bundler/definition.rb | 2 +- spec/bundler/install/deploy_spec.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 63033b9065..cb94063b05 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -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? diff --git a/spec/bundler/install/deploy_spec.rb b/spec/bundler/install/deploy_spec.rb index 23d2bd39ba..dfb352f170 100644 --- a/spec/bundler/install/deploy_spec.rb +++ b/spec/bundler/install/deploy_spec.rb @@ -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"