diff --git a/git-am.sh b/git-am.sh index 8bcb206022..351b4f86fa 100755 --- a/git-am.sh +++ b/git-am.sh @@ -230,11 +230,14 @@ then ;; ,t) git rerere clear - git read-tree --reset -u HEAD ORIG_HEAD - git reset ORIG_HEAD + test -f "$dotest/dirtyindex" || { + git read-tree --reset -u HEAD ORIG_HEAD + git reset ORIG_HEAD + } rm -fr "$dotest" exit ;; esac + rm -f "$dotest/dirtyindex" else # Make sure we are not given --skip, --resolved, nor --abort test "$skip$resolved$abort" = "" || @@ -287,7 +290,11 @@ fi case "$resolved" in '') files=$(git diff-index --cached --name-only HEAD --) || exit - test "$files" && die "Dirty index: cannot apply patches (dirty: $files)" + if test "$files" + then + : >"$dotest/dirtyindex" + die "Dirty index: cannot apply patches (dirty: $files)" + fi esac if test "$(cat "$dotest/utf8")" = t