Skip to content

Commit 14ebde1

Browse files
authored
Merge pull request #9146 from jeremyevans/lockfile-precedence-9117
Make BUNDLE_LOCKFILE environment variable have precedence over lockfile method in Gemfile
2 parents b365a65 + 6e3603a commit 14ebde1

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

bundler/lib/bundler/cli.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def initialize(*args)
6969

7070
# lock --lockfile works differently than install --lockfile
7171
unless current_cmd == "lock"
72-
custom_lockfile = options[:lockfile] || Bundler.settings[:lockfile]
72+
custom_lockfile = options[:lockfile] || ENV["BUNDLE_LOCKFILE"] || Bundler.settings[:lockfile]
7373
if custom_lockfile && !custom_lockfile.empty?
7474
Bundler::SharedHelpers.set_env "BUNDLE_LOCKFILE", File.expand_path(custom_lockfile)
7575
reset_settings = true
@@ -282,8 +282,10 @@ def install
282282
end
283283

284284
require_relative "cli/install"
285+
options = self.options.dup
286+
options["lockfile"] ||= ENV["BUNDLE_LOCKFILE"]
285287
Bundler.settings.temporary(no_install: false) do
286-
Install.new(options.dup).run
288+
Install.new(options).run
287289
end
288290
end
289291

bundler/lib/bundler/man/gemfile.5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,9 @@ The \fBbundle install\fR \fB\-\-no\-lock\fR option (which disables lockfile crea
494494
.IP "2." 4
495495
The \fBbundle install\fR \fB\-\-lockfile\fR option\.
496496
.IP "3." 4
497-
The \fBlockfile\fR method in the Gemfile\.
498-
.IP "4." 4
499497
The \fBBUNDLE_LOCKFILE\fR environment variable\.
498+
.IP "4." 4
499+
The \fBlockfile\fR method in the Gemfile\.
500500
.IP "5." 4
501501
The default behavior of adding \fB\.lock\fR to the end of the Gemfile name\.
502502
.IP "" 0

bundler/lib/bundler/man/gemfile.5.ronn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,6 @@ following precedence is used:
581581

582582
1. The `bundle install` `--no-lock` option (which disables lockfile creation).
583583
1. The `bundle install` `--lockfile` option.
584-
1. The `lockfile` method in the Gemfile.
585584
1. The `BUNDLE_LOCKFILE` environment variable.
585+
1. The `lockfile` method in the Gemfile.
586586
1. The default behavior of adding `.lock` to the end of the Gemfile name.

bundler/spec/commands/install_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@
4141
expect(bundled_app("OmgFile.lock")).to exist
4242
end
4343

44+
it "creates lockfile using BUNDLE_LOCKFILE instead of lockfile method" do
45+
ENV["BUNDLE_LOCKFILE"] = "ReallyOmgFile.lock"
46+
install_gemfile <<-G
47+
lockfile "OmgFile.lock"
48+
source "https://gem.repo1"
49+
gem "myrack", "1.0"
50+
G
51+
52+
expect(bundled_app("ReallyOmgFile.lock")).to exist
53+
expect(bundled_app("OmgFile.lock")).not_to exist
54+
ensure
55+
ENV.delete("BUNDLE_LOCKFILE")
56+
end
57+
4458
it "creates lockfile based on --lockfile option is given" do
4559
gemfile bundled_app("OmgFile"), <<-G
4660
source "https://gem.repo1"

0 commit comments

Comments
 (0)