From c9cdc2537f1d276c446359c6e595d6629e05755b Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Thu, 21 Mar 2019 18:04:14 +0000 Subject: [PATCH] =?UTF-8?q?brew.sh:=20don=E2=80=99t=20always=20autoupdate?= =?UTF-8?q?=20with=20no=20params.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only `brew upgrade` and `brew cask upgrade` actually do anything if no additional parameters are specified. As a result, we don’t need to always update in those cases when we’re just showing help output anyway (as has been done for `brew tap`). --- Library/Homebrew/brew.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index c37e0c03e5..ffcd7c9f6f 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -416,8 +416,22 @@ update-preinstall() { [[ -z "$HOMEBREW_HELP" ]] || return [[ -z "$HOMEBREW_NO_AUTO_UPDATE" ]] || return [[ -z "$HOMEBREW_AUTO_UPDATING" ]] || return - [[ -z "$HOMEBREW_AUTO_UPDATE_CHECKED" ]] || return [[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]] || return + [[ -z "$HOMEBREW_AUTO_UPDATE_CHECKED" ]] || return + + # If we've checked for updates, we don't need to check again. + export HOMEBREW_AUTO_UPDATE_CHECKED="1" + + if [[ "$HOMEBREW_COMMAND" = "cask" ]] + then + if [[ "$HOMEBREW_CASK_COMMAND" != "upgrade" && $HOMEBREW_ARG_COUNT -lt 3 ]] + then + return + fi + elif [[ "$HOMEBREW_COMMAND" != "upgrade" && $HOMEBREW_ARG_COUNT -lt 2 ]] + then + return + fi if [[ "$HOMEBREW_COMMAND" = "install" || "$HOMEBREW_COMMAND" = "upgrade" || "$HOMEBREW_COMMAND" = "bump-formula-pr" || @@ -432,9 +446,6 @@ update-preinstall() { timer_pid=$! fi - # Allow auto-update migration now we have a fix in place (below in this function). - export HOMEBREW_ENABLE_AUTO_UPDATE_MIGRATION="1" - brew update --preinstall if [[ -n "$timer_pid" ]] @@ -445,15 +456,9 @@ update-preinstall() { unset HOMEBREW_AUTO_UPDATING - # If we've checked for updates, we don't need to check again. - export HOMEBREW_AUTO_UPDATE_CHECKED="1" - # exec a new process to set any new environment variables. exec "$HOMEBREW_BREW_FILE" "$@" fi - - # If we've checked for updates, we don't need to check again. - export HOMEBREW_AUTO_UPDATE_CHECKED="1" } if [[ -n "$HOMEBREW_BASH_COMMAND" ]]