git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-am: Keep index in case of abort with dirty index

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Feb 26, 2009, 09:52 UTC
Message-ID
<1235641973-18307-1-git-send-email-git@drmicha.warpmail.net>
In-Reply-To
<7v8wnu2x67.fsf@gitster.siamese.dyndns.org>

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>
---
Something like this?
 git-am.sh |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index 8bcb206..7013fea 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -230,8 +230,10 @@ 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
@@ -287,7 +289,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
-- 
1.6.2.rc1.30.gd43c
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 4 in “[Bug?] "git am --abort" loses previous "git add"”
  1. Junio C HamanoFeb 25, 2009
  2. git-am: Keep index in case of abort with dirty indexMichael J Gruber, Feb 26, 2009
  3. Junio C HamanoFeb 26, 2009
  4. git-am: make --abort less dangerousJunio C Hamano, Feb 26, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.