3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git apply with rejects
10 TEST_PASSES_SANITIZE_LEAK
=true
13 test_expect_success setup
'
14 test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 >file1 &&
15 cat file1 >saved.file1 &&
16 git update-index --add file1 &&
17 git commit -m initial &&
19 test_write_lines 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 >file1 &&
23 test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 >expected &&
26 git update-index --add --remove file1 file2 &&
27 git diff -M HEAD >patch.2 &&
30 mv saved.file1 file1 &&
31 git update-index --add --remove file1 file2 &&
33 test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 >file1 &&
35 cat file1 >saved.file1
38 test_expect_success
'apply --reject is incompatible with --3way' '
39 test_when_finished "cat saved.file1 >file1" &&
42 test_must_fail git apply --reject --3way patch.0 &&
46 test_expect_success
'apply without --reject should fail' '
48 test_must_fail git apply patch.1 &&
49 test_cmp file1 saved.file1
52 test_expect_success
'apply without --reject should fail' '
54 test_must_fail git apply --verbose patch.1 &&
55 test_cmp file1 saved.file1
58 test_expect_success
'apply with --reject should fail but update the file' '
60 cat saved.file1 >file1 &&
61 rm -f file1.rej file2.rej &&
63 test_must_fail git apply --reject patch.1 &&
64 test_cmp expected file1 &&
66 test_path_is_file file1.rej &&
67 test_path_is_missing file2.rej
70 test_expect_success
'apply with --reject should fail but update the file' '
72 cat saved.file1 >file1 &&
73 rm -f file1.rej file2.rej file2 &&
75 test_must_fail git apply --reject patch.2 >rejects &&
76 test_path_is_missing file1 &&
77 test_cmp expected file2 &&
79 test_path_is_file file2.rej &&
80 test_path_is_missing file1.rej
84 test_expect_success
'the same test with --verbose' '
86 cat saved.file1 >file1 &&
87 rm -f file1.rej file2.rej file2 &&
89 test_must_fail git apply --reject --verbose patch.2 >rejects &&
90 test_path_is_missing file1 &&
91 test_cmp expected file2 &&
93 test_path_is_file file2.rej &&
94 test_path_is_missing file1.rej
98 test_expect_success
'apply cleanly with --verbose' '
100 git cat-file -p HEAD:file1 >file1 &&
101 rm -f file?.rej file2 &&
103 git apply --verbose patch.1 &&