Skip to content

Commit c652c23

Browse files
committed
Read BUNDLE_VERSION env var in BundlerVersionFinder
Bundler::Settings resolves the `version` setting from the BUNDLE_VERSION environment variable, but Gem::BundlerVersionFinder only consulted the .bundle/config file. As a result `BUNDLE_VERSION=system` was ignored at activation time and a lockfile-pinned bundler installed globally won out over the default gem. #9534
1 parent 92b0305 commit c652c23

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

lib/rubygems/bundler_version_finder.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def self.lockfile_contents
7070
private_class_method :lockfile_contents
7171

7272
def self.bundle_config_version
73+
env_version = ENV["BUNDLE_VERSION"]
74+
return env_version if env_version && !env_version.empty?
75+
7376
version = nil
7477

7578
[bundler_local_config_file, bundler_global_config_file].each do |config_file|

test/rubygems/test_gem_bundler_version_finder.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,48 @@ def test_bundler_version_with_bundle_config_version
104104
end
105105
end
106106

107+
def test_bundler_version_with_bundle_version_env_system
108+
ENV["BUNDLE_VERSION"] = "system"
109+
110+
bvf.stub(:lockfile_contents, "\n\nBUNDLED WITH\n 1.1.1.1\n") do
111+
assert_nil bvf.bundler_version
112+
end
113+
end
114+
115+
def test_bundler_version_with_bundle_version_env_overrides_config
116+
ENV["BUNDLE_VERSION"] = "2.3.4"
117+
118+
config_content = <<~CONFIG
119+
BUNDLE_VERSION: "1.2.3"
120+
CONFIG
121+
122+
Tempfile.create("bundle_config") do |f|
123+
f.write(config_content)
124+
f.flush
125+
126+
bvf.stub(:bundler_global_config_file, f.path) do
127+
assert_equal v("2.3.4"), bvf.bundler_version
128+
end
129+
end
130+
end
131+
132+
def test_bundler_version_with_empty_bundle_version_env
133+
ENV["BUNDLE_VERSION"] = ""
134+
135+
config_content = <<~CONFIG
136+
BUNDLE_VERSION: "1.2.3"
137+
CONFIG
138+
139+
Tempfile.create("bundle_config") do |f|
140+
f.write(config_content)
141+
f.flush
142+
143+
bvf.stub(:bundler_global_config_file, f.path) do
144+
assert_equal v("1.2.3"), bvf.bundler_version
145+
end
146+
end
147+
end
148+
107149
def test_bundler_version_with_bundle_config_non_existent_file
108150
bvf.stub(:bundler_global_config_file, "/non/existent/path") do
109151
assert_nil bvf.bundler_version

0 commit comments

Comments
 (0)