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

[PATCH 3/3] t6042: add testcase covering long chains of rename conflicts

From
Elijah Newren <newren@gmail.com>
Date
Jul 2, 2018, 13:30 UTC
Message-ID
<20180702133054.18638-4-newren@gmail.com>
In-Reply-To
<20180702133054.18638-1-newren@gmail.com>

Each rename is a lego: the source side could be connected to a delete or another rename, and the destination side could be connected to a rename or a conflicting add. Previous tests combined these to get e.g. rename/rename(1to2)/add/add, rename/rename(2to1)/delete/delete, and rename/add/delete. But we can also build bigger chains of conflicts. Add a testcase demonstrating this.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t6042-merge-rename-corner-cases.sh | 111 +++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)
diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh
index 46e1aa7df..d9c4068e9 100755
--- a/t/t6042-merge-rename-corner-cases.sh
+++ b/t/t6042-merge-rename-corner-cases.sh
@@ -827,4 +827,115 @@ test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
 	)
 '
 
+# Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
+#   Commit O: one,      three,       five
+#   Commit A: one->two, three->four, five->six
+#   Commit B: one->six, three->two,  five->four
+#   Expected: six CONFLICT(rename/rename) messages, each path in two of the
+#             multi-way merged contents found in two, four, six
+
+test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
+	test_create_repo mod6 &&
+	(
+		cd mod6 &&
+		test_seq 11 19 >one &&
+		test_seq 31 39 >three &&
+		test_seq 51 59 >five &&
+		git add . &&
+		test_tick &&
+		git commit -m "O" &&
+
+		git branch O &&
+		git branch A &&
+		git branch B &&
+
+		git checkout A &&
+		test_seq 10 19 >one &&
+		echo 40        >>three &&
+		git add one three &&
+		git mv  one   two  &&
+		git mv  three four &&
+		git mv  five  six  &&
+		test_tick &&
+		git commit -m "A" &&
+
+		git checkout B &&
+		echo 20    >>one       &&
+		echo forty >>three     &&
+		echo 60    >>five      &&
+		git add one three five &&
+		git mv  one   six  &&
+		git mv  three two  &&
+		git mv  five  four &&
+		test_tick &&
+		git commit -m "B"
+	)
+'
+
+test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
+	(
+		cd mod6 &&
+
+		git checkout A^0 &&
+
+		test_must_fail git merge -s recursive B^0 >out 2>err &&
+
+		test_i18ngrep "CONFLICT (rename/rename)" out &&
+		test_must_be_empty err &&
+
+		git ls-files -s >file_count &&
+		test_line_count = 6 file_count &&
+		git ls-files -u >file_count &&
+		test_line_count = 6 file_count &&
+		git ls-files -o >file_count &&
+		test_line_count = 3 file_count &&
+
+		test_seq 10 20 >merged-one &&
+		test_seq 51 60 >merged-five &&
+		# Determine what the merge of three would give us.
+		test_seq 30 40 >three-side-A &&
+		test_seq 31 39 >three-side-B &&
+		echo forty >three-side-B &&
+		>empty &&
+		test_must_fail git merge-file \
+			-L "HEAD" \
+			-L "" \
+			-L "B^0" \
+			three-side-A empty three-side-B &&
+		sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
+
+		# Verify the index is as expected
+		git rev-parse >actual         \
+			:2:two       :3:two   \
+			:2:four      :3:four  \
+			:2:six       :3:six   &&
+		git hash-object >expect           \
+			merged-one   merged-three \
+			merged-three merged-five  \
+			merged-five  merged-one   &&
+		test_cmp expect actual &&
+
+		git cat-file -p :2:two >expect &&
+		git cat-file -p :3:two >other &&
+		test_must_fail git merge-file    \
+			-L "HEAD"  -L ""  -L "B^0" \
+			expect     empty  other &&
+		test_cmp expect two &&
+
+		git cat-file -p :2:four >expect &&
+		git cat-file -p :3:four >other &&
+		test_must_fail git merge-file    \
+			-L "HEAD"  -L ""  -L "B^0" \
+			expect     empty  other &&
+		test_cmp expect four &&
+
+		git cat-file -p :2:six >expect &&
+		git cat-file -p :3:six >other &&
+		test_must_fail git merge-file    \
+			-L "HEAD"  -L ""  -L "B^0" \
+			expect     empty  other &&
+		test_cmp expect six
+	)
+'
+
 test_done
-- 
2.18.0.130.gd703bbb5d
Previous: Elijah NewrenNext: Elijah Newren
Message 3 of 4 in “Add missing rename-related corner cases for merging”
  1. 0/3 Add missing rename-related corner cases for mergingElijah Newren, Jul 2, 2018
  2. 2/3 t6042: add testcase covering rename/rename(2to1)/delete/delete conflictElijah Newren, Jul 2, 2018
  3. 3/3 t6042: add testcase covering long chains of rename conflictsElijah Newren, Jul 2, 2018
  4. 1/3 t6042: add testcase covering rename/add/delete conflict typeElijah Newren, Jul 2, 2018

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.