Skip to content

Commit 9a10026

Browse files
authored
Merge pull request #9862 from ruby/skip-local-resolve-for-empty-checksums
Stop resolving locally for empty CHECKSUMS entries
2 parents f5b9b02 + d6213f8 commit 9a10026

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

lib/bundler/definition.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def setup_domain!(options = {})
198198

199199
sources.cached!
200200

201-
if options[:add_checksums] || (!options[:local] && (install_needed? || refetch_needed?(options)))
201+
if options[:add_checksums] || (!options[:local] && (install_needed? || refetch_needed?(options) || @locked_spec_with_empty_checksums))
202202
sources.remote!
203203
true
204204
else
@@ -650,7 +650,7 @@ def something_changed?
650650
@missing_lockfile_dep ||
651651
@unlocking_bundler ||
652652
@locked_spec_with_missing_checksums ||
653-
@locked_spec_with_empty_checksums ||
653+
empty_checksums_actionable? ||
654654
@locked_spec_with_missing_deps ||
655655
@locked_spec_with_invalid_deps
656656
end
@@ -659,6 +659,16 @@ def resolve_needed?
659659
unlocking? || something_changed?
660660
end
661661

662+
# Only a remote fetch can fill an empty CHECKSUMS entry, so it justifies a
663+
# resolution only when one is coming. Resolving locally for it would repeat
664+
# on every `Bundler.setup` without changing the lockfile. Frozen mode still
665+
# has to refuse the entry.
666+
def empty_checksums_actionable?
667+
return false unless @locked_spec_with_empty_checksums
668+
669+
Bundler.frozen_bundle? || !sources.local_mode?
670+
end
671+
662672
def should_add_extra_platforms?
663673
!lockfile_exists? && Bundler::MatchPlatform.generic_local_platform_is_ruby? && !Bundler.settings[:force_ruby_platform]
664674
end

spec/lock/lockfile_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,36 @@
16821682
expect(the_bundle).not_to include_gems "myrack 0.9.1"
16831683
end
16841684

1685+
it "fills empty CHECKSUMS entries when not frozen, even if every gem is already installed" do
1686+
system_gems "myrack-0.9.1", gem_repo: gem_repo2
1687+
1688+
lockfile <<-L
1689+
GEM
1690+
remote: https://gem.repo2/
1691+
specs:
1692+
myrack (0.9.1)
1693+
1694+
PLATFORMS
1695+
#{lockfile_platforms}
1696+
1697+
DEPENDENCIES
1698+
myrack
1699+
1700+
CHECKSUMS
1701+
myrack (0.9.1)
1702+
1703+
BUNDLED WITH
1704+
#{Bundler::VERSION}
1705+
L
1706+
1707+
install_gemfile <<-G
1708+
source "https://gem.repo2"
1709+
gem "myrack"
1710+
G
1711+
1712+
expect(lockfile).to include(" #{checksum_to_lock(gem_repo2, "myrack", "0.9.1")}\n")
1713+
end
1714+
16851715
it "automatically fixes the lockfile when it's missing deps, they conflict with other locked deps, but conflicts are fixable" do
16861716
build_repo4 do
16871717
build_gem "other_dep", "0.9"

spec/runtime/setup_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,24 @@ def clean_load_path(lp)
259259
expect(bundled_app_lock).to exist
260260
end
261261

262+
it "does not resolve again for the empty CHECKSUMS entries it locked itself" do
263+
system_gems "myrack-1.0.0"
264+
265+
gemfile <<-G
266+
source "https://gem.repo1"
267+
gem "myrack"
268+
G
269+
270+
ruby "require 'bundler'; Bundler.setup"
271+
expect(out).to include("Resolving dependencies...")
272+
lockfile = File.read(bundled_app_lock)
273+
expect(lockfile).to include("CHECKSUMS\n myrack (1.0.0)\n")
274+
275+
ruby "require 'bundler'; Bundler.setup"
276+
expect(out).not_to include("Resolving dependencies...")
277+
expect(File.read(bundled_app_lock)).to eq(lockfile)
278+
end
279+
262280
describe "$BUNDLE_GEMFILE" do
263281
context "user provides an absolute path" do
264282
it "uses BUNDLE_GEMFILE to locate the gemfile if present" do

0 commit comments

Comments
 (0)