X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-am.sh;h=f5afe1562af869a3d84197913e14667b9ce729c0;hb=909ca7b9ac11711478aaa5dd4ab17a0d1dabe075;hp=df09b42840b7675e135605f9108894ce93e6d477;hpb=4bb4d30095fbc3b1689cc656e71f6a51e43fbd69;p=git.git diff --git a/git-am.sh b/git-am.sh index df09b4284..f5afe1562 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" @@ -283,7 +305,8 @@ split_patches () { msgnum= ;; *) - if test -n "$parse_patch" ; then + if test -n "$patch_format" + then clean_abort "Patch format $patch_format is not supported." else clean_abort "Patch format detection failed." @@ -419,10 +442,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 @@ -484,6 +508,8 @@ else fi fi +git update-index -q --refresh + case "$resolved" in '') case "$HAS_HEAD" in @@ -554,13 +580,6 @@ then resume= fi -if test "$this" -gt "$last" -then - say Nothing to do. - rm -fr "$dotest" - exit -fi - while test "$this" -le "$last" do msgnum=`printf "%0${prec}d" $this`