Imported Upstream version 2.25.3
[platform/upstream/git.git] / t / t6044-merge-unrelated-index-changes.sh
index 0102348..5e3779e 100755 (executable)
@@ -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' '
@@ -75,7 +82,8 @@ test_expect_success 'ff update, important file modified' '
        touch subdir/e &&
        git add subdir/e &&
 
-       test_must_fail git merge E^0
+       test_must_fail git merge E^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'resolve, trivial' '
@@ -84,7 +92,8 @@ test_expect_success 'resolve, trivial' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s resolve C^0
+       test_must_fail git merge -s resolve C^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'resolve, non-trivial' '
@@ -93,7 +102,8 @@ test_expect_success 'resolve, non-trivial' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s resolve D^0
+       test_must_fail git merge -s resolve D^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'recursive' '
@@ -102,7 +112,55 @@ test_expect_success 'recursive' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s recursive C^0
+       test_must_fail git merge -s recursive C^0 &&
+       test_path_is_missing .git/MERGE_HEAD
+'
+
+test_expect_success '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_path_is_missing .git/MERGE_HEAD
+'
+
+test_expect_success 'merge-recursive, when index==head but head!=HEAD' '
+       git reset --hard &&
+       git checkout C^0 &&
+
+       # Make index match B
+       git diff C B -- | git apply --cached &&
+       # Merge B & F, with B as "head"
+       git merge-recursive A -- B F > out &&
+       test_i18ngrep "Already up to date" out
+'
+
+test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' '
+       git reset --hard &&
+       git checkout B^0 &&
+
+       mkdir subdir &&
+       test_seq 1 10 >subdir/a &&
+       git add subdir/a &&
+
+       # We have staged changes; merge should error out
+       test_must_fail git merge -s recursive E^0 2>err &&
+       test_i18ngrep "changes to the following files would be overwritten" err
+'
+
+test_expect_success 'recursive, when file has staged changes matching what a merge would give' '
+       git reset --hard &&
+       git checkout B^0 &&
+
+       mkdir subdir &&
+       test_seq 1 11 >subdir/a &&
+       git add subdir/a &&
+
+       # We have staged changes; merge should error out
+       test_must_fail git merge -s recursive E^0 2>err &&
+       test_i18ngrep "changes to the following files would be overwritten" err
 '
 
 test_expect_success 'octopus, unrelated file touched' '
@@ -111,7 +169,8 @@ test_expect_success 'octopus, unrelated file touched' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge C^0 D^0
+       test_must_fail git merge C^0 D^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'octopus, related file removed' '
@@ -120,7 +179,8 @@ test_expect_success 'octopus, related file removed' '
 
        git rm b &&
 
-       test_must_fail git merge C^0 D^0
+       test_must_fail git merge C^0 D^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'octopus, related file modified' '
@@ -129,7 +189,8 @@ test_expect_success 'octopus, related file modified' '
 
        echo 12 >>a && git add a &&
 
-       test_must_fail git merge C^0 D^0
+       test_must_fail git merge C^0 D^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'ours' '
@@ -138,7 +199,8 @@ test_expect_success 'ours' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s ours C^0
+       test_must_fail git merge -s ours C^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_expect_success 'subtree' '
@@ -147,7 +209,8 @@ test_expect_success 'subtree' '
 
        touch random_file && git add random_file &&
 
-       test_must_fail git merge -s subtree E^0
+       test_must_fail git merge -s subtree E^0 &&
+       test_path_is_missing .git/MERGE_HEAD
 '
 
 test_done