summaryrefslogtreecommitdiff
path: root/git-am.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-12-21 10:35:53 -0800
committerJunio C Hamano <gitster@pobox.com>2010-12-21 11:16:28 -0800
commit7b3b7e37581fb5266a260687c21af1571b4ade81 (patch)
tree62f8028ae58d7b6d6d6b372b9cd0b1e692fb6e44 /git-am.sh
parent05bb5a2584ca0e1c87a2135a83c5573b9337d06f (diff)
downloadgit-7b3b7e37581fb5266a260687c21af1571b4ade81.tar.gz
am --abort: keep unrelated commits since the last failure and warn
After making commits (either by pulling or doing their own work) after a failed "am", the user will be reminded by next "am" invocation that there was a failed "am" that the user needs to decide to resolve or to get rid of the old "am" attempt. The "am --abort" option was meant to help the latter. However, it rewinded the HEAD back to the beginning of the failed "am" attempt, discarding commits made (perhaps by mistake) since. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-am.sh')
-rwxr-xr-xgit-am.sh27
1 files changed, 25 insertions, 2 deletions
diff --git a/git-am.sh b/git-am.sh
index de116a29ef..e5671f61c6 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