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_relative_paths
() {
1281 local testroot
=`test_init patch_relative_paths`
1283 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
1285 if [ $ret -ne 0 ]; then
1286 test_done
$testroot $ret
1290 cat <<EOF > $testroot/wt/gamma/patch
1302 (cd $testroot/wt
/gamma
&& got
patch patch) > $testroot/stdout
1304 if [ $ret -ne 0 ]; then
1305 test_done
$testroot $ret
1309 echo 'M gamma/delta' > $testroot/stdout.expected
1310 echo 'A gamma/eta' >> $testroot/stdout.expected
1312 cmp -s $testroot/stdout.expected
$testroot/stdout
1314 if [ $ret -ne 0 ]; then
1315 diff -u $testroot/stdout.expected
$testroot/stdout
1317 test_done
$testroot $ret
1320 test_patch_with_path_prefix
() {
1321 local testroot
=`test_init patch_with_path_prefix`
1323 got checkout
-p gamma
$testroot/repo
$testroot/wt
> /dev
/null
1325 if [ $ret -ne 0 ]; then
1326 test_done
$testroot $ret
1330 cat <<EOF > $testroot/wt/patch
1342 (cd $testroot/wt
&& got
patch patch) > $testroot/stdout
1344 if [ $ret -ne 0 ]; then
1345 test_done
$testroot $ret
1349 echo 'M delta' > $testroot/stdout.expected
1350 echo 'A eta' >> $testroot/stdout.expected
1352 cmp -s $testroot/stdout.expected
$testroot/stdout
1354 if [ $ret -ne 0 ]; then
1355 diff -u $testroot/stdout.expected
$testroot/stdout
1357 test_done
$testroot $ret
1360 test_patch_relpath_with_path_prefix
() {
1361 local testroot
=`test_init patch_relpaths_with_path_prefix`
1363 got checkout
-p gamma
$testroot/repo
$testroot/wt
> /dev
/null
1365 if [ $ret -ne 0 ]; then
1366 test_done
$testroot $ret
1370 mkdir
-p $testroot/wt
/epsilon
/zeta
/
1372 cat <<EOF > $testroot/wt/patch
1379 (cd $testroot/wt
/epsilon
/zeta
&& got
patch -p1 $testroot/wt
/patch) \
1382 if [ $ret -ne 0 ]; then
1383 test_done
$testroot $ret
1387 echo 'A epsilon/zeta/theta' >> $testroot/stdout.expected
1389 cmp -s $testroot/stdout.expected
$testroot/stdout
1391 if [ $ret -ne 0 ]; then
1392 diff -u $testroot/stdout.expected
$testroot/stdout
1393 test_done
$testroot $ret
1397 echo 'theta' > $testroot/theta.expected
1398 cmp -s $testroot/wt
/epsilon
/zeta
/theta
$testroot/theta.expected
1400 if [ $ret -ne 0 ]; then
1401 diff -u $testroot/wt
/epsilon
/zeta
/theta
$testroot/theta.expected
1403 test_done
$testroot $ret
1406 test_patch_reverse
() {
1407 local testroot
=`test_init patch_reverse`
1409 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
1411 if [ $ret -ne 0 ]; then
1412 test_done
$testroot $ret
1416 cat <<EOF > $testroot/wt/patch
1421 \ No newline at end of file
1425 (cd $testroot/wt
&& got
patch -R patch) > $testroot/stdout
1427 if [ $ret -ne 0 ]; then
1428 test_done
$testroot $ret
1432 echo "M alpha" > $testroot/stdout.expected
1433 cmp -s $testroot/stdout.expected
$testroot/stdout
1435 if [ $ret -ne 0 ]; then
1436 diff -u $testroot/stdout.expected
$testroot/stdout
1437 test_done
$testroot $ret
1441 echo -n ALPHA
> $testroot/wt
/alpha.expected
1442 cmp -s $testroot/wt
/alpha.expected
$testroot/wt
/alpha
1444 if [ $ret -ne 0 ]; then
1445 diff -u $testroot/wt
/alpha.expected
$testroot/wt
/alpha
1447 test_done
$testroot $ret
1450 test_patch_merge_simple
() {
1451 local testroot
=`test_init patch_merge_simple`
1453 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
1455 if [ $ret -ne 0 ]; then
1456 test_done
$testroot $ret
1460 jot 10 > $testroot/wt
/numbers
1461 (cd $testroot/wt
&& got add numbers
&& got commit
-m +numbers
) \
1464 if [ $ret -ne 0 ]; then
1465 test_done
$testroot $ret
1469 jot 10 |
sed 's/4/four/g' > $testroot/wt
/numbers
1471 (cd $testroot/wt
&& got
diff > $testroot/old.
diff \
1472 && got revert numbers
) >/dev
/null
1474 if [ $ret -ne 0 ]; then
1475 test_done
$testroot $ret
1479 jot 10 |
sed 's/6/six/g' > $testroot/wt
/numbers
1480 (cd $testroot/wt
&& got commit
-m 'edit numbers') \
1483 if [ $ret -ne 0 ]; then
1484 test_done
$testroot $ret
1488 (cd $testroot/wt
&& got
patch $testroot/old.
diff) \
1491 if [ $ret -ne 0 ]; then
1492 test_done
$testroot $ret
1496 echo 'G numbers' > $testroot/stdout.expected
1497 cmp -s $testroot/stdout
$testroot/stdout.expected
1499 if [ $ret -ne 0 ]; then
1500 diff -u $testroot/stdout
$testroot/stdout.expected
1501 test_done
$testroot $ret
1505 jot 10 |
sed -e s
/4/four
/ -e s
/6/six
/ > $testroot/wt
/numbers.expected
1506 cmp -s $testroot/wt
/numbers
$testroot/wt
/numbers.expected
1508 if [ $ret -ne 0 ]; then
1509 diff -u $testroot/wt
/numbers
$testroot/wt
/numbers.expected
1511 test_done
$testroot $ret
1514 test_patch_merge_gitdiff
() {
1515 local testroot
=`test_init patch_merge_gitdiff`
1517 jot 10 > $testroot/repo
/numbers
1518 (cd $testroot/repo
&& git add numbers
&& \
1519 git_commit
$testroot/repo
-m "nums")
1521 if [ $ret -ne 0 ]; then
1522 test_done
$testroot $ret
1526 jot 10 |
sed 's/4/four/g' > $testroot/repo
/numbers
1527 (cd $testroot/repo
&& git
diff > $testroot/old.
diff)
1529 if [ $ret -ne 0 ]; then
1530 test_done
$testroot $ret
1535 jot 10 > $testroot/repo
/numbers
1537 jot 10 |
sed 's/6/six/g' > $testroot/repo
/numbers
1538 (cd $testroot/repo
&& git add numbers
&& \
1539 git_commit
$testroot/repo
-m "edit")
1541 if [ $ret -ne 0 ]; then
1542 test_done
$testroot $ret
1546 # now work with got:
1547 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
1549 if [ $ret -ne 0 ]; then
1550 test_done
$testroot $ret
1554 (cd $testroot/wt
&& got
patch $testroot/old.
diff) > $testroot/stdout
1556 if [ $ret -ne 0 ]; then
1557 test_done
$testroot $ret
1561 echo 'G numbers' > $testroot/stdout.expected
1562 cmp -s $testroot/stdout
$testroot/stdout.expected
1564 if [ $ret -ne 0 ]; then
1565 diff -u $testroot/stdout
$testroot/stdout.expected
1567 test_done
$testroot $ret
1570 test_patch_merge_conflict
() {
1571 local testroot
=`test_init patch_merge_conflict`
1573 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
1575 if [ $ret -ne 0 ]; then
1576 test_done
$testroot $ret
1580 jot 10 > $testroot/wt
/numbers
1581 (cd $testroot/wt
&& got add numbers
&& got commit
-m +numbers
) \
1584 if [ $ret -ne 0 ]; then
1585 test_done
$testroot $ret
1589 local commit_id
=`git_show_head $testroot/repo`
1591 jot 10 |
sed 's/6/six/g' > $testroot/wt
/numbers
1592 echo ALPHA
> $testroot/wt
/alpha
1594 (cd $testroot/wt
&& got
diff > $testroot/old.
diff \
1595 && got revert alpha numbers
) >/dev
/null
1597 if [ $ret -ne 0 ]; then
1598 test_done
$testroot $ret
1602 jot 10 |
sed 's/6/3+3/g' > $testroot/wt
/numbers
1603 jot -c 3 a
> $testroot/wt
/alpha
1604 (cd $testroot/wt
&& got commit
-m 'edit alpha and numbers') \
1607 if [ $ret -ne 0 ]; then
1608 test_done
$testroot $ret
1612 (cd $testroot/wt
&& got
patch $testroot/old.
diff) \
1613 > $testroot/stdout
2>/dev
/null
1615 if [ $ret -eq 0 ]; then
1616 echo "got patch merged a diff that should conflict" >&2
1617 test_done
$testroot 0
1621 echo 'C alpha' > $testroot/stdout.expected
1622 echo 'C numbers' >> $testroot/stdout.expected
1623 cmp -s $testroot/stdout
$testroot/stdout.expected
1625 if [ $ret -ne 0 ]; then
1626 diff -u $testroot/stdout
$testroot/stdout.expected
1627 test_done
$testroot $ret
1631 # XXX: prefixing every line with a tab otherwise got thinks
1632 # the file has conflicts in it.
1633 cat <<-EOF > $testroot/wt/alpha.expected
1636 ||||||| commit $commit_id
1645 cat <<-EOF > $testroot/wt/numbers.expected
1653 ||||||| commit $commit_id
1664 cmp -s $testroot/wt
/alpha
$testroot/wt
/alpha.expected
1666 if [ $ret -ne 0 ]; then
1667 diff -u $testroot/wt
/alpha
$testroot/wt
/alpha.expected
1668 test_done
$testroot $ret
1672 cmp -s $testroot/wt
/numbers
$testroot/wt
/numbers.expected
1674 if [ $ret -ne 0 ]; then
1675 diff -u $testroot/wt
/numbers
$testroot/wt
/numbers.expected
1677 test_done
$testroot $ret
1680 test_patch_merge_unknown_blob
() {
1681 local testroot
=`test_init patch_merge_unknown_blob`
1683 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
1685 if [ $ret -ne 0 ]; then
1686 test_done
$testroot $ret
1690 cat <<EOF > $testroot/wt/patch
1692 diff aaaabbbbccccddddeeeeffff0000111122223333 foo/bar
1694 blob - aaaabbbbccccddddeeeeffff0000111122223333
1696 blob + 0000111122223333444455556666777788889999
1706 (cd $testroot/wt
/ && got
patch patch) > $testroot/stdout
1708 if [ $ret -ne 0 ]; then
1709 test_done
$testroot $ret
1713 echo 'M alpha' > $testroot/stdout.expected
1714 cmp -s $testroot/stdout.expected
$testroot/stdout
1716 if [ $ret -ne 0 ]; then
1717 diff -u $testroot/stdout.expected
$testroot/stdout
1718 test_done
$testroot $ret
1722 # try again without a `diff' header
1724 cat <<EOF > $testroot/wt/patch
1726 blob - aaaabbbbccccddddeeeeffff0000111122223333
1728 blob + 0000111122223333444455556666777788889999
1738 (cd $testroot/wt
&& got revert alpha
> /dev
/null
&& got
patch patch) \
1741 if [ $ret -ne 0 ]; then
1742 test_done
$testroot $ret
1746 echo 'M alpha' > $testroot/stdout.expected
1747 cmp -s $testroot/stdout.expected
$testroot/stdout
1749 if [ $ret -ne 0 ]; then
1750 diff -u $testroot/stdout.expected
$testroot/stdout
1751 test_done
$testroot $ret
1755 # try again with a git-style diff
1757 cat <<EOF > $testroot/wt/patch
1758 diff --git a/alpha b/alpha
1759 index 0123456789ab..abcdef012345 100644
1767 (cd $testroot/wt
&& got revert alpha
> /dev
/null
&& got
patch patch) \
1770 if [ $ret -ne 0 ]; then
1771 test_done
$testroot $ret
1775 echo 'M alpha' > $testroot/stdout.expected
1776 cmp -s $testroot/stdout.expected
$testroot/stdout
1778 if [ $ret -ne 0 ]; then
1779 diff -u $testroot/stdout.expected
$testroot/stdout
1781 test_done
$testroot $ret
1785 run_test test_patch_add_file
1786 run_test test_patch_rm_file
1787 run_test test_patch_simple_edit_file
1788 run_test test_patch_prepend_line
1789 run_test test_patch_replace_line
1790 run_test test_patch_multiple_hunks
1791 run_test test_patch_multiple_files
1792 run_test test_patch_dont_apply
1793 run_test test_patch_malformed
1794 run_test test_patch_no_patch
1795 run_test test_patch_equals_for_context
1796 run_test test_patch_rename
1797 run_test test_patch_illegal_status
1798 run_test test_patch_nop
1799 run_test test_patch_preserve_perm
1800 run_test test_patch_create_dirs
1801 run_test test_patch_with_offset
1802 run_test test_patch_prefer_new_path
1803 run_test test_patch_no_newline
1804 run_test test_patch_strip
1805 run_test test_patch_relative_paths
1806 run_test test_patch_with_path_prefix
1807 run_test test_patch_relpath_with_path_prefix
1808 run_test test_patch_reverse
1809 run_test test_patch_merge_simple
1810 run_test test_patch_merge_gitdiff
1811 run_test test_patch_merge_conflict
1812 run_test test_patch_merge_unknown_blob