Blame


1 069bbb86 2022-03-07 thomas #!/bin/sh
2 069bbb86 2022-03-07 thomas #
3 069bbb86 2022-03-07 thomas # Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 069bbb86 2022-03-07 thomas #
5 069bbb86 2022-03-07 thomas # Permission to use, copy, modify, and distribute this software for any
6 069bbb86 2022-03-07 thomas # purpose with or without fee is hereby granted, provided that the above
7 069bbb86 2022-03-07 thomas # copyright notice and this permission notice appear in all copies.
8 069bbb86 2022-03-07 thomas #
9 069bbb86 2022-03-07 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 069bbb86 2022-03-07 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 069bbb86 2022-03-07 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 069bbb86 2022-03-07 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 069bbb86 2022-03-07 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 069bbb86 2022-03-07 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 069bbb86 2022-03-07 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 069bbb86 2022-03-07 thomas
17 069bbb86 2022-03-07 thomas . ./common.sh
18 069bbb86 2022-03-07 thomas
19 3b6e8f19 2022-08-06 thomas test_patch_basic() {
20 3b6e8f19 2022-08-06 thomas local testroot=`test_init patch_basic`
21 069bbb86 2022-03-07 thomas
22 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
23 069bbb86 2022-03-07 thomas ret=$?
24 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
25 069bbb86 2022-03-07 thomas test_done $testroot $ret
26 069bbb86 2022-03-07 thomas return 1
27 069bbb86 2022-03-07 thomas fi
28 069bbb86 2022-03-07 thomas
29 cf85a643 2024-04-09 thomas seq 100 > $testroot/wt/numbers
30 3b6e8f19 2022-08-06 thomas (cd $testroot/wt && got add numbers && got commit -m +numbers) \
31 3b6e8f19 2022-08-06 thomas >/dev/null
32 069bbb86 2022-03-07 thomas ret=$?
33 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
34 3b6e8f19 2022-08-06 thomas test_done "$testroot" $ret
35 069bbb86 2022-03-07 thomas return 1
36 069bbb86 2022-03-07 thomas fi
37 069bbb86 2022-03-07 thomas
38 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
39 069bbb86 2022-03-07 thomas --- alpha
40 069bbb86 2022-03-07 thomas +++ alpha
41 069bbb86 2022-03-07 thomas @@ -1 +1 @@
42 069bbb86 2022-03-07 thomas -alpha
43 069bbb86 2022-03-07 thomas +alpha is my favourite character
44 3b6e8f19 2022-08-06 thomas --- beta
45 3b6e8f19 2022-08-06 thomas +++ /dev/null
46 3b6e8f19 2022-08-06 thomas @@ -1 +0,0 @@
47 3b6e8f19 2022-08-06 thomas -beta
48 3b6e8f19 2022-08-06 thomas --- gamma/delta
49 3b6e8f19 2022-08-06 thomas +++ gamma/delta
50 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
51 3b6e8f19 2022-08-06 thomas +this is:
52 3b6e8f19 2022-08-06 thomas delta
53 3b6e8f19 2022-08-06 thomas --- /dev/null
54 3b6e8f19 2022-08-06 thomas +++ eta
55 3b6e8f19 2022-08-06 thomas @@ -0,0 +5,5 @@
56 3b6e8f19 2022-08-06 thomas +1
57 3b6e8f19 2022-08-06 thomas +2
58 3b6e8f19 2022-08-06 thomas +3
59 3b6e8f19 2022-08-06 thomas +4
60 3b6e8f19 2022-08-06 thomas +5
61 069bbb86 2022-03-07 thomas --- numbers
62 069bbb86 2022-03-07 thomas +++ numbers
63 069bbb86 2022-03-07 thomas @@ -3,7 +3,7 @@
64 069bbb86 2022-03-07 thomas 3
65 069bbb86 2022-03-07 thomas 4
66 069bbb86 2022-03-07 thomas 5
67 069bbb86 2022-03-07 thomas -6
68 3b6e8f19 2022-08-06 thomas +six
69 069bbb86 2022-03-07 thomas 7
70 069bbb86 2022-03-07 thomas 8
71 069bbb86 2022-03-07 thomas 9
72 069bbb86 2022-03-07 thomas @@ -57,7 +57,7 @@
73 069bbb86 2022-03-07 thomas 57
74 069bbb86 2022-03-07 thomas 58
75 069bbb86 2022-03-07 thomas 59
76 069bbb86 2022-03-07 thomas -60
77 3b6e8f19 2022-08-06 thomas +sixty
78 069bbb86 2022-03-07 thomas 61
79 069bbb86 2022-03-07 thomas 62
80 069bbb86 2022-03-07 thomas 63
81 069bbb86 2022-03-07 thomas @@ -98,3 +98,6 @@
82 069bbb86 2022-03-07 thomas 98
83 069bbb86 2022-03-07 thomas 99
84 069bbb86 2022-03-07 thomas 100
85 069bbb86 2022-03-07 thomas +101
86 069bbb86 2022-03-07 thomas +102
87 3b6e8f19 2022-08-06 thomas +103
88 069bbb86 2022-03-07 thomas EOF
89 069bbb86 2022-03-07 thomas
90 ce3641f6 2022-10-16 thomas (cd $testroot/wt && got patch < patch) > $testroot/stdout
91 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
92 3b6e8f19 2022-08-06 thomas test_done "$testroot" $ret
93 069bbb86 2022-03-07 thomas return 1
94 069bbb86 2022-03-07 thomas fi
95 069bbb86 2022-03-07 thomas
96 3b6e8f19 2022-08-06 thomas echo 'M alpha' > $testroot/stdout.expected
97 3b6e8f19 2022-08-06 thomas echo 'D beta' >> $testroot/stdout.expected
98 3b6e8f19 2022-08-06 thomas echo 'M gamma/delta' >> $testroot/stdout.expected
99 3b6e8f19 2022-08-06 thomas echo 'A eta' >> $testroot/stdout.expected
100 3b6e8f19 2022-08-06 thomas echo 'M numbers' >> $testroot/stdout.expected
101 3b6e8f19 2022-08-06 thomas
102 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
103 069bbb86 2022-03-07 thomas ret=$?
104 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
105 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
106 069bbb86 2022-03-07 thomas test_done $testroot $ret
107 069bbb86 2022-03-07 thomas return 1
108 069bbb86 2022-03-07 thomas fi
109 069bbb86 2022-03-07 thomas
110 3b6e8f19 2022-08-06 thomas echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
111 3b6e8f19 2022-08-06 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
112 069bbb86 2022-03-07 thomas ret=$?
113 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
114 3b6e8f19 2022-08-06 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
115 3b6e8f19 2022-08-06 thomas test_done "$testroot" $ret
116 3b6e8f19 2022-08-06 thomas return 1
117 069bbb86 2022-03-07 thomas fi
118 069bbb86 2022-03-07 thomas
119 3b6e8f19 2022-08-06 thomas if [ -f "$testroot/wt/beta" ]; then
120 3b6e8f19 2022-08-06 thomas echo "beta was not deleted!" >&2
121 3b6e8f19 2022-08-06 thomas test_done "$testroot" 1
122 069bbb86 2022-03-07 thomas return 1
123 069bbb86 2022-03-07 thomas fi
124 069bbb86 2022-03-07 thomas
125 3b6e8f19 2022-08-06 thomas echo 'this is:' > $testroot/wt/gamma/delta.expected
126 3b6e8f19 2022-08-06 thomas echo 'delta' >> $testroot/wt/gamma/delta.expected
127 3b6e8f19 2022-08-06 thomas cmp -s $testroot/wt/gamma/delta.expected $testroot/wt/gamma/delta
128 069bbb86 2022-03-07 thomas ret=$?
129 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
130 3b6e8f19 2022-08-06 thomas diff -u $testroot/wt/gamma/delta.expected $testroot/wt/gamma/delta
131 3b6e8f19 2022-08-06 thomas test_done "$testroot" $ret
132 069bbb86 2022-03-07 thomas return 1
133 069bbb86 2022-03-07 thomas fi
134 069bbb86 2022-03-07 thomas
135 cf85a643 2024-04-09 thomas seq 5 > $testroot/wt/eta.expected
136 3b6e8f19 2022-08-06 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
137 069bbb86 2022-03-07 thomas ret=$?
138 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
139 3b6e8f19 2022-08-06 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
140 3b6e8f19 2022-08-06 thomas test_done "$testroot" $ret
141 069bbb86 2022-03-07 thomas return 1
142 069bbb86 2022-03-07 thomas fi
143 069bbb86 2022-03-07 thomas
144 cf85a643 2024-04-09 thomas seq 103 | sed -e 's/^6$/six/' -e 's/60/sixty/' \
145 3b6e8f19 2022-08-06 thomas > $testroot/wt/numbers.expected
146 3b6e8f19 2022-08-06 thomas cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
147 3b6e8f19 2022-08-06 thomas ret=$?
148 3b6e8f19 2022-08-06 thomas if [ $ret -ne 0 ]; then
149 3b6e8f19 2022-08-06 thomas diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
150 3b6e8f19 2022-08-06 thomas fi
151 3b6e8f19 2022-08-06 thomas test_done $testroot $ret
152 069bbb86 2022-03-07 thomas }
153 069bbb86 2022-03-07 thomas
154 069bbb86 2022-03-07 thomas test_patch_dont_apply() {
155 069bbb86 2022-03-07 thomas local testroot=`test_init patch_dont_apply`
156 069bbb86 2022-03-07 thomas
157 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
158 069bbb86 2022-03-07 thomas ret=$?
159 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
160 069bbb86 2022-03-07 thomas test_done $testroot $ret
161 069bbb86 2022-03-07 thomas return 1
162 069bbb86 2022-03-07 thomas fi
163 069bbb86 2022-03-07 thomas
164 cf85a643 2024-04-09 thomas seq 100 > $testroot/wt/numbers
165 7dd42450 2022-03-13 thomas (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
166 7dd42450 2022-03-13 thomas >/dev/null
167 7dd42450 2022-03-13 thomas ret=$?
168 7dd42450 2022-03-13 thomas if [ $ret -ne 0 ]; then
169 7dd42450 2022-03-13 thomas test_done $testroot $ret
170 7dd42450 2022-03-13 thomas return 1
171 7dd42450 2022-03-13 thomas fi
172 7dd42450 2022-03-13 thomas
173 7dd42450 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
174 49114f01 2022-03-22 thomas --- alpha
175 49114f01 2022-03-22 thomas +++ alpha
176 49114f01 2022-03-22 thomas @@ -1 +1,2 @@
177 49114f01 2022-03-22 thomas +hatsuseno
178 49114f01 2022-03-22 thomas alpha something
179 7dd42450 2022-03-13 thomas --- numbers
180 7dd42450 2022-03-13 thomas +++ /dev/null
181 7dd42450 2022-03-13 thomas @@ -1,9 +0,0 @@
182 7dd42450 2022-03-13 thomas -1
183 7dd42450 2022-03-13 thomas -2
184 7dd42450 2022-03-13 thomas -3
185 7dd42450 2022-03-13 thomas -4
186 7dd42450 2022-03-13 thomas -5
187 7dd42450 2022-03-13 thomas -6
188 7dd42450 2022-03-13 thomas -7
189 7dd42450 2022-03-13 thomas -8
190 7dd42450 2022-03-13 thomas -9
191 7dd42450 2022-03-13 thomas EOF
192 7dd42450 2022-03-13 thomas
193 49114f01 2022-03-22 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
194 7dd42450 2022-03-13 thomas ret=$?
195 7dd42450 2022-03-13 thomas if [ $ret -eq 0 ]; then # should fail
196 7dd42450 2022-03-13 thomas test_done $testroot 1
197 069bbb86 2022-03-07 thomas return 1
198 069bbb86 2022-03-07 thomas fi
199 069bbb86 2022-03-07 thomas
200 49114f01 2022-03-22 thomas cat <<EOF > $testroot/stdout.expected
201 49114f01 2022-03-22 thomas # alpha
202 49114f01 2022-03-22 thomas @@ -1,1 +1,2 @@ hunk failed to apply
203 49114f01 2022-03-22 thomas # numbers
204 49114f01 2022-03-22 thomas @@ -1,9 +0,0 @@ hunk failed to apply
205 1faec3fb 2023-05-14 thomas Files where patch failed to apply: 2
206 49114f01 2022-03-22 thomas EOF
207 49114f01 2022-03-22 thomas
208 49114f01 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
209 7dd42450 2022-03-13 thomas ret=$?
210 7dd42450 2022-03-13 thomas if [ $ret -ne 0 ]; then
211 49114f01 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
212 7dd42450 2022-03-13 thomas fi
213 069bbb86 2022-03-07 thomas test_done $testroot $ret
214 069bbb86 2022-03-07 thomas }
215 069bbb86 2022-03-07 thomas
216 069bbb86 2022-03-07 thomas test_patch_malformed() {
217 069bbb86 2022-03-07 thomas local testroot=`test_init patch_malformed`
218 069bbb86 2022-03-07 thomas
219 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
220 069bbb86 2022-03-07 thomas ret=$?
221 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
222 069bbb86 2022-03-07 thomas test_done $testroot $ret
223 069bbb86 2022-03-07 thomas return 1
224 069bbb86 2022-03-07 thomas fi
225 069bbb86 2022-03-07 thomas
226 069bbb86 2022-03-07 thomas # missing "@@"
227 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
228 069bbb86 2022-03-07 thomas --- alpha
229 069bbb86 2022-03-07 thomas +++ alpha
230 069bbb86 2022-03-07 thomas @@ -1 +1,2
231 069bbb86 2022-03-07 thomas +hatsuseno
232 069bbb86 2022-03-07 thomas alpha
233 069bbb86 2022-03-07 thomas EOF
234 069bbb86 2022-03-07 thomas
235 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
236 069bbb86 2022-03-07 thomas echo "got: malformed patch" > $testroot/stderr.expected
237 069bbb86 2022-03-07 thomas
238 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
239 069bbb86 2022-03-07 thomas > $testroot/stdout \
240 069bbb86 2022-03-07 thomas 2> $testroot/stderr
241 069bbb86 2022-03-07 thomas ret=$?
242 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then
243 069bbb86 2022-03-07 thomas echo "got managed to apply an invalid patch"
244 069bbb86 2022-03-07 thomas test_done $testroot 1
245 069bbb86 2022-03-07 thomas return 1
246 069bbb86 2022-03-07 thomas fi
247 069bbb86 2022-03-07 thomas
248 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
249 069bbb86 2022-03-07 thomas ret=$?
250 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
251 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
252 069bbb86 2022-03-07 thomas test_done $testroot $ret
253 069bbb86 2022-03-07 thomas return 1
254 069bbb86 2022-03-07 thomas fi
255 069bbb86 2022-03-07 thomas
256 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
257 069bbb86 2022-03-07 thomas ret=$?
258 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
259 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
260 069bbb86 2022-03-07 thomas test_done $testroot $ret
261 069bbb86 2022-03-07 thomas return 1
262 069bbb86 2022-03-07 thomas fi
263 069bbb86 2022-03-07 thomas
264 069bbb86 2022-03-07 thomas # wrong first character
265 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
266 069bbb86 2022-03-07 thomas --- alpha
267 069bbb86 2022-03-07 thomas +++ alpha
268 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
269 069bbb86 2022-03-07 thomas +hatsuseno
270 069bbb86 2022-03-07 thomas alpha
271 88c260f4 2022-05-14 thomas EOF
272 88c260f4 2022-05-14 thomas
273 88c260f4 2022-05-14 thomas (cd $testroot/wt && got patch patch) \
274 88c260f4 2022-05-14 thomas > $testroot/stdout \
275 88c260f4 2022-05-14 thomas 2> $testroot/stderr
276 88c260f4 2022-05-14 thomas ret=$?
277 88c260f4 2022-05-14 thomas if [ $ret -eq 0 ]; then
278 88c260f4 2022-05-14 thomas echo "got managed to apply an invalid patch"
279 88c260f4 2022-05-14 thomas test_done $testroot 1
280 88c260f4 2022-05-14 thomas return 1
281 88c260f4 2022-05-14 thomas fi
282 88c260f4 2022-05-14 thomas
283 88c260f4 2022-05-14 thomas cmp -s $testroot/stdout.expected $testroot/stdout
284 88c260f4 2022-05-14 thomas ret=$?
285 88c260f4 2022-05-14 thomas if [ $ret -ne 0 ]; then
286 88c260f4 2022-05-14 thomas diff -u $testroot/stdout.expected $testroot/stdout
287 88c260f4 2022-05-14 thomas test_done $testroot $ret
288 88c260f4 2022-05-14 thomas return 1
289 88c260f4 2022-05-14 thomas fi
290 88c260f4 2022-05-14 thomas
291 88c260f4 2022-05-14 thomas cmp -s $testroot/stderr.expected $testroot/stderr
292 88c260f4 2022-05-14 thomas ret=$?
293 88c260f4 2022-05-14 thomas if [ $ret -ne 0 ]; then
294 88c260f4 2022-05-14 thomas diff -u $testroot/stderr.expected $testroot/stderr
295 88c260f4 2022-05-14 thomas test_done $testroot $ret
296 88c260f4 2022-05-14 thomas return 1
297 88c260f4 2022-05-14 thomas fi
298 88c260f4 2022-05-14 thomas
299 88c260f4 2022-05-14 thomas # empty hunk
300 88c260f4 2022-05-14 thomas cat <<EOF > $testroot/wt/patch
301 88c260f4 2022-05-14 thomas diff --git a/alpha b/iota
302 88c260f4 2022-05-14 thomas --- a/alpha
303 88c260f4 2022-05-14 thomas +++ b/iota
304 88c260f4 2022-05-14 thomas @@ -0,0 +0,0 @@
305 069bbb86 2022-03-07 thomas EOF
306 069bbb86 2022-03-07 thomas
307 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
308 069bbb86 2022-03-07 thomas > $testroot/stdout \
309 069bbb86 2022-03-07 thomas 2> $testroot/stderr
310 069bbb86 2022-03-07 thomas ret=$?
311 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then
312 069bbb86 2022-03-07 thomas echo "got managed to apply an invalid patch"
313 069bbb86 2022-03-07 thomas test_done $testroot 1
314 069bbb86 2022-03-07 thomas return 1
315 069bbb86 2022-03-07 thomas fi
316 069bbb86 2022-03-07 thomas
317 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
318 069bbb86 2022-03-07 thomas ret=$?
319 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
320 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
321 069bbb86 2022-03-07 thomas test_done $testroot $ret
322 069bbb86 2022-03-07 thomas return 1
323 069bbb86 2022-03-07 thomas fi
324 069bbb86 2022-03-07 thomas
325 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
326 069bbb86 2022-03-07 thomas ret=$?
327 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
328 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
329 069bbb86 2022-03-07 thomas test_done $testroot $ret
330 069bbb86 2022-03-07 thomas return 1
331 069bbb86 2022-03-07 thomas fi
332 069bbb86 2022-03-07 thomas
333 069bbb86 2022-03-07 thomas test_done $testroot $ret
334 069bbb86 2022-03-07 thomas }
335 069bbb86 2022-03-07 thomas
336 069bbb86 2022-03-07 thomas test_patch_no_patch() {
337 069bbb86 2022-03-07 thomas local testroot=`test_init patch_no_patch`
338 069bbb86 2022-03-07 thomas
339 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
340 069bbb86 2022-03-07 thomas ret=$?
341 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
342 069bbb86 2022-03-07 thomas test_done $testroot $ret
343 069bbb86 2022-03-07 thomas return 1
344 069bbb86 2022-03-07 thomas fi
345 069bbb86 2022-03-07 thomas
346 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
347 069bbb86 2022-03-07 thomas hello world!
348 069bbb86 2022-03-07 thomas ...
349 069bbb86 2022-03-07 thomas
350 069bbb86 2022-03-07 thomas some other nonsense
351 069bbb86 2022-03-07 thomas ...
352 069bbb86 2022-03-07 thomas
353 069bbb86 2022-03-07 thomas there's no patch in here!
354 069bbb86 2022-03-07 thomas EOF
355 069bbb86 2022-03-07 thomas
356 069bbb86 2022-03-07 thomas echo -n > $testroot/stdout.expected
357 069bbb86 2022-03-07 thomas echo "got: no patch found" > $testroot/stderr.expected
358 069bbb86 2022-03-07 thomas
359 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) \
360 069bbb86 2022-03-07 thomas > $testroot/stdout \
361 069bbb86 2022-03-07 thomas 2> $testroot/stderr
362 069bbb86 2022-03-07 thomas ret=$?
363 10cdd9aa 2022-03-08 thomas if [ $ret -eq 0 ]; then # should fail
364 069bbb86 2022-03-07 thomas test_done $testroot 1
365 069bbb86 2022-03-07 thomas return 1
366 069bbb86 2022-03-07 thomas fi
367 e1c219c8 2022-04-22 thomas
368 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
369 069bbb86 2022-03-07 thomas ret=$?
370 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
371 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
372 069bbb86 2022-03-07 thomas test_done $testroot $ret
373 069bbb86 2022-03-07 thomas return 1
374 069bbb86 2022-03-07 thomas fi
375 069bbb86 2022-03-07 thomas
376 069bbb86 2022-03-07 thomas cmp -s $testroot/stderr.expected $testroot/stderr
377 069bbb86 2022-03-07 thomas ret=$?
378 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
379 069bbb86 2022-03-07 thomas diff -u $testroot/stderr.expected $testroot/stderr
380 069bbb86 2022-03-07 thomas test_done $testroot $ret
381 069bbb86 2022-03-07 thomas return 1
382 069bbb86 2022-03-07 thomas fi
383 069bbb86 2022-03-07 thomas
384 069bbb86 2022-03-07 thomas test_done $testroot $ret
385 069bbb86 2022-03-07 thomas }
386 069bbb86 2022-03-07 thomas
387 069bbb86 2022-03-07 thomas test_patch_equals_for_context() {
388 9a49df74 2022-04-23 thomas local testroot=`test_init patch_equals_for_context`
389 069bbb86 2022-03-07 thomas
390 069bbb86 2022-03-07 thomas got checkout $testroot/repo $testroot/wt > /dev/null
391 069bbb86 2022-03-07 thomas ret=$?
392 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
393 069bbb86 2022-03-07 thomas test_done $testroot $ret
394 069bbb86 2022-03-07 thomas return 1
395 069bbb86 2022-03-07 thomas fi
396 069bbb86 2022-03-07 thomas
397 069bbb86 2022-03-07 thomas cat <<EOF > $testroot/wt/patch
398 069bbb86 2022-03-07 thomas --- alpha
399 069bbb86 2022-03-07 thomas +++ alpha
400 069bbb86 2022-03-07 thomas @@ -1 +1,2 @@
401 069bbb86 2022-03-07 thomas +hatsuseno
402 069bbb86 2022-03-07 thomas =alpha
403 069bbb86 2022-03-07 thomas EOF
404 069bbb86 2022-03-07 thomas
405 069bbb86 2022-03-07 thomas echo "M alpha" > $testroot/stdout.expected
406 069bbb86 2022-03-07 thomas
407 069bbb86 2022-03-07 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
408 069bbb86 2022-03-07 thomas ret=$?
409 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
410 069bbb86 2022-03-07 thomas test_done $testroot $ret
411 069bbb86 2022-03-07 thomas return 1
412 069bbb86 2022-03-07 thomas fi
413 069bbb86 2022-03-07 thomas
414 069bbb86 2022-03-07 thomas cmp -s $testroot/stdout.expected $testroot/stdout
415 069bbb86 2022-03-07 thomas ret=$?
416 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
417 069bbb86 2022-03-07 thomas diff -u $testroot/stdout.expected $testroot/stdout
418 069bbb86 2022-03-07 thomas test_done $testroot $ret
419 069bbb86 2022-03-07 thomas return 1
420 069bbb86 2022-03-07 thomas fi
421 069bbb86 2022-03-07 thomas
422 069bbb86 2022-03-07 thomas echo hatsuseno > $testroot/wt/alpha.expected
423 069bbb86 2022-03-07 thomas echo alpha >> $testroot/wt/alpha.expected
424 069bbb86 2022-03-07 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
425 069bbb86 2022-03-07 thomas ret=$?
426 10cdd9aa 2022-03-08 thomas if [ $ret -ne 0 ]; then
427 069bbb86 2022-03-07 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
428 069bbb86 2022-03-07 thomas fi
429 069bbb86 2022-03-07 thomas test_done $testroot $ret
430 069bbb86 2022-03-07 thomas }
431 bb2ad8ff 2022-03-13 thomas
432 bb2ad8ff 2022-03-13 thomas test_patch_rename() {
433 bb2ad8ff 2022-03-13 thomas local testroot=`test_init patch_rename`
434 bb2ad8ff 2022-03-13 thomas
435 bb2ad8ff 2022-03-13 thomas got checkout $testroot/repo $testroot/wt > /dev/null
436 bb2ad8ff 2022-03-13 thomas ret=$?
437 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
438 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
439 bb2ad8ff 2022-03-13 thomas return 1
440 bb2ad8ff 2022-03-13 thomas fi
441 bb2ad8ff 2022-03-13 thomas
442 bb2ad8ff 2022-03-13 thomas cat <<EOF > $testroot/wt/patch
443 8afe1f71 2022-05-12 thomas diff --git a/beta b/iota
444 8afe1f71 2022-05-12 thomas similarity index 100%
445 8afe1f71 2022-05-12 thomas rename from beta
446 8afe1f71 2022-05-12 thomas rename to iota
447 be53ddb1 2022-03-22 thomas diff --git a/alpha b/eta
448 be53ddb1 2022-03-22 thomas --- a/alpha
449 be53ddb1 2022-03-22 thomas +++ b/eta
450 8afe1f71 2022-05-12 thomas @@ -1 +1 @@
451 8afe1f71 2022-05-12 thomas -alpha
452 8afe1f71 2022-05-12 thomas +eta
453 bb2ad8ff 2022-03-13 thomas EOF
454 069bbb86 2022-03-07 thomas
455 8afe1f71 2022-05-12 thomas echo 'D beta' > $testroot/stdout.expected
456 8afe1f71 2022-05-12 thomas echo 'A iota' >> $testroot/stdout.expected
457 8afe1f71 2022-05-12 thomas echo 'D alpha' >> $testroot/stdout.expected
458 8afe1f71 2022-05-12 thomas echo 'A eta' >> $testroot/stdout.expected
459 bb2ad8ff 2022-03-13 thomas
460 bb2ad8ff 2022-03-13 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
461 bb2ad8ff 2022-03-13 thomas ret=$?
462 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
463 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
464 bb2ad8ff 2022-03-13 thomas return 1
465 bb2ad8ff 2022-03-13 thomas fi
466 bb2ad8ff 2022-03-13 thomas
467 bb2ad8ff 2022-03-13 thomas cmp -s $testroot/stdout.expected $testroot/stdout
468 bb2ad8ff 2022-03-13 thomas ret=$?
469 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
470 bb2ad8ff 2022-03-13 thomas diff -u $testroot/stdout.expected $testroot/stdout
471 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
472 bb2ad8ff 2022-03-13 thomas return 1
473 bb2ad8ff 2022-03-13 thomas fi
474 bb2ad8ff 2022-03-13 thomas
475 8afe1f71 2022-05-12 thomas if [ -f $testroot/wt/alpha -o -f $testroot/wt/beta ]; then
476 8afe1f71 2022-05-12 thomas echo "alpha or beta were not removed" >&2
477 bb2ad8ff 2022-03-13 thomas test_done $testroot 1
478 bb2ad8ff 2022-03-13 thomas return 1
479 bb2ad8ff 2022-03-13 thomas fi
480 8afe1f71 2022-05-12 thomas if [ ! -f $testroot/wt/iota -o ! -f $testroot/wt/eta ]; then
481 8afe1f71 2022-05-12 thomas echo "iota or eta were not created" >&2
482 bb2ad8ff 2022-03-13 thomas test_done $testroot 1
483 bb2ad8ff 2022-03-13 thomas return 1
484 bb2ad8ff 2022-03-13 thomas fi
485 bb2ad8ff 2022-03-13 thomas
486 8afe1f71 2022-05-12 thomas echo beta > $testroot/wt/iota.expected
487 8afe1f71 2022-05-12 thomas cmp -s $testroot/wt/iota.expected $testroot/wt/iota
488 bb2ad8ff 2022-03-13 thomas ret=$?
489 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
490 8afe1f71 2022-05-12 thomas diff -u $testroot/wt/iota.expected $testroot/wt/iota
491 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
492 bb2ad8ff 2022-03-13 thomas return 1
493 bb2ad8ff 2022-03-13 thomas fi
494 bb2ad8ff 2022-03-13 thomas
495 8afe1f71 2022-05-12 thomas echo eta > $testroot/wt/eta.expected
496 8afe1f71 2022-05-12 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
497 bb2ad8ff 2022-03-13 thomas ret=$?
498 bb2ad8ff 2022-03-13 thomas if [ $ret -ne 0 ]; then
499 8afe1f71 2022-05-12 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
500 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
501 bb2ad8ff 2022-03-13 thomas return 1
502 bb2ad8ff 2022-03-13 thomas fi
503 bb2ad8ff 2022-03-13 thomas
504 bb2ad8ff 2022-03-13 thomas test_done $testroot $ret
505 bb2ad8ff 2022-03-13 thomas }
506 10e55613 2022-03-22 thomas
507 10e55613 2022-03-22 thomas test_patch_illegal_status() {
508 10e55613 2022-03-22 thomas local testroot=`test_init patch_illegal_status`
509 10e55613 2022-03-22 thomas
510 10e55613 2022-03-22 thomas got checkout $testroot/repo $testroot/wt > /dev/null
511 10e55613 2022-03-22 thomas ret=$?
512 10e55613 2022-03-22 thomas if [ $ret -ne 0 ]; then
513 10e55613 2022-03-22 thomas test_done $testroot $ret
514 10e55613 2022-03-22 thomas return 1
515 10e55613 2022-03-22 thomas fi
516 10e55613 2022-03-22 thomas
517 49114f01 2022-03-22 thomas # try to patch an obstructed file, add a versioned one, edit a
518 49114f01 2022-03-22 thomas # non existent file and an unversioned one, and remove a
519 49114f01 2022-03-22 thomas # non existent file.
520 10e55613 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
521 49114f01 2022-03-22 thomas --- alpha
522 49114f01 2022-03-22 thomas +++ alpha
523 49114f01 2022-03-22 thomas @@ -1 +1,2 @@
524 49114f01 2022-03-22 thomas alpha
525 49114f01 2022-03-22 thomas +was edited
526 49114f01 2022-03-22 thomas --- /dev/null
527 49114f01 2022-03-22 thomas +++ beta
528 49114f01 2022-03-22 thomas @@ -0,0 +1 @@
529 49114f01 2022-03-22 thomas +beta
530 10e55613 2022-03-22 thomas --- iota
531 10e55613 2022-03-22 thomas +++ iota
532 10e55613 2022-03-22 thomas @@ -1 +1 @@
533 49114f01 2022-03-22 thomas -iota
534 49114f01 2022-03-22 thomas +IOTA
535 49114f01 2022-03-22 thomas --- kappa
536 49114f01 2022-03-22 thomas +++ kappa
537 49114f01 2022-03-22 thomas @@ -1 +1 @@
538 49114f01 2022-03-22 thomas -kappa
539 49114f01 2022-03-22 thomas +KAPPA
540 49114f01 2022-03-22 thomas --- lambda
541 49114f01 2022-03-22 thomas +++ /dev/null
542 49114f01 2022-03-22 thomas @@ -1 +0,0 @@
543 49114f01 2022-03-22 thomas -lambda
544 10e55613 2022-03-22 thomas EOF
545 42d9d68e 2022-03-13 thomas
546 49114f01 2022-03-22 thomas echo kappa > $testroot/wt/kappa
547 10e55613 2022-03-22 thomas rm $testroot/wt/alpha
548 10e55613 2022-03-22 thomas mkdir $testroot/wt/alpha
549 10e55613 2022-03-22 thomas
550 49114f01 2022-03-22 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout \
551 10e55613 2022-03-22 thomas 2> $testroot/stderr
552 10e55613 2022-03-22 thomas ret=$?
553 10e55613 2022-03-22 thomas if [ $ret -eq 0 ]; then
554 10e55613 2022-03-22 thomas echo "edited a missing file" >&2
555 4e2bdb0d 2022-06-13 thomas test_done $testroot 1
556 10e55613 2022-03-22 thomas return 1
557 10e55613 2022-03-22 thomas fi
558 10e55613 2022-03-22 thomas
559 49114f01 2022-03-22 thomas cat <<EOF > $testroot/stdout.expected
560 49114f01 2022-03-22 thomas # alpha
561 49114f01 2022-03-22 thomas # beta
562 49114f01 2022-03-22 thomas # iota
563 49114f01 2022-03-22 thomas # kappa
564 49114f01 2022-03-22 thomas # lambda
565 1faec3fb 2023-05-14 thomas Files where patch failed to apply: 5
566 49114f01 2022-03-22 thomas EOF
567 10e55613 2022-03-22 thomas
568 49114f01 2022-03-22 thomas cat <<EOF > $testroot/stderr.expected
569 49114f01 2022-03-22 thomas got: alpha: file has unexpected status
570 49114f01 2022-03-22 thomas got: beta: file has unexpected status
571 49114f01 2022-03-22 thomas got: iota: No such file or directory
572 49114f01 2022-03-22 thomas got: kappa: file has unexpected status
573 49114f01 2022-03-22 thomas got: lambda: No such file or directory
574 49114f01 2022-03-22 thomas got: patch failed to apply
575 10e55613 2022-03-22 thomas EOF
576 10e55613 2022-03-22 thomas
577 49114f01 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
578 10e55613 2022-03-22 thomas ret=$?
579 49114f01 2022-03-22 thomas if [ $ret -ne 0 ]; then
580 49114f01 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
581 10e55613 2022-03-22 thomas test_done $testroot $ret
582 10e55613 2022-03-22 thomas return 1
583 10e55613 2022-03-22 thomas fi
584 10e55613 2022-03-22 thomas
585 10e55613 2022-03-22 thomas cmp -s $testroot/stderr.expected $testroot/stderr
586 10e55613 2022-03-22 thomas ret=$?
587 49114f01 2022-03-22 thomas if [ $ret -ne 0 ]; then
588 10e55613 2022-03-22 thomas diff -u $testroot/stderr.expected $testroot/stderr
589 814624e7 2022-03-22 thomas test_done $testroot $ret
590 814624e7 2022-03-22 thomas return 1
591 10e55613 2022-03-22 thomas fi
592 814624e7 2022-03-22 thomas
593 814624e7 2022-03-22 thomas (cd $testroot/wt && got status) > $testroot/stdout
594 814624e7 2022-03-22 thomas cat <<EOF > $testroot/stdout.expected
595 814624e7 2022-03-22 thomas ~ alpha
596 814624e7 2022-03-22 thomas ? kappa
597 814624e7 2022-03-22 thomas ? patch
598 814624e7 2022-03-22 thomas EOF
599 814624e7 2022-03-22 thomas
600 814624e7 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
601 814624e7 2022-03-22 thomas ret=$?
602 814624e7 2022-03-22 thomas if [ $ret -ne 0 ]; then
603 814624e7 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
604 814624e7 2022-03-22 thomas fi
605 eaf99875 2022-03-22 thomas test_done $testroot $ret
606 eaf99875 2022-03-22 thomas }
607 eaf99875 2022-03-22 thomas
608 eaf99875 2022-03-22 thomas test_patch_nop() {
609 eaf99875 2022-03-22 thomas local testroot=`test_init patch_nop`
610 eaf99875 2022-03-22 thomas
611 eaf99875 2022-03-22 thomas got checkout $testroot/repo $testroot/wt > /dev/null
612 eaf99875 2022-03-22 thomas ret=$?
613 eaf99875 2022-03-22 thomas if [ $ret -ne 0 ]; then
614 eaf99875 2022-03-22 thomas test_done $testroot $ret
615 eaf99875 2022-03-22 thomas return 1
616 eaf99875 2022-03-22 thomas fi
617 eaf99875 2022-03-22 thomas
618 eaf99875 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
619 eaf99875 2022-03-22 thomas --- alpha
620 eaf99875 2022-03-22 thomas +++ alpha
621 eaf99875 2022-03-22 thomas @@ -1 +1 @@
622 eaf99875 2022-03-22 thomas -alpha
623 eaf99875 2022-03-22 thomas +cafe alpha
624 eaf99875 2022-03-22 thomas --- beta
625 eaf99875 2022-03-22 thomas +++ /dev/null
626 eaf99875 2022-03-22 thomas @@ -1 +0,0 @@
627 eaf99875 2022-03-22 thomas -beta
628 be53ddb1 2022-03-22 thomas diff --git a/gamma/delta b/gamma/delta.new
629 eaf99875 2022-03-22 thomas --- gamma/delta
630 eaf99875 2022-03-22 thomas +++ gamma/delta.new
631 eaf99875 2022-03-22 thomas @@ -1 +1 @@
632 eaf99875 2022-03-22 thomas -delta
633 eaf99875 2022-03-22 thomas +delta updated and renamed!
634 eaf99875 2022-03-22 thomas EOF
635 eaf99875 2022-03-22 thomas
636 eaf99875 2022-03-22 thomas (cd $testroot/wt && got patch -n patch)
637 eaf99875 2022-03-22 thomas ret=$?
638 eaf99875 2022-03-22 thomas if [ $ret -ne 0 ]; then
639 eaf99875 2022-03-22 thomas test_done $testroot $ret
640 eaf99875 2022-03-22 thomas return 1
641 10e55613 2022-03-22 thomas fi
642 eaf99875 2022-03-22 thomas
643 eaf99875 2022-03-22 thomas # remove the patch to avoid the ? entry
644 eaf99875 2022-03-22 thomas rm $testroot/wt/patch
645 eaf99875 2022-03-22 thomas
646 eaf99875 2022-03-22 thomas (cd $testroot/wt && got status) > $testroot/stdout
647 eaf99875 2022-03-22 thomas ret=$?
648 eaf99875 2022-03-22 thomas if [ $ret -ne 0 ]; then
649 eaf99875 2022-03-22 thomas test_done $testroot $ret
650 eaf99875 2022-03-22 thomas return 1
651 eaf99875 2022-03-22 thomas fi
652 eaf99875 2022-03-22 thomas
653 eaf99875 2022-03-22 thomas echo -n > $testroot/stdout.expected
654 eaf99875 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
655 eaf99875 2022-03-22 thomas ret=$?
656 eaf99875 2022-03-22 thomas if [ $ret -ne 0 ]; then
657 eaf99875 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
658 eaf99875 2022-03-22 thomas fi
659 10e55613 2022-03-22 thomas test_done $testroot $ret
660 da09d8ed 2022-03-22 thomas }
661 da09d8ed 2022-03-22 thomas
662 da09d8ed 2022-03-22 thomas test_patch_preserve_perm() {
663 da09d8ed 2022-03-22 thomas local testroot=`test_init patch_preserve_perm`
664 da09d8ed 2022-03-22 thomas
665 da09d8ed 2022-03-22 thomas got checkout $testroot/repo $testroot/wt > /dev/null
666 da09d8ed 2022-03-22 thomas ret=$?
667 da09d8ed 2022-03-22 thomas if [ $ret -ne 0 ]; then
668 da09d8ed 2022-03-22 thomas test_done $testroot $ret
669 da09d8ed 2022-03-22 thomas return 1
670 da09d8ed 2022-03-22 thomas fi
671 da09d8ed 2022-03-22 thomas
672 da09d8ed 2022-03-22 thomas chmod +x $testroot/wt/alpha
673 da09d8ed 2022-03-22 thomas (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
674 da09d8ed 2022-03-22 thomas ret=$?
675 da09d8ed 2022-03-22 thomas if [ $ret -ne 0 ]; then
676 da09d8ed 2022-03-22 thomas test_done $testroot $ret
677 da09d8ed 2022-03-22 thomas return 1
678 da09d8ed 2022-03-22 thomas fi
679 da09d8ed 2022-03-22 thomas
680 da09d8ed 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
681 da09d8ed 2022-03-22 thomas --- alpha
682 da09d8ed 2022-03-22 thomas +++ alpha
683 da09d8ed 2022-03-22 thomas @@ -1 +1,2 @@
684 da09d8ed 2022-03-22 thomas alpha
685 da09d8ed 2022-03-22 thomas +was edited
686 da09d8ed 2022-03-22 thomas EOF
687 da09d8ed 2022-03-22 thomas
688 da09d8ed 2022-03-22 thomas (cd $testroot/wt && got patch patch) > /dev/null
689 da09d8ed 2022-03-22 thomas ret=$?
690 da09d8ed 2022-03-22 thomas if [ $ret -ne 0 ]; then
691 da09d8ed 2022-03-22 thomas test_done $testroot $ret
692 da09d8ed 2022-03-22 thomas return 1
693 da09d8ed 2022-03-22 thomas fi
694 da09d8ed 2022-03-22 thomas
695 da09d8ed 2022-03-22 thomas if [ ! -x $testroot/wt/alpha ]; then
696 da09d8ed 2022-03-22 thomas echo "alpha is no more executable!" >&2
697 da09d8ed 2022-03-22 thomas test_done $testroot 1
698 e0c1f81c 2022-03-22 thomas return 1
699 e0c1f81c 2022-03-22 thomas fi
700 e0c1f81c 2022-03-22 thomas test_done $testroot 0
701 e0c1f81c 2022-03-22 thomas }
702 e0c1f81c 2022-03-22 thomas
703 e0c1f81c 2022-03-22 thomas test_patch_create_dirs() {
704 e0c1f81c 2022-03-22 thomas local testroot=`test_init patch_create_dirs`
705 e0c1f81c 2022-03-22 thomas
706 e0c1f81c 2022-03-22 thomas got checkout $testroot/repo $testroot/wt > /dev/null
707 e0c1f81c 2022-03-22 thomas ret=$?
708 e0c1f81c 2022-03-22 thomas if [ $ret -ne 0 ]; then
709 e0c1f81c 2022-03-22 thomas test_done $testroot $ret
710 e0c1f81c 2022-03-22 thomas return 1
711 e0c1f81c 2022-03-22 thomas fi
712 e0c1f81c 2022-03-22 thomas
713 e0c1f81c 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
714 e0c1f81c 2022-03-22 thomas --- /dev/null
715 e0c1f81c 2022-03-22 thomas +++ iota/kappa/lambda
716 e0c1f81c 2022-03-22 thomas @@ -0,0 +1 @@
717 e0c1f81c 2022-03-22 thomas +lambda
718 e0c1f81c 2022-03-22 thomas EOF
719 e0c1f81c 2022-03-22 thomas
720 e0c1f81c 2022-03-22 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
721 e0c1f81c 2022-03-22 thomas ret=$?
722 e0c1f81c 2022-03-22 thomas if [ $ret -ne 0 ]; then
723 e0c1f81c 2022-03-22 thomas test_done $testroot $ret
724 da09d8ed 2022-03-22 thomas return 1
725 da09d8ed 2022-03-22 thomas fi
726 e0c1f81c 2022-03-22 thomas
727 e0c1f81c 2022-03-22 thomas echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
728 e0c1f81c 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
729 e0c1f81c 2022-03-22 thomas ret=$?
730 e0c1f81c 2022-03-22 thomas if [ $ret -ne 0 ]; then
731 e0c1f81c 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
732 e0c1f81c 2022-03-22 thomas test_done $testroot $ret
733 e0c1f81c 2022-03-22 thomas return 1
734 e0c1f81c 2022-03-22 thomas fi
735 e0c1f81c 2022-03-22 thomas
736 e0c1f81c 2022-03-22 thomas if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
737 e0c1f81c 2022-03-22 thomas echo "file not created!" >&2
738 e0c1f81c 2022-03-22 thomas test_done $testroot $ret
739 e0c1f81c 2022-03-22 thomas return 1
740 e0c1f81c 2022-03-22 thomas fi
741 da09d8ed 2022-03-22 thomas test_done $testroot 0
742 10e55613 2022-03-22 thomas }
743 10e55613 2022-03-22 thomas
744 49114f01 2022-03-22 thomas test_patch_with_offset() {
745 49114f01 2022-03-22 thomas local testroot=`test_init patch_with_offset`
746 49114f01 2022-03-22 thomas
747 49114f01 2022-03-22 thomas got checkout $testroot/repo $testroot/wt > /dev/null
748 49114f01 2022-03-22 thomas ret=$?
749 49114f01 2022-03-22 thomas if [ $ret -ne 0 ]; then
750 49114f01 2022-03-22 thomas test_done $testroot $ret
751 49114f01 2022-03-22 thomas return 1
752 49114f01 2022-03-22 thomas fi
753 49114f01 2022-03-22 thomas
754 49114f01 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
755 49114f01 2022-03-22 thomas --- numbers
756 49114f01 2022-03-22 thomas +++ numbers
757 49114f01 2022-03-22 thomas @@ -47,7 +47,7 @@
758 49114f01 2022-03-22 thomas 47
759 49114f01 2022-03-22 thomas 48
760 49114f01 2022-03-22 thomas 49
761 49114f01 2022-03-22 thomas -50
762 49114f01 2022-03-22 thomas +midway tru it!
763 49114f01 2022-03-22 thomas 51
764 49114f01 2022-03-22 thomas 52
765 49114f01 2022-03-22 thomas 53
766 49114f01 2022-03-22 thomas @@ -87,7 +87,7 @@
767 49114f01 2022-03-22 thomas 87
768 49114f01 2022-03-22 thomas 88
769 49114f01 2022-03-22 thomas 89
770 49114f01 2022-03-22 thomas -90
771 49114f01 2022-03-22 thomas +almost there!
772 49114f01 2022-03-22 thomas 91
773 49114f01 2022-03-22 thomas 92
774 49114f01 2022-03-22 thomas 93
775 49114f01 2022-03-22 thomas EOF
776 49114f01 2022-03-22 thomas
777 cf85a643 2024-04-09 thomas seq 100 > $testroot/wt/numbers
778 7a9950a8 2022-11-18 thomas ed -s "$testroot/wt/numbers" <<EOF
779 49114f01 2022-03-22 thomas 1,10d
780 cf85a643 2024-04-09 thomas 50r !seq 20
781 49114f01 2022-03-22 thomas w
782 49114f01 2022-03-22 thomas q
783 49114f01 2022-03-22 thomas EOF
784 49114f01 2022-03-22 thomas
785 49114f01 2022-03-22 thomas (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
786 49114f01 2022-03-22 thomas > /dev/null
787 49114f01 2022-03-22 thomas ret=$?
788 49114f01 2022-03-22 thomas if [ $ret -ne 0 ]; then
789 49114f01 2022-03-22 thomas test_done $testroot $ret
790 49114f01 2022-03-22 thomas return 1
791 49114f01 2022-03-22 thomas fi
792 49114f01 2022-03-22 thomas
793 49114f01 2022-03-22 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
794 49114f01 2022-03-22 thomas ret=$?
795 49114f01 2022-03-22 thomas if [ $ret -ne 0 ]; then
796 49114f01 2022-03-22 thomas test_done $testroot/wt $ret
797 49114f01 2022-03-22 thomas return 1
798 49114f01 2022-03-22 thomas fi
799 49114f01 2022-03-22 thomas
800 49114f01 2022-03-22 thomas cat <<EOF > $testroot/stdout.expected
801 49114f01 2022-03-22 thomas M numbers
802 49114f01 2022-03-22 thomas @@ -47,7 +47,7 @@ applied with offset -10
803 49114f01 2022-03-22 thomas @@ -87,7 +87,7 @@ applied with offset 10
804 13b170bf 2024-04-25 thomas.ad EOF
805 13b170bf 2024-04-25 thomas.ad
806 13b170bf 2024-04-25 thomas.ad cmp -s $testroot/stdout.expected $testroot/stdout
807 13b170bf 2024-04-25 thomas.ad ret=$?
808 13b170bf 2024-04-25 thomas.ad if [ $ret -ne 0 ]; then
809 13b170bf 2024-04-25 thomas.ad diff -u $testroot/stdout.expected $testroot/stdout
810 13b170bf 2024-04-25 thomas.ad fi
811 13b170bf 2024-04-25 thomas.ad test_done $testroot $ret
812 13b170bf 2024-04-25 thomas.ad }
813 13b170bf 2024-04-25 thomas.ad
814 13b170bf 2024-04-25 thomas.ad test_patch_empty_file() {
815 13b170bf 2024-04-25 thomas.ad local testroot=`test_init patch_empty_file`
816 13b170bf 2024-04-25 thomas.ad
817 13b170bf 2024-04-25 thomas.ad got checkout $testroot/repo $testroot/wt > /dev/null
818 13b170bf 2024-04-25 thomas.ad ret=$?
819 13b170bf 2024-04-25 thomas.ad if [ $ret -ne 0 ]; then
820 13b170bf 2024-04-25 thomas.ad test_done $testroot $ret
821 13b170bf 2024-04-25 thomas.ad return 1
822 13b170bf 2024-04-25 thomas.ad fi
823 13b170bf 2024-04-25 thomas.ad
824 13b170bf 2024-04-25 thomas.ad echo -n > $testroot/wt/alpha
825 13b170bf 2024-04-25 thomas.ad (cd "$testroot/wt" && got commit -m 'edit alpha' alpha) >/dev/null
826 ec05a5de 2024-04-25 thomas.ad
827 ec05a5de 2024-04-25 thomas.ad # try a patch which re-adds file contents; should suceeed
828 13b170bf 2024-04-25 thomas.ad cat <<EOF >$testroot/wt/patch
829 13b170bf 2024-04-25 thomas.ad --- alpha
830 13b170bf 2024-04-25 thomas.ad +++ alpha
831 13b170bf 2024-04-25 thomas.ad @@ -0,0 +1 @@
832 13b170bf 2024-04-25 thomas.ad +alpha
833 be53ddb1 2022-03-22 thomas EOF
834 13b170bf 2024-04-25 thomas.ad (cd $testroot/wt && got patch patch) > $testroot/stdout
835 13b170bf 2024-04-25 thomas.ad ret=$?
836 13b170bf 2024-04-25 thomas.ad if [ $ret -ne 0 ]; then
837 13b170bf 2024-04-25 thomas.ad test_done $testroot $ret
838 13b170bf 2024-04-25 thomas.ad return 1
839 13b170bf 2024-04-25 thomas.ad fi
840 13b170bf 2024-04-25 thomas.ad echo 'M alpha' > $testroot/stdout.expected
841 be53ddb1 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
842 be53ddb1 2022-03-22 thomas ret=$?
843 be53ddb1 2022-03-22 thomas if [ $ret -ne 0 ]; then
844 be53ddb1 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
845 ec05a5de 2024-04-25 thomas.ad test_done $testroot $ret
846 ec05a5de 2024-04-25 thomas.ad return 1
847 be53ddb1 2022-03-22 thomas fi
848 ec05a5de 2024-04-25 thomas.ad
849 ec05a5de 2024-04-25 thomas.ad (cd $testroot/wt && got revert -R . > /dev/null)
850 ec05a5de 2024-04-25 thomas.ad
851 ec05a5de 2024-04-25 thomas.ad # try a patch which edits the file; should fail
852 ec05a5de 2024-04-25 thomas.ad cat <<EOF >$testroot/wt/patch
853 ec05a5de 2024-04-25 thomas.ad --- alpha
854 ec05a5de 2024-04-25 thomas.ad +++ alpha
855 ec05a5de 2024-04-25 thomas.ad @@ -1 +1 @@
856 ec05a5de 2024-04-25 thomas.ad -alpha
857 ec05a5de 2024-04-25 thomas.ad +beta
858 ec05a5de 2024-04-25 thomas.ad EOF
859 ec05a5de 2024-04-25 thomas.ad (cd $testroot/wt && got patch patch) > $testroot/stdout \
860 ec05a5de 2024-04-25 thomas.ad 2> $testroot/stderr
861 ec05a5de 2024-04-25 thomas.ad ret=$?
862 ec05a5de 2024-04-25 thomas.ad if [ $ret -eq 0 ]; then
863 ec05a5de 2024-04-25 thomas.ad echo "got patch suceeded unexpectedly" >&2
864 ec05a5de 2024-04-25 thomas.ad test_done $testroot $ret
865 ec05a5de 2024-04-25 thomas.ad return 1
866 ec05a5de 2024-04-25 thomas.ad fi
867 ec05a5de 2024-04-25 thomas.ad
868 ec05a5de 2024-04-25 thomas.ad echo 'got: patch failed to apply' > $testroot/stderr.expected
869 ec05a5de 2024-04-25 thomas.ad cmp -s $testroot/stderr.expected $testroot/stderr
870 ec05a5de 2024-04-25 thomas.ad ret=$?
871 ec05a5de 2024-04-25 thomas.ad if [ $ret -ne 0 ]; then
872 ec05a5de 2024-04-25 thomas.ad diff -u $testroot/stderr.expected $testroot/stderr
873 ec05a5de 2024-04-25 thomas.ad test_done $testroot $ret
874 ec05a5de 2024-04-25 thomas.ad return 1
875 ec05a5de 2024-04-25 thomas.ad fi
876 ec05a5de 2024-04-25 thomas.ad
877 ec05a5de 2024-04-25 thomas.ad (cd $testroot/wt && got revert -R . > /dev/null)
878 ec05a5de 2024-04-25 thomas.ad
879 ec05a5de 2024-04-25 thomas.ad # try a patch which deletes lines from the file; should fail
880 ec05a5de 2024-04-25 thomas.ad cat <<EOF >$testroot/wt/patch
881 ec05a5de 2024-04-25 thomas.ad --- alpha
882 ec05a5de 2024-04-25 thomas.ad +++ alpha
883 ec05a5de 2024-04-25 thomas.ad @@ -1,2 +0 @@
884 ec05a5de 2024-04-25 thomas.ad -alpha
885 ec05a5de 2024-04-25 thomas.ad -beta
886 ec05a5de 2024-04-25 thomas.ad EOF
887 ec05a5de 2024-04-25 thomas.ad (cd $testroot/wt && got patch patch) > $testroot/stdout \
888 ec05a5de 2024-04-25 thomas.ad 2> $testroot/stderr
889 ec05a5de 2024-04-25 thomas.ad ret=$?
890 ec05a5de 2024-04-25 thomas.ad if [ $ret -eq 0 ]; then
891 ec05a5de 2024-04-25 thomas.ad echo "got patch suceeded unexpectedly" >&2
892 ec05a5de 2024-04-25 thomas.ad test_done $testroot $ret
893 ec05a5de 2024-04-25 thomas.ad return 1
894 ec05a5de 2024-04-25 thomas.ad fi
895 ec05a5de 2024-04-25 thomas.ad echo 'got: patch failed to apply' > $testroot/stderr.expected
896 ec05a5de 2024-04-25 thomas.ad cmp -s $testroot/stderr.expected $testroot/stderr
897 ec05a5de 2024-04-25 thomas.ad ret=$?
898 ec05a5de 2024-04-25 thomas.ad if [ $ret -ne 0 ]; then
899 ec05a5de 2024-04-25 thomas.ad diff -u $testroot/stderr.expected $testroot/stderr
900 ec05a5de 2024-04-25 thomas.ad fi
901 be53ddb1 2022-03-22 thomas test_done $testroot $ret
902 be53ddb1 2022-03-22 thomas }
903 be53ddb1 2022-03-22 thomas
904 be53ddb1 2022-03-22 thomas test_patch_prefer_new_path() {
905 be53ddb1 2022-03-22 thomas local testroot=`test_init patch_orig`
906 be53ddb1 2022-03-22 thomas
907 be53ddb1 2022-03-22 thomas got checkout $testroot/repo $testroot/wt > /dev/null
908 be53ddb1 2022-03-22 thomas ret=$?
909 be53ddb1 2022-03-22 thomas if [ $ret -ne 0 ]; then
910 be53ddb1 2022-03-22 thomas test_done $testroot $ret
911 be53ddb1 2022-03-22 thomas return 1
912 be53ddb1 2022-03-22 thomas fi
913 be53ddb1 2022-03-22 thomas
914 be53ddb1 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
915 be53ddb1 2022-03-22 thomas --- alpha.orig
916 be53ddb1 2022-03-22 thomas +++ alpha
917 be53ddb1 2022-03-22 thomas @@ -1 +1,2 @@
918 be53ddb1 2022-03-22 thomas alpha
919 be53ddb1 2022-03-22 thomas +was edited
920 49114f01 2022-03-22 thomas EOF
921 49114f01 2022-03-22 thomas
922 be53ddb1 2022-03-22 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
923 be53ddb1 2022-03-22 thomas ret=$?
924 be53ddb1 2022-03-22 thomas if [ $ret -ne 0 ]; then
925 be53ddb1 2022-03-22 thomas test_done $testroot $ret
926 be53ddb1 2022-03-22 thomas return 1
927 be53ddb1 2022-03-22 thomas fi
928 be53ddb1 2022-03-22 thomas
929 e1c219c8 2022-04-22 thomas echo 'M alpha' > $testroot/stdout.expected
930 49114f01 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
931 49114f01 2022-03-22 thomas ret=$?
932 49114f01 2022-03-22 thomas if [ $ret -ne 0 ]; then
933 49114f01 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
934 49114f01 2022-03-22 thomas fi
935 49114f01 2022-03-22 thomas test_done $testroot $ret
936 49114f01 2022-03-22 thomas }
937 49114f01 2022-03-22 thomas
938 ff7f34d3 2022-03-22 thomas test_patch_no_newline() {
939 ff7f34d3 2022-03-22 thomas local testroot=`test_init patch_no_newline`
940 ff7f34d3 2022-03-22 thomas
941 ff7f34d3 2022-03-22 thomas got checkout $testroot/repo $testroot/wt > /dev/null
942 ff7f34d3 2022-03-22 thomas ret=$?
943 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
944 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
945 ff7f34d3 2022-03-22 thomas return 1
946 ff7f34d3 2022-03-22 thomas fi
947 ff7f34d3 2022-03-22 thomas
948 ff7f34d3 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
949 ff7f34d3 2022-03-22 thomas --- /dev/null
950 ff7f34d3 2022-03-22 thomas +++ eta
951 ff7f34d3 2022-03-22 thomas @@ -0,0 +1 @@
952 ff7f34d3 2022-03-22 thomas +eta
953 ff7f34d3 2022-03-22 thomas \ No newline at end of file
954 ff7f34d3 2022-03-22 thomas EOF
955 ff7f34d3 2022-03-22 thomas
956 ff7f34d3 2022-03-22 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
957 ff7f34d3 2022-03-22 thomas ret=$?
958 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
959 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
960 ff7f34d3 2022-03-22 thomas return 1
961 ff7f34d3 2022-03-22 thomas fi
962 ff7f34d3 2022-03-22 thomas
963 ff7f34d3 2022-03-22 thomas echo "A eta" > $testroot/stdout.expected
964 ff7f34d3 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
965 ff7f34d3 2022-03-22 thomas ret=$?
966 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
967 ff7f34d3 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
968 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
969 ff7f34d3 2022-03-22 thomas return 1
970 ff7f34d3 2022-03-22 thomas fi
971 ff7f34d3 2022-03-22 thomas
972 ff7f34d3 2022-03-22 thomas echo -n eta > $testroot/wt/eta.expected
973 ff7f34d3 2022-03-22 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
974 ff7f34d3 2022-03-22 thomas ret=$?
975 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
976 ff7f34d3 2022-03-22 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
977 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
978 ff7f34d3 2022-03-22 thomas return 1
979 ff7f34d3 2022-03-22 thomas fi
980 ff7f34d3 2022-03-22 thomas
981 ff7f34d3 2022-03-22 thomas (cd $testroot/wt && got commit -m 'add eta') > /dev/null
982 ff7f34d3 2022-03-22 thomas ret=$?
983 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
984 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
985 ff7f34d3 2022-03-22 thomas return 1
986 ff7f34d3 2022-03-22 thomas fi
987 ff7f34d3 2022-03-22 thomas
988 ff7f34d3 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
989 ff7f34d3 2022-03-22 thomas --- eta
990 ff7f34d3 2022-03-22 thomas +++ eta
991 ff7f34d3 2022-03-22 thomas @@ -1 +1 @@
992 ff7f34d3 2022-03-22 thomas -eta
993 ff7f34d3 2022-03-22 thomas \ No newline at end of file
994 ff7f34d3 2022-03-22 thomas +ETA
995 ff7f34d3 2022-03-22 thomas \ No newline at end of file
996 ff7f34d3 2022-03-22 thomas EOF
997 ff7f34d3 2022-03-22 thomas
998 ff7f34d3 2022-03-22 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
999 ff7f34d3 2022-03-22 thomas ret=$?
1000 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
1001 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
1002 ff7f34d3 2022-03-22 thomas return 1
1003 ff7f34d3 2022-03-22 thomas fi
1004 ff7f34d3 2022-03-22 thomas
1005 ff7f34d3 2022-03-22 thomas echo "M eta" > $testroot/stdout.expected
1006 ff7f34d3 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1007 ff7f34d3 2022-03-22 thomas ret=$?
1008 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
1009 ff7f34d3 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1010 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
1011 ff7f34d3 2022-03-22 thomas return 1
1012 ff7f34d3 2022-03-22 thomas fi
1013 ff7f34d3 2022-03-22 thomas
1014 ff7f34d3 2022-03-22 thomas echo -n ETA > $testroot/wt/eta.expected
1015 ff7f34d3 2022-03-22 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1016 ff7f34d3 2022-03-22 thomas ret=$?
1017 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
1018 ff7f34d3 2022-03-22 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
1019 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
1020 ff7f34d3 2022-03-22 thomas return 1
1021 ff7f34d3 2022-03-22 thomas fi
1022 ff7f34d3 2022-03-22 thomas
1023 ff7f34d3 2022-03-22 thomas (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
1024 ff7f34d3 2022-03-22 thomas ret=$?
1025 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
1026 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
1027 ff7f34d3 2022-03-22 thomas return 1
1028 ff7f34d3 2022-03-22 thomas fi
1029 ff7f34d3 2022-03-22 thomas
1030 ff7f34d3 2022-03-22 thomas cat <<EOF > $testroot/wt/patch
1031 ff7f34d3 2022-03-22 thomas --- eta
1032 ff7f34d3 2022-03-22 thomas +++ eta
1033 ff7f34d3 2022-03-22 thomas @@ -1 +1 @@
1034 ff7f34d3 2022-03-22 thomas -ETA
1035 ff7f34d3 2022-03-22 thomas \ No newline at end of file
1036 ff7f34d3 2022-03-22 thomas +eta
1037 ff7f34d3 2022-03-22 thomas EOF
1038 ff7f34d3 2022-03-22 thomas
1039 ff7f34d3 2022-03-22 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
1040 ff7f34d3 2022-03-22 thomas ret=$?
1041 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
1042 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
1043 ff7f34d3 2022-03-22 thomas return 1
1044 ff7f34d3 2022-03-22 thomas fi
1045 ff7f34d3 2022-03-22 thomas
1046 ff7f34d3 2022-03-22 thomas echo "M eta" > $testroot/stdout.expected
1047 ff7f34d3 2022-03-22 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1048 ff7f34d3 2022-03-22 thomas ret=$?
1049 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
1050 ff7f34d3 2022-03-22 thomas diff -u $testroot/stdout.expected $testroot/stdout
1051 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
1052 ff7f34d3 2022-03-22 thomas return 1
1053 ff7f34d3 2022-03-22 thomas fi
1054 ff7f34d3 2022-03-22 thomas
1055 ff7f34d3 2022-03-22 thomas echo eta > $testroot/wt/eta.expected
1056 ff7f34d3 2022-03-22 thomas cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1057 ff7f34d3 2022-03-22 thomas ret=$?
1058 ff7f34d3 2022-03-22 thomas if [ $ret -ne 0 ]; then
1059 ff7f34d3 2022-03-22 thomas diff -u $testroot/wt/eta.expected $testroot/wt/eta
1060 ff7f34d3 2022-03-22 thomas fi
1061 ff7f34d3 2022-03-22 thomas test_done $testroot $ret
1062 ff7f34d3 2022-03-22 thomas }
1063 ff7f34d3 2022-03-22 thomas
1064 d9db2ff9 2022-04-16 thomas test_patch_strip() {
1065 d9db2ff9 2022-04-16 thomas local testroot=`test_init patch_strip`
1066 d9db2ff9 2022-04-16 thomas
1067 d9db2ff9 2022-04-16 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1068 d9db2ff9 2022-04-16 thomas ret=$?
1069 d9db2ff9 2022-04-16 thomas if [ $ret -ne 0 ]; then
1070 d9db2ff9 2022-04-16 thomas test_done $testroot $ret
1071 d9db2ff9 2022-04-16 thomas return 1
1072 d9db2ff9 2022-04-16 thomas fi
1073 d9db2ff9 2022-04-16 thomas
1074 d9db2ff9 2022-04-16 thomas cat <<EOF > $testroot/wt/patch
1075 d9db2ff9 2022-04-16 thomas --- foo/bar/alpha.orig
1076 d9db2ff9 2022-04-16 thomas +++ foo/bar/alpha
1077 d9db2ff9 2022-04-16 thomas @@ -1 +1 @@
1078 d9db2ff9 2022-04-16 thomas -alpha
1079 d9db2ff9 2022-04-16 thomas +ALPHA
1080 d9db2ff9 2022-04-16 thomas EOF
1081 d9db2ff9 2022-04-16 thomas
1082 d9db2ff9 2022-04-16 thomas (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
1083 d9db2ff9 2022-04-16 thomas ret=$?
1084 d9db2ff9 2022-04-16 thomas if [ $ret -ne 0 ]; then
1085 d9db2ff9 2022-04-16 thomas test_done $testroot $ret
1086 d9db2ff9 2022-04-16 thomas return 1
1087 d9db2ff9 2022-04-16 thomas fi
1088 d9db2ff9 2022-04-16 thomas
1089 d9db2ff9 2022-04-16 thomas echo "M alpha" >> $testroot/stdout.expected
1090 d9db2ff9 2022-04-16 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1091 d9db2ff9 2022-04-16 thomas ret=$?
1092 d9db2ff9 2022-04-16 thomas if [ $ret -ne 0 ]; then
1093 d9db2ff9 2022-04-16 thomas diff -u $testroot/stdout.expected $testroot/stdout
1094 d9db2ff9 2022-04-16 thomas test_done $testroot $ret
1095 d9db2ff9 2022-04-16 thomas return 1
1096 d9db2ff9 2022-04-16 thomas fi
1097 d9db2ff9 2022-04-16 thomas
1098 d9db2ff9 2022-04-16 thomas (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1099 d9db2ff9 2022-04-16 thomas ret=$?
1100 d9db2ff9 2022-04-16 thomas if [ $ret -ne 0 ]; then
1101 d9db2ff9 2022-04-16 thomas test_done $testroot $ret
1102 d9db2ff9 2022-04-16 thomas return 1
1103 d9db2ff9 2022-04-16 thomas fi
1104 d9db2ff9 2022-04-16 thomas
1105 d9db2ff9 2022-04-16 thomas (cd $testroot/wt && got patch -p3 patch) \
1106 d9db2ff9 2022-04-16 thomas 2> $testroot/stderr
1107 d9db2ff9 2022-04-16 thomas ret=$?
1108 d9db2ff9 2022-04-16 thomas if [ $ret -eq 0 ]; then
1109 d9db2ff9 2022-04-16 thomas echo "stripped more components than available!"
1110 d9db2ff9 2022-04-16 thomas test_done $testroot 1
1111 d9db2ff9 2022-04-16 thomas return 1
1112 d9db2ff9 2022-04-16 thomas fi
1113 d9db2ff9 2022-04-16 thomas
1114 d9db2ff9 2022-04-16 thomas cat <<EOF > $testroot/stderr.expected
1115 d9db2ff9 2022-04-16 thomas got: can't strip 1 path-components from foo/bar/alpha: bad path
1116 d9db2ff9 2022-04-16 thomas EOF
1117 d9db2ff9 2022-04-16 thomas
1118 d9db2ff9 2022-04-16 thomas cmp -s $testroot/stderr.expected $testroot/stderr
1119 d9db2ff9 2022-04-16 thomas ret=$?
1120 d9db2ff9 2022-04-16 thomas if [ $ret -ne 0 ]; then
1121 d9db2ff9 2022-04-16 thomas diff -u $testroot/stderr.expected $testroot/stderr
1122 d9db2ff9 2022-04-16 thomas fi
1123 d9db2ff9 2022-04-16 thomas test_done $testroot 0
1124 bb90ca7b 2022-07-03 thomas }
1125 bb90ca7b 2022-07-03 thomas
1126 bb90ca7b 2022-07-03 thomas test_patch_whitespace() {
1127 bb90ca7b 2022-07-03 thomas local testroot=`test_init patch_whitespace`
1128 bb90ca7b 2022-07-03 thomas
1129 bb90ca7b 2022-07-03 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1130 bb90ca7b 2022-07-03 thomas ret=$?
1131 bb90ca7b 2022-07-03 thomas if [ $ret -ne 0 ]; then
1132 bb90ca7b 2022-07-03 thomas test_done $testroot $ret
1133 bb90ca7b 2022-07-03 thomas return 1
1134 bb90ca7b 2022-07-03 thomas fi
1135 bb90ca7b 2022-07-03 thomas
1136 bb90ca7b 2022-07-03 thomas trailing=" "
1137 bb90ca7b 2022-07-03 thomas
1138 bb90ca7b 2022-07-03 thomas cat <<EOF > $testroot/wt/hello.c
1139 bb90ca7b 2022-07-03 thomas #include <stdio.h>
1140 bb90ca7b 2022-07-03 thomas
1141 bb90ca7b 2022-07-03 thomas int
1142 bb90ca7b 2022-07-03 thomas main(void)
1143 bb90ca7b 2022-07-03 thomas {
1144 bb90ca7b 2022-07-03 thomas /* the trailing whitespace is on purpose */
1145 bb90ca7b 2022-07-03 thomas printf("hello, world\n");$trailing
1146 bb90ca7b 2022-07-03 thomas return 0;
1147 bb90ca7b 2022-07-03 thomas }
1148 bb90ca7b 2022-07-03 thomas EOF
1149 bb90ca7b 2022-07-03 thomas
1150 bb90ca7b 2022-07-03 thomas (cd $testroot/wt && got add hello.c && got ci -m '+hello.c') \
1151 bb90ca7b 2022-07-03 thomas > /dev/null
1152 bb90ca7b 2022-07-03 thomas ret=$?
1153 bb90ca7b 2022-07-03 thomas if [ $ret -ne 0 ]; then
1154 bb90ca7b 2022-07-03 thomas test_done $testroot $ret
1155 bb90ca7b 2022-07-03 thomas return 1
1156 bb90ca7b 2022-07-03 thomas fi
1157 bb90ca7b 2022-07-03 thomas
1158 bb90ca7b 2022-07-03 thomas # test with a diff with various whitespace corruptions
1159 bb90ca7b 2022-07-03 thomas cat <<EOF > $testroot/wt/patch
1160 bb90ca7b 2022-07-03 thomas --- hello.c
1161 bb90ca7b 2022-07-03 thomas +++ hello.c
1162 bb90ca7b 2022-07-03 thomas @@ -5,5 +5,5 @@
1163 bb90ca7b 2022-07-03 thomas {
1164 bb90ca7b 2022-07-03 thomas /* the trailing whitespace is on purpose */
1165 bb90ca7b 2022-07-03 thomas printf("hello, world\n");
1166 bb90ca7b 2022-07-03 thomas - return 0;
1167 bb90ca7b 2022-07-03 thomas + return 5; /* always fails */
1168 bb90ca7b 2022-07-03 thomas }
1169 bb90ca7b 2022-07-03 thomas EOF
1170 bb90ca7b 2022-07-03 thomas
1171 bb90ca7b 2022-07-03 thomas (cd $testroot/wt && got patch patch) \
1172 bb90ca7b 2022-07-03 thomas 2>$testroot/stderr >$testroot/stdout
1173 bb90ca7b 2022-07-03 thomas ret=$?
1174 bb90ca7b 2022-07-03 thomas if [ $ret -ne 0 ]; then
1175 bb90ca7b 2022-07-03 thomas echo "failed to apply diff" >&2
1176 bb90ca7b 2022-07-03 thomas test_done $testroot $ret
1177 bb90ca7b 2022-07-03 thomas return 1
1178 bb90ca7b 2022-07-03 thomas fi
1179 bb90ca7b 2022-07-03 thomas
1180 bb90ca7b 2022-07-03 thomas echo 'M hello.c' > $testroot/stdout.expected
1181 bb90ca7b 2022-07-03 thomas echo '@@ -5,5 +5,5 @@ hunk contains mangled whitespace' \
1182 bb90ca7b 2022-07-03 thomas >> $testroot/stdout.expected
1183 bb90ca7b 2022-07-03 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1184 bb90ca7b 2022-07-03 thomas ret=$?
1185 bb90ca7b 2022-07-03 thomas if [ $ret -ne 0 ]; then
1186 bb90ca7b 2022-07-03 thomas diff -u $testroot/stdout.expected $testroot/stdout
1187 bb90ca7b 2022-07-03 thomas test_done $testroot $ret
1188 bb90ca7b 2022-07-03 thomas return 1
1189 bb90ca7b 2022-07-03 thomas fi
1190 bb90ca7b 2022-07-03 thomas
1191 bb90ca7b 2022-07-03 thomas cat <<EOF > $testroot/wt/hello.c.expected
1192 bb90ca7b 2022-07-03 thomas #include <stdio.h>
1193 bb90ca7b 2022-07-03 thomas
1194 bb90ca7b 2022-07-03 thomas int
1195 bb90ca7b 2022-07-03 thomas main(void)
1196 bb90ca7b 2022-07-03 thomas {
1197 bb90ca7b 2022-07-03 thomas /* the trailing whitespace is on purpose */
1198 bb90ca7b 2022-07-03 thomas printf("hello, world\n");$trailing
1199 bb90ca7b 2022-07-03 thomas return 5; /* always fails */
1200 bb90ca7b 2022-07-03 thomas }
1201 bb90ca7b 2022-07-03 thomas EOF
1202 bb90ca7b 2022-07-03 thomas
1203 bb90ca7b 2022-07-03 thomas cmp -s $testroot/wt/hello.c.expected $testroot/wt/hello.c
1204 bb90ca7b 2022-07-03 thomas ret=$?
1205 bb90ca7b 2022-07-03 thomas if [ $ret -ne 0 ]; then
1206 bb90ca7b 2022-07-03 thomas diff -u $testroot/wt/hello.c.expected $testroot/wt/hello.c
1207 bb90ca7b 2022-07-03 thomas fi
1208 bb90ca7b 2022-07-03 thomas test_done $testroot $ret
1209 d9db2ff9 2022-04-16 thomas }
1210 72f46891 2022-04-23 thomas
1211 72f46891 2022-04-23 thomas test_patch_relative_paths() {
1212 9a49df74 2022-04-23 thomas local testroot=`test_init patch_relative_paths`
1213 72f46891 2022-04-23 thomas
1214 72f46891 2022-04-23 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1215 72f46891 2022-04-23 thomas ret=$?
1216 72f46891 2022-04-23 thomas if [ $ret -ne 0 ]; then
1217 72f46891 2022-04-23 thomas test_done $testroot $ret
1218 72f46891 2022-04-23 thomas return 1
1219 72f46891 2022-04-23 thomas fi
1220 d9db2ff9 2022-04-16 thomas
1221 72f46891 2022-04-23 thomas cat <<EOF > $testroot/wt/gamma/patch
1222 72f46891 2022-04-23 thomas --- delta
1223 72f46891 2022-04-23 thomas +++ delta
1224 72f46891 2022-04-23 thomas @@ -1 +1 @@
1225 72f46891 2022-04-23 thomas -delta
1226 72f46891 2022-04-23 thomas +DELTA
1227 72f46891 2022-04-23 thomas --- /dev/null
1228 72f46891 2022-04-23 thomas +++ eta
1229 72f46891 2022-04-23 thomas @@ -0,0 +1 @@
1230 72f46891 2022-04-23 thomas +eta
1231 72f46891 2022-04-23 thomas EOF
1232 72f46891 2022-04-23 thomas
1233 72f46891 2022-04-23 thomas (cd $testroot/wt/gamma && got patch patch) > $testroot/stdout
1234 72f46891 2022-04-23 thomas ret=$?
1235 72f46891 2022-04-23 thomas if [ $ret -ne 0 ]; then
1236 72f46891 2022-04-23 thomas test_done $testroot $ret
1237 72f46891 2022-04-23 thomas return 1
1238 72f46891 2022-04-23 thomas fi
1239 72f46891 2022-04-23 thomas
1240 72f46891 2022-04-23 thomas echo 'M gamma/delta' > $testroot/stdout.expected
1241 72f46891 2022-04-23 thomas echo 'A gamma/eta' >> $testroot/stdout.expected
1242 cfbf5531 2022-04-23 thomas
1243 cfbf5531 2022-04-23 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1244 cfbf5531 2022-04-23 thomas ret=$?
1245 cfbf5531 2022-04-23 thomas if [ $ret -ne 0 ]; then
1246 cfbf5531 2022-04-23 thomas diff -u $testroot/stdout.expected $testroot/stdout
1247 cfbf5531 2022-04-23 thomas fi
1248 cfbf5531 2022-04-23 thomas test_done $testroot $ret
1249 cfbf5531 2022-04-23 thomas }
1250 cfbf5531 2022-04-23 thomas
1251 cfbf5531 2022-04-23 thomas test_patch_with_path_prefix() {
1252 cfbf5531 2022-04-23 thomas local testroot=`test_init patch_with_path_prefix`
1253 cfbf5531 2022-04-23 thomas
1254 cfbf5531 2022-04-23 thomas got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1255 cfbf5531 2022-04-23 thomas ret=$?
1256 cfbf5531 2022-04-23 thomas if [ $ret -ne 0 ]; then
1257 cfbf5531 2022-04-23 thomas test_done $testroot $ret
1258 cfbf5531 2022-04-23 thomas return 1
1259 cfbf5531 2022-04-23 thomas fi
1260 cfbf5531 2022-04-23 thomas
1261 cfbf5531 2022-04-23 thomas cat <<EOF > $testroot/wt/patch
1262 cfbf5531 2022-04-23 thomas --- delta
1263 cfbf5531 2022-04-23 thomas +++ delta
1264 cfbf5531 2022-04-23 thomas @@ -1 +1 @@
1265 cfbf5531 2022-04-23 thomas -delta
1266 cfbf5531 2022-04-23 thomas +DELTA
1267 cfbf5531 2022-04-23 thomas --- /dev/null
1268 cfbf5531 2022-04-23 thomas +++ eta
1269 cfbf5531 2022-04-23 thomas @@ -0,0 +1 @@
1270 cfbf5531 2022-04-23 thomas +eta
1271 cfbf5531 2022-04-23 thomas EOF
1272 cfbf5531 2022-04-23 thomas
1273 cfbf5531 2022-04-23 thomas (cd $testroot/wt && got patch patch) > $testroot/stdout
1274 cfbf5531 2022-04-23 thomas ret=$?
1275 cfbf5531 2022-04-23 thomas if [ $ret -ne 0 ]; then
1276 cfbf5531 2022-04-23 thomas test_done $testroot $ret
1277 cfbf5531 2022-04-23 thomas return 1
1278 cfbf5531 2022-04-23 thomas fi
1279 cfbf5531 2022-04-23 thomas
1280 cfbf5531 2022-04-23 thomas echo 'M delta' > $testroot/stdout.expected
1281 cfbf5531 2022-04-23 thomas echo 'A eta' >> $testroot/stdout.expected
1282 cfbf5531 2022-04-23 thomas
1283 cfbf5531 2022-04-23 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1284 cfbf5531 2022-04-23 thomas ret=$?
1285 cfbf5531 2022-04-23 thomas if [ $ret -ne 0 ]; then
1286 cfbf5531 2022-04-23 thomas diff -u $testroot/stdout.expected $testroot/stdout
1287 cfbf5531 2022-04-23 thomas fi
1288 cfbf5531 2022-04-23 thomas test_done $testroot $ret
1289 cfbf5531 2022-04-23 thomas }
1290 72f46891 2022-04-23 thomas
1291 cfbf5531 2022-04-23 thomas test_patch_relpath_with_path_prefix() {
1292 cfbf5531 2022-04-23 thomas local testroot=`test_init patch_relpaths_with_path_prefix`
1293 cfbf5531 2022-04-23 thomas
1294 cfbf5531 2022-04-23 thomas got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1295 cfbf5531 2022-04-23 thomas ret=$?
1296 cfbf5531 2022-04-23 thomas if [ $ret -ne 0 ]; then
1297 cfbf5531 2022-04-23 thomas test_done $testroot $ret
1298 cfbf5531 2022-04-23 thomas return 1
1299 cfbf5531 2022-04-23 thomas fi
1300 cfbf5531 2022-04-23 thomas
1301 cfbf5531 2022-04-23 thomas mkdir -p $testroot/wt/epsilon/zeta/
1302 cfbf5531 2022-04-23 thomas
1303 cfbf5531 2022-04-23 thomas cat <<EOF > $testroot/wt/patch
1304 cfbf5531 2022-04-23 thomas --- /dev/null
1305 cfbf5531 2022-04-23 thomas +++ zeta/theta
1306 cfbf5531 2022-04-23 thomas @@ -0,0 +1 @@
1307 cfbf5531 2022-04-23 thomas +theta
1308 cfbf5531 2022-04-23 thomas EOF
1309 cfbf5531 2022-04-23 thomas
1310 cfbf5531 2022-04-23 thomas (cd $testroot/wt/epsilon/zeta && got patch -p1 $testroot/wt/patch) \
1311 cfbf5531 2022-04-23 thomas > $testroot/stdout
1312 cfbf5531 2022-04-23 thomas ret=$?
1313 cfbf5531 2022-04-23 thomas if [ $ret -ne 0 ]; then
1314 cfbf5531 2022-04-23 thomas test_done $testroot $ret
1315 cfbf5531 2022-04-23 thomas return 1
1316 cfbf5531 2022-04-23 thomas fi
1317 cfbf5531 2022-04-23 thomas
1318 cfbf5531 2022-04-23 thomas echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1319 cfbf5531 2022-04-23 thomas
1320 72f46891 2022-04-23 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1321 72f46891 2022-04-23 thomas ret=$?
1322 72f46891 2022-04-23 thomas if [ $ret -ne 0 ]; then
1323 72f46891 2022-04-23 thomas diff -u $testroot/stdout.expected $testroot/stdout
1324 cfbf5531 2022-04-23 thomas test_done $testroot $ret
1325 cfbf5531 2022-04-23 thomas return 1
1326 72f46891 2022-04-23 thomas fi
1327 cfbf5531 2022-04-23 thomas
1328 cfbf5531 2022-04-23 thomas echo 'theta' > $testroot/theta.expected
1329 cfbf5531 2022-04-23 thomas cmp -s $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1330 cfbf5531 2022-04-23 thomas ret=$?
1331 cfbf5531 2022-04-23 thomas if [ $ret -ne 0 ]; then
1332 cfbf5531 2022-04-23 thomas diff -u $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1333 cfbf5531 2022-04-23 thomas fi
1334 72f46891 2022-04-23 thomas test_done $testroot $ret
1335 72f46891 2022-04-23 thomas }
1336 eaef698f 2022-04-23 thomas
1337 eaef698f 2022-04-23 thomas test_patch_reverse() {
1338 eaef698f 2022-04-23 thomas local testroot=`test_init patch_reverse`
1339 eaef698f 2022-04-23 thomas
1340 eaef698f 2022-04-23 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1341 eaef698f 2022-04-23 thomas ret=$?
1342 eaef698f 2022-04-23 thomas if [ $ret -ne 0 ]; then
1343 eaef698f 2022-04-23 thomas test_done $testroot $ret
1344 eaef698f 2022-04-23 thomas return 1
1345 eaef698f 2022-04-23 thomas fi
1346 eaef698f 2022-04-23 thomas
1347 eaef698f 2022-04-23 thomas cat <<EOF > $testroot/wt/patch
1348 eaef698f 2022-04-23 thomas --- alpha
1349 eaef698f 2022-04-23 thomas +++ alpha
1350 eaef698f 2022-04-23 thomas @@ -1 +1 @@
1351 eaef698f 2022-04-23 thomas -ALPHA
1352 eaef698f 2022-04-23 thomas \ No newline at end of file
1353 eaef698f 2022-04-23 thomas +alpha
1354 eaef698f 2022-04-23 thomas EOF
1355 72f46891 2022-04-23 thomas
1356 eaef698f 2022-04-23 thomas (cd $testroot/wt && got patch -R patch) > $testroot/stdout
1357 eaef698f 2022-04-23 thomas ret=$?
1358 eaef698f 2022-04-23 thomas if [ $ret -ne 0 ]; then
1359 eaef698f 2022-04-23 thomas test_done $testroot $ret
1360 eaef698f 2022-04-23 thomas return 1
1361 eaef698f 2022-04-23 thomas fi
1362 eaef698f 2022-04-23 thomas
1363 eaef698f 2022-04-23 thomas echo "M alpha" > $testroot/stdout.expected
1364 eaef698f 2022-04-23 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1365 eaef698f 2022-04-23 thomas ret=$?
1366 eaef698f 2022-04-23 thomas if [ $ret -ne 0 ]; then
1367 eaef698f 2022-04-23 thomas diff -u $testroot/stdout.expected $testroot/stdout
1368 eaef698f 2022-04-23 thomas test_done $testroot $ret
1369 eaef698f 2022-04-23 thomas return 1
1370 eaef698f 2022-04-23 thomas fi
1371 eaef698f 2022-04-23 thomas
1372 eaef698f 2022-04-23 thomas echo -n ALPHA > $testroot/wt/alpha.expected
1373 eaef698f 2022-04-23 thomas cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
1374 eaef698f 2022-04-23 thomas ret=$?
1375 eaef698f 2022-04-23 thomas if [ $ret -ne 0 ]; then
1376 eaef698f 2022-04-23 thomas diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
1377 0f76ab83 2022-06-23 thomas fi
1378 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1379 0f76ab83 2022-06-23 thomas }
1380 0f76ab83 2022-06-23 thomas
1381 0f76ab83 2022-06-23 thomas test_patch_merge_simple() {
1382 0f76ab83 2022-06-23 thomas local testroot=`test_init patch_merge_simple`
1383 0f76ab83 2022-06-23 thomas
1384 0f76ab83 2022-06-23 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1385 0f76ab83 2022-06-23 thomas ret=$?
1386 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1387 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1388 0f76ab83 2022-06-23 thomas return 1
1389 0f76ab83 2022-06-23 thomas fi
1390 0f76ab83 2022-06-23 thomas
1391 cf85a643 2024-04-09 thomas seq 10 > $testroot/wt/numbers
1392 25a880e1 2022-07-03 thomas chmod +x $testroot/wt/numbers
1393 0f76ab83 2022-06-23 thomas (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1394 0f76ab83 2022-06-23 thomas > /dev/null
1395 0f76ab83 2022-06-23 thomas ret=$?
1396 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1397 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1398 0f76ab83 2022-06-23 thomas return 1
1399 0f76ab83 2022-06-23 thomas fi
1400 0f76ab83 2022-06-23 thomas
1401 cf85a643 2024-04-09 thomas seq 10 | sed 's/4/four/g' > $testroot/wt/numbers
1402 0f76ab83 2022-06-23 thomas
1403 0f76ab83 2022-06-23 thomas (cd $testroot/wt && got diff > $testroot/old.diff \
1404 0f76ab83 2022-06-23 thomas && got revert numbers) >/dev/null
1405 0f76ab83 2022-06-23 thomas ret=$?
1406 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1407 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1408 0f76ab83 2022-06-23 thomas return 1
1409 0f76ab83 2022-06-23 thomas fi
1410 0f76ab83 2022-06-23 thomas
1411 cf85a643 2024-04-09 thomas seq 10 | sed 's/6/six/g' > $testroot/wt/numbers
1412 0f76ab83 2022-06-23 thomas (cd $testroot/wt && got commit -m 'edit numbers') \
1413 0f76ab83 2022-06-23 thomas > /dev/null
1414 0f76ab83 2022-06-23 thomas ret=$?
1415 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1416 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1417 0f76ab83 2022-06-23 thomas return 1
1418 0f76ab83 2022-06-23 thomas fi
1419 0f76ab83 2022-06-23 thomas
1420 0f76ab83 2022-06-23 thomas (cd $testroot/wt && got patch $testroot/old.diff) \
1421 762b8e82 2022-06-23 thomas > $testroot/stdout
1422 0f76ab83 2022-06-23 thomas ret=$?
1423 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1424 762b8e82 2022-06-23 thomas test_done $testroot $ret
1425 762b8e82 2022-06-23 thomas return 1
1426 762b8e82 2022-06-23 thomas fi
1427 762b8e82 2022-06-23 thomas
1428 762b8e82 2022-06-23 thomas echo 'G numbers' > $testroot/stdout.expected
1429 762b8e82 2022-06-23 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1430 762b8e82 2022-06-23 thomas ret=$?
1431 762b8e82 2022-06-23 thomas if [ $ret -ne 0 ]; then
1432 762b8e82 2022-06-23 thomas diff -u $testroot/stdout $testroot/stdout.expected
1433 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1434 0f76ab83 2022-06-23 thomas return 1
1435 0f76ab83 2022-06-23 thomas fi
1436 0f76ab83 2022-06-23 thomas
1437 cf85a643 2024-04-09 thomas seq 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1438 0f76ab83 2022-06-23 thomas cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1439 0f76ab83 2022-06-23 thomas ret=$?
1440 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1441 0f76ab83 2022-06-23 thomas diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1442 25a880e1 2022-07-03 thomas test_done $testroot $ret
1443 25a880e1 2022-07-03 thomas return 1
1444 19dd85cb 2022-07-01 thomas fi
1445 25a880e1 2022-07-03 thomas
1446 25a880e1 2022-07-03 thomas test -x $testroot/wt/numbers
1447 25a880e1 2022-07-03 thomas ret=$?
1448 25a880e1 2022-07-03 thomas if [ $ret -ne 0 ]; then
1449 25a880e1 2022-07-03 thomas echo "numbers lost the executable bit" >&2
1450 25a880e1 2022-07-03 thomas fi
1451 19dd85cb 2022-07-01 thomas test_done $testroot $ret
1452 19dd85cb 2022-07-01 thomas }
1453 19dd85cb 2022-07-01 thomas
1454 19dd85cb 2022-07-01 thomas test_patch_merge_gitdiff() {
1455 19dd85cb 2022-07-01 thomas local testroot=`test_init patch_merge_gitdiff`
1456 19dd85cb 2022-07-01 thomas
1457 cf85a643 2024-04-09 thomas seq 10 > $testroot/repo/numbers
1458 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add numbers && \
1459 d1e03b8c 2023-10-08 thomas git_commit $testroot/repo -m "nums"
1460 19dd85cb 2022-07-01 thomas ret=$?
1461 19dd85cb 2022-07-01 thomas if [ $ret -ne 0 ]; then
1462 19dd85cb 2022-07-01 thomas test_done $testroot $ret
1463 19dd85cb 2022-07-01 thomas return 1
1464 19dd85cb 2022-07-01 thomas fi
1465 19dd85cb 2022-07-01 thomas
1466 cf85a643 2024-04-09 thomas seq 10 | sed 's/4/four/g' > $testroot/repo/numbers
1467 d1e03b8c 2023-10-08 thomas git -C $testroot/repo diff > $testroot/old.diff
1468 19dd85cb 2022-07-01 thomas ret=$?
1469 19dd85cb 2022-07-01 thomas if [ $ret -ne 0 ]; then
1470 19dd85cb 2022-07-01 thomas test_done $testroot $ret
1471 19dd85cb 2022-07-01 thomas return 1
1472 19dd85cb 2022-07-01 thomas fi
1473 19dd85cb 2022-07-01 thomas
1474 19dd85cb 2022-07-01 thomas # restore numbers
1475 cf85a643 2024-04-09 thomas seq 10 > $testroot/repo/numbers
1476 19dd85cb 2022-07-01 thomas
1477 cf85a643 2024-04-09 thomas seq 10 | sed 's/6/six/g' > $testroot/repo/numbers
1478 d1e03b8c 2023-10-08 thomas git -C $testroot/repo add numbers && \
1479 d1e03b8c 2023-10-08 thomas git_commit $testroot/repo -m "edit"
1480 19dd85cb 2022-07-01 thomas ret=$?
1481 19dd85cb 2022-07-01 thomas if [ $ret -ne 0 ]; then
1482 19dd85cb 2022-07-01 thomas test_done $testroot $ret
1483 19dd85cb 2022-07-01 thomas return 1
1484 19dd85cb 2022-07-01 thomas fi
1485 19dd85cb 2022-07-01 thomas
1486 19dd85cb 2022-07-01 thomas # now work with got:
1487 19dd85cb 2022-07-01 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1488 19dd85cb 2022-07-01 thomas ret=$?
1489 19dd85cb 2022-07-01 thomas if [ $ret -ne 0 ]; then
1490 19dd85cb 2022-07-01 thomas test_done $testroot $ret
1491 19dd85cb 2022-07-01 thomas return 1
1492 19dd85cb 2022-07-01 thomas fi
1493 19dd85cb 2022-07-01 thomas
1494 19dd85cb 2022-07-01 thomas (cd $testroot/wt && got patch $testroot/old.diff) > $testroot/stdout
1495 19dd85cb 2022-07-01 thomas ret=$?
1496 19dd85cb 2022-07-01 thomas if [ $ret -ne 0 ]; then
1497 19dd85cb 2022-07-01 thomas test_done $testroot $ret
1498 19dd85cb 2022-07-01 thomas return 1
1499 0f76ab83 2022-06-23 thomas fi
1500 19dd85cb 2022-07-01 thomas
1501 19dd85cb 2022-07-01 thomas echo 'G numbers' > $testroot/stdout.expected
1502 19dd85cb 2022-07-01 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1503 19dd85cb 2022-07-01 thomas ret=$?
1504 19dd85cb 2022-07-01 thomas if [ $ret -ne 0 ]; then
1505 19dd85cb 2022-07-01 thomas diff -u $testroot/stdout $testroot/stdout.expected
1506 19dd85cb 2022-07-01 thomas fi
1507 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1508 0f76ab83 2022-06-23 thomas }
1509 7d8bcb99 2022-07-28 thomas
1510 7d8bcb99 2022-07-28 thomas test_patch_merge_base_provided() {
1511 7d8bcb99 2022-07-28 thomas local testroot=`test_init patch_merge_base_provided`
1512 7d8bcb99 2022-07-28 thomas
1513 7d8bcb99 2022-07-28 thomas got checkout $testroot/repo $testroot/wt >/dev/null
1514 7d8bcb99 2022-07-28 thomas ret=$?
1515 7d8bcb99 2022-07-28 thomas if [ $ret -ne 0 ]; then
1516 7d8bcb99 2022-07-28 thomas test_done $testroot $ret
1517 7d8bcb99 2022-07-28 thomas return 1
1518 7d8bcb99 2022-07-28 thomas fi
1519 7d8bcb99 2022-07-28 thomas
1520 cf85a643 2024-04-09 thomas seq 10 > $testroot/wt/numbers
1521 7d8bcb99 2022-07-28 thomas (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1522 7d8bcb99 2022-07-28 thomas >/dev/null
1523 7d8bcb99 2022-07-28 thomas ret=$?
1524 7d8bcb99 2022-07-28 thomas if [ $ret -ne 0 ]; then
1525 7d8bcb99 2022-07-28 thomas test_done $testroot $ret
1526 7d8bcb99 2022-07-28 thomas return 1
1527 7d8bcb99 2022-07-28 thomas fi
1528 0f76ab83 2022-06-23 thomas
1529 7d8bcb99 2022-07-28 thomas local commit_id=`git_show_head $testroot/repo`
1530 7d8bcb99 2022-07-28 thomas
1531 cf85a643 2024-04-09 thomas seq 10 | sed s/4/four/ > $testroot/wt/numbers
1532 7d8bcb99 2022-07-28 thomas
1533 7d8bcb99 2022-07-28 thomas # get rid of the metadata
1534 7d8bcb99 2022-07-28 thomas (cd $testroot/wt && got diff | sed -n '/^---/,$p' > patch) \
1535 7d8bcb99 2022-07-28 thomas >/dev/null
1536 7d8bcb99 2022-07-28 thomas
1537 cf85a643 2024-04-09 thomas seq 10 | sed s/6/six/ > $testroot/wt/numbers
1538 7d8bcb99 2022-07-28 thomas (cd $testroot/wt && got commit -m 'edit numbers') >/dev/null
1539 7d8bcb99 2022-07-28 thomas ret=$?
1540 7d8bcb99 2022-07-28 thomas if [ $ret -ne 0 ]; then
1541 7d8bcb99 2022-07-28 thomas test_done $testroot $ret
1542 7d8bcb99 2022-07-28 thomas return 1
1543 7d8bcb99 2022-07-28 thomas fi
1544 7d8bcb99 2022-07-28 thomas
1545 7d8bcb99 2022-07-28 thomas (cd $testroot/wt && got patch -c $commit_id patch) >$testroot/stdout
1546 7d8bcb99 2022-07-28 thomas ret=$?
1547 7d8bcb99 2022-07-28 thomas if [ $ret -ne 0 ]; then
1548 7d8bcb99 2022-07-28 thomas test_done $testroot $ret
1549 7d8bcb99 2022-07-28 thomas return 1
1550 7d8bcb99 2022-07-28 thomas fi
1551 7d8bcb99 2022-07-28 thomas
1552 7d8bcb99 2022-07-28 thomas echo 'G numbers' > $testroot/stdout.expected
1553 7d8bcb99 2022-07-28 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1554 7d8bcb99 2022-07-28 thomas ret=$?
1555 7d8bcb99 2022-07-28 thomas if [ $ret -ne 0 ]; then
1556 7d8bcb99 2022-07-28 thomas diff -u $testroot/stdout $testroot/stdout.expected
1557 7d8bcb99 2022-07-28 thomas test_done $testroot $ret
1558 7d8bcb99 2022-07-28 thomas return 1
1559 7d8bcb99 2022-07-28 thomas fi
1560 7d8bcb99 2022-07-28 thomas
1561 cf85a643 2024-04-09 thomas seq 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1562 7d8bcb99 2022-07-28 thomas cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1563 7d8bcb99 2022-07-28 thomas ret=$?
1564 7d8bcb99 2022-07-28 thomas if [ $ret -ne 0 ]; then
1565 7d8bcb99 2022-07-28 thomas diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1566 7d8bcb99 2022-07-28 thomas fi
1567 7d8bcb99 2022-07-28 thomas test_done $testroot $ret
1568 7d8bcb99 2022-07-28 thomas }
1569 7d8bcb99 2022-07-28 thomas
1570 0f76ab83 2022-06-23 thomas test_patch_merge_conflict() {
1571 0f76ab83 2022-06-23 thomas local testroot=`test_init patch_merge_conflict`
1572 0f76ab83 2022-06-23 thomas
1573 0f76ab83 2022-06-23 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1574 0f76ab83 2022-06-23 thomas ret=$?
1575 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1576 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1577 0f76ab83 2022-06-23 thomas return 1
1578 0f76ab83 2022-06-23 thomas fi
1579 0f76ab83 2022-06-23 thomas
1580 cf85a643 2024-04-09 thomas seq 10 > $testroot/wt/numbers
1581 0f76ab83 2022-06-23 thomas (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1582 0f76ab83 2022-06-23 thomas > /dev/null
1583 0f76ab83 2022-06-23 thomas ret=$?
1584 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1585 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1586 0f76ab83 2022-06-23 thomas return 1
1587 0f76ab83 2022-06-23 thomas fi
1588 016bfe4b 2022-06-23 thomas
1589 016bfe4b 2022-06-23 thomas local commit_id=`git_show_head $testroot/repo`
1590 0f76ab83 2022-06-23 thomas
1591 cf85a643 2024-04-09 thomas seq 10 | sed 's/6/six/g' > $testroot/wt/numbers
1592 68ceedb3 2022-07-03 thomas echo ALPHA > $testroot/wt/alpha
1593 0f76ab83 2022-06-23 thomas
1594 0f76ab83 2022-06-23 thomas (cd $testroot/wt && got diff > $testroot/old.diff \
1595 68ceedb3 2022-07-03 thomas && got revert alpha numbers) >/dev/null
1596 0f76ab83 2022-06-23 thomas ret=$?
1597 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1598 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1599 0f76ab83 2022-06-23 thomas return 1
1600 0f76ab83 2022-06-23 thomas fi
1601 0f76ab83 2022-06-23 thomas
1602 cf85a643 2024-04-09 thomas seq 10 | sed 's/6/3+3/g' > $testroot/wt/numbers
1603 cf85a643 2024-04-09 thomas printf '%s\n' a b c > $testroot/wt/alpha
1604 68ceedb3 2022-07-03 thomas (cd $testroot/wt && got commit -m 'edit alpha and numbers') \
1605 0f76ab83 2022-06-23 thomas > /dev/null
1606 0f76ab83 2022-06-23 thomas ret=$?
1607 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1608 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1609 0f76ab83 2022-06-23 thomas return 1
1610 eaef698f 2022-04-23 thomas fi
1611 0f76ab83 2022-06-23 thomas
1612 0f76ab83 2022-06-23 thomas (cd $testroot/wt && got patch $testroot/old.diff) \
1613 762b8e82 2022-06-23 thomas > $testroot/stdout 2>/dev/null
1614 0f76ab83 2022-06-23 thomas ret=$?
1615 0f76ab83 2022-06-23 thomas if [ $ret -eq 0 ]; then
1616 0f76ab83 2022-06-23 thomas echo "got patch merged a diff that should conflict" >&2
1617 8e6eb32a 2023-05-14 thomas test_done $testroot 1
1618 0f76ab83 2022-06-23 thomas return 1
1619 0f76ab83 2022-06-23 thomas fi
1620 0f76ab83 2022-06-23 thomas
1621 68ceedb3 2022-07-03 thomas echo 'C alpha' > $testroot/stdout.expected
1622 68ceedb3 2022-07-03 thomas echo 'C numbers' >> $testroot/stdout.expected
1623 1faec3fb 2023-05-14 thomas echo 'Files with merge conflicts: 2' >> $testroot/stdout.expected
1624 762b8e82 2022-06-23 thomas cmp -s $testroot/stdout $testroot/stdout.expected
1625 762b8e82 2022-06-23 thomas ret=$?
1626 762b8e82 2022-06-23 thomas if [ $ret -ne 0 ]; then
1627 762b8e82 2022-06-23 thomas diff -u $testroot/stdout $testroot/stdout.expected
1628 762b8e82 2022-06-23 thomas test_done $testroot $ret
1629 762b8e82 2022-06-23 thomas return 1
1630 762b8e82 2022-06-23 thomas fi
1631 762b8e82 2022-06-23 thomas
1632 0f76ab83 2022-06-23 thomas # XXX: prefixing every line with a tab otherwise got thinks
1633 0f76ab83 2022-06-23 thomas # the file has conflicts in it.
1634 68ceedb3 2022-07-03 thomas cat <<-EOF > $testroot/wt/alpha.expected
1635 68ceedb3 2022-07-03 thomas <<<<<<< --- alpha
1636 68ceedb3 2022-07-03 thomas ALPHA
1637 68ceedb3 2022-07-03 thomas ||||||| commit $commit_id
1638 68ceedb3 2022-07-03 thomas alpha
1639 68ceedb3 2022-07-03 thomas =======
1640 68ceedb3 2022-07-03 thomas a
1641 68ceedb3 2022-07-03 thomas b
1642 68ceedb3 2022-07-03 thomas c
1643 68ceedb3 2022-07-03 thomas >>>>>>> +++ alpha
1644 68ceedb3 2022-07-03 thomas EOF
1645 68ceedb3 2022-07-03 thomas
1646 0f76ab83 2022-06-23 thomas cat <<-EOF > $testroot/wt/numbers.expected
1647 0f76ab83 2022-06-23 thomas 1
1648 0f76ab83 2022-06-23 thomas 2
1649 0f76ab83 2022-06-23 thomas 3
1650 0f76ab83 2022-06-23 thomas 4
1651 0f76ab83 2022-06-23 thomas 5
1652 0f76ab83 2022-06-23 thomas <<<<<<< --- numbers
1653 0f76ab83 2022-06-23 thomas six
1654 016bfe4b 2022-06-23 thomas ||||||| commit $commit_id
1655 0f76ab83 2022-06-23 thomas 6
1656 0f76ab83 2022-06-23 thomas =======
1657 0f76ab83 2022-06-23 thomas 3+3
1658 0f76ab83 2022-06-23 thomas >>>>>>> +++ numbers
1659 0f76ab83 2022-06-23 thomas 7
1660 0f76ab83 2022-06-23 thomas 8
1661 0f76ab83 2022-06-23 thomas 9
1662 0f76ab83 2022-06-23 thomas 10
1663 0f76ab83 2022-06-23 thomas EOF
1664 0f76ab83 2022-06-23 thomas
1665 68ceedb3 2022-07-03 thomas cmp -s $testroot/wt/alpha $testroot/wt/alpha.expected
1666 68ceedb3 2022-07-03 thomas ret=$?
1667 68ceedb3 2022-07-03 thomas if [ $ret -ne 0 ]; then
1668 68ceedb3 2022-07-03 thomas diff -u $testroot/wt/alpha $testroot/wt/alpha.expected
1669 68ceedb3 2022-07-03 thomas test_done $testroot $ret
1670 68ceedb3 2022-07-03 thomas return 1
1671 68ceedb3 2022-07-03 thomas fi
1672 68ceedb3 2022-07-03 thomas
1673 0f76ab83 2022-06-23 thomas cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1674 0f76ab83 2022-06-23 thomas ret=$?
1675 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1676 0f76ab83 2022-06-23 thomas diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1677 0f76ab83 2022-06-23 thomas fi
1678 eaef698f 2022-04-23 thomas test_done $testroot $ret
1679 eaef698f 2022-04-23 thomas }
1680 eaef698f 2022-04-23 thomas
1681 0f76ab83 2022-06-23 thomas test_patch_merge_unknown_blob() {
1682 0f76ab83 2022-06-23 thomas local testroot=`test_init patch_merge_unknown_blob`
1683 0f76ab83 2022-06-23 thomas
1684 0f76ab83 2022-06-23 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1685 0f76ab83 2022-06-23 thomas ret=$?
1686 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1687 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1688 0f76ab83 2022-06-23 thomas return 1
1689 0f76ab83 2022-06-23 thomas fi
1690 0f76ab83 2022-06-23 thomas
1691 0f76ab83 2022-06-23 thomas cat <<EOF > $testroot/wt/patch
1692 0f76ab83 2022-06-23 thomas I've got a
1693 c9a4f4fa 2022-06-23 thomas diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
1694 c9a4f4fa 2022-06-23 thomas with a
1695 0f76ab83 2022-06-23 thomas blob - aaaabbbbccccddddeeeeffff0000111122223333
1696 0f76ab83 2022-06-23 thomas and also a
1697 c9a4f4fa 2022-06-23 thomas blob + 0000111122223333444455556666777788889999
1698 0f76ab83 2022-06-23 thomas for this dummy diff
1699 0f76ab83 2022-06-23 thomas --- alpha
1700 0f76ab83 2022-06-23 thomas +++ alpha
1701 0f76ab83 2022-06-23 thomas @@ -1 +1 @@
1702 0f76ab83 2022-06-23 thomas -alpha
1703 0f76ab83 2022-06-23 thomas +ALPHA
1704 0f76ab83 2022-06-23 thomas will it work?
1705 0f76ab83 2022-06-23 thomas EOF
1706 0f76ab83 2022-06-23 thomas
1707 0f76ab83 2022-06-23 thomas (cd $testroot/wt/ && got patch patch) > $testroot/stdout
1708 0f76ab83 2022-06-23 thomas ret=$?
1709 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1710 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1711 0f76ab83 2022-06-23 thomas return 1
1712 0f76ab83 2022-06-23 thomas fi
1713 0f76ab83 2022-06-23 thomas
1714 0f76ab83 2022-06-23 thomas echo 'M alpha' > $testroot/stdout.expected
1715 0f76ab83 2022-06-23 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1716 0f76ab83 2022-06-23 thomas ret=$?
1717 0f76ab83 2022-06-23 thomas if [ $ret -ne 0 ]; then
1718 0f76ab83 2022-06-23 thomas diff -u $testroot/stdout.expected $testroot/stdout
1719 c9a4f4fa 2022-06-23 thomas test_done $testroot $ret
1720 c9a4f4fa 2022-06-23 thomas return 1
1721 0f76ab83 2022-06-23 thomas fi
1722 c9a4f4fa 2022-06-23 thomas
1723 c9a4f4fa 2022-06-23 thomas # try again without a `diff' header
1724 c9a4f4fa 2022-06-23 thomas
1725 c9a4f4fa 2022-06-23 thomas cat <<EOF > $testroot/wt/patch
1726 c9a4f4fa 2022-06-23 thomas I've got a
1727 c9a4f4fa 2022-06-23 thomas blob - aaaabbbbccccddddeeeeffff0000111122223333
1728 c9a4f4fa 2022-06-23 thomas and also a
1729 c9a4f4fa 2022-06-23 thomas blob + 0000111122223333444455556666777788889999
1730 c9a4f4fa 2022-06-23 thomas for this dummy diff
1731 c9a4f4fa 2022-06-23 thomas --- alpha
1732 c9a4f4fa 2022-06-23 thomas +++ alpha
1733 c9a4f4fa 2022-06-23 thomas @@ -1 +1 @@
1734 c9a4f4fa 2022-06-23 thomas -alpha
1735 c9a4f4fa 2022-06-23 thomas +ALPHA
1736 c9a4f4fa 2022-06-23 thomas will it work?
1737 c9a4f4fa 2022-06-23 thomas EOF
1738 c9a4f4fa 2022-06-23 thomas
1739 c9a4f4fa 2022-06-23 thomas (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1740 c9a4f4fa 2022-06-23 thomas > $testroot/stdout
1741 c9a4f4fa 2022-06-23 thomas ret=$?
1742 c9a4f4fa 2022-06-23 thomas if [ $ret -ne 0 ]; then
1743 c9a4f4fa 2022-06-23 thomas test_done $testroot $ret
1744 c9a4f4fa 2022-06-23 thomas return 1
1745 c9a4f4fa 2022-06-23 thomas fi
1746 c9a4f4fa 2022-06-23 thomas
1747 c9a4f4fa 2022-06-23 thomas echo 'M alpha' > $testroot/stdout.expected
1748 c9a4f4fa 2022-06-23 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1749 c9a4f4fa 2022-06-23 thomas ret=$?
1750 c9a4f4fa 2022-06-23 thomas if [ $ret -ne 0 ]; then
1751 c9a4f4fa 2022-06-23 thomas diff -u $testroot/stdout.expected $testroot/stdout
1752 19dd85cb 2022-07-01 thomas test_done $testroot $ret
1753 19dd85cb 2022-07-01 thomas return 1
1754 c9a4f4fa 2022-06-23 thomas fi
1755 19dd85cb 2022-07-01 thomas
1756 19dd85cb 2022-07-01 thomas # try again with a git-style diff
1757 19dd85cb 2022-07-01 thomas
1758 19dd85cb 2022-07-01 thomas cat <<EOF > $testroot/wt/patch
1759 19dd85cb 2022-07-01 thomas diff --git a/alpha b/alpha
1760 19dd85cb 2022-07-01 thomas index 0123456789ab..abcdef012345 100644
1761 19dd85cb 2022-07-01 thomas --- a/alpha
1762 19dd85cb 2022-07-01 thomas +++ b/alpha
1763 19dd85cb 2022-07-01 thomas @@ -1 +1 @@
1764 19dd85cb 2022-07-01 thomas -alpha
1765 19dd85cb 2022-07-01 thomas +ALPHA
1766 19dd85cb 2022-07-01 thomas EOF
1767 19dd85cb 2022-07-01 thomas
1768 19dd85cb 2022-07-01 thomas (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1769 19dd85cb 2022-07-01 thomas > $testroot/stdout
1770 19dd85cb 2022-07-01 thomas ret=$?
1771 19dd85cb 2022-07-01 thomas if [ $ret -ne 0 ]; then
1772 19dd85cb 2022-07-01 thomas test_done $testroot $ret
1773 19dd85cb 2022-07-01 thomas return 1
1774 19dd85cb 2022-07-01 thomas fi
1775 19dd85cb 2022-07-01 thomas
1776 19dd85cb 2022-07-01 thomas echo 'M alpha' > $testroot/stdout.expected
1777 19dd85cb 2022-07-01 thomas cmp -s $testroot/stdout.expected $testroot/stdout
1778 19dd85cb 2022-07-01 thomas ret=$?
1779 19dd85cb 2022-07-01 thomas if [ $ret -ne 0 ]; then
1780 19dd85cb 2022-07-01 thomas diff -u $testroot/stdout.expected $testroot/stdout
1781 19dd85cb 2022-07-01 thomas fi
1782 0f76ab83 2022-06-23 thomas test_done $testroot $ret
1783 0f76ab83 2022-06-23 thomas }
1784 f4602cbd 2022-07-23 thomas
1785 f4602cbd 2022-07-23 thomas test_patch_merge_reverse() {
1786 f4602cbd 2022-07-23 thomas local testroot=`test_init patch_merge_simple`
1787 f4602cbd 2022-07-23 thomas
1788 f4602cbd 2022-07-23 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1789 f4602cbd 2022-07-23 thomas ret=$?
1790 f4602cbd 2022-07-23 thomas if [ $ret -ne 0 ]; then
1791 f4602cbd 2022-07-23 thomas test_done $testroot $ret
1792 f4602cbd 2022-07-23 thomas return 1
1793 f4602cbd 2022-07-23 thomas fi
1794 0f76ab83 2022-06-23 thomas
1795 cf85a643 2024-04-09 thomas seq 10 > $testroot/wt/numbers
1796 f4602cbd 2022-07-23 thomas (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1797 f4602cbd 2022-07-23 thomas > /dev/null
1798 f4602cbd 2022-07-23 thomas ret=$?
1799 f4602cbd 2022-07-23 thomas if [ $ret -ne 0 ]; then
1800 f4602cbd 2022-07-23 thomas test_done $testroot $ret
1801 f4602cbd 2022-07-23 thomas return 1
1802 f4602cbd 2022-07-23 thomas fi
1803 f4602cbd 2022-07-23 thomas
1804 f4602cbd 2022-07-23 thomas local commit_id=`git_show_head $testroot/repo`
1805 f4602cbd 2022-07-23 thomas
1806 cf85a643 2024-04-09 thomas seq 10 | sed s/5/five/g > $testroot/wt/numbers
1807 f4602cbd 2022-07-23 thomas (cd $testroot/wt && got diff > $testroot/wt/patch \
1808 f4602cbd 2022-07-23 thomas && got commit -m 'edit numbers') > /dev/null
1809 f4602cbd 2022-07-23 thomas ret=$?
1810 f4602cbd 2022-07-23 thomas if [ $ret -ne 0 ]; then
1811 f4602cbd 2022-07-23 thomas test_done $testroot $ret
1812 f4602cbd 2022-07-23 thomas return 1
1813 f4602cbd 2022-07-23 thomas fi
1814 f4602cbd 2022-07-23 thomas
1815 cf85a643 2024-04-09 thomas seq 10 | sed -e s/5/five/g -e s/6/six/g > $testroot/wt/numbers
1816 f4602cbd 2022-07-23 thomas (cd $testroot/wt && got commit -m 'edit numbers again') >/dev/null
1817 f4602cbd 2022-07-23 thomas ret=$?
1818 f4602cbd 2022-07-23 thomas if [ $ret -ne 0 ]; then
1819 f4602cbd 2022-07-23 thomas test_done $testroot $ret
1820 f4602cbd 2022-07-23 thomas return 1
1821 f4602cbd 2022-07-23 thomas fi
1822 f4602cbd 2022-07-23 thomas
1823 f4602cbd 2022-07-23 thomas (cd $testroot/wt && got patch -R patch) >/dev/null 2>&1
1824 f4602cbd 2022-07-23 thomas ret=$?
1825 f4602cbd 2022-07-23 thomas if [ $ret -eq 0 ]; then
1826 f4602cbd 2022-07-23 thomas echo "unexpectedly reverted the patch" >&2
1827 f4602cbd 2022-07-23 thomas test_done $testroot 1
1828 f4602cbd 2022-07-23 thomas return 1
1829 f4602cbd 2022-07-23 thomas fi
1830 f4602cbd 2022-07-23 thomas
1831 f4602cbd 2022-07-23 thomas cat <<-EOF > $testroot/wt/numbers.expected
1832 f4602cbd 2022-07-23 thomas 1
1833 f4602cbd 2022-07-23 thomas 2
1834 f4602cbd 2022-07-23 thomas 3
1835 f4602cbd 2022-07-23 thomas 4
1836 f4602cbd 2022-07-23 thomas <<<<<<< --- numbers
1837 f4602cbd 2022-07-23 thomas 5
1838 f4602cbd 2022-07-23 thomas 6
1839 f4602cbd 2022-07-23 thomas ||||||| +++ numbers
1840 f4602cbd 2022-07-23 thomas five
1841 f4602cbd 2022-07-23 thomas =======
1842 f4602cbd 2022-07-23 thomas five
1843 f4602cbd 2022-07-23 thomas six
1844 f4602cbd 2022-07-23 thomas >>>>>>> commit $commit_id
1845 f4602cbd 2022-07-23 thomas 7
1846 f4602cbd 2022-07-23 thomas 8
1847 f4602cbd 2022-07-23 thomas 9
1848 f4602cbd 2022-07-23 thomas 10
1849 f4602cbd 2022-07-23 thomas EOF
1850 f4602cbd 2022-07-23 thomas
1851 f4602cbd 2022-07-23 thomas cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1852 f4602cbd 2022-07-23 thomas ret=$?
1853 f4602cbd 2022-07-23 thomas if [ $ret -ne 0 ]; then
1854 f4602cbd 2022-07-23 thomas diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1855 37e766f4 2022-09-21 thomas fi
1856 37e766f4 2022-09-21 thomas test_done $testroot $ret
1857 37e766f4 2022-09-21 thomas }
1858 37e766f4 2022-09-21 thomas
1859 37e766f4 2022-09-21 thomas test_patch_newfile_xbit_got_diff() {
1860 37e766f4 2022-09-21 thomas local testroot=`test_init patch_newfile_xbit`
1861 37e766f4 2022-09-21 thomas
1862 37e766f4 2022-09-21 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1863 37e766f4 2022-09-21 thomas ret=$?
1864 37e766f4 2022-09-21 thomas if [ $ret -ne 0 ]; then
1865 37e766f4 2022-09-21 thomas test_done $testroot $ret
1866 37e766f4 2022-09-21 thomas return 1
1867 37e766f4 2022-09-21 thomas fi
1868 37e766f4 2022-09-21 thomas
1869 37e766f4 2022-09-21 thomas cat <<EOF > $testroot/wt/patch
1870 37e766f4 2022-09-21 thomas blob - /dev/null
1871 37e766f4 2022-09-21 thomas blob + abcdef0123456789abcdef012345678901234567 (mode 755)
1872 37e766f4 2022-09-21 thomas --- /dev/null
1873 37e766f4 2022-09-21 thomas +++ xfile
1874 37e766f4 2022-09-21 thomas @@ -0,0 +1,1 @@
1875 37e766f4 2022-09-21 thomas +xfile
1876 37e766f4 2022-09-21 thomas EOF
1877 37e766f4 2022-09-21 thomas
1878 37e766f4 2022-09-21 thomas (cd $testroot/wt && got patch patch) > /dev/null
1879 37e766f4 2022-09-21 thomas ret=$?
1880 37e766f4 2022-09-21 thomas if [ $ret -ne 0 ]; then
1881 37e766f4 2022-09-21 thomas test_done $testroot $ret
1882 37e766f4 2022-09-21 thomas return 1
1883 f4602cbd 2022-07-23 thomas fi
1884 37e766f4 2022-09-21 thomas
1885 37e766f4 2022-09-21 thomas if [ ! -x $testroot/wt/xfile ]; then
1886 37e766f4 2022-09-21 thomas echo "failed to set xbit on newfile" >&2
1887 37e766f4 2022-09-21 thomas test_done $testroot 1
1888 37e766f4 2022-09-21 thomas return 1
1889 37e766f4 2022-09-21 thomas fi
1890 37e766f4 2022-09-21 thomas
1891 37e766f4 2022-09-21 thomas echo xfile > $testroot/wt/xfile.expected
1892 37e766f4 2022-09-21 thomas cmp -s $testroot/wt/xfile $testroot/wt/xfile.expected
1893 37e766f4 2022-09-21 thomas ret=$?
1894 37e766f4 2022-09-21 thomas if [ $ret -ne 0 ]; then
1895 37e766f4 2022-09-21 thomas echo "fail"
1896 37e766f4 2022-09-21 thomas diff -u $testroot/wt/xfile $testroot/wt/xfile.expected
1897 37e766f4 2022-09-21 thomas fi
1898 37e766f4 2022-09-21 thomas
1899 f4602cbd 2022-07-23 thomas test_done $testroot $ret
1900 f4602cbd 2022-07-23 thomas }
1901 f4602cbd 2022-07-23 thomas
1902 37e766f4 2022-09-21 thomas test_patch_newfile_xbit_git_diff() {
1903 37e766f4 2022-09-21 thomas local testroot=`test_init patch_newfile_xbit`
1904 37e766f4 2022-09-21 thomas
1905 37e766f4 2022-09-21 thomas got checkout $testroot/repo $testroot/wt > /dev/null
1906 37e766f4 2022-09-21 thomas ret=$?
1907 37e766f4 2022-09-21 thomas if [ $ret -ne 0 ]; then
1908 37e766f4 2022-09-21 thomas test_done $testroot $ret
1909 37e766f4 2022-09-21 thomas return 1
1910 37e766f4 2022-09-21 thomas fi
1911 37e766f4 2022-09-21 thomas
1912 37e766f4 2022-09-21 thomas cat <<EOF > $testroot/wt/patch
1913 37e766f4 2022-09-21 thomas diff --git a/xfile b/xfile
1914 37e766f4 2022-09-21 thomas new file mode 100755
1915 37e766f4 2022-09-21 thomas index 00000000..abcdef01
1916 37e766f4 2022-09-21 thomas --- /dev/null
1917 37e766f4 2022-09-21 thomas +++ b/xfile
1918 37e766f4 2022-09-21 thomas @@ -0,0 +1,1 @@
1919 37e766f4 2022-09-21 thomas +xfile
1920 37e766f4 2022-09-21 thomas EOF
1921 37e766f4 2022-09-21 thomas
1922 37e766f4 2022-09-21 thomas (cd $testroot/wt && got patch patch) > /dev/null
1923 37e766f4 2022-09-21 thomas ret=$?
1924 37e766f4 2022-09-21 thomas if [ $ret -ne 0 ]; then
1925 37e766f4 2022-09-21 thomas test_done $testroot $ret
1926 37e766f4 2022-09-21 thomas return 1
1927 37e766f4 2022-09-21 thomas fi
1928 37e766f4 2022-09-21 thomas
1929 37e766f4 2022-09-21 thomas if [ ! -x $testroot/wt/xfile ]; then
1930 37e766f4 2022-09-21 thomas echo "failed to set xbit on newfile" >&2
1931 37e766f4 2022-09-21 thomas test_done $testroot 1
1932 37e766f4 2022-09-21 thomas return 1
1933 37e766f4 2022-09-21 thomas fi
1934 37e766f4 2022-09-21 thomas
1935 37e766f4 2022-09-21 thomas echo xfile > $testroot/wt/xfile.expected
1936 37e766f4 2022-09-21 thomas cmp -s $testroot/wt/xfile $testroot/wt/xfile.expected
1937 37e766f4 2022-09-21 thomas ret=$?
1938 37e766f4 2022-09-21 thomas if [ $ret -ne 0 ]; then
1939 37e766f4 2022-09-21 thomas echo "fail"
1940 37e766f4 2022-09-21 thomas diff -u $testroot/wt/xfile $testroot/wt/xfile.expected
1941 37e766f4 2022-09-21 thomas fi
1942 37e766f4 2022-09-21 thomas
1943 37e766f4 2022-09-21 thomas test_done $testroot $ret
1944 a2c162eb 2022-10-30 thomas }
1945 a2c162eb 2022-10-30 thomas
1946 a2c162eb 2022-10-30 thomas test_patch_umask() {
1947 a2c162eb 2022-10-30 thomas local testroot=`test_init patch_umask`
1948 a2c162eb 2022-10-30 thomas
1949 a2c162eb 2022-10-30 thomas got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1950 a2c162eb 2022-10-30 thomas
1951 a2c162eb 2022-10-30 thomas cat <<EOF >$testroot/wt/patch
1952 a2c162eb 2022-10-30 thomas --- alpha
1953 a2c162eb 2022-10-30 thomas +++ alpha
1954 a2c162eb 2022-10-30 thomas @@ -1 +1 @@
1955 a2c162eb 2022-10-30 thomas -alpha
1956 a2c162eb 2022-10-30 thomas +modified alpha
1957 a2c162eb 2022-10-30 thomas EOF
1958 a2c162eb 2022-10-30 thomas
1959 a2c162eb 2022-10-30 thomas # using a subshell to avoid clobbering global umask
1960 a2c162eb 2022-10-30 thomas (umask 077 && cd "$testroot/wt" && got patch <patch) >/dev/null
1961 a2c162eb 2022-10-30 thomas ret=$?
1962 a2c162eb 2022-10-30 thomas if [ $ret -ne 0 ]; then
1963 a2c162eb 2022-10-30 thomas test_done "$testroot" $ret
1964 a2c162eb 2022-10-30 thomas return 1
1965 a2c162eb 2022-10-30 thomas fi
1966 a2c162eb 2022-10-30 thomas
1967 a2c162eb 2022-10-30 thomas if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1968 a2c162eb 2022-10-30 thomas echo "alpha is not 0600 after patch" >&2
1969 a2c162eb 2022-10-30 thomas ls -l "$testroot/wt/alpha" >&2
1970 a2c162eb 2022-10-30 thomas test_done "$testroot" 1
1971 a2c162eb 2022-10-30 thomas return 1
1972 a2c162eb 2022-10-30 thomas fi
1973 a2c162eb 2022-10-30 thomas
1974 a2c162eb 2022-10-30 thomas test_done "$testroot" 0
1975 37e766f4 2022-09-21 thomas }
1976 650a3405 2023-01-02 thomas
1977 650a3405 2023-01-02 thomas test_patch_remove_binary_file() {
1978 650a3405 2023-01-02 thomas local testroot=`test_init patch_remove_binary_file`
1979 650a3405 2023-01-02 thomas
1980 650a3405 2023-01-02 thomas if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
1981 650a3405 2023-01-02 thomas test_done $testroot $ret
1982 650a3405 2023-01-02 thomas return 1
1983 650a3405 2023-01-02 thomas fi
1984 650a3405 2023-01-02 thomas
1985 650a3405 2023-01-02 thomas dd if=/dev/zero of=$testroot/wt/x bs=1 count=16 2>/dev/null >&2
1986 650a3405 2023-01-02 thomas (cd $testroot/wt && got add x && got commit -m +x) >/dev/null
1987 650a3405 2023-01-02 thomas
1988 650a3405 2023-01-02 thomas (cd $testroot/wt && \
1989 650a3405 2023-01-02 thomas got branch demo && \
1990 650a3405 2023-01-02 thomas got rm x && \
1991 650a3405 2023-01-02 thomas got ci -m -x &&
1992 650a3405 2023-01-02 thomas got up -b master) >/dev/null
1993 650a3405 2023-01-02 thomas
1994 650a3405 2023-01-02 thomas echo 'D x' > $testroot/stdout.expected
1995 37e766f4 2022-09-21 thomas
1996 650a3405 2023-01-02 thomas (cd $testroot/wt && got log -c demo -l 1 -p >patch)
1997 650a3405 2023-01-02 thomas
1998 650a3405 2023-01-02 thomas (cd $testroot/wt && got patch <patch) > $testroot/stdout
1999 650a3405 2023-01-02 thomas if [ $? -ne 0 ]; then
2000 650a3405 2023-01-02 thomas echo 'patch failed' >&2
2001 650a3405 2023-01-02 thomas test_done $testroot 1
2002 650a3405 2023-01-02 thomas return 1
2003 650a3405 2023-01-02 thomas fi
2004 650a3405 2023-01-02 thomas
2005 650a3405 2023-01-02 thomas if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2006 650a3405 2023-01-02 thomas diff -u $testroot/stdout.expected $testroot/stdout
2007 650a3405 2023-01-02 thomas test_done $testroot 1
2008 650a3405 2023-01-02 thomas return 1
2009 650a3405 2023-01-02 thomas fi
2010 650a3405 2023-01-02 thomas
2011 650a3405 2023-01-02 thomas # try again using a git produced diff
2012 650a3405 2023-01-02 thomas (cd $testroot/wt && got revert x) >/dev/null
2013 650a3405 2023-01-02 thomas
2014 d1e03b8c 2023-10-08 thomas git -C $testroot/repo show demo >$testroot/wt/patch
2015 650a3405 2023-01-02 thomas
2016 650a3405 2023-01-02 thomas (cd $testroot/wt && got patch <patch) > $testroot/stdout
2017 650a3405 2023-01-02 thomas if [ $? -ne 0 ]; then
2018 650a3405 2023-01-02 thomas echo 'patch failed' >&2
2019 650a3405 2023-01-02 thomas test_done $testroot 1
2020 650a3405 2023-01-02 thomas return 1
2021 650a3405 2023-01-02 thomas fi
2022 650a3405 2023-01-02 thomas
2023 650a3405 2023-01-02 thomas if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2024 650a3405 2023-01-02 thomas diff -u $testroot/stdout.expected $testroot/stdout
2025 650a3405 2023-01-02 thomas test_done $testroot 1
2026 650a3405 2023-01-02 thomas return 1
2027 650a3405 2023-01-02 thomas fi
2028 650a3405 2023-01-02 thomas
2029 650a3405 2023-01-02 thomas # try again using a diff(1) style patch
2030 650a3405 2023-01-02 thomas (cd $testroot/wt && got revert x) >/dev/null
2031 650a3405 2023-01-02 thomas
2032 650a3405 2023-01-02 thomas echo "Binary files x and /dev/null differ" >$testroot/wt/patch
2033 650a3405 2023-01-02 thomas (cd $testroot/wt && got patch <patch) >$testroot/stdout
2034 650a3405 2023-01-02 thomas if [ $? -ne 0 ]; then
2035 650a3405 2023-01-02 thomas echo 'patch failed' >&2
2036 650a3405 2023-01-02 thomas test_done $testroot 1
2037 650a3405 2023-01-02 thomas return 1
2038 650a3405 2023-01-02 thomas fi
2039 650a3405 2023-01-02 thomas
2040 650a3405 2023-01-02 thomas if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2041 650a3405 2023-01-02 thomas diff -u $testroot/stdout.expected $testroot/stdout
2042 650a3405 2023-01-02 thomas test_done $testroot 1
2043 650a3405 2023-01-02 thomas return 1
2044 650a3405 2023-01-02 thomas fi
2045 650a3405 2023-01-02 thomas
2046 650a3405 2023-01-02 thomas test_done $testroot 0
2047 650a3405 2023-01-02 thomas }
2048 fb885120 2023-07-19 thomas
2049 fb885120 2023-07-19 thomas test_patch_commit_keywords() {
2050 fb885120 2023-07-19 thomas local testroot=`test_init patch_commit_keywords`
2051 fb885120 2023-07-19 thomas
2052 fb885120 2023-07-19 thomas got checkout $testroot/repo $testroot/wt >/dev/null
2053 fb885120 2023-07-19 thomas ret=$?
2054 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2055 fb885120 2023-07-19 thomas test_done $testroot $ret
2056 fb885120 2023-07-19 thomas return 1
2057 fb885120 2023-07-19 thomas fi
2058 fb885120 2023-07-19 thomas
2059 cf85a643 2024-04-09 thomas seq 10 > $testroot/wt/numbers
2060 fb885120 2023-07-19 thomas (cd $testroot/wt && got add numbers && got commit -m +numbers) \
2061 fb885120 2023-07-19 thomas >/dev/null
2062 fb885120 2023-07-19 thomas ret=$?
2063 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2064 fb885120 2023-07-19 thomas test_done $testroot $ret
2065 fb885120 2023-07-19 thomas return 1
2066 fb885120 2023-07-19 thomas fi
2067 fb885120 2023-07-19 thomas
2068 cf85a643 2024-04-09 thomas seq 10 | sed s/4/four/ > $testroot/wt/numbers
2069 fb885120 2023-07-19 thomas
2070 fb885120 2023-07-19 thomas # get rid of the metadata
2071 fb885120 2023-07-19 thomas (cd $testroot/wt && got diff | sed -n '/^---/,$p' > patch) \
2072 fb885120 2023-07-19 thomas >/dev/null
2073 650a3405 2023-01-02 thomas
2074 cf85a643 2024-04-09 thomas seq 10 | sed s/6/six/ > $testroot/wt/numbers
2075 fb885120 2023-07-19 thomas (cd $testroot/wt && got commit -m 'edit numbers') >/dev/null
2076 fb885120 2023-07-19 thomas ret=$?
2077 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2078 fb885120 2023-07-19 thomas test_done $testroot $ret
2079 fb885120 2023-07-19 thomas return 1
2080 fb885120 2023-07-19 thomas fi
2081 fb885120 2023-07-19 thomas
2082 fb885120 2023-07-19 thomas (cd $testroot/wt && got patch -c :head:- patch) >$testroot/stdout
2083 fb885120 2023-07-19 thomas ret=$?
2084 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2085 fb885120 2023-07-19 thomas test_done $testroot $ret
2086 fb885120 2023-07-19 thomas return 1
2087 fb885120 2023-07-19 thomas fi
2088 fb885120 2023-07-19 thomas
2089 fb885120 2023-07-19 thomas echo 'G numbers' > $testroot/stdout.expected
2090 fb885120 2023-07-19 thomas cmp -s $testroot/stdout $testroot/stdout.expected
2091 fb885120 2023-07-19 thomas ret=$?
2092 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2093 fb885120 2023-07-19 thomas diff -u $testroot/stdout $testroot/stdout.expected
2094 fb885120 2023-07-19 thomas test_done $testroot $ret
2095 fb885120 2023-07-19 thomas return 1
2096 fb885120 2023-07-19 thomas fi
2097 fb885120 2023-07-19 thomas
2098 cf85a643 2024-04-09 thomas seq 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
2099 fb885120 2023-07-19 thomas cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
2100 fb885120 2023-07-19 thomas ret=$?
2101 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2102 fb885120 2023-07-19 thomas diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
2103 fb885120 2023-07-19 thomas fi
2104 fb885120 2023-07-19 thomas
2105 fb885120 2023-07-19 thomas (cd "$testroot/wt" && got rv numbers > /dev/null)
2106 fb885120 2023-07-19 thomas
2107 fb885120 2023-07-19 thomas (cd $testroot/wt && got patch -c :base:- patch) >$testroot/stdout
2108 fb885120 2023-07-19 thomas ret=$?
2109 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2110 fb885120 2023-07-19 thomas test_done $testroot $ret
2111 fb885120 2023-07-19 thomas return 1
2112 fb885120 2023-07-19 thomas fi
2113 fb885120 2023-07-19 thomas
2114 fb885120 2023-07-19 thomas echo 'G numbers' > $testroot/stdout.expected
2115 fb885120 2023-07-19 thomas cmp -s $testroot/stdout $testroot/stdout.expected
2116 fb885120 2023-07-19 thomas ret=$?
2117 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2118 fb885120 2023-07-19 thomas diff -u $testroot/stdout $testroot/stdout.expected
2119 fb885120 2023-07-19 thomas test_done $testroot $ret
2120 fb885120 2023-07-19 thomas return 1
2121 fb885120 2023-07-19 thomas fi
2122 fb885120 2023-07-19 thomas
2123 cf85a643 2024-04-09 thomas seq 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
2124 fb885120 2023-07-19 thomas cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
2125 fb885120 2023-07-19 thomas ret=$?
2126 fb885120 2023-07-19 thomas if [ $ret -ne 0 ]; then
2127 fb885120 2023-07-19 thomas diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
2128 fb885120 2023-07-19 thomas fi
2129 fb885120 2023-07-19 thomas
2130 fb885120 2023-07-19 thomas test_done $testroot $ret
2131 fb885120 2023-07-19 thomas }
2132 fb885120 2023-07-19 thomas
2133 069bbb86 2022-03-07 thomas test_parseargs "$@"
2134 3b6e8f19 2022-08-06 thomas run_test test_patch_basic
2135 069bbb86 2022-03-07 thomas run_test test_patch_dont_apply
2136 069bbb86 2022-03-07 thomas run_test test_patch_malformed
2137 069bbb86 2022-03-07 thomas run_test test_patch_no_patch
2138 069bbb86 2022-03-07 thomas run_test test_patch_equals_for_context
2139 bb2ad8ff 2022-03-13 thomas run_test test_patch_rename
2140 10e55613 2022-03-22 thomas run_test test_patch_illegal_status
2141 eaf99875 2022-03-22 thomas run_test test_patch_nop
2142 da09d8ed 2022-03-22 thomas run_test test_patch_preserve_perm
2143 e0c1f81c 2022-03-22 thomas run_test test_patch_create_dirs
2144 49114f01 2022-03-22 thomas run_test test_patch_with_offset
2145 13b170bf 2024-04-25 thomas.ad run_test test_patch_empty_file
2146 be53ddb1 2022-03-22 thomas run_test test_patch_prefer_new_path
2147 ff7f34d3 2022-03-22 thomas run_test test_patch_no_newline
2148 d9db2ff9 2022-04-16 thomas run_test test_patch_strip
2149 bb90ca7b 2022-07-03 thomas run_test test_patch_whitespace
2150 72f46891 2022-04-23 thomas run_test test_patch_relative_paths
2151 cfbf5531 2022-04-23 thomas run_test test_patch_with_path_prefix
2152 cfbf5531 2022-04-23 thomas run_test test_patch_relpath_with_path_prefix
2153 eaef698f 2022-04-23 thomas run_test test_patch_reverse
2154 0f76ab83 2022-06-23 thomas run_test test_patch_merge_simple
2155 19dd85cb 2022-07-01 thomas run_test test_patch_merge_gitdiff
2156 7d8bcb99 2022-07-28 thomas run_test test_patch_merge_base_provided
2157 0f76ab83 2022-06-23 thomas run_test test_patch_merge_conflict
2158 0f76ab83 2022-06-23 thomas run_test test_patch_merge_unknown_blob
2159 f4602cbd 2022-07-23 thomas run_test test_patch_merge_reverse
2160 37e766f4 2022-09-21 thomas run_test test_patch_newfile_xbit_got_diff
2161 37e766f4 2022-09-21 thomas run_test test_patch_newfile_xbit_git_diff
2162 a2c162eb 2022-10-30 thomas run_test test_patch_umask
2163 650a3405 2023-01-02 thomas run_test test_patch_remove_binary_file
2164 fb885120 2023-07-19 thomas run_test test_patch_commit_keywords