Skip to content

Commit 18ac3ce

Browse files
committed
Fix bundle lock regression when using update and lockfile flags:
- Ref #8917 - ### Problem Prior to Bundler 2.5.6, running `bundle lock --update foo --lockfile Gemfile_bumped.lock` would update only the foo gem and write the lockfile to the `Gemfile_bumped.lock`. In Bundler 2.5.6 and above running the same command, updates absolutely all gems. This change is related to #7047 ### Solution Build the definition using the existing lockfile, not the one passed in the `--lockfile` as it may not exist. Dump the definition into a new lockfile.
1 parent aab490f commit 18ac3ce

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

bundler/lib/bundler/cli/lock.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ def run
3535
update = { bundler: bundler }
3636
end
3737

38-
file = options[:lockfile]
39-
file = file ? Pathname.new(file).expand_path : Bundler.default_lockfile
40-
4138
Bundler.settings.temporary(frozen: false) do
42-
definition = Bundler.definition(update, file)
39+
definition = Bundler.definition(update, Bundler.default_lockfile)
4340
definition.add_checksums if options["add-checksums"]
4441

4542
Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update]
@@ -71,8 +68,11 @@ def run
7168
if print
7269
puts definition.to_lock
7370
else
71+
file = options[:lockfile]
72+
file = file ? Pathname.new(file).expand_path : Bundler.default_lockfile
73+
7474
puts "Writing lockfile to #{file}"
75-
definition.lock
75+
definition.lock(false, file)
7676
end
7777
end
7878

bundler/spec/commands/lock_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,44 @@
311311
expect { read_lockfile }.to raise_error(Errno::ENOENT)
312312
end
313313

314+
it "updates a specific gem and write to a custom location" do
315+
build_repo4 do
316+
build_gem "uri", %w[1.0.2 1.0.3]
317+
build_gem "warning", %w[1.4.0 1.5.0]
318+
end
319+
320+
gemfile <<~G
321+
source "https://gem.repo4"
322+
323+
gem "uri"
324+
gem "warning"
325+
G
326+
327+
lockfile <<~L
328+
GEM
329+
remote: https://gem.repo4
330+
specs:
331+
uri (1.0.2)
332+
warning (1.4.0)
333+
334+
PLATFORMS
335+
#{lockfile_platforms}
336+
337+
DEPENDENCIES
338+
uri
339+
warning
340+
341+
BUNDLED WITH
342+
#{Bundler::VERSION}
343+
L
344+
345+
bundle "lock --update uri --lockfile=lock"
346+
347+
lockfile_content = read_lockfile("lock")
348+
expect(lockfile_content).to include("uri (1.0.3)")
349+
expect(lockfile_content).to include("warning (1.4.0)")
350+
end
351+
314352
it "writes to custom location using --lockfile when a default lockfile is present" do
315353
gemfile_with_rails_weakling_and_foo_from_repo4
316354

0 commit comments

Comments
 (0)