From 0291a579fbca3ed66a439835a8da3bd16a5378f6 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 27 Apr 2014 17:27:22 -0500 Subject: [PATCH] Respect tap directory layout when searching This matches the logic in find_formula. --- Library/Homebrew/cmd/search.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index a912af39ce..180deeaddc 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -97,19 +97,27 @@ module Homebrew extend self return [] if (HOMEBREW_LIBRARY/"Taps/#{user.downcase}/homebrew-#{repo.downcase}").directory? results = [] + tree = {} + GitHub.open "https://api.github.com/repos/#{user}/homebrew-#{repo}/git/trees/HEAD?recursive=1" do |json| user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization json["tree"].each do |object| next unless object["type"] == "blob" - path = object["path"] - name = File.basename(path, ".rb") + subtree, file = File.split(object["path"]) - if path.end_with?(".rb") && rx === name - results << "#{user}/#{repo}/#{name}" + if File.extname(file) == ".rb" + tree[subtree] ||= [] + tree[subtree] << file end end end + + paths = tree["Formula"] || tree["HomebrewFormula"] || tree["."] || [] + paths.each do |path| + name = File.basename(path, ".rb") + results << "#{user}/#{repo}/#{name}" if rx === name + end rescue GitHub::HTTPNotFoundError => e opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`" []