diagnostic: add check for broken taps

Detect half-baked core taps that show up on a fairly regular basis (e.g. #11465).

The logic is simple enough: Since an improper tap wouldn't have a complete Git config, and is always somewhere below `HOMEBREW_REPOSITORY`, any Git operation would look at the Brew repo instead. We simply need to test for any of:

1. Empty tap origin
2. Empty tap HEAD
3. Tap HEAD == Brew HEAD
This commit is contained in:
Adrian Ho 2021-06-01 00:41:44 +08:00
parent 5115cc25fa
commit c7bbb904e8

View File

@ -147,6 +147,27 @@ module Homebrew
end
end
def broken_tap_msg(tap)
<<~EOS
#{tap.full_name} was not tapped properly.
To fix:
rm -rf "#{tap.path}"
brew tap #{tap.name}
EOS
end
def broken_tap(tap)
return unless Utils::Git.available?
return unless HOMEBREW_REPOSITORY.git?
return broken_tap_msg(tap) if tap.remote.blank?
tap_head = tap.git_head
return broken_tap_msg(tap) if tap_head.blank?
return broken_tap_msg(tap) if tap_head == HOMEBREW_REPOSITORY.git_head
end
def check_for_installed_developer_tools
return if DevelopmentTools.installed?
@ -558,15 +579,16 @@ module Homebrew
examine_git_origin(HOMEBREW_REPOSITORY, Homebrew::EnvConfig.brew_git_remote)
end
def check_coretap_git_origin
examine_git_origin(CoreTap.instance.path, Homebrew::EnvConfig.core_git_remote)
def check_coretap_integrity
coretap = CoreTap.instance
broken_tap(coretap) || examine_git_origin(coretap.path, Homebrew::EnvConfig.core_git_remote)
end
def check_casktap_git_origin
def check_casktap_integrity
default_cask_tap = Tap.default_cask_tap
return unless default_cask_tap.installed?
examine_git_origin(default_cask_tap.path, default_cask_tap.remote)
broken_tap(default_cask_tap) || examine_git_origin(default_cask_tap.path, default_cask_tap.remote)
end
sig { returns(T.nilable(String)) }