Skip to content

Commit 8f1354e

Browse files
Merge pull request #8962 from Earlopain/source-change-re-resolve
Fix outdated lockfile during `bundle lock` when source changes
2 parents dd5d15f + 85514e3 commit 8f1354e

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

bundler/lib/bundler/definition.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,8 @@ def converge_specs(specs)
10361036

10371037
specs.each do |s|
10381038
name = s.name
1039+
next if @gems_to_unlock.include?(name)
1040+
10391041
dep = @dependencies.find {|d| s.satisfies?(d) }
10401042
lockfile_source = s.source
10411043

@@ -1049,12 +1051,13 @@ def converge_specs(specs)
10491051

10501052
# Replace the locked dependency's source with the equivalent source from the Gemfile
10511053
s.source = replacement_source || default_source
1054+
next if s.source_changed?
10521055

10531056
source = s.source
10541057
next if @sources_to_unlock.include?(source.name)
10551058

10561059
# Path sources have special logic
1057-
if source.instance_of?(Source::Path) || source.instance_of?(Source::Gemspec) || (source.instance_of?(Source::Git) && !@gems_to_unlock.include?(name) && deps.include?(dep))
1060+
if source.is_a?(Source::Path)
10581061
new_spec = source.specs[s].first
10591062
if new_spec
10601063
s.runtime_dependencies.replace(new_spec.runtime_dependencies)
@@ -1136,7 +1139,7 @@ def lockfiles_equal?(current, proposed, preserve_unknown_sections)
11361139
def additional_base_requirements_to_prevent_downgrades(resolution_base)
11371140
return resolution_base unless @locked_gems && !sources.expired_sources?(@locked_gems.sources)
11381141
@originally_locked_specs.each do |locked_spec|
1139-
next if locked_spec.source.is_a?(Source::Path)
1142+
next if locked_spec.source.is_a?(Source::Path) || locked_spec.source_changed?
11401143

11411144
name = locked_spec.name
11421145
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)