diff --git a/lib/bundler/self_manager.rb b/lib/bundler/self_manager.rb index 70a5fedabdd577..491800514dfffe 100644 --- a/lib/bundler/self_manager.rb +++ b/lib/bundler/self_manager.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/bundler/runtime/self_management_spec.rb b/spec/bundler/runtime/self_management_spec.rb index 248555355cbf0b..d741c3c15bfc14 100644 --- a/spec/bundler/runtime/self_management_spec.rb +++ b/spec/bundler/runtime/self_management_spec.rb @@ -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