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_basic() {
20 local testroot=`test_init patch_basic`
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 jot 100 > $testroot/wt/numbers
30 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
31 >/dev/null
32 ret=$?
33 if [ $ret -ne 0 ]; then
34 test_done "$testroot" $ret
35 return 1
36 fi
38 cat <<EOF > $testroot/wt/patch
39 --- alpha
40 +++ alpha
41 @@ -1 +1 @@
42 -alpha
43 +alpha is my favourite character
44 --- beta
45 +++ /dev/null
46 @@ -1 +0,0 @@
47 -beta
48 --- gamma/delta
49 +++ gamma/delta
50 @@ -1 +1,2 @@
51 +this is:
52 delta
53 --- /dev/null
54 +++ eta
55 @@ -0,0 +5,5 @@
56 +1
57 +2
58 +3
59 +4
60 +5
61 --- numbers
62 +++ numbers
63 @@ -3,7 +3,7 @@
64 3
65 4
66 5
67 -6
68 +six
69 7
70 8
71 9
72 @@ -57,7 +57,7 @@
73 57
74 58
75 59
76 -60
77 +sixty
78 61
79 62
80 63
81 @@ -98,3 +98,6 @@
82 98
83 99
84 100
85 +101
86 +102
87 +103
88 EOF
90 (cd $testroot/wt && got patch < patch) > $testroot/stdout
91 if [ $ret -ne 0 ]; then
92 test_done "$testroot" $ret
93 return 1
94 fi
96 echo 'M alpha' > $testroot/stdout.expected
97 echo 'D beta' >> $testroot/stdout.expected
98 echo 'M gamma/delta' >> $testroot/stdout.expected
99 echo 'A eta' >> $testroot/stdout.expected
100 echo 'M numbers' >> $testroot/stdout.expected
102 cmp -s $testroot/stdout.expected $testroot/stdout
103 ret=$?
104 if [ $ret -ne 0 ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
106 test_done $testroot $ret
107 return 1
108 fi
110 echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
111 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
112 ret=$?
113 if [ $ret -ne 0 ]; then
114 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
115 test_done "$testroot" $ret
116 return 1
117 fi
119 if [ -f "$testroot/wt/beta" ]; then
120 echo "beta was not deleted!" >&2
121 test_done "$testroot" 1
122 return 1
123 fi
125 echo 'this is:' > $testroot/wt/gamma/delta.expected
126 echo 'delta' >> $testroot/wt/gamma/delta.expected
127 cmp -s $testroot/wt/gamma/delta.expected $testroot/wt/gamma/delta
128 ret=$?
129 if [ $ret -ne 0 ]; then
130 diff -u $testroot/wt/gamma/delta.expected $testroot/wt/gamma/delta
131 test_done "$testroot" $ret
132 return 1
133 fi
135 jot 5 > $testroot/wt/eta.expected
136 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
137 ret=$?
138 if [ $ret -ne 0 ]; then
139 diff -u $testroot/wt/eta.expected $testroot/wt/eta
140 test_done "$testroot" $ret
141 return 1
142 fi
144 jot 103 | sed -e 's/^6$/six/' -e 's/60/sixty/' \
145 > $testroot/wt/numbers.expected
146 cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
147 ret=$?
148 if [ $ret -ne 0 ]; then
149 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
150 fi
151 test_done $testroot $ret
154 test_patch_dont_apply() {
155 local testroot=`test_init patch_dont_apply`
157 got checkout $testroot/repo $testroot/wt > /dev/null
158 ret=$?
159 if [ $ret -ne 0 ]; then
160 test_done $testroot $ret
161 return 1
162 fi
164 jot 100 > $testroot/wt/numbers
165 (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
166 >/dev/null
167 ret=$?
168 if [ $ret -ne 0 ]; then
169 test_done $testroot $ret
170 return 1
171 fi
173 cat <<EOF > $testroot/wt/patch
174 --- alpha
175 +++ alpha
176 @@ -1 +1,2 @@
177 +hatsuseno
178 alpha something
179 --- numbers
180 +++ /dev/null
181 @@ -1,9 +0,0 @@
182 -1
183 -2
184 -3
185 -4
186 -5
187 -6
188 -7
189 -8
190 -9
191 EOF
193 (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
194 ret=$?
195 if [ $ret -eq 0 ]; then # should fail
196 test_done $testroot 1
197 return 1
198 fi
200 cat <<EOF > $testroot/stdout.expected
201 # alpha
202 @@ -1,1 +1,2 @@ hunk failed to apply
203 # numbers
204 @@ -1,9 +0,0 @@ hunk failed to apply
205 Files where patch failed to apply: 2
206 EOF
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret=$?
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 fi
213 test_done $testroot $ret
216 test_patch_malformed() {
217 local testroot=`test_init patch_malformed`
219 got checkout $testroot/repo $testroot/wt > /dev/null
220 ret=$?
221 if [ $ret -ne 0 ]; then
222 test_done $testroot $ret
223 return 1
224 fi
226 # missing "@@"
227 cat <<EOF > $testroot/wt/patch
228 --- alpha
229 +++ alpha
230 @@ -1 +1,2
231 +hatsuseno
232 alpha
233 EOF
235 echo -n > $testroot/stdout.expected
236 echo "got: malformed patch" > $testroot/stderr.expected
238 (cd $testroot/wt && got patch patch) \
239 > $testroot/stdout \
240 2> $testroot/stderr
241 ret=$?
242 if [ $ret -eq 0 ]; then
243 echo "got managed to apply an invalid patch"
244 test_done $testroot 1
245 return 1
246 fi
248 cmp -s $testroot/stdout.expected $testroot/stdout
249 ret=$?
250 if [ $ret -ne 0 ]; then
251 diff -u $testroot/stdout.expected $testroot/stdout
252 test_done $testroot $ret
253 return 1
254 fi
256 cmp -s $testroot/stderr.expected $testroot/stderr
257 ret=$?
258 if [ $ret -ne 0 ]; then
259 diff -u $testroot/stderr.expected $testroot/stderr
260 test_done $testroot $ret
261 return 1
262 fi
264 # wrong first character
265 cat <<EOF > $testroot/wt/patch
266 --- alpha
267 +++ alpha
268 @@ -1 +1,2 @@
269 +hatsuseno
270 alpha
271 EOF
273 (cd $testroot/wt && got patch patch) \
274 > $testroot/stdout \
275 2> $testroot/stderr
276 ret=$?
277 if [ $ret -eq 0 ]; then
278 echo "got managed to apply an invalid patch"
279 test_done $testroot 1
280 return 1
281 fi
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret=$?
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done $testroot $ret
288 return 1
289 fi
291 cmp -s $testroot/stderr.expected $testroot/stderr
292 ret=$?
293 if [ $ret -ne 0 ]; then
294 diff -u $testroot/stderr.expected $testroot/stderr
295 test_done $testroot $ret
296 return 1
297 fi
299 # empty hunk
300 cat <<EOF > $testroot/wt/patch
301 diff --git a/alpha b/iota
302 --- a/alpha
303 +++ b/iota
304 @@ -0,0 +0,0 @@
305 EOF
307 (cd $testroot/wt && got patch patch) \
308 > $testroot/stdout \
309 2> $testroot/stderr
310 ret=$?
311 if [ $ret -eq 0 ]; then
312 echo "got managed to apply an invalid patch"
313 test_done $testroot 1
314 return 1
315 fi
317 cmp -s $testroot/stdout.expected $testroot/stdout
318 ret=$?
319 if [ $ret -ne 0 ]; then
320 diff -u $testroot/stdout.expected $testroot/stdout
321 test_done $testroot $ret
322 return 1
323 fi
325 cmp -s $testroot/stderr.expected $testroot/stderr
326 ret=$?
327 if [ $ret -ne 0 ]; then
328 diff -u $testroot/stderr.expected $testroot/stderr
329 test_done $testroot $ret
330 return 1
331 fi
333 test_done $testroot $ret
336 test_patch_no_patch() {
337 local testroot=`test_init patch_no_patch`
339 got checkout $testroot/repo $testroot/wt > /dev/null
340 ret=$?
341 if [ $ret -ne 0 ]; then
342 test_done $testroot $ret
343 return 1
344 fi
346 cat <<EOF > $testroot/wt/patch
347 hello world!
348 ...
350 some other nonsense
351 ...
353 there's no patch in here!
354 EOF
356 echo -n > $testroot/stdout.expected
357 echo "got: no patch found" > $testroot/stderr.expected
359 (cd $testroot/wt && got patch patch) \
360 > $testroot/stdout \
361 2> $testroot/stderr
362 ret=$?
363 if [ $ret -eq 0 ]; then # should fail
364 test_done $testroot 1
365 return 1
366 fi
368 cmp -s $testroot/stdout.expected $testroot/stdout
369 ret=$?
370 if [ $ret -ne 0 ]; then
371 diff -u $testroot/stdout.expected $testroot/stdout
372 test_done $testroot $ret
373 return 1
374 fi
376 cmp -s $testroot/stderr.expected $testroot/stderr
377 ret=$?
378 if [ $ret -ne 0 ]; then
379 diff -u $testroot/stderr.expected $testroot/stderr
380 test_done $testroot $ret
381 return 1
382 fi
384 test_done $testroot $ret
387 test_patch_equals_for_context() {
388 local testroot=`test_init patch_equals_for_context`
390 got checkout $testroot/repo $testroot/wt > /dev/null
391 ret=$?
392 if [ $ret -ne 0 ]; then
393 test_done $testroot $ret
394 return 1
395 fi
397 cat <<EOF > $testroot/wt/patch
398 --- alpha
399 +++ alpha
400 @@ -1 +1,2 @@
401 +hatsuseno
402 =alpha
403 EOF
405 echo "M alpha" > $testroot/stdout.expected
407 (cd $testroot/wt && got patch patch) > $testroot/stdout
408 ret=$?
409 if [ $ret -ne 0 ]; then
410 test_done $testroot $ret
411 return 1
412 fi
414 cmp -s $testroot/stdout.expected $testroot/stdout
415 ret=$?
416 if [ $ret -ne 0 ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
418 test_done $testroot $ret
419 return 1
420 fi
422 echo hatsuseno > $testroot/wt/alpha.expected
423 echo alpha >> $testroot/wt/alpha.expected
424 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
425 ret=$?
426 if [ $ret -ne 0 ]; then
427 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
428 fi
429 test_done $testroot $ret
432 test_patch_rename() {
433 local testroot=`test_init patch_rename`
435 got checkout $testroot/repo $testroot/wt > /dev/null
436 ret=$?
437 if [ $ret -ne 0 ]; then
438 test_done $testroot $ret
439 return 1
440 fi
442 cat <<EOF > $testroot/wt/patch
443 diff --git a/beta b/iota
444 similarity index 100%
445 rename from beta
446 rename to iota
447 diff --git a/alpha b/eta
448 --- a/alpha
449 +++ b/eta
450 @@ -1 +1 @@
451 -alpha
452 +eta
453 EOF
455 echo 'D beta' > $testroot/stdout.expected
456 echo 'A iota' >> $testroot/stdout.expected
457 echo 'D alpha' >> $testroot/stdout.expected
458 echo 'A eta' >> $testroot/stdout.expected
460 (cd $testroot/wt && got patch patch) > $testroot/stdout
461 ret=$?
462 if [ $ret -ne 0 ]; then
463 test_done $testroot $ret
464 return 1
465 fi
467 cmp -s $testroot/stdout.expected $testroot/stdout
468 ret=$?
469 if [ $ret -ne 0 ]; then
470 diff -u $testroot/stdout.expected $testroot/stdout
471 test_done $testroot $ret
472 return 1
473 fi
475 if [ -f $testroot/wt/alpha -o -f $testroot/wt/beta ]; then
476 echo "alpha or beta were not removed" >&2
477 test_done $testroot 1
478 return 1
479 fi
480 if [ ! -f $testroot/wt/iota -o ! -f $testroot/wt/eta ]; then
481 echo "iota or eta were not created" >&2
482 test_done $testroot 1
483 return 1
484 fi
486 echo beta > $testroot/wt/iota.expected
487 cmp -s $testroot/wt/iota.expected $testroot/wt/iota
488 ret=$?
489 if [ $ret -ne 0 ]; then
490 diff -u $testroot/wt/iota.expected $testroot/wt/iota
491 test_done $testroot $ret
492 return 1
493 fi
495 echo eta > $testroot/wt/eta.expected
496 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
497 ret=$?
498 if [ $ret -ne 0 ]; then
499 diff -u $testroot/wt/eta.expected $testroot/wt/eta
500 test_done $testroot $ret
501 return 1
502 fi
504 test_done $testroot $ret
507 test_patch_illegal_status() {
508 local testroot=`test_init patch_illegal_status`
510 got checkout $testroot/repo $testroot/wt > /dev/null
511 ret=$?
512 if [ $ret -ne 0 ]; then
513 test_done $testroot $ret
514 return 1
515 fi
517 # try to patch an obstructed file, add a versioned one, edit a
518 # non existent file and an unversioned one, and remove a
519 # non existent file.
520 cat <<EOF > $testroot/wt/patch
521 --- alpha
522 +++ alpha
523 @@ -1 +1,2 @@
524 alpha
525 +was edited
526 --- /dev/null
527 +++ beta
528 @@ -0,0 +1 @@
529 +beta
530 --- iota
531 +++ iota
532 @@ -1 +1 @@
533 -iota
534 +IOTA
535 --- kappa
536 +++ kappa
537 @@ -1 +1 @@
538 -kappa
539 +KAPPA
540 --- lambda
541 +++ /dev/null
542 @@ -1 +0,0 @@
543 -lambda
544 EOF
546 echo kappa > $testroot/wt/kappa
547 rm $testroot/wt/alpha
548 mkdir $testroot/wt/alpha
550 (cd $testroot/wt && got patch patch) > $testroot/stdout \
551 2> $testroot/stderr
552 ret=$?
553 if [ $ret -eq 0 ]; then
554 echo "edited a missing file" >&2
555 test_done $testroot 1
556 return 1
557 fi
559 cat <<EOF > $testroot/stdout.expected
560 # alpha
561 # beta
562 # iota
563 # kappa
564 # lambda
565 Files where patch failed to apply: 5
566 EOF
568 cat <<EOF > $testroot/stderr.expected
569 got: alpha: file has unexpected status
570 got: beta: file has unexpected status
571 got: iota: No such file or directory
572 got: kappa: file has unexpected status
573 got: lambda: No such file or directory
574 got: patch failed to apply
575 EOF
577 cmp -s $testroot/stdout.expected $testroot/stdout
578 ret=$?
579 if [ $ret -ne 0 ]; then
580 diff -u $testroot/stdout.expected $testroot/stdout
581 test_done $testroot $ret
582 return 1
583 fi
585 cmp -s $testroot/stderr.expected $testroot/stderr
586 ret=$?
587 if [ $ret -ne 0 ]; then
588 diff -u $testroot/stderr.expected $testroot/stderr
589 test_done $testroot $ret
590 return 1
591 fi
593 (cd $testroot/wt && got status) > $testroot/stdout
594 cat <<EOF > $testroot/stdout.expected
595 ~ alpha
596 ? kappa
597 ? patch
598 EOF
600 cmp -s $testroot/stdout.expected $testroot/stdout
601 ret=$?
602 if [ $ret -ne 0 ]; then
603 diff -u $testroot/stdout.expected $testroot/stdout
604 fi
605 test_done $testroot $ret
608 test_patch_nop() {
609 local testroot=`test_init patch_nop`
611 got checkout $testroot/repo $testroot/wt > /dev/null
612 ret=$?
613 if [ $ret -ne 0 ]; then
614 test_done $testroot $ret
615 return 1
616 fi
618 cat <<EOF > $testroot/wt/patch
619 --- alpha
620 +++ alpha
621 @@ -1 +1 @@
622 -alpha
623 +cafe alpha
624 --- beta
625 +++ /dev/null
626 @@ -1 +0,0 @@
627 -beta
628 diff --git a/gamma/delta b/gamma/delta.new
629 --- gamma/delta
630 +++ gamma/delta.new
631 @@ -1 +1 @@
632 -delta
633 +delta updated and renamed!
634 EOF
636 (cd $testroot/wt && got patch -n patch)
637 ret=$?
638 if [ $ret -ne 0 ]; then
639 test_done $testroot $ret
640 return 1
641 fi
643 # remove the patch to avoid the ? entry
644 rm $testroot/wt/patch
646 (cd $testroot/wt && got status) > $testroot/stdout
647 ret=$?
648 if [ $ret -ne 0 ]; then
649 test_done $testroot $ret
650 return 1
651 fi
653 echo -n > $testroot/stdout.expected
654 cmp -s $testroot/stdout.expected $testroot/stdout
655 ret=$?
656 if [ $ret -ne 0 ]; then
657 diff -u $testroot/stdout.expected $testroot/stdout
658 fi
659 test_done $testroot $ret
662 test_patch_preserve_perm() {
663 local testroot=`test_init patch_preserve_perm`
665 got checkout $testroot/repo $testroot/wt > /dev/null
666 ret=$?
667 if [ $ret -ne 0 ]; then
668 test_done $testroot $ret
669 return 1
670 fi
672 chmod +x $testroot/wt/alpha
673 (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
674 ret=$?
675 if [ $ret -ne 0 ]; then
676 test_done $testroot $ret
677 return 1
678 fi
680 cat <<EOF > $testroot/wt/patch
681 --- alpha
682 +++ alpha
683 @@ -1 +1,2 @@
684 alpha
685 +was edited
686 EOF
688 (cd $testroot/wt && got patch patch) > /dev/null
689 ret=$?
690 if [ $ret -ne 0 ]; then
691 test_done $testroot $ret
692 return 1
693 fi
695 if [ ! -x $testroot/wt/alpha ]; then
696 echo "alpha is no more executable!" >&2
697 test_done $testroot 1
698 return 1
699 fi
700 test_done $testroot 0
703 test_patch_create_dirs() {
704 local testroot=`test_init patch_create_dirs`
706 got checkout $testroot/repo $testroot/wt > /dev/null
707 ret=$?
708 if [ $ret -ne 0 ]; then
709 test_done $testroot $ret
710 return 1
711 fi
713 cat <<EOF > $testroot/wt/patch
714 --- /dev/null
715 +++ iota/kappa/lambda
716 @@ -0,0 +1 @@
717 +lambda
718 EOF
720 (cd $testroot/wt && got patch patch) > $testroot/stdout
721 ret=$?
722 if [ $ret -ne 0 ]; then
723 test_done $testroot $ret
724 return 1
725 fi
727 echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
728 cmp -s $testroot/stdout.expected $testroot/stdout
729 ret=$?
730 if [ $ret -ne 0 ]; then
731 diff -u $testroot/stdout.expected $testroot/stdout
732 test_done $testroot $ret
733 return 1
734 fi
736 if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
737 echo "file not created!" >&2
738 test_done $testroot $ret
739 return 1
740 fi
741 test_done $testroot 0
744 test_patch_with_offset() {
745 local testroot=`test_init patch_with_offset`
747 got checkout $testroot/repo $testroot/wt > /dev/null
748 ret=$?
749 if [ $ret -ne 0 ]; then
750 test_done $testroot $ret
751 return 1
752 fi
754 cat <<EOF > $testroot/wt/patch
755 --- numbers
756 +++ numbers
757 @@ -47,7 +47,7 @@
758 47
759 48
760 49
761 -50
762 +midway tru it!
763 51
764 52
765 53
766 @@ -87,7 +87,7 @@
767 87
768 88
769 89
770 -90
771 +almost there!
772 91
773 92
774 93
775 EOF
777 jot 100 > $testroot/wt/numbers
778 ed -s "$testroot/wt/numbers" <<EOF
779 1,10d
780 50r !jot 20
783 EOF
785 (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
786 > /dev/null
787 ret=$?
788 if [ $ret -ne 0 ]; then
789 test_done $testroot $ret
790 return 1
791 fi
793 (cd $testroot/wt && got patch patch) > $testroot/stdout
794 ret=$?
795 if [ $ret -ne 0 ]; then
796 test_done $testroot/wt $ret
797 return 1
798 fi
800 cat <<EOF > $testroot/stdout.expected
801 M numbers
802 @@ -47,7 +47,7 @@ applied with offset -10
803 @@ -87,7 +87,7 @@ applied with offset 10
804 EOF
806 cmp -s $testroot/stdout.expected $testroot/stdout
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 diff -u $testroot/stdout.expected $testroot/stdout
810 fi
811 test_done $testroot $ret
814 test_patch_prefer_new_path() {
815 local testroot=`test_init patch_orig`
817 got checkout $testroot/repo $testroot/wt > /dev/null
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 test_done $testroot $ret
821 return 1
822 fi
824 cat <<EOF > $testroot/wt/patch
825 --- alpha.orig
826 +++ alpha
827 @@ -1 +1,2 @@
828 alpha
829 +was edited
830 EOF
832 (cd $testroot/wt && got patch patch) > $testroot/stdout
833 ret=$?
834 if [ $ret -ne 0 ]; then
835 test_done $testroot $ret
836 return 1
837 fi
839 echo 'M alpha' > $testroot/stdout.expected
840 cmp -s $testroot/stdout.expected $testroot/stdout
841 ret=$?
842 if [ $ret -ne 0 ]; then
843 diff -u $testroot/stdout.expected $testroot/stdout
844 fi
845 test_done $testroot $ret
848 test_patch_no_newline() {
849 local testroot=`test_init patch_no_newline`
851 got checkout $testroot/repo $testroot/wt > /dev/null
852 ret=$?
853 if [ $ret -ne 0 ]; then
854 test_done $testroot $ret
855 return 1
856 fi
858 cat <<EOF > $testroot/wt/patch
859 --- /dev/null
860 +++ eta
861 @@ -0,0 +1 @@
862 +eta
863 \ No newline at end of file
864 EOF
866 (cd $testroot/wt && got patch patch) > $testroot/stdout
867 ret=$?
868 if [ $ret -ne 0 ]; then
869 test_done $testroot $ret
870 return 1
871 fi
873 echo "A eta" > $testroot/stdout.expected
874 cmp -s $testroot/stdout.expected $testroot/stdout
875 ret=$?
876 if [ $ret -ne 0 ]; then
877 diff -u $testroot/stdout.expected $testroot/stdout
878 test_done $testroot $ret
879 return 1
880 fi
882 echo -n eta > $testroot/wt/eta.expected
883 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
884 ret=$?
885 if [ $ret -ne 0 ]; then
886 diff -u $testroot/wt/eta.expected $testroot/wt/eta
887 test_done $testroot $ret
888 return 1
889 fi
891 (cd $testroot/wt && got commit -m 'add eta') > /dev/null
892 ret=$?
893 if [ $ret -ne 0 ]; then
894 test_done $testroot $ret
895 return 1
896 fi
898 cat <<EOF > $testroot/wt/patch
899 --- eta
900 +++ eta
901 @@ -1 +1 @@
902 -eta
903 \ No newline at end of file
904 +ETA
905 \ No newline at end of file
906 EOF
908 (cd $testroot/wt && got patch patch) > $testroot/stdout
909 ret=$?
910 if [ $ret -ne 0 ]; then
911 test_done $testroot $ret
912 return 1
913 fi
915 echo "M eta" > $testroot/stdout.expected
916 cmp -s $testroot/stdout.expected $testroot/stdout
917 ret=$?
918 if [ $ret -ne 0 ]; then
919 diff -u $testroot/stdout.expected $testroot/stdout
920 test_done $testroot $ret
921 return 1
922 fi
924 echo -n ETA > $testroot/wt/eta.expected
925 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
926 ret=$?
927 if [ $ret -ne 0 ]; then
928 diff -u $testroot/wt/eta.expected $testroot/wt/eta
929 test_done $testroot $ret
930 return 1
931 fi
933 (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
934 ret=$?
935 if [ $ret -ne 0 ]; then
936 test_done $testroot $ret
937 return 1
938 fi
940 cat <<EOF > $testroot/wt/patch
941 --- eta
942 +++ eta
943 @@ -1 +1 @@
944 -ETA
945 \ No newline at end of file
946 +eta
947 EOF
949 (cd $testroot/wt && got patch patch) > $testroot/stdout
950 ret=$?
951 if [ $ret -ne 0 ]; then
952 test_done $testroot $ret
953 return 1
954 fi
956 echo "M eta" > $testroot/stdout.expected
957 cmp -s $testroot/stdout.expected $testroot/stdout
958 ret=$?
959 if [ $ret -ne 0 ]; then
960 diff -u $testroot/stdout.expected $testroot/stdout
961 test_done $testroot $ret
962 return 1
963 fi
965 echo eta > $testroot/wt/eta.expected
966 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
967 ret=$?
968 if [ $ret -ne 0 ]; then
969 diff -u $testroot/wt/eta.expected $testroot/wt/eta
970 fi
971 test_done $testroot $ret
974 test_patch_strip() {
975 local testroot=`test_init patch_strip`
977 got checkout $testroot/repo $testroot/wt > /dev/null
978 ret=$?
979 if [ $ret -ne 0 ]; then
980 test_done $testroot $ret
981 return 1
982 fi
984 cat <<EOF > $testroot/wt/patch
985 --- foo/bar/alpha.orig
986 +++ foo/bar/alpha
987 @@ -1 +1 @@
988 -alpha
989 +ALPHA
990 EOF
992 (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
993 ret=$?
994 if [ $ret -ne 0 ]; then
995 test_done $testroot $ret
996 return 1
997 fi
999 echo "M alpha" >> $testroot/stdout.expected
1000 cmp -s $testroot/stdout.expected $testroot/stdout
1001 ret=$?
1002 if [ $ret -ne 0 ]; then
1003 diff -u $testroot/stdout.expected $testroot/stdout
1004 test_done $testroot $ret
1005 return 1
1008 (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1009 ret=$?
1010 if [ $ret -ne 0 ]; then
1011 test_done $testroot $ret
1012 return 1
1015 (cd $testroot/wt && got patch -p3 patch) \
1016 2> $testroot/stderr
1017 ret=$?
1018 if [ $ret -eq 0 ]; then
1019 echo "stripped more components than available!"
1020 test_done $testroot 1
1021 return 1
1024 cat <<EOF > $testroot/stderr.expected
1025 got: can't strip 1 path-components from foo/bar/alpha: bad path
1026 EOF
1028 cmp -s $testroot/stderr.expected $testroot/stderr
1029 ret=$?
1030 if [ $ret -ne 0 ]; then
1031 diff -u $testroot/stderr.expected $testroot/stderr
1033 test_done $testroot 0
1036 test_patch_whitespace() {
1037 local testroot=`test_init patch_whitespace`
1039 got checkout $testroot/repo $testroot/wt > /dev/null
1040 ret=$?
1041 if [ $ret -ne 0 ]; then
1042 test_done $testroot $ret
1043 return 1
1046 trailing=" "
1048 cat <<EOF > $testroot/wt/hello.c
1049 #include <stdio.h>
1051 int
1052 main(void)
1054 /* the trailing whitespace is on purpose */
1055 printf("hello, world\n");$trailing
1056 return 0;
1058 EOF
1060 (cd $testroot/wt && got add hello.c && got ci -m '+hello.c') \
1061 > /dev/null
1062 ret=$?
1063 if [ $ret -ne 0 ]; then
1064 test_done $testroot $ret
1065 return 1
1068 # test with a diff with various whitespace corruptions
1069 cat <<EOF > $testroot/wt/patch
1070 --- hello.c
1071 +++ hello.c
1072 @@ -5,5 +5,5 @@
1074 /* the trailing whitespace is on purpose */
1075 printf("hello, world\n");
1076 - return 0;
1077 + return 5; /* always fails */
1079 EOF
1081 (cd $testroot/wt && got patch patch) \
1082 2>$testroot/stderr >$testroot/stdout
1083 ret=$?
1084 if [ $ret -ne 0 ]; then
1085 echo "failed to apply diff" >&2
1086 test_done $testroot $ret
1087 return 1
1090 echo 'M hello.c' > $testroot/stdout.expected
1091 echo '@@ -5,5 +5,5 @@ hunk contains mangled whitespace' \
1092 >> $testroot/stdout.expected
1093 cmp -s $testroot/stdout.expected $testroot/stdout
1094 ret=$?
1095 if [ $ret -ne 0 ]; then
1096 diff -u $testroot/stdout.expected $testroot/stdout
1097 test_done $testroot $ret
1098 return 1
1101 cat <<EOF > $testroot/wt/hello.c.expected
1102 #include <stdio.h>
1104 int
1105 main(void)
1107 /* the trailing whitespace is on purpose */
1108 printf("hello, world\n");$trailing
1109 return 5; /* always fails */
1111 EOF
1113 cmp -s $testroot/wt/hello.c.expected $testroot/wt/hello.c
1114 ret=$?
1115 if [ $ret -ne 0 ]; then
1116 diff -u $testroot/wt/hello.c.expected $testroot/wt/hello.c
1118 test_done $testroot $ret
1121 test_patch_relative_paths() {
1122 local testroot=`test_init patch_relative_paths`
1124 got checkout $testroot/repo $testroot/wt > /dev/null
1125 ret=$?
1126 if [ $ret -ne 0 ]; then
1127 test_done $testroot $ret
1128 return 1
1131 cat <<EOF > $testroot/wt/gamma/patch
1132 --- delta
1133 +++ delta
1134 @@ -1 +1 @@
1135 -delta
1136 +DELTA
1137 --- /dev/null
1138 +++ eta
1139 @@ -0,0 +1 @@
1140 +eta
1141 EOF
1143 (cd $testroot/wt/gamma && got patch patch) > $testroot/stdout
1144 ret=$?
1145 if [ $ret -ne 0 ]; then
1146 test_done $testroot $ret
1147 return 1
1150 echo 'M gamma/delta' > $testroot/stdout.expected
1151 echo 'A gamma/eta' >> $testroot/stdout.expected
1153 cmp -s $testroot/stdout.expected $testroot/stdout
1154 ret=$?
1155 if [ $ret -ne 0 ]; then
1156 diff -u $testroot/stdout.expected $testroot/stdout
1158 test_done $testroot $ret
1161 test_patch_with_path_prefix() {
1162 local testroot=`test_init patch_with_path_prefix`
1164 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1165 ret=$?
1166 if [ $ret -ne 0 ]; then
1167 test_done $testroot $ret
1168 return 1
1171 cat <<EOF > $testroot/wt/patch
1172 --- delta
1173 +++ delta
1174 @@ -1 +1 @@
1175 -delta
1176 +DELTA
1177 --- /dev/null
1178 +++ eta
1179 @@ -0,0 +1 @@
1180 +eta
1181 EOF
1183 (cd $testroot/wt && got patch patch) > $testroot/stdout
1184 ret=$?
1185 if [ $ret -ne 0 ]; then
1186 test_done $testroot $ret
1187 return 1
1190 echo 'M delta' > $testroot/stdout.expected
1191 echo 'A eta' >> $testroot/stdout.expected
1193 cmp -s $testroot/stdout.expected $testroot/stdout
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 diff -u $testroot/stdout.expected $testroot/stdout
1198 test_done $testroot $ret
1201 test_patch_relpath_with_path_prefix() {
1202 local testroot=`test_init patch_relpaths_with_path_prefix`
1204 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1205 ret=$?
1206 if [ $ret -ne 0 ]; then
1207 test_done $testroot $ret
1208 return 1
1211 mkdir -p $testroot/wt/epsilon/zeta/
1213 cat <<EOF > $testroot/wt/patch
1214 --- /dev/null
1215 +++ zeta/theta
1216 @@ -0,0 +1 @@
1217 +theta
1218 EOF
1220 (cd $testroot/wt/epsilon/zeta && got patch -p1 $testroot/wt/patch) \
1221 > $testroot/stdout
1222 ret=$?
1223 if [ $ret -ne 0 ]; then
1224 test_done $testroot $ret
1225 return 1
1228 echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1230 cmp -s $testroot/stdout.expected $testroot/stdout
1231 ret=$?
1232 if [ $ret -ne 0 ]; then
1233 diff -u $testroot/stdout.expected $testroot/stdout
1234 test_done $testroot $ret
1235 return 1
1238 echo 'theta' > $testroot/theta.expected
1239 cmp -s $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1240 ret=$?
1241 if [ $ret -ne 0 ]; then
1242 diff -u $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1244 test_done $testroot $ret
1247 test_patch_reverse() {
1248 local testroot=`test_init patch_reverse`
1250 got checkout $testroot/repo $testroot/wt > /dev/null
1251 ret=$?
1252 if [ $ret -ne 0 ]; then
1253 test_done $testroot $ret
1254 return 1
1257 cat <<EOF > $testroot/wt/patch
1258 --- alpha
1259 +++ alpha
1260 @@ -1 +1 @@
1261 -ALPHA
1262 \ No newline at end of file
1263 +alpha
1264 EOF
1266 (cd $testroot/wt && got patch -R patch) > $testroot/stdout
1267 ret=$?
1268 if [ $ret -ne 0 ]; then
1269 test_done $testroot $ret
1270 return 1
1273 echo "M alpha" > $testroot/stdout.expected
1274 cmp -s $testroot/stdout.expected $testroot/stdout
1275 ret=$?
1276 if [ $ret -ne 0 ]; then
1277 diff -u $testroot/stdout.expected $testroot/stdout
1278 test_done $testroot $ret
1279 return 1
1282 echo -n ALPHA > $testroot/wt/alpha.expected
1283 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
1284 ret=$?
1285 if [ $ret -ne 0 ]; then
1286 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
1288 test_done $testroot $ret
1291 test_patch_merge_simple() {
1292 local testroot=`test_init patch_merge_simple`
1294 got checkout $testroot/repo $testroot/wt > /dev/null
1295 ret=$?
1296 if [ $ret -ne 0 ]; then
1297 test_done $testroot $ret
1298 return 1
1301 jot 10 > $testroot/wt/numbers
1302 chmod +x $testroot/wt/numbers
1303 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1304 > /dev/null
1305 ret=$?
1306 if [ $ret -ne 0 ]; then
1307 test_done $testroot $ret
1308 return 1
1311 jot 10 | sed 's/4/four/g' > $testroot/wt/numbers
1313 (cd $testroot/wt && got diff > $testroot/old.diff \
1314 && got revert numbers) >/dev/null
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 test_done $testroot $ret
1318 return 1
1321 jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1322 (cd $testroot/wt && got commit -m 'edit numbers') \
1323 > /dev/null
1324 ret=$?
1325 if [ $ret -ne 0 ]; then
1326 test_done $testroot $ret
1327 return 1
1330 (cd $testroot/wt && got patch $testroot/old.diff) \
1331 > $testroot/stdout
1332 ret=$?
1333 if [ $ret -ne 0 ]; then
1334 test_done $testroot $ret
1335 return 1
1338 echo 'G numbers' > $testroot/stdout.expected
1339 cmp -s $testroot/stdout $testroot/stdout.expected
1340 ret=$?
1341 if [ $ret -ne 0 ]; then
1342 diff -u $testroot/stdout $testroot/stdout.expected
1343 test_done $testroot $ret
1344 return 1
1347 jot 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1348 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1349 ret=$?
1350 if [ $ret -ne 0 ]; then
1351 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1352 test_done $testroot $ret
1353 return 1
1356 test -x $testroot/wt/numbers
1357 ret=$?
1358 if [ $ret -ne 0 ]; then
1359 echo "numbers lost the executable bit" >&2
1361 test_done $testroot $ret
1364 test_patch_merge_gitdiff() {
1365 local testroot=`test_init patch_merge_gitdiff`
1367 jot 10 > $testroot/repo/numbers
1368 (cd $testroot/repo && git add numbers && \
1369 git_commit $testroot/repo -m "nums")
1370 ret=$?
1371 if [ $ret -ne 0 ]; then
1372 test_done $testroot $ret
1373 return 1
1376 jot 10 | sed 's/4/four/g' > $testroot/repo/numbers
1377 (cd $testroot/repo && git diff > $testroot/old.diff)
1378 ret=$?
1379 if [ $ret -ne 0 ]; then
1380 test_done $testroot $ret
1381 return 1
1384 # restore numbers
1385 jot 10 > $testroot/repo/numbers
1387 jot 10 | sed 's/6/six/g' > $testroot/repo/numbers
1388 (cd $testroot/repo && git add numbers && \
1389 git_commit $testroot/repo -m "edit")
1390 ret=$?
1391 if [ $ret -ne 0 ]; then
1392 test_done $testroot $ret
1393 return 1
1396 # now work with got:
1397 got checkout $testroot/repo $testroot/wt > /dev/null
1398 ret=$?
1399 if [ $ret -ne 0 ]; then
1400 test_done $testroot $ret
1401 return 1
1404 (cd $testroot/wt && got patch $testroot/old.diff) > $testroot/stdout
1405 ret=$?
1406 if [ $ret -ne 0 ]; then
1407 test_done $testroot $ret
1408 return 1
1411 echo 'G numbers' > $testroot/stdout.expected
1412 cmp -s $testroot/stdout $testroot/stdout.expected
1413 ret=$?
1414 if [ $ret -ne 0 ]; then
1415 diff -u $testroot/stdout $testroot/stdout.expected
1417 test_done $testroot $ret
1420 test_patch_merge_base_provided() {
1421 local testroot=`test_init patch_merge_base_provided`
1423 got checkout $testroot/repo $testroot/wt >/dev/null
1424 ret=$?
1425 if [ $ret -ne 0 ]; then
1426 test_done $testroot $ret
1427 return 1
1430 jot 10 > $testroot/wt/numbers
1431 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1432 >/dev/null
1433 ret=$?
1434 if [ $ret -ne 0 ]; then
1435 test_done $testroot $ret
1436 return 1
1439 local commit_id=`git_show_head $testroot/repo`
1441 jot 10 | sed s/4/four/ > $testroot/wt/numbers
1443 # get rid of the metadata
1444 (cd $testroot/wt && got diff | sed -n '/^---/,$p' > patch) \
1445 >/dev/null
1447 jot 10 | sed s/6/six/ > $testroot/wt/numbers
1448 (cd $testroot/wt && got commit -m 'edit numbers') >/dev/null
1449 ret=$?
1450 if [ $ret -ne 0 ]; then
1451 test_done $testroot $ret
1452 return 1
1455 (cd $testroot/wt && got patch -c $commit_id patch) >$testroot/stdout
1456 ret=$?
1457 if [ $ret -ne 0 ]; then
1458 test_done $testroot $ret
1459 return 1
1462 echo 'G numbers' > $testroot/stdout.expected
1463 cmp -s $testroot/stdout $testroot/stdout.expected
1464 ret=$?
1465 if [ $ret -ne 0 ]; then
1466 diff -u $testroot/stdout $testroot/stdout.expected
1467 test_done $testroot $ret
1468 return 1
1471 jot 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1472 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1473 ret=$?
1474 if [ $ret -ne 0 ]; then
1475 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1477 test_done $testroot $ret
1480 test_patch_merge_conflict() {
1481 local testroot=`test_init patch_merge_conflict`
1483 got checkout $testroot/repo $testroot/wt > /dev/null
1484 ret=$?
1485 if [ $ret -ne 0 ]; then
1486 test_done $testroot $ret
1487 return 1
1490 jot 10 > $testroot/wt/numbers
1491 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1492 > /dev/null
1493 ret=$?
1494 if [ $ret -ne 0 ]; then
1495 test_done $testroot $ret
1496 return 1
1499 local commit_id=`git_show_head $testroot/repo`
1501 jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1502 echo ALPHA > $testroot/wt/alpha
1504 (cd $testroot/wt && got diff > $testroot/old.diff \
1505 && got revert alpha numbers) >/dev/null
1506 ret=$?
1507 if [ $ret -ne 0 ]; then
1508 test_done $testroot $ret
1509 return 1
1512 jot 10 | sed 's/6/3+3/g' > $testroot/wt/numbers
1513 jot -c 3 a > $testroot/wt/alpha
1514 (cd $testroot/wt && got commit -m 'edit alpha and numbers') \
1515 > /dev/null
1516 ret=$?
1517 if [ $ret -ne 0 ]; then
1518 test_done $testroot $ret
1519 return 1
1522 (cd $testroot/wt && got patch $testroot/old.diff) \
1523 > $testroot/stdout 2>/dev/null
1524 ret=$?
1525 if [ $ret -eq 0 ]; then
1526 echo "got patch merged a diff that should conflict" >&2
1527 test_done $testroot 1
1528 return 1
1531 echo 'C alpha' > $testroot/stdout.expected
1532 echo 'C numbers' >> $testroot/stdout.expected
1533 echo 'Files with merge conflicts: 2' >> $testroot/stdout.expected
1534 cmp -s $testroot/stdout $testroot/stdout.expected
1535 ret=$?
1536 if [ $ret -ne 0 ]; then
1537 diff -u $testroot/stdout $testroot/stdout.expected
1538 test_done $testroot $ret
1539 return 1
1542 # XXX: prefixing every line with a tab otherwise got thinks
1543 # the file has conflicts in it.
1544 cat <<-EOF > $testroot/wt/alpha.expected
1545 <<<<<<< --- alpha
1546 ALPHA
1547 ||||||| commit $commit_id
1548 alpha
1549 =======
1553 >>>>>>> +++ alpha
1554 EOF
1556 cat <<-EOF > $testroot/wt/numbers.expected
1562 <<<<<<< --- numbers
1563 six
1564 ||||||| commit $commit_id
1566 =======
1567 3+3
1568 >>>>>>> +++ numbers
1573 EOF
1575 cmp -s $testroot/wt/alpha $testroot/wt/alpha.expected
1576 ret=$?
1577 if [ $ret -ne 0 ]; then
1578 diff -u $testroot/wt/alpha $testroot/wt/alpha.expected
1579 test_done $testroot $ret
1580 return 1
1583 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1584 ret=$?
1585 if [ $ret -ne 0 ]; then
1586 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1588 test_done $testroot $ret
1591 test_patch_merge_unknown_blob() {
1592 local testroot=`test_init patch_merge_unknown_blob`
1594 got checkout $testroot/repo $testroot/wt > /dev/null
1595 ret=$?
1596 if [ $ret -ne 0 ]; then
1597 test_done $testroot $ret
1598 return 1
1601 cat <<EOF > $testroot/wt/patch
1602 I've got a
1603 diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
1604 with a
1605 blob - aaaabbbbccccddddeeeeffff0000111122223333
1606 and also a
1607 blob + 0000111122223333444455556666777788889999
1608 for this dummy diff
1609 --- alpha
1610 +++ alpha
1611 @@ -1 +1 @@
1612 -alpha
1613 +ALPHA
1614 will it work?
1615 EOF
1617 (cd $testroot/wt/ && got patch patch) > $testroot/stdout
1618 ret=$?
1619 if [ $ret -ne 0 ]; then
1620 test_done $testroot $ret
1621 return 1
1624 echo 'M alpha' > $testroot/stdout.expected
1625 cmp -s $testroot/stdout.expected $testroot/stdout
1626 ret=$?
1627 if [ $ret -ne 0 ]; then
1628 diff -u $testroot/stdout.expected $testroot/stdout
1629 test_done $testroot $ret
1630 return 1
1633 # try again without a `diff' header
1635 cat <<EOF > $testroot/wt/patch
1636 I've got a
1637 blob - aaaabbbbccccddddeeeeffff0000111122223333
1638 and also a
1639 blob + 0000111122223333444455556666777788889999
1640 for this dummy diff
1641 --- alpha
1642 +++ alpha
1643 @@ -1 +1 @@
1644 -alpha
1645 +ALPHA
1646 will it work?
1647 EOF
1649 (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1650 > $testroot/stdout
1651 ret=$?
1652 if [ $ret -ne 0 ]; then
1653 test_done $testroot $ret
1654 return 1
1657 echo 'M alpha' > $testroot/stdout.expected
1658 cmp -s $testroot/stdout.expected $testroot/stdout
1659 ret=$?
1660 if [ $ret -ne 0 ]; then
1661 diff -u $testroot/stdout.expected $testroot/stdout
1662 test_done $testroot $ret
1663 return 1
1666 # try again with a git-style diff
1668 cat <<EOF > $testroot/wt/patch
1669 diff --git a/alpha b/alpha
1670 index 0123456789ab..abcdef012345 100644
1671 --- a/alpha
1672 +++ b/alpha
1673 @@ -1 +1 @@
1674 -alpha
1675 +ALPHA
1676 EOF
1678 (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1679 > $testroot/stdout
1680 ret=$?
1681 if [ $ret -ne 0 ]; then
1682 test_done $testroot $ret
1683 return 1
1686 echo 'M alpha' > $testroot/stdout.expected
1687 cmp -s $testroot/stdout.expected $testroot/stdout
1688 ret=$?
1689 if [ $ret -ne 0 ]; then
1690 diff -u $testroot/stdout.expected $testroot/stdout
1692 test_done $testroot $ret
1695 test_patch_merge_reverse() {
1696 local testroot=`test_init patch_merge_simple`
1698 got checkout $testroot/repo $testroot/wt > /dev/null
1699 ret=$?
1700 if [ $ret -ne 0 ]; then
1701 test_done $testroot $ret
1702 return 1
1705 jot 10 > $testroot/wt/numbers
1706 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1707 > /dev/null
1708 ret=$?
1709 if [ $ret -ne 0 ]; then
1710 test_done $testroot $ret
1711 return 1
1714 local commit_id=`git_show_head $testroot/repo`
1716 jot 10 | sed s/5/five/g > $testroot/wt/numbers
1717 (cd $testroot/wt && got diff > $testroot/wt/patch \
1718 && got commit -m 'edit numbers') > /dev/null
1719 ret=$?
1720 if [ $ret -ne 0 ]; then
1721 test_done $testroot $ret
1722 return 1
1725 jot 10 | sed -e s/5/five/g -e s/6/six/g > $testroot/wt/numbers
1726 (cd $testroot/wt && got commit -m 'edit numbers again') >/dev/null
1727 ret=$?
1728 if [ $ret -ne 0 ]; then
1729 test_done $testroot $ret
1730 return 1
1733 (cd $testroot/wt && got patch -R patch) >/dev/null 2>&1
1734 ret=$?
1735 if [ $ret -eq 0 ]; then
1736 echo "unexpectedly reverted the patch" >&2
1737 test_done $testroot 1
1738 return 1
1741 cat <<-EOF > $testroot/wt/numbers.expected
1746 <<<<<<< --- numbers
1749 ||||||| +++ numbers
1750 five
1751 =======
1752 five
1753 six
1754 >>>>>>> commit $commit_id
1759 EOF
1761 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1762 ret=$?
1763 if [ $ret -ne 0 ]; then
1764 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1766 test_done $testroot $ret
1769 test_patch_newfile_xbit_got_diff() {
1770 local testroot=`test_init patch_newfile_xbit`
1772 got checkout $testroot/repo $testroot/wt > /dev/null
1773 ret=$?
1774 if [ $ret -ne 0 ]; then
1775 test_done $testroot $ret
1776 return 1
1779 cat <<EOF > $testroot/wt/patch
1780 blob - /dev/null
1781 blob + abcdef0123456789abcdef012345678901234567 (mode 755)
1782 --- /dev/null
1783 +++ xfile
1784 @@ -0,0 +1,1 @@
1785 +xfile
1786 EOF
1788 (cd $testroot/wt && got patch patch) > /dev/null
1789 ret=$?
1790 if [ $ret -ne 0 ]; then
1791 test_done $testroot $ret
1792 return 1
1795 if [ ! -x $testroot/wt/xfile ]; then
1796 echo "failed to set xbit on newfile" >&2
1797 test_done $testroot 1
1798 return 1
1801 echo xfile > $testroot/wt/xfile.expected
1802 cmp -s $testroot/wt/xfile $testroot/wt/xfile.expected
1803 ret=$?
1804 if [ $ret -ne 0 ]; then
1805 echo "fail"
1806 diff -u $testroot/wt/xfile $testroot/wt/xfile.expected
1809 test_done $testroot $ret
1812 test_patch_newfile_xbit_git_diff() {
1813 local testroot=`test_init patch_newfile_xbit`
1815 got checkout $testroot/repo $testroot/wt > /dev/null
1816 ret=$?
1817 if [ $ret -ne 0 ]; then
1818 test_done $testroot $ret
1819 return 1
1822 cat <<EOF > $testroot/wt/patch
1823 diff --git a/xfile b/xfile
1824 new file mode 100755
1825 index 00000000..abcdef01
1826 --- /dev/null
1827 +++ b/xfile
1828 @@ -0,0 +1,1 @@
1829 +xfile
1830 EOF
1832 (cd $testroot/wt && got patch patch) > /dev/null
1833 ret=$?
1834 if [ $ret -ne 0 ]; then
1835 test_done $testroot $ret
1836 return 1
1839 if [ ! -x $testroot/wt/xfile ]; then
1840 echo "failed to set xbit on newfile" >&2
1841 test_done $testroot 1
1842 return 1
1845 echo xfile > $testroot/wt/xfile.expected
1846 cmp -s $testroot/wt/xfile $testroot/wt/xfile.expected
1847 ret=$?
1848 if [ $ret -ne 0 ]; then
1849 echo "fail"
1850 diff -u $testroot/wt/xfile $testroot/wt/xfile.expected
1853 test_done $testroot $ret
1856 test_patch_umask() {
1857 local testroot=`test_init patch_umask`
1859 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1861 cat <<EOF >$testroot/wt/patch
1862 --- alpha
1863 +++ alpha
1864 @@ -1 +1 @@
1865 -alpha
1866 +modified alpha
1867 EOF
1869 # using a subshell to avoid clobbering global umask
1870 (umask 077 && cd "$testroot/wt" && got patch <patch) >/dev/null
1871 ret=$?
1872 if [ $ret -ne 0 ]; then
1873 test_done "$testroot" $ret
1874 return 1
1877 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1878 echo "alpha is not 0600 after patch" >&2
1879 ls -l "$testroot/wt/alpha" >&2
1880 test_done "$testroot" 1
1881 return 1
1884 test_done "$testroot" 0
1887 test_patch_remove_binary_file() {
1888 local testroot=`test_init patch_remove_binary_file`
1890 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
1891 test_done $testroot $ret
1892 return 1
1895 dd if=/dev/zero of=$testroot/wt/x bs=1 count=16 2>/dev/null >&2
1896 (cd $testroot/wt && got add x && got commit -m +x) >/dev/null
1898 (cd $testroot/wt && \
1899 got branch demo && \
1900 got rm x && \
1901 got ci -m -x &&
1902 got up -b master) >/dev/null
1904 echo 'D x' > $testroot/stdout.expected
1906 (cd $testroot/wt && got log -c demo -l 1 -p >patch)
1908 (cd $testroot/wt && got patch <patch) > $testroot/stdout
1909 if [ $? -ne 0 ]; then
1910 echo 'patch failed' >&2
1911 test_done $testroot 1
1912 return 1
1915 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
1916 diff -u $testroot/stdout.expected $testroot/stdout
1917 test_done $testroot 1
1918 return 1
1921 # try again using a git produced diff
1922 (cd $testroot/wt && got revert x) >/dev/null
1924 (cd $testroot/repo && git show demo) >$testroot/wt/patch
1926 (cd $testroot/wt && got patch <patch) > $testroot/stdout
1927 if [ $? -ne 0 ]; then
1928 echo 'patch failed' >&2
1929 test_done $testroot 1
1930 return 1
1933 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
1934 diff -u $testroot/stdout.expected $testroot/stdout
1935 test_done $testroot 1
1936 return 1
1939 # try again using a diff(1) style patch
1940 (cd $testroot/wt && got revert x) >/dev/null
1942 echo "Binary files x and /dev/null differ" >$testroot/wt/patch
1943 (cd $testroot/wt && got patch <patch) >$testroot/stdout
1944 if [ $? -ne 0 ]; then
1945 echo 'patch failed' >&2
1946 test_done $testroot 1
1947 return 1
1950 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
1951 diff -u $testroot/stdout.expected $testroot/stdout
1952 test_done $testroot 1
1953 return 1
1956 test_done $testroot 0
1959 test_parseargs "$@"
1960 run_test test_patch_basic
1961 run_test test_patch_dont_apply
1962 run_test test_patch_malformed
1963 run_test test_patch_no_patch
1964 run_test test_patch_equals_for_context
1965 run_test test_patch_rename
1966 run_test test_patch_illegal_status
1967 run_test test_patch_nop
1968 run_test test_patch_preserve_perm
1969 run_test test_patch_create_dirs
1970 run_test test_patch_with_offset
1971 run_test test_patch_prefer_new_path
1972 run_test test_patch_no_newline
1973 run_test test_patch_strip
1974 run_test test_patch_whitespace
1975 run_test test_patch_relative_paths
1976 run_test test_patch_with_path_prefix
1977 run_test test_patch_relpath_with_path_prefix
1978 run_test test_patch_reverse
1979 run_test test_patch_merge_simple
1980 run_test test_patch_merge_gitdiff
1981 run_test test_patch_merge_base_provided
1982 run_test test_patch_merge_conflict
1983 run_test test_patch_merge_unknown_blob
1984 run_test test_patch_merge_reverse
1985 run_test test_patch_newfile_xbit_got_diff
1986 run_test test_patch_newfile_xbit_git_diff
1987 run_test test_patch_umask
1988 run_test test_patch_remove_binary_file