Skip to content

Commit 29d3ea1

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[rubygems/rubygems] Fix bundle lock --add-checksums when gems are already installed
rubygems/rubygems@a087c452ad
1 parent a6fd6cb commit 29d3ea1

File tree

2 files changed

+93
-23
lines changed

2 files changed

+93
-23
lines changed

lib/bundler/definition.rb

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ def check!
186186
def setup_domain!(options = {})
187187
prefer_local! if options[:"prefer-local"]
188188

189-
if options[:local] || no_install_needed?
190-
Bundler.settings.set_command_option(:jobs, 1) if no_install_needed? # to avoid the overhead of Bundler::Worker
191-
with_cache!
192-
false
193-
else
189+
if options[:add_checksums] || (!options[:local] && install_needed?)
194190
remotely!
195191
true
192+
else
193+
Bundler.settings.set_command_option(:jobs, 1) unless install_needed? # to avoid the overhead of Bundler::Worker
194+
with_cache!
195+
false
196196
end
197197
end
198198

@@ -513,26 +513,11 @@ def remove_platform(platform)
513513
end
514514

515515
def nothing_changed?
516-
return false unless lockfile_exists?
517-
518-
!@source_changes &&
519-
!@dependency_changes &&
520-
!@current_platform_missing &&
521-
@new_platforms.empty? &&
522-
!@path_changes &&
523-
!@local_changes &&
524-
!@missing_lockfile_dep &&
525-
!@unlocking_bundler &&
526-
!@locked_spec_with_missing_deps &&
527-
!@locked_spec_with_invalid_deps
528-
end
529-
530-
def no_install_needed?
531-
no_resolve_needed? && !missing_specs?
516+
!something_changed?
532517
end
533518

534519
def no_resolve_needed?
535-
!unlocking? && nothing_changed?
520+
!resolve_needed?
536521
end
537522

538523
def unlocking?
@@ -544,13 +529,36 @@ def unlocking?
544529
def add_checksums
545530
@locked_checksums = true
546531

547-
setup_domain!
532+
setup_domain!(add_checksums: true)
548533

549534
specs # force materialization to real specifications, so that checksums are fetched
550535
end
551536

552537
private
553538

539+
def install_needed?
540+
resolve_needed? || missing_specs?
541+
end
542+
543+
def something_changed?
544+
return true unless lockfile_exists?
545+
546+
@source_changes ||
547+
@dependency_changes ||
548+
@current_platform_missing ||
549+
@new_platforms.any? ||
550+
@path_changes ||
551+
@local_changes ||
552+
@missing_lockfile_dep ||
553+
@unlocking_bundler ||
554+
@locked_spec_with_missing_deps ||
555+
@locked_spec_with_invalid_deps
556+
end
557+
558+
def resolve_needed?
559+
unlocking? || something_changed?
560+
end
561+
554562
def should_add_extra_platforms?
555563
!lockfile_exists? && generic_local_platform_is_ruby? && !Bundler.settings[:force_ruby_platform]
556564
end

spec/bundler/commands/lock_spec.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,68 @@
18941894
L
18951895
end
18961896

1897+
it "adds checksums to an existing lockfile, when gems are already installed" do
1898+
build_repo4 do
1899+
build_gem "nokogiri", "1.14.2"
1900+
build_gem "nokogiri", "1.14.2" do |s|
1901+
s.platform = "x86_64-linux"
1902+
end
1903+
end
1904+
1905+
gemfile <<-G
1906+
source "https://gem.repo4"
1907+
1908+
gem "nokogiri"
1909+
G
1910+
1911+
lockfile <<~L
1912+
GEM
1913+
remote: https://gem.repo4/
1914+
specs:
1915+
nokogiri (1.14.2)
1916+
nokogiri (1.14.2-x86_64-linux)
1917+
1918+
PLATFORMS
1919+
ruby
1920+
x86_64-linux
1921+
1922+
DEPENDENCIES
1923+
nokogiri
1924+
1925+
BUNDLED WITH
1926+
#{Bundler::VERSION}
1927+
L
1928+
1929+
simulate_platform "x86_64-linux" do
1930+
bundle "install"
1931+
1932+
bundle "lock --add-checksums"
1933+
end
1934+
1935+
checksums = checksums_section do |c|
1936+
c.checksum gem_repo4, "nokogiri", "1.14.2"
1937+
c.checksum gem_repo4, "nokogiri", "1.14.2", "x86_64-linux"
1938+
end
1939+
1940+
expect(lockfile).to eq <<~L
1941+
GEM
1942+
remote: https://gem.repo4/
1943+
specs:
1944+
nokogiri (1.14.2)
1945+
nokogiri (1.14.2-x86_64-linux)
1946+
1947+
PLATFORMS
1948+
ruby
1949+
x86_64-linux
1950+
1951+
DEPENDENCIES
1952+
nokogiri
1953+
#{checksums}
1954+
BUNDLED WITH
1955+
#{Bundler::VERSION}
1956+
L
1957+
end
1958+
18971959
it "generates checksums by default if configured to do so" do
18981960
build_repo4 do
18991961
build_gem "nokogiri", "1.14.2"

0 commit comments

Comments
 (0)