From 61e82290d724664ba8e45ef7c0c872365fb8d01e Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 8 Feb 2023 02:41:41 +0800 Subject: [PATCH] brew.sh: declare commands that call `auto-update` as an array Follow up to #14536. --- Library/Homebrew/brew.sh | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index e06f49f2953a6..5441f713ec8bb 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -209,6 +209,19 @@ EOS fi } +# NOTE: the members of the array in the second arg must not have spaces! +check-array-membership() { + local item=$1 + shift + + if [[ " ${*} " == *" ${item} "* ]] + then + return 0 + else + return 1 + fi +} + # Let user know we're still updating Homebrew if brew update --auto-update # exceeds 3 seconds. auto-update-timer() { @@ -237,12 +250,16 @@ auto-update() { # If we've checked for updates, we don't need to check again. export HOMEBREW_AUTO_UPDATE_CHECKED="1" - if [[ "${HOMEBREW_COMMAND}" == "install" ]] || - [[ "${HOMEBREW_COMMAND}" == "upgrade" ]] || - [[ "${HOMEBREW_COMMAND}" == "bump-formula-pr" ]] || - [[ "${HOMEBREW_COMMAND}" == "bump-cask-pr" ]] || - [[ "${HOMEBREW_COMMAND}" == "bundle" ]] || - [[ "${HOMEBREW_COMMAND}" == "release" ]] || + AUTO_UPDATE_COMMANDS=( + install + upgrade + bump-formula-pr + bump-cask-pr + bundle + release + ) + + if check-array-membership "${HOMEBREW_COMMAND}" "${AUTO_UPDATE_COMMANDS[@]}" || [[ "${HOMEBREW_COMMAND}" == "tap" && "${HOMEBREW_ARG_COUNT}" -gt 1 ]] then export HOMEBREW_AUTO_UPDATING="1" @@ -290,6 +307,8 @@ auto-update() { # exec a new process to set any new environment variables. exec "${HOMEBREW_BREW_FILE}" "$@" fi + + unset AUTO_UPDATE_COMMANDS } ##### @@ -776,7 +795,7 @@ then update-python-resources ) - if [[ " ${NO_INSTALL_FROM_API_COMMANDS[*]} " == *" ${HOMEBREW_COMMAND} "* ]] + if check-array-membership "${HOMEBREW_COMMAND}" "${NO_INSTALL_FROM_API_COMMANDS[@]}" then export HOMEBREW_NO_INSTALL_FROM_API=1 fi