summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 05bb5a2)
raw | patch | inline | side by side (parent: 05bb5a2)
author | Junio C Hamano <gitster@pobox.com> | |
Tue, 21 Dec 2010 18:35:53 +0000 (10:35 -0800) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 21 Dec 2010 19:16:28 +0000 (11:16 -0800) |
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>
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>
git-am.sh | patch | blob | history | |
t/t4151-am-abort.sh | patch | blob | history |
diff --git a/git-am.sh b/git-am.sh
index de116a29ef091a23f60603a28f1260ba60f054ac..e5671f61c61aad7fe47e174a31b534da6d8d2798 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
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"
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 b55c4117884744db8eda17e42fe05e0e65216215..c95c4ccc393d0863ad53b6a2a684893282d7d9e6 100755 (executable)
--- a/t/t4151-am-abort.sh
+++ b/t/t4151-am-abort.sh
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