Skip to content

Commit

Permalink
[rubygems/rubygems] restart with BUNDLE_VERSION if it's specified
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbt committed Jul 13, 2023
1 parent f16c880 commit d3305ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/bundler/self_manager.rb
Expand Up @@ -9,25 +9,19 @@ class SelfManager
def restart_with_locked_bundler_if_needed
return unless needs_switching? && installed?

restart_with(lockfile_version)
restart_with(restart_version)
end

def install_locked_bundler_and_restart_with_it_if_needed
return unless needs_switching?

begin
# BUNDLE_VERSION=x.y.z
restart_version = Gem::Version.new(Bundler.settings[:version])

if restart_version == lockfile_version
Bundler.ui.info \
"Bundler #{current_version} is running, but your configuration was #{restart_version}. " \
"Installing Bundler #{restart_version} and restarting using that version."
rescue ArgumentError
# BUNDLE_VERSION=local
restart_version = lockfile_version

"Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \
"Installing Bundler #{lockfile_version} and restarting using that version."
else
Bundler.ui.info \
"Bundler #{current_version} is running, but your lockfile was generated with #{restart_version}. " \
"Bundler #{current_version} is running, but your configuration was #{restart_version}. " \
"Installing Bundler #{restart_version} and restarting using that version."
end

Expand Down Expand Up @@ -164,7 +158,7 @@ def updating?
def installed?
Bundler.configure

Bundler.rubygems.find_bundler(lockfile_version.to_s)
Bundler.rubygems.find_bundler(restart_version.to_s)
end

def current_version
Expand All @@ -177,5 +171,14 @@ def lockfile_version
parsed_version = Bundler::LockfileParser.bundled_with
@lockfile_version = parsed_version ? Gem::Version.new(parsed_version) : nil
end

def restart_version
return @restart_version if defined?(@restart_version)
# BUNDLE_VERSION=x.y.z
@restart_version = Gem::Version.new(Bundler.settings[:version])
rescue ArgumentError
# BUNDLE_VERSION=local
@restart_version = lockfile_version
end
end
end
3 changes: 3 additions & 0 deletions spec/bundler/runtime/self_management_spec.rb
Expand Up @@ -109,6 +109,9 @@
bundle "config set --local version #{previous_minor}"
bundle "install", :artifice => "vcr"
expect(out).to include("Bundler #{Bundler::VERSION} is running, but your configuration was #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.")

bundle "-v"
expect(out).to eq(Bundler::VERSION[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor)
end

it "does not try to install when using bundle config version global" do
Expand Down

0 comments on commit d3305ca

Please sign in to comment.