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 = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) }
possible_tap = Tap.fetch(possible_tap.first) if possible_tap 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 # Unset HOMEBREW_HELP to avoid confusing the tap
with_env HOMEBREW_HELP: nil do with_env HOMEBREW_HELP: nil do

View File

@ -99,8 +99,6 @@ module Homebrew
begin begin
return Cask::CaskLoader.load(name, config: Cask::Config.from_args(@parent)) return Cask::CaskLoader.load(name, config: Cask::Config.from_args(@parent))
rescue Cask::CaskUnavailableError => e rescue Cask::CaskUnavailableError => e
retry if Tap.install_default_cask_tap_if_necessary
raise e if only == :cask raise e if only == :cask
end end
end end

View File

@ -153,8 +153,14 @@ module Homebrew
EOS EOS
end end
formulae, casks = args.named.to_formulae_and_casks begin
.partition { |formula_or_cask| formula_or_cask.is_a?(Formula) } 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? if casks.any?
Cask::Cmd::Install.install_casks( Cask::Cmd::Install.install_casks(

View File

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

View File

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

View File

@ -67,8 +67,8 @@ class Tap
@default_cask_tap ||= fetch("Homebrew", "cask") @default_cask_tap ||= fetch("Homebrew", "cask")
end end
sig { returns(T::Boolean) } sig { params(force: T::Boolean).returns(T::Boolean) }
def self.install_default_cask_tap_if_necessary def self.install_default_cask_tap_if_necessary(force: false)
false false
end end
@ -326,6 +326,17 @@ class Tap
.update_from_formula_names!(formula_names) .update_from_formula_names!(formula_names)
end 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 if clone_target
return unless private? return unless private?
return if quiet return if quiet
@ -352,7 +363,7 @@ class Tap
end end
# Uninstall this {Tap}. # Uninstall this {Tap}.
def uninstall def uninstall(manual: false)
require "descriptions" require "descriptions"
raise TapUnavailableError, name unless installed? raise TapUnavailableError, name unless installed?
@ -374,6 +385,14 @@ class Tap
Commands.rebuild_commands_completion_list Commands.rebuild_commands_completion_list
clear_cache 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 end
# True if the {#remote} of {Tap} is customized. # True if the {#remote} of {Tap} is customized.
@ -624,6 +643,12 @@ class Tap
Pathname.glob TAP_DIRECTORY/"*/*/cmd" Pathname.glob TAP_DIRECTORY/"*/*/cmd"
end 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 # @private
def formula_file_to_name(file) def formula_file_to_name(file)
"#{name}/#{file.basename(".rb")}" "#{name}/#{file.basename(".rb")}"