[rubygems/rubygems] Auto switch to locked bundler version even when using binstubs

https://github.com/rubygems/rubygems/commit/076aba8b1c
This commit is contained in:
David Rodríguez 2024-06-06 13:38:16 +02:00 committed by git
parent ad9fe6f376
commit 3e84da0970
5 changed files with 35 additions and 1 deletions

View File

@ -167,6 +167,10 @@ module Bundler
end end
end end
def auto_switch
self_manager.restart_with_locked_bundler_if_needed
end
# Automatically install dependencies if Bundler.settings[:auto_install] exists. # Automatically install dependencies if Bundler.settings[:auto_install] exists.
# This is set through config cmd `bundle config set --global auto_install 1`. # This is set through config cmd `bundle config set --global auto_install 1`.
# #

View File

@ -65,7 +65,7 @@ module Bundler
Bundler.reset_settings_and_root! Bundler.reset_settings_and_root!
end end
Bundler.self_manager.restart_with_locked_bundler_if_needed Bundler.auto_switch
Bundler.settings.set_command_option_if_given :retry, options[:retry] Bundler.settings.set_command_option_if_given :retry, options[:retry]

View File

@ -92,6 +92,7 @@ module Bundler
def autoswitching_applies? def autoswitching_applies?
ENV["BUNDLER_VERSION"].nil? && ENV["BUNDLER_VERSION"].nil? &&
Bundler.rubygems.supports_bundler_trampolining? && Bundler.rubygems.supports_bundler_trampolining? &&
ruby_can_restart_with_same_arguments? &&
SharedHelpers.in_bundle? && SharedHelpers.in_bundle? &&
lockfile_version lockfile_version
end end
@ -151,6 +152,10 @@ module Bundler
!version.to_s.end_with?(".dev") !version.to_s.end_with?(".dev")
end end
def ruby_can_restart_with_same_arguments?
$PROGRAM_NAME != "-e"
end
def updating? def updating?
"update".start_with?(ARGV.first || " ") && ARGV[1..-1].any? {|a| a.start_with?("--bundler") } "update".start_with?(ARGV.first || " ") && ARGV[1..-1].any? {|a| a.start_with?("--bundler") }
end end

View File

@ -5,6 +5,9 @@ require_relative "shared_helpers"
if Bundler::SharedHelpers.in_bundle? if Bundler::SharedHelpers.in_bundle?
require_relative "../bundler" require_relative "../bundler"
# autoswitch to locked Bundler version if available
Bundler.auto_switch
# try to auto_install first before we get to the `Bundler.ui.silence`, so user knows what is happening # try to auto_install first before we get to the `Bundler.ui.silence`, so user knows what is happening
Bundler.auto_install Bundler.auto_install

View File

@ -35,6 +35,17 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do
bundle "-v", artifice: nil bundle "-v", artifice: nil
expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor) expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor)
# App now uses locked version, even when not using the CLI directly
file = bundled_app("bin/bundle_version.rb")
create_file file, <<-RUBY
#!#{Gem.ruby}
require 'bundler/setup'
puts Bundler::VERSION
RUBY
file.chmod(0o777)
sys_exec "bin/bundle_version.rb", artifice: nil
expect(out).to eq(previous_minor)
# Subsequent installs use the locked version without reinstalling # Subsequent installs use the locked version without reinstalling
bundle "install --verbose", artifice: nil bundle "install --verbose", artifice: nil
expect(out).to include("Using bundler #{previous_minor}") expect(out).to include("Using bundler #{previous_minor}")
@ -57,6 +68,17 @@ RSpec.describe "Self management", rubygems: ">= 3.3.0.dev", realworld: true do
bundle "-v" bundle "-v"
expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor) expect(out).to end_with(previous_minor[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor)
# App now uses locked version, even when not using the CLI directly
file = bundled_app("bin/bundle_version.rb")
create_file file, <<-RUBY
#!#{Gem.ruby}
require 'bundler/setup'
puts Bundler::VERSION
RUBY
file.chmod(0o777)
sys_exec "bin/bundle_version.rb", artifice: nil
expect(out).to eq(previous_minor)
# Subsequent installs use the locked version without reinstalling # Subsequent installs use the locked version without reinstalling
bundle "install --verbose" bundle "install --verbose"
expect(out).to include("Using bundler #{previous_minor}") expect(out).to include("Using bundler #{previous_minor}")