3 e9ce266e 2022-03-07 op # Copyright (c) 2022 Omar Polo <op@openbsd.org>
5 e9ce266e 2022-03-07 op # Permission to use, copy, modify, and distribute this software for any
6 e9ce266e 2022-03-07 op # purpose with or without fee is hereby granted, provided that the above
7 e9ce266e 2022-03-07 op # copyright notice and this permission notice appear in all copies.
9 e9ce266e 2022-03-07 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 e9ce266e 2022-03-07 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 e9ce266e 2022-03-07 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 e9ce266e 2022-03-07 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 e9ce266e 2022-03-07 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 e9ce266e 2022-03-07 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 e9ce266e 2022-03-07 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 57b1c3f2 2022-08-01 op test_patch_basic() {
20 57b1c3f2 2022-08-01 op local testroot=`test_init patch_basic`
22 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
24 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
25 e9ce266e 2022-03-07 op test_done $testroot $ret
29 2fed5287 2024-04-09 op seq 100 > $testroot/wt/numbers
30 57b1c3f2 2022-08-01 op (cd $testroot/wt && got add numbers && got commit -m +numbers) \
33 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
34 57b1c3f2 2022-08-01 op test_done "$testroot" $ret
38 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
43 e9ce266e 2022-03-07 op +alpha is my favourite character
48 57b1c3f2 2022-08-01 op --- gamma/delta
49 57b1c3f2 2022-08-01 op +++ gamma/delta
55 57b1c3f2 2022-08-01 op @@ -0,0 +5,5 @@
63 e9ce266e 2022-03-07 op @@ -3,7 +3,7 @@
72 e9ce266e 2022-03-07 op @@ -57,7 +57,7 @@
81 e9ce266e 2022-03-07 op @@ -98,3 +98,6 @@
90 9cda65e5 2022-10-15 stsp (cd $testroot/wt && got patch < patch) > $testroot/stdout
91 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
92 57b1c3f2 2022-08-01 op test_done "$testroot" $ret
96 57b1c3f2 2022-08-01 op echo 'M alpha' > $testroot/stdout.expected
97 57b1c3f2 2022-08-01 op echo 'D beta' >> $testroot/stdout.expected
98 57b1c3f2 2022-08-01 op echo 'M gamma/delta' >> $testroot/stdout.expected
99 57b1c3f2 2022-08-01 op echo 'A eta' >> $testroot/stdout.expected
100 57b1c3f2 2022-08-01 op echo 'M numbers' >> $testroot/stdout.expected
102 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
104 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
105 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
106 e9ce266e 2022-03-07 op test_done $testroot $ret
110 57b1c3f2 2022-08-01 op echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
111 57b1c3f2 2022-08-01 op cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
113 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
114 57b1c3f2 2022-08-01 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
115 57b1c3f2 2022-08-01 op test_done "$testroot" $ret
119 57b1c3f2 2022-08-01 op if [ -f "$testroot/wt/beta" ]; then
120 57b1c3f2 2022-08-01 op echo "beta was not deleted!" >&2
121 57b1c3f2 2022-08-01 op test_done "$testroot" 1
125 57b1c3f2 2022-08-01 op echo 'this is:' > $testroot/wt/gamma/delta.expected
126 57b1c3f2 2022-08-01 op echo 'delta' >> $testroot/wt/gamma/delta.expected
127 57b1c3f2 2022-08-01 op cmp -s $testroot/wt/gamma/delta.expected $testroot/wt/gamma/delta
129 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
130 57b1c3f2 2022-08-01 op diff -u $testroot/wt/gamma/delta.expected $testroot/wt/gamma/delta
131 57b1c3f2 2022-08-01 op test_done "$testroot" $ret
135 2fed5287 2024-04-09 op seq 5 > $testroot/wt/eta.expected
136 57b1c3f2 2022-08-01 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
138 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
139 57b1c3f2 2022-08-01 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
140 57b1c3f2 2022-08-01 op test_done "$testroot" $ret
144 2fed5287 2024-04-09 op seq 103 | sed -e 's/^6$/six/' -e 's/60/sixty/' \
145 57b1c3f2 2022-08-01 op > $testroot/wt/numbers.expected
146 57b1c3f2 2022-08-01 op cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
148 57b1c3f2 2022-08-01 op if [ $ret -ne 0 ]; then
149 57b1c3f2 2022-08-01 op diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
151 57b1c3f2 2022-08-01 op test_done $testroot $ret
154 e9ce266e 2022-03-07 op test_patch_dont_apply() {
155 e9ce266e 2022-03-07 op local testroot=`test_init patch_dont_apply`
157 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
159 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
160 e9ce266e 2022-03-07 op test_done $testroot $ret
164 2fed5287 2024-04-09 op seq 100 > $testroot/wt/numbers
165 5b67f96e 2022-03-13 op (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
168 5b67f96e 2022-03-13 op if [ $ret -ne 0 ]; then
169 5b67f96e 2022-03-13 op test_done $testroot $ret
173 5b67f96e 2022-03-13 op cat <<EOF > $testroot/wt/patch
176 60aa1fa0 2022-03-17 op @@ -1 +1,2 @@
178 60aa1fa0 2022-03-17 op alpha something
180 5b67f96e 2022-03-13 op +++ /dev/null
181 5b67f96e 2022-03-13 op @@ -1,9 +0,0 @@
193 60aa1fa0 2022-03-17 op (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
195 5b67f96e 2022-03-13 op if [ $ret -eq 0 ]; then # should fail
196 5b67f96e 2022-03-13 op test_done $testroot 1
200 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/stdout.expected
202 60aa1fa0 2022-03-17 op @@ -1,1 +1,2 @@ hunk failed to apply
204 60aa1fa0 2022-03-17 op @@ -1,9 +0,0 @@ hunk failed to apply
205 bfcdc9e9 2023-05-11 stsp Files where patch failed to apply: 2
208 60aa1fa0 2022-03-17 op cmp -s $testroot/stdout.expected $testroot/stdout
210 5b67f96e 2022-03-13 op if [ $ret -ne 0 ]; then
211 60aa1fa0 2022-03-17 op diff -u $testroot/stdout.expected $testroot/stdout
213 e9ce266e 2022-03-07 op test_done $testroot $ret
216 e9ce266e 2022-03-07 op test_patch_malformed() {
217 e9ce266e 2022-03-07 op local testroot=`test_init patch_malformed`
219 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
221 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
222 e9ce266e 2022-03-07 op test_done $testroot $ret
226 e9ce266e 2022-03-07 op # missing "@@"
227 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
235 e9ce266e 2022-03-07 op echo -n > $testroot/stdout.expected
236 e9ce266e 2022-03-07 op echo "got: malformed patch" > $testroot/stderr.expected
238 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
239 e9ce266e 2022-03-07 op > $testroot/stdout \
240 e9ce266e 2022-03-07 op 2> $testroot/stderr
242 bfbccd0a 2022-03-08 op if [ $ret -eq 0 ]; then
243 e9ce266e 2022-03-07 op echo "got managed to apply an invalid patch"
244 e9ce266e 2022-03-07 op test_done $testroot 1
248 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
250 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
251 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
252 e9ce266e 2022-03-07 op test_done $testroot $ret
256 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
258 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
259 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
260 e9ce266e 2022-03-07 op test_done $testroot $ret
264 e9ce266e 2022-03-07 op # wrong first character
265 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
268 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
273 be33dff7 2022-05-13 op (cd $testroot/wt && got patch patch) \
274 be33dff7 2022-05-13 op > $testroot/stdout \
275 be33dff7 2022-05-13 op 2> $testroot/stderr
277 be33dff7 2022-05-13 op if [ $ret -eq 0 ]; then
278 be33dff7 2022-05-13 op echo "got managed to apply an invalid patch"
279 be33dff7 2022-05-13 op test_done $testroot 1
283 be33dff7 2022-05-13 op cmp -s $testroot/stdout.expected $testroot/stdout
285 be33dff7 2022-05-13 op if [ $ret -ne 0 ]; then
286 be33dff7 2022-05-13 op diff -u $testroot/stdout.expected $testroot/stdout
287 be33dff7 2022-05-13 op test_done $testroot $ret
291 be33dff7 2022-05-13 op cmp -s $testroot/stderr.expected $testroot/stderr
293 be33dff7 2022-05-13 op if [ $ret -ne 0 ]; then
294 be33dff7 2022-05-13 op diff -u $testroot/stderr.expected $testroot/stderr
295 be33dff7 2022-05-13 op test_done $testroot $ret
300 be33dff7 2022-05-13 op cat <<EOF > $testroot/wt/patch
301 be33dff7 2022-05-13 op diff --git a/alpha b/iota
304 be33dff7 2022-05-13 op @@ -0,0 +0,0 @@
307 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
308 e9ce266e 2022-03-07 op > $testroot/stdout \
309 e9ce266e 2022-03-07 op 2> $testroot/stderr
311 bfbccd0a 2022-03-08 op if [ $ret -eq 0 ]; then
312 e9ce266e 2022-03-07 op echo "got managed to apply an invalid patch"
313 e9ce266e 2022-03-07 op test_done $testroot 1
317 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
319 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
320 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
321 e9ce266e 2022-03-07 op test_done $testroot $ret
325 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
327 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
328 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
329 e9ce266e 2022-03-07 op test_done $testroot $ret
333 e9ce266e 2022-03-07 op test_done $testroot $ret
336 e9ce266e 2022-03-07 op test_patch_no_patch() {
337 e9ce266e 2022-03-07 op local testroot=`test_init patch_no_patch`
339 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
341 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
342 e9ce266e 2022-03-07 op test_done $testroot $ret
346 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
350 e9ce266e 2022-03-07 op some other nonsense
353 e9ce266e 2022-03-07 op there's no patch in here!
356 e9ce266e 2022-03-07 op echo -n > $testroot/stdout.expected
357 e9ce266e 2022-03-07 op echo "got: no patch found" > $testroot/stderr.expected
359 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) \
360 e9ce266e 2022-03-07 op > $testroot/stdout \
361 e9ce266e 2022-03-07 op 2> $testroot/stderr
363 bfbccd0a 2022-03-08 op if [ $ret -eq 0 ]; then # should fail
364 e9ce266e 2022-03-07 op test_done $testroot 1
368 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
370 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
371 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
372 e9ce266e 2022-03-07 op test_done $testroot $ret
376 e9ce266e 2022-03-07 op cmp -s $testroot/stderr.expected $testroot/stderr
378 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
379 e9ce266e 2022-03-07 op diff -u $testroot/stderr.expected $testroot/stderr
380 e9ce266e 2022-03-07 op test_done $testroot $ret
384 e9ce266e 2022-03-07 op test_done $testroot $ret
387 e9ce266e 2022-03-07 op test_patch_equals_for_context() {
388 f1d6cebb 2022-04-23 op local testroot=`test_init patch_equals_for_context`
390 e9ce266e 2022-03-07 op got checkout $testroot/repo $testroot/wt > /dev/null
392 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
393 e9ce266e 2022-03-07 op test_done $testroot $ret
397 e9ce266e 2022-03-07 op cat <<EOF > $testroot/wt/patch
400 e9ce266e 2022-03-07 op @@ -1 +1,2 @@
405 e9ce266e 2022-03-07 op echo "M alpha" > $testroot/stdout.expected
407 e9ce266e 2022-03-07 op (cd $testroot/wt && got patch patch) > $testroot/stdout
409 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
410 e9ce266e 2022-03-07 op test_done $testroot $ret
414 e9ce266e 2022-03-07 op cmp -s $testroot/stdout.expected $testroot/stdout
416 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
417 e9ce266e 2022-03-07 op diff -u $testroot/stdout.expected $testroot/stdout
418 e9ce266e 2022-03-07 op test_done $testroot $ret
422 e9ce266e 2022-03-07 op echo hatsuseno > $testroot/wt/alpha.expected
423 e9ce266e 2022-03-07 op echo alpha >> $testroot/wt/alpha.expected
424 e9ce266e 2022-03-07 op cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
426 bfbccd0a 2022-03-08 op if [ $ret -ne 0 ]; then
427 e9ce266e 2022-03-07 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
429 e9ce266e 2022-03-07 op test_done $testroot $ret
432 6e96b326 2022-03-12 op test_patch_rename() {
433 6e96b326 2022-03-12 op local testroot=`test_init patch_rename`
435 6e96b326 2022-03-12 op got checkout $testroot/repo $testroot/wt > /dev/null
437 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
438 6e96b326 2022-03-12 op test_done $testroot $ret
442 6e96b326 2022-03-12 op cat <<EOF > $testroot/wt/patch
443 4379a9aa 2022-05-02 op diff --git a/beta b/iota
444 4379a9aa 2022-05-02 op similarity index 100%
445 4379a9aa 2022-05-02 op rename from beta
446 4379a9aa 2022-05-02 op rename to iota
447 7a30b5cb 2022-03-20 op diff --git a/alpha b/eta
455 4379a9aa 2022-05-02 op echo 'D beta' > $testroot/stdout.expected
456 4379a9aa 2022-05-02 op echo 'A iota' >> $testroot/stdout.expected
457 4379a9aa 2022-05-02 op echo 'D alpha' >> $testroot/stdout.expected
458 4379a9aa 2022-05-02 op echo 'A eta' >> $testroot/stdout.expected
460 6e96b326 2022-03-12 op (cd $testroot/wt && got patch patch) > $testroot/stdout
462 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
463 6e96b326 2022-03-12 op test_done $testroot $ret
467 6e96b326 2022-03-12 op cmp -s $testroot/stdout.expected $testroot/stdout
469 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
470 6e96b326 2022-03-12 op diff -u $testroot/stdout.expected $testroot/stdout
471 6e96b326 2022-03-12 op test_done $testroot $ret
475 4379a9aa 2022-05-02 op if [ -f $testroot/wt/alpha -o -f $testroot/wt/beta ]; then
476 4379a9aa 2022-05-02 op echo "alpha or beta were not removed" >&2
477 6e96b326 2022-03-12 op test_done $testroot 1
480 4379a9aa 2022-05-02 op if [ ! -f $testroot/wt/iota -o ! -f $testroot/wt/eta ]; then
481 4379a9aa 2022-05-02 op echo "iota or eta were not created" >&2
482 6e96b326 2022-03-12 op test_done $testroot 1
486 4379a9aa 2022-05-02 op echo beta > $testroot/wt/iota.expected
487 4379a9aa 2022-05-02 op cmp -s $testroot/wt/iota.expected $testroot/wt/iota
489 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
490 4379a9aa 2022-05-02 op diff -u $testroot/wt/iota.expected $testroot/wt/iota
491 6e96b326 2022-03-12 op test_done $testroot $ret
495 4379a9aa 2022-05-02 op echo eta > $testroot/wt/eta.expected
496 4379a9aa 2022-05-02 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
498 6e96b326 2022-03-12 op if [ $ret -ne 0 ]; then
499 4379a9aa 2022-05-02 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
500 6e96b326 2022-03-12 op test_done $testroot $ret
504 6e96b326 2022-03-12 op test_done $testroot $ret
507 dbda770b 2022-03-13 op test_patch_illegal_status() {
508 dbda770b 2022-03-13 op local testroot=`test_init patch_illegal_status`
510 dbda770b 2022-03-13 op got checkout $testroot/repo $testroot/wt > /dev/null
512 dbda770b 2022-03-13 op if [ $ret -ne 0 ]; then
513 dbda770b 2022-03-13 op test_done $testroot $ret
517 60aa1fa0 2022-03-17 op # try to patch an obstructed file, add a versioned one, edit a
518 60aa1fa0 2022-03-17 op # non existent file and an unversioned one, and remove a
519 60aa1fa0 2022-03-17 op # non existent file.
520 dbda770b 2022-03-13 op cat <<EOF > $testroot/wt/patch
523 60aa1fa0 2022-03-17 op @@ -1 +1,2 @@
526 60aa1fa0 2022-03-17 op --- /dev/null
528 60aa1fa0 2022-03-17 op @@ -0,0 +1 @@
541 60aa1fa0 2022-03-17 op +++ /dev/null
542 60aa1fa0 2022-03-17 op @@ -1 +0,0 @@
546 60aa1fa0 2022-03-17 op echo kappa > $testroot/wt/kappa
547 dbda770b 2022-03-13 op rm $testroot/wt/alpha
548 dbda770b 2022-03-13 op mkdir $testroot/wt/alpha
550 60aa1fa0 2022-03-17 op (cd $testroot/wt && got patch patch) > $testroot/stdout \
551 dbda770b 2022-03-13 op 2> $testroot/stderr
553 dbda770b 2022-03-13 op if [ $ret -eq 0 ]; then
554 dbda770b 2022-03-13 op echo "edited a missing file" >&2
555 a19f439c 2022-06-03 op test_done $testroot 1
559 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/stdout.expected
565 bfcdc9e9 2023-05-11 stsp Files where patch failed to apply: 5
568 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/stderr.expected
569 60aa1fa0 2022-03-17 op got: alpha: file has unexpected status
570 60aa1fa0 2022-03-17 op got: beta: file has unexpected status
571 60aa1fa0 2022-03-17 op got: iota: No such file or directory
572 60aa1fa0 2022-03-17 op got: kappa: file has unexpected status
573 60aa1fa0 2022-03-17 op got: lambda: No such file or directory
574 60aa1fa0 2022-03-17 op got: patch failed to apply
577 60aa1fa0 2022-03-17 op cmp -s $testroot/stdout.expected $testroot/stdout
579 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
580 60aa1fa0 2022-03-17 op diff -u $testroot/stdout.expected $testroot/stdout
581 dbda770b 2022-03-13 op test_done $testroot $ret
585 dbda770b 2022-03-13 op cmp -s $testroot/stderr.expected $testroot/stderr
587 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
588 dbda770b 2022-03-13 op diff -u $testroot/stderr.expected $testroot/stderr
589 78f5ac24 2022-03-19 op test_done $testroot $ret
593 78f5ac24 2022-03-19 op (cd $testroot/wt && got status) > $testroot/stdout
594 78f5ac24 2022-03-19 op cat <<EOF > $testroot/stdout.expected
600 78f5ac24 2022-03-19 op cmp -s $testroot/stdout.expected $testroot/stdout
602 78f5ac24 2022-03-19 op if [ $ret -ne 0 ]; then
603 78f5ac24 2022-03-19 op diff -u $testroot/stdout.expected $testroot/stdout
605 899fcfdf 2022-03-13 op test_done $testroot $ret
608 899fcfdf 2022-03-13 op test_patch_nop() {
609 899fcfdf 2022-03-13 op local testroot=`test_init patch_nop`
611 899fcfdf 2022-03-13 op got checkout $testroot/repo $testroot/wt > /dev/null
613 899fcfdf 2022-03-13 op if [ $ret -ne 0 ]; then
614 899fcfdf 2022-03-13 op test_done $testroot $ret
618 899fcfdf 2022-03-13 op cat <<EOF > $testroot/wt/patch
625 899fcfdf 2022-03-13 op +++ /dev/null
626 899fcfdf 2022-03-13 op @@ -1 +0,0 @@
628 7a30b5cb 2022-03-20 op diff --git a/gamma/delta b/gamma/delta.new
629 899fcfdf 2022-03-13 op --- gamma/delta
630 899fcfdf 2022-03-13 op +++ gamma/delta.new
633 899fcfdf 2022-03-13 op +delta updated and renamed!
636 899fcfdf 2022-03-13 op (cd $testroot/wt && got patch -n patch)
638 899fcfdf 2022-03-13 op if [ $ret -ne 0 ]; then
639 899fcfdf 2022-03-13 op test_done $testroot $ret
643 899fcfdf 2022-03-13 op # remove the patch to avoid the ? entry
644 899fcfdf 2022-03-13 op rm $testroot/wt/patch
646 899fcfdf 2022-03-13 op (cd $testroot/wt && got status) > $testroot/stdout
648 899fcfdf 2022-03-13 op if [ $ret -ne 0 ]; then
649 899fcfdf 2022-03-13 op test_done $testroot $ret
653 899fcfdf 2022-03-13 op echo -n > $testroot/stdout.expected
654 899fcfdf 2022-03-13 op cmp -s $testroot/stdout.expected $testroot/stdout
656 899fcfdf 2022-03-13 op if [ $ret -ne 0 ]; then
657 899fcfdf 2022-03-13 op diff -u $testroot/stdout.expected $testroot/stdout
659 dbda770b 2022-03-13 op test_done $testroot $ret
662 2be5e1a2 2022-03-16 op test_patch_preserve_perm() {
663 2be5e1a2 2022-03-16 op local testroot=`test_init patch_preserve_perm`
665 2be5e1a2 2022-03-16 op got checkout $testroot/repo $testroot/wt > /dev/null
667 2be5e1a2 2022-03-16 op if [ $ret -ne 0 ]; then
668 2be5e1a2 2022-03-16 op test_done $testroot $ret
672 2be5e1a2 2022-03-16 op chmod +x $testroot/wt/alpha
673 2be5e1a2 2022-03-16 op (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
675 2be5e1a2 2022-03-16 op if [ $ret -ne 0 ]; then
676 2be5e1a2 2022-03-16 op test_done $testroot $ret
680 2be5e1a2 2022-03-16 op cat <<EOF > $testroot/wt/patch
683 2be5e1a2 2022-03-16 op @@ -1 +1,2 @@
688 2be5e1a2 2022-03-16 op (cd $testroot/wt && got patch patch) > /dev/null
690 2be5e1a2 2022-03-16 op if [ $ret -ne 0 ]; then
691 2be5e1a2 2022-03-16 op test_done $testroot $ret
695 2be5e1a2 2022-03-16 op if [ ! -x $testroot/wt/alpha ]; then
696 2be5e1a2 2022-03-16 op echo "alpha is no more executable!" >&2
697 2be5e1a2 2022-03-16 op test_done $testroot 1
700 95d68340 2022-03-16 op test_done $testroot 0
703 95d68340 2022-03-16 op test_patch_create_dirs() {
704 95d68340 2022-03-16 op local testroot=`test_init patch_create_dirs`
706 95d68340 2022-03-16 op got checkout $testroot/repo $testroot/wt > /dev/null
708 95d68340 2022-03-16 op if [ $ret -ne 0 ]; then
709 95d68340 2022-03-16 op test_done $testroot $ret
713 95d68340 2022-03-16 op cat <<EOF > $testroot/wt/patch
714 95d68340 2022-03-16 op --- /dev/null
715 95d68340 2022-03-16 op +++ iota/kappa/lambda
716 95d68340 2022-03-16 op @@ -0,0 +1 @@
720 95d68340 2022-03-16 op (cd $testroot/wt && got patch patch) > $testroot/stdout
722 95d68340 2022-03-16 op if [ $ret -ne 0 ]; then
723 95d68340 2022-03-16 op test_done $testroot $ret
727 95d68340 2022-03-16 op echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
728 95d68340 2022-03-16 op cmp -s $testroot/stdout.expected $testroot/stdout
730 95d68340 2022-03-16 op if [ $ret -ne 0 ]; then
731 95d68340 2022-03-16 op diff -u $testroot/stdout.expected $testroot/stdout
732 95d68340 2022-03-16 op test_done $testroot $ret
736 95d68340 2022-03-16 op if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
737 95d68340 2022-03-16 op echo "file not created!" >&2
738 95d68340 2022-03-16 op test_done $testroot $ret
741 2be5e1a2 2022-03-16 op test_done $testroot 0
744 60aa1fa0 2022-03-17 op test_patch_with_offset() {
745 60aa1fa0 2022-03-17 op local testroot=`test_init patch_with_offset`
747 60aa1fa0 2022-03-17 op got checkout $testroot/repo $testroot/wt > /dev/null
749 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
750 60aa1fa0 2022-03-17 op test_done $testroot $ret
754 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/wt/patch
757 60aa1fa0 2022-03-17 op @@ -47,7 +47,7 @@
762 60aa1fa0 2022-03-17 op +midway tru it!
766 60aa1fa0 2022-03-17 op @@ -87,7 +87,7 @@
771 60aa1fa0 2022-03-17 op +almost there!
777 2fed5287 2024-04-09 op seq 100 > $testroot/wt/numbers
778 5f94a4e0 2022-11-18 op ed -s "$testroot/wt/numbers" <<EOF
785 60aa1fa0 2022-03-17 op (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
788 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
789 60aa1fa0 2022-03-17 op test_done $testroot $ret
793 60aa1fa0 2022-03-17 op (cd $testroot/wt && got patch patch) > $testroot/stdout
795 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
796 60aa1fa0 2022-03-17 op test_done $testroot/wt $ret
800 60aa1fa0 2022-03-17 op cat <<EOF > $testroot/stdout.expected
802 60aa1fa0 2022-03-17 op @@ -47,7 +47,7 @@ applied with offset -10
803 60aa1fa0 2022-03-17 op @@ -87,7 +87,7 @@ applied with offset 10
806 04a87797 2024-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
808 04a87797 2024-04-23 op if [ $ret -ne 0 ]; then
809 04a87797 2024-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
811 04a87797 2024-04-23 op test_done $testroot $ret
814 04a87797 2024-04-23 op test_patch_empty_file() {
815 04a87797 2024-04-23 op local testroot=`test_init patch_empty_file`
817 04a87797 2024-04-23 op got checkout $testroot/repo $testroot/wt > /dev/null
819 04a87797 2024-04-23 op if [ $ret -ne 0 ]; then
820 04a87797 2024-04-23 op test_done $testroot $ret
824 04a87797 2024-04-23 op echo -n > $testroot/wt/alpha
825 04a87797 2024-04-23 op (cd "$testroot/wt" && got commit -m 'edit alpha' alpha) >/dev/null
827 27aa2674 2024-04-23 stsp # try a patch which re-adds file contents; should suceeed
828 04a87797 2024-04-23 op cat <<EOF >$testroot/wt/patch
831 04a87797 2024-04-23 op @@ -0,0 +1 @@
834 04a87797 2024-04-23 op (cd $testroot/wt && got patch patch) > $testroot/stdout
836 04a87797 2024-04-23 op if [ $ret -ne 0 ]; then
837 04a87797 2024-04-23 op test_done $testroot $ret
840 04a87797 2024-04-23 op echo 'M alpha' > $testroot/stdout.expected
841 7a30b5cb 2022-03-20 op cmp -s $testroot/stdout.expected $testroot/stdout
843 7a30b5cb 2022-03-20 op if [ $ret -ne 0 ]; then
844 7a30b5cb 2022-03-20 op diff -u $testroot/stdout.expected $testroot/stdout
845 27aa2674 2024-04-23 stsp test_done $testroot $ret
849 27aa2674 2024-04-23 stsp (cd $testroot/wt && got revert -R . > /dev/null)
851 27aa2674 2024-04-23 stsp # try a patch which edits the file; should fail
852 27aa2674 2024-04-23 stsp cat <<EOF >$testroot/wt/patch
855 27aa2674 2024-04-23 stsp @@ -1 +1 @@
859 27aa2674 2024-04-23 stsp (cd $testroot/wt && got patch patch) > $testroot/stdout \
860 27aa2674 2024-04-23 stsp 2> $testroot/stderr
862 27aa2674 2024-04-23 stsp if [ $ret -eq 0 ]; then
863 27aa2674 2024-04-23 stsp echo "got patch suceeded unexpectedly" >&2
864 27aa2674 2024-04-23 stsp test_done $testroot $ret
868 27aa2674 2024-04-23 stsp echo 'got: patch failed to apply' > $testroot/stderr.expected
869 27aa2674 2024-04-23 stsp cmp -s $testroot/stderr.expected $testroot/stderr
871 27aa2674 2024-04-23 stsp if [ $ret -ne 0 ]; then
872 27aa2674 2024-04-23 stsp diff -u $testroot/stderr.expected $testroot/stderr
873 27aa2674 2024-04-23 stsp test_done $testroot $ret
877 27aa2674 2024-04-23 stsp (cd $testroot/wt && got revert -R . > /dev/null)
879 27aa2674 2024-04-23 stsp # try a patch which deletes lines from the file; should fail
880 27aa2674 2024-04-23 stsp cat <<EOF >$testroot/wt/patch
883 27aa2674 2024-04-23 stsp @@ -1,2 +0 @@
887 27aa2674 2024-04-23 stsp (cd $testroot/wt && got patch patch) > $testroot/stdout \
888 27aa2674 2024-04-23 stsp 2> $testroot/stderr
890 27aa2674 2024-04-23 stsp if [ $ret -eq 0 ]; then
891 27aa2674 2024-04-23 stsp echo "got patch suceeded unexpectedly" >&2
892 27aa2674 2024-04-23 stsp test_done $testroot $ret
895 27aa2674 2024-04-23 stsp echo 'got: patch failed to apply' > $testroot/stderr.expected
896 27aa2674 2024-04-23 stsp cmp -s $testroot/stderr.expected $testroot/stderr
898 27aa2674 2024-04-23 stsp if [ $ret -ne 0 ]; then
899 27aa2674 2024-04-23 stsp diff -u $testroot/stderr.expected $testroot/stderr
901 7a30b5cb 2022-03-20 op test_done $testroot $ret
904 7a30b5cb 2022-03-20 op test_patch_prefer_new_path() {
905 7a30b5cb 2022-03-20 op local testroot=`test_init patch_orig`
907 7a30b5cb 2022-03-20 op got checkout $testroot/repo $testroot/wt > /dev/null
909 7a30b5cb 2022-03-20 op if [ $ret -ne 0 ]; then
910 7a30b5cb 2022-03-20 op test_done $testroot $ret
914 7a30b5cb 2022-03-20 op cat <<EOF > $testroot/wt/patch
915 7a30b5cb 2022-03-20 op --- alpha.orig
917 7a30b5cb 2022-03-20 op @@ -1 +1,2 @@
922 7a30b5cb 2022-03-20 op (cd $testroot/wt && got patch patch) > $testroot/stdout
924 7a30b5cb 2022-03-20 op if [ $ret -ne 0 ]; then
925 7a30b5cb 2022-03-20 op test_done $testroot $ret
929 3313bcd8 2022-04-19 op echo 'M alpha' > $testroot/stdout.expected
930 60aa1fa0 2022-03-17 op cmp -s $testroot/stdout.expected $testroot/stdout
932 60aa1fa0 2022-03-17 op if [ $ret -ne 0 ]; then
933 60aa1fa0 2022-03-17 op diff -u $testroot/stdout.expected $testroot/stdout
935 60aa1fa0 2022-03-17 op test_done $testroot $ret
938 b3c57ab2 2022-03-22 op test_patch_no_newline() {
939 b3c57ab2 2022-03-22 op local testroot=`test_init patch_no_newline`
941 b3c57ab2 2022-03-22 op got checkout $testroot/repo $testroot/wt > /dev/null
943 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
944 b3c57ab2 2022-03-22 op test_done $testroot $ret
948 b3c57ab2 2022-03-22 op cat <<EOF > $testroot/wt/patch
949 b3c57ab2 2022-03-22 op --- /dev/null
951 b3c57ab2 2022-03-22 op @@ -0,0 +1 @@
953 b3c57ab2 2022-03-22 op \ No newline at end of file
956 b3c57ab2 2022-03-22 op (cd $testroot/wt && got patch patch) > $testroot/stdout
958 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
959 b3c57ab2 2022-03-22 op test_done $testroot $ret
963 b3c57ab2 2022-03-22 op echo "A eta" > $testroot/stdout.expected
964 b3c57ab2 2022-03-22 op cmp -s $testroot/stdout.expected $testroot/stdout
966 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
967 b3c57ab2 2022-03-22 op diff -u $testroot/stdout.expected $testroot/stdout
968 b3c57ab2 2022-03-22 op test_done $testroot $ret
972 b3c57ab2 2022-03-22 op echo -n eta > $testroot/wt/eta.expected
973 b3c57ab2 2022-03-22 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
975 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
976 b3c57ab2 2022-03-22 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
977 b3c57ab2 2022-03-22 op test_done $testroot $ret
981 b3c57ab2 2022-03-22 op (cd $testroot/wt && got commit -m 'add eta') > /dev/null
983 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
984 b3c57ab2 2022-03-22 op test_done $testroot $ret
988 b3c57ab2 2022-03-22 op cat <<EOF > $testroot/wt/patch
993 b3c57ab2 2022-03-22 op \ No newline at end of file
995 b3c57ab2 2022-03-22 op \ No newline at end of file
998 b3c57ab2 2022-03-22 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1000 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1001 b3c57ab2 2022-03-22 op test_done $testroot $ret
1005 b3c57ab2 2022-03-22 op echo "M eta" > $testroot/stdout.expected
1006 b3c57ab2 2022-03-22 op cmp -s $testroot/stdout.expected $testroot/stdout
1008 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1009 b3c57ab2 2022-03-22 op diff -u $testroot/stdout.expected $testroot/stdout
1010 b3c57ab2 2022-03-22 op test_done $testroot $ret
1014 b3c57ab2 2022-03-22 op echo -n ETA > $testroot/wt/eta.expected
1015 b3c57ab2 2022-03-22 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1017 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1018 b3c57ab2 2022-03-22 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
1019 b3c57ab2 2022-03-22 op test_done $testroot $ret
1023 b3c57ab2 2022-03-22 op (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
1025 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1026 b3c57ab2 2022-03-22 op test_done $testroot $ret
1030 b3c57ab2 2022-03-22 op cat <<EOF > $testroot/wt/patch
1035 b3c57ab2 2022-03-22 op \ No newline at end of file
1039 b3c57ab2 2022-03-22 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1041 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1042 b3c57ab2 2022-03-22 op test_done $testroot $ret
1046 b3c57ab2 2022-03-22 op echo "M eta" > $testroot/stdout.expected
1047 b3c57ab2 2022-03-22 op cmp -s $testroot/stdout.expected $testroot/stdout
1049 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1050 b3c57ab2 2022-03-22 op diff -u $testroot/stdout.expected $testroot/stdout
1051 b3c57ab2 2022-03-22 op test_done $testroot $ret
1055 b3c57ab2 2022-03-22 op echo eta > $testroot/wt/eta.expected
1056 b3c57ab2 2022-03-22 op cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1058 b3c57ab2 2022-03-22 op if [ $ret -ne 0 ]; then
1059 b3c57ab2 2022-03-22 op diff -u $testroot/wt/eta.expected $testroot/wt/eta
1061 b3c57ab2 2022-03-22 op test_done $testroot $ret
1064 9d6cabd5 2022-04-07 op test_patch_strip() {
1065 9d6cabd5 2022-04-07 op local testroot=`test_init patch_strip`
1067 9d6cabd5 2022-04-07 op got checkout $testroot/repo $testroot/wt > /dev/null
1069 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1070 9d6cabd5 2022-04-07 op test_done $testroot $ret
1074 9d6cabd5 2022-04-07 op cat <<EOF > $testroot/wt/patch
1075 9d6cabd5 2022-04-07 op --- foo/bar/alpha.orig
1076 9d6cabd5 2022-04-07 op +++ foo/bar/alpha
1082 9d6cabd5 2022-04-07 op (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
1084 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1085 9d6cabd5 2022-04-07 op test_done $testroot $ret
1089 9d6cabd5 2022-04-07 op echo "M alpha" >> $testroot/stdout.expected
1090 9d6cabd5 2022-04-07 op cmp -s $testroot/stdout.expected $testroot/stdout
1092 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1093 9d6cabd5 2022-04-07 op diff -u $testroot/stdout.expected $testroot/stdout
1094 9d6cabd5 2022-04-07 op test_done $testroot $ret
1098 9d6cabd5 2022-04-07 op (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1100 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1101 9d6cabd5 2022-04-07 op test_done $testroot $ret
1105 9d6cabd5 2022-04-07 op (cd $testroot/wt && got patch -p3 patch) \
1106 9d6cabd5 2022-04-07 op 2> $testroot/stderr
1108 9d6cabd5 2022-04-07 op if [ $ret -eq 0 ]; then
1109 9d6cabd5 2022-04-07 op echo "stripped more components than available!"
1110 9d6cabd5 2022-04-07 op test_done $testroot 1
1114 9d6cabd5 2022-04-07 op cat <<EOF > $testroot/stderr.expected
1115 9d6cabd5 2022-04-07 op got: can't strip 1 path-components from foo/bar/alpha: bad path
1118 9d6cabd5 2022-04-07 op cmp -s $testroot/stderr.expected $testroot/stderr
1120 9d6cabd5 2022-04-07 op if [ $ret -ne 0 ]; then
1121 9d6cabd5 2022-04-07 op diff -u $testroot/stderr.expected $testroot/stderr
1123 9d6cabd5 2022-04-07 op test_done $testroot 0
1126 a92a2042 2022-07-02 op test_patch_whitespace() {
1127 a92a2042 2022-07-02 op local testroot=`test_init patch_whitespace`
1129 a92a2042 2022-07-02 op got checkout $testroot/repo $testroot/wt > /dev/null
1131 a92a2042 2022-07-02 op if [ $ret -ne 0 ]; then
1132 a92a2042 2022-07-02 op test_done $testroot $ret
1136 a92a2042 2022-07-02 op trailing=" "
1138 a92a2042 2022-07-02 op cat <<EOF > $testroot/wt/hello.c
1139 a92a2042 2022-07-02 op #include <stdio.h>
1144 a92a2042 2022-07-02 op /* the trailing whitespace is on purpose */
1145 a92a2042 2022-07-02 op printf("hello, world\n");$trailing
1150 a92a2042 2022-07-02 op (cd $testroot/wt && got add hello.c && got ci -m '+hello.c') \
1153 a92a2042 2022-07-02 op if [ $ret -ne 0 ]; then
1154 a92a2042 2022-07-02 op test_done $testroot $ret
1158 a92a2042 2022-07-02 op # test with a diff with various whitespace corruptions
1159 a92a2042 2022-07-02 op cat <<EOF > $testroot/wt/patch
1162 a92a2042 2022-07-02 op @@ -5,5 +5,5 @@
1164 a92a2042 2022-07-02 op /* the trailing whitespace is on purpose */
1165 a92a2042 2022-07-02 op printf("hello, world\n");
1167 a92a2042 2022-07-02 op + return 5; /* always fails */
1171 a92a2042 2022-07-02 op (cd $testroot/wt && got patch patch) \
1172 a92a2042 2022-07-02 op 2>$testroot/stderr >$testroot/stdout
1174 a92a2042 2022-07-02 op if [ $ret -ne 0 ]; then
1175 a92a2042 2022-07-02 op echo "failed to apply diff" >&2
1176 a92a2042 2022-07-02 op test_done $testroot $ret
1180 a92a2042 2022-07-02 op echo 'M hello.c' > $testroot/stdout.expected
1181 a92a2042 2022-07-02 op echo '@@ -5,5 +5,5 @@ hunk contains mangled whitespace' \
1182 a92a2042 2022-07-02 op >> $testroot/stdout.expected
1183 a92a2042 2022-07-02 op cmp -s $testroot/stdout.expected $testroot/stdout
1185 a92a2042 2022-07-02 op if [ $ret -ne 0 ]; then
1186 a92a2042 2022-07-02 op diff -u $testroot/stdout.expected $testroot/stdout
1187 a92a2042 2022-07-02 op test_done $testroot $ret
1191 a92a2042 2022-07-02 op cat <<EOF > $testroot/wt/hello.c.expected
1192 a92a2042 2022-07-02 op #include <stdio.h>
1197 a92a2042 2022-07-02 op /* the trailing whitespace is on purpose */
1198 a92a2042 2022-07-02 op printf("hello, world\n");$trailing
1199 a92a2042 2022-07-02 op return 5; /* always fails */
1203 a92a2042 2022-07-02 op cmp -s $testroot/wt/hello.c.expected $testroot/wt/hello.c
1205 a92a2042 2022-07-02 op if [ $ret -ne 0 ]; then
1206 a92a2042 2022-07-02 op diff -u $testroot/wt/hello.c.expected $testroot/wt/hello.c
1208 a92a2042 2022-07-02 op test_done $testroot $ret
1211 ed3bff83 2022-04-23 op test_patch_relative_paths() {
1212 f1d6cebb 2022-04-23 op local testroot=`test_init patch_relative_paths`
1214 ed3bff83 2022-04-23 op got checkout $testroot/repo $testroot/wt > /dev/null
1216 ed3bff83 2022-04-23 op if [ $ret -ne 0 ]; then
1217 ed3bff83 2022-04-23 op test_done $testroot $ret
1221 ed3bff83 2022-04-23 op cat <<EOF > $testroot/wt/gamma/patch
1227 ed3bff83 2022-04-23 op --- /dev/null
1229 ed3bff83 2022-04-23 op @@ -0,0 +1 @@
1233 ed3bff83 2022-04-23 op (cd $testroot/wt/gamma && got patch patch) > $testroot/stdout
1235 ed3bff83 2022-04-23 op if [ $ret -ne 0 ]; then
1236 ed3bff83 2022-04-23 op test_done $testroot $ret
1240 ed3bff83 2022-04-23 op echo 'M gamma/delta' > $testroot/stdout.expected
1241 ed3bff83 2022-04-23 op echo 'A gamma/eta' >> $testroot/stdout.expected
1243 15e1bda6 2022-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
1245 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1246 15e1bda6 2022-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
1248 15e1bda6 2022-04-23 op test_done $testroot $ret
1251 15e1bda6 2022-04-23 op test_patch_with_path_prefix() {
1252 15e1bda6 2022-04-23 op local testroot=`test_init patch_with_path_prefix`
1254 15e1bda6 2022-04-23 op got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1256 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1257 15e1bda6 2022-04-23 op test_done $testroot $ret
1261 15e1bda6 2022-04-23 op cat <<EOF > $testroot/wt/patch
1267 15e1bda6 2022-04-23 op --- /dev/null
1269 15e1bda6 2022-04-23 op @@ -0,0 +1 @@
1273 15e1bda6 2022-04-23 op (cd $testroot/wt && got patch patch) > $testroot/stdout
1275 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1276 15e1bda6 2022-04-23 op test_done $testroot $ret
1280 15e1bda6 2022-04-23 op echo 'M delta' > $testroot/stdout.expected
1281 15e1bda6 2022-04-23 op echo 'A eta' >> $testroot/stdout.expected
1283 15e1bda6 2022-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
1285 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1286 15e1bda6 2022-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
1288 15e1bda6 2022-04-23 op test_done $testroot $ret
1291 15e1bda6 2022-04-23 op test_patch_relpath_with_path_prefix() {
1292 15e1bda6 2022-04-23 op local testroot=`test_init patch_relpaths_with_path_prefix`
1294 15e1bda6 2022-04-23 op got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1296 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1297 15e1bda6 2022-04-23 op test_done $testroot $ret
1301 15e1bda6 2022-04-23 op mkdir -p $testroot/wt/epsilon/zeta/
1303 15e1bda6 2022-04-23 op cat <<EOF > $testroot/wt/patch
1304 15e1bda6 2022-04-23 op --- /dev/null
1305 15e1bda6 2022-04-23 op +++ zeta/theta
1306 15e1bda6 2022-04-23 op @@ -0,0 +1 @@
1310 15e1bda6 2022-04-23 op (cd $testroot/wt/epsilon/zeta && got patch -p1 $testroot/wt/patch) \
1311 15e1bda6 2022-04-23 op > $testroot/stdout
1313 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1314 15e1bda6 2022-04-23 op test_done $testroot $ret
1318 15e1bda6 2022-04-23 op echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1320 ed3bff83 2022-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
1322 ed3bff83 2022-04-23 op if [ $ret -ne 0 ]; then
1323 ed3bff83 2022-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
1324 15e1bda6 2022-04-23 op test_done $testroot $ret
1328 15e1bda6 2022-04-23 op echo 'theta' > $testroot/theta.expected
1329 15e1bda6 2022-04-23 op cmp -s $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1331 15e1bda6 2022-04-23 op if [ $ret -ne 0 ]; then
1332 15e1bda6 2022-04-23 op diff -u $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1334 ed3bff83 2022-04-23 op test_done $testroot $ret
1337 bad961bf 2022-04-23 op test_patch_reverse() {
1338 bad961bf 2022-04-23 op local testroot=`test_init patch_reverse`
1340 bad961bf 2022-04-23 op got checkout $testroot/repo $testroot/wt > /dev/null
1342 bad961bf 2022-04-23 op if [ $ret -ne 0 ]; then
1343 bad961bf 2022-04-23 op test_done $testroot $ret
1347 bad961bf 2022-04-23 op cat <<EOF > $testroot/wt/patch
1352 bad961bf 2022-04-23 op \ No newline at end of file
1356 bad961bf 2022-04-23 op (cd $testroot/wt && got patch -R patch) > $testroot/stdout
1358 bad961bf 2022-04-23 op if [ $ret -ne 0 ]; then
1359 bad961bf 2022-04-23 op test_done $testroot $ret
1363 bad961bf 2022-04-23 op echo "M alpha" > $testroot/stdout.expected
1364 bad961bf 2022-04-23 op cmp -s $testroot/stdout.expected $testroot/stdout
1366 bad961bf 2022-04-23 op if [ $ret -ne 0 ]; then
1367 bad961bf 2022-04-23 op diff -u $testroot/stdout.expected $testroot/stdout
1368 bad961bf 2022-04-23 op test_done $testroot $ret
1372 bad961bf 2022-04-23 op echo -n ALPHA > $testroot/wt/alpha.expected
1373 bad961bf 2022-04-23 op cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
1375 bad961bf 2022-04-23 op if [ $ret -ne 0 ]; then
1376 bad961bf 2022-04-23 op diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
1378 55e9459f 2022-06-19 op test_done $testroot $ret
1381 55e9459f 2022-06-19 op test_patch_merge_simple() {
1382 55e9459f 2022-06-19 op local testroot=`test_init patch_merge_simple`
1384 55e9459f 2022-06-19 op got checkout $testroot/repo $testroot/wt > /dev/null
1386 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1387 55e9459f 2022-06-19 op test_done $testroot $ret
1391 2fed5287 2024-04-09 op seq 10 > $testroot/wt/numbers
1392 5dffb1a1 2022-07-02 op chmod +x $testroot/wt/numbers
1393 55e9459f 2022-06-19 op (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1396 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1397 55e9459f 2022-06-19 op test_done $testroot $ret
1401 2fed5287 2024-04-09 op seq 10 | sed 's/4/four/g' > $testroot/wt/numbers
1403 55e9459f 2022-06-19 op (cd $testroot/wt && got diff > $testroot/old.diff \
1404 55e9459f 2022-06-19 op && got revert numbers) >/dev/null
1406 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1407 55e9459f 2022-06-19 op test_done $testroot $ret
1411 2fed5287 2024-04-09 op seq 10 | sed 's/6/six/g' > $testroot/wt/numbers
1412 55e9459f 2022-06-19 op (cd $testroot/wt && got commit -m 'edit numbers') \
1415 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1416 55e9459f 2022-06-19 op test_done $testroot $ret
1420 55e9459f 2022-06-19 op (cd $testroot/wt && got patch $testroot/old.diff) \
1421 9802c41c 2022-06-21 op > $testroot/stdout
1423 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1424 9802c41c 2022-06-21 op test_done $testroot $ret
1428 9802c41c 2022-06-21 op echo 'G numbers' > $testroot/stdout.expected
1429 9802c41c 2022-06-21 op cmp -s $testroot/stdout $testroot/stdout.expected
1431 9802c41c 2022-06-21 op if [ $ret -ne 0 ]; then
1432 9802c41c 2022-06-21 op diff -u $testroot/stdout $testroot/stdout.expected
1433 55e9459f 2022-06-19 op test_done $testroot $ret
1437 2fed5287 2024-04-09 op seq 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1438 55e9459f 2022-06-19 op cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1440 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1441 55e9459f 2022-06-19 op diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1442 5dffb1a1 2022-07-02 op test_done $testroot $ret
1446 5dffb1a1 2022-07-02 op test -x $testroot/wt/numbers
1448 5dffb1a1 2022-07-02 op if [ $ret -ne 0 ]; then
1449 5dffb1a1 2022-07-02 op echo "numbers lost the executable bit" >&2
1451 db0dfdd7 2022-06-27 op test_done $testroot $ret
1454 db0dfdd7 2022-06-27 op test_patch_merge_gitdiff() {
1455 db0dfdd7 2022-06-27 op local testroot=`test_init patch_merge_gitdiff`
1457 2fed5287 2024-04-09 op seq 10 > $testroot/repo/numbers
1458 f73bf5bd 2023-10-01 naddy git -C $testroot/repo add numbers && \
1459 f73bf5bd 2023-10-01 naddy git_commit $testroot/repo -m "nums"
1461 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1462 db0dfdd7 2022-06-27 op test_done $testroot $ret
1466 2fed5287 2024-04-09 op seq 10 | sed 's/4/four/g' > $testroot/repo/numbers
1467 f73bf5bd 2023-10-01 naddy git -C $testroot/repo diff > $testroot/old.diff
1469 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1470 db0dfdd7 2022-06-27 op test_done $testroot $ret
1474 db0dfdd7 2022-06-27 op # restore numbers
1475 2fed5287 2024-04-09 op seq 10 > $testroot/repo/numbers
1477 2fed5287 2024-04-09 op seq 10 | sed 's/6/six/g' > $testroot/repo/numbers
1478 f73bf5bd 2023-10-01 naddy git -C $testroot/repo add numbers && \
1479 f73bf5bd 2023-10-01 naddy git_commit $testroot/repo -m "edit"
1481 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1482 db0dfdd7 2022-06-27 op test_done $testroot $ret
1486 db0dfdd7 2022-06-27 op # now work with got:
1487 db0dfdd7 2022-06-27 op got checkout $testroot/repo $testroot/wt > /dev/null
1489 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1490 db0dfdd7 2022-06-27 op test_done $testroot $ret
1494 db0dfdd7 2022-06-27 op (cd $testroot/wt && got patch $testroot/old.diff) > $testroot/stdout
1496 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1497 db0dfdd7 2022-06-27 op test_done $testroot $ret
1501 db0dfdd7 2022-06-27 op echo 'G numbers' > $testroot/stdout.expected
1502 db0dfdd7 2022-06-27 op cmp -s $testroot/stdout $testroot/stdout.expected
1504 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1505 db0dfdd7 2022-06-27 op diff -u $testroot/stdout $testroot/stdout.expected
1507 55e9459f 2022-06-19 op test_done $testroot $ret
1510 5f56d41e 2022-07-28 op test_patch_merge_base_provided() {
1511 5f56d41e 2022-07-28 op local testroot=`test_init patch_merge_base_provided`
1513 5f56d41e 2022-07-28 op got checkout $testroot/repo $testroot/wt >/dev/null
1515 5f56d41e 2022-07-28 op if [ $ret -ne 0 ]; then
1516 5f56d41e 2022-07-28 op test_done $testroot $ret
1520 2fed5287 2024-04-09 op seq 10 > $testroot/wt/numbers
1521 5f56d41e 2022-07-28 op (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1524 5f56d41e 2022-07-28 op if [ $ret -ne 0 ]; then
1525 5f56d41e 2022-07-28 op test_done $testroot $ret
1529 5f56d41e 2022-07-28 op local commit_id=`git_show_head $testroot/repo`
1531 2fed5287 2024-04-09 op seq 10 | sed s/4/four/ > $testroot/wt/numbers
1533 5f56d41e 2022-07-28 op # get rid of the metadata
1534 5f56d41e 2022-07-28 op (cd $testroot/wt && got diff | sed -n '/^---/,$p' > patch) \
1537 2fed5287 2024-04-09 op seq 10 | sed s/6/six/ > $testroot/wt/numbers
1538 5f56d41e 2022-07-28 op (cd $testroot/wt && got commit -m 'edit numbers') >/dev/null
1540 5f56d41e 2022-07-28 op if [ $ret -ne 0 ]; then
1541 5f56d41e 2022-07-28 op test_done $testroot $ret
1545 5f56d41e 2022-07-28 op (cd $testroot/wt && got patch -c $commit_id patch) >$testroot/stdout
1547 5f56d41e 2022-07-28 op if [ $ret -ne 0 ]; then
1548 5f56d41e 2022-07-28 op test_done $testroot $ret
1552 5f56d41e 2022-07-28 op echo 'G numbers' > $testroot/stdout.expected
1553 5f56d41e 2022-07-28 op cmp -s $testroot/stdout $testroot/stdout.expected
1555 5f56d41e 2022-07-28 op if [ $ret -ne 0 ]; then
1556 5f56d41e 2022-07-28 op diff -u $testroot/stdout $testroot/stdout.expected
1557 5f56d41e 2022-07-28 op test_done $testroot $ret
1561 2fed5287 2024-04-09 op seq 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1562 5f56d41e 2022-07-28 op cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1564 5f56d41e 2022-07-28 op if [ $ret -ne 0 ]; then
1565 5f56d41e 2022-07-28 op diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1567 5f56d41e 2022-07-28 op test_done $testroot $ret
1570 55e9459f 2022-06-19 op test_patch_merge_conflict() {
1571 55e9459f 2022-06-19 op local testroot=`test_init patch_merge_conflict`
1573 55e9459f 2022-06-19 op got checkout $testroot/repo $testroot/wt > /dev/null
1575 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1576 55e9459f 2022-06-19 op test_done $testroot $ret
1580 2fed5287 2024-04-09 op seq 10 > $testroot/wt/numbers
1581 55e9459f 2022-06-19 op (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1584 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1585 55e9459f 2022-06-19 op test_done $testroot $ret
1589 d8b5af43 2022-06-19 op local commit_id=`git_show_head $testroot/repo`
1591 2fed5287 2024-04-09 op seq 10 | sed 's/6/six/g' > $testroot/wt/numbers
1592 acf749fc 2022-07-02 op echo ALPHA > $testroot/wt/alpha
1594 55e9459f 2022-06-19 op (cd $testroot/wt && got diff > $testroot/old.diff \
1595 acf749fc 2022-07-02 op && got revert alpha numbers) >/dev/null
1597 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1598 55e9459f 2022-06-19 op test_done $testroot $ret
1602 2fed5287 2024-04-09 op seq 10 | sed 's/6/3+3/g' > $testroot/wt/numbers
1603 2fed5287 2024-04-09 op printf '%s\n' a b c > $testroot/wt/alpha
1604 acf749fc 2022-07-02 op (cd $testroot/wt && got commit -m 'edit alpha and numbers') \
1607 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1608 55e9459f 2022-06-19 op test_done $testroot $ret
1612 55e9459f 2022-06-19 op (cd $testroot/wt && got patch $testroot/old.diff) \
1613 9802c41c 2022-06-21 op > $testroot/stdout 2>/dev/null
1615 55e9459f 2022-06-19 op if [ $ret -eq 0 ]; then
1616 55e9459f 2022-06-19 op echo "got patch merged a diff that should conflict" >&2
1617 e423877d 2023-05-11 stsp test_done $testroot 1
1621 acf749fc 2022-07-02 op echo 'C alpha' > $testroot/stdout.expected
1622 acf749fc 2022-07-02 op echo 'C numbers' >> $testroot/stdout.expected
1623 bfcdc9e9 2023-05-11 stsp echo 'Files with merge conflicts: 2' >> $testroot/stdout.expected
1624 9802c41c 2022-06-21 op cmp -s $testroot/stdout $testroot/stdout.expected
1626 9802c41c 2022-06-21 op if [ $ret -ne 0 ]; then
1627 9802c41c 2022-06-21 op diff -u $testroot/stdout $testroot/stdout.expected
1628 9802c41c 2022-06-21 op test_done $testroot $ret
1632 55e9459f 2022-06-19 op # XXX: prefixing every line with a tab otherwise got thinks
1633 55e9459f 2022-06-19 op # the file has conflicts in it.
1634 acf749fc 2022-07-02 op cat <<-EOF > $testroot/wt/alpha.expected
1635 acf749fc 2022-07-02 op <<<<<<< --- alpha
1637 acf749fc 2022-07-02 op ||||||| commit $commit_id
1643 acf749fc 2022-07-02 op >>>>>>> +++ alpha
1646 55e9459f 2022-06-19 op cat <<-EOF > $testroot/wt/numbers.expected
1652 55e9459f 2022-06-19 op <<<<<<< --- numbers
1654 d8b5af43 2022-06-19 op ||||||| commit $commit_id
1658 55e9459f 2022-06-19 op >>>>>>> +++ numbers
1665 acf749fc 2022-07-02 op cmp -s $testroot/wt/alpha $testroot/wt/alpha.expected
1667 acf749fc 2022-07-02 op if [ $ret -ne 0 ]; then
1668 acf749fc 2022-07-02 op diff -u $testroot/wt/alpha $testroot/wt/alpha.expected
1669 acf749fc 2022-07-02 op test_done $testroot $ret
1673 55e9459f 2022-06-19 op cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1675 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1676 55e9459f 2022-06-19 op diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1678 bad961bf 2022-04-23 op test_done $testroot $ret
1681 55e9459f 2022-06-19 op test_patch_merge_unknown_blob() {
1682 55e9459f 2022-06-19 op local testroot=`test_init patch_merge_unknown_blob`
1684 55e9459f 2022-06-19 op got checkout $testroot/repo $testroot/wt > /dev/null
1686 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1687 55e9459f 2022-06-19 op test_done $testroot $ret
1691 55e9459f 2022-06-19 op cat <<EOF > $testroot/wt/patch
1693 dbc68eed 2022-06-21 op diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
1695 55e9459f 2022-06-19 op blob - aaaabbbbccccddddeeeeffff0000111122223333
1697 dbc68eed 2022-06-21 op blob + 0000111122223333444455556666777788889999
1698 55e9459f 2022-06-19 op for this dummy diff
1704 55e9459f 2022-06-19 op will it work?
1707 55e9459f 2022-06-19 op (cd $testroot/wt/ && got patch patch) > $testroot/stdout
1709 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1710 55e9459f 2022-06-19 op test_done $testroot $ret
1714 55e9459f 2022-06-19 op echo 'M alpha' > $testroot/stdout.expected
1715 55e9459f 2022-06-19 op cmp -s $testroot/stdout.expected $testroot/stdout
1717 55e9459f 2022-06-19 op if [ $ret -ne 0 ]; then
1718 55e9459f 2022-06-19 op diff -u $testroot/stdout.expected $testroot/stdout
1719 dbc68eed 2022-06-21 op test_done $testroot $ret
1723 dbc68eed 2022-06-21 op # try again without a `diff' header
1725 dbc68eed 2022-06-21 op cat <<EOF > $testroot/wt/patch
1727 dbc68eed 2022-06-21 op blob - aaaabbbbccccddddeeeeffff0000111122223333
1729 dbc68eed 2022-06-21 op blob + 0000111122223333444455556666777788889999
1730 dbc68eed 2022-06-21 op for this dummy diff
1736 dbc68eed 2022-06-21 op will it work?
1739 dbc68eed 2022-06-21 op (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1740 dbc68eed 2022-06-21 op > $testroot/stdout
1742 dbc68eed 2022-06-21 op if [ $ret -ne 0 ]; then
1743 dbc68eed 2022-06-21 op test_done $testroot $ret
1747 dbc68eed 2022-06-21 op echo 'M alpha' > $testroot/stdout.expected
1748 dbc68eed 2022-06-21 op cmp -s $testroot/stdout.expected $testroot/stdout
1750 dbc68eed 2022-06-21 op if [ $ret -ne 0 ]; then
1751 dbc68eed 2022-06-21 op diff -u $testroot/stdout.expected $testroot/stdout
1752 db0dfdd7 2022-06-27 op test_done $testroot $ret
1756 db0dfdd7 2022-06-27 op # try again with a git-style diff
1758 db0dfdd7 2022-06-27 op cat <<EOF > $testroot/wt/patch
1759 db0dfdd7 2022-06-27 op diff --git a/alpha b/alpha
1760 db0dfdd7 2022-06-27 op index 0123456789ab..abcdef012345 100644
1768 db0dfdd7 2022-06-27 op (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1769 db0dfdd7 2022-06-27 op > $testroot/stdout
1771 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1772 db0dfdd7 2022-06-27 op test_done $testroot $ret
1776 db0dfdd7 2022-06-27 op echo 'M alpha' > $testroot/stdout.expected
1777 db0dfdd7 2022-06-27 op cmp -s $testroot/stdout.expected $testroot/stdout
1779 db0dfdd7 2022-06-27 op if [ $ret -ne 0 ]; then
1780 db0dfdd7 2022-06-27 op diff -u $testroot/stdout.expected $testroot/stdout
1782 55e9459f 2022-06-19 op test_done $testroot $ret
1785 38d61ead 2022-07-23 op test_patch_merge_reverse() {
1786 38d61ead 2022-07-23 op local testroot=`test_init patch_merge_simple`
1788 38d61ead 2022-07-23 op got checkout $testroot/repo $testroot/wt > /dev/null
1790 38d61ead 2022-07-23 op if [ $ret -ne 0 ]; then
1791 38d61ead 2022-07-23 op test_done $testroot $ret
1795 2fed5287 2024-04-09 op seq 10 > $testroot/wt/numbers
1796 38d61ead 2022-07-23 op (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1799 38d61ead 2022-07-23 op if [ $ret -ne 0 ]; then
1800 38d61ead 2022-07-23 op test_done $testroot $ret
1804 38d61ead 2022-07-23 op local commit_id=`git_show_head $testroot/repo`
1806 2fed5287 2024-04-09 op seq 10 | sed s/5/five/g > $testroot/wt/numbers
1807 38d61ead 2022-07-23 op (cd $testroot/wt && got diff > $testroot/wt/patch \
1808 38d61ead 2022-07-23 op && got commit -m 'edit numbers') > /dev/null
1810 38d61ead 2022-07-23 op if [ $ret -ne 0 ]; then
1811 38d61ead 2022-07-23 op test_done $testroot $ret
1815 2fed5287 2024-04-09 op seq 10 | sed -e s/5/five/g -e s/6/six/g > $testroot/wt/numbers
1816 38d61ead 2022-07-23 op (cd $testroot/wt && got commit -m 'edit numbers again') >/dev/null
1818 38d61ead 2022-07-23 op if [ $ret -ne 0 ]; then
1819 38d61ead 2022-07-23 op test_done $testroot $ret
1823 38d61ead 2022-07-23 op (cd $testroot/wt && got patch -R patch) >/dev/null 2>&1
1825 38d61ead 2022-07-23 op if [ $ret -eq 0 ]; then
1826 38d61ead 2022-07-23 op echo "unexpectedly reverted the patch" >&2
1827 38d61ead 2022-07-23 op test_done $testroot 1
1831 38d61ead 2022-07-23 op cat <<-EOF > $testroot/wt/numbers.expected
1836 38d61ead 2022-07-23 op <<<<<<< --- numbers
1839 38d61ead 2022-07-23 op ||||||| +++ numbers
1844 38d61ead 2022-07-23 op >>>>>>> commit $commit_id
1851 38d61ead 2022-07-23 op cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1853 38d61ead 2022-07-23 op if [ $ret -ne 0 ]; then
1854 38d61ead 2022-07-23 op diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1856 611e5fc2 2022-09-21 mark test_done $testroot $ret
1859 611e5fc2 2022-09-21 mark test_patch_newfile_xbit_got_diff() {
1860 611e5fc2 2022-09-21 mark local testroot=`test_init patch_newfile_xbit`
1862 611e5fc2 2022-09-21 mark got checkout $testroot/repo $testroot/wt > /dev/null
1864 611e5fc2 2022-09-21 mark if [ $ret -ne 0 ]; then
1865 611e5fc2 2022-09-21 mark test_done $testroot $ret
1869 611e5fc2 2022-09-21 mark cat <<EOF > $testroot/wt/patch
1870 611e5fc2 2022-09-21 mark blob - /dev/null
1871 611e5fc2 2022-09-21 mark blob + abcdef0123456789abcdef012345678901234567 (mode 755)
1872 611e5fc2 2022-09-21 mark --- /dev/null
1874 611e5fc2 2022-09-21 mark @@ -0,0 +1,1 @@
1878 611e5fc2 2022-09-21 mark (cd $testroot/wt && got patch patch) > /dev/null
1880 611e5fc2 2022-09-21 mark if [ $ret -ne 0 ]; then
1881 611e5fc2 2022-09-21 mark test_done $testroot $ret
1885 611e5fc2 2022-09-21 mark if [ ! -x $testroot/wt/xfile ]; then
1886 611e5fc2 2022-09-21 mark echo "failed to set xbit on newfile" >&2
1887 611e5fc2 2022-09-21 mark test_done $testroot 1
1891 611e5fc2 2022-09-21 mark echo xfile > $testroot/wt/xfile.expected
1892 611e5fc2 2022-09-21 mark cmp -s $testroot/wt/xfile $testroot/wt/xfile.expected
1894 611e5fc2 2022-09-21 mark if [ $ret -ne 0 ]; then
1895 611e5fc2 2022-09-21 mark echo "fail"
1896 611e5fc2 2022-09-21 mark diff -u $testroot/wt/xfile $testroot/wt/xfile.expected
1899 38d61ead 2022-07-23 op test_done $testroot $ret
1902 611e5fc2 2022-09-21 mark test_patch_newfile_xbit_git_diff() {
1903 611e5fc2 2022-09-21 mark local testroot=`test_init patch_newfile_xbit`
1905 611e5fc2 2022-09-21 mark got checkout $testroot/repo $testroot/wt > /dev/null
1907 611e5fc2 2022-09-21 mark if [ $ret -ne 0 ]; then
1908 611e5fc2 2022-09-21 mark test_done $testroot $ret
1912 611e5fc2 2022-09-21 mark cat <<EOF > $testroot/wt/patch
1913 611e5fc2 2022-09-21 mark diff --git a/xfile b/xfile
1914 611e5fc2 2022-09-21 mark new file mode 100755
1915 611e5fc2 2022-09-21 mark index 00000000..abcdef01
1916 611e5fc2 2022-09-21 mark --- /dev/null
1917 611e5fc2 2022-09-21 mark +++ b/xfile
1918 611e5fc2 2022-09-21 mark @@ -0,0 +1,1 @@
1922 611e5fc2 2022-09-21 mark (cd $testroot/wt && got patch patch) > /dev/null
1924 611e5fc2 2022-09-21 mark if [ $ret -ne 0 ]; then
1925 611e5fc2 2022-09-21 mark test_done $testroot $ret
1929 611e5fc2 2022-09-21 mark if [ ! -x $testroot/wt/xfile ]; then
1930 611e5fc2 2022-09-21 mark echo "failed to set xbit on newfile" >&2
1931 611e5fc2 2022-09-21 mark test_done $testroot 1
1935 611e5fc2 2022-09-21 mark echo xfile > $testroot/wt/xfile.expected
1936 611e5fc2 2022-09-21 mark cmp -s $testroot/wt/xfile $testroot/wt/xfile.expected
1938 611e5fc2 2022-09-21 mark if [ $ret -ne 0 ]; then
1939 611e5fc2 2022-09-21 mark echo "fail"
1940 611e5fc2 2022-09-21 mark diff -u $testroot/wt/xfile $testroot/wt/xfile.expected
1943 611e5fc2 2022-09-21 mark test_done $testroot $ret
1946 b2b3fce1 2022-10-29 op test_patch_umask() {
1947 b2b3fce1 2022-10-29 op local testroot=`test_init patch_umask`
1949 b2b3fce1 2022-10-29 op got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1951 b2b3fce1 2022-10-29 op cat <<EOF >$testroot/wt/patch
1956 b2b3fce1 2022-10-29 op +modified alpha
1959 b2b3fce1 2022-10-29 op # using a subshell to avoid clobbering global umask
1960 b2b3fce1 2022-10-29 op (umask 077 && cd "$testroot/wt" && got patch <patch) >/dev/null
1962 b2b3fce1 2022-10-29 op if [ $ret -ne 0 ]; then
1963 b2b3fce1 2022-10-29 op test_done "$testroot" $ret
1967 b2b3fce1 2022-10-29 op if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1968 b2b3fce1 2022-10-29 op echo "alpha is not 0600 after patch" >&2
1969 b2b3fce1 2022-10-29 op ls -l "$testroot/wt/alpha" >&2
1970 b2b3fce1 2022-10-29 op test_done "$testroot" 1
1974 b2b3fce1 2022-10-29 op test_done "$testroot" 0
1977 684a9a6c 2022-12-31 op test_patch_remove_binary_file() {
1978 684a9a6c 2022-12-31 op local testroot=`test_init patch_remove_binary_file`
1980 684a9a6c 2022-12-31 op if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
1981 684a9a6c 2022-12-31 op test_done $testroot $ret
1985 684a9a6c 2022-12-31 op dd if=/dev/zero of=$testroot/wt/x bs=1 count=16 2>/dev/null >&2
1986 684a9a6c 2022-12-31 op (cd $testroot/wt && got add x && got commit -m +x) >/dev/null
1988 684a9a6c 2022-12-31 op (cd $testroot/wt && \
1989 684a9a6c 2022-12-31 op got branch demo && \
1990 684a9a6c 2022-12-31 op got rm x && \
1991 684a9a6c 2022-12-31 op got ci -m -x &&
1992 684a9a6c 2022-12-31 op got up -b master) >/dev/null
1994 684a9a6c 2022-12-31 op echo 'D x' > $testroot/stdout.expected
1996 684a9a6c 2022-12-31 op (cd $testroot/wt && got log -c demo -l 1 -p >patch)
1998 684a9a6c 2022-12-31 op (cd $testroot/wt && got patch <patch) > $testroot/stdout
1999 684a9a6c 2022-12-31 op if [ $? -ne 0 ]; then
2000 684a9a6c 2022-12-31 op echo 'patch failed' >&2
2001 684a9a6c 2022-12-31 op test_done $testroot 1
2005 684a9a6c 2022-12-31 op if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2006 684a9a6c 2022-12-31 op diff -u $testroot/stdout.expected $testroot/stdout
2007 684a9a6c 2022-12-31 op test_done $testroot 1
2011 684a9a6c 2022-12-31 op # try again using a git produced diff
2012 684a9a6c 2022-12-31 op (cd $testroot/wt && got revert x) >/dev/null
2014 f73bf5bd 2023-10-01 naddy git -C $testroot/repo show demo >$testroot/wt/patch
2016 684a9a6c 2022-12-31 op (cd $testroot/wt && got patch <patch) > $testroot/stdout
2017 684a9a6c 2022-12-31 op if [ $? -ne 0 ]; then
2018 684a9a6c 2022-12-31 op echo 'patch failed' >&2
2019 684a9a6c 2022-12-31 op test_done $testroot 1
2023 684a9a6c 2022-12-31 op if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2024 684a9a6c 2022-12-31 op diff -u $testroot/stdout.expected $testroot/stdout
2025 684a9a6c 2022-12-31 op test_done $testroot 1
2029 684a9a6c 2022-12-31 op # try again using a diff(1) style patch
2030 684a9a6c 2022-12-31 op (cd $testroot/wt && got revert x) >/dev/null
2032 684a9a6c 2022-12-31 op echo "Binary files x and /dev/null differ" >$testroot/wt/patch
2033 684a9a6c 2022-12-31 op (cd $testroot/wt && got patch <patch) >$testroot/stdout
2034 684a9a6c 2022-12-31 op if [ $? -ne 0 ]; then
2035 684a9a6c 2022-12-31 op echo 'patch failed' >&2
2036 684a9a6c 2022-12-31 op test_done $testroot 1
2040 684a9a6c 2022-12-31 op if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2041 684a9a6c 2022-12-31 op diff -u $testroot/stdout.expected $testroot/stdout
2042 684a9a6c 2022-12-31 op test_done $testroot 1
2046 684a9a6c 2022-12-31 op test_done $testroot 0
2049 c8d1a97c 2023-07-17 mark test_patch_commit_keywords() {
2050 c8d1a97c 2023-07-17 mark local testroot=`test_init patch_commit_keywords`
2052 c8d1a97c 2023-07-17 mark got checkout $testroot/repo $testroot/wt >/dev/null
2054 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2055 c8d1a97c 2023-07-17 mark test_done $testroot $ret
2059 2fed5287 2024-04-09 op seq 10 > $testroot/wt/numbers
2060 c8d1a97c 2023-07-17 mark (cd $testroot/wt && got add numbers && got commit -m +numbers) \
2061 c8d1a97c 2023-07-17 mark >/dev/null
2063 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2064 c8d1a97c 2023-07-17 mark test_done $testroot $ret
2068 2fed5287 2024-04-09 op seq 10 | sed s/4/four/ > $testroot/wt/numbers
2070 c8d1a97c 2023-07-17 mark # get rid of the metadata
2071 c8d1a97c 2023-07-17 mark (cd $testroot/wt && got diff | sed -n '/^---/,$p' > patch) \
2072 c8d1a97c 2023-07-17 mark >/dev/null
2074 2fed5287 2024-04-09 op seq 10 | sed s/6/six/ > $testroot/wt/numbers
2075 c8d1a97c 2023-07-17 mark (cd $testroot/wt && got commit -m 'edit numbers') >/dev/null
2077 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2078 c8d1a97c 2023-07-17 mark test_done $testroot $ret
2082 c8d1a97c 2023-07-17 mark (cd $testroot/wt && got patch -c :head:- patch) >$testroot/stdout
2084 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2085 c8d1a97c 2023-07-17 mark test_done $testroot $ret
2089 c8d1a97c 2023-07-17 mark echo 'G numbers' > $testroot/stdout.expected
2090 c8d1a97c 2023-07-17 mark cmp -s $testroot/stdout $testroot/stdout.expected
2092 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2093 c8d1a97c 2023-07-17 mark diff -u $testroot/stdout $testroot/stdout.expected
2094 c8d1a97c 2023-07-17 mark test_done $testroot $ret
2098 2fed5287 2024-04-09 op seq 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
2099 c8d1a97c 2023-07-17 mark cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
2101 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2102 c8d1a97c 2023-07-17 mark diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
2105 c8d1a97c 2023-07-17 mark (cd "$testroot/wt" && got rv numbers > /dev/null)
2107 c8d1a97c 2023-07-17 mark (cd $testroot/wt && got patch -c :base:- patch) >$testroot/stdout
2109 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2110 c8d1a97c 2023-07-17 mark test_done $testroot $ret
2114 c8d1a97c 2023-07-17 mark echo 'G numbers' > $testroot/stdout.expected
2115 c8d1a97c 2023-07-17 mark cmp -s $testroot/stdout $testroot/stdout.expected
2117 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2118 c8d1a97c 2023-07-17 mark diff -u $testroot/stdout $testroot/stdout.expected
2119 c8d1a97c 2023-07-17 mark test_done $testroot $ret
2123 2fed5287 2024-04-09 op seq 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
2124 c8d1a97c 2023-07-17 mark cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
2126 c8d1a97c 2023-07-17 mark if [ $ret -ne 0 ]; then
2127 c8d1a97c 2023-07-17 mark diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
2130 c8d1a97c 2023-07-17 mark test_done $testroot $ret
2133 e9ce266e 2022-03-07 op test_parseargs "$@"
2134 57b1c3f2 2022-08-01 op run_test test_patch_basic
2135 e9ce266e 2022-03-07 op run_test test_patch_dont_apply
2136 e9ce266e 2022-03-07 op run_test test_patch_malformed
2137 e9ce266e 2022-03-07 op run_test test_patch_no_patch
2138 e9ce266e 2022-03-07 op run_test test_patch_equals_for_context
2139 6e96b326 2022-03-12 op run_test test_patch_rename
2140 dbda770b 2022-03-13 op run_test test_patch_illegal_status
2141 899fcfdf 2022-03-13 op run_test test_patch_nop
2142 2be5e1a2 2022-03-16 op run_test test_patch_preserve_perm
2143 95d68340 2022-03-16 op run_test test_patch_create_dirs
2144 60aa1fa0 2022-03-17 op run_test test_patch_with_offset
2145 04a87797 2024-04-23 op run_test test_patch_empty_file
2146 7a30b5cb 2022-03-20 op run_test test_patch_prefer_new_path
2147 b3c57ab2 2022-03-22 op run_test test_patch_no_newline
2148 9d6cabd5 2022-04-07 op run_test test_patch_strip
2149 a92a2042 2022-07-02 op run_test test_patch_whitespace
2150 ed3bff83 2022-04-23 op run_test test_patch_relative_paths
2151 15e1bda6 2022-04-23 op run_test test_patch_with_path_prefix
2152 15e1bda6 2022-04-23 op run_test test_patch_relpath_with_path_prefix
2153 bad961bf 2022-04-23 op run_test test_patch_reverse
2154 55e9459f 2022-06-19 op run_test test_patch_merge_simple
2155 db0dfdd7 2022-06-27 op run_test test_patch_merge_gitdiff
2156 5f56d41e 2022-07-28 op run_test test_patch_merge_base_provided
2157 55e9459f 2022-06-19 op run_test test_patch_merge_conflict
2158 55e9459f 2022-06-19 op run_test test_patch_merge_unknown_blob
2159 38d61ead 2022-07-23 op run_test test_patch_merge_reverse
2160 611e5fc2 2022-09-21 mark run_test test_patch_newfile_xbit_got_diff
2161 611e5fc2 2022-09-21 mark run_test test_patch_newfile_xbit_git_diff
2162 b2b3fce1 2022-10-29 op run_test test_patch_umask
2163 684a9a6c 2022-12-31 op run_test test_patch_remove_binary_file
2164 c8d1a97c 2023-07-17 mark run_test test_patch_commit_keywords