From 40f697e96e5dfcd38ace587a848f917c38d2ab1f Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 30 Apr 2023 15:03:51 +0100 Subject: [PATCH] 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. --- Library/Homebrew/diagnostic.rb | 26 +++++++++++++++++++ .../Homebrew/test/diagnostic_checks_spec.rb | 20 ++++++++++++++ 2 files changed, 46 insertions(+) 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