Skip to content

Commit

Permalink
Merge branch 'jc/maint-am-abort-safely' into maint
Browse files Browse the repository at this point in the history
* jc/maint-am-abort-safely:
  am --abort: keep unrelated commits since the last failure and warn
  • Loading branch information
gitster committed Dec 28, 2010
2 parents 0ec9ee3 + 7b3b7e3 commit 2f73969
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
27 changes: 25 additions & 2 deletions git-am.sh
Expand Up @@ -68,9 +68,31 @@ sq () {

stop_here () {
echo "$1" >"$dotest/next"
git rev-parse --verify -q HEAD >"$dotest/abort-safety"
exit 1
}

safe_to_abort () {
if test -f "$dotest/dirtyindex"
then
return 1
fi

if ! test -s "$dotest/abort-safety"
then
return 0
fi

abort_safety=$(cat "$dotest/abort-safety")
if test "z$(git rev-parse --verify -q HEAD)" = "z$abort_safety"
then
return 0
fi
echo >&2 "You seem to have moved HEAD since the last 'am' failure."
echo >&2 "Not rewinding to ORIG_HEAD"
return 1
}

stop_here_user_resolve () {
if [ -n "$resolvemsg" ]; then
printf '%s\n' "$resolvemsg"
Expand Down Expand Up @@ -419,10 +441,11 @@ then
exec git rebase --abort
fi
git rerere clear
test -f "$dotest/dirtyindex" || {
if safe_to_abort
then
git read-tree --reset -u HEAD ORIG_HEAD
git reset ORIG_HEAD
}
fi
rm -fr "$dotest"
exit ;;
esac
Expand Down
9 changes: 9 additions & 0 deletions t/t4151-am-abort.sh
Expand Up @@ -62,4 +62,13 @@ do

done

test_expect_success 'am --abort will keep the local commits intact' '
test_must_fail git am 0004-*.patch &&
test_commit unrelated &&
git rev-parse HEAD >expect &&
git am --abort &&
git rev-parse HEAD >actual &&
test_cmp expect actual
'

test_done

0 comments on commit 2f73969

Please sign in to comment.