aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/switch.rb3
-rw-r--r--Library/Homebrew/extend/ARGV.rb12
-rw-r--r--Library/Homebrew/formulary.rb18
3 files changed, 25 insertions, 8 deletions
diff --git a/Library/Homebrew/cmd/switch.rb b/Library/Homebrew/cmd/switch.rb
index 5efebd7e5..b4c3c43d9 100644
--- a/Library/Homebrew/cmd/switch.rb
+++ b/Library/Homebrew/cmd/switch.rb
@@ -12,8 +12,7 @@ module Homebrew
name = ARGV.shift
version = ARGV.shift
- canonical_name = Formulary.canonical_name(name)
- rack = HOMEBREW_CELLAR.join(canonical_name)
+ rack = Formulary.to_rack(name)
unless rack.directory?
onoe "#{name} not found in the Cellar."
diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb
index 5a13230ac..66ff3dfd5 100644
--- a/Library/Homebrew/extend/ARGV.rb
+++ b/Library/Homebrew/extend/ARGV.rb
@@ -47,14 +47,14 @@ module HomebrewArgvExtension
require "keg"
require "formula"
@kegs ||= downcased_unique_named.collect do |name|
- canonical_name = Formulary.canonical_name(name)
- rack = HOMEBREW_CELLAR/canonical_name
+ rack = Formulary.to_rack(name)
+
dirs = rack.directory? ? rack.subdirs : []
- raise NoSuchKegError.new(canonical_name) if dirs.empty?
+ raise NoSuchKegError.new(rack.basename) if dirs.empty?
- linked_keg_ref = HOMEBREW_LIBRARY.join("LinkedKegs", canonical_name)
- opt_prefix = HOMEBREW_PREFIX.join("opt", canonical_name)
+ linked_keg_ref = HOMEBREW_LIBRARY.join("LinkedKegs", rack.basename)
+ opt_prefix = HOMEBREW_PREFIX.join("opt", rack.basename)
begin
if opt_prefix.symlink? && opt_prefix.directory?
@@ -66,7 +66,7 @@ module HomebrewArgvExtension
elsif (prefix = (name.include?("/") ? Formulary.factory(name) : Formulary.from_rack(rack)).prefix).directory?
Keg.new(prefix)
else
- raise MultipleVersionsInstalledError.new(canonical_name)
+ raise MultipleVersionsInstalledError.new(rack.basename)
end
rescue FormulaUnavailableError
raise <<-EOS.undent
diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb
index 4a31b3121..8fcffb59e 100644
--- a/Library/Homebrew/formulary.rb
+++ b/Library/Homebrew/formulary.rb
@@ -195,6 +195,24 @@ class Formulary
end
end
+ def self.to_rack(ref)
+ name = canonical_name(ref)
+ rack = HOMEBREW_CELLAR/name
+
+ # Handle the case when ref is an old name and the installation
+ # hasn't been migrated or when it's a package installed from
+ # path but same name formula was renamed.
+ unless rack.directory?
+ if ref =~ HOMEBREW_TAP_FORMULA_REGEX
+ rack = HOMEBREW_CELLAR/$3
+ elsif !ref.include?("/")
+ rack = HOMEBREW_CELLAR/ref
+ end
+ end
+
+ rack
+ end
+
def self.canonical_name(ref)
loader_for(ref).name
rescue TapFormulaAmbiguityError