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