Merge pull request #10366 from Rylan12/auto-tap-fix

Don't tap user-untapped official taps
This commit is contained in:
Rylan Polster 2021-01-21 15:47:07 -05:00 committed by GitHub
commit acede7315a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 10 deletions

View File

@ -132,7 +132,9 @@ 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?
if !possible_tap || possible_tap.installed? || Tap.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

View File

@ -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

View File

@ -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(

View File

@ -43,7 +43,7 @@ module Homebrew
end
end
tap.uninstall
tap.uninstall manual: true
end
end
end

View File

@ -2,9 +2,11 @@
# 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 !force && Tap.untapped_official_taps.include?(default_cask_tap.name)
default_cask_tap.install
true
end

View File

@ -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
@ -326,6 +326,17 @@ class Tap
.update_from_formula_names!(formula_names)
end
if official?
untapped = self.class.untapped_official_taps
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
@ -352,7 +363,7 @@ class Tap
end
# Uninstall this {Tap}.
def uninstall
def uninstall(manual: false)
require "descriptions"
raise TapUnavailableError, name unless installed?
@ -374,6 +385,14 @@ class Tap
Commands.rebuild_commands_completion_list
clear_cache
return if !manual || !official?
untapped = self.class.untapped_official_taps
return if untapped.include? name
untapped << name
Homebrew::Settings.write :untapped, untapped.join(";")
end
# True if the {#remote} of {Tap} is customized.
@ -624,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")}"