summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-04-07 07:07:43 +0000
committerColby Swandale <me@colby.fyi>2018-04-20 10:28:36 +1000
commit04820bd77bb55ddf78f64608749b197f72aa0471 (patch)
tree5c32f7373e3a799ea55e5b938ff2644952e0cac4
parent5590e9bd81488fe3e33bd753dff8c53178fae17e (diff)
downloadbundler-04820bd77bb55ddf78f64608749b197f72aa0471.tar.gz
Auto merge of #6474 - agrim123:agr-bundle-lock-fix, r=segiddins
Fix bundle lock when default gemfile is present Thanks so much for the contribution! To make reviewing this PR a bit easier, please fill out answers to the following questions. ### What was the end-user problem that led to this PR? The problem was on running `bundle lock --lockfile=AlternativeGemfile.lock` if a default lockfile already exists then `AlternativeGemfile.lock` is not created. ### What was your diagnosis of the problem? My diagnosis was that the [lock](https://github.com/bundler/bundler/blob/master/lib/bundler/definition.rb#L340) function does not check the file but for contents, so a new file is not created in case of an existing lockfile. ### What is your fix for the problem, implemented in this PR? My fix was to check for the file existence. Closes #6460 (cherry picked from commit cecdfdb5b2a76133b0a83093ff6d80d1ffd97b46)
-rw-r--r--lib/bundler/definition.rb3
-rw-r--r--spec/commands/lock_spec.rb8
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 84c0682f61..0a02547f0d 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -338,7 +338,8 @@ module Bundler
end
preserve_unknown_sections ||= !updating_major && (Bundler.frozen_bundle? || !(unlocking? || @unlocking_bundler))
- return if lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections)
+
+ return if file && File.exist?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections)
if Bundler.frozen_bundle?
Bundler.ui.error "Cannot write a changed lockfile while frozen."
diff --git a/spec/commands/lock_spec.rb b/spec/commands/lock_spec.rb
index 01337d27ce..b31d54c962 100644
--- a/spec/commands/lock_spec.rb
+++ b/spec/commands/lock_spec.rb
@@ -97,6 +97,14 @@ RSpec.describe "bundle lock" do
expect { read_lockfile }.to raise_error(Errno::ENOENT)
end
+ it "writes to custom location using --lockfile when a default lockfile is present" do
+ bundle "install"
+ bundle "lock --lockfile=lock"
+
+ expect(out).to match(/Writing lockfile to.+lock/)
+ expect(read_lockfile("lock")).to eq(@lockfile)
+ end
+
it "update specific gems using --update" do
lockfile @lockfile.gsub("2.3.2", "2.3.1").gsub("10.0.2", "10.0.1")