Skip to content

Commit 769c025

Browse files
authored
Merge pull request #9213 from eileencodes/fix-dependency-source-bug
Fix dependency source bug in bundler
2 parents be91cbb + dff76ba commit 769c025

2 files changed

Lines changed: 132 additions & 1 deletion

File tree

bundler/lib/bundler/definition.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,22 @@ def converge_specs(specs)
10661066

10671067
deps << dep if !replacement_source || lockfile_source.include?(replacement_source) || new_deps.include?(dep)
10681068
else
1069-
replacement_source = sources.get(lockfile_source)
1069+
parent_dep = @dependencies.find do |d|
1070+
next unless d.source && d.source != lockfile_source
1071+
next if d.source.is_a?(Source::Gemspec)
1072+
1073+
parent_locked_specs = @originally_locked_specs[d.name]
1074+
1075+
parent_locked_specs.any? do |parent_spec|
1076+
parent_spec.runtime_dependencies.any? {|rd| rd.name == s.name }
1077+
end
1078+
end
1079+
1080+
if parent_dep
1081+
replacement_source = parent_dep.source
1082+
else
1083+
replacement_source = sources.get(lockfile_source)
1084+
end
10701085
end
10711086

10721087
# Replace the locked dependency's source with the equivalent source from the Gemfile

bundler/spec/install/gemfile/sources_spec.rb

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,4 +1079,120 @@
10791079
expect(lockfile).to eq original_lockfile.gsub("bigdecimal (1.0.0)", "bigdecimal (3.3.1)")
10801080
end
10811081
end
1082+
1083+
context "when switching a gem with components from rubygems to git source" do
1084+
before do
1085+
build_repo2 do
1086+
build_gem "rails", "7.0.0" do |s|
1087+
s.add_dependency "actionpack", "7.0.0"
1088+
s.add_dependency "activerecord", "7.0.0"
1089+
end
1090+
build_gem "actionpack", "7.0.0"
1091+
build_gem "activerecord", "7.0.0"
1092+
# propshaft also depends on actionpack, creating the conflict
1093+
build_gem "propshaft", "1.0.0" do |s|
1094+
s.add_dependency "actionpack", ">= 7.0.0"
1095+
end
1096+
end
1097+
1098+
build_git "rails", "7.0.0", path: lib_path("rails") do |s|
1099+
s.add_dependency "actionpack", "7.0.0"
1100+
s.add_dependency "activerecord", "7.0.0"
1101+
end
1102+
1103+
build_git "actionpack", "7.0.0", path: lib_path("rails")
1104+
build_git "activerecord", "7.0.0", path: lib_path("rails")
1105+
1106+
install_gemfile <<-G
1107+
source "https://gem.repo2"
1108+
gem "rails", "7.0.0"
1109+
gem "propshaft"
1110+
G
1111+
end
1112+
1113+
it "moves component gems to the git source in the lockfile" do
1114+
expect(lockfile).to include("remote: https://gem.repo2")
1115+
expect(lockfile).to include("rails (7.0.0)")
1116+
expect(lockfile).to include("actionpack (7.0.0)")
1117+
expect(lockfile).to include("activerecord (7.0.0)")
1118+
expect(lockfile).to include("propshaft (1.0.0)")
1119+
1120+
gemfile <<-G
1121+
source "https://gem.repo2"
1122+
gem "rails", git: "#{lib_path("rails")}"
1123+
gem "propshaft"
1124+
G
1125+
1126+
bundle "install"
1127+
1128+
expect(lockfile).to include("remote: #{lib_path("rails")}")
1129+
expect(lockfile).to include("rails (7.0.0)")
1130+
expect(lockfile).to include("actionpack (7.0.0)")
1131+
expect(lockfile).to include("activerecord (7.0.0)")
1132+
1133+
# Component gems should NOT remain in the GEM section
1134+
# Extract just the GEM section by splitting on GIT first, then GEM
1135+
gem_section = lockfile.split("GEM\n").last.split(/\n(PLATFORMS|DEPENDENCIES)/)[0]
1136+
expect(gem_section).not_to include("actionpack (7.0.0)")
1137+
expect(gem_section).not_to include("activerecord (7.0.0)")
1138+
end
1139+
end
1140+
1141+
context "when switching a gem with components from rubygems to path source" do
1142+
before do
1143+
build_repo2 do
1144+
build_gem "rails", "7.0.0" do |s|
1145+
s.add_dependency "actionpack", "7.0.0"
1146+
s.add_dependency "activerecord", "7.0.0"
1147+
end
1148+
build_gem "actionpack", "7.0.0"
1149+
build_gem "activerecord", "7.0.0"
1150+
# propshaft also depends on actionpack, creating the conflict
1151+
build_gem "propshaft", "1.0.0" do |s|
1152+
s.add_dependency "actionpack", ">= 7.0.0"
1153+
end
1154+
end
1155+
1156+
build_lib "rails", "7.0.0", path: lib_path("rails") do |s|
1157+
s.add_dependency "actionpack", "7.0.0"
1158+
s.add_dependency "activerecord", "7.0.0"
1159+
end
1160+
1161+
build_lib "actionpack", "7.0.0", path: lib_path("rails")
1162+
build_lib "activerecord", "7.0.0", path: lib_path("rails")
1163+
1164+
install_gemfile <<-G
1165+
source "https://gem.repo2"
1166+
gem "rails", "7.0.0"
1167+
gem "propshaft"
1168+
G
1169+
end
1170+
1171+
it "moves component gems to the path source in the lockfile" do
1172+
expect(lockfile).to include("remote: https://gem.repo2")
1173+
expect(lockfile).to include("rails (7.0.0)")
1174+
expect(lockfile).to include("actionpack (7.0.0)")
1175+
expect(lockfile).to include("activerecord (7.0.0)")
1176+
expect(lockfile).to include("propshaft (1.0.0)")
1177+
1178+
gemfile <<-G
1179+
source "https://gem.repo2"
1180+
gem "rails", path: "#{lib_path("rails")}"
1181+
gem "propshaft"
1182+
G
1183+
1184+
bundle "install"
1185+
1186+
expect(lockfile).to include("remote: #{lib_path("rails")}")
1187+
expect(lockfile).to include("rails (7.0.0)")
1188+
expect(lockfile).to include("actionpack (7.0.0)")
1189+
expect(lockfile).to include("activerecord (7.0.0)")
1190+
1191+
# Component gems should NOT remain in the GEM section
1192+
# Extract just the GEM section by splitting appropriately
1193+
gem_section = lockfile.split("GEM\n").last.split(/\n(PLATFORMS|DEPENDENCIES)/)[0]
1194+
expect(gem_section).not_to include("actionpack (7.0.0)")
1195+
expect(gem_section).not_to include("activerecord (7.0.0)")
1196+
end
1197+
end
10821198
end

0 commit comments

Comments
 (0)