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 && rm epsilon.link && ln -s 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 && rm epsilon/beta.link && ln -s ../gamma \
1086 # an unversioned symlink
1087 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1088 # symlink to file A now points to non-existent file B
1089 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1091 (cd $testroot/wt && got rm zeta.link > /dev/null)
1093 (cd $testroot/wt && ln -sf beta new.link)
1094 (cd $testroot/wt && got add new.link > /dev/null)
1096 (cd $testroot/wt && got revert alpha.link epsilon.link \
1097 passwd.link epsilon/beta.link dotgotfoo.link \
1098 nonexistent.link zeta.link new.link > $testroot/stdout)
1100 cat > $testroot/stdout.expected <<EOF
1109 cmp -s $testroot/stdout.expected $testroot/stdout
1111 if [ $ret -ne 0 ]; then
1112 diff -u $testroot/stdout.expected $testroot/stdout
1113 test_done "$testroot" "$ret"
1117 if ! [ -h $testroot/wt/alpha.link ]; then
1118 echo "alpha.link is not a symlink"
1119 test_done "$testroot" "1"
1123 readlink $testroot/wt/alpha.link > $testroot/stdout
1124 echo "alpha" > $testroot/stdout.expected
1125 cmp -s $testroot/stdout.expected $testroot/stdout
1127 if [ $ret -ne 0 ]; then
1128 diff -u $testroot/stdout.expected $testroot/stdout
1129 test_done "$testroot" "$ret"
1133 if ! [ -h $testroot/wt/epsilon.link ]; then
1134 echo "epsilon.link is not a symlink"
1135 test_done "$testroot" "1"
1139 readlink $testroot/wt/epsilon.link > $testroot/stdout
1140 echo "epsilon" > $testroot/stdout.expected
1141 cmp -s $testroot/stdout.expected $testroot/stdout
1143 if [ $ret -ne 0 ]; then
1144 diff -u $testroot/stdout.expected $testroot/stdout
1145 test_done "$testroot" "$ret"
1149 if [ -h $testroot/wt/passwd.link ]; then
1150 echo "passwd.link should not be a symlink" >&2
1151 test_done "$testroot" "1"
1155 echo -n "/etc/passwd" > $testroot/content.expected
1156 cp $testroot/wt/passwd.link $testroot/content
1158 cmp -s $testroot/content.expected $testroot/content
1160 if [ $ret -ne 0 ]; then
1161 diff -u $testroot/content.expected $testroot/content
1162 test_done "$testroot" "$ret"
1166 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1167 echo "../beta" > $testroot/stdout.expected
1168 cmp -s $testroot/stdout.expected $testroot/stdout
1170 if [ $ret -ne 0 ]; then
1171 diff -u $testroot/stdout.expected $testroot/stdout
1172 test_done "$testroot" "$ret"
1176 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1177 echo "nonexistent" > $testroot/stdout.expected
1178 cmp -s $testroot/stdout.expected $testroot/stdout
1180 if [ $ret -ne 0 ]; then
1181 diff -u $testroot/stdout.expected $testroot/stdout
1182 test_done "$testroot" "$ret"
1186 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1187 echo "dotgotfoo.link is not a symlink " >&2
1188 test_done "$testroot" "1"
1191 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1192 echo ".got/foo" > $testroot/stdout.expected
1193 cmp -s $testroot/stdout.expected $testroot/stdout
1195 if [ $ret -ne 0 ]; then
1196 diff -u $testroot/stdout.expected $testroot/stdout
1197 test_done "$testroot" "$ret"
1201 if [ ! -h $testroot/wt/zeta.link ]; then
1202 echo -n "zeta.link is not a symlink" >&2
1203 test_done "$testroot" "1"
1207 readlink $testroot/wt/zeta.link > $testroot/stdout
1208 echo "epsilon/zeta" > $testroot/stdout.expected
1209 cmp -s $testroot/stdout.expected $testroot/stdout
1211 if [ $ret -ne 0 ]; then
1212 diff -u $testroot/stdout.expected $testroot/stdout
1213 test_done "$testroot" "$ret"
1217 if [ ! -h $testroot/wt/new.link ]; then
1218 echo -n "new.link is not a symlink" >&2
1219 test_done "$testroot" "1"
1223 (cd $testroot/wt && got status > $testroot/stdout)
1224 echo "? dotgotfoo.link" > $testroot/stdout.expected
1225 echo "? new.link" >> $testroot/stdout.expected
1226 cmp -s $testroot/stdout.expected $testroot/stdout
1228 if [ $ret -ne 0 ]; then
1229 diff -u $testroot/stdout.expected $testroot/stdout
1232 test_done "$testroot" "$ret"
1235 test_revert_patch_symlink() {
1236 local testroot=`test_init revert_patch_symlink`
1238 (cd $testroot/repo && ln -s alpha alpha.link)
1239 (cd $testroot/repo && ln -s epsilon epsilon.link)
1240 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1241 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1242 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1243 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1244 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1245 (cd $testroot/repo && git add .)
1246 git_commit $testroot/repo -m "add symlinks"
1247 local commit_id1=`git_show_head $testroot/repo`
1249 got checkout $testroot/repo $testroot/wt > /dev/null
1251 # symlink to file A now points to file B
1252 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1253 # symlink to a directory A now points to file B
1254 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1255 # "bad" symlink now contains a different target path
1256 echo "foo" > $testroot/wt/passwd.link
1257 # relative symlink to directory A now points to relative directory B
1258 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1260 # an unversioned symlink
1261 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1262 # symlink to file A now points to non-existent file B
1263 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1265 (cd $testroot/wt && got rm zeta.link > /dev/null)
1266 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1268 (cd $testroot/wt && ln -sf beta new.link)
1269 (cd $testroot/wt && got add new.link > /dev/null)
1270 (cd $testroot/wt && ln -sf beta zeta3.link)
1271 (cd $testroot/wt && got add zeta3.link > /dev/null)
1273 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1274 (cd $testroot/wt && got revert -F $testroot/patchscript -p -R . \
1277 if [ $ret -ne 0 ]; then
1278 echo "got revert command failed unexpectedly" >&2
1279 test_done "$testroot" "1"
1282 cat > $testroot/stdout.expected <<EOF
1283 -----------------------------------------------
1286 \ No newline at end of file
1288 \ No newline at end of file
1289 -----------------------------------------------
1290 M alpha.link (change 1 of 1)
1291 revert this change? [y/n/q] y
1293 -----------------------------------------------
1296 \ No newline at end of file
1298 \ No newline at end of file
1299 -----------------------------------------------
1300 M epsilon/beta.link (change 1 of 1)
1301 revert this change? [y/n/q] n
1302 -----------------------------------------------
1305 \ No newline at end of file
1307 \ No newline at end of file
1308 -----------------------------------------------
1309 M epsilon.link (change 1 of 1)
1310 revert this change? [y/n/q] y
1313 revert this addition? [y/n] n
1314 -----------------------------------------------
1317 \ No newline at end of file
1319 \ No newline at end of file
1320 -----------------------------------------------
1321 M nonexistent.link (change 1 of 1)
1322 revert this change? [y/n/q] y
1324 -----------------------------------------------
1327 \ No newline at end of file
1329 -----------------------------------------------
1330 M passwd.link (change 1 of 1)
1331 revert this change? [y/n/q] y
1334 revert this deletion? [y/n] n
1336 revert this deletion? [y/n] y
1339 revert this addition? [y/n] y
1342 cmp -s $testroot/stdout.expected $testroot/stdout
1344 if [ $ret -ne 0 ]; then
1345 diff -u $testroot/stdout.expected $testroot/stdout
1346 test_done "$testroot" "$ret"
1350 if ! [ -h $testroot/wt/alpha.link ]; then
1351 echo "alpha.link is not a symlink"
1352 test_done "$testroot" "1"
1356 readlink $testroot/wt/alpha.link > $testroot/stdout
1357 echo "alpha" > $testroot/stdout.expected
1358 cmp -s $testroot/stdout.expected $testroot/stdout
1360 if [ $ret -ne 0 ]; then
1361 diff -u $testroot/stdout.expected $testroot/stdout
1362 test_done "$testroot" "$ret"
1366 if ! [ -h $testroot/wt/epsilon.link ]; then
1367 echo "epsilon.link is not a symlink"
1368 test_done "$testroot" "1"
1372 readlink $testroot/wt/epsilon.link > $testroot/stdout
1373 echo "epsilon" > $testroot/stdout.expected
1374 cmp -s $testroot/stdout.expected $testroot/stdout
1376 if [ $ret -ne 0 ]; then
1377 diff -u $testroot/stdout.expected $testroot/stdout
1378 test_done "$testroot" "$ret"
1382 if [ -h $testroot/wt/passwd.link ]; then
1383 echo "passwd.link should not be a symlink" >&2
1384 test_done "$testroot" "1"
1388 echo -n "/etc/passwd" > $testroot/content.expected
1389 cp $testroot/wt/passwd.link $testroot/content
1391 cmp -s $testroot/content.expected $testroot/content
1393 if [ $ret -ne 0 ]; then
1394 diff -u $testroot/content.expected $testroot/content
1395 test_done "$testroot" "$ret"
1399 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1400 echo "../gamma" > $testroot/stdout.expected
1401 cmp -s $testroot/stdout.expected $testroot/stdout
1403 if [ $ret -ne 0 ]; then
1404 diff -u $testroot/stdout.expected $testroot/stdout
1405 test_done "$testroot" "$ret"
1409 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1410 echo "nonexistent" > $testroot/stdout.expected
1411 cmp -s $testroot/stdout.expected $testroot/stdout
1413 if [ $ret -ne 0 ]; then
1414 diff -u $testroot/stdout.expected $testroot/stdout
1415 test_done "$testroot" "$ret"
1419 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1420 echo "dotgotfoo.link is not a symlink " >&2
1421 test_done "$testroot" "1"
1424 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1425 echo ".got/foo" > $testroot/stdout.expected
1426 cmp -s $testroot/stdout.expected $testroot/stdout
1428 if [ $ret -ne 0 ]; then
1429 diff -u $testroot/stdout.expected $testroot/stdout
1430 test_done "$testroot" "$ret"
1435 if [ -e $testroot/wt/zeta.link ]; then
1436 echo -n "zeta.link should not exist on disk" >&2
1437 test_done "$testroot" "1"
1441 if [ ! -h $testroot/wt/zeta2.link ]; then
1442 echo -n "zeta2.link is not a symlink" >&2
1443 test_done "$testroot" "1"
1447 readlink $testroot/wt/zeta2.link > $testroot/stdout
1448 echo "epsilon/zeta" > $testroot/stdout.expected
1449 cmp -s $testroot/stdout.expected $testroot/stdout
1451 if [ $ret -ne 0 ]; then
1452 diff -u $testroot/stdout.expected $testroot/stdout
1453 test_done "$testroot" "$ret"
1457 if [ ! -h $testroot/wt/zeta3.link ]; then
1458 echo -n "zeta3.link is not a symlink" >&2
1459 test_done "$testroot" "1"
1463 readlink $testroot/wt/zeta3.link > $testroot/stdout
1464 echo "beta" > $testroot/stdout.expected
1465 cmp -s $testroot/stdout.expected $testroot/stdout
1467 if [ $ret -ne 0 ]; then
1468 diff -u $testroot/stdout.expected $testroot/stdout
1469 test_done "$testroot" "$ret"
1473 if [ ! -h $testroot/wt/new.link ]; then
1474 echo -n "new.link is not a symlink" >&2
1475 test_done "$testroot" "1"
1479 (cd $testroot/wt && got status > $testroot/stdout)
1480 echo "? dotgotfoo.link" > $testroot/stdout.expected
1481 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1482 echo "A new.link" >> $testroot/stdout.expected
1483 echo "D zeta.link" >> $testroot/stdout.expected
1484 echo "? zeta3.link" >> $testroot/stdout.expected
1485 cmp -s $testroot/stdout.expected $testroot/stdout
1487 if [ $ret -ne 0 ]; then
1488 diff -u $testroot/stdout.expected $testroot/stdout
1491 test_done "$testroot" "$ret"
1494 test_revert_umask() {
1495 local testroot=`test_init revert_umask`
1497 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1498 echo "edit alpha" > $testroot/wt/alpha
1500 # using a subshell to avoid clobbering global umask
1501 (umask 077 && cd "$testroot/wt" && got revert alpha) \
1504 if [ $ret -ne 0 ]; then
1505 test_done "$testroot" $ret
1509 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1510 echo "alpha is not 0600 after revert" >&2
1511 ls -l "$testroot/wt/alpha" >&2
1512 test_done "$testroot" 1
1515 test_done "$testroot" 0
1519 run_test test_revert_basic
1520 run_test test_revert_rm
1521 run_test test_revert_add
1522 run_test test_revert_multiple
1523 run_test test_revert_file_in_new_subdir
1524 run_test test_revert_no_arguments
1525 run_test test_revert_directory
1526 run_test test_revert_directory_unknown
1527 run_test test_revert_patch
1528 run_test test_revert_patch_added
1529 run_test test_revert_patch_removed
1530 run_test test_revert_patch_one_change
1531 run_test test_revert_added_subtree
1532 run_test test_revert_deleted_subtree
1533 run_test test_revert_symlink
1534 run_test test_revert_patch_symlink
1535 run_test test_revert_umask