Skip to content

Read BUNDLE_VERSION env var in BundlerVersionFinder#9538

Merged
hsbt merged 1 commit into
masterfrom
bundle-version-env-system
May 14, 2026
Merged

Read BUNDLE_VERSION env var in BundlerVersionFinder#9538
hsbt merged 1 commit into
masterfrom
bundle-version-env-system

Conversation

@hsbt
Copy link
Copy Markdown
Member

@hsbt hsbt commented May 12, 2026

What was the end-user or developer problem that led to this PR?

Fixes #9534

What is your fix for the problem, implemented in this PR?

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.

Make sure the following tasks are checked

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
Copilot AI review requested due to automatic review settings May 12, 2026 07:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates RubyGems’ Bundler activation/version selection logic so Gem::BundlerVersionFinder honors the BUNDLE_VERSION environment variable (matching Bundler’s own Settings precedence), instead of only reading .bundle/config. This addresses cases like BUNDLE_VERSION=system being ignored when a lockfile-pinned Bundler version is installed globally.

Changes:

  • Teach Gem::BundlerVersionFinder.bundle_config_version to consult ENV["BUNDLE_VERSION"] before reading local/global Bundler config files.
  • Add tests asserting BUNDLE_VERSION=system is respected and that BUNDLE_VERSION overrides config-file BUNDLE_VERSION.
  • Add tests ensuring an empty BUNDLE_VERSION env var does not override config.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/rubygems/bundler_version_finder.rb Read BUNDLE_VERSION env var as the highest-priority source for the bundle “version” setting.
test/rubygems/test_gem_bundler_version_finder.rb Add coverage for BUNDLE_VERSION env var behavior (system / overrides config / empty).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 72 to +75
def self.bundle_config_version
env_version = ENV["BUNDLE_VERSION"]
return env_version if env_version && !env_version.empty?

assert_nil bvf.bundler_version
end
end

@hsbt hsbt merged commit 65ae6ea into master May 14, 2026
98 checks passed
@hsbt hsbt deleted the bundle-version-env-system branch May 14, 2026 00:51
pull Bot pushed a commit to NeatNerdPrime/rubygems that referenced this pull request May 14, 2026
Bundler treats "lockfile" as a special value for the version setting,
meaning "use the version recorded in BUNDLED WITH". BundlerVersionFinder
was passing the raw string to Gem::Version.new and raising ArgumentError
both from the env var added in ruby#9538 and from .bundle/config.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUNDLE_VERSION=system does not always use the default_gem of bundler

2 participants