From 0b216798bb33e63e7b9da795925f610f93cc1e33 Mon Sep 17 00:00:00 2001
From: Alyssa Ross <hi@alyssa.is>
Date: Sun, 15 Jan 2017 17:40:51 +0000
Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"uses:=20properly=20handle?=
 =?UTF-8?q?=20untapped=20fo=E2=80=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

鈥mulae in recursive dependency expansion""

This reverts commit dc9819b86c60b5c6fd10373ff318d8ef60f97d52.
---
 Library/Homebrew/cmd/uses.rb             | 73 ++++++++++++------------
 Library/Homebrew/dependency.rb           |  2 +-
 Library/Homebrew/test/dependency_test.rb |  5 ++
 3 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb
index fb11a31a74..f9af367549 100644
--- a/Library/Homebrew/cmd/uses.rb
+++ b/Library/Homebrew/cmd/uses.rb
@@ -47,48 +47,49 @@ module Homebrew
 
     uses = formulae.select do |f|
       used_formulae.all? do |ff|
-        begin
-          if recursive
-            deps = f.recursive_dependencies do |dependent, dep|
-              if dep.recommended?
-                Dependency.prune if ignores.include?("recommended?") || dependent.build.without?(dep)
-              elsif dep.optional?
-                Dependency.prune if !includes.include?("optional?") && !dependent.build.with?(dep)
-              elsif dep.build?
-                Dependency.prune unless includes.include?("build?")
-              end
+        if recursive
+          deps = f.recursive_dependencies do |dependent, dep|
+            if dep.recommended?
+              Dependency.prune if ignores.include?("recommended?") || dependent.build.without?(dep)
+            elsif dep.optional?
+              Dependency.prune if !includes.include?("optional?") && !dependent.build.with?(dep)
+            elsif dep.build?
+              Dependency.prune unless includes.include?("build?")
             end
-            reqs = f.recursive_requirements do |dependent, req|
-              if req.recommended?
-                Requirement.prune if ignores.include?("recommended?") || dependent.build.without?(req)
-              elsif req.optional?
-                Requirement.prune if !includes.include?("optional?") && !dependent.build.with?(req)
-              elsif req.build?
-                Requirement.prune unless includes.include?("build?")
-              end
-            end
-          else
-            deps = f.deps.reject do |dep|
-              ignores.any? { |ignore| dep.send(ignore) } && !includes.any? { |include| dep.send(include) }
-            end
-            reqs = f.requirements.reject do |req|
-              ignores.any? { |ignore| req.send(ignore) } && !includes.any? { |include| req.send(include) }
+
+            # If a tap isn't installed, we can't find the dependencies of one
+            # its formulae, and an exception will be thrown if we try.
+            if dep.is_a?(TapDependency) && !dep.tap.installed?
+              Dependency.keep_but_prune_recursive_deps
             end
           end
-          next true if deps.any? do |dep|
-            begin
-              dep.to_formula.full_name == ff.full_name
-            rescue
-              dep.name == ff.name
+          reqs = f.recursive_requirements do |dependent, req|
+            if req.recommended?
+              Requirement.prune if ignores.include?("recommended?") || dependent.build.without?(req)
+            elsif req.optional?
+              Requirement.prune if !includes.include?("optional?") && !dependent.build.with?(req)
+            elsif req.build?
+              Requirement.prune unless includes.include?("build?")
             end
           end
-
-          reqs.any? do |req|
-            req.name == ff.name || [ff.name, ff.full_name].include?(req.default_formula)
+        else
+          deps = f.deps.reject do |dep|
+            ignores.any? { |ignore| dep.send(ignore) } && !includes.any? { |include| dep.send(include) }
+          end
+          reqs = f.requirements.reject do |req|
+            ignores.any? { |ignore| req.send(ignore) } && !includes.any? { |include| req.send(include) }
           end
-        rescue FormulaUnavailableError
-          # Silently ignore this case as we don't care about things used in
-          # taps that aren't currently tapped.
+        end
+        next true if deps.any? do |dep|
+          begin
+            dep.to_formula.full_name == ff.full_name
+          rescue
+            dep.name == ff.name
+          end
+        end
+
+        reqs.any? do |req|
+          req.name == ff.name || [ff.name, ff.full_name].include?(req.default_formula)
         end
       end
     end
diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb
index 253ba4bee7..4a452440a7 100644
--- a/Library/Homebrew/dependency.rb
+++ b/Library/Homebrew/dependency.rb
@@ -175,7 +175,7 @@ class TapDependency < Dependency
   attr_reader :tap
 
   def initialize(name, tags = [], env_proc = DEFAULT_ENV_PROC, option_names = [name.split("/").last])
-    @tap = name.rpartition("/").first
+    @tap = Tap.fetch(name.rpartition("/").first)
     super(name, tags, env_proc, option_names)
   end
 
diff --git a/Library/Homebrew/test/dependency_test.rb b/Library/Homebrew/test/dependency_test.rb
index 65255995ec..134e91d130 100644
--- a/Library/Homebrew/test/dependency_test.rb
+++ b/Library/Homebrew/test/dependency_test.rb
@@ -118,6 +118,11 @@ class DependencyTests < Homebrew::TestCase
 end
 
 class TapDependencyTests < Homebrew::TestCase
+  def test_tap
+    dep = TapDependency.new("foo/bar/dog")
+    assert_equal Tap.new("foo", "bar"), dep.tap
+  end
+
   def test_option_names
     dep = TapDependency.new("foo/bar/dog")
     assert_equal %w[dog], dep.option_names
-- 
GitLab