diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index b9136ab108..9c18de3b1c 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -842,6 +842,32 @@ module Homebrew EOS 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 add_info "Homebrew Version", HOMEBREW_VERSION add_info "macOS", MacOS.full_version diff --git a/Library/Homebrew/test/diagnostic_checks_spec.rb b/Library/Homebrew/test/diagnostic_checks_spec.rb index 8ab27219aa..7d51a90d3b 100644 --- a/Library/Homebrew/test/diagnostic_checks_spec.rb +++ b/Library/Homebrew/test/diagnostic_checks_spec.rb @@ -114,4 +114,24 @@ describe Homebrew::Diagnostic::Checks do expect(checks.check_homebrew_prefix) .to match("Your Homebrew's prefix is not #{Homebrew::DEFAULT_PREFIX}") 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