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