Skip to content

Commit f7b334e

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[rubygems/rubygems] Add bundle lock --add-checksums to add checksums to an existing lockfile
ruby/rubygems@0a9c1ce60d
1 parent 1f62a98 commit f7b334e

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

lib/bundler/cli.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ def inject(name, version)
604604
method_option "gemfile", type: :string, banner: "Use the specified gemfile instead of Gemfile"
605605
method_option "lockfile", type: :string, default: nil, banner: "the path the lockfile should be written to"
606606
method_option "full-index", type: :boolean, default: false, banner: "Fall back to using the single-file index of all gems"
607+
method_option "add-checksums", type: :boolean, default: false, banner: "Adds checksums to the lockfile"
607608
method_option "add-platform", type: :array, default: [], banner: "Add a new platform to the lockfile"
608609
method_option "remove-platform", type: :array, default: [], banner: "Remove a platform from the lockfile"
609610
method_option "normalize-platforms", type: :boolean, default: false, banner: "Normalize lockfile platforms"

lib/bundler/cli/lock.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def run
4040

4141
Bundler.settings.temporary(frozen: false) do
4242
definition = Bundler.definition(update, file)
43+
definition.locked_checksums = true if options["add-checksums"]
4344

4445
Bundler::CLI::Common.configure_gem_version_promoter(definition, options) if options[:update]
4546

lib/bundler/definition.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ class << self
1919
:ruby_version,
2020
:lockfile,
2121
:gemfiles,
22-
:locked_checksums,
2322
:sources
2423
)
2524

25+
attr_accessor :locked_checksums
26+
2627
# Given a gemfile and lockfile creates a Bundler definition
2728
#
2829
# @param gemfile [Pathname] Path to Gemfile

spec/bundler/commands/lock_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,66 @@
17721772
expect(err).not_to include("ERROR REPORT TEMPLATE")
17731773
end
17741774

1775+
it "adds checksums to an existing lockfile" do
1776+
build_repo4 do
1777+
build_gem "nokogiri", "1.14.2"
1778+
build_gem "nokogiri", "1.14.2" do |s|
1779+
s.platform = "x86_64-linux"
1780+
end
1781+
end
1782+
1783+
gemfile <<-G
1784+
source "https://gem.repo4"
1785+
1786+
gem "nokogiri"
1787+
G
1788+
1789+
lockfile <<~L
1790+
GEM
1791+
remote: https://gem.repo4/
1792+
specs:
1793+
nokogiri (1.14.2)
1794+
nokogiri (1.14.2-x86_64-linux)
1795+
1796+
PLATFORMS
1797+
ruby
1798+
x86_64-linux
1799+
1800+
DEPENDENCIES
1801+
nogokiri
1802+
1803+
BUNDLED WITH
1804+
#{Bundler::VERSION}
1805+
L
1806+
1807+
simulate_platform "x86_64-linux" do
1808+
bundle "lock --add-checksums"
1809+
end
1810+
1811+
checksums = checksums_section do |c|
1812+
c.checksum gem_repo4, "nokogiri", "1.14.2"
1813+
c.checksum gem_repo4, "nokogiri", "1.14.2", "x86_64-linux"
1814+
end
1815+
1816+
expect(lockfile).to eq <<~L
1817+
GEM
1818+
remote: https://gem.repo4/
1819+
specs:
1820+
nokogiri (1.14.2)
1821+
nokogiri (1.14.2-x86_64-linux)
1822+
1823+
PLATFORMS
1824+
ruby
1825+
x86_64-linux
1826+
1827+
DEPENDENCIES
1828+
nokogiri
1829+
#{checksums}
1830+
BUNDLED WITH
1831+
#{Bundler::VERSION}
1832+
L
1833+
end
1834+
17751835
context "when re-resolving to include prereleases" do
17761836
before do
17771837
build_repo4 do

0 commit comments

Comments
 (0)