Skip to content

Commit

Permalink
fix syncing of bundler version
Browse files Browse the repository at this point in the history
  • Loading branch information
ccutrer committed Sep 28, 2023
1 parent 6b4ae27 commit c60670f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bundler-multilock (1.0.10)
bundler-multilock (1.0.11)
bundler (~> 2.4.19)

GEM
Expand Down
14 changes: 9 additions & 5 deletions lib/bundler/multilock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -385,15 +389,15 @@ 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

current_lockfile = lockfile_definition[:lockfile]
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?
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/multilock/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Bundler
module Multilock
VERSION = "1.0.10"
VERSION = "1.0.11"
end
end
25 changes: 25 additions & 0 deletions spec/bundler/multilock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit c60670f

Please sign in to comment.