aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorPeter Aronoff2013-03-12 12:32:49 +0000
committerMike McQuaid2013-03-12 12:32:49 +0000
commitd72901f92b7385d44d8c980976db6a4336572e7e (patch)
tree5944f2eb2ffbf580c8fc60b0287d949a75739bf4 /Library
parent52e0cdefd55718711fedf2123e3d1c025057ac5e (diff)
downloadhomebrew-d72901f92b7385d44d8c980976db6a4336572e7e.tar.bz2
Update `brew tap` to work without 'homebrew-'
Currently `brew tap` only works on repos with 'homebrew-' in their name. This version tries the repo name as is and then falls back to try 'homebrew-repo' only if that fails. I've also tweaked the regex in tap_args to allow '-' in repo names. The previous regex required a match on \w. This made it impossible for people to tap repos with names like 'username/why-not'. Closes #18366. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/tap.rb22
1 files changed, 18 insertions, 4 deletions
diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb
index 5bd37548f..a091da055 100644
--- a/Library/Homebrew/cmd/tap.rb
+++ b/Library/Homebrew/cmd/tap.rb
@@ -24,7 +24,21 @@ module Homebrew extend self
# we downcase to avoid case-insensitive filesystem issues
tapd = HOMEBREW_LIBRARY/"Taps/#{user.downcase}-#{repo.downcase}"
raise "Already tapped!" if tapd.directory?
- abort unless system "git clone https://github.com/#{repouser}/homebrew-#{repo} #{tapd}"
+ # First try tapping the repo name as is. If that fails, fall back to
+ # 'homebrew-repo'.
+ stdout = `git clone https://github.com/#{repouser}/#{repo} #{tapd} 2>/dev/null`
+ unless $?.success?
+ stdout = `git clone https://github.com/#{repouser}/homebrew-#{repo} #{tapd} 2>&1`
+ if $?.success?
+ repo = "homebrew-" + repo
+ else
+ abort <<-EOS.undent
+ Neither #{repouser}/#{repo} nor #{repouser}/homebrew-#{repo} tapped.
+ Please check the tap name and try again.
+ EOS
+ end
+ end
+ puts stdout
files = []
tapd.find_formula{ |file| files << tapd.basename.join(file) }
@@ -34,7 +48,7 @@ module Homebrew extend self
# Figure out if this repo is private
# curl will throw an exception if the repo is private (Github returns a 404)
begin
- curl('-Ifso', '/dev/null', "https://api.github.com/repos/#{repouser}/homebrew-#{repo}")
+ curl('-Ifso', '/dev/null', "https://api.github.com/repos/#{repouser}/#{repo}")
rescue
puts
puts "It looks like you tapped a private repository"
@@ -43,7 +57,7 @@ module Homebrew extend self
puts "following command:"
puts
puts " cd #{tapd}"
- puts " git remote set-url origin git@github.com:#{repouser}/homebrew-#{repo}.git"
+ puts " git remote set-url origin git@github.com:#{repouser}/#{repo}.git"
puts
end
end
@@ -102,7 +116,7 @@ module Homebrew extend self
private
def tap_args
- ARGV.first =~ %r{^(\S+)/(homebrew-)?(\w+)$}
+ ARGV.first =~ %r{^(\S+)/(homebrew-)?([-\w]+)$}
raise "Invalid usage" unless $1 and $3
[$1, $3]
end