3 # Copyright (c) 2022 Omar Polo <op@openbsd.org>
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.
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.
20 local testroot=`test_init patch_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ $ret -ne 0 ]; then
25 test_done $testroot $ret
29 jot 100 > $testroot/wt/numbers
30 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
33 if [ $ret -ne 0 ]; then
34 test_done "$testroot" $ret
38 cat <<EOF > $testroot/wt/patch
43 +alpha is my favourite character
90 (cd $testroot/wt && got patch patch) > $testroot/stdout
91 if [ $ret -ne 0 ]; then
92 test_done "$testroot" $ret
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
104 if [ $ret -ne 0 ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
106 test_done $testroot $ret
110 echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
111 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
113 if [ $ret -ne 0 ]; then
114 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
115 test_done "$testroot" $ret
119 if [ -f "$testroot/wt/beta" ]; then
120 echo "beta was not deleted!" >&2
121 test_done "$testroot" 1
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
129 if [ $ret -ne 0 ]; then
130 diff -u $testroot/wt/gamma/delta.expected $testroot/wt/gamma/delta
131 test_done "$testroot" $ret
135 jot 5 > $testroot/wt/eta.expected
136 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
138 if [ $ret -ne 0 ]; then
139 diff -u $testroot/wt/eta.expected $testroot/wt/eta
140 test_done "$testroot" $ret
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
148 if [ $ret -ne 0 ]; then
149 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
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
159 if [ $ret -ne 0 ]; then
160 test_done $testroot $ret
164 jot 100 > $testroot/wt/numbers
165 (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
168 if [ $ret -ne 0 ]; then
169 test_done $testroot $ret
173 cat <<EOF > $testroot/wt/patch
193 (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
195 if [ $ret -eq 0 ]; then # should fail
196 test_done $testroot 1
200 cat <<EOF > $testroot/stdout.expected
202 @@ -1,1 +1,2 @@ hunk failed to apply
204 @@ -1,9 +0,0 @@ hunk failed to apply
207 cmp -s $testroot/stdout.expected $testroot/stdout
209 if [ $ret -ne 0 ]; then
210 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done $testroot $ret
215 test_patch_malformed() {
216 local testroot=`test_init patch_malformed`
218 got checkout $testroot/repo $testroot/wt > /dev/null
220 if [ $ret -ne 0 ]; then
221 test_done $testroot $ret
226 cat <<EOF > $testroot/wt/patch
234 echo -n > $testroot/stdout.expected
235 echo "got: malformed patch" > $testroot/stderr.expected
237 (cd $testroot/wt && got patch patch) \
241 if [ $ret -eq 0 ]; then
242 echo "got managed to apply an invalid patch"
243 test_done $testroot 1
247 cmp -s $testroot/stdout.expected $testroot/stdout
249 if [ $ret -ne 0 ]; then
250 diff -u $testroot/stdout.expected $testroot/stdout
251 test_done $testroot $ret
255 cmp -s $testroot/stderr.expected $testroot/stderr
257 if [ $ret -ne 0 ]; then
258 diff -u $testroot/stderr.expected $testroot/stderr
259 test_done $testroot $ret
263 # wrong first character
264 cat <<EOF > $testroot/wt/patch
272 (cd $testroot/wt && got patch patch) \
276 if [ $ret -eq 0 ]; then
277 echo "got managed to apply an invalid patch"
278 test_done $testroot 1
282 cmp -s $testroot/stdout.expected $testroot/stdout
284 if [ $ret -ne 0 ]; then
285 diff -u $testroot/stdout.expected $testroot/stdout
286 test_done $testroot $ret
290 cmp -s $testroot/stderr.expected $testroot/stderr
292 if [ $ret -ne 0 ]; then
293 diff -u $testroot/stderr.expected $testroot/stderr
294 test_done $testroot $ret
299 cat <<EOF > $testroot/wt/patch
300 diff --git a/alpha b/iota
306 (cd $testroot/wt && got patch patch) \
310 if [ $ret -eq 0 ]; then
311 echo "got managed to apply an invalid patch"
312 test_done $testroot 1
316 cmp -s $testroot/stdout.expected $testroot/stdout
318 if [ $ret -ne 0 ]; then
319 diff -u $testroot/stdout.expected $testroot/stdout
320 test_done $testroot $ret
324 cmp -s $testroot/stderr.expected $testroot/stderr
326 if [ $ret -ne 0 ]; then
327 diff -u $testroot/stderr.expected $testroot/stderr
328 test_done $testroot $ret
332 test_done $testroot $ret
335 test_patch_no_patch() {
336 local testroot=`test_init patch_no_patch`
338 got checkout $testroot/repo $testroot/wt > /dev/null
340 if [ $ret -ne 0 ]; then
341 test_done $testroot $ret
345 cat <<EOF > $testroot/wt/patch
352 there's no patch in here!
355 echo -n > $testroot/stdout.expected
356 echo "got: no patch found" > $testroot/stderr.expected
358 (cd $testroot/wt && got patch patch) \
362 if [ $ret -eq 0 ]; then # should fail
363 test_done $testroot 1
367 cmp -s $testroot/stdout.expected $testroot/stdout
369 if [ $ret -ne 0 ]; then
370 diff -u $testroot/stdout.expected $testroot/stdout
371 test_done $testroot $ret
375 cmp -s $testroot/stderr.expected $testroot/stderr
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/stderr.expected $testroot/stderr
379 test_done $testroot $ret
383 test_done $testroot $ret
386 test_patch_equals_for_context() {
387 local testroot=`test_init patch_equals_for_context`
389 got checkout $testroot/repo $testroot/wt > /dev/null
391 if [ $ret -ne 0 ]; then
392 test_done $testroot $ret
396 cat <<EOF > $testroot/wt/patch
404 echo "M alpha" > $testroot/stdout.expected
406 (cd $testroot/wt && got patch patch) > $testroot/stdout
408 if [ $ret -ne 0 ]; then
409 test_done $testroot $ret
413 cmp -s $testroot/stdout.expected $testroot/stdout
415 if [ $ret -ne 0 ]; then
416 diff -u $testroot/stdout.expected $testroot/stdout
417 test_done $testroot $ret
421 echo hatsuseno > $testroot/wt/alpha.expected
422 echo alpha >> $testroot/wt/alpha.expected
423 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
425 if [ $ret -ne 0 ]; then
426 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
428 test_done $testroot $ret
431 test_patch_rename() {
432 local testroot=`test_init patch_rename`
434 got checkout $testroot/repo $testroot/wt > /dev/null
436 if [ $ret -ne 0 ]; then
437 test_done $testroot $ret
441 cat <<EOF > $testroot/wt/patch
442 diff --git a/beta b/iota
443 similarity index 100%
446 diff --git a/alpha b/eta
454 echo 'D beta' > $testroot/stdout.expected
455 echo 'A iota' >> $testroot/stdout.expected
456 echo 'D alpha' >> $testroot/stdout.expected
457 echo 'A eta' >> $testroot/stdout.expected
459 (cd $testroot/wt && got patch patch) > $testroot/stdout
461 if [ $ret -ne 0 ]; then
462 test_done $testroot $ret
466 cmp -s $testroot/stdout.expected $testroot/stdout
468 if [ $ret -ne 0 ]; then
469 diff -u $testroot/stdout.expected $testroot/stdout
470 test_done $testroot $ret
474 if [ -f $testroot/wt/alpha -o -f $testroot/wt/beta ]; then
475 echo "alpha or beta were not removed" >&2
476 test_done $testroot 1
479 if [ ! -f $testroot/wt/iota -o ! -f $testroot/wt/eta ]; then
480 echo "iota or eta were not created" >&2
481 test_done $testroot 1
485 echo beta > $testroot/wt/iota.expected
486 cmp -s $testroot/wt/iota.expected $testroot/wt/iota
488 if [ $ret -ne 0 ]; then
489 diff -u $testroot/wt/iota.expected $testroot/wt/iota
490 test_done $testroot $ret
494 echo eta > $testroot/wt/eta.expected
495 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
497 if [ $ret -ne 0 ]; then
498 diff -u $testroot/wt/eta.expected $testroot/wt/eta
499 test_done $testroot $ret
503 test_done $testroot $ret
506 test_patch_illegal_status() {
507 local testroot=`test_init patch_illegal_status`
509 got checkout $testroot/repo $testroot/wt > /dev/null
511 if [ $ret -ne 0 ]; then
512 test_done $testroot $ret
516 # try to patch an obstructed file, add a versioned one, edit a
517 # non existent file and an unversioned one, and remove a
519 cat <<EOF > $testroot/wt/patch
545 echo kappa > $testroot/wt/kappa
546 rm $testroot/wt/alpha
547 mkdir $testroot/wt/alpha
549 (cd $testroot/wt && got patch patch) > $testroot/stdout \
552 if [ $ret -eq 0 ]; then
553 echo "edited a missing file" >&2
554 test_done $testroot 1
558 cat <<EOF > $testroot/stdout.expected
566 cat <<EOF > $testroot/stderr.expected
567 got: alpha: file has unexpected status
568 got: beta: file has unexpected status
569 got: iota: No such file or directory
570 got: kappa: file has unexpected status
571 got: lambda: No such file or directory
572 got: patch failed to apply
575 cmp -s $testroot/stdout.expected $testroot/stdout
577 if [ $ret -ne 0 ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 test_done $testroot $ret
583 cmp -s $testroot/stderr.expected $testroot/stderr
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stderr.expected $testroot/stderr
587 test_done $testroot $ret
591 (cd $testroot/wt && got status) > $testroot/stdout
592 cat <<EOF > $testroot/stdout.expected
598 cmp -s $testroot/stdout.expected $testroot/stdout
600 if [ $ret -ne 0 ]; then
601 diff -u $testroot/stdout.expected $testroot/stdout
603 test_done $testroot $ret
607 local testroot=`test_init patch_nop`
609 got checkout $testroot/repo $testroot/wt > /dev/null
611 if [ $ret -ne 0 ]; then
612 test_done $testroot $ret
616 cat <<EOF > $testroot/wt/patch
626 diff --git a/gamma/delta b/gamma/delta.new
631 +delta updated and renamed!
634 (cd $testroot/wt && got patch -n patch)
636 if [ $ret -ne 0 ]; then
637 test_done $testroot $ret
641 # remove the patch to avoid the ? entry
642 rm $testroot/wt/patch
644 (cd $testroot/wt && got status) > $testroot/stdout
646 if [ $ret -ne 0 ]; then
647 test_done $testroot $ret
651 echo -n > $testroot/stdout.expected
652 cmp -s $testroot/stdout.expected $testroot/stdout
654 if [ $ret -ne 0 ]; then
655 diff -u $testroot/stdout.expected $testroot/stdout
657 test_done $testroot $ret
660 test_patch_preserve_perm() {
661 local testroot=`test_init patch_preserve_perm`
663 got checkout $testroot/repo $testroot/wt > /dev/null
665 if [ $ret -ne 0 ]; then
666 test_done $testroot $ret
670 chmod +x $testroot/wt/alpha
671 (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
673 if [ $ret -ne 0 ]; then
674 test_done $testroot $ret
678 cat <<EOF > $testroot/wt/patch
686 (cd $testroot/wt && got patch patch) > /dev/null
688 if [ $ret -ne 0 ]; then
689 test_done $testroot $ret
693 if [ ! -x $testroot/wt/alpha ]; then
694 echo "alpha is no more executable!" >&2
695 test_done $testroot 1
698 test_done $testroot 0
701 test_patch_create_dirs() {
702 local testroot=`test_init patch_create_dirs`
704 got checkout $testroot/repo $testroot/wt > /dev/null
706 if [ $ret -ne 0 ]; then
707 test_done $testroot $ret
711 cat <<EOF > $testroot/wt/patch
713 +++ iota/kappa/lambda
718 (cd $testroot/wt && got patch patch) > $testroot/stdout
720 if [ $ret -ne 0 ]; then
721 test_done $testroot $ret
725 echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
726 cmp -s $testroot/stdout.expected $testroot/stdout
728 if [ $ret -ne 0 ]; then
729 diff -u $testroot/stdout.expected $testroot/stdout
730 test_done $testroot $ret
734 if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
735 echo "file not created!" >&2
736 test_done $testroot $ret
739 test_done $testroot 0
742 test_patch_with_offset() {
743 local testroot=`test_init patch_with_offset`
745 got checkout $testroot/repo $testroot/wt > /dev/null
747 if [ $ret -ne 0 ]; then
748 test_done $testroot $ret
752 cat <<EOF > $testroot/wt/patch
775 jot 100 > $testroot/wt/numbers
776 ed $testroot/wt/numbers <<EOF > /dev/null 2> /dev/null
783 (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
786 if [ $ret -ne 0 ]; then
787 test_done $testroot $ret
791 (cd $testroot/wt && got patch patch) > $testroot/stdout
793 if [ $ret -ne 0 ]; then
794 test_done $testroot/wt $ret
798 cat <<EOF > $testroot/stdout.expected
800 @@ -47,7 +47,7 @@ applied with offset -10
801 @@ -87,7 +87,7 @@ applied with offset 10
804 cmp -s $testroot/stdout.expected $testroot/stdout
806 if [ $ret -ne 0 ]; then
807 diff -u $testroot/stdout.expected $testroot/stdout
809 test_done $testroot $ret
812 test_patch_prefer_new_path() {
813 local testroot=`test_init patch_orig`
815 got checkout $testroot/repo $testroot/wt > /dev/null
817 if [ $ret -ne 0 ]; then
818 test_done $testroot $ret
822 cat <<EOF > $testroot/wt/patch
830 (cd $testroot/wt && got patch patch) > $testroot/stdout
832 if [ $ret -ne 0 ]; then
833 test_done $testroot $ret
837 echo 'M alpha' > $testroot/stdout.expected
838 cmp -s $testroot/stdout.expected $testroot/stdout
840 if [ $ret -ne 0 ]; then
841 diff -u $testroot/stdout.expected $testroot/stdout
843 test_done $testroot $ret
846 test_patch_no_newline() {
847 local testroot=`test_init patch_no_newline`
849 got checkout $testroot/repo $testroot/wt > /dev/null
851 if [ $ret -ne 0 ]; then
852 test_done $testroot $ret
856 cat <<EOF > $testroot/wt/patch
861 \ No newline at end of file
864 (cd $testroot/wt && got patch patch) > $testroot/stdout
866 if [ $ret -ne 0 ]; then
867 test_done $testroot $ret
871 echo "A eta" > $testroot/stdout.expected
872 cmp -s $testroot/stdout.expected $testroot/stdout
874 if [ $ret -ne 0 ]; then
875 diff -u $testroot/stdout.expected $testroot/stdout
876 test_done $testroot $ret
880 echo -n eta > $testroot/wt/eta.expected
881 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
883 if [ $ret -ne 0 ]; then
884 diff -u $testroot/wt/eta.expected $testroot/wt/eta
885 test_done $testroot $ret
889 (cd $testroot/wt && got commit -m 'add eta') > /dev/null
891 if [ $ret -ne 0 ]; then
892 test_done $testroot $ret
896 cat <<EOF > $testroot/wt/patch
901 \ No newline at end of file
903 \ No newline at end of file
906 (cd $testroot/wt && got patch patch) > $testroot/stdout
908 if [ $ret -ne 0 ]; then
909 test_done $testroot $ret
913 echo "M eta" > $testroot/stdout.expected
914 cmp -s $testroot/stdout.expected $testroot/stdout
916 if [ $ret -ne 0 ]; then
917 diff -u $testroot/stdout.expected $testroot/stdout
918 test_done $testroot $ret
922 echo -n ETA > $testroot/wt/eta.expected
923 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
925 if [ $ret -ne 0 ]; then
926 diff -u $testroot/wt/eta.expected $testroot/wt/eta
927 test_done $testroot $ret
931 (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
933 if [ $ret -ne 0 ]; then
934 test_done $testroot $ret
938 cat <<EOF > $testroot/wt/patch
943 \ No newline at end of file
947 (cd $testroot/wt && got patch patch) > $testroot/stdout
949 if [ $ret -ne 0 ]; then
950 test_done $testroot $ret
954 echo "M eta" > $testroot/stdout.expected
955 cmp -s $testroot/stdout.expected $testroot/stdout
957 if [ $ret -ne 0 ]; then
958 diff -u $testroot/stdout.expected $testroot/stdout
959 test_done $testroot $ret
963 echo eta > $testroot/wt/eta.expected
964 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
966 if [ $ret -ne 0 ]; then
967 diff -u $testroot/wt/eta.expected $testroot/wt/eta
969 test_done $testroot $ret
973 local testroot=`test_init patch_strip`
975 got checkout $testroot/repo $testroot/wt > /dev/null
977 if [ $ret -ne 0 ]; then
978 test_done $testroot $ret
982 cat <<EOF > $testroot/wt/patch
983 --- foo/bar/alpha.orig
990 (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
992 if [ $ret -ne 0 ]; then
993 test_done $testroot $ret
997 echo "M alpha" >> $testroot/stdout.expected
998 cmp -s $testroot/stdout.expected $testroot/stdout
1000 if [ $ret -ne 0 ]; then
1001 diff -u $testroot/stdout.expected $testroot/stdout
1002 test_done $testroot $ret
1006 (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1008 if [ $ret -ne 0 ]; then
1009 test_done $testroot $ret
1013 (cd $testroot/wt && got patch -p3 patch) \
1016 if [ $ret -eq 0 ]; then
1017 echo "stripped more components than available!"
1018 test_done $testroot 1
1022 cat <<EOF > $testroot/stderr.expected
1023 got: can't strip 1 path-components from foo/bar/alpha: bad path
1026 cmp -s $testroot/stderr.expected $testroot/stderr
1028 if [ $ret -ne 0 ]; then
1029 diff -u $testroot/stderr.expected $testroot/stderr
1031 test_done $testroot 0
1034 test_patch_whitespace() {
1035 local testroot=`test_init patch_whitespace`
1037 got checkout $testroot/repo $testroot/wt > /dev/null
1039 if [ $ret -ne 0 ]; then
1040 test_done $testroot $ret
1046 cat <<EOF > $testroot/wt/hello.c
1052 /* the trailing whitespace is on purpose */
1053 printf("hello, world\n");$trailing
1058 (cd $testroot/wt && got add hello.c && got ci -m '+hello.c') \
1061 if [ $ret -ne 0 ]; then
1062 test_done $testroot $ret
1066 # test with a diff with various whitespace corruptions
1067 cat <<EOF > $testroot/wt/patch
1072 /* the trailing whitespace is on purpose */
1073 printf("hello, world\n");
1075 + return 5; /* always fails */
1079 (cd $testroot/wt && got patch patch) \
1080 2>$testroot/stderr >$testroot/stdout
1082 if [ $ret -ne 0 ]; then
1083 echo "failed to apply diff" >&2
1084 test_done $testroot $ret
1088 echo 'M hello.c' > $testroot/stdout.expected
1089 echo '@@ -5,5 +5,5 @@ hunk contains mangled whitespace' \
1090 >> $testroot/stdout.expected
1091 cmp -s $testroot/stdout.expected $testroot/stdout
1093 if [ $ret -ne 0 ]; then
1094 diff -u $testroot/stdout.expected $testroot/stdout
1095 test_done $testroot $ret
1099 cat <<EOF > $testroot/wt/hello.c.expected
1105 /* the trailing whitespace is on purpose */
1106 printf("hello, world\n");$trailing
1107 return 5; /* always fails */
1111 cmp -s $testroot/wt/hello.c.expected $testroot/wt/hello.c
1113 if [ $ret -ne 0 ]; then
1114 diff -u $testroot/wt/hello.c.expected $testroot/wt/hello.c
1116 test_done $testroot $ret
1119 test_patch_relative_paths() {
1120 local testroot=`test_init patch_relative_paths`
1122 got checkout $testroot/repo $testroot/wt > /dev/null
1124 if [ $ret -ne 0 ]; then
1125 test_done $testroot $ret
1129 cat <<EOF > $testroot/wt/gamma/patch
1141 (cd $testroot/wt/gamma && got patch patch) > $testroot/stdout
1143 if [ $ret -ne 0 ]; then
1144 test_done $testroot $ret
1148 echo 'M gamma/delta' > $testroot/stdout.expected
1149 echo 'A gamma/eta' >> $testroot/stdout.expected
1151 cmp -s $testroot/stdout.expected $testroot/stdout
1153 if [ $ret -ne 0 ]; then
1154 diff -u $testroot/stdout.expected $testroot/stdout
1156 test_done $testroot $ret
1159 test_patch_with_path_prefix() {
1160 local testroot=`test_init patch_with_path_prefix`
1162 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1164 if [ $ret -ne 0 ]; then
1165 test_done $testroot $ret
1169 cat <<EOF > $testroot/wt/patch
1181 (cd $testroot/wt && got patch patch) > $testroot/stdout
1183 if [ $ret -ne 0 ]; then
1184 test_done $testroot $ret
1188 echo 'M delta' > $testroot/stdout.expected
1189 echo 'A eta' >> $testroot/stdout.expected
1191 cmp -s $testroot/stdout.expected $testroot/stdout
1193 if [ $ret -ne 0 ]; then
1194 diff -u $testroot/stdout.expected $testroot/stdout
1196 test_done $testroot $ret
1199 test_patch_relpath_with_path_prefix() {
1200 local testroot=`test_init patch_relpaths_with_path_prefix`
1202 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
1204 if [ $ret -ne 0 ]; then
1205 test_done $testroot $ret
1209 mkdir -p $testroot/wt/epsilon/zeta/
1211 cat <<EOF > $testroot/wt/patch
1218 (cd $testroot/wt/epsilon/zeta && got patch -p1 $testroot/wt/patch) \
1221 if [ $ret -ne 0 ]; then
1222 test_done $testroot $ret
1226 echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1228 cmp -s $testroot/stdout.expected $testroot/stdout
1230 if [ $ret -ne 0 ]; then
1231 diff -u $testroot/stdout.expected $testroot/stdout
1232 test_done $testroot $ret
1236 echo 'theta' > $testroot/theta.expected
1237 cmp -s $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1239 if [ $ret -ne 0 ]; then
1240 diff -u $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
1242 test_done $testroot $ret
1245 test_patch_reverse() {
1246 local testroot=`test_init patch_reverse`
1248 got checkout $testroot/repo $testroot/wt > /dev/null
1250 if [ $ret -ne 0 ]; then
1251 test_done $testroot $ret
1255 cat <<EOF > $testroot/wt/patch
1260 \ No newline at end of file
1264 (cd $testroot/wt && got patch -R patch) > $testroot/stdout
1266 if [ $ret -ne 0 ]; then
1267 test_done $testroot $ret
1271 echo "M alpha" > $testroot/stdout.expected
1272 cmp -s $testroot/stdout.expected $testroot/stdout
1274 if [ $ret -ne 0 ]; then
1275 diff -u $testroot/stdout.expected $testroot/stdout
1276 test_done $testroot $ret
1280 echo -n ALPHA > $testroot/wt/alpha.expected
1281 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
1283 if [ $ret -ne 0 ]; then
1284 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
1286 test_done $testroot $ret
1289 test_patch_merge_simple() {
1290 local testroot=`test_init patch_merge_simple`
1292 got checkout $testroot/repo $testroot/wt > /dev/null
1294 if [ $ret -ne 0 ]; then
1295 test_done $testroot $ret
1299 jot 10 > $testroot/wt/numbers
1300 chmod +x $testroot/wt/numbers
1301 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1304 if [ $ret -ne 0 ]; then
1305 test_done $testroot $ret
1309 jot 10 | sed 's/4/four/g' > $testroot/wt/numbers
1311 (cd $testroot/wt && got diff > $testroot/old.diff \
1312 && got revert numbers) >/dev/null
1314 if [ $ret -ne 0 ]; then
1315 test_done $testroot $ret
1319 jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1320 (cd $testroot/wt && got commit -m 'edit numbers') \
1323 if [ $ret -ne 0 ]; then
1324 test_done $testroot $ret
1328 (cd $testroot/wt && got patch $testroot/old.diff) \
1331 if [ $ret -ne 0 ]; then
1332 test_done $testroot $ret
1336 echo 'G numbers' > $testroot/stdout.expected
1337 cmp -s $testroot/stdout $testroot/stdout.expected
1339 if [ $ret -ne 0 ]; then
1340 diff -u $testroot/stdout $testroot/stdout.expected
1341 test_done $testroot $ret
1345 jot 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1346 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1348 if [ $ret -ne 0 ]; then
1349 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1350 test_done $testroot $ret
1354 test -x $testroot/wt/numbers
1356 if [ $ret -ne 0 ]; then
1357 echo "numbers lost the executable bit" >&2
1359 test_done $testroot $ret
1362 test_patch_merge_gitdiff() {
1363 local testroot=`test_init patch_merge_gitdiff`
1365 jot 10 > $testroot/repo/numbers
1366 (cd $testroot/repo && git add numbers && \
1367 git_commit $testroot/repo -m "nums")
1369 if [ $ret -ne 0 ]; then
1370 test_done $testroot $ret
1374 jot 10 | sed 's/4/four/g' > $testroot/repo/numbers
1375 (cd $testroot/repo && git diff > $testroot/old.diff)
1377 if [ $ret -ne 0 ]; then
1378 test_done $testroot $ret
1383 jot 10 > $testroot/repo/numbers
1385 jot 10 | sed 's/6/six/g' > $testroot/repo/numbers
1386 (cd $testroot/repo && git add numbers && \
1387 git_commit $testroot/repo -m "edit")
1389 if [ $ret -ne 0 ]; then
1390 test_done $testroot $ret
1394 # now work with got:
1395 got checkout $testroot/repo $testroot/wt > /dev/null
1397 if [ $ret -ne 0 ]; then
1398 test_done $testroot $ret
1402 (cd $testroot/wt && got patch $testroot/old.diff) > $testroot/stdout
1404 if [ $ret -ne 0 ]; then
1405 test_done $testroot $ret
1409 echo 'G numbers' > $testroot/stdout.expected
1410 cmp -s $testroot/stdout $testroot/stdout.expected
1412 if [ $ret -ne 0 ]; then
1413 diff -u $testroot/stdout $testroot/stdout.expected
1415 test_done $testroot $ret
1418 test_patch_merge_base_provided() {
1419 local testroot=`test_init patch_merge_base_provided`
1421 got checkout $testroot/repo $testroot/wt >/dev/null
1423 if [ $ret -ne 0 ]; then
1424 test_done $testroot $ret
1428 jot 10 > $testroot/wt/numbers
1429 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1432 if [ $ret -ne 0 ]; then
1433 test_done $testroot $ret
1437 local commit_id=`git_show_head $testroot/repo`
1439 jot 10 | sed s/4/four/ > $testroot/wt/numbers
1441 # get rid of the metadata
1442 (cd $testroot/wt && got diff | sed -n '/^---/,$p' > patch) \
1445 jot 10 | sed s/6/six/ > $testroot/wt/numbers
1446 (cd $testroot/wt && got commit -m 'edit numbers') >/dev/null
1448 if [ $ret -ne 0 ]; then
1449 test_done $testroot $ret
1453 (cd $testroot/wt && got patch -c $commit_id patch) >$testroot/stdout
1455 if [ $ret -ne 0 ]; then
1456 test_done $testroot $ret
1460 echo 'G numbers' > $testroot/stdout.expected
1461 cmp -s $testroot/stdout $testroot/stdout.expected
1463 if [ $ret -ne 0 ]; then
1464 diff -u $testroot/stdout $testroot/stdout.expected
1465 test_done $testroot $ret
1469 jot 10 | sed -e s/4/four/ -e s/6/six/ > $testroot/wt/numbers.expected
1470 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1472 if [ $ret -ne 0 ]; then
1473 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1475 test_done $testroot $ret
1478 test_patch_merge_conflict() {
1479 local testroot=`test_init patch_merge_conflict`
1481 got checkout $testroot/repo $testroot/wt > /dev/null
1483 if [ $ret -ne 0 ]; then
1484 test_done $testroot $ret
1488 jot 10 > $testroot/wt/numbers
1489 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1492 if [ $ret -ne 0 ]; then
1493 test_done $testroot $ret
1497 local commit_id=`git_show_head $testroot/repo`
1499 jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1500 echo ALPHA > $testroot/wt/alpha
1502 (cd $testroot/wt && got diff > $testroot/old.diff \
1503 && got revert alpha numbers) >/dev/null
1505 if [ $ret -ne 0 ]; then
1506 test_done $testroot $ret
1510 jot 10 | sed 's/6/3+3/g' > $testroot/wt/numbers
1511 jot -c 3 a > $testroot/wt/alpha
1512 (cd $testroot/wt && got commit -m 'edit alpha and numbers') \
1515 if [ $ret -ne 0 ]; then
1516 test_done $testroot $ret
1520 (cd $testroot/wt && got patch $testroot/old.diff) \
1521 > $testroot/stdout 2>/dev/null
1523 if [ $ret -eq 0 ]; then
1524 echo "got patch merged a diff that should conflict" >&2
1525 test_done $testroot 0
1529 echo 'C alpha' > $testroot/stdout.expected
1530 echo 'C numbers' >> $testroot/stdout.expected
1531 cmp -s $testroot/stdout $testroot/stdout.expected
1533 if [ $ret -ne 0 ]; then
1534 diff -u $testroot/stdout $testroot/stdout.expected
1535 test_done $testroot $ret
1539 # XXX: prefixing every line with a tab otherwise got thinks
1540 # the file has conflicts in it.
1541 cat <<-EOF > $testroot/wt/alpha.expected
1544 ||||||| commit $commit_id
1553 cat <<-EOF > $testroot/wt/numbers.expected
1561 ||||||| commit $commit_id
1572 cmp -s $testroot/wt/alpha $testroot/wt/alpha.expected
1574 if [ $ret -ne 0 ]; then
1575 diff -u $testroot/wt/alpha $testroot/wt/alpha.expected
1576 test_done $testroot $ret
1580 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1582 if [ $ret -ne 0 ]; then
1583 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1585 test_done $testroot $ret
1588 test_patch_merge_unknown_blob() {
1589 local testroot=`test_init patch_merge_unknown_blob`
1591 got checkout $testroot/repo $testroot/wt > /dev/null
1593 if [ $ret -ne 0 ]; then
1594 test_done $testroot $ret
1598 cat <<EOF > $testroot/wt/patch
1600 diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
1602 blob - aaaabbbbccccddddeeeeffff0000111122223333
1604 blob + 0000111122223333444455556666777788889999
1614 (cd $testroot/wt/ && got patch patch) > $testroot/stdout
1616 if [ $ret -ne 0 ]; then
1617 test_done $testroot $ret
1621 echo 'M alpha' > $testroot/stdout.expected
1622 cmp -s $testroot/stdout.expected $testroot/stdout
1624 if [ $ret -ne 0 ]; then
1625 diff -u $testroot/stdout.expected $testroot/stdout
1626 test_done $testroot $ret
1630 # try again without a `diff' header
1632 cat <<EOF > $testroot/wt/patch
1634 blob - aaaabbbbccccddddeeeeffff0000111122223333
1636 blob + 0000111122223333444455556666777788889999
1646 (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1649 if [ $ret -ne 0 ]; then
1650 test_done $testroot $ret
1654 echo 'M alpha' > $testroot/stdout.expected
1655 cmp -s $testroot/stdout.expected $testroot/stdout
1657 if [ $ret -ne 0 ]; then
1658 diff -u $testroot/stdout.expected $testroot/stdout
1659 test_done $testroot $ret
1663 # try again with a git-style diff
1665 cat <<EOF > $testroot/wt/patch
1666 diff --git a/alpha b/alpha
1667 index 0123456789ab..abcdef012345 100644
1675 (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1678 if [ $ret -ne 0 ]; then
1679 test_done $testroot $ret
1683 echo 'M alpha' > $testroot/stdout.expected
1684 cmp -s $testroot/stdout.expected $testroot/stdout
1686 if [ $ret -ne 0 ]; then
1687 diff -u $testroot/stdout.expected $testroot/stdout
1689 test_done $testroot $ret
1692 test_patch_merge_reverse() {
1693 local testroot=`test_init patch_merge_simple`
1695 got checkout $testroot/repo $testroot/wt > /dev/null
1697 if [ $ret -ne 0 ]; then
1698 test_done $testroot $ret
1702 jot 10 > $testroot/wt/numbers
1703 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1706 if [ $ret -ne 0 ]; then
1707 test_done $testroot $ret
1711 local commit_id=`git_show_head $testroot/repo`
1713 jot 10 | sed s/5/five/g > $testroot/wt/numbers
1714 (cd $testroot/wt && got diff > $testroot/wt/patch \
1715 && got commit -m 'edit numbers') > /dev/null
1717 if [ $ret -ne 0 ]; then
1718 test_done $testroot $ret
1722 jot 10 | sed -e s/5/five/g -e s/6/six/g > $testroot/wt/numbers
1723 (cd $testroot/wt && got commit -m 'edit numbers again') >/dev/null
1725 if [ $ret -ne 0 ]; then
1726 test_done $testroot $ret
1730 (cd $testroot/wt && got patch -R patch) >/dev/null 2>&1
1732 if [ $ret -eq 0 ]; then
1733 echo "unexpectedly reverted the patch" >&2
1734 test_done $testroot 1
1738 cat <<-EOF > $testroot/wt/numbers.expected
1751 >>>>>>> commit $commit_id
1758 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
1760 if [ $ret -ne 0 ]; then
1761 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1763 test_done $testroot $ret
1767 run_test test_patch_basic
1768 run_test test_patch_dont_apply
1769 run_test test_patch_malformed
1770 run_test test_patch_no_patch
1771 run_test test_patch_equals_for_context
1772 run_test test_patch_rename
1773 run_test test_patch_illegal_status
1774 run_test test_patch_nop
1775 run_test test_patch_preserve_perm
1776 run_test test_patch_create_dirs
1777 run_test test_patch_with_offset
1778 run_test test_patch_prefer_new_path
1779 run_test test_patch_no_newline
1780 run_test test_patch_strip
1781 run_test test_patch_whitespace
1782 run_test test_patch_relative_paths
1783 run_test test_patch_with_path_prefix
1784 run_test test_patch_relpath_with_path_prefix
1785 run_test test_patch_reverse
1786 run_test test_patch_merge_simple
1787 run_test test_patch_merge_gitdiff
1788 run_test test_patch_merge_base_provided
1789 run_test test_patch_merge_conflict
1790 run_test test_patch_merge_unknown_blob
1791 run_test test_patch_merge_reverse