From ddee97628ff7ecfb706df54e559d10e27c38310e Mon Sep 17 00:00:00 2001 From: Salim Djerbouh <13698160+CaddyDz@users.noreply.github.com> Date: Thu, 13 Mar 2025 11:13:33 +0100 Subject: [PATCH] feat: prevent accidental brew upgrades Add function to intercept brew upgrade commands and display a warning instead of executing them. This helps prevent system breakage from unexpected dependency changes during package upgrades. - Blocks `brew upgrade` command - Blocks `brew update && brew upgrade --greedy` pattern - Provides instructions on how to bypass if really needed Signed-off-by: Salim Djerbouh <13698160+CaddyDz@users.noreply.github.com> --- .functions.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.functions.sh b/.functions.sh index 08a97f6..ca934d8 100644 --- a/.functions.sh +++ b/.functions.sh @@ -94,4 +94,18 @@ port() { port=$((min_port + (sum % port_range))) echo $port +} + +# Prevent brew upgrade commands +brew() { + local command="$1" + shift + + if [[ "$command" == "upgrade" ]] || [[ "$command" == "update" && "$*" == *"--greedy"* ]] || [[ "$command" == "update" && "$*" == *"upgrade"* ]]; then + echo "⛔️ BREW UPGRADE BLOCKED: This command has been disabled to prevent breaking your system, it will break Postgres & Meilisearch and you will waste a lot of time fixing them." + echo "If you really need to upgrade packages, use 'command brew $command $*' to bypass this protection." + return 1 + else + command brew "$command" "$@" + fi } \ No newline at end of file