From 9e9e2e5a833c9c3e07532f200df2edf86baa2515 Mon Sep 17 00:00:00 2001 From: David Stosik <816901+davidstosik@users.noreply.github.com> Date: Wed, 1 Jul 2026 22:04:55 +0900 Subject: [PATCH] Respect Gemfile lockfile in `bundle lock` Use the lockfile path resolved from the definition when no explicit `--lockfile` option is passed. --- lib/bundler/cli/lock.rb | 2 +- spec/commands/lock_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb index 2f78868936c1..a1359f63715a 100644 --- a/lib/bundler/cli/lock.rb +++ b/lib/bundler/cli/lock.rb @@ -69,7 +69,7 @@ def run puts definition.to_lock else file = options[:lockfile] - file = file ? Pathname.new(file).expand_path : Bundler.default_lockfile + file = file ? Pathname.new(file).expand_path : definition.lockfile puts "Writing lockfile to #{file}" definition.write_lock(file, false) diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb index 4914c11cc3f8..fde728a2675f 100644 --- a/spec/commands/lock_spec.rb +++ b/spec/commands/lock_spec.rb @@ -177,6 +177,23 @@ expect(read_lockfile).to eq(expected_lockfile) end + it "writes the lockfile configured in the Gemfile" do + build_repo4 do + build_gem "foo", "1.0" + end + + gemfile <<-G + source "https://gem.repo4" + gem "foo", "1.0" + lockfile "custom.lock" + G + + bundle "lock" + + expect(bundled_app("Gemfile.lock")).not_to exist + expect(bundled_app("custom.lock")).to exist + end + it "prints a lockfile without fetching new checksums if the existing lockfile had no checksums" do gemfile_with_rails_weakling_and_foo_from_repo4