Skip to content

Commit da017b9

Browse files
hsbtclaude
andcommitted
Restore lockfile remote order for GEM sections
Bundler::Source::Rubygems stores remotes in reverse of the lockfile order, so reading them straight through flipped which remote a spec downloads from when a GEM section lists more than one. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 3fe9b33 commit da017b9

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

lib/rubygems/request_set.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,10 @@ def load_lockfile(lock_file) # :nodoc:
354354
parser.specs.group_by(&:source).each do |source, specs|
355355
case source
356356
when Bundler::Source::Rubygems
357-
remotes = source.remotes.map {|remote| Gem::Source.new(remote.to_s) }
357+
# Bundler::Source::Rubygems stores remotes in reverse of the lockfile
358+
# order (Bundler::Source::Rubygems#to_lock reverses them back), so
359+
# restore the lockfile order here.
360+
remotes = source.remotes.reverse.map {|remote| Gem::Source.new(remote.to_s) }
358361
remotes << Gem::Source.new(Gem::DEFAULT_HOST) if remotes.empty?
359362
lock_set = Gem::Resolver::LockSet.new(remotes)
360363
specs.each do |spec|

test/rubygems/test_gem_request_set.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,39 @@ def test_load_gemdeps_with_lockfile_gem_section
385385
assert_equal [dep("a", "~> 1.0")], spec.dependencies
386386
end
387387

388+
def test_load_gemdeps_with_lockfile_gem_section_multiple_remotes
389+
rs = Gem::RequestSet.new
390+
391+
File.open "gem.deps.rb", "w" do |io|
392+
io.puts 'gem "a"'
393+
end
394+
395+
File.open "gem.deps.rb.lock", "w" do |io|
396+
io.puts <<~LOCKFILE
397+
GEM
398+
remote: https://gems.example/
399+
remote: https://other.example/
400+
specs:
401+
a (2)
402+
403+
PLATFORMS
404+
#{Gem::Platform::RUBY}
405+
406+
DEPENDENCIES
407+
a
408+
LOCKFILE
409+
end
410+
411+
rs.load_gemdeps "gem.deps.rb"
412+
413+
lock_set = rs.sets.find {|set| Gem::Resolver::LockSet === set }
414+
refute_nil lock_set, "LockSet should be created from GEM section"
415+
assert_equal %w[a-2], lock_set.specs.map(&:full_name)
416+
417+
assert_equal %w[https://gems.example/ https://other.example/],
418+
lock_set.specs.flat_map {|s| s.sources.map {|src| src.uri.to_s } }
419+
end
420+
388421
def test_load_gemdeps_with_lockfile_git_section
389422
rs = Gem::RequestSet.new
390423

0 commit comments

Comments
 (0)