(un)tap/update/readall: use Tap class
This commit is contained in:
parent
f7bcfe5115
commit
44383fecb8
@ -34,12 +34,9 @@ module Homebrew
|
||||
if ARGV.named.empty?
|
||||
formulae = Formula.full_names
|
||||
else
|
||||
user, repo = tap_args
|
||||
user.downcase!
|
||||
repo.downcase!
|
||||
tap = HOMEBREW_LIBRARY/"Taps/#{user}/homebrew-#{repo}"
|
||||
raise "#{tap} does not exist!" unless tap.directory?
|
||||
tap.find_formula { |f| formulae << f }
|
||||
tap = Tap.new(*tap_args)
|
||||
raise "#{tap} does not exist!" unless tap.installed?
|
||||
formulae = tap.formula_files
|
||||
end
|
||||
|
||||
formulae.sort.each do |n|
|
||||
|
@ -1,9 +1,9 @@
|
||||
require "tap"
|
||||
|
||||
module Homebrew
|
||||
def tap
|
||||
if ARGV.empty?
|
||||
each_tap do |user, repo|
|
||||
puts "#{user.basename}/#{repo.basename.sub("homebrew-", "")}" if (repo/".git").directory?
|
||||
end
|
||||
puts Tap.names
|
||||
elsif ARGV.first == "--repair"
|
||||
migrate_taps :force => true
|
||||
else
|
||||
@ -14,35 +14,25 @@ module Homebrew
|
||||
end
|
||||
|
||||
def install_tap user, repo, clone_target=nil
|
||||
# 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
|
||||
tapd = HOMEBREW_LIBRARY/"Taps/#{user.downcase}/homebrew-#{repo.downcase}"
|
||||
return false if tapd.directory?
|
||||
ohai "Tapping #{repouser}/#{repo}"
|
||||
if clone_target
|
||||
args = %W[clone #{clone_target} #{tapd}]
|
||||
else
|
||||
args = %W[clone https://github.com/#{repouser}/homebrew-#{repo} #{tapd}]
|
||||
end
|
||||
tap = Tap.new user, repo, clone_target
|
||||
return false if tap.installed?
|
||||
ohai "Tapping #{tap}"
|
||||
args = %W[clone #{tap.remote} #{tap.path}]
|
||||
args << "--depth=1" unless ARGV.include?("--full")
|
||||
safe_system "git", *args
|
||||
|
||||
files = []
|
||||
tapd.find_formula { |file| files << file }
|
||||
puts "Tapped #{files.length} formula#{plural(files.length, 'e')} (#{tapd.abv})"
|
||||
formula_count = tap.formula_files.size
|
||||
puts "Tapped #{formula_count} formula#{plural(formula_count, 'e')} (#{tap.path.abv})"
|
||||
|
||||
if check_private?(clone_target, repouser, repo)
|
||||
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:
|
||||
|
||||
cd #{tapd}
|
||||
git remote set-url origin git@github.com:#{repouser}/homebrew-#{repo}.git
|
||||
EOS
|
||||
cd #{tap.path}
|
||||
git remote set-url origin git@github.com:#{tap.user}/homebrew-#{tap.repo}.git
|
||||
EOS
|
||||
end
|
||||
|
||||
true
|
||||
@ -58,33 +48,9 @@ module Homebrew
|
||||
|
||||
private
|
||||
|
||||
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
|
||||
|
||||
def tap_args(tap_name=ARGV.named.first)
|
||||
tap_name =~ HOMEBREW_TAP_ARGS_REGEX
|
||||
raise "Invalid tap name" unless $1 && $3
|
||||
[$1, $3]
|
||||
end
|
||||
|
||||
def private_tap?(user, repo)
|
||||
GitHub.private_repo?(user, "homebrew-#{repo}")
|
||||
rescue GitHub::HTTPNotFoundError
|
||||
true
|
||||
rescue GitHub::Error
|
||||
false
|
||||
end
|
||||
|
||||
def check_private?(clone_target, user, repo)
|
||||
!clone_target && private_tap?(user, repo)
|
||||
end
|
||||
end
|
||||
|
@ -4,26 +4,16 @@ module Homebrew
|
||||
def untap
|
||||
raise "Usage is `brew untap <tap-name>`" if ARGV.empty?
|
||||
|
||||
ARGV.each do |tapname|
|
||||
user, repo = tap_args(tapname)
|
||||
ARGV.named.each do |tapname|
|
||||
tap = Tap.new(*tap_args(tapname))
|
||||
|
||||
# We consistently downcase in tap to ensure we are not bitten by
|
||||
# case-insensitive filesystem issues, which is the default on mac. The
|
||||
# problem being the filesystem cares, but our regexps don't. So unless we
|
||||
# resolve *every* path we will get bitten.
|
||||
user.downcase!
|
||||
repo.downcase!
|
||||
raise "No such tap!" unless tap.installed?
|
||||
puts "Untapping #{tap}... (#{tap.path.abv})"
|
||||
|
||||
tapd = HOMEBREW_LIBRARY/"Taps/#{user}/homebrew-#{repo}"
|
||||
|
||||
raise "No such tap!" unless tapd.directory?
|
||||
puts "Untapping #{tapname}... (#{tapd.abv})"
|
||||
|
||||
files = []
|
||||
tapd.find_formula { |file| files << file }
|
||||
tapd.rmtree
|
||||
tapd.dirname.rmdir_if_possible
|
||||
puts "Untapped #{files.length} formula#{plural(files.length, 'e')}"
|
||||
formula_count = tap.formula_files.size
|
||||
tap.path.rmtree
|
||||
tap.path.dirname.rmdir_if_possible
|
||||
puts "Untapped #{formula_count} formula#{plural(formula_count, 'e')}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -27,14 +27,14 @@ module Homebrew
|
||||
# this procedure will be removed in the future if it seems unnecessasry
|
||||
rename_taps_dir_if_necessary
|
||||
|
||||
each_tap do |user, repo|
|
||||
repo.cd do
|
||||
updater = Updater.new(repo)
|
||||
Tap.each do |tap|
|
||||
tap.path.cd do
|
||||
updater = Updater.new(tap.path)
|
||||
|
||||
begin
|
||||
updater.pull!
|
||||
rescue
|
||||
onoe "Failed to update tap: #{user.basename}/#{repo.basename.sub("homebrew-", "")}"
|
||||
onoe "Failed to update tap: #{tap}"
|
||||
else
|
||||
report.update(updater.report) do |key, oldval, newval|
|
||||
oldval.concat(newval)
|
||||
|
Loading…
x
Reference in New Issue
Block a user