2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2012-03-02 20:28:54 +00:00
|
|
|
def tap
|
|
|
|
if ARGV.empty?
|
2014-04-25 11:25:38 -05:00
|
|
|
each_tap do |user, repo|
|
|
|
|
puts "#{user.basename}/#{repo.basename.sub("homebrew-", "")}" if (repo/".git").directory?
|
|
|
|
end
|
2012-08-04 15:06:37 -04:00
|
|
|
elsif ARGV.first == "--repair"
|
2015-05-08 20:19:12 +08:00
|
|
|
migrate_taps :force => true
|
2012-03-02 20:28:54 +00:00
|
|
|
else
|
2015-06-02 17:27:05 -04:00
|
|
|
user, repo = tap_args
|
|
|
|
clone_target = ARGV.named[1]
|
|
|
|
opoo "Already tapped!" unless install_tap(user, repo, clone_target)
|
2012-03-02 20:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-02 17:27:05 -04:00
|
|
|
def install_tap user, repo, clone_target=nil
|
2012-03-18 01:45:26 +00:00
|
|
|
# we special case homebrew so users don't have to shift in a terminal
|
|
|
|
repouser = if user == "homebrew" then "Homebrew" else user end
|
|
|
|
user = "homebrew" if user == "Homebrew"
|
|
|
|
|
|
|
|
# we downcase to avoid case-insensitive filesystem issues
|
2014-04-24 11:26:45 +09:00
|
|
|
tapd = HOMEBREW_LIBRARY/"Taps/#{user.downcase}/homebrew-#{repo.downcase}"
|
2014-01-03 21:51:23 +00:00
|
|
|
return false if tapd.directory?
|
2015-04-09 09:00:18 +01:00
|
|
|
ohai "Tapping #{repouser}/#{repo}"
|
2015-06-02 17:27:05 -04:00
|
|
|
if clone_target
|
|
|
|
args = %W[clone #{clone_target} #{tapd}]
|
|
|
|
else
|
|
|
|
args = %W[clone https://github.com/#{repouser}/homebrew-#{repo} #{tapd}]
|
|
|
|
end
|
2015-04-01 20:31:17 +08:00
|
|
|
args << "--depth=1" unless ARGV.include?("--full")
|
|
|
|
safe_system "git", *args
|
2012-03-02 20:28:54 +00:00
|
|
|
|
2012-03-07 22:48:44 +00:00
|
|
|
files = []
|
2014-04-25 18:58:16 -05:00
|
|
|
tapd.find_formula { |file| files << file }
|
2015-04-09 09:00:18 +01:00
|
|
|
puts "Tapped #{files.length} formula#{plural(files.length, 'e')} (#{tapd.abv})"
|
2012-05-14 16:18:24 -06:00
|
|
|
|
2015-06-02 17:27:05 -04:00
|
|
|
if check_private?(clone_target, repouser, repo)
|
|
|
|
puts <<-EOS.undent
|
|
|
|
It looks like you tapped a private repository. To avoid entering your
|
|
|
|
credentials each time you update, you can use git HTTP credential
|
|
|
|
caching or issue the following command:
|
2014-02-08 20:41:11 -05:00
|
|
|
|
2015-06-02 17:27:05 -04:00
|
|
|
cd #{tapd}
|
|
|
|
git remote set-url origin git@github.com:#{repouser}/homebrew-#{repo}.git
|
|
|
|
EOS
|
2012-05-14 16:18:24 -06:00
|
|
|
end
|
2014-01-03 21:51:23 +00:00
|
|
|
|
|
|
|
true
|
2012-03-07 22:48:44 +00:00
|
|
|
end
|
|
|
|
|
2015-05-08 20:19:12 +08:00
|
|
|
# Migrate tapped formulae from symlink-based to directory-based structure.
|
|
|
|
def migrate_taps(options={})
|
|
|
|
ignore = HOMEBREW_LIBRARY/"Formula/.gitignore"
|
|
|
|
return unless ignore.exist? || options.fetch(:force, false)
|
|
|
|
(HOMEBREW_LIBRARY/"Formula").children.select(&:symlink?).each(&:unlink)
|
|
|
|
ignore.unlink if ignore.exist?
|
2012-08-04 15:06:37 -04:00
|
|
|
end
|
|
|
|
|
2012-03-02 20:28:54 +00:00
|
|
|
private
|
|
|
|
|
2014-04-25 11:25:38 -05:00
|
|
|
def each_tap
|
|
|
|
taps = HOMEBREW_LIBRARY.join("Taps")
|
|
|
|
|
|
|
|
if taps.directory?
|
|
|
|
taps.subdirs.each do |user|
|
|
|
|
user.subdirs.each do |repo|
|
|
|
|
yield user, repo
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-01 20:31:17 +08:00
|
|
|
def tap_args(tap_name=ARGV.named.first)
|
2015-02-01 12:11:54 -05:00
|
|
|
tap_name =~ HOMEBREW_TAP_ARGS_REGEX
|
2014-01-12 00:20:33 +09:00
|
|
|
raise "Invalid tap name" unless $1 && $3
|
2012-03-02 20:28:54 +00:00
|
|
|
[$1, $3]
|
|
|
|
end
|
|
|
|
|
2014-02-08 20:41:11 -05:00
|
|
|
def private_tap?(user, repo)
|
|
|
|
GitHub.private_repo?(user, "homebrew-#{repo}")
|
2014-02-23 23:04:44 -05:00
|
|
|
rescue GitHub::HTTPNotFoundError
|
2014-02-08 20:41:11 -05:00
|
|
|
true
|
|
|
|
rescue GitHub::Error
|
|
|
|
false
|
|
|
|
end
|
2015-06-02 17:27:05 -04:00
|
|
|
|
|
|
|
def check_private?(clone_target, user, repo)
|
2015-06-08 22:13:50 +08:00
|
|
|
!clone_target && private_tap?(user, repo)
|
2015-06-02 17:27:05 -04:00
|
|
|
end
|
2012-03-16 12:49:09 +00:00
|
|
|
end
|