diff options
author | The Bundler Bot <bot@bundler.io> | 2018-04-07 07:07:43 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2018-04-07 07:07:43 +0000 |
commit | cecdfdb5b2a76133b0a83093ff6d80d1ffd97b46 (patch) | |
tree | 955643462ae68e1b21a80a87d8aa9d561743cd4d | |
parent | fb38825ead6603588dae17b34b23f282548ee425 (diff) | |
parent | a3fbedc2d02c8f6b6d7281c7659f28be9d89dfee (diff) | |
download | bundler-cecdfdb5b2a76133b0a83093ff6d80d1ffd97b46.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
-rw-r--r-- | lib/bundler/definition.rb | 3 | ||||
-rw-r--r-- | spec/commands/lock_spec.rb | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 91d34ad150..bec3cadbb4 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -337,7 +337,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 bd5bdfff2f..81eba1ceda 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") |