aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2014-04-27 17:27:22 -0500
committerJack Nagel2014-04-27 17:28:19 -0500
commit0291a579fbca3ed66a439835a8da3bd16a5378f6 (patch)
treec8c5ef8e692087ff1c43a6aef0e4f6f3f28dffb8 /Library
parentccc62a0cad3816389db805143f39013218b57bce (diff)
downloadbrew-0291a579fbca3ed66a439835a8da3bd16a5378f6.tar.bz2
Respect tap directory layout when searching
This matches the logic in find_formula.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/search.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index a912af39c..180deeadd 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`"
[]