Skip to content
Snippets Groups Projects
Commit 2d84fc56 authored by Xu Cheng's avatar Xu Cheng
Browse files

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
parent fafe8f0f
No related branches found
No related tags found
No related merge requests found
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment