diff options
| author | Jeremy Evans <code@jeremyevans.net> | 2025-11-30 19:16:52 -0800 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-12-02 08:25:17 +0000 |
| commit | 456ba321a84d34e76c8837ac96f47a11457480cb (patch) | |
| tree | 85c59455cd6eef2b39372035248ebd9568663bb6 | |
| parent | 0e22108d60fbd0e338fb6e110ddd81a93b45b592 (diff) | |
[ruby/rubygems] Make BUNDLE_LOCKFILE environment variable have precedence over lockfile method in Gemfile
It would be simpler to do `options[:lockfile] ||= ENV["BUNDLE_LOCKFILE"]`,
but that doesn't work as `options` is frozen.
Fixes https://github.com/ruby/rubygems/pull/9117
https://github.com/ruby/rubygems/commit/6e3603a0e9
| -rw-r--r-- | lib/bundler/cli.rb | 6 | ||||
| -rw-r--r-- | lib/bundler/man/gemfile.5 | 4 | ||||
| -rw-r--r-- | lib/bundler/man/gemfile.5.ronn | 2 | ||||
| -rw-r--r-- | spec/bundler/commands/install_spec.rb | 14 |
4 files changed, 21 insertions, 5 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 9c29751a7c..36ce04eb2a 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -69,7 +69,7 @@ module Bundler # lock --lockfile works differently than install --lockfile unless current_cmd == "lock" - custom_lockfile = options[:lockfile] || Bundler.settings[:lockfile] + custom_lockfile = options[:lockfile] || ENV["BUNDLE_LOCKFILE"] || Bundler.settings[:lockfile] if custom_lockfile && !custom_lockfile.empty? Bundler::SharedHelpers.set_env "BUNDLE_LOCKFILE", File.expand_path(custom_lockfile) reset_settings = true @@ -282,8 +282,10 @@ module Bundler end require_relative "cli/install" + options = self.options.dup + options["lockfile"] ||= ENV["BUNDLE_LOCKFILE"] Bundler.settings.temporary(no_install: false) do - Install.new(options.dup).run + Install.new(options).run end end diff --git a/lib/bundler/man/gemfile.5 b/lib/bundler/man/gemfile.5 index fce7d8e178..a8c055a0c1 100644 --- a/lib/bundler/man/gemfile.5 +++ b/lib/bundler/man/gemfile.5 @@ -494,9 +494,9 @@ The \fBbundle install\fR \fB\-\-no\-lock\fR option (which disables lockfile crea .IP "2." 4 The \fBbundle install\fR \fB\-\-lockfile\fR option\. .IP "3." 4 -The \fBlockfile\fR method in the Gemfile\. -.IP "4." 4 The \fBBUNDLE_LOCKFILE\fR environment variable\. +.IP "4." 4 +The \fBlockfile\fR method in the Gemfile\. .IP "5." 4 The default behavior of adding \fB\.lock\fR to the end of the Gemfile name\. .IP "" 0 diff --git a/lib/bundler/man/gemfile.5.ronn b/lib/bundler/man/gemfile.5.ronn index e4bc91359e..18d7bb826e 100644 --- a/lib/bundler/man/gemfile.5.ronn +++ b/lib/bundler/man/gemfile.5.ronn @@ -581,6 +581,6 @@ following precedence is used: 1. The `bundle install` `--no-lock` option (which disables lockfile creation). 1. The `bundle install` `--lockfile` option. -1. The `lockfile` method in the Gemfile. 1. The `BUNDLE_LOCKFILE` environment variable. +1. The `lockfile` method in the Gemfile. 1. The default behavior of adding `.lock` to the end of the Gemfile name. diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb index bacd8d64f2..3dc8aa0dc0 100644 --- a/spec/bundler/commands/install_spec.rb +++ b/spec/bundler/commands/install_spec.rb @@ -41,6 +41,20 @@ RSpec.describe "bundle install with gem sources" do expect(bundled_app("OmgFile.lock")).to exist end + it "creates lockfile using BUNDLE_LOCKFILE instead of lockfile method" do + ENV["BUNDLE_LOCKFILE"] = "ReallyOmgFile.lock" + install_gemfile <<-G + lockfile "OmgFile.lock" + source "https://gem.repo1" + gem "myrack", "1.0" + G + + expect(bundled_app("ReallyOmgFile.lock")).to exist + expect(bundled_app("OmgFile.lock")).not_to exist + ensure + ENV.delete("BUNDLE_LOCKFILE") + end + it "creates lockfile based on --lockfile option is given" do gemfile bundled_app("OmgFile"), <<-G source "https://gem.repo1" |
