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

[PATCH 1/3] t6044: recursive can silently incorporate dirty changes in a merge

From
Elijah Newren <newren@gmail.com>
Date
Dec 21, 2017, 19:19 UTC
Message-ID
<20171221191907.4251-1-newren@gmail.com>
In-Reply-To
<CABPp-BGy3_RyVQfCm+9O_AAfKA0_CZ5ajJE7NuLbToERWyWmqQ@mail.gmail.com>

The recursive merge strategy has some special handling when the tree for the merge branch exactly matches the merge base, but that code path is missing checks for the index having changes relative to HEAD. Add a testcase covering this scenario.

Reported-by: Andreas Krey <a.krey@gmx.de>
Signed-off-by: Elijah Newren <newren@gmail.com>
---
 t/t6044-merge-unrelated-index-changes.sh | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/t/t6044-merge-unrelated-index-changes.sh b/t/t6044-merge-unrelated-index-changes.sh
index 01023486c5..5e472be92b 100755
--- a/t/t6044-merge-unrelated-index-changes.sh
+++ b/t/t6044-merge-unrelated-index-changes.sh
@@ -6,18 +6,21 @@ test_description="merges with unrelated index changes"
 
 # Testcase for some simple merges
 #   A
-#   o-----o B
+#   o-------o B
 #    \
-#     \---o C
+#     \-----o C
 #      \
-#       \-o D
+#       \---o D
 #        \
-#         o E
+#         \-o E
+#          \
+#           o F
 #   Commit A: some file a
 #   Commit B: adds file b, modifies end of a
 #   Commit C: adds file c
 #   Commit D: adds file d, modifies beginning of a
 #   Commit E: renames a->subdir/a, adds subdir/e
+#   Commit F: empty commit
 
 test_expect_success 'setup trivial merges' '
 	test_seq 1 10 >a &&
@@ -29,6 +32,7 @@ test_expect_success 'setup trivial merges' '
 	git branch C &&
 	git branch D &&
 	git branch E &&
+	git branch F &&
 
 	git checkout B &&
 	echo b >b &&
@@ -52,7 +56,10 @@ test_expect_success 'setup trivial merges' '
 	git mv a subdir/a &&
 	echo e >subdir/e &&
 	git add subdir &&
-	test_tick && git commit -m E
+	test_tick && git commit -m E &&
+
+	git checkout F &&
+	test_tick && git commit --allow-empty -m F
 '
 
 test_expect_success 'ff update' '
@@ -105,6 +112,15 @@ test_expect_success 'recursive' '
 	test_must_fail git merge -s recursive C^0
 '
 
+test_expect_failure 'recursive, when merge branch matches merge base' '
+	git reset --hard &&
+	git checkout B^0 &&
+
+	touch random_file && git add random_file &&
+
+	test_must_fail git merge -s recursive F^0
+'
+
 test_expect_success 'octopus, unrelated file touched' '
 	git reset --hard &&
 	git checkout B^0 &&
-- 
2.15.1.436.g63a861020b
Previous: Elijah NewrenNext: Elijah Newren
Message 3 of 15 in “git merge commits staged files (when two trees are identical)”
  1. Andreas KreyDec 20, 2017
  2. Elijah NewrenDec 21, 2017
  3. 1/3 t6044: recursive can silently incorporate dirty changes in a mergeElijah Newren, Dec 21, 2017
  4. 3/3 merge-recursive: Avoid incorporating uncommitted changes in a mergeElijah Newren, Dec 21, 2017
  5. Junio C HamanoDec 22, 2017
  6. Junio C HamanoJan 8, 2018
  7. merge-recursive: do not look at the index during recursive mergeJunio C Hamano, Jan 9, 2018
  8. Junio C HamanoJan 9, 2018
  9. Eric SunshineJan 9, 2018
  10. Elijah NewrenJan 9, 2018
  11. Junio C HamanoJan 9, 2018
  12. 2/3 move index_has_changes() from builtin/am.c to merge.c for reuseElijah Newren, Dec 21, 2017
  13. Elijah NewrenDec 21, 2017
  14. Junio C HamanoDec 22, 2017
  15. Elijah NewrenDec 23, 2017

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.