Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew.sh: declare commands that call auto-update as an array #14554

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

#####
Expand Down Expand Up @@ -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
Expand Down