2011-08-23 23:30:52 +01:00
|
|
|
require 'cmd/outdated'
|
|
|
|
require 'cmd/install'
|
|
|
|
|
|
|
|
class Fixnum
|
|
|
|
def plural_s
|
|
|
|
if self > 1 then "s" else "" end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def upgrade
|
|
|
|
Homebrew.perform_preinstall_checks
|
|
|
|
|
|
|
|
outdated = if ARGV.named.empty?
|
|
|
|
Homebrew.outdated_brews
|
|
|
|
else
|
2011-09-11 13:06:05 -07:00
|
|
|
ARGV.formulae.each do |f|
|
2011-09-02 09:55:37 +01:00
|
|
|
raise "#{f} already upgraded" if f.installed?
|
|
|
|
raise "#{f} not installed" unless f.rack.exist? and not f.rack.children.empty?
|
|
|
|
end
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
|
2011-09-11 13:16:01 -07:00
|
|
|
# Expand the outdated list to include outdated dependencies then sort and
|
|
|
|
# reduce such that dependencies are installed first and installation is not
|
|
|
|
# attempted twice. Sorting is implicit the way `recursive_deps` returns
|
|
|
|
# root dependencies at the head of the list and `uniq` keeps the first
|
|
|
|
# element it encounters and discards the rest.
|
|
|
|
outdated.map!{ |f| f.recursive_deps.reject{ |d| d.installed?} << f }
|
|
|
|
outdated.flatten!
|
|
|
|
outdated.uniq!
|
|
|
|
|
2011-08-24 17:33:28 -07:00
|
|
|
if outdated.length > 1
|
2011-08-25 18:02:36 -07:00
|
|
|
oh1 "Upgrading #{outdated.length} outdated package#{outdated.length.plural_s}, with result:"
|
2011-09-11 13:06:05 -07:00
|
|
|
puts outdated.map{ |f| "#{f.name} #{f.version}" } * ", "
|
2011-08-23 23:30:52 +01:00
|
|
|
end
|
|
|
|
|
2011-09-11 13:06:05 -07:00
|
|
|
outdated.each do |f|
|
|
|
|
installer = FormulaInstaller.new f
|
2011-08-23 23:30:52 +01:00
|
|
|
installer.show_header = false
|
2011-09-11 13:06:05 -07:00
|
|
|
oh1 "Upgrading #{f.name}"
|
2011-08-23 23:30:52 +01:00
|
|
|
installer.install
|
2012-02-20 15:02:32 -06:00
|
|
|
Keg.new(f.linked_keg.realpath).unlink if f.linked_keg.directory?
|
2011-08-23 23:30:52 +01:00
|
|
|
installer.caveats
|
|
|
|
installer.finish # includes link step
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|