Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_patch_add_file() {
20 local testroot=`test_init patch_add_file`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done $testroot $ret
26 return 1
27 fi
29 cat <<EOF > $testroot/wt/patch
30 --- /dev/null
31 +++ eta
32 @@ -0,0 +5,5 @@
33 +1
34 +2
35 +3
36 +4
37 +5
38 EOF
40 (cd $testroot/wt && got patch patch) > $testroot/stdout
41 ret=$?
42 if [ $ret -ne 0 ]; then
43 test_done $testroot $ret
44 return 1
45 fi
47 echo "A eta" > $testroot/stdout.expected
48 cmp -s $testroot/stdout.expected $testroot/stdout
49 ret=$?
50 if [ $ret -ne 0 ]; then
51 diff -u $testroot/stdout.expected $testroot/stdout
52 test_done $testroot $ret
53 return 1
54 fi
56 jot 5 > $testroot/wt/eta.expected
57 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
58 ret=$?
59 if [ $ret -ne 0 ]; then
60 diff -u $testroot/wt/eta.expected $testroot/wt/eta
61 fi
62 test_done $testroot $ret
63 }
65 test_patch_rm_file() {
66 local testroot=`test_init patch_rm_file`
68 got checkout $testroot/repo $testroot/wt > /dev/null
69 ret=$?
70 if [ $ret -ne 0 ]; then
71 test_done $testroot $ret
72 return 1
73 fi
75 cat <<EOF > $testroot/wt/patch
76 --- alpha
77 +++ /dev/null
78 @@ -1 +0,0 @@
79 -alpha
80 EOF
82 echo "D alpha" > $testroot/stdout.expected
84 (cd $testroot/wt && got patch patch) > $testroot/stdout
85 ret=$?
86 if [ $ret -ne 0 ]; then
87 test_done $testroot $ret
88 return 1
89 fi
91 cmp -s $testroot/stdout.expected $testroot/stdout
92 ret=$?
93 if [ $ret -ne 0 ]; then
94 diff -u $testroot/stdout.expected $testroot/stdout
95 test_done $testroot $ret
96 return 1
97 fi
99 if [ -f $testroot/wt/alpha ]; then
100 ret=1
101 echo "alpha still exists!"
102 fi
103 test_done $testroot $ret
106 test_patch_simple_edit_file() {
107 local testroot=`test_init patch_simple_edit_file`
109 got checkout $testroot/repo $testroot/wt > /dev/null
110 ret=$?
111 if [ $ret -ne 0 ]; then
112 test_done $testroot $ret
113 return 1
114 fi
116 cat <<EOF > $testroot/wt/patch
117 --- alpha
118 +++ alpha
119 @@ -1 +1 @@
120 -alpha
121 +alpha is my favourite character
122 EOF
124 echo "M alpha" > $testroot/stdout.expected
126 (cd $testroot/wt && got patch patch) > $testroot/stdout
127 ret=$?
128 if [ $ret -ne 0 ]; then
129 test_done $testroot $ret
130 return 1
131 fi
133 cmp -s $testroot/stdout.expected $testroot/stdout
134 ret=$?
135 if [ $ret -ne 0 ]; then
136 diff -u $testroot/stdout.expected $testroot/stdout
137 test_done $testroot $ret
138 return 1
139 fi
141 echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
142 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
143 ret=$?
144 if [ $ret -ne 0 ]; then
145 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
146 fi
147 test_done $testroot $ret
150 test_patch_prepend_line() {
151 local testroot=`test_init patch_prepend_line`
153 got checkout $testroot/repo $testroot/wt > /dev/null
154 ret=$?
155 if [ $ret -ne 0 ]; then
156 test_done $testroot $ret
157 return 1
158 fi
160 cat <<EOF > $testroot/wt/patch
161 --- alpha
162 +++ alpha
163 @@ -1 +1,2 @@
164 +hatsuseno
165 alpha
166 EOF
168 echo "M alpha" > $testroot/stdout.expected
170 (cd $testroot/wt && got patch patch) > $testroot/stdout
171 ret=$?
172 if [ $ret -ne 0 ]; then
173 test_done $testroot $ret
174 return 1
175 fi
177 cmp -s $testroot/stdout.expected $testroot/stdout
178 ret=$?
179 if [ $ret -ne 0 ]; then
180 diff -u $testroot/stdout.expected $testroot/stdout
181 test_done $testroot $ret
182 return 1
183 fi
185 echo hatsuseno > $testroot/wt/alpha.expected
186 echo alpha >> $testroot/wt/alpha.expected
187 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
188 ret=$?
189 if [ $ret -ne 0 ]; then
190 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
191 fi
192 test_done $testroot $ret
195 test_patch_replace_line() {
196 local testroot=`test_init patch_replace_line`
198 got checkout $testroot/repo $testroot/wt > /dev/null
199 ret=$?
200 if [ $ret -ne 0 ]; then
201 test_done $testroot $ret
202 return 1
203 fi
205 jot 10 > $testroot/wt/numbers
206 (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
207 >/dev/null
208 ret=$?
209 if [ $ret -ne 0 ]; then
210 test_done $testroot $ret
211 return 1
212 fi
214 cat <<EOF > $testroot/wt/patch
215 --- numbers
216 +++ numbers
217 @@ -3,7 +3,7 @@
221 -6
222 +foo
226 EOF
228 echo "M numbers" > $testroot/stdout.expected
230 (cd $testroot/wt && got patch patch) > $testroot/stdout
231 ret=$?
232 if [ $ret -ne 0 ]; then
233 test_done $testroot $ret
234 return 1
235 fi
237 cmp -s $testroot/stdout.expected $testroot/stdout
238 ret=$?
239 if [ $ret -ne 0 ]; then
240 diff -u $testroot/stdout.expected $testroot/stdout
241 test_done $testroot $ret
242 return 1
243 fi
245 jot 10 | sed 's/6/foo/' > $testroot/wt/numbers.expected
246 cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
247 ret=$?
248 if [ $ret -ne 0 ]; then
249 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
250 fi
251 test_done $testroot $ret
254 test_patch_multiple_hunks() {
255 local testroot=`test_init patch_replace_multiple_hunks`
257 got checkout $testroot/repo $testroot/wt > /dev/null
258 ret=$?
259 if [ $ret -ne 0 ]; then
260 test_done $testroot $ret
261 return 1
262 fi
264 jot 100 > $testroot/wt/numbers
265 (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
266 >/dev/null
267 ret=$?
268 if [ $ret -ne 0 ]; then
269 test_done $testroot $ret
270 return 1
271 fi
273 cat <<EOF > $testroot/wt/patch
274 --- numbers
275 +++ numbers
276 @@ -3,7 +3,7 @@
280 -6
281 +foo
285 @@ -57,7 +57,7 @@
286 57
287 58
288 59
289 -60
290 +foo foo
291 61
292 62
293 63
294 @@ -98,3 +98,6 @@
295 98
296 99
297 100
298 +101
299 +102
300 +...
301 EOF
303 echo "M numbers" > $testroot/stdout.expected
305 (cd $testroot/wt && got patch patch) > $testroot/stdout
306 ret=$?
307 if [ $ret -ne 0 ]; then
308 test_done $testroot $ret
309 return 1
310 fi
312 cmp -s $testroot/stdout.expected $testroot/stdout
313 ret=$?
314 if [ $ret -ne 0 ]; then
315 diff -u $testroot/stdout.expected $testroot/stdout
316 test_done $testroot $ret
317 return 1
318 fi
320 jot 100 | sed -e 's/^6$/foo/' -e 's/^60$/foo foo/' \
321 > $testroot/wt/numbers.expected
322 echo "101" >> $testroot/wt/numbers.expected
323 echo "102" >> $testroot/wt/numbers.expected
324 echo "..." >> $testroot/wt/numbers.expected
326 cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
327 ret=$?
328 if [ $ret -ne 0 ]; then
329 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
330 fi
331 test_done $testroot $ret
334 test_patch_multiple_files() {
335 local testroot=`test_init patch_multiple_files`
337 got checkout $testroot/repo $testroot/wt > /dev/null
338 ret=$?
339 if [ $ret -ne 0 ]; then
340 test_done $testroot $ret
341 return 1
342 fi
344 cat <<EOF > $testroot/wt/patch
345 --- alpha Mon Mar 7 19:02:07 2022
346 +++ alpha Mon Mar 7 19:01:53 2022
347 @@ -1 +1,3 @@
348 +new
349 alpha
350 +available
351 --- beta Mon Mar 7 19:02:11 2022
352 +++ beta Mon Mar 7 19:01:46 2022
353 @@ -1 +1,3 @@
354 beta
355 +was
356 +improved
357 --- gamma/delta Mon Mar 7 19:02:17 2022
358 +++ gamma/delta Mon Mar 7 19:01:37 2022
359 @@ -1 +1 @@
360 -delta
361 +delta new
362 EOF
364 echo "M alpha" > $testroot/stdout.expected
365 echo "M beta" >> $testroot/stdout.expected
366 echo "M gamma/delta" >> $testroot/stdout.expected
368 (cd $testroot/wt && got patch patch) > $testroot/stdout
369 ret=$?
370 if [ $ret -ne 0 ]; then
371 test_done $testroot $ret
372 return 1
373 fi
375 cmp -s $testroot/stdout.expected $testroot/stdout
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 test_done $testroot $ret
380 return 1
381 fi
383 printf 'new\nalpha\navailable\n' > $testroot/wt/alpha.expected
384 printf 'beta\nwas\nimproved\n' > $testroot/wt/beta.expected
385 printf 'delta new\n' > $testroot/wt/gamma/delta.expected
387 for f in alpha beta gamma/delta; do
388 cmp -s $testroot/wt/$f.expected $testroot/wt/$f
389 ret=$?
390 if [ $ret -ne 0 ]; then
391 diff -u $testroot/wt/$f.expected $testroot/wt/$f
392 test_done $testroot $ret
393 return 1
394 fi
395 done
397 test_done $testroot 0
400 test_patch_dont_apply() {
401 local testroot=`test_init patch_dont_apply`
403 got checkout $testroot/repo $testroot/wt > /dev/null
404 ret=$?
405 if [ $ret -ne 0 ]; then
406 test_done $testroot $ret
407 return 1
408 fi
410 jot 100 > $testroot/wt/numbers
411 (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
412 >/dev/null
413 ret=$?
414 if [ $ret -ne 0 ]; then
415 test_done $testroot $ret
416 return 1
417 fi
419 cat <<EOF > $testroot/wt/patch
420 --- alpha
421 +++ alpha
422 @@ -1 +1,2 @@
423 +hatsuseno
424 alpha something
425 --- numbers
426 +++ /dev/null
427 @@ -1,9 +0,0 @@
428 -1
429 -2
430 -3
431 -4
432 -5
433 -6
434 -7
435 -8
436 -9
437 EOF
439 (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
440 ret=$?
441 if [ $ret -eq 0 ]; then # should fail
442 test_done $testroot 1
443 return 1
444 fi
446 cat <<EOF > $testroot/stdout.expected
447 # alpha
448 @@ -1,1 +1,2 @@ hunk failed to apply
449 # numbers
450 @@ -1,9 +0,0 @@ hunk failed to apply
451 EOF
453 cmp -s $testroot/stdout.expected $testroot/stdout
454 ret=$?
455 if [ $ret -ne 0 ]; then
456 diff -u $testroot/stdout.expected $testroot/stdout
457 fi
458 test_done $testroot $ret
461 test_patch_malformed() {
462 local testroot=`test_init patch_malformed`
464 got checkout $testroot/repo $testroot/wt > /dev/null
465 ret=$?
466 if [ $ret -ne 0 ]; then
467 test_done $testroot $ret
468 return 1
469 fi
471 # missing "@@"
472 cat <<EOF > $testroot/wt/patch
473 --- alpha
474 +++ alpha
475 @@ -1 +1,2
476 +hatsuseno
477 alpha
478 EOF
480 echo -n > $testroot/stdout.expected
481 echo "got: malformed patch" > $testroot/stderr.expected
483 (cd $testroot/wt && got patch patch) \
484 > $testroot/stdout \
485 2> $testroot/stderr
486 ret=$?
487 if [ $ret -eq 0 ]; then
488 echo "got managed to apply an invalid patch"
489 test_done $testroot 1
490 return 1
491 fi
493 cmp -s $testroot/stdout.expected $testroot/stdout
494 ret=$?
495 if [ $ret -ne 0 ]; then
496 diff -u $testroot/stdout.expected $testroot/stdout
497 test_done $testroot $ret
498 return 1
499 fi
501 cmp -s $testroot/stderr.expected $testroot/stderr
502 ret=$?
503 if [ $ret -ne 0 ]; then
504 diff -u $testroot/stderr.expected $testroot/stderr
505 test_done $testroot $ret
506 return 1
507 fi
509 # wrong first character
510 cat <<EOF > $testroot/wt/patch
511 --- alpha
512 +++ alpha
513 @@ -1 +1,2 @@
514 +hatsuseno
515 alpha
516 EOF
518 (cd $testroot/wt && got patch patch) \
519 > $testroot/stdout \
520 2> $testroot/stderr
521 ret=$?
522 if [ $ret -eq 0 ]; then
523 echo "got managed to apply an invalid patch"
524 test_done $testroot 1
525 return 1
526 fi
528 cmp -s $testroot/stdout.expected $testroot/stdout
529 ret=$?
530 if [ $ret -ne 0 ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done $testroot $ret
533 return 1
534 fi
536 cmp -s $testroot/stderr.expected $testroot/stderr
537 ret=$?
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stderr.expected $testroot/stderr
540 test_done $testroot $ret
541 return 1
542 fi
544 # empty hunk
545 cat <<EOF > $testroot/wt/patch
546 diff --git a/alpha b/iota
547 --- a/alpha
548 +++ b/iota
549 @@ -0,0 +0,0 @@
550 EOF
552 (cd $testroot/wt && got patch patch) \
553 > $testroot/stdout \
554 2> $testroot/stderr
555 ret=$?
556 if [ $ret -eq 0 ]; then
557 echo "got managed to apply an invalid patch"
558 test_done $testroot 1
559 return 1
560 fi
562 cmp -s $testroot/stdout.expected $testroot/stdout
563 ret=$?
564 if [ $ret -ne 0 ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done $testroot $ret
567 return 1
568 fi
570 cmp -s $testroot/stderr.expected $testroot/stderr
571 ret=$?
572 if [ $ret -ne 0 ]; then
573 diff -u $testroot/stderr.expected $testroot/stderr
574 test_done $testroot $ret
575 return 1
576 fi
578 test_done $testroot $ret
581 test_patch_no_patch() {
582 local testroot=`test_init patch_no_patch`
584 got checkout $testroot/repo $testroot/wt > /dev/null
585 ret=$?
586 if [ $ret -ne 0 ]; then
587 test_done $testroot $ret
588 return 1
589 fi
591 cat <<EOF > $testroot/wt/patch
592 hello world!
593 ...
595 some other nonsense
596 ...
598 there's no patch in here!
599 EOF
601 echo -n > $testroot/stdout.expected
602 echo "got: no patch found" > $testroot/stderr.expected
604 (cd $testroot/wt && got patch patch) \
605 > $testroot/stdout \
606 2> $testroot/stderr
607 ret=$?
608 if [ $ret -eq 0 ]; then # should fail
609 test_done $testroot 1
610 return 1
611 fi
613 cmp -s $testroot/stdout.expected $testroot/stdout
614 ret=$?
615 if [ $ret -ne 0 ]; then
616 diff -u $testroot/stdout.expected $testroot/stdout
617 test_done $testroot $ret
618 return 1
619 fi
621 cmp -s $testroot/stderr.expected $testroot/stderr
622 ret=$?
623 if [ $ret -ne 0 ]; then
624 diff -u $testroot/stderr.expected $testroot/stderr
625 test_done $testroot $ret
626 return 1
627 fi
629 test_done $testroot $ret
632 test_patch_equals_for_context() {
633 local testroot=`test_init patch_equals_for_context`
635 got checkout $testroot/repo $testroot/wt > /dev/null
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 test_done $testroot $ret
639 return 1
640 fi
642 cat <<EOF > $testroot/wt/patch
643 --- alpha
644 +++ alpha
645 @@ -1 +1,2 @@
646 +hatsuseno
647 =alpha
648 EOF
650 echo "M alpha" > $testroot/stdout.expected
652 (cd $testroot/wt && got patch patch) > $testroot/stdout
653 ret=$?
654 if [ $ret -ne 0 ]; then
655 test_done $testroot $ret
656 return 1
657 fi
659 cmp -s $testroot/stdout.expected $testroot/stdout
660 ret=$?
661 if [ $ret -ne 0 ]; then
662 diff -u $testroot/stdout.expected $testroot/stdout
663 test_done $testroot $ret
664 return 1
665 fi
667 echo hatsuseno > $testroot/wt/alpha.expected
668 echo alpha >> $testroot/wt/alpha.expected
669 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
670 ret=$?
671 if [ $ret -ne 0 ]; then
672 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
673 fi
674 test_done $testroot $ret
677 test_patch_rename() {
678 local testroot=`test_init patch_rename`
680 got checkout $testroot/repo $testroot/wt > /dev/null
681 ret=$?
682 if [ $ret -ne 0 ]; then
683 test_done $testroot $ret
684 return 1
685 fi
687 cat <<EOF > $testroot/wt/patch
688 diff --git a/beta b/iota
689 similarity index 100%
690 rename from beta
691 rename to iota
692 diff --git a/alpha b/eta
693 --- a/alpha
694 +++ b/eta
695 @@ -1 +1 @@
696 -alpha
697 +eta
698 EOF
700 echo 'D beta' > $testroot/stdout.expected
701 echo 'A iota' >> $testroot/stdout.expected
702 echo 'D alpha' >> $testroot/stdout.expected
703 echo 'A eta' >> $testroot/stdout.expected
705 (cd $testroot/wt && got patch patch) > $testroot/stdout
706 ret=$?
707 if [ $ret -ne 0 ]; then
708 test_done $testroot $ret
709 return 1
710 fi
712 cmp -s $testroot/stdout.expected $testroot/stdout
713 ret=$?
714 if [ $ret -ne 0 ]; then
715 diff -u $testroot/stdout.expected $testroot/stdout
716 test_done $testroot $ret
717 return 1
718 fi
720 if [ -f $testroot/wt/alpha -o -f $testroot/wt/beta ]; then
721 echo "alpha or beta were not removed" >&2
722 test_done $testroot 1
723 return 1
724 fi
725 if [ ! -f $testroot/wt/iota -o ! -f $testroot/wt/eta ]; then
726 echo "iota or eta were not created" >&2
727 test_done $testroot 1
728 return 1
729 fi
731 echo beta > $testroot/wt/iota.expected
732 cmp -s $testroot/wt/iota.expected $testroot/wt/iota
733 ret=$?
734 if [ $ret -ne 0 ]; then
735 diff -u $testroot/wt/iota.expected $testroot/wt/iota
736 test_done $testroot $ret
737 return 1
738 fi
740 echo eta > $testroot/wt/eta.expected
741 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
742 ret=$?
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/wt/eta.expected $testroot/wt/eta
745 test_done $testroot $ret
746 return 1
747 fi
749 test_done $testroot $ret
752 test_patch_illegal_status() {
753 local testroot=`test_init patch_illegal_status`
755 got checkout $testroot/repo $testroot/wt > /dev/null
756 ret=$?
757 if [ $ret -ne 0 ]; then
758 test_done $testroot $ret
759 return 1
760 fi
762 # try to patch an obstructed file, add a versioned one, edit a
763 # non existent file and an unversioned one, and remove a
764 # non existent file.
765 cat <<EOF > $testroot/wt/patch
766 --- alpha
767 +++ alpha
768 @@ -1 +1,2 @@
769 alpha
770 +was edited
771 --- /dev/null
772 +++ beta
773 @@ -0,0 +1 @@
774 +beta
775 --- iota
776 +++ iota
777 @@ -1 +1 @@
778 -iota
779 +IOTA
780 --- kappa
781 +++ kappa
782 @@ -1 +1 @@
783 -kappa
784 +KAPPA
785 --- lambda
786 +++ /dev/null
787 @@ -1 +0,0 @@
788 -lambda
789 EOF
791 echo kappa > $testroot/wt/kappa
792 rm $testroot/wt/alpha
793 mkdir $testroot/wt/alpha
795 (cd $testroot/wt && got patch patch) > $testroot/stdout \
796 2> $testroot/stderr
797 ret=$?
798 if [ $ret -eq 0 ]; then
799 echo "edited a missing file" >&2
800 test_done $testroot 1
801 return 1
802 fi
804 cat <<EOF > $testroot/stdout.expected
805 # alpha
806 # beta
807 # iota
808 # kappa
809 # lambda
810 EOF
812 cat <<EOF > $testroot/stderr.expected
813 got: alpha: file has unexpected status
814 got: beta: file has unexpected status
815 got: iota: No such file or directory
816 got: kappa: file has unexpected status
817 got: lambda: No such file or directory
818 got: patch failed to apply
819 EOF
821 cmp -s $testroot/stdout.expected $testroot/stdout
822 ret=$?
823 if [ $ret -ne 0 ]; then
824 diff -u $testroot/stdout.expected $testroot/stdout
825 test_done $testroot $ret
826 return 1
827 fi
829 cmp -s $testroot/stderr.expected $testroot/stderr
830 ret=$?
831 if [ $ret -ne 0 ]; then
832 diff -u $testroot/stderr.expected $testroot/stderr
833 test_done $testroot $ret
834 return 1
835 fi
837 (cd $testroot/wt && got status) > $testroot/stdout
838 cat <<EOF > $testroot/stdout.expected
839 ~ alpha
840 ? kappa
841 ? patch
842 EOF
844 cmp -s $testroot/stdout.expected $testroot/stdout
845 ret=$?
846 if [ $ret -ne 0 ]; then
847 diff -u $testroot/stdout.expected $testroot/stdout
848 fi
849 test_done $testroot $ret
852 test_patch_nop() {
853 local testroot=`test_init patch_nop`
855 got checkout $testroot/repo $testroot/wt > /dev/null
856 ret=$?
857 if [ $ret -ne 0 ]; then
858 test_done $testroot $ret
859 return 1
860 fi
862 cat <<EOF > $testroot/wt/patch
863 --- alpha
864 +++ alpha
865 @@ -1 +1 @@
866 -alpha
867 +cafe alpha
868 --- beta
869 +++ /dev/null
870 @@ -1 +0,0 @@
871 -beta
872 diff --git a/gamma/delta b/gamma/delta.new
873 --- gamma/delta
874 +++ gamma/delta.new
875 @@ -1 +1 @@
876 -delta
877 +delta updated and renamed!
878 EOF
880 (cd $testroot/wt && got patch -n patch)
881 ret=$?
882 if [ $ret -ne 0 ]; then
883 test_done $testroot $ret
884 return 1
885 fi
887 # remove the patch to avoid the ? entry
888 rm $testroot/wt/patch
890 (cd $testroot/wt && got status) > $testroot/stdout
891 ret=$?
892 if [ $ret -ne 0 ]; then
893 test_done $testroot $ret
894 return 1
895 fi
897 echo -n > $testroot/stdout.expected
898 cmp -s $testroot/stdout.expected $testroot/stdout
899 ret=$?
900 if [ $ret -ne 0 ]; then
901 diff -u $testroot/stdout.expected $testroot/stdout
902 fi
903 test_done $testroot $ret
906 test_patch_preserve_perm() {
907 local testroot=`test_init patch_preserve_perm`
909 got checkout $testroot/repo $testroot/wt > /dev/null
910 ret=$?
911 if [ $ret -ne 0 ]; then
912 test_done $testroot $ret
913 return 1
914 fi
916 chmod +x $testroot/wt/alpha
917 (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
918 ret=$?
919 if [ $ret -ne 0 ]; then
920 test_done $testroot $ret
921 return 1
922 fi
924 cat <<EOF > $testroot/wt/patch
925 --- alpha
926 +++ alpha
927 @@ -1 +1,2 @@
928 alpha
929 +was edited
930 EOF
932 (cd $testroot/wt && got patch patch) > /dev/null
933 ret=$?
934 if [ $ret -ne 0 ]; then
935 test_done $testroot $ret
936 return 1
937 fi
939 if [ ! -x $testroot/wt/alpha ]; then
940 echo "alpha is no more executable!" >&2
941 test_done $testroot 1
942 return 1
943 fi
944 test_done $testroot 0
947 test_patch_create_dirs() {
948 local testroot=`test_init patch_create_dirs`
950 got checkout $testroot/repo $testroot/wt > /dev/null
951 ret=$?
952 if [ $ret -ne 0 ]; then
953 test_done $testroot $ret
954 return 1
955 fi
957 cat <<EOF > $testroot/wt/patch
958 --- /dev/null
959 +++ iota/kappa/lambda
960 @@ -0,0 +1 @@
961 +lambda
962 EOF
964 (cd $testroot/wt && got patch patch) > $testroot/stdout
965 ret=$?
966 if [ $ret -ne 0 ]; then
967 test_done $testroot $ret
968 return 1
969 fi
971 echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
972 cmp -s $testroot/stdout.expected $testroot/stdout
973 ret=$?
974 if [ $ret -ne 0 ]; then
975 diff -u $testroot/stdout.expected $testroot/stdout
976 test_done $testroot $ret
977 return 1
978 fi
980 if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
981 echo "file not created!" >&2
982 test_done $testroot $ret
983 return 1
984 fi
985 test_done $testroot 0
988 test_patch_with_offset() {
989 local testroot=`test_init patch_with_offset`
991 got checkout $testroot/repo $testroot/wt > /dev/null
992 ret=$?
993 if [ $ret -ne 0 ]; then
994 test_done $testroot $ret
995 return 1
996 fi
998 cat <<EOF > $testroot/wt/patch
999 --- numbers
1000 +++ numbers
1001 @@ -47,7 +47,7 @@
1005 -50
1006 +midway tru it!
1010 @@ -87,7 +87,7 @@
1014 -90
1015 +almost there!
1019 EOF
1021 jot 100 > $testroot/wt/numbers
1022 ed $testroot/wt/numbers <<EOF > /dev/null 2> /dev/null
1023 1,10d
1024 50r !jot 20
1027 EOF
1029 (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
1030 > /dev/null
1031 ret=$?
1032 if [ $ret -ne 0 ]; then
1033 test_done $testroot $ret
1034 return 1
1037 (cd $testroot/wt && got patch patch) > $testroot/stdout
1038 ret=$?
1039 if [ $ret -ne 0 ]; then
1040 test_done $testroot/wt $ret
1041 return 1
1044 cat <<EOF > $testroot/stdout.expected
1045 M numbers
1046 @@ -47,7 +47,7 @@ applied with offset -10
1047 @@ -87,7 +87,7 @@ applied with offset 10
1048 EOF
1050 cmp -s $testroot/stdout.expected $testroot/stdout
1051 ret=$?
1052 if [ $ret -ne 0 ]; then
1053 diff -u $testroot/stdout.expected $testroot/stdout
1055 test_done $testroot $ret
1058 test_patch_prefer_new_path() {
1059 local testroot=`test_init patch_orig`
1061 got checkout $testroot/repo $testroot/wt > /dev/null
1062 ret=$?
1063 if [ $ret -ne 0 ]; then
1064 test_done $testroot $ret
1065 return 1
1068 cat <<EOF > $testroot/wt/patch
1069 --- alpha.orig
1070 +++ alpha
1071 @@ -1 +1,2 @@
1072 alpha
1073 +was edited
1074 EOF
1076 (cd $testroot/wt && got patch patch) > $testroot/stdout
1077 ret=$?
1078 if [ $ret -ne 0 ]; then
1079 test_done $testroot $ret
1080 return 1
1083 echo 'M alpha' > $testroot/stdout.expected
1084 cmp -s $testroot/stdout.expected $testroot/stdout
1085 ret=$?
1086 if [ $ret -ne 0 ]; then
1087 diff -u $testroot/stdout.expected $testroot/stdout
1089 test_done $testroot $ret
1092 test_patch_no_newline() {
1093 local testroot=`test_init patch_no_newline`
1095 got checkout $testroot/repo $testroot/wt > /dev/null
1096 ret=$?
1097 if [ $ret -ne 0 ]; then
1098 test_done $testroot $ret
1099 return 1
1102 cat <<EOF > $testroot/wt/patch
1103 --- /dev/null
1104 +++ eta
1105 @@ -0,0 +1 @@
1106 +eta
1107 \ No newline at end of file
1108 EOF
1110 (cd $testroot/wt && got patch patch) > $testroot/stdout
1111 ret=$?
1112 if [ $ret -ne 0 ]; then
1113 test_done $testroot $ret
1114 return 1
1117 echo "A eta" > $testroot/stdout.expected
1118 cmp -s $testroot/stdout.expected $testroot/stdout
1119 ret=$?
1120 if [ $ret -ne 0 ]; then
1121 diff -u $testroot/stdout.expected $testroot/stdout
1122 test_done $testroot $ret
1123 return 1
1126 echo -n eta > $testroot/wt/eta.expected
1127 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1128 ret=$?
1129 if [ $ret -ne 0 ]; then
1130 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1131 test_done $testroot $ret
1132 return 1
1135 (cd $testroot/wt && got commit -m 'add eta') > /dev/null
1136 ret=$?
1137 if [ $ret -ne 0 ]; then
1138 test_done $testroot $ret
1139 return 1
1142 cat <<EOF > $testroot/wt/patch
1143 --- eta
1144 +++ eta
1145 @@ -1 +1 @@
1146 -eta
1147 \ No newline at end of file
1148 +ETA
1149 \ No newline at end of file
1150 EOF
1152 (cd $testroot/wt && got patch patch) > $testroot/stdout
1153 ret=$?
1154 if [ $ret -ne 0 ]; then
1155 test_done $testroot $ret
1156 return 1
1159 echo "M eta" > $testroot/stdout.expected
1160 cmp -s $testroot/stdout.expected $testroot/stdout
1161 ret=$?
1162 if [ $ret -ne 0 ]; then
1163 diff -u $testroot/stdout.expected $testroot/stdout
1164 test_done $testroot $ret
1165 return 1
1168 echo -n ETA > $testroot/wt/eta.expected
1169 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1170 ret=$?
1171 if [ $ret -ne 0 ]; then
1172 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1173 test_done $testroot $ret
1174 return 1
1177 (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
1178 ret=$?
1179 if [ $ret -ne 0 ]; then
1180 test_done $testroot $ret
1181 return 1
1184 cat <<EOF > $testroot/wt/patch
1185 --- eta
1186 +++ eta
1187 @@ -1 +1 @@
1188 -ETA
1189 \ No newline at end of file
1190 +eta
1191 EOF
1193 (cd $testroot/wt && got patch patch) > $testroot/stdout
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 test_done $testroot $ret
1197 return 1
1200 echo "M eta" > $testroot/stdout.expected
1201 cmp -s $testroot/stdout.expected $testroot/stdout
1202 ret=$?
1203 if [ $ret -ne 0 ]; then
1204 diff -u $testroot/stdout.expected $testroot/stdout
1205 test_done $testroot $ret
1206 return 1
1209 echo eta > $testroot/wt/eta.expected
1210 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1211 ret=$?
1212 if [ $ret -ne 0 ]; then
1213 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1215 test_done $testroot $ret
1218 test_patch_strip() {
1219 local testroot=`test_init patch_strip`
1221 got checkout $testroot/repo $testroot/wt > /dev/null
1222 ret=$?
1223 if [ $ret -ne 0 ]; then
1224 test_done $testroot $ret
1225 return 1
1228 cat <<EOF > $testroot/wt/patch
1229 --- foo/bar/alpha.orig
1230 +++ foo/bar/alpha
1231 @@ -1 +1 @@
1232 -alpha
1233 +ALPHA
1234 EOF
1236 (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
1237 ret=$?
1238 if [ $ret -ne 0 ]; then
1239 test_done $testroot $ret
1240 return 1
1243 echo "M alpha" >> $testroot/stdout.expected
1244 cmp -s $testroot/stdout.expected $testroot/stdout
1245 ret=$?
1246 if [ $ret -ne 0 ]; then
1247 diff -u $testroot/stdout.expected $testroot/stdout
1248 test_done $testroot $ret
1249 return 1
1252 (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1253 ret=$?
1254 if [ $ret -ne 0 ]; then
1255 test_done $testroot $ret
1256 return 1
1259 (cd $testroot/wt && got patch -p3 patch) \
1260 2> $testroot/stderr
1261 ret=$?
1262 if [ $ret -eq 0 ]; then
1263 echo "stripped more components than available!"
1264 test_done $testroot 1
1265 return 1
1268 cat <<EOF > $testroot/stderr.expected
1269 got: can't strip 1 path-components from foo/bar/alpha: bad path
1270 EOF
1272 cmp -s $testroot/stderr.expected $testroot/stderr
1273 ret=$?
1274 if [ $ret -ne 0 ]; then
1275 diff -u $testroot/stderr.expected $testroot/stderr
1277 test_done $testroot 0
1280 test_patch_whitespace() {
1281 local testroot=`test_init patch_whitespace`
1283 got checkout $testroot/repo $testroot/wt > /dev/null
1284 ret=$?
1285 if [ $ret -ne 0 ]; then
1286 test_done $testroot $ret
1287 return 1
1290 trailing=" "
1292 cat <<EOF > $testroot/wt/hello.c
1293 #include <stdio.h>
1295 int
1296 main(void)
1298 /* the trailing whitespace is on purpose */
1299 printf("hello, world\n");$trailing
1300 return 0;
1302 EOF
1304 (cd $testroot/wt && got add hello.c && got ci -m '+hello.c') \
1305 > /dev/null
1306 ret=$?
1307 if [ $ret -ne 0 ]; then
1308 test_done $testroot $ret
1309 return 1
1312 # test with a diff with various whitespace corruptions
1313 cat <<EOF > $testroot/wt/patch
1314 --- hello.c
1315 +++ hello.c
1316 @@ -5,5 +5,5 @@
1318 /* the trailing whitespace is on purpose */
1319 printf("hello, world\n");
1320 - return 0;
1321 + return 5; /* always fails */
1323 EOF
1325 (cd $testroot/wt && got patch patch) \
1326 2>$testroot/stderr >$testroot/stdout
1327 ret=$?
1328 if [ $ret -ne 0 ]; then
1329 echo "failed to apply diff" >&2
1330 test_done $testroot $ret
1331 return 1
1334 echo 'M hello.c' > $testroot/stdout.expected
1335 echo '@@ -5,5 +5,5 @@ hunk contains mangled whitespace' \
1336 >> $testroot/stdout.expected
1337 cmp -s $testroot/stdout.expected $testroot/stdout
1338 ret=$?
1339 if [ $ret -ne 0 ]; then
1340 diff -u $testroot/stdout.expected $testroot/stdout
1341 test_done $testroot $ret
1342 return 1
1345 cat <<EOF > $testroot/wt/hello.c.expected
1346 #include <stdio.h>
1348 int
1349 main(void)
1351 /* the trailing whitespace is on purpose */
1352 printf("hello, world\n");$trailing
1353 return 5; /* always fails */
1355 EOF
1357 cmp -s $testroot/wt/hello.c.expected $testroot/wt/hello.c
1358 ret=$?
1359 if [ $ret -ne 0 ]; then
1360 diff -u $testroot/wt/hello.c.expected $testroot/wt/hello.c
1362 test_done $testroot $ret
1365 test_patch_relative_paths() {
1366 local testroot=`test_init patch_relative_paths`
1368 got checkout $testroot/repo $testroot/wt > /dev/null
1369 ret=$?
1370 if [ $ret -ne 0 ]; then
1371 test_done $testroot $ret
1372 return 1
1375 cat <<EOF > $testroot/wt/gamma/patch
1376 --- delta
1377 +++ delta
1378 @@ -1 +1 @@
1379 -delta
1380 +DELTA
1381 --- /dev/null
1382 +++ eta
1383 @@ -0,0 +1 @@
1384 +eta
1385 EOF
1387 (cd $testroot/wt/gamma && got patch patch) > $testroot/stdout
1388 ret=$?
1389 if [ $ret -ne 0 ]; then
1390 test_done $testroot $ret
1391 return 1
1394 echo 'M gamma/delta' > $testroot/stdout.expected
1395 echo 'A gamma/eta' >> $testroot/stdout.expected
1397 cmp -s $testroot/stdout.expected $testroot/stdout
1398 ret=$?
1399 if [ $ret -ne 0 ]; then
1400 diff -u $testroot/stdout.expected $testroot/stdout
1402 test_done $testroot $ret
1405 test_patch_with_path_prefix() {
1406 local testroot=`test_init patch_with_path_prefix`
1408 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1409 ret=$?
1410 if [ $ret -ne 0 ]; then
1411 test_done $testroot $ret
1412 return 1
1415 cat <<EOF > $testroot/wt/patch
1416 --- delta
1417 +++ delta
1418 @@ -1 +1 @@
1419 -delta
1420 +DELTA
1421 --- /dev/null
1422 +++ eta
1423 @@ -0,0 +1 @@
1424 +eta
1425 EOF
1427 (cd $testroot/wt && got patch patch) > $testroot/stdout
1428 ret=$?
1429 if [ $ret -ne 0 ]; then
1430 test_done $testroot $ret
1431 return 1
1434 echo 'M delta' > $testroot/stdout.expected
1435 echo 'A eta' >> $testroot/stdout.expected
1437 cmp -s $testroot/stdout.expected $testroot/stdout
1438 ret=$?
1439 if [ $ret -ne 0 ]; then
1440 diff -u $testroot/stdout.expected $testroot/stdout
1442 test_done $testroot $ret
1445 test_patch_relpath_with_path_prefix() {
1446 local testroot=`test_init patch_relpaths_with_path_prefix`
1448 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1449 ret=$?
1450 if [ $ret -ne 0 ]; then
1451 test_done $testroot $ret
1452 return 1
1455 mkdir -p $testroot/wt/epsilon/zeta/
1457 cat <<EOF > $testroot/wt/patch
1458 --- /dev/null
1459 +++ zeta/theta
1460 @@ -0,0 +1 @@
1461 +theta
1462 EOF
1464 (cd $testroot/wt/epsilon/zeta && got patch -p1 $testroot/wt/patch) \
1465 > $testroot/stdout
1466 ret=$?
1467 if [ $ret -ne 0 ]; then
1468 test_done $testroot $ret
1469 return 1
1472 echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1474 cmp -s $testroot/stdout.expected $testroot/stdout
1475 ret=$?
1476 if [ $ret -ne 0 ]; then
1477 diff -u $testroot/stdout.expected $testroot/stdout
1478 test_done $testroot $ret
1479 return 1
1482 echo 'theta' > $testroot/theta.expected
1483 cmp -s $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1484 ret=$?
1485 if [ $ret -ne 0 ]; then
1486 diff -u $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1488 test_done $testroot $ret
1491 test_patch_reverse() {
1492 local testroot=`test_init patch_reverse`
1494 got checkout $testroot/repo $testroot/wt > /dev/null
1495 ret=$?
1496 if [ $ret -ne 0 ]; then
1497 test_done $testroot $ret
1498 return 1
1501 cat <<EOF > $testroot/wt/patch
1502 --- alpha
1503 +++ alpha
1504 @@ -1 +1 @@
1505 -ALPHA
1506 \ No newline at end of file
1507 +alpha
1508 EOF
1510 (cd $testroot/wt && got patch -R patch) > $testroot/stdout
1511 ret=$?
1512 if [ $ret -ne 0 ]; then
1513 test_done $testroot $ret
1514 return 1
1517 echo "M alpha" > $testroot/stdout.expected
1518 cmp -s $testroot/stdout.expected $testroot/stdout
1519 ret=$?
1520 if [ $ret -ne 0 ]; then
1521 diff -u $testroot/stdout.expected $testroot/stdout
1522 test_done $testroot $ret
1523 return 1
1526 echo -n ALPHA > $testroot/wt/alpha.expected
1527 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
1528 ret=$?
1529 if [ $ret -ne 0 ]; then
1530 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
1532 test_done $testroot $ret
1535 test_patch_merge_simple() {
1536 local testroot=`test_init patch_merge_simple`
1538 got checkout $testroot/repo $testroot/wt > /dev/null
1539 ret=$?
1540 if [ $ret -ne 0 ]; then
1541 test_done $testroot $ret
1542 return 1
1545 jot 10 > $testroot/wt/numbers
1546 chmod +x $testroot/wt/numbers
1547 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1548 > /dev/null
1549 ret=$?
1550 if [ $ret -ne 0 ]; then
1551 test_done $testroot $ret
1552 return 1
1555 jot 10 | sed 's/4/four/g' > $testroot/wt/numbers
1557 (cd $testroot/wt && got diff > $testroot/old.diff \
1558 && got revert numbers) >/dev/null
1559 ret=$?
1560 if [ $ret -ne 0 ]; then
1561 test_done $testroot $ret
1562 return 1
1565 jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1566 (cd $testroot/wt && got commit -m 'edit numbers') \
1567 > /dev/null
1568 ret=$?
1569 if [ $ret -ne 0 ]; then
1570 test_done $testroot $ret
1571 return 1
1574 (cd $testroot/wt && got patch $testroot/old.diff) \
1575 > $testroot/stdout
1576 ret=$?
1577 if [ $ret -ne 0 ]; then
1578 test_done $testroot $ret
1579 return 1
1582 echo 'G numbers' > $testroot/stdout.expected
1583 cmp -s $testroot/stdout $testroot/stdout.expected
1584 ret=$?
1585 if [ $ret -ne 0 ]; then
1586 diff -u $testroot/stdout $testroot/stdout.expected
1587 test_done $testroot $ret
1588 return 1
1591 jot 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1592 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1593 ret=$?
1594 if [ $ret -ne 0 ]; then
1595 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1596 test_done $testroot $ret
1597 return 1
1600 test -x $testroot/wt/numbers
1601 ret=$?
1602 if [ $ret -ne 0 ]; then
1603 echo "numbers lost the executable bit" >&2
1605 test_done $testroot $ret
1608 test_patch_merge_gitdiff() {
1609 local testroot=`test_init patch_merge_gitdiff`
1611 jot 10 > $testroot/repo/numbers
1612 (cd $testroot/repo && git add numbers && \
1613 git_commit $testroot/repo -m "nums")
1614 ret=$?
1615 if [ $ret -ne 0 ]; then
1616 test_done $testroot $ret
1617 return 1
1620 jot 10 | sed 's/4/four/g' > $testroot/repo/numbers
1621 (cd $testroot/repo && git diff > $testroot/old.diff)
1622 ret=$?
1623 if [ $ret -ne 0 ]; then
1624 test_done $testroot $ret
1625 return 1
1628 # restore numbers
1629 jot 10 > $testroot/repo/numbers
1631 jot 10 | sed 's/6/six/g' > $testroot/repo/numbers
1632 (cd $testroot/repo && git add numbers && \
1633 git_commit $testroot/repo -m "edit")
1634 ret=$?
1635 if [ $ret -ne 0 ]; then
1636 test_done $testroot $ret
1637 return 1
1640 # now work with got:
1641 got checkout $testroot/repo $testroot/wt > /dev/null
1642 ret=$?
1643 if [ $ret -ne 0 ]; then
1644 test_done $testroot $ret
1645 return 1
1648 (cd $testroot/wt && got patch $testroot/old.diff) > $testroot/stdout
1649 ret=$?
1650 if [ $ret -ne 0 ]; then
1651 test_done $testroot $ret
1652 return 1
1655 echo 'G numbers' > $testroot/stdout.expected
1656 cmp -s $testroot/stdout $testroot/stdout.expected
1657 ret=$?
1658 if [ $ret -ne 0 ]; then
1659 diff -u $testroot/stdout $testroot/stdout.expected
1661 test_done $testroot $ret
1664 test_patch_merge_conflict() {
1665 local testroot=`test_init patch_merge_conflict`
1667 got checkout $testroot/repo $testroot/wt > /dev/null
1668 ret=$?
1669 if [ $ret -ne 0 ]; then
1670 test_done $testroot $ret
1671 return 1
1674 jot 10 > $testroot/wt/numbers
1675 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1676 > /dev/null
1677 ret=$?
1678 if [ $ret -ne 0 ]; then
1679 test_done $testroot $ret
1680 return 1
1683 local commit_id=`git_show_head $testroot/repo`
1685 jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1686 echo ALPHA > $testroot/wt/alpha
1688 (cd $testroot/wt && got diff > $testroot/old.diff \
1689 && got revert alpha numbers) >/dev/null
1690 ret=$?
1691 if [ $ret -ne 0 ]; then
1692 test_done $testroot $ret
1693 return 1
1696 jot 10 | sed 's/6/3+3/g' > $testroot/wt/numbers
1697 jot -c 3 a > $testroot/wt/alpha
1698 (cd $testroot/wt && got commit -m 'edit alpha and numbers') \
1699 > /dev/null
1700 ret=$?
1701 if [ $ret -ne 0 ]; then
1702 test_done $testroot $ret
1703 return 1
1706 (cd $testroot/wt && got patch $testroot/old.diff) \
1707 > $testroot/stdout 2>/dev/null
1708 ret=$?
1709 if [ $ret -eq 0 ]; then
1710 echo "got patch merged a diff that should conflict" >&2
1711 test_done $testroot 0
1712 return 1
1715 echo 'C alpha' > $testroot/stdout.expected
1716 echo 'C numbers' >> $testroot/stdout.expected
1717 cmp -s $testroot/stdout $testroot/stdout.expected
1718 ret=$?
1719 if [ $ret -ne 0 ]; then
1720 diff -u $testroot/stdout $testroot/stdout.expected
1721 test_done $testroot $ret
1722 return 1
1725 # XXX: prefixing every line with a tab otherwise got thinks
1726 # the file has conflicts in it.
1727 cat <<-EOF > $testroot/wt/alpha.expected
1728 <<<<<<< --- alpha
1729 ALPHA
1730 ||||||| commit $commit_id
1731 alpha
1732 =======
1736 >>>>>>> +++ alpha
1737 EOF
1739 cat <<-EOF > $testroot/wt/numbers.expected
1745 <<<<<<< --- numbers
1746 six
1747 ||||||| commit $commit_id
1749 =======
1750 3+3
1751 >>>>>>> +++ numbers
1756 EOF
1758 cmp -s $testroot/wt/alpha $testroot/wt/alpha.expected
1759 ret=$?
1760 if [ $ret -ne 0 ]; then
1761 diff -u $testroot/wt/alpha $testroot/wt/alpha.expected
1762 test_done $testroot $ret
1763 return 1
1766 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1767 ret=$?
1768 if [ $ret -ne 0 ]; then
1769 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1771 test_done $testroot $ret
1774 test_patch_merge_unknown_blob() {
1775 local testroot=`test_init patch_merge_unknown_blob`
1777 got checkout $testroot/repo $testroot/wt > /dev/null
1778 ret=$?
1779 if [ $ret -ne 0 ]; then
1780 test_done $testroot $ret
1781 return 1
1784 cat <<EOF > $testroot/wt/patch
1785 I've got a
1786 diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
1787 with a
1788 blob - aaaabbbbccccddddeeeeffff0000111122223333
1789 and also a
1790 blob + 0000111122223333444455556666777788889999
1791 for this dummy diff
1792 --- alpha
1793 +++ alpha
1794 @@ -1 +1 @@
1795 -alpha
1796 +ALPHA
1797 will it work?
1798 EOF
1800 (cd $testroot/wt/ && got patch patch) > $testroot/stdout
1801 ret=$?
1802 if [ $ret -ne 0 ]; then
1803 test_done $testroot $ret
1804 return 1
1807 echo 'M alpha' > $testroot/stdout.expected
1808 cmp -s $testroot/stdout.expected $testroot/stdout
1809 ret=$?
1810 if [ $ret -ne 0 ]; then
1811 diff -u $testroot/stdout.expected $testroot/stdout
1812 test_done $testroot $ret
1813 return 1
1816 # try again without a `diff' header
1818 cat <<EOF > $testroot/wt/patch
1819 I've got a
1820 blob - aaaabbbbccccddddeeeeffff0000111122223333
1821 and also a
1822 blob + 0000111122223333444455556666777788889999
1823 for this dummy diff
1824 --- alpha
1825 +++ alpha
1826 @@ -1 +1 @@
1827 -alpha
1828 +ALPHA
1829 will it work?
1830 EOF
1832 (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1833 > $testroot/stdout
1834 ret=$?
1835 if [ $ret -ne 0 ]; then
1836 test_done $testroot $ret
1837 return 1
1840 echo 'M alpha' > $testroot/stdout.expected
1841 cmp -s $testroot/stdout.expected $testroot/stdout
1842 ret=$?
1843 if [ $ret -ne 0 ]; then
1844 diff -u $testroot/stdout.expected $testroot/stdout
1845 test_done $testroot $ret
1846 return 1
1849 # try again with a git-style diff
1851 cat <<EOF > $testroot/wt/patch
1852 diff --git a/alpha b/alpha
1853 index 0123456789ab..abcdef012345 100644
1854 --- a/alpha
1855 +++ b/alpha
1856 @@ -1 +1 @@
1857 -alpha
1858 +ALPHA
1859 EOF
1861 (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1862 > $testroot/stdout
1863 ret=$?
1864 if [ $ret -ne 0 ]; then
1865 test_done $testroot $ret
1866 return 1
1869 echo 'M alpha' > $testroot/stdout.expected
1870 cmp -s $testroot/stdout.expected $testroot/stdout
1871 ret=$?
1872 if [ $ret -ne 0 ]; then
1873 diff -u $testroot/stdout.expected $testroot/stdout
1875 test_done $testroot $ret
1878 test_parseargs "$@"
1879 run_test test_patch_add_file
1880 run_test test_patch_rm_file
1881 run_test test_patch_simple_edit_file
1882 run_test test_patch_prepend_line
1883 run_test test_patch_replace_line
1884 run_test test_patch_multiple_hunks
1885 run_test test_patch_multiple_files
1886 run_test test_patch_dont_apply
1887 run_test test_patch_malformed
1888 run_test test_patch_no_patch
1889 run_test test_patch_equals_for_context
1890 run_test test_patch_rename
1891 run_test test_patch_illegal_status
1892 run_test test_patch_nop
1893 run_test test_patch_preserve_perm
1894 run_test test_patch_create_dirs
1895 run_test test_patch_with_offset
1896 run_test test_patch_prefer_new_path
1897 run_test test_patch_no_newline
1898 run_test test_patch_strip
1899 run_test test_patch_whitespace
1900 run_test test_patch_relative_paths
1901 run_test test_patch_with_path_prefix
1902 run_test test_patch_relpath_with_path_prefix
1903 run_test test_patch_reverse
1904 run_test test_patch_merge_simple
1905 run_test test_patch_merge_gitdiff
1906 run_test test_patch_merge_conflict
1907 run_test test_patch_merge_unknown_blob