Skip to content

Commit ac5661d

Browse files
deivid-rodriguezmatzbot
authored andcommitted
[rubygems/rubygems] Fix locking of incorrect version of git gem in an edge case
In particular, when a gem registry transitive dependency is changed to a git source direct dependency. ruby/rubygems@bcdc7660d9
1 parent 486485a commit ac5661d

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

lib/bundler/definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ def converge_specs(specs)
950950
if dep
951951
gemfile_source = dep.source || default_source
952952

953-
deps << dep if !dep.source || lockfile_source.include?(dep.source)
953+
deps << dep if !dep.source || lockfile_source.include?(dep.source) || new_deps.include?(dep)
954954

955955
# Replace the locked dependency's source with the equivalent source from the Gemfile
956956
s.source = gemfile_source

spec/bundler/lock/git_spec.rb

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
RSpec.describe "bundle lock with git gems" do
4-
before :each do
4+
let(:install_gemfile_with_foo_as_a_git_dependency) do
55
build_git "foo"
66

77
install_gemfile <<-G
@@ -11,10 +11,14 @@
1111
end
1212

1313
it "doesn't break right after running lock" do
14+
install_gemfile_with_foo_as_a_git_dependency
15+
1416
expect(the_bundle).to include_gems "foo 1.0.0"
1517
end
1618

1719
it "doesn't print errors even if running lock after removing the cache" do
20+
install_gemfile_with_foo_as_a_git_dependency
21+
1822
FileUtils.rm_rf(Dir[default_cache_path("git/foo-1.0-*")].first)
1923

2024
bundle "lock --verbose"
@@ -23,6 +27,8 @@
2327
end
2428

2529
it "prints a proper error when changing a locked Gemfile to point to a bad branch" do
30+
install_gemfile_with_foo_as_a_git_dependency
31+
2632
gemfile <<-G
2733
source "https://gem.repo1"
2834
gem 'foo', :git => "#{lib_path("foo-1.0")}", :branch => "bad"
@@ -34,6 +40,8 @@
3440
end
3541

3642
it "prints a proper error when installing a Gemfile with a locked ref that does not exist" do
43+
install_gemfile_with_foo_as_a_git_dependency
44+
3745
lockfile <<~L
3846
GIT
3947
remote: #{lib_path("foo-1.0")}
@@ -61,6 +69,8 @@
6169
end
6270

6371
it "locks a git source to the current ref" do
72+
install_gemfile_with_foo_as_a_git_dependency
73+
6474
update_git "foo"
6575
bundle :install
6676

@@ -73,13 +83,17 @@
7383
end
7484

7585
it "properly clones a git source locked to an out of date ref" do
86+
install_gemfile_with_foo_as_a_git_dependency
87+
7688
update_git "foo"
7789

7890
bundle :install, env: { "BUNDLE_PATH" => "foo" }
7991
expect(err).to be_empty
8092
end
8193

8294
it "properly fetches a git source locked to an unreachable ref" do
95+
install_gemfile_with_foo_as_a_git_dependency
96+
8397
# Create a commit and make it unreachable
8498
git "checkout -b foo ", lib_path("foo-1.0")
8599
unreachable_sha = update_git("foo").ref_for("HEAD")
@@ -118,6 +132,8 @@
118132
end
119133

120134
it "properly fetches a git source locked to an annotated tag" do
135+
install_gemfile_with_foo_as_a_git_dependency
136+
121137
# Create an annotated tag
122138
git("tag -a v1.0 -m 'Annotated v1.0'", lib_path("foo-1.0"))
123139
annotated_tag = git("rev-parse v1.0", lib_path("foo-1.0"))
@@ -154,9 +170,54 @@
154170
end
155171

156172
it "provides correct #full_gem_path" do
173+
install_gemfile_with_foo_as_a_git_dependency
174+
157175
run <<-RUBY
158176
puts Bundler.rubygems.find_name('foo').first.full_gem_path
159177
RUBY
160178
expect(out).to eq(bundle("info foo --path"))
161179
end
180+
181+
it "does not lock versions that don't exist in the repository when changing a GEM transitive dep to a GIT direct dep" do
182+
build_repo4 do
183+
build_gem "activesupport", "8.0.0" do |s|
184+
s.add_dependency "securerandom"
185+
end
186+
187+
build_gem "securerandom", "0.3.1"
188+
end
189+
190+
path = lib_path("securerandom")
191+
192+
build_git "securerandom", "0.3.2", path: path
193+
194+
lockfile <<~L
195+
GEM
196+
remote: https://gem.repo4/
197+
specs:
198+
activesupport (8.0.0)
199+
securerandom
200+
securerandom (0.3.1)
201+
202+
PLATFORMS
203+
#{lockfile_platforms}
204+
205+
DEPENDENCIES
206+
activesupport
207+
208+
BUNDLED WITH
209+
#{Bundler::VERSION}
210+
L
211+
212+
gemfile <<~G
213+
source "https://gem.repo4"
214+
215+
gem "activesupport"
216+
gem "securerandom", git: "#{path}"
217+
G
218+
219+
bundle "lock"
220+
221+
expect(lockfile).to include("securerandom (0.3.2)")
222+
end
162223
end

0 commit comments

Comments
 (0)