63 lines
1.9 KiB
Ruby
Raw Normal View History

2015-06-08 18:05:58 +08:00
require "tap"
module Homebrew
2012-03-02 20:28:54 +00:00
def tap
if ARGV.empty?
2015-06-08 18:05:58 +08:00
puts Tap.names
elsif ARGV.first == "--repair"
migrate_taps :force => true
elsif ARGV.first == "--list-official"
require "official_taps"
2015-08-21 12:33:33 +08:00
puts OFFICIAL_TAPS.map { |t| "homebrew/#{t}" }
elsif ARGV.first == "--list-pinned"
puts Tap.select(&:pinned?).map(&:name)
2012-03-02 20:28:54 +00:00
else
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
def install_tap(user, repo, clone_target = nil)
tap = Tap.new user, repo
2015-06-08 18:05:58 +08:00
return false if tap.installed?
ohai "Tapping #{tap}"
remote = clone_target || "https://github.com/#{tap.user}/homebrew-#{tap.repo}"
args = %W[clone #{remote} #{tap.path}]
args << "--depth=1" unless ARGV.include?("--full")
safe_system "git", *args
2012-03-02 20:28:54 +00:00
2015-06-08 18:05:58 +08:00
formula_count = tap.formula_files.size
puts "Tapped #{formula_count} formula#{plural(formula_count, "e")} (#{tap.path.abv})"
2015-06-08 18:05:58 +08:00
if !clone_target && tap.private?
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:
2015-06-08 18:05:58 +08:00
cd #{tap.path}
git remote set-url origin git@github.com:#{tap.user}/homebrew-#{tap.repo}.git
EOS
end
true
end
# 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.each { |c| c.unlink if c.symlink? }
ignore.unlink if ignore.exist?
end
2012-03-02 20:28:54 +00:00
private
def tap_args(tap_name = ARGV.named.first)
tap_name =~ HOMEBREW_TAP_ARGS_REGEX
raise "Invalid tap name" unless $1 && $3
2012-03-02 20:28:54 +00:00
[$1, $3]
end
2012-03-16 12:49:09 +00:00
end