summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2024-12-13 19:17:40 +0100
committergit <svn-admin@ruby-lang.org>2024-12-16 19:51:16 +0000
commit29d3ea1e84d44335d998cadaf7cf3b45270a962e (patch)
treefac92cfc608aa0353f0f1c75a4a458d27d72b754
parenta6fd6cb72f22531cc3cc976de99c5f9eccbf7101 (diff)
[rubygems/rubygems] Fix `bundle lock --add-checksums` when gems are already installed
https://github.com/rubygems/rubygems/commit/a087c452ad
-rw-r--r--lib/bundler/definition.rb54
-rw-r--r--spec/bundler/commands/lock_spec.rb62
2 files changed, 93 insertions, 23 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 76397c4045..85951f9314 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -186,13 +186,13 @@ module Bundler
def setup_domain!(options = {})
prefer_local! if options[:"prefer-local"]
- if options[:local] || no_install_needed?
- Bundler.settings.set_command_option(:jobs, 1) if no_install_needed? # to avoid the overhead of Bundler::Worker
- with_cache!
- false
- else
+ if options[:add_checksums] || (!options[:local] && install_needed?)
remotely!
true
+ else
+ Bundler.settings.set_command_option(:jobs, 1) unless install_needed? # to avoid the overhead of Bundler::Worker
+ with_cache!
+ false
end
end
@@ -513,26 +513,11 @@ module Bundler
end
def nothing_changed?
- return false unless lockfile_exists?
-
- !@source_changes &&
- !@dependency_changes &&
- !@current_platform_missing &&
- @new_platforms.empty? &&
- !@path_changes &&
- !@local_changes &&
- !@missing_lockfile_dep &&
- !@unlocking_bundler &&
- !@locked_spec_with_missing_deps &&
- !@locked_spec_with_invalid_deps
- end
-
- def no_install_needed?
- no_resolve_needed? && !missing_specs?
+ !something_changed?
end
def no_resolve_needed?
- !unlocking? && nothing_changed?
+ !resolve_needed?
end
def unlocking?
@@ -544,13 +529,36 @@ module Bundler
def add_checksums
@locked_checksums = true
- setup_domain!
+ setup_domain!(add_checksums: true)
specs # force materialization to real specifications, so that checksums are fetched
end
private
+ def install_needed?
+ resolve_needed? || missing_specs?
+ end
+
+ def something_changed?
+ return true unless lockfile_exists?
+
+ @source_changes ||
+ @dependency_changes ||
+ @current_platform_missing ||
+ @new_platforms.any? ||
+ @path_changes ||
+ @local_changes ||
+ @missing_lockfile_dep ||
+ @unlocking_bundler ||
+ @locked_spec_with_missing_deps ||
+ @locked_spec_with_invalid_deps
+ end
+
+ def resolve_needed?
+ unlocking? || something_changed?
+ end
+
def should_add_extra_platforms?
!lockfile_exists? && generic_local_platform_is_ruby? && !Bundler.settings[:force_ruby_platform]
end
diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb
index 7044cd3175..db600e356f 100644
--- a/spec/bundler/commands/lock_spec.rb
+++ b/spec/bundler/commands/lock_spec.rb
@@ -1894,6 +1894,68 @@ RSpec.describe "bundle lock" do
L
end
+ it "adds checksums to an existing lockfile, when gems are already installed" do
+ build_repo4 do
+ build_gem "nokogiri", "1.14.2"
+ build_gem "nokogiri", "1.14.2" do |s|
+ s.platform = "x86_64-linux"
+ end
+ end
+
+ gemfile <<-G
+ source "https://gem.repo4"
+
+ gem "nokogiri"
+ G
+
+ lockfile <<~L
+ GEM
+ remote: https://gem.repo4/
+ specs:
+ nokogiri (1.14.2)
+ nokogiri (1.14.2-x86_64-linux)
+
+ PLATFORMS
+ ruby
+ x86_64-linux
+
+ DEPENDENCIES
+ nokogiri
+
+ BUNDLED WITH
+ #{Bundler::VERSION}
+ L
+
+ simulate_platform "x86_64-linux" do
+ bundle "install"
+
+ bundle "lock --add-checksums"
+ end
+
+ checksums = checksums_section do |c|
+ c.checksum gem_repo4, "nokogiri", "1.14.2"
+ c.checksum gem_repo4, "nokogiri", "1.14.2", "x86_64-linux"
+ end
+
+ expect(lockfile).to eq <<~L
+ GEM
+ remote: https://gem.repo4/
+ specs:
+ nokogiri (1.14.2)
+ nokogiri (1.14.2-x86_64-linux)
+
+ PLATFORMS
+ ruby
+ x86_64-linux
+
+ DEPENDENCIES
+ nokogiri
+ #{checksums}
+ BUNDLED WITH
+ #{Bundler::VERSION}
+ L
+ end
+
it "generates checksums by default if configured to do so" do
build_repo4 do
build_gem "nokogiri", "1.14.2"