Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle BUNDLER_VERSION being set to an empty string #6928

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions bundler/spec/commands/binstubs_spec.rb
Expand Up @@ -150,6 +150,12 @@
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
skip "does not work on old rubies" if RUBY_VERSION < "2.7.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are now 3.0+, this line should be deletable


sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "" }
ccutrer marked this conversation as resolved.
Show resolved Hide resolved
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