aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd
diff options
context:
space:
mode:
authorXu Cheng2016-01-20 22:58:45 +0800
committerXu Cheng2016-01-21 21:14:55 +0800
commit2d84fc56fe233b435b8d16ebc012e83155b45c09 (patch)
tree3e71fd09a49bd6ec7f323db2b808124f271aa69e /Library/Homebrew/cmd
parentfafe8f0f53bf91fc41f016b5c2af41ca712783f7 (diff)
downloadbrew-2d84fc56fe233b435b8d16ebc012e83155b45c09.tar.bz2
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
Diffstat (limited to 'Library/Homebrew/cmd')
-rwxr-xr-xLibrary/Homebrew/cmd/update-bash.sh26
1 files changed, 19 insertions, 7 deletions
diff --git a/Library/Homebrew/cmd/update-bash.sh b/Library/Homebrew/cmd/update-bash.sh
index 2c0c3ea9b..d38d6dc72 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() {