File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -68,9 +68,31 @@ sq () {
6868
6969stop_here () {
7070 echo " $1 " > " $dotest /next"
71+ git rev-parse --verify -q HEAD > " $dotest /abort-safety"
7172 exit 1
7273}
7374
75+ safe_to_abort () {
76+ if test -f " $dotest /dirtyindex"
77+ then
78+ return 1
79+ fi
80+
81+ if ! test -s " $dotest /abort-safety"
82+ then
83+ return 0
84+ fi
85+
86+ abort_safety=$( cat " $dotest /abort-safety" )
87+ if test " z$( git rev-parse --verify -q HEAD) " = " z$abort_safety "
88+ then
89+ return 0
90+ fi
91+ echo >&2 " You seem to have moved HEAD since the last 'am' failure."
92+ echo >&2 " Not rewinding to ORIG_HEAD"
93+ return 1
94+ }
95+
7496stop_here_user_resolve () {
7597 if [ -n " $resolvemsg " ]; then
7698 printf ' %s\n' " $resolvemsg "
@@ -419,10 +441,11 @@ then
419441 exec git rebase --abort
420442 fi
421443 git rerere clear
422- test -f " $dotest /dirtyindex" || {
444+ if safe_to_abort
445+ then
423446 git read-tree --reset -u HEAD ORIG_HEAD
424447 git reset ORIG_HEAD
425- }
448+ fi
426449 rm -fr " $dotest "
427450 exit ;;
428451 esac
Original file line number Diff line number Diff line change 6262
6363done
6464
65+ test_expect_success ' am --abort will keep the local commits intact' '
66+ test_must_fail git am 0004-*.patch &&
67+ test_commit unrelated &&
68+ git rev-parse HEAD >expect &&
69+ git am --abort &&
70+ git rev-parse HEAD >actual &&
71+ test_cmp expect actual
72+ '
73+
6574test_done
You can’t perform that action at this time.
0 commit comments