X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-am.sh;h=6cdd5910db50c96df3d149fba172750cb10c09cb;hb=5cd7fadc076880c48a27fd4e5e70844f127ceb99;hp=df09b42840b7675e135605f9108894ce93e6d477;hpb=643b6ef809cdbc47c698b688b0dfe218eca9b474;p=git.git diff --git a/git-am.sh b/git-am.sh index df09b4284..6cdd5910d 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 @@ -554,13 +577,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`