From 3ca68c076ef58c54e1af58950b1dc78d1d32da23 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Tue, 19 Jan 2021 17:55:03 -0500 Subject: [PATCH 1/4] Don't tap user-untapped official taps --- Library/Homebrew/brew.rb | 5 ++++- Library/Homebrew/extend/os/mac/tap.rb | 3 +++ Library/Homebrew/tap.rb | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index a6299cdc44..be7af80553 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -132,7 +132,10 @@ begin possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) } possible_tap = Tap.fetch(possible_tap.first) if possible_tap - odie "Unknown command: #{cmd}" if !possible_tap || possible_tap.installed? + untapped_official_taps = Homebrew::Settings.read(:untapped)&.split(";") || [] + if !possible_tap || possible_tap.installed? || untapped_official_taps.include?(possible_tap.name) + odie "Unknown command: #{cmd}" + end # Unset HOMEBREW_HELP to avoid confusing the tap with_env HOMEBREW_HELP: nil do diff --git a/Library/Homebrew/extend/os/mac/tap.rb b/Library/Homebrew/extend/os/mac/tap.rb index 495901ea68..e64fc7cfc9 100644 --- a/Library/Homebrew/extend/os/mac/tap.rb +++ b/Library/Homebrew/extend/os/mac/tap.rb @@ -5,6 +5,9 @@ class Tap def self.install_default_cask_tap_if_necessary return false if default_cask_tap.installed? + untapped_official_taps = Homebrew::Settings.read(:untapped)&.split(";") || [] + return false if untapped_official_taps.include?(default_cask_tap.name) + default_cask_tap.install true end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 2e75f812fa..3580d5e41f 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -326,6 +326,17 @@ class Tap .update_from_formula_names!(formula_names) end + if official? + untapped = Homebrew::Settings.read(:untapped)&.split(";") || [] + untapped -= [name] + + if untapped.empty? + Homebrew::Settings.delete :untapped + else + Homebrew::Settings.write :untapped, untapped.join(";") + end + end + return if clone_target return unless private? return if quiet @@ -374,6 +385,15 @@ class Tap Commands.rebuild_commands_completion_list clear_cache + + return unless official? + + untapped = Homebrew::Settings.read(:untapped)&.split(";") || [] + + return if untapped.include? name + + untapped << name + Homebrew::Settings.write :untapped, untapped.join(";") end # True if the {#remote} of {Tap} is customized. From ebba3698877b6beb14fdaf2f8f420c7b99c913df Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 20 Jan 2021 12:02:24 -0500 Subject: [PATCH 2/4] Tap: add untapped_official_taps method --- Library/Homebrew/brew.rb | 3 +-- Library/Homebrew/extend/os/mac/tap.rb | 3 +-- Library/Homebrew/tap.rb | 11 ++++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index be7af80553..4edc7d5a2a 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -132,8 +132,7 @@ begin possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) } possible_tap = Tap.fetch(possible_tap.first) if possible_tap - untapped_official_taps = Homebrew::Settings.read(:untapped)&.split(";") || [] - if !possible_tap || possible_tap.installed? || untapped_official_taps.include?(possible_tap.name) + if !possible_tap || possible_tap.installed? || Tap.untapped_official_taps.include?(possible_tap.name) odie "Unknown command: #{cmd}" end diff --git a/Library/Homebrew/extend/os/mac/tap.rb b/Library/Homebrew/extend/os/mac/tap.rb index e64fc7cfc9..25dcb2042f 100644 --- a/Library/Homebrew/extend/os/mac/tap.rb +++ b/Library/Homebrew/extend/os/mac/tap.rb @@ -5,8 +5,7 @@ class Tap def self.install_default_cask_tap_if_necessary return false if default_cask_tap.installed? - untapped_official_taps = Homebrew::Settings.read(:untapped)&.split(";") || [] - return false if untapped_official_taps.include?(default_cask_tap.name) + return false if Tap.untapped_official_taps.include?(default_cask_tap.name) default_cask_tap.install true diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 3580d5e41f..bbf73c37a8 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -327,7 +327,7 @@ class Tap end if official? - untapped = Homebrew::Settings.read(:untapped)&.split(";") || [] + untapped = self.class.untapped_official_taps untapped -= [name] if untapped.empty? @@ -388,8 +388,7 @@ class Tap return unless official? - untapped = Homebrew::Settings.read(:untapped)&.split(";") || [] - + untapped = self.class.untapped_official_taps return if untapped.include? name untapped << name @@ -644,6 +643,12 @@ class Tap Pathname.glob TAP_DIRECTORY/"*/*/cmd" end + # An array of official taps that have been manually untapped + sig { returns(T::Array[String]) } + def self.untapped_official_taps + Homebrew::Settings.read(:untapped)&.split(";") || [] + end + # @private def formula_file_to_name(file) "#{name}/#{file.basename(".rb")}" From 64816651d0d0ce23bffe4b7ea2723ea34f1a2649 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Wed, 20 Jan 2021 12:13:22 -0500 Subject: [PATCH 3/4] Only tap homebrew/cask on CaskUnavailableError in brew install --- Library/Homebrew/cli/named_args.rb | 2 -- Library/Homebrew/cmd/install.rb | 10 ++++++++-- Library/Homebrew/extend/os/mac/tap.rb | 4 ++-- Library/Homebrew/tap.rb | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cli/named_args.rb b/Library/Homebrew/cli/named_args.rb index f1f5bf2ad2..c7a509b80c 100644 --- a/Library/Homebrew/cli/named_args.rb +++ b/Library/Homebrew/cli/named_args.rb @@ -99,8 +99,6 @@ module Homebrew begin return Cask::CaskLoader.load(name, config: Cask::Config.from_args(@parent)) rescue Cask::CaskUnavailableError => e - retry if Tap.install_default_cask_tap_if_necessary - raise e if only == :cask end end diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 8be132b70a..14455e8bd1 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -153,8 +153,14 @@ module Homebrew EOS end - formulae, casks = args.named.to_formulae_and_casks - .partition { |formula_or_cask| formula_or_cask.is_a?(Formula) } + begin + formulae, casks = args.named.to_formulae_and_casks + .partition { |formula_or_cask| formula_or_cask.is_a?(Formula) } + rescue FormulaOrCaskUnavailableError, Cask::CaskUnavailableError => e + retry if Tap.install_default_cask_tap_if_necessary(force: args.cask?) + + raise e + end if casks.any? Cask::Cmd::Install.install_casks( diff --git a/Library/Homebrew/extend/os/mac/tap.rb b/Library/Homebrew/extend/os/mac/tap.rb index 25dcb2042f..ca2701238a 100644 --- a/Library/Homebrew/extend/os/mac/tap.rb +++ b/Library/Homebrew/extend/os/mac/tap.rb @@ -2,10 +2,10 @@ # frozen_string_literal: true class Tap - def self.install_default_cask_tap_if_necessary + def self.install_default_cask_tap_if_necessary(force: false) return false if default_cask_tap.installed? - return false if Tap.untapped_official_taps.include?(default_cask_tap.name) + return false if !force && Tap.untapped_official_taps.include?(default_cask_tap.name) default_cask_tap.install true diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index bbf73c37a8..739ecdaca7 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -67,8 +67,8 @@ class Tap @default_cask_tap ||= fetch("Homebrew", "cask") end - sig { returns(T::Boolean) } - def self.install_default_cask_tap_if_necessary + sig { params(force: T::Boolean).returns(T::Boolean) } + def self.install_default_cask_tap_if_necessary(force: false) false end From ecfad29347d9e58b9499144cab0a539d9e863ce9 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 21 Jan 2021 08:42:22 -0500 Subject: [PATCH 4/4] tap: write untapped setting only on manual untap --- Library/Homebrew/cmd/untap.rb | 2 +- Library/Homebrew/tap.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index e00d6ae9e7..33f56c4ba8 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -43,7 +43,7 @@ module Homebrew end end - tap.uninstall + tap.uninstall manual: true end end end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 739ecdaca7..da6a653fa1 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -363,7 +363,7 @@ class Tap end # Uninstall this {Tap}. - def uninstall + def uninstall(manual: false) require "descriptions" raise TapUnavailableError, name unless installed? @@ -386,7 +386,7 @@ class Tap Commands.rebuild_commands_completion_list clear_cache - return unless official? + return if !manual || !official? untapped = self.class.untapped_official_taps return if untapped.include? name