Skip to content

Commit c767184

Browse files
Michael J Grubergitster
authored andcommitted
git-am: Keep index in case of abort with dirty index
git am --abort resets the index unconditionally. But in case a previous git am exited due to a dirty index it is preferable to keep that index. Make it so. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2591838 commit c767184

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

git-am.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,14 @@ then
230230
;;
231231
,t)
232232
git rerere clear
233-
git read-tree --reset -u HEAD ORIG_HEAD
234-
git reset ORIG_HEAD
233+
test -f "$dotest/dirtyindex" || {
234+
git read-tree --reset -u HEAD ORIG_HEAD
235+
git reset ORIG_HEAD
236+
}
235237
rm -fr "$dotest"
236238
exit ;;
237239
esac
240+
rm -f "$dotest/dirtyindex"
238241
else
239242
# Make sure we are not given --skip, --resolved, nor --abort
240243
test "$skip$resolved$abort" = "" ||
@@ -287,7 +290,11 @@ fi
287290
case "$resolved" in
288291
'')
289292
files=$(git diff-index --cached --name-only HEAD --) || exit
290-
test "$files" && die "Dirty index: cannot apply patches (dirty: $files)"
293+
if test "$files"
294+
then
295+
: >"$dotest/dirtyindex"
296+
die "Dirty index: cannot apply patches (dirty: $files)"
297+
fi
291298
esac
292299

293300
if test "$(cat "$dotest/utf8")" = t

0 commit comments

Comments
 (0)