Skip to content

Commit 85514e3

Browse files
Earlopaindeivid-rodriguez
authored andcommitted
Fix outdated lockfile during bundle lock when source changes
When the source used to be git and switches back to rubygems, it is possible that the git source contains a version that ruybgems doesn't know about yet. So don't add the locked spec to the base resolve, and also don't add a lower bound requirement on the version, since the version in the new source may actually be lower.
1 parent 59ec6b4 commit 85514e3

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

bundler/lib/bundler/definition.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ def converge_specs(specs)
10511051

10521052
# Replace the locked dependency's source with the equivalent source from the Gemfile
10531053
s.source = replacement_source || default_source
1054+
next if s.source_changed?
10541055

10551056
source = s.source
10561057
next if @sources_to_unlock.include?(source.name)
@@ -1138,7 +1139,7 @@ def lockfiles_equal?(current, proposed, preserve_unknown_sections)
11381139
def additional_base_requirements_to_prevent_downgrades(resolution_base)
11391140
return resolution_base unless @locked_gems && !sources.expired_sources?(@locked_gems.sources)
11401141
@originally_locked_specs.each do |locked_spec|
1141-
next if locked_spec.source.is_a?(Source::Path)
1142+
next if locked_spec.source.is_a?(Source::Path) || locked_spec.source_changed?
11421143

11431144
name = locked_spec.name
11441145
next if @changed_dependencies.include?(name)

bundler/spec/lock/git_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,39 @@
220220

221221
expect(lockfile).to include("securerandom (0.3.2)")
222222
end
223+
224+
it "does not lock versions that don't exist in the repository when changing a GIT direct dep to a GEM direct dep" do
225+
build_repo4 do
226+
build_gem "ruby-lsp", "0.16.1"
227+
end
228+
229+
path = lib_path("ruby-lsp")
230+
revision = build_git("ruby-lsp", "0.16.2", path: path).ref_for("HEAD")
231+
232+
lockfile <<~L
233+
GIT
234+
remote: #{path}
235+
revision: #{revision}
236+
specs:
237+
ruby-lsp (0.16.2)
238+
239+
PLATFORMS
240+
#{lockfile_platforms}
241+
242+
DEPENDENCIES
243+
ruby-lsp!
244+
245+
BUNDLED WITH
246+
#{Bundler::VERSION}
247+
L
248+
249+
gemfile <<~G
250+
source "https://gem.repo4"
251+
gem "ruby-lsp"
252+
G
253+
254+
bundle "lock"
255+
256+
expect(lockfile).to include("ruby-lsp (0.16.1)")
257+
end
223258
end

0 commit comments

Comments
 (0)