Skip to content

Commit 0def57b

Browse files
committed
fix syncing of changed git sources
1 parent 29a5dbe commit 0def57b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/bundler/multilock.rb

+11-3
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ def after_install_all(install: true)
260260
spec_precedences[spec.name] = precedence || :parent
261261
end
262262

263+
lockfile.sources.map! do |source|
264+
parent_lockfile.sources.find { |s| s == source } || source
265+
end
263266
# replace any duplicate specs with what's in the parent lockfile
264267
lockfile.specs.map! do |spec|
265268
parent_spec = cache.find_matching_spec(parent_specs, spec)
@@ -268,9 +271,7 @@ def after_install_all(install: true)
268271

269272
dependency_changes ||= spec != parent_spec
270273

271-
new_spec = parent_spec.dup
272-
new_spec.source = spec.source
273-
new_spec
274+
parent_spec
274275
end
275276

276277
lockfile.platforms.replace(parent_lockfile.platforms).uniq!
@@ -483,6 +484,13 @@ def write_lockfile(lockfile_definition,
483484
# from someone else
484485
if current_lockfile.exist? && install
485486
Bundler.settings.temporary(frozen: true) do
487+
# it keeps the same sources as the builder, which now shares with
488+
# `definition` above; give it its own copy to avoid stomping on it
489+
builder.instance_variable_set(
490+
:@sources,
491+
builder.instance_variable_get(:@sources).dup
492+
)
493+
486494
current_definition = builder.to_definition(current_lockfile, {})
487495
# if something has changed, we skip this step; it's unlocking anyway
488496
next unless current_definition.no_resolve_needed?

spec/bundler/multilock_spec.rb

+24
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,24 @@
974974
end
975975
end
976976

977+
it "syncs git sources that have updated" do
978+
with_gemfile(<<~RUBY) do
979+
gem "rspecq", github: "instructure/rspecq"
980+
981+
lockfile "alt" do
982+
end
983+
RUBY
984+
invoke_bundler("install")
985+
replace_lockfile_git_pin("d7fa5536da01cccb5109ba05c9e236d6660da593")
986+
invoke_bundler("install")
987+
988+
expect(invoke_bundler("info rspecq")).to include("d7fa553")
989+
990+
invoke_bundler("update rspecq")
991+
expect(invoke_bundler("info rspecq")).not_to include("d7fa553")
992+
end
993+
end
994+
977995
private
978996

979997
def create_local_gem(name, content = "", subdirectory: true)
@@ -1070,6 +1088,12 @@ def replace_lockfile_pin(lockfile, gem, version)
10701088
File.write(lockfile, new_contents)
10711089
end
10721090

1091+
def replace_lockfile_git_pin(revision)
1092+
new_contents = File.read("Gemfile.lock").gsub(/revision: [0-9a-f]+/, "revision: #{revision}")
1093+
1094+
File.write("Gemfile.lock", new_contents)
1095+
end
1096+
10731097
def update_lockfile_bundler(lockfile, version)
10741098
new_contents = File.read(lockfile).gsub(/BUNDLED WITH\n [0-9.]+/, "BUNDLED WITH\n #{version}")
10751099

0 commit comments

Comments
 (0)