diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index d2c234bacb..e07aa29eb2 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -1,5 +1,4 @@ require "tap" -require "descriptions" module Homebrew def tap @@ -14,48 +13,22 @@ module Homebrew puts Tap.select(&:pinned?).map(&:name) else user, repo = tap_args - clone_target = ARGV.named[1] - opoo "#{user}/#{repo} already tapped!" unless install_tap(user, repo, clone_target) + tap = Tap.fetch(user, repo) + tap.install(:clone_target => ARGV.named[1], :full_clone => ARGV.include?("--full")) 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) - # ensure git is installed - Utils.ensure_git_installed! - - 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") - + opoo "Homebrew.install_tap is deprecated, use Tap#install." + tap = Tap.fetch(user, repo) 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. - tap.path.parent.rmdir_if_possible - end - raise + tap.install(:clone_target => clone_target, :full_clone => ARGV.include?("--full")) + rescue TapAlreadyTappedError + false + else + true 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 # Migrate tapped formulae from symlink-based to directory-based structure. diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index c70a0d0073..2d08ae8c7a 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -1,5 +1,4 @@ require "cmd/tap" # for tap_args -require "descriptions" module Homebrew def untap @@ -7,17 +6,7 @@ module Homebrew ARGV.named.each do |tapname| tap = Tap.fetch(*tap_args(tapname)) - - 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")}" + tap.uninstall end end end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 436ff89ccb..b732a2a6fb 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -1,4 +1,5 @@ require "utils/json" +require "descriptions" # 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 @@ -89,6 +90,59 @@ class Tap @path.directory? 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. def custom_remote? return true unless remote