]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4117-apply-reject.sh
t/t5505-remote: modernize style
[thirdparty/git.git] / t / t4117-apply-reject.sh
CommitLineData
57dc397c
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git apply with rejects
57dc397c
JH
7
8'
9
10. ./test-lib.sh
11
12test_expect_success setup '
13 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
14 do
15 echo $i
16 done >file1 &&
17 cat file1 >saved.file1 &&
18 git update-index --add file1 &&
19 git commit -m initial &&
20
21 for i in 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21
22 do
23 echo $i
24 done >file1 &&
25 git diff >patch.1 &&
82e2765f
JH
26 cat file1 >clean &&
27
28 for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21
29 do
30 echo $i
31 done >expected &&
57dc397c
JH
32
33 mv file1 file2 &&
34 git update-index --add --remove file1 file2 &&
35 git diff -M HEAD >patch.2 &&
36
37 rm -f file1 file2 &&
38 mv saved.file1 file1 &&
39 git update-index --add --remove file1 file2 &&
40
41 for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21
42 do
43 echo $i
44 done >file1 &&
45
46 cat file1 >saved.file1
47'
48
cfb6f9ac
JH
49test_expect_success 'apply --reject is incompatible with --3way' '
50 test_when_finished "cat saved.file1 >file1" &&
51 git diff >patch.0 &&
52 git checkout file1 &&
53 test_must_fail git apply --reject --3way patch.0 &&
54 git diff --exit-code
55'
56
57dc397c
JH
57test_expect_success 'apply without --reject should fail' '
58
59 if git apply patch.1
60 then
61 echo "Eh? Why?"
62 exit 1
63 fi
64
3af82863 65 test_cmp file1 saved.file1
57dc397c
JH
66'
67
a2bf404e
JH
68test_expect_success 'apply without --reject should fail' '
69
70 if git apply --verbose patch.1
71 then
72 echo "Eh? Why?"
73 exit 1
74 fi
75
3af82863 76 test_cmp file1 saved.file1
a2bf404e
JH
77'
78
57dc397c
JH
79test_expect_success 'apply with --reject should fail but update the file' '
80
82e2765f
JH
81 cat saved.file1 >file1 &&
82 rm -f file1.rej file2.rej &&
57dc397c 83
82e2765f 84 if git apply --reject patch.1
57dc397c
JH
85 then
86 echo "succeeds with --reject?"
87 exit 1
88 fi
57dc397c 89
3af82863 90 test_cmp file1 expected &&
82e2765f
JH
91
92 cat file1.rej &&
93
94 if test -f file2.rej
95 then
96 echo "file2 should not have been touched"
97 exit 1
98 fi
57dc397c
JH
99'
100
101test_expect_success 'apply with --reject should fail but update the file' '
102
82e2765f
JH
103 cat saved.file1 >file1 &&
104 rm -f file1.rej file2.rej file2 &&
57dc397c
JH
105
106 if git apply --reject patch.2 >rejects
107 then
108 echo "succeeds with --reject?"
109 exit 1
110 fi
111
57dc397c
JH
112 test -f file1 && {
113 echo "file1 still exists?"
114 exit 1
115 }
3af82863 116 test_cmp file2 expected &&
82e2765f
JH
117
118 cat file2.rej &&
119
120 if test -f file1.rej
121 then
122 echo "file2 should not have been touched"
123 exit 1
124 fi
125
57dc397c
JH
126'
127
a2bf404e
JH
128test_expect_success 'the same test with --verbose' '
129
130 cat saved.file1 >file1 &&
131 rm -f file1.rej file2.rej file2 &&
132
133 if git apply --reject --verbose patch.2 >rejects
134 then
135 echo "succeeds with --reject?"
136 exit 1
137 fi
138
139 test -f file1 && {
140 echo "file1 still exists?"
141 exit 1
142 }
3af82863 143 test_cmp file2 expected &&
a2bf404e
JH
144
145 cat file2.rej &&
146
147 if test -f file1.rej
148 then
149 echo "file2 should not have been touched"
150 exit 1
151 fi
152
153'
154
155test_expect_success 'apply cleanly with --verbose' '
156
157 git cat-file -p HEAD:file1 >file1 &&
158 rm -f file?.rej file2 &&
159
160 git apply --verbose patch.1 &&
161
3af82863 162 test_cmp file1 clean
a2bf404e
JH
163'
164
57dc397c 165test_done