Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Initial implementation for git local repos #1779

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 53 additions & 18 deletions lib/bundler/definition.rb
Expand Up @@ -68,28 +68,13 @@ def initialize(lockfile, dependencies, sources, unlock)
@new_platform = !@platforms.include?(current_platform)
@platforms |= [current_platform]

@path_changes = @sources.any? do |source|
next unless source.instance_of?(Source::Path)

locked = @locked_sources.find do |ls|
ls.class == source.class && ls.path == source.path
end

if locked
unlocking = locked.specs.any? do |spec|
@locked_specs.any? do |locked_spec|
locked_spec.source != locked
end
end
end

!locked || unlocking || source.specs != locked.specs
end
@path_changes = converge_paths
eager_unlock = expand_dependencies(@unlock[:gems])
@unlock[:gems] = @locked_specs.for(eager_unlock).map { |s| s.name }

@source_changes = converge_sources
@dependency_changes = converge_dependencies
@local_changes = converge_locals

fixup_dependency_types!
end
Expand Down Expand Up @@ -174,7 +159,7 @@ def specs_for(groups)

def resolve
@resolve ||= begin
if Bundler.settings[:frozen] || (!@unlocking && !@source_changes && !@dependency_changes && !@new_platform && !@path_changes)
if Bundler.settings[:frozen] || (!@unlocking && nothing_changed?)
@locked_specs
else
last_resolve = converge_locked_specs
Expand Down Expand Up @@ -352,13 +337,63 @@ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)

private

def nothing_changed?
!@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes
end

def pretty_dep(dep, source = false)
msg = "#{dep.name}"
msg << " (#{dep.requirement})" unless dep.requirement == Gem::Requirement.default
msg << " from the `#{dep.source}` source" if source && dep.source
msg
end

# Check if the specs of the given source changed
# according to the locked source. A block should be
# in order to specify how the locked version of
# the source should be found.
def specs_changed?(source, &block)
locked = @locked_sources.find(&block)

if locked
unlocking = locked.specs.any? do |spec|
@locked_specs.any? do |locked_spec|
locked_spec.source != locked
end
end
end

!locked || unlocking || source.specs != locked.specs
end

# Get all locals and override their matching sources.
# Return true if any of the locals changed (for example,
# they point to a new revision) or depend on new specs.
def converge_locals
locals = []

Bundler.settings.local_overrides.map do |k,v|
spec = @dependencies.find { |s| s.name == k }
source = spec && spec.source
if source && source.respond_to?(:local_override!)
locals << [ source, source.local_override!(v) ]
end
end

locals.any? do |source, changed|
changed || specs_changed?(source) { |o| source.class === o.class && source.uri == o.uri }
end
end

def converge_paths
@sources.any? do |source|
next unless source.instance_of?(Source::Path)
specs_changed?(source) do |ls|
ls.class == source.class && ls.path == source.path
end
end
end

def converge_sources
changes = false

Expand Down
10 changes: 10 additions & 0 deletions lib/bundler/settings.rb
Expand Up @@ -32,6 +32,16 @@ def all
end
end

def local_overrides
repos = {}
all.each do |k|
if k =~ /\.local$/
repos[$`] = self[k]
end
end
repos
end

def locations(key)
locations = {}

Expand Down