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 sed -i -e 's/^2$/a/' $testroot/wt/numbers
388 sed -i -e 's/^7$/b/' $testroot/wt/numbers
389 sed -i -e 's/^16$/c/' $testroot/wt/numbers
391 (cd $testroot/wt && got diff > $testroot/numbers.diff)
393 # don't revert any hunks
394 printf "n\nn\nn\n" > $testroot/patchscript
395 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
396 numbers > $testroot/stdout)
398 if [ $ret -ne 0 ]; then
399 echo "got revert command failed unexpectedly" >&2
400 test_done "$testroot" "1"
403 cat > $testroot/stdout.expected <<EOF
404 -----------------------------------------------
412 -----------------------------------------------
413 M numbers (change 1 of 3)
414 revert this change? [y/n/q] n
415 -----------------------------------------------
425 -----------------------------------------------
426 M numbers (change 2 of 3)
427 revert this change? [y/n/q] n
428 -----------------------------------------------
435 -----------------------------------------------
436 M numbers (change 3 of 3)
437 revert this change? [y/n/q] n
439 cmp -s $testroot/stdout.expected $testroot/stdout
441 if [ $ret -ne 0 ]; then
442 diff -u $testroot/stdout.expected $testroot/stdout
443 test_done "$testroot" "$ret"
447 (cd $testroot/wt && got status > $testroot/stdout)
448 echo "M numbers" > $testroot/stdout.expected
449 cmp -s $testroot/stdout.expected $testroot/stdout
451 if [ $ret -ne 0 ]; then
452 diff -u $testroot/stdout.expected $testroot/stdout
453 test_done "$testroot" "$ret"
457 (cd $testroot/wt && got diff > $testroot/stdout)
458 cmp -s $testroot/numbers.diff $testroot/stdout
460 if [ $ret -ne 0 ]; then
461 diff -u $testroot/numbers.diff $testroot/stdout
462 test_done "$testroot" "$ret"
467 printf "y\nn\nn\n" > $testroot/patchscript
468 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
469 numbers > $testroot/stdout)
471 if [ $ret -ne 0 ]; then
472 echo "got revert command failed unexpectedly" >&2
473 test_done "$testroot" "1"
476 cat > $testroot/stdout.expected <<EOF
477 -----------------------------------------------
485 -----------------------------------------------
486 M numbers (change 1 of 3)
487 revert this change? [y/n/q] y
488 -----------------------------------------------
498 -----------------------------------------------
499 M numbers (change 2 of 3)
500 revert this change? [y/n/q] n
501 -----------------------------------------------
508 -----------------------------------------------
509 M numbers (change 3 of 3)
510 revert this change? [y/n/q] n
512 cmp -s $testroot/stdout.expected $testroot/stdout
514 if [ $ret -ne 0 ]; then
515 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
520 (cd $testroot/wt && got status > $testroot/stdout)
521 echo "M numbers" > $testroot/stdout.expected
522 cmp -s $testroot/stdout.expected $testroot/stdout
524 if [ $ret -ne 0 ]; then
525 diff -u $testroot/stdout.expected $testroot/stdout
526 test_done "$testroot" "$ret"
530 echo "diff $testroot/wt" > $testroot/stdout.expected
531 echo "commit - $commit_id" >> $testroot/stdout.expected
532 echo "path + $testroot/wt" >> $testroot/stdout.expected
533 echo -n 'blob - ' >> $testroot/stdout.expected
534 got tree -r $testroot/repo -i -c $commit_id \
535 | grep 'numbers$' | cut -d' ' -f 1 \
536 >> $testroot/stdout.expected
537 echo 'file + numbers' >> $testroot/stdout.expected
538 cat >> $testroot/stdout.expected <<EOF
557 (cd $testroot/wt && got diff > $testroot/stdout)
558 cmp -s $testroot/stdout.expected $testroot/stdout
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
566 # put first hunk back
567 sed -i -e 's/^2$/a/' $testroot/wt/numbers
570 printf "n\ny\nn\n" > $testroot/patchscript
571 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
572 numbers > $testroot/stdout)
574 cat > $testroot/stdout.expected <<EOF
575 -----------------------------------------------
583 -----------------------------------------------
584 M numbers (change 1 of 3)
585 revert this change? [y/n/q] n
586 -----------------------------------------------
596 -----------------------------------------------
597 M numbers (change 2 of 3)
598 revert this change? [y/n/q] y
599 -----------------------------------------------
606 -----------------------------------------------
607 M numbers (change 3 of 3)
608 revert this change? [y/n/q] n
610 cmp -s $testroot/stdout.expected $testroot/stdout
612 if [ $ret -ne 0 ]; then
613 diff -u $testroot/stdout.expected $testroot/stdout
614 test_done "$testroot" "$ret"
618 (cd $testroot/wt && got status > $testroot/stdout)
619 echo "M numbers" > $testroot/stdout.expected
620 cmp -s $testroot/stdout.expected $testroot/stdout
622 if [ $ret -ne 0 ]; then
623 diff -u $testroot/stdout.expected $testroot/stdout
624 test_done "$testroot" "$ret"
628 (cd $testroot/wt && got diff > $testroot/stdout)
630 echo "diff $testroot/wt" > $testroot/stdout.expected
631 echo "commit - $commit_id" >> $testroot/stdout.expected
632 echo "path + $testroot/wt" >> $testroot/stdout.expected
633 echo -n 'blob - ' >> $testroot/stdout.expected
634 got tree -r $testroot/repo -i -c $commit_id \
635 | grep 'numbers$' | cut -d' ' -f 1 \
636 >> $testroot/stdout.expected
637 echo 'file + numbers' >> $testroot/stdout.expected
638 cat >> $testroot/stdout.expected <<EOF
655 cmp -s $testroot/stdout.expected $testroot/stdout
657 if [ $ret -ne 0 ]; then
658 diff -u $testroot/stdout.expected $testroot/stdout
659 test_done "$testroot" "$ret"
664 printf "n\ny\n" > $testroot/patchscript
665 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
666 numbers > $testroot/stdout)
667 cat > $testroot/stdout.expected <<EOF
668 -----------------------------------------------
676 -----------------------------------------------
677 M numbers (change 1 of 2)
678 revert this change? [y/n/q] n
679 -----------------------------------------------
686 -----------------------------------------------
687 M numbers (change 2 of 2)
688 revert this change? [y/n/q] y
690 cmp -s $testroot/stdout.expected $testroot/stdout
692 if [ $ret -ne 0 ]; then
693 diff -u $testroot/stdout.expected $testroot/stdout
694 test_done "$testroot" "$ret"
698 (cd $testroot/wt && got diff > $testroot/stdout)
700 echo "diff $testroot/wt" > $testroot/stdout.expected
701 echo "commit - $commit_id" >> $testroot/stdout.expected
702 echo "path + $testroot/wt" >> $testroot/stdout.expected
703 echo -n 'blob - ' >> $testroot/stdout.expected
704 got tree -r $testroot/repo -i -c $commit_id \
705 | grep 'numbers$' | cut -d' ' -f 1 \
706 >> $testroot/stdout.expected
707 echo 'file + numbers' >> $testroot/stdout.expected
708 cat >> $testroot/stdout.expected <<EOF
719 cmp -s $testroot/stdout.expected $testroot/stdout
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
724 test_done "$testroot" "$ret"
727 test_revert_patch_added() {
728 local testroot=`test_init revert_patch_added`
729 local commit_id=`git_show_head $testroot/repo`
731 got checkout $testroot/repo $testroot/wt > /dev/null
733 if [ $ret -ne 0 ]; then
734 test_done "$testroot" "$ret"
738 echo "new" > $testroot/wt/epsilon/new
739 (cd $testroot/wt && got add epsilon/new > /dev/null)
741 printf "n\n" > $testroot/patchscript
742 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
743 epsilon/new > $testroot/stdout)
745 echo "A epsilon/new" > $testroot/stdout.expected
746 echo "revert this addition? [y/n] n" >> $testroot/stdout.expected
747 cmp -s $testroot/stdout.expected $testroot/stdout
749 if [ $ret -ne 0 ]; then
750 diff -u $testroot/stdout.expected $testroot/stdout
751 test_done "$testroot" "$ret"
755 (cd $testroot/wt && got status > $testroot/stdout)
756 echo "A epsilon/new" > $testroot/stdout.expected
757 cmp -s $testroot/stdout.expected $testroot/stdout
759 if [ $ret -ne 0 ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
761 test_done "$testroot" "$ret"
765 printf "y\n" > $testroot/patchscript
766 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
767 epsilon/new > $testroot/stdout)
769 echo "A epsilon/new" > $testroot/stdout.expected
770 echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
771 echo "R epsilon/new" >> $testroot/stdout.expected
772 cmp -s $testroot/stdout.expected $testroot/stdout
774 if [ $ret -ne 0 ]; then
775 diff -u $testroot/stdout.expected $testroot/stdout
776 test_done "$testroot" "$ret"
780 (cd $testroot/wt && got status > $testroot/stdout)
781 echo "? epsilon/new" > $testroot/stdout.expected
782 cmp -s $testroot/stdout.expected $testroot/stdout
784 if [ $ret -ne 0 ]; then
785 diff -u $testroot/stdout.expected $testroot/stdout
787 test_done "$testroot" "$ret"
790 test_revert_patch_removed() {
791 local testroot=`test_init revert_patch_removed`
792 local commit_id=`git_show_head $testroot/repo`
794 got checkout $testroot/repo $testroot/wt > /dev/null
796 if [ $ret -ne 0 ]; then
797 test_done "$testroot" "$ret"
801 (cd $testroot/wt && got rm beta > /dev/null)
803 printf "n\n" > $testroot/patchscript
804 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
805 beta > $testroot/stdout)
806 echo "D beta" > $testroot/stdout.expected
807 echo "revert this deletion? [y/n] n" >> $testroot/stdout.expected
808 cmp -s $testroot/stdout.expected $testroot/stdout
810 if [ $ret -ne 0 ]; then
811 diff -u $testroot/stdout.expected $testroot/stdout
812 test_done "$testroot" "$ret"
816 (cd $testroot/wt && got status > $testroot/stdout)
817 echo "D beta" > $testroot/stdout.expected
818 cmp -s $testroot/stdout.expected $testroot/stdout
820 if [ $ret -ne 0 ]; then
821 diff -u $testroot/stdout.expected $testroot/stdout
822 test_done "$testroot" "$ret"
826 printf "y\n" > $testroot/patchscript
827 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
828 beta > $testroot/stdout)
830 echo "D beta" > $testroot/stdout.expected
831 echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
832 echo "R beta" >> $testroot/stdout.expected
833 cmp -s $testroot/stdout.expected $testroot/stdout
835 if [ $ret -ne 0 ]; then
836 diff -u $testroot/stdout.expected $testroot/stdout
837 test_done "$testroot" "$ret"
841 (cd $testroot/wt && got status > $testroot/stdout)
842 echo -n > $testroot/stdout.expected
843 cmp -s $testroot/stdout.expected $testroot/stdout
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
848 test_done "$testroot" "$ret"
851 test_revert_patch_one_change() {
852 local testroot=`test_init revert_patch_one_change`
854 jot 16 > $testroot/repo/numbers
855 (cd $testroot/repo && git add numbers)
856 git_commit $testroot/repo -m "added numbers file"
857 local commit_id=`git_show_head $testroot/repo`
859 got checkout $testroot/repo $testroot/wt > /dev/null
861 if [ $ret -ne 0 ]; then
862 test_done "$testroot" "$ret"
866 # Ensure file size is changed. Avoids race condition causing test
867 # failures where 'got revert' does not see changes to revert if
868 # timestamps and size in stat info remain unchanged.
869 sed -i -e 's/^2$/aa/' $testroot/wt/numbers
871 # revert change with -p
872 printf "y\n" > $testroot/patchscript
873 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
874 numbers > $testroot/stdout)
876 if [ $ret -ne 0 ]; then
877 echo "got revert command failed unexpectedly" >&2
878 test_done "$testroot" "1"
881 cat > $testroot/stdout.expected <<EOF
882 -----------------------------------------------
890 -----------------------------------------------
891 M numbers (change 1 of 1)
892 revert this change? [y/n/q] y
895 if [ $ret -ne 0 ]; then
896 echo "got revert command failed unexpectedly" >&2
897 test_done "$testroot" "1"
901 cmp -s $testroot/stdout.expected $testroot/stdout
903 if [ $ret -ne 0 ]; then
904 diff -u $testroot/stdout.expected $testroot/stdout
905 test_done "$testroot" "$ret"
909 (cd $testroot/wt && got status > $testroot/stdout)
910 echo -n > $testroot/stdout.expected
911 cmp -s $testroot/stdout.expected $testroot/stdout
913 if [ $ret -ne 0 ]; then
914 diff -u $testroot/stdout.expected $testroot/stdout
915 test_done "$testroot" "$ret"
919 (cd $testroot/wt && got diff > $testroot/stdout)
920 echo -n > $testroot/stdout.expected
921 cmp -s $testroot/stdout.expected $testroot/stdout
923 if [ $ret -ne 0 ]; then
924 diff -u $testroot/stdout.expected $testroot/stdout
926 test_done "$testroot" "$ret"
929 test_revert_added_subtree() {
930 local testroot=`test_init revert_added_subtree`
932 got checkout $testroot/repo $testroot/wt > /dev/null
934 if [ $ret -ne 0 ]; then
935 test_done "$testroot" "$ret"
939 mkdir -p $testroot/wt/epsilon/foo/bar/baz
940 mkdir -p $testroot/wt/epsilon/foo/bar/bax
941 echo "new file" > $testroot/wt/epsilon/foo/a.o
942 echo "new file" > $testroot/wt/epsilon/foo/a.o
943 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
944 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
945 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
946 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
947 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
948 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
949 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
950 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
951 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
952 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
953 (cd $testroot/wt && got add -R epsilon >/dev/null)
955 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
956 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
957 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
958 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
959 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
960 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
961 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
962 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
963 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
964 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
965 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
967 (cd $testroot/wt && got revert -R . > $testroot/stdout)
969 cmp -s $testroot/stdout.expected $testroot/stdout
971 if [ $ret -ne 0 ]; then
972 diff -u $testroot/stdout.expected $testroot/stdout
973 test_done "$testroot" "$ret"
977 echo "? epsilon/foo/a.o" > $testroot/stdout.expected
978 echo "? epsilon/foo/bar/b.d" >> $testroot/stdout.expected
979 echo "? epsilon/foo/bar/b.o" >> $testroot/stdout.expected
980 echo "? epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
981 echo "? epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
982 echo "? epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
983 echo "? epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
984 echo "? epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
985 echo "? epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
986 echo "? epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
987 echo "? epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
989 (cd $testroot/wt && got status > $testroot/stdout)
991 cmp -s $testroot/stdout.expected $testroot/stdout
993 if [ $ret -ne 0 ]; then
994 diff -u $testroot/stdout.expected $testroot/stdout
996 test_done "$testroot" "$ret"
999 test_revert_deleted_subtree() {
1000 local testroot=`test_init revert_deleted_subtree`
1002 got checkout $testroot/repo $testroot/wt > /dev/null
1004 if [ $ret -ne 0 ]; then
1005 test_done "$testroot" "$ret"
1009 mkdir -p $testroot/wt/epsilon/foo/bar/baz
1010 mkdir -p $testroot/wt/epsilon/foo/bar/bax
1011 echo "new file" > $testroot/wt/epsilon/foo/a.o
1012 echo "new file" > $testroot/wt/epsilon/foo/a.o
1013 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
1014 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
1015 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
1016 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
1017 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
1018 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
1019 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
1020 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
1021 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
1022 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
1023 (cd $testroot/wt && got add -R epsilon >/dev/null)
1024 (cd $testroot/wt && got commit -m "add subtree" >/dev/null)
1026 # now delete and revert the entire subtree
1027 (cd $testroot/wt && got rm -R epsilon/foo >/dev/null)
1029 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
1030 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
1031 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
1032 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
1033 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
1034 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
1035 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
1036 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
1037 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
1038 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
1039 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
1041 (cd $testroot/wt && got revert -R . > $testroot/stdout)
1043 cmp -s $testroot/stdout.expected $testroot/stdout
1045 if [ $ret -ne 0 ]; then
1046 diff -u $testroot/stdout.expected $testroot/stdout
1047 test_done "$testroot" "$ret"
1051 echo -n > $testroot/stdout.expected
1052 (cd $testroot/wt && got status > $testroot/stdout)
1054 cmp -s $testroot/stdout.expected $testroot/stdout
1056 if [ $ret -ne 0 ]; then
1057 diff -u $testroot/stdout.expected $testroot/stdout
1059 test_done "$testroot" "$ret"
1062 test_revert_symlink() {
1063 local testroot=`test_init revert_symlink`
1065 (cd $testroot/repo && ln -s alpha alpha.link)
1066 (cd $testroot/repo && ln -s epsilon epsilon.link)
1067 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1068 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1069 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1070 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1071 (cd $testroot/repo && git add .)
1072 git_commit $testroot/repo -m "add symlinks"
1073 local commit_id1=`git_show_head $testroot/repo`
1075 got checkout $testroot/repo $testroot/wt > /dev/null
1077 # symlink to file A now points to file B
1078 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1079 # symlink to a directory A now points to file B
1080 (cd $testroot/wt && ln -sfh beta epsilon.link)
1081 # "bad" symlink now contains a different target path
1082 echo "foo" > $testroot/wt/passwd.link
1083 # relative symlink to directory A now points to relative directory B
1084 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
1085 # an unversioned symlink
1086 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1087 # symlink to file A now points to non-existent file B
1088 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1090 (cd $testroot/wt && got rm zeta.link > /dev/null)
1092 (cd $testroot/wt && ln -sf beta new.link)
1093 (cd $testroot/wt && got add new.link > /dev/null)
1095 (cd $testroot/wt && got revert alpha.link epsilon.link \
1096 passwd.link epsilon/beta.link dotgotfoo.link \
1097 nonexistent.link zeta.link new.link > $testroot/stdout)
1099 cat > $testroot/stdout.expected <<EOF
1108 cmp -s $testroot/stdout.expected $testroot/stdout
1110 if [ $ret -ne 0 ]; then
1111 diff -u $testroot/stdout.expected $testroot/stdout
1112 test_done "$testroot" "$ret"
1116 if ! [ -h $testroot/wt/alpha.link ]; then
1117 echo "alpha.link is not a symlink"
1118 test_done "$testroot" "1"
1122 readlink $testroot/wt/alpha.link > $testroot/stdout
1123 echo "alpha" > $testroot/stdout.expected
1124 cmp -s $testroot/stdout.expected $testroot/stdout
1126 if [ $ret -ne 0 ]; then
1127 diff -u $testroot/stdout.expected $testroot/stdout
1128 test_done "$testroot" "$ret"
1132 if ! [ -h $testroot/wt/epsilon.link ]; then
1133 echo "epsilon.link is not a symlink"
1134 test_done "$testroot" "1"
1138 readlink $testroot/wt/epsilon.link > $testroot/stdout
1139 echo "epsilon" > $testroot/stdout.expected
1140 cmp -s $testroot/stdout.expected $testroot/stdout
1142 if [ $ret -ne 0 ]; then
1143 diff -u $testroot/stdout.expected $testroot/stdout
1144 test_done "$testroot" "$ret"
1148 if [ -h $testroot/wt/passwd.link ]; then
1149 echo "passwd.link should not be a symlink" >&2
1150 test_done "$testroot" "1"
1154 echo -n "/etc/passwd" > $testroot/content.expected
1155 cp $testroot/wt/passwd.link $testroot/content
1157 cmp -s $testroot/content.expected $testroot/content
1159 if [ $ret -ne 0 ]; then
1160 diff -u $testroot/content.expected $testroot/content
1161 test_done "$testroot" "$ret"
1165 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1166 echo "../beta" > $testroot/stdout.expected
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1169 if [ $ret -ne 0 ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1171 test_done "$testroot" "$ret"
1175 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1176 echo "nonexistent" > $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 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1186 echo "dotgotfoo.link is not a symlink " >&2
1187 test_done "$testroot" "1"
1190 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1191 echo ".got/foo" > $testroot/stdout.expected
1192 cmp -s $testroot/stdout.expected $testroot/stdout
1194 if [ $ret -ne 0 ]; then
1195 diff -u $testroot/stdout.expected $testroot/stdout
1196 test_done "$testroot" "$ret"
1200 if [ ! -h $testroot/wt/zeta.link ]; then
1201 echo -n "zeta.link is not a symlink" >&2
1202 test_done "$testroot" "1"
1206 readlink $testroot/wt/zeta.link > $testroot/stdout
1207 echo "epsilon/zeta" > $testroot/stdout.expected
1208 cmp -s $testroot/stdout.expected $testroot/stdout
1210 if [ $ret -ne 0 ]; then
1211 diff -u $testroot/stdout.expected $testroot/stdout
1212 test_done "$testroot" "$ret"
1216 if [ ! -h $testroot/wt/new.link ]; then
1217 echo -n "new.link is not a symlink" >&2
1218 test_done "$testroot" "1"
1222 (cd $testroot/wt && got status > $testroot/stdout)
1223 echo "? dotgotfoo.link" > $testroot/stdout.expected
1224 echo "? new.link" >> $testroot/stdout.expected
1225 cmp -s $testroot/stdout.expected $testroot/stdout
1227 if [ $ret -ne 0 ]; then
1228 diff -u $testroot/stdout.expected $testroot/stdout
1231 test_done "$testroot" "$ret"
1234 test_revert_patch_symlink() {
1235 local testroot=`test_init revert_patch_symlink`
1237 (cd $testroot/repo && ln -s alpha alpha.link)
1238 (cd $testroot/repo && ln -s epsilon epsilon.link)
1239 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1240 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1241 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1242 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1243 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1244 (cd $testroot/repo && git add .)
1245 git_commit $testroot/repo -m "add symlinks"
1246 local commit_id1=`git_show_head $testroot/repo`
1248 got checkout $testroot/repo $testroot/wt > /dev/null
1250 # symlink to file A now points to file B
1251 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1252 # symlink to a directory A now points to file B
1253 (cd $testroot/wt && ln -sfh beta epsilon.link)
1254 # "bad" symlink now contains a different target path
1255 echo "foo" > $testroot/wt/passwd.link
1256 # relative symlink to directory A now points to relative directory B
1257 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
1258 # an unversioned symlink
1259 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1260 # symlink to file A now points to non-existent file B
1261 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1263 (cd $testroot/wt && got rm zeta.link > /dev/null)
1264 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1266 (cd $testroot/wt && ln -sf beta new.link)
1267 (cd $testroot/wt && got add new.link > /dev/null)
1268 (cd $testroot/wt && ln -sf beta zeta3.link)
1269 (cd $testroot/wt && got add zeta3.link > /dev/null)
1271 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1272 (cd $testroot/wt && got revert -F $testroot/patchscript -p -R . \
1275 if [ $ret -ne 0 ]; then
1276 echo "got revert command failed unexpectedly" >&2
1277 test_done "$testroot" "1"
1280 cat > $testroot/stdout.expected <<EOF
1281 -----------------------------------------------
1284 \ No newline at end of file
1286 \ No newline at end of file
1287 -----------------------------------------------
1288 M alpha.link (change 1 of 1)
1289 revert this change? [y/n/q] y
1291 -----------------------------------------------
1294 \ No newline at end of file
1296 \ No newline at end of file
1297 -----------------------------------------------
1298 M epsilon/beta.link (change 1 of 1)
1299 revert this change? [y/n/q] n
1300 -----------------------------------------------
1303 \ No newline at end of file
1305 \ No newline at end of file
1306 -----------------------------------------------
1307 M epsilon.link (change 1 of 1)
1308 revert this change? [y/n/q] y
1311 revert this addition? [y/n] n
1312 -----------------------------------------------
1315 \ No newline at end of file
1317 \ No newline at end of file
1318 -----------------------------------------------
1319 M nonexistent.link (change 1 of 1)
1320 revert this change? [y/n/q] y
1322 -----------------------------------------------
1325 \ No newline at end of file
1327 -----------------------------------------------
1328 M passwd.link (change 1 of 1)
1329 revert this change? [y/n/q] y
1332 revert this deletion? [y/n] n
1334 revert this deletion? [y/n] y
1337 revert this addition? [y/n] y
1340 cmp -s $testroot/stdout.expected $testroot/stdout
1342 if [ $ret -ne 0 ]; then
1343 diff -u $testroot/stdout.expected $testroot/stdout
1344 test_done "$testroot" "$ret"
1348 if ! [ -h $testroot/wt/alpha.link ]; then
1349 echo "alpha.link is not a symlink"
1350 test_done "$testroot" "1"
1354 readlink $testroot/wt/alpha.link > $testroot/stdout
1355 echo "alpha" > $testroot/stdout.expected
1356 cmp -s $testroot/stdout.expected $testroot/stdout
1358 if [ $ret -ne 0 ]; then
1359 diff -u $testroot/stdout.expected $testroot/stdout
1360 test_done "$testroot" "$ret"
1364 if ! [ -h $testroot/wt/epsilon.link ]; then
1365 echo "epsilon.link is not a symlink"
1366 test_done "$testroot" "1"
1370 readlink $testroot/wt/epsilon.link > $testroot/stdout
1371 echo "epsilon" > $testroot/stdout.expected
1372 cmp -s $testroot/stdout.expected $testroot/stdout
1374 if [ $ret -ne 0 ]; then
1375 diff -u $testroot/stdout.expected $testroot/stdout
1376 test_done "$testroot" "$ret"
1380 if [ -h $testroot/wt/passwd.link ]; then
1381 echo "passwd.link should not be a symlink" >&2
1382 test_done "$testroot" "1"
1386 echo -n "/etc/passwd" > $testroot/content.expected
1387 cp $testroot/wt/passwd.link $testroot/content
1389 cmp -s $testroot/content.expected $testroot/content
1391 if [ $ret -ne 0 ]; then
1392 diff -u $testroot/content.expected $testroot/content
1393 test_done "$testroot" "$ret"
1397 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1398 echo "../gamma" > $testroot/stdout.expected
1399 cmp -s $testroot/stdout.expected $testroot/stdout
1401 if [ $ret -ne 0 ]; then
1402 diff -u $testroot/stdout.expected $testroot/stdout
1403 test_done "$testroot" "$ret"
1407 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1408 echo "nonexistent" > $testroot/stdout.expected
1409 cmp -s $testroot/stdout.expected $testroot/stdout
1411 if [ $ret -ne 0 ]; then
1412 diff -u $testroot/stdout.expected $testroot/stdout
1413 test_done "$testroot" "$ret"
1417 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1418 echo "dotgotfoo.link is not a symlink " >&2
1419 test_done "$testroot" "1"
1422 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1423 echo ".got/foo" > $testroot/stdout.expected
1424 cmp -s $testroot/stdout.expected $testroot/stdout
1426 if [ $ret -ne 0 ]; then
1427 diff -u $testroot/stdout.expected $testroot/stdout
1428 test_done "$testroot" "$ret"
1433 if [ -e $testroot/wt/zeta.link ]; then
1434 echo -n "zeta.link should not exist on disk" >&2
1435 test_done "$testroot" "1"
1439 if [ ! -h $testroot/wt/zeta2.link ]; then
1440 echo -n "zeta2.link is not a symlink" >&2
1441 test_done "$testroot" "1"
1445 readlink $testroot/wt/zeta2.link > $testroot/stdout
1446 echo "epsilon/zeta" > $testroot/stdout.expected
1447 cmp -s $testroot/stdout.expected $testroot/stdout
1449 if [ $ret -ne 0 ]; then
1450 diff -u $testroot/stdout.expected $testroot/stdout
1451 test_done "$testroot" "$ret"
1455 if [ ! -h $testroot/wt/zeta3.link ]; then
1456 echo -n "zeta3.link is not a symlink" >&2
1457 test_done "$testroot" "1"
1461 readlink $testroot/wt/zeta3.link > $testroot/stdout
1462 echo "beta" > $testroot/stdout.expected
1463 cmp -s $testroot/stdout.expected $testroot/stdout
1465 if [ $ret -ne 0 ]; then
1466 diff -u $testroot/stdout.expected $testroot/stdout
1467 test_done "$testroot" "$ret"
1471 if [ ! -h $testroot/wt/new.link ]; then
1472 echo -n "new.link is not a symlink" >&2
1473 test_done "$testroot" "1"
1477 (cd $testroot/wt && got status > $testroot/stdout)
1478 echo "? dotgotfoo.link" > $testroot/stdout.expected
1479 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1480 echo "A new.link" >> $testroot/stdout.expected
1481 echo "D zeta.link" >> $testroot/stdout.expected
1482 echo "? zeta3.link" >> $testroot/stdout.expected
1483 cmp -s $testroot/stdout.expected $testroot/stdout
1485 if [ $ret -ne 0 ]; then
1486 diff -u $testroot/stdout.expected $testroot/stdout
1489 test_done "$testroot" "$ret"
1492 test_revert_umask() {
1493 local testroot=`test_init revert_umask`
1495 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1496 echo "edit alpha" > $testroot/wt/alpha
1498 # using a subshell to avoid clobbering global umask
1499 (umask 077 && cd "$testroot/wt" && got revert alpha) \
1502 if [ $ret -ne 0 ]; then
1503 test_done "$testroot" $ret
1507 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1508 echo "alpha is not 0600 after revert" >&2
1509 ls -l "$testroot/wt/alpha" >&2
1510 test_done "$testroot" 1
1513 test_done "$testroot" 0
1517 run_test test_revert_basic
1518 run_test test_revert_rm
1519 run_test test_revert_add
1520 run_test test_revert_multiple
1521 run_test test_revert_file_in_new_subdir
1522 run_test test_revert_no_arguments
1523 run_test test_revert_directory
1524 run_test test_revert_directory_unknown
1525 run_test test_revert_patch
1526 run_test test_revert_patch_added
1527 run_test test_revert_patch_removed
1528 run_test test_revert_patch_one_change
1529 run_test test_revert_added_subtree
1530 run_test test_revert_deleted_subtree
1531 run_test test_revert_symlink
1532 run_test test_revert_patch_symlink
1533 run_test test_revert_umask