[rubygems/rubygems] Improve frozen mode error message

This error message is also printed when using `bundler/setup` in frozen
model, so we're not necessarily installing any gems when it happens.

This new message play nicer with all situations.

https://github.com/rubygems/rubygems/commit/6874bbacce
This commit is contained in:
David Rodríguez 2023-06-10 00:19:39 +02:00 committed by Hiroshi SHIBATA
parent 23ecaab8dd
commit e86f4c581b
5 changed files with 19 additions and 22 deletions

View File

@ -364,18 +364,6 @@ module Bundler
end end
def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false) def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
msg = String.new
msg << "You are trying to install in frozen mode after changing your Gemfile.\n" \
"Run `bundle install` elsewhere and add the updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control.\n"
unless explicit_flag
suggested_command = unless Bundler.settings.locations("frozen").keys.include?(:env)
"bundle config set frozen false"
end
msg << "If this is a development machine, remove the #{Bundler.default_gemfile.relative_path_from(SharedHelpers.pwd)} " \
"freeze by running `#{suggested_command}`." if suggested_command
end
added = [] added = []
deleted = [] deleted = []
changed = [] changed = []
@ -405,11 +393,20 @@ module Bundler
end end
reason = change_reason reason = change_reason
msg << "\n\n#{reason.split(", ").map(&:capitalize).join("\n")}" 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? msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any?
msg << "\n\nYou have deleted from the Gemfile:\n" << deleted.join("\n") if deleted.any? msg << "\n\nYou have deleted from the Gemfile:\n" << deleted.join("\n") if deleted.any?
msg << "\n\nYou have changed in the Gemfile:\n" << changed.join("\n") if changed.any? msg << "\n\nYou have changed in the Gemfile:\n" << changed.join("\n") if changed.any?
msg << "\n" msg << "\n\nRun `bundle install` elsewhere and add the updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control.\n"
unless explicit_flag
suggested_command = unless Bundler.settings.locations("frozen").keys.include?(:env)
"bundle config set frozen false"
end
msg << "If this is a development machine, remove the #{Bundler.default_gemfile.relative_path_from(SharedHelpers.pwd)} " \
"freeze by running `#{suggested_command}`." if suggested_command
end
raise ProductionError, msg if added.any? || deleted.any? || changed.any? || !nothing_changed? raise ProductionError, msg if added.any? || deleted.any? || changed.any? || !nothing_changed?
end end

View File

@ -109,7 +109,7 @@ Usage: "bundle inject GEM VERSION"
gem "rack-obama" gem "rack-obama"
G G
bundle "inject 'rack' '> 0'", :raise_on_error => false bundle "inject 'rack' '> 0'", :raise_on_error => false
expect(err).to match(/trying to install in frozen mode after changing/) expect(err).to match(/the lockfile can't be updated because frozen mode is set/)
expect(bundled_app_lock.read).not_to match(/rack-obama/) expect(bundled_app_lock.read).not_to match(/rack-obama/)
end end

View File

@ -658,27 +658,27 @@ RSpec.describe "bundle update" do
bundle "update", :all => true, :raise_on_error => false bundle "update", :all => true, :raise_on_error => false
expect(last_command).to be_failure expect(last_command).to be_failure
expect(err).to match(/You are trying to install in frozen mode after changing your Gemfile/) expect(err).to match(/Bundler is unlocking, but the lockfile can't be updated because frozen mode is set/)
expect(err).to match(/freeze by running `bundle config set frozen false`./) expect(err).to match(/freeze by running `bundle config set frozen false`./)
end end
it "should fail loudly when frozen is set globally" do it "should fail loudly when frozen is set globally" do
bundle "config set --global frozen 1" bundle "config set --global frozen 1"
bundle "update", :all => true, :raise_on_error => false bundle "update", :all => true, :raise_on_error => false
expect(err).to match(/You are trying to install in frozen mode after changing your Gemfile/). expect(err).to match(/Bundler is unlocking, but the lockfile can't be updated because frozen mode is set/).
and match(/freeze by running `bundle config set frozen false`./) and match(/freeze by running `bundle config set frozen false`./)
end end
it "should fail loudly when deployment is set globally" do it "should fail loudly when deployment is set globally" do
bundle "config set --global deployment true" bundle "config set --global deployment true"
bundle "update", :all => true, :raise_on_error => false bundle "update", :all => true, :raise_on_error => false
expect(err).to match(/You are trying to install in frozen mode after changing your Gemfile/). expect(err).to match(/Bundler is unlocking, but the lockfile can't be updated because frozen mode is set/).
and match(/freeze by running `bundle config set frozen false`./) and match(/freeze by running `bundle config set frozen false`./)
end end
it "should not suggest any command to unfreeze bundler if frozen is set through ENV" do it "should not suggest any command to unfreeze bundler if frozen is set through ENV" do
bundle "update", :all => true, :raise_on_error => false, :env => { "BUNDLE_FROZEN" => "true" } bundle "update", :all => true, :raise_on_error => false, :env => { "BUNDLE_FROZEN" => "true" }
expect(err).to match(/You are trying to install in frozen mode after changing your Gemfile/) expect(err).to match(/Bundler is unlocking, but the lockfile can't be updated because frozen mode is set/)
expect(err).not_to match(/by running/) expect(err).not_to match(/by running/)
end end
end end

View File

@ -473,7 +473,7 @@ RSpec.describe "install in deployment or frozen mode" do
run "require 'rack'", :raise_on_error => false run "require 'rack'", :raise_on_error => false
expect(err).to include strip_whitespace(<<-E).strip expect(err).to include strip_whitespace(<<-E).strip
The dependencies in your gemfile changed The dependencies in your gemfile changed, but the lockfile can't be updated because frozen mode is set (Bundler::ProductionError)
You have added to the Gemfile: You have added to the Gemfile:
* rack (= 1.0.0) * rack (= 1.0.0)
@ -506,7 +506,7 @@ You have deleted from the Gemfile:
simulate_new_machine simulate_new_machine
bundle "config set --local deployment true" bundle "config set --local deployment true"
bundle "install --verbose" bundle "install --verbose"
expect(out).not_to include("You are trying to install in frozen mode after changing your Gemfile") expect(out).not_to include("but the lockfile can't be updated because frozen mode is set")
expect(out).not_to include("You have added to the Gemfile") expect(out).not_to include("You have added to the Gemfile")
expect(out).not_to include("You have deleted from the Gemfile") expect(out).not_to include("You have deleted from the Gemfile")
expect(out).to include("vendor/cache/foo") expect(out).to include("vendor/cache/foo")

View File

@ -150,7 +150,7 @@ RSpec.describe "bundle install from an existing gemspec" do
output = bundle("install", :dir => tmp.join("foo")) output = bundle("install", :dir => tmp.join("foo"))
expect(output).not_to match(/You have added to the Gemfile/) expect(output).not_to match(/You have added to the Gemfile/)
expect(output).not_to match(/You have deleted from the Gemfile/) expect(output).not_to match(/You have deleted from the Gemfile/)
expect(output).not_to match(/install in frozen mode after changing/) expect(output).not_to match(/the lockfile can't be updated because frozen mode is set/)
end end
it "should match a lockfile without needing to re-resolve" do it "should match a lockfile without needing to re-resolve" do