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