3 # Copyright (c) 2019 Stefan Sperling <stsp@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 revert_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
29 echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
31 echo 'R epsilon/zeta' > $testroot/stdout.expected
33 (cd $testroot/wt && got revert epsilon/zeta > $testroot/stdout)
35 cmp -s $testroot/stdout.expected $testroot/stdout
37 if [ $ret -ne 0 ]; then
38 diff -u $testroot/stdout.expected $testroot/stdout
39 test_done "$testroot" "$ret"
43 echo "zeta" > $testroot/content.expected
44 cat $testroot/wt/epsilon/zeta > $testroot/content
46 cmp -s $testroot/content.expected $testroot/content
48 if [ $ret -ne 0 ]; then
49 diff -u $testroot/content.expected $testroot/content
51 test_done "$testroot" "$ret"
56 local testroot=`test_init revert_rm`
58 got checkout $testroot/repo $testroot/wt > /dev/null
60 if [ $ret -ne 0 ]; then
61 test_done "$testroot" "$ret"
65 (cd $testroot/wt && got rm beta >/dev/null)
67 echo 'R beta' > $testroot/stdout.expected
69 (cd $testroot/wt && got revert beta > $testroot/stdout)
71 cmp -s $testroot/stdout.expected $testroot/stdout
73 if [ $ret -ne 0 ]; then
74 diff -u $testroot/stdout.expected $testroot/stdout
75 test_done "$testroot" "$ret"
79 echo "beta" > $testroot/content.expected
80 cat $testroot/wt/beta > $testroot/content
82 cmp -s $testroot/content.expected $testroot/content
84 if [ $ret -ne 0 ]; then
85 diff -u $testroot/content.expected $testroot/content
87 test_done "$testroot" "$ret"
91 local testroot=`test_init revert_add`
93 got checkout $testroot/repo $testroot/wt > /dev/null
95 if [ $ret -ne 0 ]; then
96 test_done "$testroot" "$ret"
100 echo "new file" > $testroot/wt/new
101 (cd $testroot/wt && got add new >/dev/null)
103 echo 'R new' > $testroot/stdout.expected
105 (cd $testroot/wt && got revert new > $testroot/stdout)
107 cmp -s $testroot/stdout.expected $testroot/stdout
109 if [ $ret -ne 0 ]; then
110 diff -u $testroot/stdout.expected $testroot/stdout
111 test_done "$testroot" "$ret"
115 echo "new file" > $testroot/content.expected
116 cat $testroot/wt/new > $testroot/content
118 cmp -s $testroot/content.expected $testroot/content
120 if [ $ret -ne 0 ]; then
121 diff -u $testroot/content.expected $testroot/content
122 test_done "$testroot" "$ret"
126 echo '? new' > $testroot/stdout.expected
128 (cd $testroot/wt && got status > $testroot/stdout)
130 cmp -s $testroot/stdout.expected $testroot/stdout
132 if [ $ret -ne 0 ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
135 test_done "$testroot" "$ret"
138 test_revert_multiple() {
139 local testroot=`test_init revert_multiple`
141 got checkout $testroot/repo $testroot/wt > /dev/null
143 if [ $ret -ne 0 ]; then
144 test_done "$testroot" "$ret"
148 echo "modified alpha" > $testroot/wt/alpha
149 echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
151 echo 'R alpha' > $testroot/stdout.expected
152 echo 'R epsilon/zeta' >> $testroot/stdout.expected
154 (cd $testroot/wt && got revert alpha epsilon/zeta > $testroot/stdout)
156 cmp -s $testroot/stdout.expected $testroot/stdout
158 if [ $ret -ne 0 ]; then
159 diff -u $testroot/stdout.expected $testroot/stdout
160 test_done "$testroot" "$ret"
164 echo "alpha" > $testroot/content.expected
165 cat $testroot/wt/alpha > $testroot/content
167 cmp -s $testroot/content.expected $testroot/content
169 if [ $ret -ne 0 ]; then
170 diff -u $testroot/content.expected $testroot/content
171 test_done "$testroot" "$ret"
175 echo "zeta" > $testroot/content.expected
176 cat $testroot/wt/epsilon/zeta > $testroot/content
178 cmp -s $testroot/content.expected $testroot/content
180 if [ $ret -ne 0 ]; then
181 diff -u $testroot/content.expected $testroot/content
183 test_done "$testroot" "$ret"
186 test_revert_file_in_new_subdir() {
187 local testroot=`test_init revert_file_in_new_subdir`
189 got checkout $testroot/repo $testroot/wt > /dev/null
191 if [ $ret -ne 0 ]; then
192 test_done "$testroot" "$ret"
197 mkdir -p $testroot/wt/newdir
198 echo new > $testroot/wt/newdir/new
199 (cd $testroot/wt && got add newdir/new > /dev/null)
201 (cd $testroot/wt && got revert newdir/new > $testroot/stdout)
203 echo "R newdir/new" > $testroot/stdout.expected
204 cmp -s $testroot/stdout.expected $testroot/stdout
206 if [ $ret -ne 0 ]; then
207 diff -u $testroot/stdout.expected $testroot/stdout
208 test_done "$testroot" "$ret"
212 (cd $testroot/wt && got status > $testroot/stdout)
214 echo "? newdir/new" > $testroot/stdout.expected
215 cmp -s $testroot/stdout.expected $testroot/stdout
217 if [ $ret -ne 0 ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
220 test_done "$testroot" "$ret"
224 test_revert_no_arguments() {
225 local testroot=`test_init revert_no_arguments`
227 got checkout $testroot/repo $testroot/wt > /dev/null
229 if [ $ret -ne 0 ]; then
230 test_done "$testroot" "$ret"
234 echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
236 (cd $testroot/wt && got revert > $testroot/stdout 2> $testroot/stderr)
238 if [ $ret -eq 0 ]; then
239 echo "revert command succeeded unexpectedly" >&2
240 test_done "$testroot" "1"
244 echo -n > $testroot/stdout.expected
245 cmp -s $testroot/stdout.expected $testroot/stdout
247 if [ $ret -ne 0 ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
253 echo "usage: got revert [-pR] [-F response-script] path ..." \
254 > $testroot/stderr.expected
255 cmp -s $testroot/stderr.expected $testroot/stderr
257 if [ $ret -ne 0 ]; then
258 diff -u $testroot/stderr.expected $testroot/stderr
260 test_done "$testroot" "$ret"
263 test_revert_directory() {
264 local testroot=`test_init revert_directory`
266 got checkout $testroot/repo $testroot/wt > /dev/null
268 if [ $ret -ne 0 ]; then
269 test_done "$testroot" "$ret"
273 echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
275 (cd $testroot/wt && got revert . > $testroot/stdout 2> $testroot/stderr)
277 if [ $ret -eq 0 ]; then
278 echo "got revert command succeeded unexpectedly" >&2
279 test_done "$testroot" "1"
282 echo "got: reverting directories requires -R option" \
283 > $testroot/stderr.expected
284 cmp -s $testroot/stderr.expected $testroot/stderr
286 if [ $ret -ne 0 ]; then
287 diff -u $testroot/stderr.expected $testroot/stderr
288 test_done "$testroot" "$ret"
292 echo -n > $testroot/stdout.expected
293 cmp -s $testroot/stdout.expected $testroot/stdout
295 if [ $ret -ne 0 ]; then
296 diff -u $testroot/stdout.expected $testroot/stdout
297 test_done "$testroot" "$ret"
301 (cd $testroot/wt && got revert -R . > $testroot/stdout)
303 echo 'R epsilon/zeta' > $testroot/stdout.expected
304 cmp -s $testroot/stdout.expected $testroot/stdout
306 if [ $ret -ne 0 ]; then
307 diff -u $testroot/stdout.expected $testroot/stdout
308 test_done "$testroot" "$ret"
312 echo "zeta" > $testroot/content.expected
313 cat $testroot/wt/epsilon/zeta > $testroot/content
315 cmp -s $testroot/content.expected $testroot/content
317 if [ $ret -ne 0 ]; then
318 diff -u $testroot/content.expected $testroot/content
320 test_done "$testroot" "$ret"
323 test_revert_directory_unknown() {
324 local testroot=`test_init revert_directory_unknown`
326 got checkout $testroot/repo $testroot/wt > /dev/null
328 if [ $ret -ne 0 ]; then
329 test_done "$testroot" "$ret"
333 echo "modified alpha" > $testroot/wt/alpha
334 echo "new untracked file" > $testroot/wt/epsilon/new_file
335 echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
337 (cd $testroot/wt && got revert -R . > $testroot/stdout)
339 echo 'R alpha' > $testroot/stdout.expected
340 echo 'R epsilon/zeta' >> $testroot/stdout.expected
341 cmp -s $testroot/stdout.expected $testroot/stdout
343 if [ $ret -ne 0 ]; then
344 diff -u $testroot/stdout.expected $testroot/stdout
345 test_done "$testroot" "$ret"
349 echo "new untracked file" > $testroot/content.expected
350 cat $testroot/wt/epsilon/new_file > $testroot/content
352 cmp -s $testroot/content.expected $testroot/content
354 if [ $ret -ne 0 ]; then
355 diff -u $testroot/content.expected $testroot/content
356 test_done "$testroot" "$ret"
360 echo "zeta" > $testroot/content.expected
361 cat $testroot/wt/epsilon/zeta > $testroot/content
363 cmp -s $testroot/content.expected $testroot/content
365 if [ $ret -ne 0 ]; then
366 diff -u $testroot/content.expected $testroot/content
369 test_done "$testroot" "$ret"
372 test_revert_patch() {
373 local testroot=`test_init revert_patch`
375 jot 16 > $testroot/repo/numbers
376 (cd $testroot/repo && git add numbers)
377 git_commit $testroot/repo -m "added numbers file"
378 local commit_id=`git_show_head $testroot/repo`
380 got checkout $testroot/repo $testroot/wt > /dev/null
382 if [ $ret -ne 0 ]; then
383 test_done "$testroot" "$ret"
387 ed -s $testroot/wt/numbers <<-\EOF
394 (cd $testroot/wt && got diff > $testroot/numbers.diff)
396 # don't revert any hunks
397 printf "n\nn\nn\n" > $testroot/patchscript
398 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
399 numbers > $testroot/stdout)
401 if [ $ret -ne 0 ]; then
402 echo "got revert command failed unexpectedly" >&2
403 test_done "$testroot" "1"
406 cat > $testroot/stdout.expected <<EOF
407 -----------------------------------------------
415 -----------------------------------------------
416 M numbers (change 1 of 3)
417 revert this change? [y/n/q] n
418 -----------------------------------------------
428 -----------------------------------------------
429 M numbers (change 2 of 3)
430 revert this change? [y/n/q] n
431 -----------------------------------------------
438 -----------------------------------------------
439 M numbers (change 3 of 3)
440 revert this change? [y/n/q] n
442 cmp -s $testroot/stdout.expected $testroot/stdout
444 if [ $ret -ne 0 ]; then
445 diff -u $testroot/stdout.expected $testroot/stdout
446 test_done "$testroot" "$ret"
450 (cd $testroot/wt && got status > $testroot/stdout)
451 echo "M numbers" > $testroot/stdout.expected
452 cmp -s $testroot/stdout.expected $testroot/stdout
454 if [ $ret -ne 0 ]; then
455 diff -u $testroot/stdout.expected $testroot/stdout
456 test_done "$testroot" "$ret"
460 (cd $testroot/wt && got diff > $testroot/stdout)
461 cmp -s $testroot/numbers.diff $testroot/stdout
463 if [ $ret -ne 0 ]; then
464 diff -u $testroot/numbers.diff $testroot/stdout
465 test_done "$testroot" "$ret"
470 printf "y\nn\nn\n" > $testroot/patchscript
471 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
472 numbers > $testroot/stdout)
474 if [ $ret -ne 0 ]; then
475 echo "got revert command failed unexpectedly" >&2
476 test_done "$testroot" "1"
479 cat > $testroot/stdout.expected <<EOF
480 -----------------------------------------------
488 -----------------------------------------------
489 M numbers (change 1 of 3)
490 revert this change? [y/n/q] y
491 -----------------------------------------------
501 -----------------------------------------------
502 M numbers (change 2 of 3)
503 revert this change? [y/n/q] n
504 -----------------------------------------------
511 -----------------------------------------------
512 M numbers (change 3 of 3)
513 revert this change? [y/n/q] n
515 cmp -s $testroot/stdout.expected $testroot/stdout
517 if [ $ret -ne 0 ]; then
518 diff -u $testroot/stdout.expected $testroot/stdout
519 test_done "$testroot" "$ret"
523 (cd $testroot/wt && got status > $testroot/stdout)
524 echo "M numbers" > $testroot/stdout.expected
525 cmp -s $testroot/stdout.expected $testroot/stdout
527 if [ $ret -ne 0 ]; then
528 diff -u $testroot/stdout.expected $testroot/stdout
529 test_done "$testroot" "$ret"
533 echo "diff $testroot/wt" > $testroot/stdout.expected
534 echo "commit - $commit_id" >> $testroot/stdout.expected
535 echo "path + $testroot/wt" >> $testroot/stdout.expected
536 echo -n 'blob - ' >> $testroot/stdout.expected
537 got tree -r $testroot/repo -i -c $commit_id \
538 | grep 'numbers$' | cut -d' ' -f 1 \
539 >> $testroot/stdout.expected
540 echo 'file + numbers' >> $testroot/stdout.expected
541 cat >> $testroot/stdout.expected <<EOF
560 (cd $testroot/wt && got diff > $testroot/stdout)
561 cmp -s $testroot/stdout.expected $testroot/stdout
563 if [ $ret -ne 0 ]; then
564 diff -u $testroot/stdout.expected $testroot/stdout
565 test_done "$testroot" "$ret"
569 # put first hunk back
570 ed -s $testroot/wt/numbers <<-\EOF
576 printf "n\ny\nn\n" > $testroot/patchscript
577 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
578 numbers > $testroot/stdout)
580 cat > $testroot/stdout.expected <<EOF
581 -----------------------------------------------
589 -----------------------------------------------
590 M numbers (change 1 of 3)
591 revert this change? [y/n/q] n
592 -----------------------------------------------
602 -----------------------------------------------
603 M numbers (change 2 of 3)
604 revert this change? [y/n/q] y
605 -----------------------------------------------
612 -----------------------------------------------
613 M numbers (change 3 of 3)
614 revert this change? [y/n/q] n
616 cmp -s $testroot/stdout.expected $testroot/stdout
618 if [ $ret -ne 0 ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
624 (cd $testroot/wt && got status > $testroot/stdout)
625 echo "M numbers" > $testroot/stdout.expected
626 cmp -s $testroot/stdout.expected $testroot/stdout
628 if [ $ret -ne 0 ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
634 (cd $testroot/wt && got diff > $testroot/stdout)
636 echo "diff $testroot/wt" > $testroot/stdout.expected
637 echo "commit - $commit_id" >> $testroot/stdout.expected
638 echo "path + $testroot/wt" >> $testroot/stdout.expected
639 echo -n 'blob - ' >> $testroot/stdout.expected
640 got tree -r $testroot/repo -i -c $commit_id \
641 | grep 'numbers$' | cut -d' ' -f 1 \
642 >> $testroot/stdout.expected
643 echo 'file + numbers' >> $testroot/stdout.expected
644 cat >> $testroot/stdout.expected <<EOF
661 cmp -s $testroot/stdout.expected $testroot/stdout
663 if [ $ret -ne 0 ]; then
664 diff -u $testroot/stdout.expected $testroot/stdout
665 test_done "$testroot" "$ret"
670 printf "n\ny\n" > $testroot/patchscript
671 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
672 numbers > $testroot/stdout)
673 cat > $testroot/stdout.expected <<EOF
674 -----------------------------------------------
682 -----------------------------------------------
683 M numbers (change 1 of 2)
684 revert this change? [y/n/q] n
685 -----------------------------------------------
692 -----------------------------------------------
693 M numbers (change 2 of 2)
694 revert this change? [y/n/q] y
696 cmp -s $testroot/stdout.expected $testroot/stdout
698 if [ $ret -ne 0 ]; then
699 diff -u $testroot/stdout.expected $testroot/stdout
700 test_done "$testroot" "$ret"
704 (cd $testroot/wt && got diff > $testroot/stdout)
706 echo "diff $testroot/wt" > $testroot/stdout.expected
707 echo "commit - $commit_id" >> $testroot/stdout.expected
708 echo "path + $testroot/wt" >> $testroot/stdout.expected
709 echo -n 'blob - ' >> $testroot/stdout.expected
710 got tree -r $testroot/repo -i -c $commit_id \
711 | grep 'numbers$' | cut -d' ' -f 1 \
712 >> $testroot/stdout.expected
713 echo 'file + numbers' >> $testroot/stdout.expected
714 cat >> $testroot/stdout.expected <<EOF
725 cmp -s $testroot/stdout.expected $testroot/stdout
727 if [ $ret -ne 0 ]; then
728 diff -u $testroot/stdout.expected $testroot/stdout
730 test_done "$testroot" "$ret"
733 test_revert_patch_added() {
734 local testroot=`test_init revert_patch_added`
735 local commit_id=`git_show_head $testroot/repo`
737 got checkout $testroot/repo $testroot/wt > /dev/null
739 if [ $ret -ne 0 ]; then
740 test_done "$testroot" "$ret"
744 echo "new" > $testroot/wt/epsilon/new
745 (cd $testroot/wt && got add epsilon/new > /dev/null)
747 printf "n\n" > $testroot/patchscript
748 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
749 epsilon/new > $testroot/stdout)
751 echo "A epsilon/new" > $testroot/stdout.expected
752 echo "revert this addition? [y/n] n" >> $testroot/stdout.expected
753 cmp -s $testroot/stdout.expected $testroot/stdout
755 if [ $ret -ne 0 ]; then
756 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
761 (cd $testroot/wt && got status > $testroot/stdout)
762 echo "A epsilon/new" > $testroot/stdout.expected
763 cmp -s $testroot/stdout.expected $testroot/stdout
765 if [ $ret -ne 0 ]; then
766 diff -u $testroot/stdout.expected $testroot/stdout
767 test_done "$testroot" "$ret"
771 printf "y\n" > $testroot/patchscript
772 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
773 epsilon/new > $testroot/stdout)
775 echo "A epsilon/new" > $testroot/stdout.expected
776 echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
777 echo "R epsilon/new" >> $testroot/stdout.expected
778 cmp -s $testroot/stdout.expected $testroot/stdout
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
782 test_done "$testroot" "$ret"
786 (cd $testroot/wt && got status > $testroot/stdout)
787 echo "? epsilon/new" > $testroot/stdout.expected
788 cmp -s $testroot/stdout.expected $testroot/stdout
790 if [ $ret -ne 0 ]; then
791 diff -u $testroot/stdout.expected $testroot/stdout
793 test_done "$testroot" "$ret"
796 test_revert_patch_removed() {
797 local testroot=`test_init revert_patch_removed`
798 local commit_id=`git_show_head $testroot/repo`
800 got checkout $testroot/repo $testroot/wt > /dev/null
802 if [ $ret -ne 0 ]; then
803 test_done "$testroot" "$ret"
807 (cd $testroot/wt && got rm beta > /dev/null)
809 printf "n\n" > $testroot/patchscript
810 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
811 beta > $testroot/stdout)
812 echo "D beta" > $testroot/stdout.expected
813 echo "revert this deletion? [y/n] n" >> $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected $testroot/stdout
816 if [ $ret -ne 0 ]; then
817 diff -u $testroot/stdout.expected $testroot/stdout
818 test_done "$testroot" "$ret"
822 (cd $testroot/wt && got status > $testroot/stdout)
823 echo "D beta" > $testroot/stdout.expected
824 cmp -s $testroot/stdout.expected $testroot/stdout
826 if [ $ret -ne 0 ]; then
827 diff -u $testroot/stdout.expected $testroot/stdout
828 test_done "$testroot" "$ret"
832 printf "y\n" > $testroot/patchscript
833 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
834 beta > $testroot/stdout)
836 echo "D beta" > $testroot/stdout.expected
837 echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
838 echo "R beta" >> $testroot/stdout.expected
839 cmp -s $testroot/stdout.expected $testroot/stdout
841 if [ $ret -ne 0 ]; then
842 diff -u $testroot/stdout.expected $testroot/stdout
843 test_done "$testroot" "$ret"
847 (cd $testroot/wt && got status > $testroot/stdout)
848 echo -n > $testroot/stdout.expected
849 cmp -s $testroot/stdout.expected $testroot/stdout
851 if [ $ret -ne 0 ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
854 test_done "$testroot" "$ret"
857 test_revert_patch_one_change() {
858 local testroot=`test_init revert_patch_one_change`
860 jot 16 > $testroot/repo/numbers
861 (cd $testroot/repo && git add numbers)
862 git_commit $testroot/repo -m "added numbers file"
863 local commit_id=`git_show_head $testroot/repo`
865 got checkout $testroot/repo $testroot/wt > /dev/null
867 if [ $ret -ne 0 ]; then
868 test_done "$testroot" "$ret"
872 # Ensure file size is changed. Avoids race condition causing test
873 # failures where 'got revert' does not see changes to revert if
874 # timestamps and size in stat info remain unchanged.
875 ed -s $testroot/wt/numbers <<-\EOF
880 # revert change with -p
881 printf "y\n" > $testroot/patchscript
882 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
883 numbers > $testroot/stdout)
885 if [ $ret -ne 0 ]; then
886 echo "got revert command failed unexpectedly" >&2
887 test_done "$testroot" "1"
890 cat > $testroot/stdout.expected <<EOF
891 -----------------------------------------------
899 -----------------------------------------------
900 M numbers (change 1 of 1)
901 revert this change? [y/n/q] y
904 if [ $ret -ne 0 ]; then
905 echo "got revert command failed unexpectedly" >&2
906 test_done "$testroot" "1"
910 cmp -s $testroot/stdout.expected $testroot/stdout
912 if [ $ret -ne 0 ]; then
913 diff -u $testroot/stdout.expected $testroot/stdout
914 test_done "$testroot" "$ret"
918 (cd $testroot/wt && got status > $testroot/stdout)
919 echo -n > $testroot/stdout.expected
920 cmp -s $testroot/stdout.expected $testroot/stdout
922 if [ $ret -ne 0 ]; then
923 diff -u $testroot/stdout.expected $testroot/stdout
924 test_done "$testroot" "$ret"
928 (cd $testroot/wt && got diff > $testroot/stdout)
929 echo -n > $testroot/stdout.expected
930 cmp -s $testroot/stdout.expected $testroot/stdout
932 if [ $ret -ne 0 ]; then
933 diff -u $testroot/stdout.expected $testroot/stdout
935 test_done "$testroot" "$ret"
938 test_revert_added_subtree() {
939 local testroot=`test_init revert_added_subtree`
941 got checkout $testroot/repo $testroot/wt > /dev/null
943 if [ $ret -ne 0 ]; then
944 test_done "$testroot" "$ret"
948 mkdir -p $testroot/wt/epsilon/foo/bar/baz
949 mkdir -p $testroot/wt/epsilon/foo/bar/bax
950 echo "new file" > $testroot/wt/epsilon/foo/a.o
951 echo "new file" > $testroot/wt/epsilon/foo/a.o
952 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
953 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
954 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
955 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
956 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
957 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
958 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
959 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
960 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
961 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
962 (cd $testroot/wt && got add -R epsilon >/dev/null)
964 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
965 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
966 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
967 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
968 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
969 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
970 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
971 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
972 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
973 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
974 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
976 (cd $testroot/wt && got revert -R . > $testroot/stdout)
978 cmp -s $testroot/stdout.expected $testroot/stdout
980 if [ $ret -ne 0 ]; then
981 diff -u $testroot/stdout.expected $testroot/stdout
982 test_done "$testroot" "$ret"
986 echo "? epsilon/foo/a.o" > $testroot/stdout.expected
987 echo "? epsilon/foo/bar/b.d" >> $testroot/stdout.expected
988 echo "? epsilon/foo/bar/b.o" >> $testroot/stdout.expected
989 echo "? epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
990 echo "? epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
991 echo "? epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
992 echo "? epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
993 echo "? epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
994 echo "? epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
995 echo "? epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
996 echo "? epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
998 (cd $testroot/wt && got status > $testroot/stdout)
1000 cmp -s $testroot/stdout.expected $testroot/stdout
1002 if [ $ret -ne 0 ]; then
1003 diff -u $testroot/stdout.expected $testroot/stdout
1005 test_done "$testroot" "$ret"
1008 test_revert_deleted_subtree() {
1009 local testroot=`test_init revert_deleted_subtree`
1011 got checkout $testroot/repo $testroot/wt > /dev/null
1013 if [ $ret -ne 0 ]; then
1014 test_done "$testroot" "$ret"
1018 mkdir -p $testroot/wt/epsilon/foo/bar/baz
1019 mkdir -p $testroot/wt/epsilon/foo/bar/bax
1020 echo "new file" > $testroot/wt/epsilon/foo/a.o
1021 echo "new file" > $testroot/wt/epsilon/foo/a.o
1022 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
1023 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
1024 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
1025 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
1026 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
1027 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
1028 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
1029 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
1030 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
1031 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
1032 (cd $testroot/wt && got add -R epsilon >/dev/null)
1033 (cd $testroot/wt && got commit -m "add subtree" >/dev/null)
1035 # now delete and revert the entire subtree
1036 (cd $testroot/wt && got rm -R epsilon/foo >/dev/null)
1038 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
1039 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
1040 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
1041 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
1042 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
1043 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
1044 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
1045 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
1046 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
1047 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
1048 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
1050 (cd $testroot/wt && got revert -R . > $testroot/stdout)
1052 cmp -s $testroot/stdout.expected $testroot/stdout
1054 if [ $ret -ne 0 ]; then
1055 diff -u $testroot/stdout.expected $testroot/stdout
1056 test_done "$testroot" "$ret"
1060 echo -n > $testroot/stdout.expected
1061 (cd $testroot/wt && got status > $testroot/stdout)
1063 cmp -s $testroot/stdout.expected $testroot/stdout
1065 if [ $ret -ne 0 ]; then
1066 diff -u $testroot/stdout.expected $testroot/stdout
1068 test_done "$testroot" "$ret"
1071 test_revert_symlink() {
1072 local testroot=`test_init revert_symlink`
1074 (cd $testroot/repo && ln -s alpha alpha.link)
1075 (cd $testroot/repo && ln -s epsilon epsilon.link)
1076 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1077 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1078 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1079 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1080 (cd $testroot/repo && git add .)
1081 git_commit $testroot/repo -m "add symlinks"
1082 local commit_id1=`git_show_head $testroot/repo`
1084 got checkout $testroot/repo $testroot/wt > /dev/null
1086 # symlink to file A now points to file B
1087 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1088 # symlink to a directory A now points to file B
1089 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1090 # "bad" symlink now contains a different target path
1091 echo "foo" > $testroot/wt/passwd.link
1092 # relative symlink to directory A now points to relative directory B
1093 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1095 # an unversioned symlink
1096 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1097 # symlink to file A now points to non-existent file B
1098 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1100 (cd $testroot/wt && got rm zeta.link > /dev/null)
1102 (cd $testroot/wt && ln -sf beta new.link)
1103 (cd $testroot/wt && got add new.link > /dev/null)
1105 (cd $testroot/wt && got revert alpha.link epsilon.link \
1106 passwd.link epsilon/beta.link dotgotfoo.link \
1107 nonexistent.link zeta.link new.link > $testroot/stdout)
1109 cat > $testroot/stdout.expected <<EOF
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 if ! [ -h $testroot/wt/alpha.link ]; then
1127 echo "alpha.link is not a symlink"
1128 test_done "$testroot" "1"
1132 readlink $testroot/wt/alpha.link > $testroot/stdout
1133 echo "alpha" > $testroot/stdout.expected
1134 cmp -s $testroot/stdout.expected $testroot/stdout
1136 if [ $ret -ne 0 ]; then
1137 diff -u $testroot/stdout.expected $testroot/stdout
1138 test_done "$testroot" "$ret"
1142 if ! [ -h $testroot/wt/epsilon.link ]; then
1143 echo "epsilon.link is not a symlink"
1144 test_done "$testroot" "1"
1148 readlink $testroot/wt/epsilon.link > $testroot/stdout
1149 echo "epsilon" > $testroot/stdout.expected
1150 cmp -s $testroot/stdout.expected $testroot/stdout
1152 if [ $ret -ne 0 ]; then
1153 diff -u $testroot/stdout.expected $testroot/stdout
1154 test_done "$testroot" "$ret"
1158 if [ -h $testroot/wt/passwd.link ]; then
1159 echo "passwd.link should not be a symlink" >&2
1160 test_done "$testroot" "1"
1164 echo -n "/etc/passwd" > $testroot/content.expected
1165 cp $testroot/wt/passwd.link $testroot/content
1167 cmp -s $testroot/content.expected $testroot/content
1169 if [ $ret -ne 0 ]; then
1170 diff -u $testroot/content.expected $testroot/content
1171 test_done "$testroot" "$ret"
1175 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1176 echo "../beta" > $testroot/stdout.expected
1177 cmp -s $testroot/stdout.expected $testroot/stdout
1179 if [ $ret -ne 0 ]; then
1180 diff -u $testroot/stdout.expected $testroot/stdout
1181 test_done "$testroot" "$ret"
1185 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1186 echo "nonexistent" > $testroot/stdout.expected
1187 cmp -s $testroot/stdout.expected $testroot/stdout
1189 if [ $ret -ne 0 ]; then
1190 diff -u $testroot/stdout.expected $testroot/stdout
1191 test_done "$testroot" "$ret"
1195 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1196 echo "dotgotfoo.link is not a symlink " >&2
1197 test_done "$testroot" "1"
1200 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1201 echo ".got/foo" > $testroot/stdout.expected
1202 cmp -s $testroot/stdout.expected $testroot/stdout
1204 if [ $ret -ne 0 ]; then
1205 diff -u $testroot/stdout.expected $testroot/stdout
1206 test_done "$testroot" "$ret"
1210 if [ ! -h $testroot/wt/zeta.link ]; then
1211 echo -n "zeta.link is not a symlink" >&2
1212 test_done "$testroot" "1"
1216 readlink $testroot/wt/zeta.link > $testroot/stdout
1217 echo "epsilon/zeta" > $testroot/stdout.expected
1218 cmp -s $testroot/stdout.expected $testroot/stdout
1220 if [ $ret -ne 0 ]; then
1221 diff -u $testroot/stdout.expected $testroot/stdout
1222 test_done "$testroot" "$ret"
1226 if [ ! -h $testroot/wt/new.link ]; then
1227 echo -n "new.link is not a symlink" >&2
1228 test_done "$testroot" "1"
1232 (cd $testroot/wt && got status > $testroot/stdout)
1233 echo "? dotgotfoo.link" > $testroot/stdout.expected
1234 echo "? new.link" >> $testroot/stdout.expected
1235 cmp -s $testroot/stdout.expected $testroot/stdout
1237 if [ $ret -ne 0 ]; then
1238 diff -u $testroot/stdout.expected $testroot/stdout
1241 test_done "$testroot" "$ret"
1244 test_revert_patch_symlink() {
1245 local testroot=`test_init revert_patch_symlink`
1247 (cd $testroot/repo && ln -s alpha alpha.link)
1248 (cd $testroot/repo && ln -s epsilon epsilon.link)
1249 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1250 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1251 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1252 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1253 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1254 (cd $testroot/repo && git add .)
1255 git_commit $testroot/repo -m "add symlinks"
1256 local commit_id1=`git_show_head $testroot/repo`
1258 got checkout $testroot/repo $testroot/wt > /dev/null
1260 # symlink to file A now points to file B
1261 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1262 # symlink to a directory A now points to file B
1263 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1264 # "bad" symlink now contains a different target path
1265 echo "foo" > $testroot/wt/passwd.link
1266 # relative symlink to directory A now points to relative directory B
1267 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1269 # an unversioned symlink
1270 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1271 # symlink to file A now points to non-existent file B
1272 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1274 (cd $testroot/wt && got rm zeta.link > /dev/null)
1275 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1277 (cd $testroot/wt && ln -sf beta new.link)
1278 (cd $testroot/wt && got add new.link > /dev/null)
1279 (cd $testroot/wt && ln -sf beta zeta3.link)
1280 (cd $testroot/wt && got add zeta3.link > /dev/null)
1282 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1283 (cd $testroot/wt && got revert -F $testroot/patchscript -p -R . \
1286 if [ $ret -ne 0 ]; then
1287 echo "got revert command failed unexpectedly" >&2
1288 test_done "$testroot" "1"
1291 cat > $testroot/stdout.expected <<EOF
1292 -----------------------------------------------
1295 \ No newline at end of file
1297 \ No newline at end of file
1298 -----------------------------------------------
1299 M alpha.link (change 1 of 1)
1300 revert this change? [y/n/q] y
1302 -----------------------------------------------
1305 \ No newline at end of file
1307 \ No newline at end of file
1308 -----------------------------------------------
1309 M epsilon/beta.link (change 1 of 1)
1310 revert this change? [y/n/q] n
1311 -----------------------------------------------
1314 \ No newline at end of file
1316 \ No newline at end of file
1317 -----------------------------------------------
1318 M epsilon.link (change 1 of 1)
1319 revert this change? [y/n/q] y
1322 revert this addition? [y/n] n
1323 -----------------------------------------------
1326 \ No newline at end of file
1328 \ No newline at end of file
1329 -----------------------------------------------
1330 M nonexistent.link (change 1 of 1)
1331 revert this change? [y/n/q] y
1333 -----------------------------------------------
1336 \ No newline at end of file
1338 -----------------------------------------------
1339 M passwd.link (change 1 of 1)
1340 revert this change? [y/n/q] y
1343 revert this deletion? [y/n] n
1345 revert this deletion? [y/n] y
1348 revert this addition? [y/n] y
1351 cmp -s $testroot/stdout.expected $testroot/stdout
1353 if [ $ret -ne 0 ]; then
1354 diff -u $testroot/stdout.expected $testroot/stdout
1355 test_done "$testroot" "$ret"
1359 if ! [ -h $testroot/wt/alpha.link ]; then
1360 echo "alpha.link is not a symlink"
1361 test_done "$testroot" "1"
1365 readlink $testroot/wt/alpha.link > $testroot/stdout
1366 echo "alpha" > $testroot/stdout.expected
1367 cmp -s $testroot/stdout.expected $testroot/stdout
1369 if [ $ret -ne 0 ]; then
1370 diff -u $testroot/stdout.expected $testroot/stdout
1371 test_done "$testroot" "$ret"
1375 if ! [ -h $testroot/wt/epsilon.link ]; then
1376 echo "epsilon.link is not a symlink"
1377 test_done "$testroot" "1"
1381 readlink $testroot/wt/epsilon.link > $testroot/stdout
1382 echo "epsilon" > $testroot/stdout.expected
1383 cmp -s $testroot/stdout.expected $testroot/stdout
1385 if [ $ret -ne 0 ]; then
1386 diff -u $testroot/stdout.expected $testroot/stdout
1387 test_done "$testroot" "$ret"
1391 if [ -h $testroot/wt/passwd.link ]; then
1392 echo "passwd.link should not be a symlink" >&2
1393 test_done "$testroot" "1"
1397 echo -n "/etc/passwd" > $testroot/content.expected
1398 cp $testroot/wt/passwd.link $testroot/content
1400 cmp -s $testroot/content.expected $testroot/content
1402 if [ $ret -ne 0 ]; then
1403 diff -u $testroot/content.expected $testroot/content
1404 test_done "$testroot" "$ret"
1408 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1409 echo "../gamma" > $testroot/stdout.expected
1410 cmp -s $testroot/stdout.expected $testroot/stdout
1412 if [ $ret -ne 0 ]; then
1413 diff -u $testroot/stdout.expected $testroot/stdout
1414 test_done "$testroot" "$ret"
1418 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1419 echo "nonexistent" > $testroot/stdout.expected
1420 cmp -s $testroot/stdout.expected $testroot/stdout
1422 if [ $ret -ne 0 ]; then
1423 diff -u $testroot/stdout.expected $testroot/stdout
1424 test_done "$testroot" "$ret"
1428 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1429 echo "dotgotfoo.link is not a symlink " >&2
1430 test_done "$testroot" "1"
1433 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1434 echo ".got/foo" > $testroot/stdout.expected
1435 cmp -s $testroot/stdout.expected $testroot/stdout
1437 if [ $ret -ne 0 ]; then
1438 diff -u $testroot/stdout.expected $testroot/stdout
1439 test_done "$testroot" "$ret"
1444 if [ -e $testroot/wt/zeta.link ]; then
1445 echo -n "zeta.link should not exist on disk" >&2
1446 test_done "$testroot" "1"
1450 if [ ! -h $testroot/wt/zeta2.link ]; then
1451 echo -n "zeta2.link is not a symlink" >&2
1452 test_done "$testroot" "1"
1456 readlink $testroot/wt/zeta2.link > $testroot/stdout
1457 echo "epsilon/zeta" > $testroot/stdout.expected
1458 cmp -s $testroot/stdout.expected $testroot/stdout
1460 if [ $ret -ne 0 ]; then
1461 diff -u $testroot/stdout.expected $testroot/stdout
1462 test_done "$testroot" "$ret"
1466 if [ ! -h $testroot/wt/zeta3.link ]; then
1467 echo -n "zeta3.link is not a symlink" >&2
1468 test_done "$testroot" "1"
1472 readlink $testroot/wt/zeta3.link > $testroot/stdout
1473 echo "beta" > $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 if [ ! -h $testroot/wt/new.link ]; then
1483 echo -n "new.link is not a symlink" >&2
1484 test_done "$testroot" "1"
1488 (cd $testroot/wt && got status > $testroot/stdout)
1489 echo "? dotgotfoo.link" > $testroot/stdout.expected
1490 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1491 echo "A new.link" >> $testroot/stdout.expected
1492 echo "D zeta.link" >> $testroot/stdout.expected
1493 echo "? zeta3.link" >> $testroot/stdout.expected
1494 cmp -s $testroot/stdout.expected $testroot/stdout
1496 if [ $ret -ne 0 ]; then
1497 diff -u $testroot/stdout.expected $testroot/stdout
1500 test_done "$testroot" "$ret"
1503 test_revert_umask() {
1504 local testroot=`test_init revert_umask`
1506 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1507 echo "edit alpha" > $testroot/wt/alpha
1509 # using a subshell to avoid clobbering global umask
1510 (umask 077 && cd "$testroot/wt" && got revert alpha) \
1513 if [ $ret -ne 0 ]; then
1514 test_done "$testroot" $ret
1518 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1519 echo "alpha is not 0600 after revert" >&2
1520 ls -l "$testroot/wt/alpha" >&2
1521 test_done "$testroot" 1
1524 test_done "$testroot" 0
1528 run_test test_revert_basic
1529 run_test test_revert_rm
1530 run_test test_revert_add
1531 run_test test_revert_multiple
1532 run_test test_revert_file_in_new_subdir
1533 run_test test_revert_no_arguments
1534 run_test test_revert_directory
1535 run_test test_revert_directory_unknown
1536 run_test test_revert_patch
1537 run_test test_revert_patch_added
1538 run_test test_revert_patch_removed
1539 run_test test_revert_patch_one_change
1540 run_test test_revert_added_subtree
1541 run_test test_revert_deleted_subtree
1542 run_test test_revert_symlink
1543 run_test test_revert_patch_symlink
1544 run_test test_revert_umask