From f7b334e002eba25e386917337771b65bed5297f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 6 Nov 2024 18:42:40 +0100 Subject: [PATCH] [rubygems/rubygems] Add `bundle lock --add-checksums` to add checksums to an existing lockfile https://github.com/rubygems/rubygems/commit/0a9c1ce60d --- lib/bundler/cli.rb | 1 + lib/bundler/cli/lock.rb | 1 + lib/bundler/definition.rb | 3 +- spec/bundler/commands/lock_spec.rb | 60 ++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index fb6599636b..e309535d90 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -604,6 +604,7 @@ module Bundler method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile" method_option "lockfile", type: :string, default: nil, banner: "the path the lockfile should be written to" method_option "full-index", type: :boolean, default: false, banner: "Fall back to using the single-file index of all gems" + method_option "add-checksums", type: :boolean, default: false, banner: "Adds checksums to the lockfile" method_option "add-platform", type: :array, default: [], banner: "Add a new platform to the lockfile" method_option "remove-platform", type: :array, default: [], banner: "Remove a platform from the lockfile" method_option "normalize-platforms", type: :boolean, default: false, banner: "Normalize lockfile platforms" diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb index d080480e19..17e7521766 100644 --- a/lib/bundler/cli/lock.rb +++ b/lib/bundler/cli/lock.rb @@ -40,6 +40,7 @@ module Bundler Bundler.settings.temporary(frozen: false) do definition = Bundler.definition(update, file) + definition.locked_checksums = true if options["add-checksums"] Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update] diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 84b7236a1f..a1a813b375 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -19,10 +19,11 @@ module Bundler :ruby_version, :lockfile, :gemfiles, - :locked_checksums, :sources ) + attr_accessor :locked_checksums + # Given a gemfile and lockfile creates a Bundler definition # # @param gemfile [Pathname] Path to Gemfile diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb index 5e2a6e7e8f..816fadf707 100644 --- a/spec/bundler/commands/lock_spec.rb +++ b/spec/bundler/commands/lock_spec.rb @@ -1772,6 +1772,66 @@ RSpec.describe "bundle lock" do expect(err).not_to include("ERROR REPORT TEMPLATE") end + it "adds checksums to an existing lockfile" 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 + nogokiri + + BUNDLED WITH + #{Bundler::VERSION} + L + + simulate_platform "x86_64-linux" do + 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 + context "when re-resolving to include prereleases" do before do build_repo4 do