add Tap#install and Tap#uninstall
This commit is contained in:
parent
889bb5fb03
commit
e97610b916
@ -1,5 +1,4 @@
|
|||||||
require "tap"
|
require "tap"
|
||||||
require "descriptions"
|
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
def tap
|
def tap
|
||||||
@ -14,48 +13,22 @@ module Homebrew
|
|||||||
puts Tap.select(&:pinned?).map(&:name)
|
puts Tap.select(&:pinned?).map(&:name)
|
||||||
else
|
else
|
||||||
user, repo = tap_args
|
user, repo = tap_args
|
||||||
clone_target = ARGV.named[1]
|
tap = Tap.fetch(user, repo)
|
||||||
opoo "#{user}/#{repo} already tapped!" unless install_tap(user, repo, clone_target)
|
tap.install(:clone_target => ARGV.named[1], :full_clone => ARGV.include?("--full"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @deprecated this method will be removed in the future, if no external commands use it.
|
||||||
def install_tap(user, repo, clone_target = nil)
|
def install_tap(user, repo, clone_target = nil)
|
||||||
# ensure git is installed
|
opoo "Homebrew.install_tap is deprecated, use Tap#install."
|
||||||
Utils.ensure_git_installed!
|
tap = Tap.fetch(user, repo)
|
||||||
|
|
||||||
tap = Tap.fetch user, repo
|
|
||||||
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")
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
safe_system "git", *args
|
tap.install(:clone_target => clone_target, :full_clone => ARGV.include?("--full"))
|
||||||
rescue Interrupt, ErrorDuringExecution
|
rescue TapAlreadyTappedError
|
||||||
ignore_interrupts do
|
false
|
||||||
sleep 0.1 # wait for git to cleanup the top directory when interrupt happens.
|
else
|
||||||
tap.path.parent.rmdir_if_possible
|
true
|
||||||
end
|
|
||||||
raise
|
|
||||||
end
|
end
|
||||||
|
|
||||||
formula_count = tap.formula_files.size
|
|
||||||
puts "Tapped #{formula_count} formula#{plural(formula_count, "e")} (#{tap.path.abv})"
|
|
||||||
Descriptions.cache_formulae(tap.formula_names)
|
|
||||||
|
|
||||||
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 #{tap.path}
|
|
||||||
git remote set-url origin git@github.com:#{tap.user}/homebrew-#{tap.repo}.git
|
|
||||||
EOS
|
|
||||||
end
|
|
||||||
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Migrate tapped formulae from symlink-based to directory-based structure.
|
# Migrate tapped formulae from symlink-based to directory-based structure.
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
require "cmd/tap" # for tap_args
|
require "cmd/tap" # for tap_args
|
||||||
require "descriptions"
|
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
def untap
|
def untap
|
||||||
@ -7,17 +6,7 @@ module Homebrew
|
|||||||
|
|
||||||
ARGV.named.each do |tapname|
|
ARGV.named.each do |tapname|
|
||||||
tap = Tap.fetch(*tap_args(tapname))
|
tap = Tap.fetch(*tap_args(tapname))
|
||||||
|
tap.uninstall
|
||||||
raise TapUnavailableError, tap.name unless tap.installed?
|
|
||||||
puts "Untapping #{tap}... (#{tap.path.abv})"
|
|
||||||
|
|
||||||
tap.unpin if tap.pinned?
|
|
||||||
|
|
||||||
formula_count = tap.formula_files.size
|
|
||||||
Descriptions.uncache_formulae(tap.formula_names)
|
|
||||||
tap.path.rmtree
|
|
||||||
tap.path.dirname.rmdir_if_possible
|
|
||||||
puts "Untapped #{formula_count} formula#{plural(formula_count, "e")}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require "utils/json"
|
require "utils/json"
|
||||||
|
require "descriptions"
|
||||||
|
|
||||||
# a {Tap} is used to extend the formulae provided by Homebrew core.
|
# a {Tap} is used to extend the formulae provided by Homebrew core.
|
||||||
# Usually, it's synced with a remote git repository. And it's likely
|
# Usually, it's synced with a remote git repository. And it's likely
|
||||||
@ -89,6 +90,59 @@ class Tap
|
|||||||
@path.directory?
|
@path.directory?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# install this {Tap}.
|
||||||
|
#
|
||||||
|
# @param [Hash] options
|
||||||
|
# @option options [String] :clone_targe If passed, it will be used as the clone remote.
|
||||||
|
# @option options [Boolean] :full_clone If set as true, full clone will be used.
|
||||||
|
def install(options = {})
|
||||||
|
raise TapAlreadyTappedError, name if installed?
|
||||||
|
|
||||||
|
# ensure git is installed
|
||||||
|
Utils.ensure_git_installed!
|
||||||
|
ohai "Tapping #{name}"
|
||||||
|
remote = options[:clone_target] || "https://github.com/#{@user}/homebrew-#{@repo}"
|
||||||
|
args = %W[clone #{remote} #{@path}]
|
||||||
|
args << "--depth=1" unless options.fetch(:full_clone, false)
|
||||||
|
|
||||||
|
begin
|
||||||
|
safe_system "git", *args
|
||||||
|
rescue Interrupt, ErrorDuringExecution
|
||||||
|
ignore_interrupts do
|
||||||
|
sleep 0.1 # wait for git to cleanup the top directory when interrupt happens.
|
||||||
|
@path.parent.rmdir_if_possible
|
||||||
|
end
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
|
||||||
|
formula_count = formula_files.size
|
||||||
|
puts "Tapped #{formula_count} formula#{plural(formula_count, "e")} (#{@path.abv})"
|
||||||
|
Descriptions.cache_formulae(formula_names)
|
||||||
|
|
||||||
|
if !options[:clone_target] && 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 #{@path}
|
||||||
|
git remote set-url origin git@github.com:#{@user}/homebrew-#{@repo}.git
|
||||||
|
EOS
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# uninstall this {Tap}.
|
||||||
|
def uninstall
|
||||||
|
raise TapUnavailableError, name unless installed?
|
||||||
|
|
||||||
|
puts "Untapping #{name}... (#{@path.abv})"
|
||||||
|
unpin if pinned?
|
||||||
|
formula_count = formula_files.size
|
||||||
|
Descriptions.uncache_formulae(formula_names)
|
||||||
|
@path.rmtree
|
||||||
|
@path.dirname.rmdir_if_possible
|
||||||
|
puts "Untapped #{formula_count} formula#{plural(formula_count, "e")}"
|
||||||
|
end
|
||||||
|
|
||||||
# True if the {#remote} of {Tap} is customized.
|
# True if the {#remote} of {Tap} is customized.
|
||||||
def custom_remote?
|
def custom_remote?
|
||||||
return true unless remote
|
return true unless remote
|
||||||
|
Loading…
x
Reference in New Issue
Block a user