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.
19 test_patch_add_file() {
20 local testroot=`test_init patch_add_file`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ $ret -ne 0 ]; then
25 test_done $testroot $ret
29 cat <<EOF > $testroot/wt/patch
40 (cd $testroot/wt && got patch patch) > $testroot/stdout
42 if [ $ret -ne 0 ]; then
43 test_done $testroot $ret
47 echo "A eta" > $testroot/stdout.expected
48 cmp -s $testroot/stdout.expected $testroot/stdout
50 if [ $ret -ne 0 ]; then
51 diff -u $testroot/stdout.expected $testroot/stdout
52 test_done $testroot $ret
56 jot 5 > $testroot/wt/eta.expected
57 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
59 if [ $ret -ne 0 ]; then
60 diff -u $testroot/wt/eta.expected $testroot/wt/eta
62 test_done $testroot $ret
65 test_patch_rm_file() {
66 local testroot=`test_init patch_rm_file`
68 got checkout $testroot/repo $testroot/wt > /dev/null
70 if [ $ret -ne 0 ]; then
71 test_done $testroot $ret
75 cat <<EOF > $testroot/wt/patch
82 echo "D alpha" > $testroot/stdout.expected
84 (cd $testroot/wt && got patch patch) > $testroot/stdout
86 if [ $ret -ne 0 ]; then
87 test_done $testroot $ret
91 cmp -s $testroot/stdout.expected $testroot/stdout
93 if [ $ret -ne 0 ]; then
94 diff -u $testroot/stdout.expected $testroot/stdout
95 test_done $testroot $ret
99 if [ -f $testroot/wt/alpha ]; then
101 echo "alpha still exists!"
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
111 if [ $ret -ne 0 ]; then
112 test_done $testroot $ret
116 cat <<EOF > $testroot/wt/patch
121 +alpha is my favourite character
124 echo "M alpha" > $testroot/stdout.expected
126 (cd $testroot/wt && got patch patch) > $testroot/stdout
128 if [ $ret -ne 0 ]; then
129 test_done $testroot $ret
133 cmp -s $testroot/stdout.expected $testroot/stdout
135 if [ $ret -ne 0 ]; then
136 diff -u $testroot/stdout.expected $testroot/stdout
137 test_done $testroot $ret
141 echo 'alpha is my favourite character' > $testroot/wt/alpha.expected
142 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
144 if [ $ret -ne 0 ]; then
145 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
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
155 if [ $ret -ne 0 ]; then
156 test_done $testroot $ret
160 cat <<EOF > $testroot/wt/patch
168 echo "M alpha" > $testroot/stdout.expected
170 (cd $testroot/wt && got patch patch) > $testroot/stdout
172 if [ $ret -ne 0 ]; then
173 test_done $testroot $ret
177 cmp -s $testroot/stdout.expected $testroot/stdout
179 if [ $ret -ne 0 ]; then
180 diff -u $testroot/stdout.expected $testroot/stdout
181 test_done $testroot $ret
185 echo hatsuseno > $testroot/wt/alpha.expected
186 echo alpha >> $testroot/wt/alpha.expected
187 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
189 if [ $ret -ne 0 ]; then
190 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
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
200 if [ $ret -ne 0 ]; then
201 test_done $testroot $ret
205 jot 10 > $testroot/wt/numbers
206 (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
209 if [ $ret -ne 0 ]; then
210 test_done $testroot $ret
214 cat <<EOF > $testroot/wt/patch
228 echo "M numbers" > $testroot/stdout.expected
230 (cd $testroot/wt && got patch patch) > $testroot/stdout
232 if [ $ret -ne 0 ]; then
233 test_done $testroot $ret
237 cmp -s $testroot/stdout.expected $testroot/stdout
239 if [ $ret -ne 0 ]; then
240 diff -u $testroot/stdout.expected $testroot/stdout
241 test_done $testroot $ret
245 jot 10 | sed 's/6/foo/' > $testroot/wt/numbers.expected
246 cmp -s $testroot/wt/numbers.expected $testroot/wt/numbers
248 if [ $ret -ne 0 ]; then
249 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
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
259 if [ $ret -ne 0 ]; then
260 test_done $testroot $ret
264 jot 100 > $testroot/wt/numbers
265 (cd $testroot/wt/ && got add numbers && got ci -m 'add numbers') \
268 if [ $ret -ne 0 ]; then
269 test_done $testroot $ret
273 cat <<EOF > $testroot/wt/patch
303 echo "M numbers" > $testroot/stdout.expected
305 (cd $testroot/wt && got patch patch) > $testroot/stdout
307 if [ $ret -ne 0 ]; then
308 test_done $testroot $ret
312 cmp -s $testroot/stdout.expected $testroot/stdout
314 if [ $ret -ne 0 ]; then
315 diff -u $testroot/stdout.expected $testroot/stdout
316 test_done $testroot $ret
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
328 if [ $ret -ne 0 ]; then
329 diff -u $testroot/wt/numbers.expected $testroot/wt/numbers
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
339 if [ $ret -ne 0 ]; then
340 test_done $testroot $ret
344 cat <<EOF > $testroot/wt/patch
345 --- alpha Mon Mar 7 19:02:07 2022
346 +++ alpha Mon Mar 7 19:01:53 2022
351 --- beta Mon Mar 7 19:02:11 2022
352 +++ beta Mon Mar 7 19:01:46 2022
357 --- gamma/delta Mon Mar 7 19:02:17 2022
358 +++ gamma/delta Mon Mar 7 19:01:37 2022
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
370 if [ $ret -ne 0 ]; then
371 test_done $testroot $ret
375 cmp -s $testroot/stdout.expected $testroot/stdout
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 test_done $testroot $ret
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
390 if [ $ret -ne 0 ]; then
391 diff -u $testroot/wt/$f.expected $testroot/wt/$f
392 test_done $testroot $ret
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
405 if [ $ret -ne 0 ]; then
406 test_done $testroot $ret
410 jot 100 > $testroot/wt/numbers
411 (cd $testroot/wt && got add numbers && got commit -m 'add numbers') \
414 if [ $ret -ne 0 ]; then
415 test_done $testroot $ret
419 cat <<EOF > $testroot/wt/patch
439 (cd $testroot/wt && got patch patch) > $testroot/stdout 2> /dev/null
441 if [ $ret -eq 0 ]; then # should fail
442 test_done $testroot 1
446 cat <<EOF > $testroot/stdout.expected
448 @@ -1,1 +1,2 @@ hunk failed to apply
450 @@ -1,9 +0,0 @@ hunk failed to apply
453 cmp -s $testroot/stdout.expected $testroot/stdout
455 if [ $ret -ne 0 ]; then
456 diff -u $testroot/stdout.expected $testroot/stdout
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
466 if [ $ret -ne 0 ]; then
467 test_done $testroot $ret
472 cat <<EOF > $testroot/wt/patch
480 echo -n > $testroot/stdout.expected
481 echo "got: malformed patch" > $testroot/stderr.expected
483 (cd $testroot/wt && got patch patch) \
487 if [ $ret -eq 0 ]; then
488 echo "got managed to apply an invalid patch"
489 test_done $testroot 1
493 cmp -s $testroot/stdout.expected $testroot/stdout
495 if [ $ret -ne 0 ]; then
496 diff -u $testroot/stdout.expected $testroot/stdout
497 test_done $testroot $ret
501 cmp -s $testroot/stderr.expected $testroot/stderr
503 if [ $ret -ne 0 ]; then
504 diff -u $testroot/stderr.expected $testroot/stderr
505 test_done $testroot $ret
509 # wrong first character
510 cat <<EOF > $testroot/wt/patch
518 (cd $testroot/wt && got patch patch) \
522 if [ $ret -eq 0 ]; then
523 echo "got managed to apply an invalid patch"
524 test_done $testroot 1
528 cmp -s $testroot/stdout.expected $testroot/stdout
530 if [ $ret -ne 0 ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done $testroot $ret
536 cmp -s $testroot/stderr.expected $testroot/stderr
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stderr.expected $testroot/stderr
540 test_done $testroot $ret
545 cat <<EOF > $testroot/wt/patch
546 diff --git a/alpha b/iota
552 (cd $testroot/wt && got patch patch) \
556 if [ $ret -eq 0 ]; then
557 echo "got managed to apply an invalid patch"
558 test_done $testroot 1
562 cmp -s $testroot/stdout.expected $testroot/stdout
564 if [ $ret -ne 0 ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done $testroot $ret
570 cmp -s $testroot/stderr.expected $testroot/stderr
572 if [ $ret -ne 0 ]; then
573 diff -u $testroot/stderr.expected $testroot/stderr
574 test_done $testroot $ret
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
586 if [ $ret -ne 0 ]; then
587 test_done $testroot $ret
591 cat <<EOF > $testroot/wt/patch
598 there's no patch in here!
601 echo -n > $testroot/stdout.expected
602 echo "got: no patch found" > $testroot/stderr.expected
604 (cd $testroot/wt && got patch patch) \
608 if [ $ret -eq 0 ]; then # should fail
609 test_done $testroot 1
613 cmp -s $testroot/stdout.expected $testroot/stdout
615 if [ $ret -ne 0 ]; then
616 diff -u $testroot/stdout.expected $testroot/stdout
617 test_done $testroot $ret
621 cmp -s $testroot/stderr.expected $testroot/stderr
623 if [ $ret -ne 0 ]; then
624 diff -u $testroot/stderr.expected $testroot/stderr
625 test_done $testroot $ret
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
637 if [ $ret -ne 0 ]; then
638 test_done $testroot $ret
642 cat <<EOF > $testroot/wt/patch
650 echo "M alpha" > $testroot/stdout.expected
652 (cd $testroot/wt && got patch patch) > $testroot/stdout
654 if [ $ret -ne 0 ]; then
655 test_done $testroot $ret
659 cmp -s $testroot/stdout.expected $testroot/stdout
661 if [ $ret -ne 0 ]; then
662 diff -u $testroot/stdout.expected $testroot/stdout
663 test_done $testroot $ret
667 echo hatsuseno > $testroot/wt/alpha.expected
668 echo alpha >> $testroot/wt/alpha.expected
669 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
671 if [ $ret -ne 0 ]; then
672 diff -u $testroot/wt/alpha.expected $testroot/wt/alpha
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
682 if [ $ret -ne 0 ]; then
683 test_done $testroot $ret
687 cat <<EOF > $testroot/wt/patch
688 diff --git a/beta b/iota
689 similarity index 100%
692 diff --git a/alpha b/eta
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
707 if [ $ret -ne 0 ]; then
708 test_done $testroot $ret
712 cmp -s $testroot/stdout.expected $testroot/stdout
714 if [ $ret -ne 0 ]; then
715 diff -u $testroot/stdout.expected $testroot/stdout
716 test_done $testroot $ret
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
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
731 echo beta > $testroot/wt/iota.expected
732 cmp -s $testroot/wt/iota.expected $testroot/wt/iota
734 if [ $ret -ne 0 ]; then
735 diff -u $testroot/wt/iota.expected $testroot/wt/iota
736 test_done $testroot $ret
740 echo eta > $testroot/wt/eta.expected
741 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/wt/eta.expected $testroot/wt/eta
745 test_done $testroot $ret
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
757 if [ $ret -ne 0 ]; then
758 test_done $testroot $ret
762 # try to patch an obstructed file, add a versioned one, edit a
763 # non existent file and an unversioned one, and remove a
765 cat <<EOF > $testroot/wt/patch
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 \
798 if [ $ret -eq 0 ]; then
799 echo "edited a missing file" >&2
800 test_done $testroot 1
804 cat <<EOF > $testroot/stdout.expected
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
821 cmp -s $testroot/stdout.expected $testroot/stdout
823 if [ $ret -ne 0 ]; then
824 diff -u $testroot/stdout.expected $testroot/stdout
825 test_done $testroot $ret
829 cmp -s $testroot/stderr.expected $testroot/stderr
831 if [ $ret -ne 0 ]; then
832 diff -u $testroot/stderr.expected $testroot/stderr
833 test_done $testroot $ret
837 (cd $testroot/wt && got status) > $testroot/stdout
838 cat <<EOF > $testroot/stdout.expected
844 cmp -s $testroot/stdout.expected $testroot/stdout
846 if [ $ret -ne 0 ]; then
847 diff -u $testroot/stdout.expected $testroot/stdout
849 test_done $testroot $ret
853 local testroot=`test_init patch_nop`
855 got checkout $testroot/repo $testroot/wt > /dev/null
857 if [ $ret -ne 0 ]; then
858 test_done $testroot $ret
862 cat <<EOF > $testroot/wt/patch
872 diff --git a/gamma/delta b/gamma/delta.new
877 +delta updated and renamed!
880 (cd $testroot/wt && got patch -n patch)
882 if [ $ret -ne 0 ]; then
883 test_done $testroot $ret
887 # remove the patch to avoid the ? entry
888 rm $testroot/wt/patch
890 (cd $testroot/wt && got status) > $testroot/stdout
892 if [ $ret -ne 0 ]; then
893 test_done $testroot $ret
897 echo -n > $testroot/stdout.expected
898 cmp -s $testroot/stdout.expected $testroot/stdout
900 if [ $ret -ne 0 ]; then
901 diff -u $testroot/stdout.expected $testroot/stdout
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
911 if [ $ret -ne 0 ]; then
912 test_done $testroot $ret
916 chmod +x $testroot/wt/alpha
917 (cd $testroot/wt && got commit -m 'alpha executable') > /dev/null
919 if [ $ret -ne 0 ]; then
920 test_done $testroot $ret
924 cat <<EOF > $testroot/wt/patch
932 (cd $testroot/wt && got patch patch) > /dev/null
934 if [ $ret -ne 0 ]; then
935 test_done $testroot $ret
939 if [ ! -x $testroot/wt/alpha ]; then
940 echo "alpha is no more executable!" >&2
941 test_done $testroot 1
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
952 if [ $ret -ne 0 ]; then
953 test_done $testroot $ret
957 cat <<EOF > $testroot/wt/patch
959 +++ iota/kappa/lambda
964 (cd $testroot/wt && got patch patch) > $testroot/stdout
966 if [ $ret -ne 0 ]; then
967 test_done $testroot $ret
971 echo 'A iota/kappa/lambda' >> $testroot/stdout.expected
972 cmp -s $testroot/stdout.expected $testroot/stdout
974 if [ $ret -ne 0 ]; then
975 diff -u $testroot/stdout.expected $testroot/stdout
976 test_done $testroot $ret
980 if [ ! -f $testroot/wt/iota/kappa/lambda ]; then
981 echo "file not created!" >&2
982 test_done $testroot $ret
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
993 if [ $ret -ne 0 ]; then
994 test_done $testroot $ret
998 cat <<EOF > $testroot/wt/patch
1021 jot 100 > $testroot/wt/numbers
1022 ed $testroot/wt/numbers <<EOF > /dev/null 2> /dev/null
1029 (cd $testroot/wt && got add numbers && got commit -m '+numbers') \
1032 if [ $ret -ne 0 ]; then
1033 test_done $testroot $ret
1037 (cd $testroot/wt && got patch patch) > $testroot/stdout
1039 if [ $ret -ne 0 ]; then
1040 test_done $testroot/wt $ret
1044 cat <<EOF > $testroot/stdout.expected
1046 @@ -47,7 +47,7 @@ applied with offset -10
1047 @@ -87,7 +87,7 @@ applied with offset 10
1050 cmp -s $testroot/stdout.expected $testroot/stdout
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
1063 if [ $ret -ne 0 ]; then
1064 test_done $testroot $ret
1068 cat <<EOF > $testroot/wt/patch
1076 (cd $testroot/wt && got patch patch) > $testroot/stdout
1078 if [ $ret -ne 0 ]; then
1079 test_done $testroot $ret
1083 echo 'M alpha' > $testroot/stdout.expected
1084 cmp -s $testroot/stdout.expected $testroot/stdout
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
1097 if [ $ret -ne 0 ]; then
1098 test_done $testroot $ret
1102 cat <<EOF > $testroot/wt/patch
1107 \ No newline at end of file
1110 (cd $testroot/wt && got patch patch) > $testroot/stdout
1112 if [ $ret -ne 0 ]; then
1113 test_done $testroot $ret
1117 echo "A eta" > $testroot/stdout.expected
1118 cmp -s $testroot/stdout.expected $testroot/stdout
1120 if [ $ret -ne 0 ]; then
1121 diff -u $testroot/stdout.expected $testroot/stdout
1122 test_done $testroot $ret
1126 echo -n eta > $testroot/wt/eta.expected
1127 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1129 if [ $ret -ne 0 ]; then
1130 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1131 test_done $testroot $ret
1135 (cd $testroot/wt && got commit -m 'add eta') > /dev/null
1137 if [ $ret -ne 0 ]; then
1138 test_done $testroot $ret
1142 cat <<EOF > $testroot/wt/patch
1147 \ No newline at end of file
1149 \ No newline at end of file
1152 (cd $testroot/wt && got patch patch) > $testroot/stdout
1154 if [ $ret -ne 0 ]; then
1155 test_done $testroot $ret
1159 echo "M eta" > $testroot/stdout.expected
1160 cmp -s $testroot/stdout.expected $testroot/stdout
1162 if [ $ret -ne 0 ]; then
1163 diff -u $testroot/stdout.expected $testroot/stdout
1164 test_done $testroot $ret
1168 echo -n ETA > $testroot/wt/eta.expected
1169 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
1171 if [ $ret -ne 0 ]; then
1172 diff -u $testroot/wt/eta.expected $testroot/wt/eta
1173 test_done $testroot $ret
1177 (cd $testroot/wt && got commit -m 'edit eta') > /dev/null
1179 if [ $ret -ne 0 ]; then
1180 test_done $testroot $ret
1184 cat <<EOF > $testroot/wt/patch
1189 \ No newline at end of file
1193 (cd $testroot/wt && got patch patch) > $testroot/stdout
1195 if [ $ret -ne 0 ]; then
1196 test_done $testroot $ret
1200 echo "M eta" > $testroot/stdout.expected
1201 cmp -s $testroot/stdout.expected $testroot/stdout
1203 if [ $ret -ne 0 ]; then
1204 diff -u $testroot/stdout.expected $testroot/stdout
1205 test_done $testroot $ret
1209 echo eta > $testroot/wt/eta.expected
1210 cmp -s $testroot/wt/eta.expected $testroot/wt/eta
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
1223 if [ $ret -ne 0 ]; then
1224 test_done $testroot $ret
1228 cat <<EOF > $testroot/wt/patch
1229 --- foo/bar/alpha.orig
1236 (cd $testroot/wt && got patch -p2 patch) > $testroot/stdout
1238 if [ $ret -ne 0 ]; then
1239 test_done $testroot $ret
1243 echo "M alpha" >> $testroot/stdout.expected
1244 cmp -s $testroot/stdout.expected $testroot/stdout
1246 if [ $ret -ne 0 ]; then
1247 diff -u $testroot/stdout.expected $testroot/stdout
1248 test_done $testroot $ret
1252 (cd $testroot/wt && got revert alpha) > /dev/null 2>&1
1254 if [ $ret -ne 0 ]; then
1255 test_done $testroot $ret
1259 (cd $testroot/wt && got patch -p3 patch) \
1262 if [ $ret -eq 0 ]; then
1263 echo "stripped more components than available!"
1264 test_done $testroot 1
1268 cat <<EOF > $testroot/stderr.expected
1269 got: can't strip 1 path-components from foo/bar/alpha: bad path
1272 cmp -s $testroot/stderr.expected $testroot/stderr
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
1285 if [ $ret -ne 0 ]; then
1286 test_done $testroot $ret
1292 cat <<EOF > $testroot/wt/hello.c
1298 /* the trailing whitespace is on purpose */
1299 printf("hello, world\n");$trailing
1304 (cd $testroot/wt && got add hello.c && got ci -m '+hello.c') \
1307 if [ $ret -ne 0 ]; then
1308 test_done $testroot $ret
1312 # test with a diff with various whitespace corruptions
1313 cat <<EOF > $testroot/wt/patch
1318 /* the trailing whitespace is on purpose */
1319 printf("hello, world\n");
1321 + return 5; /* always fails */
1325 (cd $testroot/wt && got patch patch) \
1326 2>$testroot/stderr >$testroot/stdout
1328 if [ $ret -ne 0 ]; then
1329 echo "failed to apply diff" >&2
1330 test_done $testroot $ret
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
1339 if [ $ret -ne 0 ]; then
1340 diff -u $testroot/stdout.expected $testroot/stdout
1341 test_done $testroot $ret
1345 cat <<EOF > $testroot/wt/hello.c.expected
1351 /* the trailing whitespace is on purpose */
1352 printf("hello, world\n");$trailing
1353 return 5; /* always fails */
1357 cmp -s $testroot/wt/hello.c.expected $testroot/wt/hello.c
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
1370 if [ $ret -ne 0 ]; then
1371 test_done $testroot $ret
1375 cat <<EOF > $testroot/wt/gamma/patch
1387 (cd $testroot/wt/gamma && got patch patch) > $testroot/stdout
1389 if [ $ret -ne 0 ]; then
1390 test_done $testroot $ret
1394 echo 'M gamma/delta' > $testroot/stdout.expected
1395 echo 'A gamma/eta' >> $testroot/stdout.expected
1397 cmp -s $testroot/stdout.expected $testroot/stdout
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
1410 if [ $ret -ne 0 ]; then
1411 test_done $testroot $ret
1415 cat <<EOF > $testroot/wt/patch
1427 (cd $testroot/wt && got patch patch) > $testroot/stdout
1429 if [ $ret -ne 0 ]; then
1430 test_done $testroot $ret
1434 echo 'M delta' > $testroot/stdout.expected
1435 echo 'A eta' >> $testroot/stdout.expected
1437 cmp -s $testroot/stdout.expected $testroot/stdout
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
1450 if [ $ret -ne 0 ]; then
1451 test_done $testroot $ret
1455 mkdir -p $testroot/wt/epsilon/zeta/
1457 cat <<EOF > $testroot/wt/patch
1464 (cd $testroot/wt/epsilon/zeta && got patch -p1 $testroot/wt/patch) \
1467 if [ $ret -ne 0 ]; then
1468 test_done $testroot $ret
1472 echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1474 cmp -s $testroot/stdout.expected $testroot/stdout
1476 if [ $ret -ne 0 ]; then
1477 diff -u $testroot/stdout.expected $testroot/stdout
1478 test_done $testroot $ret
1482 echo 'theta' > $testroot/theta.expected
1483 cmp -s $testroot/wt/epsilon/zeta/theta $testroot/theta.expected
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
1496 if [ $ret -ne 0 ]; then
1497 test_done $testroot $ret
1501 cat <<EOF > $testroot/wt/patch
1506 \ No newline at end of file
1510 (cd $testroot/wt && got patch -R patch) > $testroot/stdout
1512 if [ $ret -ne 0 ]; then
1513 test_done $testroot $ret
1517 echo "M alpha" > $testroot/stdout.expected
1518 cmp -s $testroot/stdout.expected $testroot/stdout
1520 if [ $ret -ne 0 ]; then
1521 diff -u $testroot/stdout.expected $testroot/stdout
1522 test_done $testroot $ret
1526 echo -n ALPHA > $testroot/wt/alpha.expected
1527 cmp -s $testroot/wt/alpha.expected $testroot/wt/alpha
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
1540 if [ $ret -ne 0 ]; then
1541 test_done $testroot $ret
1545 jot 10 > $testroot/wt/numbers
1546 chmod +x $testroot/wt/numbers
1547 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1550 if [ $ret -ne 0 ]; then
1551 test_done $testroot $ret
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
1560 if [ $ret -ne 0 ]; then
1561 test_done $testroot $ret
1565 jot 10 | sed 's/6/six/g' > $testroot/wt/numbers
1566 (cd $testroot/wt && got commit -m 'edit numbers') \
1569 if [ $ret -ne 0 ]; then
1570 test_done $testroot $ret
1574 (cd $testroot/wt && got patch $testroot/old.diff) \
1577 if [ $ret -ne 0 ]; then
1578 test_done $testroot $ret
1582 echo 'G numbers' > $testroot/stdout.expected
1583 cmp -s $testroot/stdout $testroot/stdout.expected
1585 if [ $ret -ne 0 ]; then
1586 diff -u $testroot/stdout $testroot/stdout.expected
1587 test_done $testroot $ret
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
1594 if [ $ret -ne 0 ]; then
1595 diff -u $testroot/wt/numbers $testroot/wt/numbers.expected
1596 test_done $testroot $ret
1600 test -x $testroot/wt/numbers
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")
1615 if [ $ret -ne 0 ]; then
1616 test_done $testroot $ret
1620 jot 10 | sed 's/4/four/g' > $testroot/repo/numbers
1621 (cd $testroot/repo && git diff > $testroot/old.diff)
1623 if [ $ret -ne 0 ]; then
1624 test_done $testroot $ret
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")
1635 if [ $ret -ne 0 ]; then
1636 test_done $testroot $ret
1640 # now work with got:
1641 got checkout $testroot/repo $testroot/wt > /dev/null
1643 if [ $ret -ne 0 ]; then
1644 test_done $testroot $ret
1648 (cd $testroot/wt && got patch $testroot/old.diff) > $testroot/stdout
1650 if [ $ret -ne 0 ]; then
1651 test_done $testroot $ret
1655 echo 'G numbers' > $testroot/stdout.expected
1656 cmp -s $testroot/stdout $testroot/stdout.expected
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
1669 if [ $ret -ne 0 ]; then
1670 test_done $testroot $ret
1674 jot 10 > $testroot/wt/numbers
1675 (cd $testroot/wt && got add numbers && got commit -m +numbers) \
1678 if [ $ret -ne 0 ]; then
1679 test_done $testroot $ret
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
1691 if [ $ret -ne 0 ]; then
1692 test_done $testroot $ret
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') \
1701 if [ $ret -ne 0 ]; then
1702 test_done $testroot $ret
1706 (cd $testroot/wt && got patch $testroot/old.diff) \
1707 > $testroot/stdout 2>/dev/null
1709 if [ $ret -eq 0 ]; then
1710 echo "got patch merged a diff that should conflict" >&2
1711 test_done $testroot 0
1715 echo 'C alpha' > $testroot/stdout.expected
1716 echo 'C numbers' >> $testroot/stdout.expected
1717 cmp -s $testroot/stdout $testroot/stdout.expected
1719 if [ $ret -ne 0 ]; then
1720 diff -u $testroot/stdout $testroot/stdout.expected
1721 test_done $testroot $ret
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
1730 ||||||| commit $commit_id
1739 cat <<-EOF > $testroot/wt/numbers.expected
1747 ||||||| commit $commit_id
1758 cmp -s $testroot/wt/alpha $testroot/wt/alpha.expected
1760 if [ $ret -ne 0 ]; then
1761 diff -u $testroot/wt/alpha $testroot/wt/alpha.expected
1762 test_done $testroot $ret
1766 cmp -s $testroot/wt/numbers $testroot/wt/numbers.expected
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
1779 if [ $ret -ne 0 ]; then
1780 test_done $testroot $ret
1784 cat <<EOF > $testroot/wt/patch
1786 diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
1788 blob - aaaabbbbccccddddeeeeffff0000111122223333
1790 blob + 0000111122223333444455556666777788889999
1800 (cd $testroot/wt/ && got patch patch) > $testroot/stdout
1802 if [ $ret -ne 0 ]; then
1803 test_done $testroot $ret
1807 echo 'M alpha' > $testroot/stdout.expected
1808 cmp -s $testroot/stdout.expected $testroot/stdout
1810 if [ $ret -ne 0 ]; then
1811 diff -u $testroot/stdout.expected $testroot/stdout
1812 test_done $testroot $ret
1816 # try again without a `diff' header
1818 cat <<EOF > $testroot/wt/patch
1820 blob - aaaabbbbccccddddeeeeffff0000111122223333
1822 blob + 0000111122223333444455556666777788889999
1832 (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1835 if [ $ret -ne 0 ]; then
1836 test_done $testroot $ret
1840 echo 'M alpha' > $testroot/stdout.expected
1841 cmp -s $testroot/stdout.expected $testroot/stdout
1843 if [ $ret -ne 0 ]; then
1844 diff -u $testroot/stdout.expected $testroot/stdout
1845 test_done $testroot $ret
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
1861 (cd $testroot/wt && got revert alpha > /dev/null && got patch patch) \
1864 if [ $ret -ne 0 ]; then
1865 test_done $testroot $ret
1869 echo 'M alpha' > $testroot/stdout.expected
1870 cmp -s $testroot/stdout.expected $testroot/stdout
1872 if [ $ret -ne 0 ]; then
1873 diff -u $testroot/stdout.expected $testroot/stdout
1875 test_done $testroot $ret
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