Skip to content

Commit

Permalink
diagnostic: add check for broken taps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Adrian Ho committed Jun 1, 2021
1 parent 5115cc2 commit c7bbb90
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ def examine_git_origin(repository_path, desired_origin)
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?

Expand Down Expand Up @@ -558,15 +579,16 @@ def check_brew_git_origin
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)) }
Expand Down

0 comments on commit c7bbb90

Please sign in to comment.