Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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.
17 . ./common.sh
19 test_revert_basic() {
20 local testroot=`test_init revert_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
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
36 ret=$?
37 if [ $ret -ne 0 ]; then
38 diff -u $testroot/stdout.expected $testroot/stdout
39 test_done "$testroot" "$ret"
40 return 1
41 fi
43 echo "zeta" > $testroot/content.expected
44 cat $testroot/wt/epsilon/zeta > $testroot/content
46 cmp -s $testroot/content.expected $testroot/content
47 ret=$?
48 if [ $ret -ne 0 ]; then
49 diff -u $testroot/content.expected $testroot/content
50 fi
51 test_done "$testroot" "$ret"
53 }
55 test_revert_rm() {
56 local testroot=`test_init revert_rm`
58 got checkout $testroot/repo $testroot/wt > /dev/null
59 ret=$?
60 if [ $ret -ne 0 ]; then
61 test_done "$testroot" "$ret"
62 return 1
63 fi
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
72 ret=$?
73 if [ $ret -ne 0 ]; then
74 diff -u $testroot/stdout.expected $testroot/stdout
75 test_done "$testroot" "$ret"
76 return 1
77 fi
79 echo "beta" > $testroot/content.expected
80 cat $testroot/wt/beta > $testroot/content
82 cmp -s $testroot/content.expected $testroot/content
83 ret=$?
84 if [ $ret -ne 0 ]; then
85 diff -u $testroot/content.expected $testroot/content
86 fi
87 test_done "$testroot" "$ret"
88 }
90 test_revert_add() {
91 local testroot=`test_init revert_add`
93 got checkout $testroot/repo $testroot/wt > /dev/null
94 ret=$?
95 if [ $ret -ne 0 ]; then
96 test_done "$testroot" "$ret"
97 return 1
98 fi
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
108 ret=$?
109 if [ $ret -ne 0 ]; then
110 diff -u $testroot/stdout.expected $testroot/stdout
111 test_done "$testroot" "$ret"
112 return 1
113 fi
115 echo "new file" > $testroot/content.expected
116 cat $testroot/wt/new > $testroot/content
118 cmp -s $testroot/content.expected $testroot/content
119 ret=$?
120 if [ $ret -ne 0 ]; then
121 diff -u $testroot/content.expected $testroot/content
122 test_done "$testroot" "$ret"
123 return 1
124 fi
126 echo '? new' > $testroot/stdout.expected
128 (cd $testroot/wt && got status > $testroot/stdout)
130 cmp -s $testroot/stdout.expected $testroot/stdout
131 ret=$?
132 if [ $ret -ne 0 ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
134 fi
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
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 test_done "$testroot" "$ret"
145 return 1
146 fi
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
157 ret=$?
158 if [ $ret -ne 0 ]; then
159 diff -u $testroot/stdout.expected $testroot/stdout
160 test_done "$testroot" "$ret"
161 return 1
162 fi
164 echo "alpha" > $testroot/content.expected
165 cat $testroot/wt/alpha > $testroot/content
167 cmp -s $testroot/content.expected $testroot/content
168 ret=$?
169 if [ $ret -ne 0 ]; then
170 diff -u $testroot/content.expected $testroot/content
171 test_done "$testroot" "$ret"
172 return 1
173 fi
175 echo "zeta" > $testroot/content.expected
176 cat $testroot/wt/epsilon/zeta > $testroot/content
178 cmp -s $testroot/content.expected $testroot/content
179 ret=$?
180 if [ $ret -ne 0 ]; then
181 diff -u $testroot/content.expected $testroot/content
182 fi
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
190 ret=$?
191 if [ $ret -ne 0 ]; then
192 test_done "$testroot" "$ret"
193 return 1
194 fi
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
205 ret=$?
206 if [ $ret -ne 0 ]; then
207 diff -u $testroot/stdout.expected $testroot/stdout
208 test_done "$testroot" "$ret"
209 return 1
210 fi
212 (cd $testroot/wt && got status > $testroot/stdout)
214 echo "? newdir/new" > $testroot/stdout.expected
215 cmp -s $testroot/stdout.expected $testroot/stdout
216 ret=$?
217 if [ $ret -ne 0 ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
219 fi
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
228 ret=$?
229 if [ $ret -ne 0 ]; then
230 test_done "$testroot" "$ret"
231 return 1
232 fi
234 echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
236 (cd $testroot/wt && got revert > $testroot/stdout 2> $testroot/stderr)
237 ret=$?
238 if [ $ret -eq 0 ]; then
239 echo "revert command succeeded unexpectedly" >&2
240 test_done "$testroot" "1"
241 return 1
242 fi
244 echo -n > $testroot/stdout.expected
245 cmp -s $testroot/stdout.expected $testroot/stdout
246 ret=$?
247 if [ $ret -ne 0 ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 echo "usage: got revert [-p] [-F response-script] [-R] path ..." \
254 > $testroot/stderr.expected
255 cmp -s $testroot/stderr.expected $testroot/stderr
256 ret=$?
257 if [ $ret -ne 0 ]; then
258 diff -u $testroot/stderr.expected $testroot/stderr
259 fi
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
267 ret=$?
268 if [ $ret -ne 0 ]; then
269 test_done "$testroot" "$ret"
270 return 1
271 fi
273 echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
275 (cd $testroot/wt && got revert . > $testroot/stdout 2> $testroot/stderr)
276 ret=$?
277 if [ $ret -eq 0 ]; then
278 echo "got revert command succeeded unexpectedly" >&2
279 test_done "$testroot" "1"
280 return 1
281 fi
282 echo "got: reverting directories requires -R option" \
283 > $testroot/stderr.expected
284 cmp -s $testroot/stderr.expected $testroot/stderr
285 ret=$?
286 if [ $ret -ne 0 ]; then
287 diff -u $testroot/stderr.expected $testroot/stderr
288 test_done "$testroot" "$ret"
289 return 1
290 fi
292 echo -n > $testroot/stdout.expected
293 cmp -s $testroot/stdout.expected $testroot/stdout
294 ret=$?
295 if [ $ret -ne 0 ]; then
296 diff -u $testroot/stdout.expected $testroot/stdout
297 test_done "$testroot" "$ret"
298 return 1
299 fi
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
305 ret=$?
306 if [ $ret -ne 0 ]; then
307 diff -u $testroot/stdout.expected $testroot/stdout
308 test_done "$testroot" "$ret"
309 return 1
310 fi
312 echo "zeta" > $testroot/content.expected
313 cat $testroot/wt/epsilon/zeta > $testroot/content
315 cmp -s $testroot/content.expected $testroot/content
316 ret=$?
317 if [ $ret -ne 0 ]; then
318 diff -u $testroot/content.expected $testroot/content
319 fi
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
327 ret=$?
328 if [ $ret -ne 0 ]; then
329 test_done "$testroot" "$ret"
330 return 1
331 fi
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
342 ret=$?
343 if [ $ret -ne 0 ]; then
344 diff -u $testroot/stdout.expected $testroot/stdout
345 test_done "$testroot" "$ret"
346 return 1
347 fi
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
353 ret=$?
354 if [ $ret -ne 0 ]; then
355 diff -u $testroot/content.expected $testroot/content
356 test_done "$testroot" "$ret"
357 return 1
358 fi
360 echo "zeta" > $testroot/content.expected
361 cat $testroot/wt/epsilon/zeta > $testroot/content
363 cmp -s $testroot/content.expected $testroot/content
364 ret=$?
365 if [ $ret -ne 0 ]; then
366 diff -u $testroot/content.expected $testroot/content
367 fi
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
381 ret=$?
382 if [ $ret -ne 0 ]; then
383 test_done "$testroot" "$ret"
384 return 1
385 fi
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)
397 ret=$?
398 if [ $ret -ne 0 ]; then
399 echo "got revert command failed unexpectedly" >&2
400 test_done "$testroot" "1"
401 return 1
402 fi
403 cat > $testroot/stdout.expected <<EOF
404 -----------------------------------------------
405 @@ -1,5 +1,5 @@
407 -2
408 +a
412 -----------------------------------------------
413 M numbers (change 1 of 3)
414 revert this change? [y/n/q] n
415 -----------------------------------------------
416 @@ -4,7 +4,7 @@
420 -7
421 +b
424 10
425 -----------------------------------------------
426 M numbers (change 2 of 3)
427 revert this change? [y/n/q] n
428 -----------------------------------------------
429 @@ -13,4 +13,4 @@
430 13
431 14
432 15
433 -16
434 +c
435 -----------------------------------------------
436 M numbers (change 3 of 3)
437 revert this change? [y/n/q] n
438 EOF
439 cmp -s $testroot/stdout.expected $testroot/stdout
440 ret=$?
441 if [ $ret -ne 0 ]; then
442 diff -u $testroot/stdout.expected $testroot/stdout
443 test_done "$testroot" "$ret"
444 return 1
445 fi
447 (cd $testroot/wt && got status > $testroot/stdout)
448 echo "M numbers" > $testroot/stdout.expected
449 cmp -s $testroot/stdout.expected $testroot/stdout
450 ret=$?
451 if [ $ret -ne 0 ]; then
452 diff -u $testroot/stdout.expected $testroot/stdout
453 test_done "$testroot" "$ret"
454 return 1
455 fi
457 (cd $testroot/wt && got diff > $testroot/stdout)
458 cmp -s $testroot/numbers.diff $testroot/stdout
459 ret=$?
460 if [ $ret -ne 0 ]; then
461 diff -u $testroot/numbers.diff $testroot/stdout
462 test_done "$testroot" "$ret"
463 return 1
464 fi
466 # revert first hunk
467 printf "y\nn\nn\n" > $testroot/patchscript
468 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
469 numbers > $testroot/stdout)
470 ret=$?
471 if [ $ret -ne 0 ]; then
472 echo "got revert command failed unexpectedly" >&2
473 test_done "$testroot" "1"
474 return 1
475 fi
476 cat > $testroot/stdout.expected <<EOF
477 -----------------------------------------------
478 @@ -1,5 +1,5 @@
480 -2
481 +a
485 -----------------------------------------------
486 M numbers (change 1 of 3)
487 revert this change? [y/n/q] y
488 -----------------------------------------------
489 @@ -4,7 +4,7 @@
493 -7
494 +b
497 10
498 -----------------------------------------------
499 M numbers (change 2 of 3)
500 revert this change? [y/n/q] n
501 -----------------------------------------------
502 @@ -13,4 +13,4 @@
503 13
504 14
505 15
506 -16
507 +c
508 -----------------------------------------------
509 M numbers (change 3 of 3)
510 revert this change? [y/n/q] n
511 EOF
512 cmp -s $testroot/stdout.expected $testroot/stdout
513 ret=$?
514 if [ $ret -ne 0 ]; then
515 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
517 return 1
518 fi
520 (cd $testroot/wt && got status > $testroot/stdout)
521 echo "M numbers" > $testroot/stdout.expected
522 cmp -s $testroot/stdout.expected $testroot/stdout
523 ret=$?
524 if [ $ret -ne 0 ]; then
525 diff -u $testroot/stdout.expected $testroot/stdout
526 test_done "$testroot" "$ret"
527 return 1
528 fi
530 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
531 echo -n 'blob - ' >> $testroot/stdout.expected
532 got tree -r $testroot/repo -i -c $commit_id \
533 | grep 'numbers$' | cut -d' ' -f 1 \
534 >> $testroot/stdout.expected
535 echo 'file + numbers' >> $testroot/stdout.expected
536 cat >> $testroot/stdout.expected <<EOF
537 --- numbers
538 +++ numbers
539 @@ -4,7 +4,7 @@
543 -7
544 +b
547 10
548 @@ -13,4 +13,4 @@
549 13
550 14
551 15
552 -16
553 +c
554 EOF
555 (cd $testroot/wt && got diff > $testroot/stdout)
556 cmp -s $testroot/stdout.expected $testroot/stdout
557 ret=$?
558 if [ $ret -ne 0 ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 test_done "$testroot" "$ret"
561 return 1
562 fi
564 # put first hunk back
565 sed -i -e 's/^2$/a/' $testroot/wt/numbers
567 # revert middle hunk
568 printf "n\ny\nn\n" > $testroot/patchscript
569 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
570 numbers > $testroot/stdout)
572 cat > $testroot/stdout.expected <<EOF
573 -----------------------------------------------
574 @@ -1,5 +1,5 @@
576 -2
577 +a
581 -----------------------------------------------
582 M numbers (change 1 of 3)
583 revert this change? [y/n/q] n
584 -----------------------------------------------
585 @@ -4,7 +4,7 @@
589 -7
590 +b
593 10
594 -----------------------------------------------
595 M numbers (change 2 of 3)
596 revert this change? [y/n/q] y
597 -----------------------------------------------
598 @@ -13,4 +13,4 @@
599 13
600 14
601 15
602 -16
603 +c
604 -----------------------------------------------
605 M numbers (change 3 of 3)
606 revert this change? [y/n/q] n
607 EOF
608 cmp -s $testroot/stdout.expected $testroot/stdout
609 ret=$?
610 if [ $ret -ne 0 ]; then
611 diff -u $testroot/stdout.expected $testroot/stdout
612 test_done "$testroot" "$ret"
613 return 1
614 fi
616 (cd $testroot/wt && got status > $testroot/stdout)
617 echo "M numbers" > $testroot/stdout.expected
618 cmp -s $testroot/stdout.expected $testroot/stdout
619 ret=$?
620 if [ $ret -ne 0 ]; then
621 diff -u $testroot/stdout.expected $testroot/stdout
622 test_done "$testroot" "$ret"
623 return 1
624 fi
626 (cd $testroot/wt && got diff > $testroot/stdout)
628 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
629 echo -n 'blob - ' >> $testroot/stdout.expected
630 got tree -r $testroot/repo -i -c $commit_id \
631 | grep 'numbers$' | cut -d' ' -f 1 \
632 >> $testroot/stdout.expected
633 echo 'file + numbers' >> $testroot/stdout.expected
634 cat >> $testroot/stdout.expected <<EOF
635 --- numbers
636 +++ numbers
637 @@ -1,5 +1,5 @@
639 -2
640 +a
644 @@ -13,4 +13,4 @@
645 13
646 14
647 15
648 -16
649 +c
650 EOF
651 cmp -s $testroot/stdout.expected $testroot/stdout
652 ret=$?
653 if [ $ret -ne 0 ]; then
654 diff -u $testroot/stdout.expected $testroot/stdout
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 # revert last hunk
660 printf "n\ny\n" > $testroot/patchscript
661 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
662 numbers > $testroot/stdout)
663 cat > $testroot/stdout.expected <<EOF
664 -----------------------------------------------
665 @@ -1,5 +1,5 @@
667 -2
668 +a
672 -----------------------------------------------
673 M numbers (change 1 of 2)
674 revert this change? [y/n/q] n
675 -----------------------------------------------
676 @@ -13,4 +13,4 @@
677 13
678 14
679 15
680 -16
681 +c
682 -----------------------------------------------
683 M numbers (change 2 of 2)
684 revert this change? [y/n/q] y
685 EOF
686 cmp -s $testroot/stdout.expected $testroot/stdout
687 ret=$?
688 if [ $ret -ne 0 ]; then
689 diff -u $testroot/stdout.expected $testroot/stdout
690 test_done "$testroot" "$ret"
691 return 1
692 fi
694 (cd $testroot/wt && got diff > $testroot/stdout)
696 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
697 echo -n 'blob - ' >> $testroot/stdout.expected
698 got tree -r $testroot/repo -i -c $commit_id \
699 | grep 'numbers$' | cut -d' ' -f 1 \
700 >> $testroot/stdout.expected
701 echo 'file + numbers' >> $testroot/stdout.expected
702 cat >> $testroot/stdout.expected <<EOF
703 --- numbers
704 +++ numbers
705 @@ -1,5 +1,5 @@
707 -2
708 +a
712 EOF
713 cmp -s $testroot/stdout.expected $testroot/stdout
714 ret=$?
715 if [ $ret -ne 0 ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
717 fi
718 test_done "$testroot" "$ret"
721 test_revert_patch_added() {
722 local testroot=`test_init revert_patch_added`
723 local commit_id=`git_show_head $testroot/repo`
725 got checkout $testroot/repo $testroot/wt > /dev/null
726 ret=$?
727 if [ $ret -ne 0 ]; then
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 echo "new" > $testroot/wt/epsilon/new
733 (cd $testroot/wt && got add epsilon/new > /dev/null)
735 printf "n\n" > $testroot/patchscript
736 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
737 epsilon/new > $testroot/stdout)
739 echo "A epsilon/new" > $testroot/stdout.expected
740 echo "revert this addition? [y/n] n" >> $testroot/stdout.expected
741 cmp -s $testroot/stdout.expected $testroot/stdout
742 ret=$?
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/stdout.expected $testroot/stdout
745 test_done "$testroot" "$ret"
746 return 1
747 fi
749 (cd $testroot/wt && got status > $testroot/stdout)
750 echo "A epsilon/new" > $testroot/stdout.expected
751 cmp -s $testroot/stdout.expected $testroot/stdout
752 ret=$?
753 if [ $ret -ne 0 ]; then
754 diff -u $testroot/stdout.expected $testroot/stdout
755 test_done "$testroot" "$ret"
756 return 1
757 fi
759 printf "y\n" > $testroot/patchscript
760 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
761 epsilon/new > $testroot/stdout)
763 echo "A epsilon/new" > $testroot/stdout.expected
764 echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
765 echo "R epsilon/new" >> $testroot/stdout.expected
766 cmp -s $testroot/stdout.expected $testroot/stdout
767 ret=$?
768 if [ $ret -ne 0 ]; then
769 diff -u $testroot/stdout.expected $testroot/stdout
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 (cd $testroot/wt && got status > $testroot/stdout)
775 echo "? epsilon/new" > $testroot/stdout.expected
776 cmp -s $testroot/stdout.expected $testroot/stdout
777 ret=$?
778 if [ $ret -ne 0 ]; then
779 diff -u $testroot/stdout.expected $testroot/stdout
780 fi
781 test_done "$testroot" "$ret"
784 test_revert_patch_removed() {
785 local testroot=`test_init revert_patch_removed`
786 local commit_id=`git_show_head $testroot/repo`
788 got checkout $testroot/repo $testroot/wt > /dev/null
789 ret=$?
790 if [ $ret -ne 0 ]; then
791 test_done "$testroot" "$ret"
792 return 1
793 fi
795 (cd $testroot/wt && got rm beta > /dev/null)
797 printf "n\n" > $testroot/patchscript
798 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
799 beta > $testroot/stdout)
800 echo "D beta" > $testroot/stdout.expected
801 echo "revert this deletion? [y/n] n" >> $testroot/stdout.expected
802 cmp -s $testroot/stdout.expected $testroot/stdout
803 ret=$?
804 if [ $ret -ne 0 ]; then
805 diff -u $testroot/stdout.expected $testroot/stdout
806 test_done "$testroot" "$ret"
807 return 1
808 fi
810 (cd $testroot/wt && got status > $testroot/stdout)
811 echo "D beta" > $testroot/stdout.expected
812 cmp -s $testroot/stdout.expected $testroot/stdout
813 ret=$?
814 if [ $ret -ne 0 ]; then
815 diff -u $testroot/stdout.expected $testroot/stdout
816 test_done "$testroot" "$ret"
817 return 1
818 fi
820 printf "y\n" > $testroot/patchscript
821 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
822 beta > $testroot/stdout)
824 echo "D beta" > $testroot/stdout.expected
825 echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
826 echo "R beta" >> $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
828 ret=$?
829 if [ $ret -ne 0 ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
831 test_done "$testroot" "$ret"
832 return 1
833 fi
835 (cd $testroot/wt && got status > $testroot/stdout)
836 echo -n > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
838 ret=$?
839 if [ $ret -ne 0 ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
841 fi
842 test_done "$testroot" "$ret"
845 test_revert_patch_one_change() {
846 local testroot=`test_init revert_patch_one_change`
848 jot 16 > $testroot/repo/numbers
849 (cd $testroot/repo && git add numbers)
850 git_commit $testroot/repo -m "added numbers file"
851 local commit_id=`git_show_head $testroot/repo`
853 got checkout $testroot/repo $testroot/wt > /dev/null
854 ret=$?
855 if [ $ret -ne 0 ]; then
856 test_done "$testroot" "$ret"
857 return 1
858 fi
860 # Ensure file size is changed. Avoids race condition causing test
861 # failures where 'got revert' does not see changes to revert if
862 # timestamps and size in stat info remain unchanged.
863 sed -i -e 's/^2$/aa/' $testroot/wt/numbers
865 # revert change with -p
866 printf "y\n" > $testroot/patchscript
867 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
868 numbers > $testroot/stdout)
869 ret=$?
870 if [ $ret -ne 0 ]; then
871 echo "got revert command failed unexpectedly" >&2
872 test_done "$testroot" "1"
873 return 1
874 fi
875 cat > $testroot/stdout.expected <<EOF
876 -----------------------------------------------
877 @@ -1,5 +1,5 @@
879 -2
880 +aa
884 -----------------------------------------------
885 M numbers (change 1 of 1)
886 revert this change? [y/n/q] y
887 EOF
888 ret=$?
889 if [ $ret -ne 0 ]; then
890 echo "got revert command failed unexpectedly" >&2
891 test_done "$testroot" "1"
892 return 1
893 fi
895 cmp -s $testroot/stdout.expected $testroot/stdout
896 ret=$?
897 if [ $ret -ne 0 ]; then
898 diff -u $testroot/stdout.expected $testroot/stdout
899 test_done "$testroot" "$ret"
900 return 1
901 fi
903 (cd $testroot/wt && got status > $testroot/stdout)
904 echo -n > $testroot/stdout.expected
905 cmp -s $testroot/stdout.expected $testroot/stdout
906 ret=$?
907 if [ $ret -ne 0 ]; then
908 diff -u $testroot/stdout.expected $testroot/stdout
909 test_done "$testroot" "$ret"
910 return 1
911 fi
913 (cd $testroot/wt && got diff > $testroot/stdout)
914 echo -n > $testroot/stdout.expected
915 cmp -s $testroot/stdout.expected $testroot/stdout
916 ret=$?
917 if [ $ret -ne 0 ]; then
918 diff -u $testroot/stdout.expected $testroot/stdout
919 fi
920 test_done "$testroot" "$ret"
923 test_revert_added_subtree() {
924 local testroot=`test_init revert_added_subtree`
926 got checkout $testroot/repo $testroot/wt > /dev/null
927 ret=$?
928 if [ $ret -ne 0 ]; then
929 test_done "$testroot" "$ret"
930 return 1
931 fi
933 mkdir -p $testroot/wt/epsilon/foo/bar/baz
934 mkdir -p $testroot/wt/epsilon/foo/bar/bax
935 echo "new file" > $testroot/wt/epsilon/foo/a.o
936 echo "new file" > $testroot/wt/epsilon/foo/a.o
937 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
938 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
939 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
940 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
941 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
942 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
943 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
944 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
945 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
946 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
947 (cd $testroot/wt && got add -R epsilon >/dev/null)
949 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
950 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
951 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
952 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
953 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
954 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
955 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
956 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
957 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
958 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
959 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
961 (cd $testroot/wt && got revert -R . > $testroot/stdout)
963 cmp -s $testroot/stdout.expected $testroot/stdout
964 ret=$?
965 if [ $ret -ne 0 ]; then
966 diff -u $testroot/stdout.expected $testroot/stdout
967 test_done "$testroot" "$ret"
968 return 1
969 fi
971 echo "? epsilon/foo/a.o" > $testroot/stdout.expected
972 echo "? epsilon/foo/bar/b.d" >> $testroot/stdout.expected
973 echo "? epsilon/foo/bar/b.o" >> $testroot/stdout.expected
974 echo "? epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
975 echo "? epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
976 echo "? epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
977 echo "? epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
978 echo "? epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
979 echo "? epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
980 echo "? epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
981 echo "? epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
983 (cd $testroot/wt && got status > $testroot/stdout)
985 cmp -s $testroot/stdout.expected $testroot/stdout
986 ret=$?
987 if [ $ret -ne 0 ]; then
988 diff -u $testroot/stdout.expected $testroot/stdout
989 fi
990 test_done "$testroot" "$ret"
993 test_revert_deleted_subtree() {
994 local testroot=`test_init revert_deleted_subtree`
996 got checkout $testroot/repo $testroot/wt > /dev/null
997 ret=$?
998 if [ $ret -ne 0 ]; then
999 test_done "$testroot" "$ret"
1000 return 1
1003 mkdir -p $testroot/wt/epsilon/foo/bar/baz
1004 mkdir -p $testroot/wt/epsilon/foo/bar/bax
1005 echo "new file" > $testroot/wt/epsilon/foo/a.o
1006 echo "new file" > $testroot/wt/epsilon/foo/a.o
1007 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
1008 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
1009 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
1010 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
1011 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
1012 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
1013 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
1014 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
1015 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
1016 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
1017 (cd $testroot/wt && got add -R epsilon >/dev/null)
1018 (cd $testroot/wt && got commit -m "add subtree" >/dev/null)
1020 # now delete and revert the entire subtree
1021 (cd $testroot/wt && got rm -R epsilon/foo >/dev/null)
1023 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
1024 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
1025 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
1026 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
1027 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
1028 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
1029 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
1030 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
1031 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
1032 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
1033 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
1035 (cd $testroot/wt && got revert -R . > $testroot/stdout)
1037 cmp -s $testroot/stdout.expected $testroot/stdout
1038 ret=$?
1039 if [ $ret -ne 0 ]; then
1040 diff -u $testroot/stdout.expected $testroot/stdout
1041 test_done "$testroot" "$ret"
1042 return 1
1045 echo -n > $testroot/stdout.expected
1046 (cd $testroot/wt && got status > $testroot/stdout)
1048 cmp -s $testroot/stdout.expected $testroot/stdout
1049 ret=$?
1050 if [ $ret -ne 0 ]; then
1051 diff -u $testroot/stdout.expected $testroot/stdout
1053 test_done "$testroot" "$ret"
1056 test_revert_symlink() {
1057 local testroot=`test_init revert_symlink`
1059 (cd $testroot/repo && ln -s alpha alpha.link)
1060 (cd $testroot/repo && ln -s epsilon epsilon.link)
1061 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1062 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1063 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1064 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1065 (cd $testroot/repo && git add .)
1066 git_commit $testroot/repo -m "add symlinks"
1067 local commit_id1=`git_show_head $testroot/repo`
1069 got checkout $testroot/repo $testroot/wt > /dev/null
1071 # symlink to file A now points to file B
1072 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1073 # symlink to a directory A now points to file B
1074 (cd $testroot/wt && ln -sfh beta epsilon.link)
1075 # "bad" symlink now contains a different target path
1076 echo "foo" > $testroot/wt/passwd.link
1077 # relative symlink to directory A now points to relative directory B
1078 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
1079 # an unversioned symlink
1080 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1081 # symlink to file A now points to non-existent file B
1082 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1083 # removed symlink
1084 (cd $testroot/wt && got rm zeta.link > /dev/null)
1085 # added symlink
1086 (cd $testroot/wt && ln -sf beta new.link)
1087 (cd $testroot/wt && got add new.link > /dev/null)
1089 (cd $testroot/wt && got revert alpha.link epsilon.link \
1090 passwd.link epsilon/beta.link dotgotfoo.link \
1091 nonexistent.link zeta.link new.link > $testroot/stdout)
1093 cat > $testroot/stdout.expected <<EOF
1094 R alpha.link
1095 R epsilon/beta.link
1096 R epsilon.link
1097 R new.link
1098 R nonexistent.link
1099 R passwd.link
1100 R zeta.link
1101 EOF
1102 cmp -s $testroot/stdout.expected $testroot/stdout
1103 ret=$?
1104 if [ $ret -ne 0 ]; then
1105 diff -u $testroot/stdout.expected $testroot/stdout
1106 test_done "$testroot" "$ret"
1107 return 1
1110 if ! [ -h $testroot/wt/alpha.link ]; then
1111 echo "alpha.link is not a symlink"
1112 test_done "$testroot" "1"
1113 return 1
1116 readlink $testroot/wt/alpha.link > $testroot/stdout
1117 echo "alpha" > $testroot/stdout.expected
1118 cmp -s $testroot/stdout.expected $testroot/stdout
1119 ret=$?
1120 if [ $ret -ne 0 ]; then
1121 diff -u $testroot/stdout.expected $testroot/stdout
1122 test_done "$testroot" "$ret"
1123 return 1
1126 if ! [ -h $testroot/wt/epsilon.link ]; then
1127 echo "epsilon.link is not a symlink"
1128 test_done "$testroot" "1"
1129 return 1
1132 readlink $testroot/wt/epsilon.link > $testroot/stdout
1133 echo "epsilon" > $testroot/stdout.expected
1134 cmp -s $testroot/stdout.expected $testroot/stdout
1135 ret=$?
1136 if [ $ret -ne 0 ]; then
1137 diff -u $testroot/stdout.expected $testroot/stdout
1138 test_done "$testroot" "$ret"
1139 return 1
1142 if [ -h $testroot/wt/passwd.link ]; then
1143 echo "passwd.link should not be a symlink" >&2
1144 test_done "$testroot" "1"
1145 return 1
1148 echo -n "/etc/passwd" > $testroot/content.expected
1149 cp $testroot/wt/passwd.link $testroot/content
1151 cmp -s $testroot/content.expected $testroot/content
1152 ret=$?
1153 if [ $ret -ne 0 ]; then
1154 diff -u $testroot/content.expected $testroot/content
1155 test_done "$testroot" "$ret"
1156 return 1
1159 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1160 echo "../beta" > $testroot/stdout.expected
1161 cmp -s $testroot/stdout.expected $testroot/stdout
1162 ret=$?
1163 if [ $ret -ne 0 ]; then
1164 diff -u $testroot/stdout.expected $testroot/stdout
1165 test_done "$testroot" "$ret"
1166 return 1
1169 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1170 echo "nonexistent" > $testroot/stdout.expected
1171 cmp -s $testroot/stdout.expected $testroot/stdout
1172 ret=$?
1173 if [ $ret -ne 0 ]; then
1174 diff -u $testroot/stdout.expected $testroot/stdout
1175 test_done "$testroot" "$ret"
1176 return 1
1179 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1180 echo "dotgotfoo.link is not a symlink " >&2
1181 test_done "$testroot" "1"
1182 return 1
1184 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1185 echo ".got/foo" > $testroot/stdout.expected
1186 cmp -s $testroot/stdout.expected $testroot/stdout
1187 ret=$?
1188 if [ $ret -ne 0 ]; then
1189 diff -u $testroot/stdout.expected $testroot/stdout
1190 test_done "$testroot" "$ret"
1191 return 1
1194 if [ ! -h $testroot/wt/zeta.link ]; then
1195 echo -n "zeta.link is not a symlink" >&2
1196 test_done "$testroot" "1"
1197 return 1
1200 readlink $testroot/wt/zeta.link > $testroot/stdout
1201 echo "epsilon/zeta" > $testroot/stdout.expected
1202 cmp -s $testroot/stdout.expected $testroot/stdout
1203 ret=$?
1204 if [ $ret -ne 0 ]; then
1205 diff -u $testroot/stdout.expected $testroot/stdout
1206 test_done "$testroot" "$ret"
1207 return 1
1210 if [ ! -h $testroot/wt/new.link ]; then
1211 echo -n "new.link is not a symlink" >&2
1212 test_done "$testroot" "1"
1213 return 1
1216 (cd $testroot/wt && got status > $testroot/stdout)
1217 echo "? dotgotfoo.link" > $testroot/stdout.expected
1218 echo "? new.link" >> $testroot/stdout.expected
1219 cmp -s $testroot/stdout.expected $testroot/stdout
1220 ret=$?
1221 if [ $ret -ne 0 ]; then
1222 diff -u $testroot/stdout.expected $testroot/stdout
1223 return 1
1225 test_done "$testroot" "$ret"
1228 test_revert_patch_symlink() {
1229 local testroot=`test_init revert_patch_symlink`
1231 (cd $testroot/repo && ln -s alpha alpha.link)
1232 (cd $testroot/repo && ln -s epsilon epsilon.link)
1233 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1234 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1235 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1236 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1237 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1238 (cd $testroot/repo && git add .)
1239 git_commit $testroot/repo -m "add symlinks"
1240 local commit_id1=`git_show_head $testroot/repo`
1242 got checkout $testroot/repo $testroot/wt > /dev/null
1244 # symlink to file A now points to file B
1245 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1246 # symlink to a directory A now points to file B
1247 (cd $testroot/wt && ln -sfh beta epsilon.link)
1248 # "bad" symlink now contains a different target path
1249 echo "foo" > $testroot/wt/passwd.link
1250 # relative symlink to directory A now points to relative directory B
1251 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
1252 # an unversioned symlink
1253 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1254 # symlink to file A now points to non-existent file B
1255 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1256 # removed symlink
1257 (cd $testroot/wt && got rm zeta.link > /dev/null)
1258 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1259 # added symlink
1260 (cd $testroot/wt && ln -sf beta new.link)
1261 (cd $testroot/wt && got add new.link > /dev/null)
1262 (cd $testroot/wt && ln -sf beta zeta3.link)
1263 (cd $testroot/wt && got add zeta3.link > /dev/null)
1265 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1266 (cd $testroot/wt && got revert -F $testroot/patchscript -p -R . \
1267 > $testroot/stdout)
1268 ret=$?
1269 if [ $ret -ne 0 ]; then
1270 echo "got revert command failed unexpectedly" >&2
1271 test_done "$testroot" "1"
1272 return 1
1274 cat > $testroot/stdout.expected <<EOF
1275 -----------------------------------------------
1276 @@ -1 +1 @@
1277 -alpha
1278 \ No newline at end of file
1279 +gamma/delta
1280 \ No newline at end of file
1281 -----------------------------------------------
1282 M alpha.link (change 1 of 1)
1283 revert this change? [y/n/q] y
1284 R alpha.link
1285 -----------------------------------------------
1286 @@ -1 +1 @@
1287 -../beta
1288 \ No newline at end of file
1289 +../gamma
1290 \ No newline at end of file
1291 -----------------------------------------------
1292 M epsilon/beta.link (change 1 of 1)
1293 revert this change? [y/n/q] n
1294 -----------------------------------------------
1295 @@ -1 +1 @@
1296 -epsilon
1297 \ No newline at end of file
1298 +beta
1299 \ No newline at end of file
1300 -----------------------------------------------
1301 M epsilon.link (change 1 of 1)
1302 revert this change? [y/n/q] y
1303 R epsilon.link
1304 A new.link
1305 revert this addition? [y/n] n
1306 -----------------------------------------------
1307 @@ -1 +1 @@
1308 -nonexistent
1309 \ No newline at end of file
1310 +nonexistent2
1311 \ No newline at end of file
1312 -----------------------------------------------
1313 M nonexistent.link (change 1 of 1)
1314 revert this change? [y/n/q] y
1315 R nonexistent.link
1316 -----------------------------------------------
1317 @@ -1 +1 @@
1318 -/etc/passwd
1319 \ No newline at end of file
1320 +foo
1321 -----------------------------------------------
1322 M passwd.link (change 1 of 1)
1323 revert this change? [y/n/q] y
1324 R passwd.link
1325 D zeta.link
1326 revert this deletion? [y/n] n
1327 D zeta2.link
1328 revert this deletion? [y/n] y
1329 R zeta2.link
1330 A zeta3.link
1331 revert this addition? [y/n] y
1332 R zeta3.link
1333 EOF
1334 cmp -s $testroot/stdout.expected $testroot/stdout
1335 ret=$?
1336 if [ $ret -ne 0 ]; then
1337 diff -u $testroot/stdout.expected $testroot/stdout
1338 test_done "$testroot" "$ret"
1339 return 1
1342 if ! [ -h $testroot/wt/alpha.link ]; then
1343 echo "alpha.link is not a symlink"
1344 test_done "$testroot" "1"
1345 return 1
1348 readlink $testroot/wt/alpha.link > $testroot/stdout
1349 echo "alpha" > $testroot/stdout.expected
1350 cmp -s $testroot/stdout.expected $testroot/stdout
1351 ret=$?
1352 if [ $ret -ne 0 ]; then
1353 diff -u $testroot/stdout.expected $testroot/stdout
1354 test_done "$testroot" "$ret"
1355 return 1
1358 if ! [ -h $testroot/wt/epsilon.link ]; then
1359 echo "epsilon.link is not a symlink"
1360 test_done "$testroot" "1"
1361 return 1
1364 readlink $testroot/wt/epsilon.link > $testroot/stdout
1365 echo "epsilon" > $testroot/stdout.expected
1366 cmp -s $testroot/stdout.expected $testroot/stdout
1367 ret=$?
1368 if [ $ret -ne 0 ]; then
1369 diff -u $testroot/stdout.expected $testroot/stdout
1370 test_done "$testroot" "$ret"
1371 return 1
1374 if [ -h $testroot/wt/passwd.link ]; then
1375 echo "passwd.link should not be a symlink" >&2
1376 test_done "$testroot" "1"
1377 return 1
1380 echo -n "/etc/passwd" > $testroot/content.expected
1381 cp $testroot/wt/passwd.link $testroot/content
1383 cmp -s $testroot/content.expected $testroot/content
1384 ret=$?
1385 if [ $ret -ne 0 ]; then
1386 diff -u $testroot/content.expected $testroot/content
1387 test_done "$testroot" "$ret"
1388 return 1
1391 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1392 echo "../gamma" > $testroot/stdout.expected
1393 cmp -s $testroot/stdout.expected $testroot/stdout
1394 ret=$?
1395 if [ $ret -ne 0 ]; then
1396 diff -u $testroot/stdout.expected $testroot/stdout
1397 test_done "$testroot" "$ret"
1398 return 1
1401 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1402 echo "nonexistent" > $testroot/stdout.expected
1403 cmp -s $testroot/stdout.expected $testroot/stdout
1404 ret=$?
1405 if [ $ret -ne 0 ]; then
1406 diff -u $testroot/stdout.expected $testroot/stdout
1407 test_done "$testroot" "$ret"
1408 return 1
1411 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1412 echo "dotgotfoo.link is not a symlink " >&2
1413 test_done "$testroot" "1"
1414 return 1
1416 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1417 echo ".got/foo" > $testroot/stdout.expected
1418 cmp -s $testroot/stdout.expected $testroot/stdout
1419 ret=$?
1420 if [ $ret -ne 0 ]; then
1421 diff -u $testroot/stdout.expected $testroot/stdout
1422 test_done "$testroot" "$ret"
1423 return 1
1427 if [ -e $testroot/wt/zeta.link ]; then
1428 echo -n "zeta.link should not exist on disk" >&2
1429 test_done "$testroot" "1"
1430 return 1
1433 if [ ! -h $testroot/wt/zeta2.link ]; then
1434 echo -n "zeta2.link is not a symlink" >&2
1435 test_done "$testroot" "1"
1436 return 1
1439 readlink $testroot/wt/zeta2.link > $testroot/stdout
1440 echo "epsilon/zeta" > $testroot/stdout.expected
1441 cmp -s $testroot/stdout.expected $testroot/stdout
1442 ret=$?
1443 if [ $ret -ne 0 ]; then
1444 diff -u $testroot/stdout.expected $testroot/stdout
1445 test_done "$testroot" "$ret"
1446 return 1
1449 if [ ! -h $testroot/wt/zeta3.link ]; then
1450 echo -n "zeta3.link is not a symlink" >&2
1451 test_done "$testroot" "1"
1452 return 1
1455 readlink $testroot/wt/zeta3.link > $testroot/stdout
1456 echo "beta" > $testroot/stdout.expected
1457 cmp -s $testroot/stdout.expected $testroot/stdout
1458 ret=$?
1459 if [ $ret -ne 0 ]; then
1460 diff -u $testroot/stdout.expected $testroot/stdout
1461 test_done "$testroot" "$ret"
1462 return 1
1465 if [ ! -h $testroot/wt/new.link ]; then
1466 echo -n "new.link is not a symlink" >&2
1467 test_done "$testroot" "1"
1468 return 1
1471 (cd $testroot/wt && got status > $testroot/stdout)
1472 echo "? dotgotfoo.link" > $testroot/stdout.expected
1473 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1474 echo "A new.link" >> $testroot/stdout.expected
1475 echo "D zeta.link" >> $testroot/stdout.expected
1476 echo "? zeta3.link" >> $testroot/stdout.expected
1477 cmp -s $testroot/stdout.expected $testroot/stdout
1478 ret=$?
1479 if [ $ret -ne 0 ]; then
1480 diff -u $testroot/stdout.expected $testroot/stdout
1481 return 1
1483 test_done "$testroot" "$ret"
1486 test_parseargs "$@"
1487 run_test test_revert_basic
1488 run_test test_revert_rm
1489 run_test test_revert_add
1490 run_test test_revert_multiple
1491 run_test test_revert_file_in_new_subdir
1492 run_test test_revert_no_arguments
1493 run_test test_revert_directory
1494 run_test test_revert_directory_unknown
1495 run_test test_revert_patch
1496 run_test test_revert_patch_added
1497 run_test test_revert_patch_removed
1498 run_test test_revert_patch_one_change
1499 run_test test_revert_added_subtree
1500 run_test test_revert_deleted_subtree
1501 run_test test_revert_symlink
1502 run_test test_revert_patch_symlink