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

[WIP PATCH 08/10] More test scripts

From
Elijah Newren <newren@gmail.com>
Date
Mar 21, 2011, 18:31 UTC
Message-ID
<1300732264-9638-9-git-send-email-newren@gmail.com>
In-Reply-To
<1300732264-9638-1-git-send-email-newren@gmail.com>
---
 t/temp10.sh |   41 +++++++++++++++++++++++++++++++++
 t/temp11.sh |   41 +++++++++++++++++++++++++++++++++
 t/temp50.sh |   38 ++++++++++++++++++++++++++++++
 t/temp9.sh  |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 193 insertions(+), 0 deletions(-)
 create mode 100755 t/temp10.sh
 create mode 100755 t/temp11.sh
 create mode 100755 t/temp50.sh
 create mode 100755 t/temp9.sh
diff --git a/t/temp10.sh b/t/temp10.sh
new file mode 100755
index 0000000..100c74f
--- /dev/null
+++ b/t/temp10.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+test_description='merge+diff issue: rename/add vs. copy/modify'
+
+. ./test-lib.sh
+
+# Testcase setup:
+#   Commit A: new file: a
+#   Commit B: modify a slightly
+#   Commit C: rename a->b, add completely different a
+#
+# We should be able to merge B & C cleanly
+
+test_expect_success 'setup modify + rename/add(source) merge' '
+	printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
+	git add a &&
+	git commit -m A &&
+	git tag A &&
+
+	git checkout -b B A &&
+	echo 8 >>a &&
+	git add a &&
+	git commit -m B &&
+
+	git checkout -b C A &&
+	git mv a b &&
+	echo something completely different >a &&
+	git add a &&
+	git commit -m C
+'
+
+test_expect_success 'no conflict merging B & C' '
+	git checkout B^0 &&
+
+	git merge -s recursive C^0 &&
+
+	test $(git rev-parse B:a) = $(git rev-parse b) &&
+	test $(git rev-parse C:a) = $(git rev-parse a)
+'
+
+test_done
diff --git a/t/temp11.sh b/t/temp11.sh
new file mode 100755
index 0000000..1d8fb9a
--- /dev/null
+++ b/t/temp11.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+test_description='merge+diff issue: rename/add vs. copy/modify, v2'
+
+. ./test-lib.sh
+
+# Testcase setup:
+#   Commit A: new file: a
+#   Commit B: rename a->b
+#   Commit C: rename a->c, add completely different a
+#
+# Merging of B & C should NOT be clean; there's a rename/rename conflict
+
+test_expect_success 'setup modify + rename/add(source) merge' '
+	printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
+	git add a &&
+	git commit -m A &&
+	git tag A &&
+
+	git checkout -b B A &&
+	git mv a b &&
+	git commit -m B &&
+
+	git checkout -b C A &&
+	git mv a c &&
+	echo something completely different >a &&
+	git add a &&
+	git commit -m C
+'
+
+test_expect_success 'detect conflict merging B & C' '
+	git checkout B^0 &&
+
+	test_must_fail git merge -s recursive C^0 &&
+
+	test -f a &&
+	test -f b &&
+	test -f c
+'
+
+test_done
diff --git a/t/temp50.sh b/t/temp50.sh
new file mode 100755
index 0000000..5baebec
--- /dev/null
+++ b/t/temp50.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+test_description="Rename/rename conflict doesn't leave files in place for user"
+
+. ./test-lib.sh
+
+test_expect_success 'setup rename/rename (1to2) conflict' '
+	echo stuff >a &&
+	git add a &&
+	test_tick &&
+	git commit -m base &&
+	git tag base &&
+
+	git checkout -b one base &&
+	git mv a b &&
+	test_tick &&
+	git commit -m one &&
+
+	git checkout -b two base &&
+	git mv a c &&
+	test_tick &&
+	git commit -m two
+'
+
+test_expect_success 'merge has correct working tree contents' '
+	git checkout two^0 &&
+
+	test_must_fail git merge -s recursive one^0 &&
+
+	test 3 -eq $(git ls-files -s | wc -l) &&
+	test 3 -eq $(git ls-files -u | wc -l) &&
+	test 0 -eq $(git ls-files -o | wc -l) &&
+
+	test -f b &&
+	test -f c
+'
+
+test_done
diff --git a/t/temp9.sh b/t/temp9.sh
new file mode 100755
index 0000000..3936461
--- /dev/null
+++ b/t/temp9.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+test_description='recursive merge corner case: rename/rename + criss-cross merge + reintroduce file with name of rename source but different contents'
+
+. ./test-lib.sh
+
+#
+# Standard setup:
+#
+#      B   D
+#      o---o
+#     / \ / \
+#  A o   X   ? F
+#     \ / \ /
+#      o---o
+#      C   E
+#
+#   Commit A: new file: a
+#   Commit B: rename a->b
+#   Commit C: rename a->c, add different a
+#   Commit D: merge B&C, keeping a&b&c, modifying a at the beginning
+#   Commit E: merge B&C, keeping a&b&c, modifying a at the end
+#
+# Now, when we merge commits D & E, there should be no conflict...
+
+test_expect_success 'setup rename/rename + criss-cross + new file' '
+	printf "lots\nof\nwords\nand\ncontent\n" >a &&
+	git add a &&
+	git commit -m A &&
+	git tag A &&
+
+	git checkout -b B A &&
+	git mv a b &&
+	git commit -m B &&
+
+	git checkout -b C A &&
+	git mv a c &&
+	printf "2\n3\n4\n5\n6\n7\n" >a &&
+	git add a &&
+	git commit -m C &&
+
+	git checkout B^0 &&
+	exit 1
+	test_must_fail git merge C &&
+	mv a old_a &&
+	echo 1 >a &&
+	cat old_a >>a &&
+	rm old_a &&
+	git add -u &&
+	git commit -m D &&
+	git tag D &&
+
+	git checkout C^0 &&
+	test_must_fail git merge B &&
+	echo 6 >> a &&
+	git add -u &&
+	git commit -m E &&
+	git tag E
+'
+
+test_expect_success 'no conflict merging D & E' '
+	git checkout D^0 &&
+
+	git merge -s recursive E^0 &&
+
+	test 3 -eq $(git ls-files -s | wc -l) &&
+	test 0 -eq $(git ls-files -u | wc -l) &&
+	test 0 -eq $(git ls-files -o | wc -l) &&
+
+	test 6 -eq $(wc -l < a)
+'
+
+test_done
-- 
1.7.4
Previous: Elijah NewrenNext: Elijah Newren
Message 9 of 11 in “Work-in-progress merge-recursive work”
  1. 00/10 Work-in-progress merge-recursive workElijah Newren, Mar 21, 2011
  2. 01/10 merge-recursive: Remove redundant check for removing rename sourceElijah Newren, Mar 21, 2011
  3. 02/10 Reminder to fix o->call_depth handling in conflict_rename_rename_1to2Elijah Newren, Mar 21, 2011
  4. 03/10 A bunch of fixes and FIXMEsElijah Newren, Mar 21, 2011
  5. 04/10 Correct a commentElijah Newren, Mar 21, 2011
  6. 05/10 merge-recursive: Fix sorting order and directory change assumptionsElijah Newren, Mar 21, 2011
  7. 06/10 Add a comment pointing out a bugElijah Newren, Mar 21, 2011
  8. 07/10 Good testcasesElijah Newren, Mar 21, 2011
  9. 08/10 More test scriptsElijah Newren, Mar 21, 2011
  10. 09/10 Tests and fixes associated with rename/rename conflictsElijah Newren, Mar 21, 2011
  11. 10/10 Add new testcase (temp14) showing how undetected renames can cause or spuriously avoid merge conflictsElijah Newren, Mar 21, 2011

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.