Skip to content

Commit 0da6796

Browse files
Fix bundle lock --add-checksums
Due to a typo in the spec, the issue was not caught initially. If Bundler does not need to re-resolve, `bundle lock` is a noop so Bundler cannot add checksums. We need to make sure to force a re-resolve when `--add-checksums` flag is given.
1 parent 3680ce4 commit 0da6796

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

bundler/lib/bundler/cli/lock.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def run
2525
update = options[:update]
2626
conservative = options[:conservative]
2727
bundler = options[:bundler]
28+
add_checksums = options["add-checksums"]
2829

2930
if update.is_a?(Array) # unlocking specific gems
3031
Bundler::CLI::Common.ensure_all_gems_in_lockfile!(update)
@@ -33,14 +34,16 @@ def run
3334
update = { conservative: conservative }
3435
elsif update && bundler
3536
update = { bundler: bundler }
37+
elsif add_checksums
38+
update = { checksums: add_checksums }
3639
end
3740

3841
file = options[:lockfile]
3942
file = file ? Pathname.new(file).expand_path : Bundler.default_lockfile
4043

4144
Bundler.settings.temporary(frozen: false) do
4245
definition = Bundler.definition(update, file)
43-
definition.locked_checksums = true if options["add-checksums"]
46+
definition.locked_checksums = true if add_checksums
4447

4548
Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update]
4649

bundler/lib/bundler/definition.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ def self.build(gemfile, lockfile, unlock)
6161
def initialize(lockfile, dependencies, sources, unlock, ruby_version = nil, optional_groups = [], gemfiles = [])
6262
if [true, false].include?(unlock)
6363
@unlocking_bundler = false
64+
@adding_checksums = false
6465
@unlocking = unlock
6566
else
6667
@unlocking_bundler = unlock.delete(:bundler)
68+
@adding_checksums = unlock.delete(:checksums)
6769
@unlocking = unlock.any? {|_k, v| !Array(v).empty? }
6870
end
6971

@@ -499,6 +501,7 @@ def nothing_changed?
499501
!@local_changes &&
500502
!@missing_lockfile_dep &&
501503
!@unlocking_bundler &&
504+
!@adding_checksums &&
502505
!@locked_spec_with_missing_deps &&
503506
!@locked_spec_with_invalid_deps
504507
end
@@ -744,6 +747,7 @@ def change_reason
744747
[@local_changes, "the gemspecs for git local gems changed"],
745748
[@missing_lockfile_dep, "your lock file is missing \"#{@missing_lockfile_dep}\""],
746749
[@unlocking_bundler, "an update to the version of Bundler itself was requested"],
750+
[@adding_checksums, "bundler is adding checksums to the lockfile"],
747751
[@locked_spec_with_missing_deps, "your lock file includes \"#{@locked_spec_with_missing_deps}\" but not some of its dependencies"],
748752
[@locked_spec_with_invalid_deps, "your lockfile does not satisfy dependencies of \"#{@locked_spec_with_invalid_deps}\""],
749753
].select(&:first).map(&:last).join(", ")

bundler/spec/commands/lock_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,16 +1798,18 @@
17981798
x86_64-linux
17991799
18001800
DEPENDENCIES
1801-
nogokiri
1801+
nokogiri
18021802
18031803
BUNDLED WITH
18041804
#{Bundler::VERSION}
18051805
L
18061806

18071807
simulate_platform "x86_64-linux" do
1808-
bundle "lock --add-checksums"
1808+
bundle "lock --add-checksums --verbose"
18091809
end
18101810

1811+
expect(out).to include("bundler is adding checksums to the lockfile")
1812+
18111813
checksums = checksums_section do |c|
18121814
c.checksum gem_repo4, "nokogiri", "1.14.2"
18131815
c.checksum gem_repo4, "nokogiri", "1.14.2", "x86_64-linux"

0 commit comments

Comments
 (0)