[rubygems/rubygems] Fix bundle update --bundler when restarts disabled

There's no reason why we should not update bundler as requested, even if
restarts are disabled.

https://github.com/rubygems/rubygems/commit/e59acd2a0d
This commit is contained in:
David Rodríguez 2025-05-29 20:49:29 +02:00 committed by Hiroshi SHIBATA
parent 5cf07c1e8f
commit e4933e1d93
2 changed files with 20 additions and 9 deletions

View File

@ -31,8 +31,6 @@ module Bundler
end end
def update_bundler_and_restart_with_it_if_needed(target) def update_bundler_and_restart_with_it_if_needed(target)
return unless autoswitching_applies?
spec = resolve_update_version_from(target) spec = resolve_update_version_from(target)
return unless spec return unless spec
@ -40,7 +38,7 @@ module Bundler
Bundler.ui.info "Updating bundler to #{version}." Bundler.ui.info "Updating bundler to #{version}."
install(spec) install(spec) unless installed?(version)
restart_with(version) restart_with(version)
end end
@ -102,8 +100,7 @@ module Bundler
def needs_switching?(restart_version) def needs_switching?(restart_version)
autoswitching_applies? && autoswitching_applies? &&
released?(restart_version) && released?(restart_version) &&
!running?(restart_version) && !running?(restart_version)
!updating?
end end
def autoswitching_applies? def autoswitching_applies?
@ -172,10 +169,6 @@ module Bundler
$PROGRAM_NAME != "-e" $PROGRAM_NAME != "-e"
end end
def updating?
"update".start_with?(ARGV.first || " ") && ARGV[1..-1].any? {|a| a.start_with?("--bundler") }
end
def installed?(restart_version) def installed?(restart_version)
Bundler.configure Bundler.configure

View File

@ -1684,6 +1684,24 @@ RSpec.describe "bundle update --bundler" do
expect(err).to eq("The `bundle update --bundler` target version (999.999.999) does not exist") expect(err).to eq("The `bundle update --bundler` target version (999.999.999) does not exist")
end end
it "errors if the explicit target version does not exist, even if auto switching is disabled" do
pristine_system_gems "bundler-9.9.9"
build_repo4 do
build_gem "myrack", "1.0"
end
install_gemfile <<-G
source "https://gem.repo4"
gem "myrack"
G
bundle :update, bundler: "999.999.999", raise_on_error: false, env: { "BUNDLER_VERSION" => "9.9.9" }
expect(last_command).to be_failure
expect(err).to eq("The `bundle update --bundler` target version (999.999.999) does not exist")
end
it "allows updating to development versions if already installed locally" do it "allows updating to development versions if already installed locally" do
system_gems "bundler-9.9.9" system_gems "bundler-9.9.9"