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 [-pR] [-F response-script] 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 $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
539 --- numbers
540 +++ numbers
541 @@ -4,7 +4,7 @@
545 -7
546 +b
549 10
550 @@ -13,4 +13,4 @@
551 13
552 14
553 15
554 -16
555 +c
556 EOF
557 (cd $testroot/wt && got diff > $testroot/stdout)
558 cmp -s $testroot/stdout.expected $testroot/stdout
559 ret=$?
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
563 return 1
564 fi
566 # put first hunk back
567 sed -i -e 's/^2$/a/' $testroot/wt/numbers
569 # revert middle hunk
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 -----------------------------------------------
576 @@ -1,5 +1,5 @@
578 -2
579 +a
583 -----------------------------------------------
584 M numbers (change 1 of 3)
585 revert this change? [y/n/q] n
586 -----------------------------------------------
587 @@ -4,7 +4,7 @@
591 -7
592 +b
595 10
596 -----------------------------------------------
597 M numbers (change 2 of 3)
598 revert this change? [y/n/q] y
599 -----------------------------------------------
600 @@ -13,4 +13,4 @@
601 13
602 14
603 15
604 -16
605 +c
606 -----------------------------------------------
607 M numbers (change 3 of 3)
608 revert this change? [y/n/q] n
609 EOF
610 cmp -s $testroot/stdout.expected $testroot/stdout
611 ret=$?
612 if [ $ret -ne 0 ]; then
613 diff -u $testroot/stdout.expected $testroot/stdout
614 test_done "$testroot" "$ret"
615 return 1
616 fi
618 (cd $testroot/wt && got status > $testroot/stdout)
619 echo "M numbers" > $testroot/stdout.expected
620 cmp -s $testroot/stdout.expected $testroot/stdout
621 ret=$?
622 if [ $ret -ne 0 ]; then
623 diff -u $testroot/stdout.expected $testroot/stdout
624 test_done "$testroot" "$ret"
625 return 1
626 fi
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
639 --- numbers
640 +++ numbers
641 @@ -1,5 +1,5 @@
643 -2
644 +a
648 @@ -13,4 +13,4 @@
649 13
650 14
651 15
652 -16
653 +c
654 EOF
655 cmp -s $testroot/stdout.expected $testroot/stdout
656 ret=$?
657 if [ $ret -ne 0 ]; then
658 diff -u $testroot/stdout.expected $testroot/stdout
659 test_done "$testroot" "$ret"
660 return 1
661 fi
663 # revert last hunk
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 -----------------------------------------------
669 @@ -1,5 +1,5 @@
671 -2
672 +a
676 -----------------------------------------------
677 M numbers (change 1 of 2)
678 revert this change? [y/n/q] n
679 -----------------------------------------------
680 @@ -13,4 +13,4 @@
681 13
682 14
683 15
684 -16
685 +c
686 -----------------------------------------------
687 M numbers (change 2 of 2)
688 revert this change? [y/n/q] y
689 EOF
690 cmp -s $testroot/stdout.expected $testroot/stdout
691 ret=$?
692 if [ $ret -ne 0 ]; then
693 diff -u $testroot/stdout.expected $testroot/stdout
694 test_done "$testroot" "$ret"
695 return 1
696 fi
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
709 --- numbers
710 +++ numbers
711 @@ -1,5 +1,5 @@
713 -2
714 +a
718 EOF
719 cmp -s $testroot/stdout.expected $testroot/stdout
720 ret=$?
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 fi
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
732 ret=$?
733 if [ $ret -ne 0 ]; then
734 test_done "$testroot" "$ret"
735 return 1
736 fi
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
748 ret=$?
749 if [ $ret -ne 0 ]; then
750 diff -u $testroot/stdout.expected $testroot/stdout
751 test_done "$testroot" "$ret"
752 return 1
753 fi
755 (cd $testroot/wt && got status > $testroot/stdout)
756 echo "A epsilon/new" > $testroot/stdout.expected
757 cmp -s $testroot/stdout.expected $testroot/stdout
758 ret=$?
759 if [ $ret -ne 0 ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
761 test_done "$testroot" "$ret"
762 return 1
763 fi
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
773 ret=$?
774 if [ $ret -ne 0 ]; then
775 diff -u $testroot/stdout.expected $testroot/stdout
776 test_done "$testroot" "$ret"
777 return 1
778 fi
780 (cd $testroot/wt && got status > $testroot/stdout)
781 echo "? epsilon/new" > $testroot/stdout.expected
782 cmp -s $testroot/stdout.expected $testroot/stdout
783 ret=$?
784 if [ $ret -ne 0 ]; then
785 diff -u $testroot/stdout.expected $testroot/stdout
786 fi
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
795 ret=$?
796 if [ $ret -ne 0 ]; then
797 test_done "$testroot" "$ret"
798 return 1
799 fi
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
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 diff -u $testroot/stdout.expected $testroot/stdout
812 test_done "$testroot" "$ret"
813 return 1
814 fi
816 (cd $testroot/wt && got status > $testroot/stdout)
817 echo "D beta" > $testroot/stdout.expected
818 cmp -s $testroot/stdout.expected $testroot/stdout
819 ret=$?
820 if [ $ret -ne 0 ]; then
821 diff -u $testroot/stdout.expected $testroot/stdout
822 test_done "$testroot" "$ret"
823 return 1
824 fi
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
834 ret=$?
835 if [ $ret -ne 0 ]; then
836 diff -u $testroot/stdout.expected $testroot/stdout
837 test_done "$testroot" "$ret"
838 return 1
839 fi
841 (cd $testroot/wt && got status > $testroot/stdout)
842 echo -n > $testroot/stdout.expected
843 cmp -s $testroot/stdout.expected $testroot/stdout
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
847 fi
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
860 ret=$?
861 if [ $ret -ne 0 ]; then
862 test_done "$testroot" "$ret"
863 return 1
864 fi
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)
875 ret=$?
876 if [ $ret -ne 0 ]; then
877 echo "got revert command failed unexpectedly" >&2
878 test_done "$testroot" "1"
879 return 1
880 fi
881 cat > $testroot/stdout.expected <<EOF
882 -----------------------------------------------
883 @@ -1,5 +1,5 @@
885 -2
886 +aa
890 -----------------------------------------------
891 M numbers (change 1 of 1)
892 revert this change? [y/n/q] y
893 EOF
894 ret=$?
895 if [ $ret -ne 0 ]; then
896 echo "got revert command failed unexpectedly" >&2
897 test_done "$testroot" "1"
898 return 1
899 fi
901 cmp -s $testroot/stdout.expected $testroot/stdout
902 ret=$?
903 if [ $ret -ne 0 ]; then
904 diff -u $testroot/stdout.expected $testroot/stdout
905 test_done "$testroot" "$ret"
906 return 1
907 fi
909 (cd $testroot/wt && got status > $testroot/stdout)
910 echo -n > $testroot/stdout.expected
911 cmp -s $testroot/stdout.expected $testroot/stdout
912 ret=$?
913 if [ $ret -ne 0 ]; then
914 diff -u $testroot/stdout.expected $testroot/stdout
915 test_done "$testroot" "$ret"
916 return 1
917 fi
919 (cd $testroot/wt && got diff > $testroot/stdout)
920 echo -n > $testroot/stdout.expected
921 cmp -s $testroot/stdout.expected $testroot/stdout
922 ret=$?
923 if [ $ret -ne 0 ]; then
924 diff -u $testroot/stdout.expected $testroot/stdout
925 fi
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
933 ret=$?
934 if [ $ret -ne 0 ]; then
935 test_done "$testroot" "$ret"
936 return 1
937 fi
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
970 ret=$?
971 if [ $ret -ne 0 ]; then
972 diff -u $testroot/stdout.expected $testroot/stdout
973 test_done "$testroot" "$ret"
974 return 1
975 fi
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
992 ret=$?
993 if [ $ret -ne 0 ]; then
994 diff -u $testroot/stdout.expected $testroot/stdout
995 fi
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
1003 ret=$?
1004 if [ $ret -ne 0 ]; then
1005 test_done "$testroot" "$ret"
1006 return 1
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
1044 ret=$?
1045 if [ $ret -ne 0 ]; then
1046 diff -u $testroot/stdout.expected $testroot/stdout
1047 test_done "$testroot" "$ret"
1048 return 1
1051 echo -n > $testroot/stdout.expected
1052 (cd $testroot/wt && got status > $testroot/stdout)
1054 cmp -s $testroot/stdout.expected $testroot/stdout
1055 ret=$?
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)
1089 # removed symlink
1090 (cd $testroot/wt && got rm zeta.link > /dev/null)
1091 # added symlink
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
1100 R alpha.link
1101 R epsilon/beta.link
1102 R epsilon.link
1103 R new.link
1104 R nonexistent.link
1105 R passwd.link
1106 R zeta.link
1107 EOF
1108 cmp -s $testroot/stdout.expected $testroot/stdout
1109 ret=$?
1110 if [ $ret -ne 0 ]; then
1111 diff -u $testroot/stdout.expected $testroot/stdout
1112 test_done "$testroot" "$ret"
1113 return 1
1116 if ! [ -h $testroot/wt/alpha.link ]; then
1117 echo "alpha.link is not a symlink"
1118 test_done "$testroot" "1"
1119 return 1
1122 readlink $testroot/wt/alpha.link > $testroot/stdout
1123 echo "alpha" > $testroot/stdout.expected
1124 cmp -s $testroot/stdout.expected $testroot/stdout
1125 ret=$?
1126 if [ $ret -ne 0 ]; then
1127 diff -u $testroot/stdout.expected $testroot/stdout
1128 test_done "$testroot" "$ret"
1129 return 1
1132 if ! [ -h $testroot/wt/epsilon.link ]; then
1133 echo "epsilon.link is not a symlink"
1134 test_done "$testroot" "1"
1135 return 1
1138 readlink $testroot/wt/epsilon.link > $testroot/stdout
1139 echo "epsilon" > $testroot/stdout.expected
1140 cmp -s $testroot/stdout.expected $testroot/stdout
1141 ret=$?
1142 if [ $ret -ne 0 ]; then
1143 diff -u $testroot/stdout.expected $testroot/stdout
1144 test_done "$testroot" "$ret"
1145 return 1
1148 if [ -h $testroot/wt/passwd.link ]; then
1149 echo "passwd.link should not be a symlink" >&2
1150 test_done "$testroot" "1"
1151 return 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
1158 ret=$?
1159 if [ $ret -ne 0 ]; then
1160 diff -u $testroot/content.expected $testroot/content
1161 test_done "$testroot" "$ret"
1162 return 1
1165 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1166 echo "../beta" > $testroot/stdout.expected
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1168 ret=$?
1169 if [ $ret -ne 0 ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1171 test_done "$testroot" "$ret"
1172 return 1
1175 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1176 echo "nonexistent" > $testroot/stdout.expected
1177 cmp -s $testroot/stdout.expected $testroot/stdout
1178 ret=$?
1179 if [ $ret -ne 0 ]; then
1180 diff -u $testroot/stdout.expected $testroot/stdout
1181 test_done "$testroot" "$ret"
1182 return 1
1185 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1186 echo "dotgotfoo.link is not a symlink " >&2
1187 test_done "$testroot" "1"
1188 return 1
1190 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1191 echo ".got/foo" > $testroot/stdout.expected
1192 cmp -s $testroot/stdout.expected $testroot/stdout
1193 ret=$?
1194 if [ $ret -ne 0 ]; then
1195 diff -u $testroot/stdout.expected $testroot/stdout
1196 test_done "$testroot" "$ret"
1197 return 1
1200 if [ ! -h $testroot/wt/zeta.link ]; then
1201 echo -n "zeta.link is not a symlink" >&2
1202 test_done "$testroot" "1"
1203 return 1
1206 readlink $testroot/wt/zeta.link > $testroot/stdout
1207 echo "epsilon/zeta" > $testroot/stdout.expected
1208 cmp -s $testroot/stdout.expected $testroot/stdout
1209 ret=$?
1210 if [ $ret -ne 0 ]; then
1211 diff -u $testroot/stdout.expected $testroot/stdout
1212 test_done "$testroot" "$ret"
1213 return 1
1216 if [ ! -h $testroot/wt/new.link ]; then
1217 echo -n "new.link is not a symlink" >&2
1218 test_done "$testroot" "1"
1219 return 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
1226 ret=$?
1227 if [ $ret -ne 0 ]; then
1228 diff -u $testroot/stdout.expected $testroot/stdout
1229 return 1
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)
1262 # removed symlink
1263 (cd $testroot/wt && got rm zeta.link > /dev/null)
1264 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1265 # added symlink
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 . \
1273 > $testroot/stdout)
1274 ret=$?
1275 if [ $ret -ne 0 ]; then
1276 echo "got revert command failed unexpectedly" >&2
1277 test_done "$testroot" "1"
1278 return 1
1280 cat > $testroot/stdout.expected <<EOF
1281 -----------------------------------------------
1282 @@ -1 +1 @@
1283 -alpha
1284 \ No newline at end of file
1285 +gamma/delta
1286 \ No newline at end of file
1287 -----------------------------------------------
1288 M alpha.link (change 1 of 1)
1289 revert this change? [y/n/q] y
1290 R alpha.link
1291 -----------------------------------------------
1292 @@ -1 +1 @@
1293 -../beta
1294 \ No newline at end of file
1295 +../gamma
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 -----------------------------------------------
1301 @@ -1 +1 @@
1302 -epsilon
1303 \ No newline at end of file
1304 +beta
1305 \ No newline at end of file
1306 -----------------------------------------------
1307 M epsilon.link (change 1 of 1)
1308 revert this change? [y/n/q] y
1309 R epsilon.link
1310 A new.link
1311 revert this addition? [y/n] n
1312 -----------------------------------------------
1313 @@ -1 +1 @@
1314 -nonexistent
1315 \ No newline at end of file
1316 +nonexistent2
1317 \ No newline at end of file
1318 -----------------------------------------------
1319 M nonexistent.link (change 1 of 1)
1320 revert this change? [y/n/q] y
1321 R nonexistent.link
1322 -----------------------------------------------
1323 @@ -1 +1 @@
1324 -/etc/passwd
1325 \ No newline at end of file
1326 +foo
1327 -----------------------------------------------
1328 M passwd.link (change 1 of 1)
1329 revert this change? [y/n/q] y
1330 R passwd.link
1331 D zeta.link
1332 revert this deletion? [y/n] n
1333 D zeta2.link
1334 revert this deletion? [y/n] y
1335 R zeta2.link
1336 A zeta3.link
1337 revert this addition? [y/n] y
1338 R zeta3.link
1339 EOF
1340 cmp -s $testroot/stdout.expected $testroot/stdout
1341 ret=$?
1342 if [ $ret -ne 0 ]; then
1343 diff -u $testroot/stdout.expected $testroot/stdout
1344 test_done "$testroot" "$ret"
1345 return 1
1348 if ! [ -h $testroot/wt/alpha.link ]; then
1349 echo "alpha.link is not a symlink"
1350 test_done "$testroot" "1"
1351 return 1
1354 readlink $testroot/wt/alpha.link > $testroot/stdout
1355 echo "alpha" > $testroot/stdout.expected
1356 cmp -s $testroot/stdout.expected $testroot/stdout
1357 ret=$?
1358 if [ $ret -ne 0 ]; then
1359 diff -u $testroot/stdout.expected $testroot/stdout
1360 test_done "$testroot" "$ret"
1361 return 1
1364 if ! [ -h $testroot/wt/epsilon.link ]; then
1365 echo "epsilon.link is not a symlink"
1366 test_done "$testroot" "1"
1367 return 1
1370 readlink $testroot/wt/epsilon.link > $testroot/stdout
1371 echo "epsilon" > $testroot/stdout.expected
1372 cmp -s $testroot/stdout.expected $testroot/stdout
1373 ret=$?
1374 if [ $ret -ne 0 ]; then
1375 diff -u $testroot/stdout.expected $testroot/stdout
1376 test_done "$testroot" "$ret"
1377 return 1
1380 if [ -h $testroot/wt/passwd.link ]; then
1381 echo "passwd.link should not be a symlink" >&2
1382 test_done "$testroot" "1"
1383 return 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
1390 ret=$?
1391 if [ $ret -ne 0 ]; then
1392 diff -u $testroot/content.expected $testroot/content
1393 test_done "$testroot" "$ret"
1394 return 1
1397 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1398 echo "../gamma" > $testroot/stdout.expected
1399 cmp -s $testroot/stdout.expected $testroot/stdout
1400 ret=$?
1401 if [ $ret -ne 0 ]; then
1402 diff -u $testroot/stdout.expected $testroot/stdout
1403 test_done "$testroot" "$ret"
1404 return 1
1407 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1408 echo "nonexistent" > $testroot/stdout.expected
1409 cmp -s $testroot/stdout.expected $testroot/stdout
1410 ret=$?
1411 if [ $ret -ne 0 ]; then
1412 diff -u $testroot/stdout.expected $testroot/stdout
1413 test_done "$testroot" "$ret"
1414 return 1
1417 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1418 echo "dotgotfoo.link is not a symlink " >&2
1419 test_done "$testroot" "1"
1420 return 1
1422 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1423 echo ".got/foo" > $testroot/stdout.expected
1424 cmp -s $testroot/stdout.expected $testroot/stdout
1425 ret=$?
1426 if [ $ret -ne 0 ]; then
1427 diff -u $testroot/stdout.expected $testroot/stdout
1428 test_done "$testroot" "$ret"
1429 return 1
1433 if [ -e $testroot/wt/zeta.link ]; then
1434 echo -n "zeta.link should not exist on disk" >&2
1435 test_done "$testroot" "1"
1436 return 1
1439 if [ ! -h $testroot/wt/zeta2.link ]; then
1440 echo -n "zeta2.link is not a symlink" >&2
1441 test_done "$testroot" "1"
1442 return 1
1445 readlink $testroot/wt/zeta2.link > $testroot/stdout
1446 echo "epsilon/zeta" > $testroot/stdout.expected
1447 cmp -s $testroot/stdout.expected $testroot/stdout
1448 ret=$?
1449 if [ $ret -ne 0 ]; then
1450 diff -u $testroot/stdout.expected $testroot/stdout
1451 test_done "$testroot" "$ret"
1452 return 1
1455 if [ ! -h $testroot/wt/zeta3.link ]; then
1456 echo -n "zeta3.link is not a symlink" >&2
1457 test_done "$testroot" "1"
1458 return 1
1461 readlink $testroot/wt/zeta3.link > $testroot/stdout
1462 echo "beta" > $testroot/stdout.expected
1463 cmp -s $testroot/stdout.expected $testroot/stdout
1464 ret=$?
1465 if [ $ret -ne 0 ]; then
1466 diff -u $testroot/stdout.expected $testroot/stdout
1467 test_done "$testroot" "$ret"
1468 return 1
1471 if [ ! -h $testroot/wt/new.link ]; then
1472 echo -n "new.link is not a symlink" >&2
1473 test_done "$testroot" "1"
1474 return 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
1484 ret=$?
1485 if [ $ret -ne 0 ]; then
1486 diff -u $testroot/stdout.expected $testroot/stdout
1487 return 1
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) \
1500 >/dev/null
1501 ret=$?
1502 if [ $ret -ne 0 ]; then
1503 test_done "$testroot" $ret
1504 return 1
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
1511 return 1
1513 test_done "$testroot" 0
1516 test_parseargs "$@"
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