From 2d84fc56fe233b435b8d16ebc012e83155b45c09 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Wed, 20 Jan 2016 22:58:45 +0800 Subject: [PATCH] update-bash: improve reset_on_interrupt * make sure exit after reset. * more wide guardian range. We should trap reset_on_interrupt as soon as we are about to change any files. * check INITIAL_BRANCH against UPSTREAM_BRANCH --- Library/Homebrew/cmd/update-bash.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cmd/update-bash.sh b/Library/Homebrew/cmd/update-bash.sh index 2c0c3ea9b8..d38d6dc72d 100755 --- a/Library/Homebrew/cmd/update-bash.sh +++ b/Library/Homebrew/cmd/update-bash.sh @@ -121,14 +121,24 @@ pop_stash_message() { # Don't warn about QUIET_ARGS; they need to be unquoted. # shellcheck disable=SC2086 reset_on_interrupt() { - [[ -z "$INITIAL_BRANCH" ]] || git checkout "$INITIAL_BRANCH" - git reset --hard "$INITIAL_REVISION" $QUIET_ARGS - if [[ -n "$INITIAL_BRANCH" ]] + if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]] + then + git checkout "$INITIAL_BRANCH" + fi + + if [[ -n "$INITIAL_REVISION" ]] + then + git reset --hard "$INITIAL_REVISION" $QUIET_ARGS + fi + + if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]] then pop_stash else pop_stash_message fi + + exit 130 } # Don't warn about QUIET_ARGS; they need to be unquoted. @@ -145,6 +155,8 @@ pull() { INITIAL_BRANCH="$(git symbolic-ref --short HEAD 2>/dev/null)" UPSTREAM_BRANCH="$(upstream_branch)" + trap reset_on_interrupt SIGINT + if [[ -n "$(git status --untracked-files=all --porcelain 2>/dev/null)" ]] then if [[ -n "$HOMEBREW_VERBOSE" ]] @@ -191,8 +203,6 @@ pull() { # ensure we don't munge line endings on checkout git config core.autocrlf false - trap reset_on_interrupt SIGINT - if [[ -n "$HOMEBREW_REBASE" ]] then git rebase $QUIET_ARGS "origin/$UPSTREAM_BRANCH" @@ -200,11 +210,11 @@ pull() { git merge --no-edit --ff $QUIET_ARGS "origin/$UPSTREAM_BRANCH" fi - trap - SIGINT - CURRENT_REVISION="$(read_current_revision)" export HOMEBREW_UPDATE_AFTER"$TAP_VAR"="$(git rev-parse "$UPSTREAM_BRANCH")" + trap '' SIGINT + if [[ "$INITIAL_BRANCH" != "$UPSTREAM_BRANCH" && -n "$INITIAL_BRANCH" ]] then git checkout "$INITIAL_BRANCH" $QUIET_ARGS @@ -212,6 +222,8 @@ pull() { else pop_stash_message fi + + trap - SIGINT } update-bash() {