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
17 changes: 16 additions & 1 deletion bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,22 @@ def converge_specs(specs)

deps << dep if !replacement_source || lockfile_source.include?(replacement_source) || new_deps.include?(dep)
else
replacement_source = sources.get(lockfile_source)
parent_dep = @dependencies.find do |d|
next unless d.source && d.source != lockfile_source
next if d.source.is_a?(Source::Gemspec)

parent_locked_specs = @originally_locked_specs[d.name]

parent_locked_specs.any? do |parent_spec|
parent_spec.runtime_dependencies.any? {|rd| rd.name == s.name }
end
end

if parent_dep
replacement_source = parent_dep.source
else
replacement_source = sources.get(lockfile_source)
end
end

# Replace the locked dependency's source with the equivalent source from the Gemfile
Expand Down
116 changes: 116 additions & 0 deletions bundler/spec/install/gemfile/sources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1079,4 +1079,120 @@
expect(lockfile).to eq original_lockfile.gsub("bigdecimal (1.0.0)", "bigdecimal (3.3.1)")
end
end

context "when switching a gem with components from rubygems to git source" do
before do
build_repo2 do
build_gem "rails", "7.0.0" do |s|
s.add_dependency "actionpack", "7.0.0"
s.add_dependency "activerecord", "7.0.0"
end
build_gem "actionpack", "7.0.0"
build_gem "activerecord", "7.0.0"
# propshaft also depends on actionpack, creating the conflict
build_gem "propshaft", "1.0.0" do |s|
s.add_dependency "actionpack", ">= 7.0.0"
end
end

build_git "rails", "7.0.0", path: lib_path("rails") do |s|
s.add_dependency "actionpack", "7.0.0"
s.add_dependency "activerecord", "7.0.0"
end

build_git "actionpack", "7.0.0", path: lib_path("rails")
build_git "activerecord", "7.0.0", path: lib_path("rails")

install_gemfile <<-G
source "https://gem.repo2"
gem "rails", "7.0.0"
gem "propshaft"
G
end

it "moves component gems to the git source in the lockfile" do
expect(lockfile).to include("remote: https://gem.repo2")
expect(lockfile).to include("rails (7.0.0)")
expect(lockfile).to include("actionpack (7.0.0)")
expect(lockfile).to include("activerecord (7.0.0)")
expect(lockfile).to include("propshaft (1.0.0)")

gemfile <<-G
source "https://gem.repo2"
gem "rails", git: "#{lib_path("rails")}"
gem "propshaft"
G

bundle "install"

expect(lockfile).to include("remote: #{lib_path("rails")}")
expect(lockfile).to include("rails (7.0.0)")
expect(lockfile).to include("actionpack (7.0.0)")
expect(lockfile).to include("activerecord (7.0.0)")

# Component gems should NOT remain in the GEM section
# Extract just the GEM section by splitting on GIT first, then GEM
gem_section = lockfile.split("GEM\n").last.split(/\n(PLATFORMS|DEPENDENCIES)/)[0]
expect(gem_section).not_to include("actionpack (7.0.0)")
expect(gem_section).not_to include("activerecord (7.0.0)")
end
end

context "when switching a gem with components from rubygems to path source" do
before do
build_repo2 do
build_gem "rails", "7.0.0" do |s|
s.add_dependency "actionpack", "7.0.0"
s.add_dependency "activerecord", "7.0.0"
end
build_gem "actionpack", "7.0.0"
build_gem "activerecord", "7.0.0"
# propshaft also depends on actionpack, creating the conflict
build_gem "propshaft", "1.0.0" do |s|
s.add_dependency "actionpack", ">= 7.0.0"
end
end

build_lib "rails", "7.0.0", path: lib_path("rails") do |s|
s.add_dependency "actionpack", "7.0.0"
s.add_dependency "activerecord", "7.0.0"
end

build_lib "actionpack", "7.0.0", path: lib_path("rails")
build_lib "activerecord", "7.0.0", path: lib_path("rails")

install_gemfile <<-G
source "https://gem.repo2"
gem "rails", "7.0.0"
gem "propshaft"
G
end

it "moves component gems to the path source in the lockfile" do
expect(lockfile).to include("remote: https://gem.repo2")
expect(lockfile).to include("rails (7.0.0)")
expect(lockfile).to include("actionpack (7.0.0)")
expect(lockfile).to include("activerecord (7.0.0)")
expect(lockfile).to include("propshaft (1.0.0)")

gemfile <<-G
source "https://gem.repo2"
gem "rails", path: "#{lib_path("rails")}"
gem "propshaft"
G

bundle "install"

expect(lockfile).to include("remote: #{lib_path("rails")}")
expect(lockfile).to include("rails (7.0.0)")
expect(lockfile).to include("actionpack (7.0.0)")
expect(lockfile).to include("activerecord (7.0.0)")

# Component gems should NOT remain in the GEM section
# Extract just the GEM section by splitting appropriately
gem_section = lockfile.split("GEM\n").last.split(/\n(PLATFORMS|DEPENDENCIES)/)[0]
expect(gem_section).not_to include("actionpack (7.0.0)")
expect(gem_section).not_to include("activerecord (7.0.0)")
end
end
end