Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/bootboot/bundler_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ def initialize(wrong_lock, *args)
end
end

module DefinitionUnlockPatch
def initialize(lockfile, dependencies, sources, unlock, *args)
@bootboot_unlock = unlock.is_a?(Hash) ? unlock.transform_values { |v| v.dup.freeze }.freeze : unlock
super
end

def bootboot_unlock
@bootboot_unlock.is_a?(Hash) ? @bootboot_unlock.transform_values(&:dup) : @bootboot_unlock
end
end

module RubyVersionPatch
def system
# Only monkey-patch if we're updating the alternate file
Expand Down Expand Up @@ -48,6 +59,7 @@ def default_lockfile
end

Bundler::Definition.prepend(DefinitionSourceRequirementsPatch)
Bundler::Definition.prepend(DefinitionUnlockPatch)
Bundler::RubyVersion.singleton_class.prepend(RubyVersionPatch)

Bundler::Dsl.class_eval do
Expand Down
3 changes: 1 addition & 2 deletions lib/bootboot/gemfile_next_auto_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def update!(current_definition)
ENV[env] = "1"
ENV["BOOTBOOT_UPDATING_ALTERNATE_LOCKFILE"] = "1"

unlock = current_definition.instance_variable_get(:@unlock)
definition = Bundler::Definition.build(GEMFILE, lock, unlock)
definition = Bundler::Definition.build(GEMFILE, lock, current_definition.bootboot_unlock)
definition.resolve_remotely!
definition.lock(lock)
ensure
Expand Down
39 changes: 39 additions & 0 deletions test/bootboot_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,41 @@ def test_sync_the_gemfile_next_after_update_of_gem
end
end

def test_sync_the_gemfile_next_after_update_of_gem_without_gemfile_change
write_gemfile do |file, _dir|
FileUtils.cp("#{file.path}.lock", gemfile_next(file))
File.write(file, 'gem "rake", "10.5.0"', mode: "a")
run_bundle_command("install", file.path)
File.write(file, file.read.gsub(', "10.5.0"', ""))
run_bundle_command("install", file.path)

assert_equal("10.5.0", locked_version("rake", "#{file.path}.lock"))
assert_equal("10.5.0", locked_version("rake", gemfile_next(file)))

run_bundle_command("update rake", file.path)

refute_equal("10.5.0", locked_version("rake", "#{file.path}.lock"))
assert_equal(locked_version("rake", "#{file.path}.lock"), locked_version("rake", gemfile_next(file)))
end
end

def test_sync_the_gemfile_next_after_update_of_all_gems
write_gemfile do |file, _dir|
FileUtils.cp("#{file.path}.lock", gemfile_next(file))
File.write(file, 'gem "rake", "10.5.0"', mode: "a")
run_bundle_command("install", file.path)
File.write(file, file.read.gsub(', "10.5.0"', ""))
run_bundle_command("install", file.path)

assert_equal("10.5.0", locked_version("rake", gemfile_next(file)))

run_bundle_command("update --all", file.path)

refute_equal("10.5.0", locked_version("rake", "#{file.path}.lock"))
assert_equal(locked_version("rake", "#{file.path}.lock"), locked_version("rake", gemfile_next(file)))
end
end

def test_sync_the_gemfile_next_when_gemfile_contain_if_else_statement
write_gemfile do |file, _dir|
FileUtils.cp("#{file.path}.lock", gemfile_next(file))
Expand Down Expand Up @@ -311,6 +346,10 @@ def gemfile_next(gemfile)
"#{gemfile.path}_next.lock"
end

def locked_version(gem_name, lockfile)
Bundler::LockfileParser.new(File.read(lockfile)).specs.find { |spec| spec.name == gem_name }.version.to_s
end

def write_gemfile(content = nil)
dir = Dir.mktmpdir
file = Tempfile.new("Gemfile", dir).tap do |f|
Expand Down
Loading