From 19e387d92e2741fa23cc6fde4743b1b8b28e0fa3 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 23 Aug 2011 23:30:52 +0100 Subject: `brew upgrade` Consequence: you can no longer install when something is already installed, you must upgrade it. This doesn't apply if the formula in question was unlinked. You can still --force installs though. Rationale: the old way of installing over the top would leave symlinks to multiple versions in /usr/local if the old version had a file the newer version didn't. The new upgrade command handles everything properly. --- Library/Homebrew/cmd/help.rb | 2 +- Library/Homebrew/cmd/install.rb | 26 +++++++++++++++----------- Library/Homebrew/cmd/upgrade.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 Library/Homebrew/cmd/upgrade.rb (limited to 'Library/Homebrew/cmd') diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb index 3e7cc75b9..2d55d0427 100644 --- a/Library/Homebrew/cmd/help.rb +++ b/Library/Homebrew/cmd/help.rb @@ -5,7 +5,7 @@ Example usage: brew search [foo] brew list [FORMULA...] brew update - brew outdated + brew upgrade [FORMULA...] brew [info | home] [FORMULA...] Troubleshooting: diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index b7f9e7cae..4b2711994 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -57,22 +57,26 @@ module Homebrew extend self end end - def install_formulae formulae - formulae = [formulae].flatten.compact - return if formulae.empty? - + def perform_preinstall_checks check_ppc check_writable_install_location check_cc check_macports + end - formulae.each do |f| - begin - installer = FormulaInstaller.new f - installer.ignore_deps = ARGV.include? '--ignore-dependencies' - installer.go - rescue FormulaAlreadyInstalledError => e - opoo e.message + def install_formulae formulae + formulae = [formulae].flatten.compact + unless formulae.empty? + perform_preinstall_checks + formulae.each do |f| + begin + fi = FormulaInstaller.new(f) + fi.install + fi.caveats + fi.finish + rescue FormulaAlreadyInstalledError => e + opoo e.message + end end end end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb new file mode 100644 index 000000000..f86e8a871 --- /dev/null +++ b/Library/Homebrew/cmd/upgrade.rb @@ -0,0 +1,35 @@ +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 + ARGV.formulae.map{ |f| [f.prefix.parent, f.name, f.version] } + end + + if outdated.count > 1 + oh1 "Upgrading #{outdated.count} outdated package#{outdated.count.plural_s}, with result:" + puts outdated.map{ |_, name, version| "#{name} #{version}" } * ", " + end + + outdated.each do |rack, name, version| + installer = FormulaInstaller.new(Formula.factory(name)) + installer.show_header = false + oh1 "Upgrading #{name}" + installer.install + Keg.new("#{rack}/#{version}").unlink + installer.caveats + installer.finish # includes link step + end + end +end -- cgit v1.2.3