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

Commit

Permalink
Merged pull request #1130 from joelmoss/outdated.
Browse files Browse the repository at this point in the history
Command to list outdated gems
  • Loading branch information
Andre Arko committed Apr 29, 2011
2 parents 3bb7799 + 8282911 commit ca6c21e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,33 @@ def show(gem_name = nil)
end
map %w(list) => "show"

desc "outdated", "Returns a list of installed gems that are outdated."
long_desc <<-D
Outdated lists the names and versions of all gems that are outdated when compared to the source.
Calling outdated with [GEM [GEM]] will check only the given gems.
D
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"
def outdated(*gems)
sources = Array(options[:source])

if gems.empty? && sources.empty?
# We're doing a full update
definition = Bundler.definition(true)
else
definition = Bundler.definition(:gems => gems, :sources => sources)
end

options["local"] ? definition.resolve_with_cache! : definition.resolve_remotely!

definition.specs.each do |spec|
spec.source.fetch(spec) if spec.source.respond_to?(:fetch)
spec.source.outdated(spec)
Bundler.ui.debug "from #{spec.loaded_from} "
end
end

desc "cache", "Cache all the gems to vendor/cache", :hide => true
method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache."
def cache
Expand Down
12 changes: 12 additions & 0 deletions lib/bundler/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ def fetch(spec)
end
end

def outdated(spec)
installed_spec = installed_specs[spec.name]
installed_spec = installed_spec.first

if installed_spec && spec.version == installed_spec.version
Bundler.ui.debug "Up to date: #{spec.name} (#{installed_spec.version}) "
return
end

Bundler.ui.info "#{spec.name} (#{spec.version} > #{installed_spec.version}) "
end

def install(spec)
path = cached_gem(spec)

Expand Down
3 changes: 3 additions & 0 deletions man/bundle.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ We divide `bundle` subcommands into primary commands and utilities.
* `bundle show(1)`:
Show the source location of a particular gem in the bundle

* `bundle outdated(1)`:
Show all of the outdated gems in the current bundle

* `bundle console(1)`:
Start an IRB session in the context of the current bundle

Expand Down
46 changes: 46 additions & 0 deletions spec/other/outdated_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "spec_helper"

describe "bundle outdated" do
before :each do
build_repo2

install_gemfile <<-G
source "file://#{gem_repo2}"
gem "activesupport"
gem "rack-obama"
G
end

describe "with no arguments" do
it "returns list of outdated gems" do
update_repo2 do
build_gem "activesupport", "3.0"
end

bundle "outdated"
out.should include("activesupport (3.0 > 2.3.5)")
out.should include("rack (1.2 > 1.0.0)")
end
end

describe "with --local option" do
it "doesn't hit repo2" do
FileUtils.rm_rf(gem_repo2)

bundle "outdated --local"
out.should_not match(/Fetching source index/)
end
end

describe "with specified gems" do
it "returns list of outdated gems" do
update_repo2 do
build_gem "activesupport", "3.0"
end

bundle "outdated rack"
out.should_not include("activesupport (3.0 > 2.3.5)")
out.should include("rack (1.2 > 1.0.0)")
end
end
end

0 comments on commit ca6c21e

Please sign in to comment.