t6042: add testcase covering rename/rename(2to1)/delete/delete conflict
[gitweb.git] / t / t6042-merge-rename-corner-cases.sh
index 1cbd946fc2eb9ab3dcad83c811abb6d18448fc4e..46e1aa7dfe2faa91e4f03fa2a8b359b293d81cdf 100755 (executable)
@@ -693,4 +693,138 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
        )
 '
 
+# Testcase rad, rename/add/delete
+#   Commit O: foo
+#   Commit A: rm foo, add different bar
+#   Commit B: rename foo->bar
+#   Expected: CONFLICT (rename/add/delete), two-way merged bar
+
+test_expect_success 'rad-setup: rename/add/delete conflict' '
+       test_create_repo rad &&
+       (
+               cd rad &&
+               echo "original file" >foo &&
+               git add foo &&
+               git commit -m "original" &&
+
+               git branch O &&
+               git branch A &&
+               git branch B &&
+
+               git checkout A &&
+               git rm foo &&
+               echo "different file" >bar &&
+               git add bar &&
+               git commit -m "Remove foo, add bar" &&
+
+               git checkout B &&
+               git mv foo bar &&
+               git commit -m "rename foo to bar"
+       )
+'
+
+test_expect_failure 'rad-check: rename/add/delete conflict' '
+       (
+               cd rad &&
+
+               git checkout B^0 &&
+               test_must_fail git merge -s recursive A^0 >out 2>err &&
+
+               # Not sure whether the output should contain just one
+               # "CONFLICT (rename/add/delete)" line, or if it should break
+               # it into a pair of "CONFLICT (rename/delete)" and
+               # "CONFLICT (rename/add)"; allow for either.
+               test_i18ngrep "CONFLICT (rename.*add)" out &&
+               test_i18ngrep "CONFLICT (rename.*delete)" out &&
+               test_must_be_empty err &&
+
+               git ls-files -s >file_count &&
+               test_line_count = 2 file_count &&
+               git ls-files -u >file_count &&
+               test_line_count = 2 file_count &&
+               git ls-files -o >file_count &&
+               test_line_count = 2 file_count &&
+
+               git rev-parse >actual \
+                       :2:bar :3:bar &&
+               git rev-parse >expect \
+                       B:bar  A:bar  &&
+
+               test_cmp file_is_missing foo &&
+               # bar should have two-way merged contents of the different
+               # versions of bar; check that content from both sides is
+               # present.
+               grep original bar &&
+               grep different bar
+       )
+'
+
+# Testcase rrdd, rename/rename(2to1)/delete/delete
+#   Commit O: foo, bar
+#   Commit A: rename foo->baz, rm bar
+#   Commit B: rename bar->baz, rm foo
+#   Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
+
+test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
+       test_create_repo rrdd &&
+       (
+               cd rrdd &&
+               echo foo >foo &&
+               echo bar >bar &&
+               git add foo bar &&
+               git commit -m O &&
+
+               git branch O &&
+               git branch A &&
+               git branch B &&
+
+               git checkout A &&
+               git mv foo baz &&
+               git rm bar &&
+               git commit -m "Rename foo, remove bar" &&
+
+               git checkout B &&
+               git mv bar baz &&
+               git rm foo &&
+               git commit -m "Rename bar, remove foo"
+       )
+'
+
+test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
+       (
+               cd rrdd &&
+
+               git checkout A^0 &&
+               test_must_fail git merge -s recursive B^0 >out 2>err &&
+
+               # Not sure whether the output should contain just one
+               # "CONFLICT (rename/rename/delete/delete)" line, or if it
+               # should break it into three: "CONFLICT (rename/rename)" and
+               # two "CONFLICT (rename/delete)" lines; allow for either.
+               test_i18ngrep "CONFLICT (rename/rename)" out &&
+               test_i18ngrep "CONFLICT (rename.*delete)" out &&
+               test_must_be_empty err &&
+
+               git ls-files -s >file_count &&
+               test_line_count = 2 file_count &&
+               git ls-files -u >file_count &&
+               test_line_count = 2 file_count &&
+               git ls-files -o >file_count &&
+               test_line_count = 2 file_count &&
+
+               git rev-parse >actual \
+                       :2:baz :3:baz &&
+               git rev-parse >expect \
+                       O:foo  O:bar  &&
+
+               test_cmp file_is_missing foo &&
+               test_cmp file_is_missing bar &&
+               # baz should have two-way merged contents of the original
+               # contents of foo and bar; check that content from both sides
+               # is present.
+               grep foo baz &&
+               grep bar baz
+       )
+'
+
 test_done