diagnostic: Check for unnecessary Core and Cask taps

- If the user doesn't have `HOMEBREW_DEVELOPER` or
  `HOMEBREW_NO_INSTALL_FROM_API` set but does have `homebrew/core` or
  `homebrew/cask` taps installed this can cause problems with installing
  outdated software.
- Hence, warn them in `brew doctor` if they have either of these taps
  installed, with instructions on how to remove them.
This commit is contained in:
Issy Long 2023-04-30 15:03:51 +01:00
parent e6d84f43d2
commit 40f697e96e
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
2 changed files with 46 additions and 0 deletions

View File

@ -842,6 +842,32 @@ module Homebrew
EOS EOS
end end
def check_for_unnecessary_core_tap
return if ENV["HOMEBREW_DEVELOPER"]
return if ENV["HOMEBREW_NO_INSTALL_FROM_API"]
return unless CoreTap.instance.installed?
<<~EOS
You have an unnecessary local Core tap!
This can cause problems installing up-to-date formulae.
Please remove it by running:
brew untap #{CoreTap.instance.name}
EOS
end
def check_for_unnecessary_cask_tap
return if ENV["HOMEBREW_DEVELOPER"]
return if ENV["HOMEBREW_NO_INSTALL_FROM_API"]
return unless (cask_tap = Tap.fetch("homebrew", "cask")).installed?
<<~EOS
You have an unnecessary local Cask tap.
This can cause problems installing up-to-date casks.
Please remove it by running:
brew untap #{cask_tap.name}
EOS
end
def check_cask_software_versions def check_cask_software_versions
add_info "Homebrew Version", HOMEBREW_VERSION add_info "Homebrew Version", HOMEBREW_VERSION
add_info "macOS", MacOS.full_version add_info "macOS", MacOS.full_version

View File

@ -114,4 +114,24 @@ describe Homebrew::Diagnostic::Checks do
expect(checks.check_homebrew_prefix) expect(checks.check_homebrew_prefix)
.to match("Your Homebrew's prefix is not #{Homebrew::DEFAULT_PREFIX}") .to match("Your Homebrew's prefix is not #{Homebrew::DEFAULT_PREFIX}")
end end
specify "#check_for_unnecessary_core_tap" do
ENV.delete("HOMEBREW_DEVELOPER")
ENV.delete("HOMEBREW_NO_INSTALL_FROM_API")
allow(CoreTap).to receive(:installed?).and_return(true)
expect(checks.check_for_unnecessary_core_tap).to match("You have an unnecessary local Core tap")
end
specify "#check_for_unnecessary_cask_tap" do
ENV.delete("HOMEBREW_DEVELOPER")
ENV.delete("HOMEBREW_NO_INSTALL_FROM_API")
cask_tap = Tap.new("homebrew", "cask")
allow(Tap).to receive(:fetch).with("homebrew", "cask").and_return(cask_tap)
allow(cask_tap).to receive(:installed?).and_return(true)
expect(checks.check_for_unnecessary_cask_tap).to match("unnecessary local Cask tap")
end
end end