aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-12-28 13:42:55 -0800
committerJunio C Hamano <gitster@pobox.com>2010-12-28 13:42:55 -0800
commit2f739695700e4a9d9de640ff623fe4e728f5b23a (patch)
treeb6f76121a20097d66a8d55f158f5e3a0dc2cecd3
parent0ec9ee3bcf5c926df9d54f63ff3ed8b97e19bb0d (diff)
parent7b3b7e37581fb5266a260687c21af1571b4ade81 (diff)
downloadgit-2f739695700e4a9d9de640ff623fe4e728f5b23a.tar.gz
git-2f739695700e4a9d9de640ff623fe4e728f5b23a.tar.xz
Merge branch 'jc/maint-am-abort-safely' into maint
* jc/maint-am-abort-safely: am --abort: keep unrelated commits since the last failure and warn
-rwxr-xr-xgit-am.sh27
-rwxr-xr-xt/t4151-am-abort.sh9
2 files changed, 34 insertions, 2 deletions
diff --git a/git-am.sh b/git-am.sh
index de116a29e..e5671f61c 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -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"
@@ -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
diff --git a/t/t4151-am-abort.sh b/t/t4151-am-abort.sh
index b55c41178..c95c4ccc3 100755
--- a/t/t4151-am-abort.sh
+++ b/t/t4151-am-abort.sh
@@ -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