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

Commit

Permalink
Merge pull request #2685 from davidblondeau/outdated-strict
Browse files Browse the repository at this point in the history
bundle outdated --strict
  • Loading branch information
indirect committed Oct 29, 2013
2 parents 42c8a80 + 06ae0ac commit c76badc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ def binstubs(*gems)
method_option "source", :type => :array, :banner => "Check against a specific source"
method_option "local", :type => :boolean, :banner =>
"Do not attempt to fetch gems remotely and use the gem cache instead"
method_option "strict", :type => :boolean, :banner =>
"Only list newer versions allowed by your Gemfile requirements"
def outdated(*gems)
sources = Array(options[:source])

Expand Down Expand Up @@ -444,13 +446,19 @@ def outdated(*gems)
[gemfile_specs.sort_by(&:name), dependency_specs.sort_by(&:name)].flatten.each do |current_spec|
next if !gems.empty? && !gems.include?(current_spec.name)

active_spec = definition.index[current_spec.name].sort_by { |b| b.version }
dependency = current_dependencies[current_spec.name]

active_spec = definition.index[current_spec.name].sort_by { |b| b.version }
if !current_spec.version.prerelease? && !options[:pre] && active_spec.size > 1
active_spec = active_spec.delete_if { |b| b.respond_to?(:version) && b.version.prerelease? }
end

active_spec = active_spec.last
if options["strict"]
active_spec = active_spec.reverse.detect do |b|
dependency && b.respond_to?(:version) && dependency.requirement.satisfied_by?(b.version)
end || active_spec.last
else
active_spec = active_spec.last
end
next if active_spec.nil?

gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
Expand All @@ -466,7 +474,6 @@ def outdated(*gems)

spec_version = "#{active_spec.version}#{active_spec.git_version}"
current_version = "#{current_spec.version}#{current_spec.git_version}"
dependency = current_dependencies[current_spec.name]
dependency_version = %|Gemfile specifies "#{dependency.requirement}"| if dependency && dependency.specific?
Bundler.ui.info " * #{active_spec.name} (#{spec_version} > #{current_version}) #{dependency_version}".rstrip
out_count += 1
Expand Down
17 changes: 17 additions & 0 deletions spec/commands/outdated_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@
gem "zebra", :git => "#{lib_path('zebra')}"
gem "foo", :git => "#{lib_path('foo')}"
gem "activesupport", "2.3.5"
gem "weakling", "~> 0.0.1"
G
end

describe "with no arguments" do
it "returns a sorted list of outdated gems" do
update_repo2 do
build_gem "activesupport", "3.0"
build_gem "weakling", "0.2"
update_git "foo", :path => lib_path("foo")
update_git "zebra", :path => lib_path("zebra")
end

bundle "outdated"

expect(out).to include("activesupport (3.0 > 2.3.5) Gemfile specifies \"= 2.3.5\"")
expect(out).to include("weakling (0.2 > 0.0.3) Gemfile specifies \"~> 0.0.1\"")
expect(out).to include("foo (1.0")

# Gem names are one per-line, between "*" and their parenthesized version.
Expand Down Expand Up @@ -114,6 +117,20 @@
end
end

describe "with --strict option" do
it "only reports gems that have a newer version that matches the specified dependency version requirements" do
update_repo2 do
build_gem "activesupport", "3.0"
build_gem "weakling", "0.0.5"
end

bundle "outdated --strict"

expect(out).to_not include("activesupport (3.0 > 2.3.5) Gemfile specifies \"= 2.3.5\"")
expect(out).to include("weakling (0.0.5 > 0.0.3) Gemfile specifies \"~> 0.0.1\"")
end
end

describe "with invalid gem name" do
it "returns could not find gem name" do
bundle "outdated invalid_gem_name"
Expand Down

0 comments on commit c76badc

Please sign in to comment.