From 3b6d80913a36d7db64aa3aa11766c6ee72b0aa29 Mon Sep 17 00:00:00 2001
From: Markus Reiter <me@reitermark.us>
Date: Mon, 12 Sep 2016 06:18:55 +0200
Subject: [PATCH] Fix cask installation from untapped Tap not working.

---
 .../cask/lib/hbc/source/tapped_qualified.rb        | 14 ++++++++++++--
 .../cask/lib/hbc/source/untapped_qualified.rb      |  9 ++++-----
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb b/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb
index 48f8501e54..1da013db2d 100644
--- a/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb
+++ b/Library/Homebrew/cask/lib/hbc/source/tapped_qualified.rb
@@ -2,11 +2,21 @@ require "hbc/source/tapped"
 
 class Hbc::Source::TappedQualified < Hbc::Source::Tapped
   def self.me?(query)
-    !Hbc::QualifiedToken.parse(query).nil? && path_for_query(query).exist?
+    return if (tap = tap_for_query(query)).nil?
+
+    tap.installed? && path_for_query(query).exist?
+  end
+
+  def self.tap_for_query(query)
+    qualified_token = Hbc::QualifiedToken.parse(query)
+    return if qualified_token.nil?
+
+    user, repo, token = qualified_token
+    Tap.fetch(user, repo)
   end
 
   def self.path_for_query(query)
     user, repo, token = Hbc::QualifiedToken.parse(query)
-    Tap.new(user, repo).cask_dir.join(token.sub(%r{(\.rb)?$}i, ".rb"))
+    Tap.fetch(user, repo).cask_dir.join(token.sub(%r{(\.rb)?$}i, ".rb"))
   end
 end
diff --git a/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb b/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb
index 361919bb38..7188d34cef 100644
--- a/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb
+++ b/Library/Homebrew/cask/lib/hbc/source/untapped_qualified.rb
@@ -1,11 +1,10 @@
 require "hbc/source/tapped_qualified"
 
 class Hbc::Source::UntappedQualified < Hbc::Source::TappedQualified
-  def self.path_for_query(query)
-    user, repo, token = Hbc::QualifiedToken.parse(query)
+  def self.me?(query)
+    return if (tap = tap_for_query(query)).nil?
 
-    tap = Tap.fetch(user, repo)
-    tap.install unless tap.installed?
-    tap.cask_dir.join(token.sub(%r{(\.rb)?$}i, ".rb"))
+    tap.install
+    tap.installed? && path_for_query(query).exist?
   end
 end
-- 
GitLab