apply: tests for the --3way option
authorJunio C Hamano <gitster@pobox.com>
Wed, 13 Jun 2012 05:57:57 +0000 (22:57 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Jul 2012 06:50:10 +0000 (23:50 -0700)
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4108-apply-threeway.sh

index e6d4da63b22c8a3df3d1dd075a8ebb88fb98e1d1..fa5d4efb89dc4ec83e3cd84fcb147958f361ab59 100755 (executable)
@@ -100,4 +100,58 @@ test_expect_success 'apply with --3way with rerere enabled' '
        test_cmp expect one
 '
 
+test_expect_success 'apply -3 with add/add conflict setup' '
+       git reset --hard &&
+
+       git checkout -b adder &&
+       create_file 1 2 3 4 5 6 7 >three &&
+       create_file 1 2 3 4 5 6 7 >four &&
+       git add three four &&
+       git commit -m "add three and four" &&
+
+       git checkout -b another adder^ &&
+       create_file 1 2 3 4 5 6 7 >three &&
+       create_file 1 2 3 four 5 6 7 >four &&
+       git add three four &&
+       git commit -m "add three and four" &&
+
+       # Merging another should be similar to applying this patch
+       git diff adder...another >P.diff &&
+
+       git checkout adder^0 &&
+       test_must_fail git merge --no-commit another &&
+       git ls-files -s >expect.ls &&
+       git diff HEAD | sanitize_conflicted_diff >expect.diff
+'
+
+test_expect_success 'apply -3 with add/add conflict' '
+       # should fail to apply ...
+       git reset --hard &&
+       git checkout adder^0 &&
+       test_must_fail git apply --index --3way P.diff &&
+       # ... and leave conflicts in the index and in the working tree
+       git ls-files -s >actual.ls &&
+       git diff HEAD | sanitize_conflicted_diff >actual.diff &&
+
+       # The result should resemble the corresponding merge
+       test_cmp expect.ls actual.ls &&
+       test_cmp expect.diff actual.diff
+'
+
+test_expect_success 'apply -3 with add/add conflict (dirty working tree)' '
+       # should fail to apply ...
+       git reset --hard &&
+       git checkout adder^0 &&
+       echo >>four &&
+       cat four >four.save &&
+       cat three >three.save &&
+       git ls-files -s >expect.ls &&
+       test_must_fail git apply --index --3way P.diff &&
+       # ... and should not touch anything
+       git ls-files -s >actual.ls &&
+       test_cmp expect.ls actual.ls &&
+       test_cmp four.save four &&
+       test_cmp three.save three
+'
+
 test_done