diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli.rb | 2 | ||||
-rw-r--r-- | lib/bundler/flex/definition.rb | 22 | ||||
-rw-r--r-- | lib/bundler/flex/lockfile_parser.rb | 4 | ||||
-rw-r--r-- | lib/bundler/lazy_specification.rb | 4 | ||||
-rw-r--r-- | lib/bundler/rubygems_ext.rb | 2 |
5 files changed, 28 insertions, 6 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 44857219..e5b30d3f 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -118,7 +118,7 @@ module Bundler Flex::Installer.install(Bundler.root, Bundler.flexdef, opts) cache if Bundler.root.join("vendor/cache").exist? rescue GemNotFound => e - if Bundler.definition.sources.empty? + if Bundler.flexdef.sources.empty? Bundler.ui.warn "Your Gemfile doesn't have any sources. You can add one with a line like 'source :gemcutter'" end raise e diff --git a/lib/bundler/flex/definition.rb b/lib/bundler/flex/definition.rb index 34741dd5..76fa8df4 100644 --- a/lib/bundler/flex/definition.rb +++ b/lib/bundler/flex/definition.rb @@ -22,9 +22,11 @@ module Bundler if lockfile && File.exists?(lockfile) locked = LockfileParser.new(File.read(lockfile)) - @locked_specs = locked.specs + @locked_deps = locked.dependencies + @locked_specs = SpecSet.new(locked.specs) else - @locked_specs = [] + @locked_deps = [] + @locked_specs = SpecSet.new([]) end end @@ -37,8 +39,22 @@ module Bundler dependencies.map { |d| d.groups }.flatten.uniq end + # We have the dependencies from Gemfile.lock and the dependencies from the + # Gemfile. Here, we are finding a list of all dependencies that were + # originally present in the Gemfile that still satisfy the requirements + # of the dependencies in the Gemfile.lock + # + # This allows us to add on the *new* requirements in the Gemfile and make + # sure that the changes result in a conservative update to the Gemfile.lock. def locked_specs_as_deps - locked_specs.map { |s| Gem::Dependency.new(s.name, s.version) } + deps = @dependencies & @locked_deps + + @dependencies.each do |dep| + next if deps.include?(dep) + deps << dep if @locked_specs.any? { |s| s.satisfies?(dep) } + end + + @locked_specs.for(deps).map { |s| Gem::Dependency.new(s.name, s.version) } end end end diff --git a/lib/bundler/flex/lockfile_parser.rb b/lib/bundler/flex/lockfile_parser.rb index f2501497..c04521ae 100644 --- a/lib/bundler/flex/lockfile_parser.rb +++ b/lib/bundler/flex/lockfile_parser.rb @@ -43,7 +43,7 @@ module Bundler TYPES[type].from_lock(source, options) end - NAME_VERSION = '(.*?)(?: \((.*)\))?' + NAME_VERSION = '(?! )(.*?)(?: \((.*)\))?:?' def parse_dependencies(line) if line =~ %r{^ {2}#{NAME_VERSION}$} @@ -62,7 +62,7 @@ module Bundler @specs << @current else line =~ %r{^ {4}#{NAME_VERSION}$} - @current.dependencies << Gem::Dependency.new(name, version) + @current.dependencies << Gem::Dependency.new($1, $2) end end diff --git a/lib/bundler/lazy_specification.rb b/lib/bundler/lazy_specification.rb index 797ab007..d2f11df6 100644 --- a/lib/bundler/lazy_specification.rb +++ b/lib/bundler/lazy_specification.rb @@ -10,5 +10,9 @@ module Bundler @version = version @dependencies = [] end + + def satisfies?(dependency) + @name == dependency.name && dependency.requirement.satisfied_by?(Gem::Version.new(@version)) + end end end
\ No newline at end of file diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 6d1d348a..b0a4625a 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -75,6 +75,8 @@ module Gem class Dependency attr_accessor :source, :groups + alias eql? == + def to_yaml_properties instance_variables.reject { |p| ["@source", "@groups"].include?(p.to_s) } end |