]>
Commit | Line | Data |
---|---|---|
57dc397c JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git apply with rejects |
57dc397c JH |
7 | |
8 | ' | |
9 | ||
10 | . ./test-lib.sh | |
11 | ||
12 | test_expect_success setup ' | |
08495412 | 13 | 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 && |
57dc397c JH |
14 | cat file1 >saved.file1 && |
15 | git update-index --add file1 && | |
16 | git commit -m initial && | |
17 | ||
08495412 | 18 | 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 && |
57dc397c | 19 | git diff >patch.1 && |
82e2765f JH |
20 | cat file1 >clean && |
21 | ||
08495412 | 22 | 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 && |
57dc397c JH |
23 | |
24 | mv file1 file2 && | |
25 | git update-index --add --remove file1 file2 && | |
26 | git diff -M HEAD >patch.2 && | |
27 | ||
28 | rm -f file1 file2 && | |
29 | mv saved.file1 file1 && | |
30 | git update-index --add --remove file1 file2 && | |
31 | ||
08495412 | 32 | 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 && |
57dc397c JH |
33 | |
34 | cat file1 >saved.file1 | |
35 | ' | |
36 | ||
cfb6f9ac JH |
37 | test_expect_success 'apply --reject is incompatible with --3way' ' |
38 | test_when_finished "cat saved.file1 >file1" && | |
39 | git diff >patch.0 && | |
40 | git checkout file1 && | |
41 | test_must_fail git apply --reject --3way patch.0 && | |
42 | git diff --exit-code | |
43 | ' | |
44 | ||
57dc397c JH |
45 | test_expect_success 'apply without --reject should fail' ' |
46 | ||
e7d053dd | 47 | test_must_fail git apply patch.1 && |
3af82863 | 48 | test_cmp file1 saved.file1 |
57dc397c JH |
49 | ' |
50 | ||
a2bf404e JH |
51 | test_expect_success 'apply without --reject should fail' ' |
52 | ||
e7d053dd | 53 | test_must_fail git apply --verbose patch.1 && |
3af82863 | 54 | test_cmp file1 saved.file1 |
a2bf404e JH |
55 | ' |
56 | ||
57dc397c JH |
57 | test_expect_success 'apply with --reject should fail but update the file' ' |
58 | ||
82e2765f JH |
59 | cat saved.file1 >file1 && |
60 | rm -f file1.rej file2.rej && | |
57dc397c | 61 | |
e7d053dd | 62 | test_must_fail git apply --reject patch.1 && |
dcbaa0b3 | 63 | test_cmp expected file1 && |
82e2765f | 64 | |
91de82ad | 65 | test_path_is_file file1.rej && |
e7d053dd | 66 | test_path_is_missing file2.rej |
57dc397c JH |
67 | ' |
68 | ||
69 | test_expect_success 'apply with --reject should fail but update the file' ' | |
70 | ||
82e2765f JH |
71 | cat saved.file1 >file1 && |
72 | rm -f file1.rej file2.rej file2 && | |
57dc397c | 73 | |
e7d053dd JK |
74 | test_must_fail git apply --reject patch.2 >rejects && |
75 | test_path_is_missing file1 && | |
dcbaa0b3 | 76 | test_cmp expected file2 && |
82e2765f | 77 | |
91de82ad | 78 | test_path_is_file file2.rej && |
e7d053dd | 79 | test_path_is_missing file1.rej |
82e2765f | 80 | |
57dc397c JH |
81 | ' |
82 | ||
a2bf404e JH |
83 | test_expect_success 'the same test with --verbose' ' |
84 | ||
85 | cat saved.file1 >file1 && | |
86 | rm -f file1.rej file2.rej file2 && | |
87 | ||
e7d053dd JK |
88 | test_must_fail git apply --reject --verbose patch.2 >rejects && |
89 | test_path_is_missing file1 && | |
dcbaa0b3 | 90 | test_cmp expected file2 && |
a2bf404e | 91 | |
91de82ad | 92 | test_path_is_file file2.rej && |
e7d053dd | 93 | test_path_is_missing file1.rej |
a2bf404e JH |
94 | |
95 | ' | |
96 | ||
97 | test_expect_success 'apply cleanly with --verbose' ' | |
98 | ||
99 | git cat-file -p HEAD:file1 >file1 && | |
100 | rm -f file?.rej file2 && | |
101 | ||
102 | git apply --verbose patch.1 && | |
103 | ||
3af82863 | 104 | test_cmp file1 clean |
a2bf404e JH |
105 | ' |
106 | ||
57dc397c | 107 | test_done |