From 5f9140f8a85caddd0ea29ce45e1201ba55e32ee8 Mon Sep 17 00:00:00 2001 From: Dawid Dziurla Date: Fri, 4 Dec 2020 21:19:48 +0100 Subject: [PATCH] untap: add --force switch Co-authored-by: Eric Knibbe --- Library/Homebrew/cmd/untap.rb | 17 +++++++++++++++++ docs/Manpage.md | 3 +++ manpages/brew.1 | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index b83667fed6..538ed707c5 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -2,6 +2,7 @@ # frozen_string_literal: true require "cli/parser" +require "formula" module Homebrew extend T::Sig @@ -16,6 +17,8 @@ module Homebrew Remove a tapped formula repository. EOS + switch "-f", "--force", + description: "Untap even if formulae or casks from this tap are currently installed." min_named 1 end @@ -28,6 +31,20 @@ module Homebrew tap = Tap.fetch(tapname) odie "Untapping #{tap} is not allowed" if tap.core_tap? + installed_tap_formulae = Formula.installed.select { |formula| formula.tap == tap } + installed_tap_casks = Cask::Caskroom.casks.select { |cask| cask.tap == tap } + + if installed_tap_formulae.length.positive? || installed_tap_casks.length.positive? + if args.force? + opoo "Untapping #{tap} even though it contains formulae or casks that are currently installed." + else + odie <<~EOS + Refusing to untap #{tap} because it contains the following installed formulae or casks: + #{(installed_tap_formulae + installed_tap_casks.map(&:token)).join("\n")} + EOS + end + end + tap.uninstall end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 27525453db..ae75704ed2 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -572,6 +572,9 @@ See also `pin`. Remove a tapped formula repository. +* `-f`, `--force`: + Untap even if formulae or casks from this tap are currently installed. + ### `update` [*`options`*] Fetch the newest version of Homebrew and all formulae from GitHub using `git`(1) and perform any necessary migrations. diff --git a/manpages/brew.1 b/manpages/brew.1 index 2e6304a461..28f7cd9b5f 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -770,6 +770,10 @@ Unpin \fIformula\fR, allowing them to be upgraded by \fBbrew upgrade\fR \fIformu .SS "\fBuntap\fR \fItap\fR" Remove a tapped formula repository\. . +.TP +\fB\-f\fR, \fB\-\-force\fR +Untap even if formulae or casks from this tap are currently installed\. +. .SS "\fBupdate\fR [\fIoptions\fR]" Fetch the newest version of Homebrew and all formulae from GitHub using \fBgit\fR(1) and perform any necessary migrations\. .