Skip to content

Commit 57cfe7c

Browse files
committed
restart with BUNDLE_VERSION if it's specified
1 parent c431a1d commit 57cfe7c

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

bundler/lib/bundler/self_manager.rb

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,19 @@ class SelfManager
99
def restart_with_locked_bundler_if_needed
1010
return unless needs_switching? && installed?
1111

12-
restart_with(lockfile_version)
12+
restart_with(restart_version)
1313
end
1414

1515
def install_locked_bundler_and_restart_with_it_if_needed
1616
return unless needs_switching?
1717

18-
begin
19-
# BUNDLE_VERSION=x.y.z
20-
restart_version = Gem::Version.new(Bundler.settings[:version])
21-
18+
if restart_version == lockfile_version
2219
Bundler.ui.info \
23-
"Bundler #{current_version} is running, but your configuration was #{restart_version}. " \
24-
"Installing Bundler #{restart_version} and restarting using that version."
25-
rescue ArgumentError
26-
# BUNDLE_VERSION=local
27-
restart_version = lockfile_version
28-
20+
"Bundler #{current_version} is running, but your lockfile was generated with #{lockfile_version}. " \
21+
"Installing Bundler #{lockfile_version} and restarting using that version."
22+
else
2923
Bundler.ui.info \
30-
"Bundler #{current_version} is running, but your lockfile was generated with #{restart_version}. " \
24+
"Bundler #{current_version} is running, but your configuration was #{restart_version}. " \
3125
"Installing Bundler #{restart_version} and restarting using that version."
3226
end
3327

@@ -164,7 +158,7 @@ def updating?
164158
def installed?
165159
Bundler.configure
166160

167-
Bundler.rubygems.find_bundler(lockfile_version.to_s)
161+
Bundler.rubygems.find_bundler(restart_version.to_s)
168162
end
169163

170164
def current_version
@@ -177,5 +171,14 @@ def lockfile_version
177171
parsed_version = Bundler::LockfileParser.bundled_with
178172
@lockfile_version = parsed_version ? Gem::Version.new(parsed_version) : nil
179173
end
174+
175+
def restart_version
176+
return @restart_version if defined?(@restart_version)
177+
# BUNDLE_VERSION=x.y.z
178+
@restart_version = Gem::Version.new(Bundler.settings[:version])
179+
rescue ArgumentError
180+
# BUNDLE_VERSION=local
181+
@restart_version = lockfile_version
182+
end
180183
end
181184
end

bundler/spec/runtime/self_management_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
bundle "config set --local version #{previous_minor}"
110110
bundle "install", :artifice => "vcr"
111111
expect(out).to include("Bundler #{Bundler::VERSION} is running, but your configuration was #{previous_minor}. Installing Bundler #{previous_minor} and restarting using that version.")
112+
113+
bundle "-v"
114+
expect(out).to eq(Bundler::VERSION[0] == "2" ? "Bundler version #{previous_minor}" : previous_minor)
112115
end
113116

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

0 commit comments

Comments
 (0)