Subject: [PATCH] unresolve: make sure resolve-undo info is left even for removed paths

From: Junio C Hamano <[email-masked]>
Date: Thu, 22 Jun 2023 15:54:40 -0700

"git rerere forget" requires that resolve-undo information is
correctly recorded in the index.

The current rerere machinery is not even prepared to access the
resolve-undo information for paths resolved for removal, as it first
goes to the main index entry and then finds the resolve-undo
information associated to the same pathname.  This has to be fixed
later (the codepath used by "git update-index --unresolve" shares
the same problem---unmerge_index_entry_at() is a flawed interface
that assumes that the index has the path in it after resolution, and
cannot be used when the resolution was to remove), but let's first
make sure we have the information recorded.

Signed-off-by: Junio C Hamano <[email-masked]>
---
 t/t2030-unresolve-info.sh | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index 2d8c70b03a..c515b40e8d 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -62,6 +62,13 @@ test_expect_success setup '
 	test_commit fourth fi/le fourth &&
 	git checkout add-add &&
 	test_commit fifth add-differently &&
+	git checkout --detach initial &&
+	git rm binary &&
+	test_commit sixth del-binary &&
+	git reset --hard HEAD^ &&
+	printf "a\0c" >binary &&
+	git add binary &&
+	test_commit seventh mod-binary &&
 	git checkout main
 '
 
@@ -126,6 +133,32 @@ test_expect_success 'unmerge with plumbing' '
 	test_line_count = 3 actual
 '
 
+test_expect_success 'del-mod conflict' '
+	git reset --hard &&
+	# they delete, we modify, resolve to ours
+	git checkout --detach seventh &&
+	test_must_fail git merge sixth &&
+	git add binary &&
+	check_resolve_undo mods binary initial:binary seventh:binary ""
+'
+
+test_expect_success 'del-mod conflict' '
+	git reset --hard &&
+	# we delete, they modify, resolve to deletion
+	git checkout --detach sixth &&
+	test_must_fail git merge seventh &&
+	git rm binary &&
+	check_resolve_undo removed binary initial:binary "" seventh:binary
+'
+
+test_expect_success 'resolve 3-way conflict to deletion' '
+	git reset --hard &&
+	git checkout --detach second &&
+	test_must_fail git merge third &&
+	git rm fi/le &&
+	check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le
+'
+
 test_expect_success 'rerere and rerere forget' '
 	mkdir .git/rr-cache &&
 	prime_resolve_undo &&
-- 
2.41.0-113-g6640c2d06d