From 7e14ec0ba67d681d1fe61d508bf9dd5aee531696 Mon Sep 17 00:00:00 2001
From: Xu Cheng <xucheng@me.com>
Date: Sat, 16 Jul 2016 21:05:28 +0800
Subject: [PATCH] ARGV#kegs: using installed_prefix to locate keg

---
 Library/Homebrew/extend/ARGV.rb | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/Library/Homebrew/extend/ARGV.rb b/Library/Homebrew/extend/ARGV.rb
index 934db177b8..0f19c6157c 100644
--- a/Library/Homebrew/extend/ARGV.rb
+++ b/Library/Homebrew/extend/ARGV.rb
@@ -49,7 +49,7 @@ module HomebrewArgvExtension
     require "keg"
     require "formula"
     @kegs ||= downcased_unique_named.collect do |name|
-      rack = Formulary.to_rack(name)
+      rack = Formulary.to_rack(name.downcase)
 
       dirs = rack.directory? ? rack.subdirs : []
 
@@ -65,10 +65,18 @@ module HomebrewArgvExtension
           Keg.new(linked_keg_ref.resolved_path)
         elsif dirs.length == 1
           Keg.new(dirs.first)
-        elsif (prefix = (name.include?("/") ? Formulary.factory(name) : Formulary.from_rack(rack)).prefix).directory?
-          Keg.new(prefix)
         else
-          raise MultipleVersionsInstalledError.new(rack.basename)
+          f = if name.include?("/") || File.exist?(name)
+            Formulary.factory(name)
+          else
+            Formulary.from_rack(rack)
+          end
+
+          if (prefix = f.installed_prefix).directory?
+            Keg.new(prefix)
+          else
+            raise MultipleVersionsInstalledError.new(rack.basename)
+          end
         end
       rescue FormulaUnavailableError
         raise <<-EOS.undent
-- 
GitLab