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 () {
68
68
69
69
stop_here () {
70
70
echo " $1 " > " $dotest /next"
71
+ git rev-parse --verify -q HEAD > " $dotest /abort-safety"
71
72
exit 1
72
73
}
73
74
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
+
74
96
stop_here_user_resolve () {
75
97
if [ -n " $resolvemsg " ]; then
76
98
printf ' %s\n' " $resolvemsg "
@@ -419,10 +441,11 @@ then
419
441
exec git rebase --abort
420
442
fi
421
443
git rerere clear
422
- test -f " $dotest /dirtyindex" || {
444
+ if safe_to_abort
445
+ then
423
446
git read-tree --reset -u HEAD ORIG_HEAD
424
447
git reset ORIG_HEAD
425
- }
448
+ fi
426
449
rm -fr " $dotest "
427
450
exit ;;
428
451
esac
Original file line number Diff line number Diff line change 62
62
63
63
done
64
64
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
+
65
74
test_done
You can’t perform that action at this time.
0 commit comments