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 cb1e1cb
Show file tree
Hide file tree
Showing 4 changed files with 7 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

0 comments on commit cb1e1cb

Please sign in to comment.