Skip to content

Commit 2406589

Browse files
authored
Merge pull request #9545 from ruby/bundle-version-lockfile-fallback
Fall back to lockfile version when `BUNDLE_VERSION` is "lockfile"
2 parents 0e59041 + 6576bb8 commit 2406589

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/rubygems/bundler_version_finder.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
module Gem::BundlerVersionFinder
44
def self.bundler_version
5-
return if bundle_config_version == "system"
5+
bcv = bundle_config_version
6+
return if bcv == "system"
67

78
v = ENV["BUNDLER_VERSION"]
89
v = nil if v&.empty?
910

1011
v ||= bundle_update_bundler_version
1112
return if v == true
1213

13-
v ||= bundle_config_version
14+
v ||= bcv unless bcv == "lockfile"
1415

1516
v ||= lockfile_version
1617
return unless v

test/rubygems/test_gem_bundler_version_finder.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,31 @@ def test_bundler_version_with_empty_bundle_version_env
146146
end
147147
end
148148

149+
def test_bundler_version_with_bundle_version_env_lockfile
150+
ENV["BUNDLE_VERSION"] = "lockfile"
151+
152+
bvf.stub(:lockfile_contents, "\n\nBUNDLED WITH\n 1.1.1.1\n") do
153+
assert_equal v("1.1.1.1"), bvf.bundler_version
154+
end
155+
end
156+
157+
def test_bundler_version_with_bundle_config_version_lockfile
158+
config_content = <<~CONFIG
159+
BUNDLE_VERSION: "lockfile"
160+
CONFIG
161+
162+
Tempfile.create("bundle_config") do |f|
163+
f.write(config_content)
164+
f.flush
165+
166+
bvf.stub(:bundler_global_config_file, f.path) do
167+
bvf.stub(:lockfile_contents, "\n\nBUNDLED WITH\n 1.1.1.1\n") do
168+
assert_equal v("1.1.1.1"), bvf.bundler_version
169+
end
170+
end
171+
end
172+
end
173+
149174
def test_bundler_version_with_bundle_config_non_existent_file
150175
bvf.stub(:bundler_global_config_file, "/non/existent/path") do
151176
assert_nil bvf.bundler_version

0 commit comments

Comments
 (0)