Skip to content

Commit

Permalink
Handle BUNDLER_VERSION being set to an empty string
Browse files Browse the repository at this point in the history
This is useful, in case you're using Docker, and an upstream
Dockerfile sets BUNDLER_VERSION to something you don't want.
It's impossible to unset it... only override to be the empty
string.
  • Loading branch information
ccutrer committed Aug 30, 2023
1 parent 54032f3 commit 68eb32a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bundler/lib/bundler/self_manager.rb
Expand Up @@ -90,7 +90,7 @@ def needs_switching?
end

def autoswitching_applies?
ENV["BUNDLER_VERSION"].nil? &&
(ENV["BUNDLER_VERSION"].nil? || ENV["BUNDLER_VERSION"].empty?) &&
Bundler.rubygems.supports_bundler_trampolining? &&
SharedHelpers.in_bundle? &&
lockfile_version
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/templates/Executable.bundler
Expand Up @@ -18,7 +18,7 @@ m = Module.new do
end

def env_var_version
ENV["BUNDLER_VERSION"]
ENV["BUNDLER_VERSION"]&.then { |v| v.empty? ? nil : v }
end

def cli_arg_version
Expand Down
4 changes: 4 additions & 0 deletions bundler/spec/commands/binstubs_spec.rb
Expand Up @@ -150,6 +150,10 @@
sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.998", "DEBUG" => "1" }, :raise_on_error => false
expect(out).to include %(Using bundler 999.999.998\n)
end

it "runs correctly even if empty" do
sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "" }
end
end

context "when a lockfile exists with a locked bundler version" do
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/bundler_version_finder.rb
Expand Up @@ -3,6 +3,7 @@
module Gem::BundlerVersionFinder
def self.bundler_version
v = ENV["BUNDLER_VERSION"]
v = nil if v&.empty?

v ||= bundle_update_bundler_version
return if v == true
Expand Down
5 changes: 5 additions & 0 deletions test/rubygems/test_gem_bundler_version_finder.rb
Expand Up @@ -32,6 +32,11 @@ def test_bundler_version_with_env_var
assert_equal v("1.1.1.1"), bvf.bundler_version
end

def test_bundler_version_with_empty_env_var
ENV["BUNDLER_VERSION"] = ""
assert_nil bvf.bundler_version
end

def test_bundler_version_with_bundle_update_bundler
ARGV.replace %w[update --bundler]
assert_nil bvf.bundler_version
Expand Down

0 comments on commit 68eb32a

Please sign in to comment.