Skip to content

Commit

Permalink
Extract a converge_specs method for later reusing it
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Nov 17, 2021
1 parent afaf868 commit e896e63
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions bundler/lib/bundler/definition.rb
Expand Up @@ -690,9 +690,27 @@ def converge_dependencies
# commonly happen if the Gemfile has changed since the lockfile was last
# generated
def converge_locked_specs
resolve = converge_specs(@locked_specs)

diff = nil

# Now, we unlock any sources that do not have anymore gems pinned to it
sources.all_sources.each do |source|
next unless source.respond_to?(:unlock!)

unless resolve.any? {|s| s.source == source }
diff ||= @locked_specs.to_a - resolve.to_a
source.unlock! if diff.any? {|s| s.source == source }
end
end

resolve
end

def converge_specs(specs)
deps = []
converged = []
@locked_specs.each do |s|
specs.each do |s|
# Replace the locked dependency's source with the equivalent source from the Gemfile
dep = @dependencies.find {|d| s.satisfies?(d) }

Expand All @@ -717,7 +735,7 @@ def converge_locked_specs
rescue PathError, GitError
# if we won't need the source (according to the lockfile),
# don't error if the path/git source isn't available
next if @locked_specs.
next if specs.
for(requested_dependencies, false, true).
none? {|locked_spec| locked_spec.source == s.source }

Expand All @@ -741,20 +759,7 @@ def converge_locked_specs
end

resolve = SpecSet.new(converged)
resolve = SpecSet.new(resolve.for(expand_dependencies(deps, true), false, false).reject{|s| @unlock[:gems].include?(s.name) })
diff = nil

# Now, we unlock any sources that do not have anymore gems pinned to it
sources.all_sources.each do |source|
next unless source.respond_to?(:unlock!)

unless resolve.any? {|s| s.source == source }
diff ||= @locked_specs.to_a - resolve.to_a
source.unlock! if diff.any? {|s| s.source == source }
end
end

resolve
SpecSet.new(resolve.for(expand_dependencies(deps, true), false, false).reject{|s| @unlock[:gems].include?(s.name) })
end

def metadata_dependencies
Expand Down

0 comments on commit e896e63

Please sign in to comment.