From c60670f86f90bae90564b21b67bf85a510c4c494 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 28 Sep 2023 12:52:25 -0600 Subject: [PATCH] fix syncing of bundler version --- Gemfile.lock | 2 +- lib/bundler/multilock.rb | 14 +++++++++----- lib/bundler/multilock/version.rb | 2 +- spec/bundler/multilock_spec.rb | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index d5fad51..47c51d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - bundler-multilock (1.0.10) + bundler-multilock (1.0.11) bundler (~> 2.4.19) GEM diff --git a/lib/bundler/multilock.rb b/lib/bundler/multilock.rb index bb3671e..b20007e 100644 --- a/lib/bundler/multilock.rb +++ b/lib/bundler/multilock.rb @@ -243,7 +243,10 @@ def after_install_all(install: true) end end lockfile.instance_variable_set(:@ruby_version, default_lockfile.ruby_version) - lockfile.instance_variable_set(:@bundler_version, default_lockfile.bundler_version) + unless lockfile.bundler_version == default_lockfile.bundler_version + unlocking_bundler = true + lockfile.instance_variable_set(:@bundler_version, default_lockfile.bundler_version) + end new_contents = LockfileGenerator.generate(lockfile) else @@ -261,7 +264,8 @@ def after_install_all(install: true) had_changes = write_lockfile(lockfile_definition, temp_lockfile.path, install: install, - dependency_changes: dependency_changes) + dependency_changes: dependency_changes, + unlocking_bundler: unlocking_bundler) end # if we had changes, bundler may have updated some common @@ -375,7 +379,7 @@ def inject_specific_preamble(gemfile, gemfiles, injection_point, preamble, add_n true end - def write_lockfile(lockfile_definition, lockfile, install:, dependency_changes: false) + def write_lockfile(lockfile_definition, lockfile, install:, dependency_changes: false, unlocking_bundler: false) prepare_block = lockfile_definition[:prepare] gemfile = lockfile_definition[:gemfile] @@ -385,7 +389,7 @@ def write_lockfile(lockfile_definition, lockfile, install:, dependency_changes: builder.eval_gemfile(gemfile, &prepare_block) if prepare_block builder.eval_gemfile(gemfile) - definition = builder.to_definition(lockfile, {}) + definition = builder.to_definition(lockfile, { bundler: unlocking_bundler }) definition.instance_variable_set(:@dependency_changes, dependency_changes) if dependency_changes orig_definition = definition.dup # we might need it twice @@ -393,7 +397,7 @@ def write_lockfile(lockfile_definition, lockfile, install:, dependency_changes: if current_lockfile.exist? definition.instance_variable_set(:@lockfile_contents, current_lockfile.read) if install - current_definition = builder.to_definition(current_lockfile, {}) + current_definition = builder.to_definition(current_lockfile, { bundler: unlocking_bundler }) begin current_definition.resolve_with_cache! if current_definition.missing_specs.any? diff --git a/lib/bundler/multilock/version.rb b/lib/bundler/multilock/version.rb index 864bd68..20ad538 100644 --- a/lib/bundler/multilock/version.rb +++ b/lib/bundler/multilock/version.rb @@ -2,6 +2,6 @@ module Bundler module Multilock - VERSION = "1.0.10" + VERSION = "1.0.11" end end diff --git a/spec/bundler/multilock_spec.rb b/spec/bundler/multilock_spec.rb index 452caaa..c26219c 100644 --- a/spec/bundler/multilock_spec.rb +++ b/spec/bundler/multilock_spec.rb @@ -592,6 +592,25 @@ end end + it "updates bundler version in secondary lockfiles" do + with_gemfile(<<~RUBY) do + gem "rake" + + lockfile("alt1") do + gem "concurrent-ruby", "1.2.1" + end + RUBY + invoke_bundler("install") + + update_lockfile_bundler("Gemfile.alt1.lock", "2.4.18") + + invoke_bundler("install") + + expect(File.read("Gemfile.alt1.lock")).not_to include("2.4.18") + expect(File.read("Gemfile.alt1.lock")).to include(Bundler::VERSION) + end + end + private def create_local_gem(name, content) @@ -680,4 +699,10 @@ def replace_lockfile_pin(lockfile, gem, version) File.write(lockfile, new_contents) end + + def update_lockfile_bundler(lockfile, version) + new_contents = File.read(lockfile).gsub(/BUNDLED WITH\n [0-9.]+/, "BUNDLED WITH\n #{version}") + + File.write(lockfile, new_contents) + end end