From ebb71682ab79616466b748f9e1da5ee25e743e94 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 25 Jul 2025 09:39:19 +0100 Subject: [PATCH] Improve error message for tap conflicts in brew install Co-authored-by: MikeMcQuaid <125011+MikeMcQuaid@users.noreply.github.com> Co-authored-by: carlocab <30379873+carlocab@users.noreply.github.com> --- Library/Homebrew/install.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index fc20c85800..62e4a8f78c 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -102,6 +102,24 @@ module Homebrew end prefix_installed = formula.prefix.exist? && !formula.prefix.children.empty? + # Check if the installed formula is from a different tap + if formula.any_version_installed? && + (current_tap_name = formula.tap&.name.presence) && + (installed_keg_tab = formula.any_installed_keg&.tab.presence) && + (installed_tap_name = installed_keg_tab.tap&.name.presence) && + installed_tap_name != current_tap_name + odie <<~EOS + #{formula.name} was installed from the #{Formatter.identifier(installed_tap_name)} tap + but you are trying to install it from the #{Formatter.identifier(current_tap_name)} tap. + Formulae with the same name from different taps cannot be installed at the same time. + + To install this version, you must first uninstall the existing formula: + brew uninstall #{formula.name} + Then you can install the desired version: + brew install #{formula.full_name} + EOS + end + if formula.keg_only? && formula.any_version_installed? && formula.optlinked? && !force # keg-only install is only possible when no other version is # linked to opt, because installing without any warnings can break