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 ed -s $testroot/wt/numbers <<-\EOF
388 ,s/^2$/a/
389 ,s/^7$/b/
390 ,s/^16$/c/
392 EOF
394 (cd $testroot/wt && got diff > $testroot/numbers.diff)
396 # don't revert any hunks
397 printf "n\nn\nn\n" > $testroot/patchscript
398 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
399 numbers > $testroot/stdout)
400 ret=$?
401 if [ $ret -ne 0 ]; then
402 echo "got revert command failed unexpectedly" >&2
403 test_done "$testroot" "1"
404 return 1
405 fi
406 cat > $testroot/stdout.expected <<EOF
407 -----------------------------------------------
408 @@ -1,5 +1,5 @@
410 -2
411 +a
415 -----------------------------------------------
416 M numbers (change 1 of 3)
417 revert this change? [y/n/q] n
418 -----------------------------------------------
419 @@ -4,7 +4,7 @@
423 -7
424 +b
427 10
428 -----------------------------------------------
429 M numbers (change 2 of 3)
430 revert this change? [y/n/q] n
431 -----------------------------------------------
432 @@ -13,4 +13,4 @@
433 13
434 14
435 15
436 -16
437 +c
438 -----------------------------------------------
439 M numbers (change 3 of 3)
440 revert this change? [y/n/q] n
441 EOF
442 cmp -s $testroot/stdout.expected $testroot/stdout
443 ret=$?
444 if [ $ret -ne 0 ]; then
445 diff -u $testroot/stdout.expected $testroot/stdout
446 test_done "$testroot" "$ret"
447 return 1
448 fi
450 (cd $testroot/wt && got status > $testroot/stdout)
451 echo "M numbers" > $testroot/stdout.expected
452 cmp -s $testroot/stdout.expected $testroot/stdout
453 ret=$?
454 if [ $ret -ne 0 ]; then
455 diff -u $testroot/stdout.expected $testroot/stdout
456 test_done "$testroot" "$ret"
457 return 1
458 fi
460 (cd $testroot/wt && got diff > $testroot/stdout)
461 cmp -s $testroot/numbers.diff $testroot/stdout
462 ret=$?
463 if [ $ret -ne 0 ]; then
464 diff -u $testroot/numbers.diff $testroot/stdout
465 test_done "$testroot" "$ret"
466 return 1
467 fi
469 # revert first hunk
470 printf "y\nn\nn\n" > $testroot/patchscript
471 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
472 numbers > $testroot/stdout)
473 ret=$?
474 if [ $ret -ne 0 ]; then
475 echo "got revert command failed unexpectedly" >&2
476 test_done "$testroot" "1"
477 return 1
478 fi
479 cat > $testroot/stdout.expected <<EOF
480 -----------------------------------------------
481 @@ -1,5 +1,5 @@
483 -2
484 +a
488 -----------------------------------------------
489 M numbers (change 1 of 3)
490 revert this change? [y/n/q] y
491 -----------------------------------------------
492 @@ -4,7 +4,7 @@
496 -7
497 +b
500 10
501 -----------------------------------------------
502 M numbers (change 2 of 3)
503 revert this change? [y/n/q] n
504 -----------------------------------------------
505 @@ -13,4 +13,4 @@
506 13
507 14
508 15
509 -16
510 +c
511 -----------------------------------------------
512 M numbers (change 3 of 3)
513 revert this change? [y/n/q] n
514 EOF
515 cmp -s $testroot/stdout.expected $testroot/stdout
516 ret=$?
517 if [ $ret -ne 0 ]; then
518 diff -u $testroot/stdout.expected $testroot/stdout
519 test_done "$testroot" "$ret"
520 return 1
521 fi
523 (cd $testroot/wt && got status > $testroot/stdout)
524 echo "M numbers" > $testroot/stdout.expected
525 cmp -s $testroot/stdout.expected $testroot/stdout
526 ret=$?
527 if [ $ret -ne 0 ]; then
528 diff -u $testroot/stdout.expected $testroot/stdout
529 test_done "$testroot" "$ret"
530 return 1
531 fi
533 echo "diff $testroot/wt" > $testroot/stdout.expected
534 echo "commit - $commit_id" >> $testroot/stdout.expected
535 echo "path + $testroot/wt" >> $testroot/stdout.expected
536 echo -n 'blob - ' >> $testroot/stdout.expected
537 got tree -r $testroot/repo -i -c $commit_id \
538 | grep 'numbers$' | cut -d' ' -f 1 \
539 >> $testroot/stdout.expected
540 echo 'file + numbers' >> $testroot/stdout.expected
541 cat >> $testroot/stdout.expected <<EOF
542 --- numbers
543 +++ numbers
544 @@ -4,7 +4,7 @@
548 -7
549 +b
552 10
553 @@ -13,4 +13,4 @@
554 13
555 14
556 15
557 -16
558 +c
559 EOF
560 (cd $testroot/wt && got diff > $testroot/stdout)
561 cmp -s $testroot/stdout.expected $testroot/stdout
562 ret=$?
563 if [ $ret -ne 0 ]; then
564 diff -u $testroot/stdout.expected $testroot/stdout
565 test_done "$testroot" "$ret"
566 return 1
567 fi
569 # put first hunk back
570 ed -s $testroot/wt/numbers <<-\EOF
571 ,s/^2$/a/
573 EOF
575 # revert middle hunk
576 printf "n\ny\nn\n" > $testroot/patchscript
577 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
578 numbers > $testroot/stdout)
580 cat > $testroot/stdout.expected <<EOF
581 -----------------------------------------------
582 @@ -1,5 +1,5 @@
584 -2
585 +a
589 -----------------------------------------------
590 M numbers (change 1 of 3)
591 revert this change? [y/n/q] n
592 -----------------------------------------------
593 @@ -4,7 +4,7 @@
597 -7
598 +b
601 10
602 -----------------------------------------------
603 M numbers (change 2 of 3)
604 revert this change? [y/n/q] y
605 -----------------------------------------------
606 @@ -13,4 +13,4 @@
607 13
608 14
609 15
610 -16
611 +c
612 -----------------------------------------------
613 M numbers (change 3 of 3)
614 revert this change? [y/n/q] n
615 EOF
616 cmp -s $testroot/stdout.expected $testroot/stdout
617 ret=$?
618 if [ $ret -ne 0 ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 (cd $testroot/wt && got status > $testroot/stdout)
625 echo "M numbers" > $testroot/stdout.expected
626 cmp -s $testroot/stdout.expected $testroot/stdout
627 ret=$?
628 if [ $ret -ne 0 ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
631 return 1
632 fi
634 (cd $testroot/wt && got diff > $testroot/stdout)
636 echo "diff $testroot/wt" > $testroot/stdout.expected
637 echo "commit - $commit_id" >> $testroot/stdout.expected
638 echo "path + $testroot/wt" >> $testroot/stdout.expected
639 echo -n 'blob - ' >> $testroot/stdout.expected
640 got tree -r $testroot/repo -i -c $commit_id \
641 | grep 'numbers$' | cut -d' ' -f 1 \
642 >> $testroot/stdout.expected
643 echo 'file + numbers' >> $testroot/stdout.expected
644 cat >> $testroot/stdout.expected <<EOF
645 --- numbers
646 +++ numbers
647 @@ -1,5 +1,5 @@
649 -2
650 +a
654 @@ -13,4 +13,4 @@
655 13
656 14
657 15
658 -16
659 +c
660 EOF
661 cmp -s $testroot/stdout.expected $testroot/stdout
662 ret=$?
663 if [ $ret -ne 0 ]; then
664 diff -u $testroot/stdout.expected $testroot/stdout
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 # revert last hunk
670 printf "n\ny\n" > $testroot/patchscript
671 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
672 numbers > $testroot/stdout)
673 cat > $testroot/stdout.expected <<EOF
674 -----------------------------------------------
675 @@ -1,5 +1,5 @@
677 -2
678 +a
682 -----------------------------------------------
683 M numbers (change 1 of 2)
684 revert this change? [y/n/q] n
685 -----------------------------------------------
686 @@ -13,4 +13,4 @@
687 13
688 14
689 15
690 -16
691 +c
692 -----------------------------------------------
693 M numbers (change 2 of 2)
694 revert this change? [y/n/q] y
695 EOF
696 cmp -s $testroot/stdout.expected $testroot/stdout
697 ret=$?
698 if [ $ret -ne 0 ]; then
699 diff -u $testroot/stdout.expected $testroot/stdout
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 (cd $testroot/wt && got diff > $testroot/stdout)
706 echo "diff $testroot/wt" > $testroot/stdout.expected
707 echo "commit - $commit_id" >> $testroot/stdout.expected
708 echo "path + $testroot/wt" >> $testroot/stdout.expected
709 echo -n 'blob - ' >> $testroot/stdout.expected
710 got tree -r $testroot/repo -i -c $commit_id \
711 | grep 'numbers$' | cut -d' ' -f 1 \
712 >> $testroot/stdout.expected
713 echo 'file + numbers' >> $testroot/stdout.expected
714 cat >> $testroot/stdout.expected <<EOF
715 --- numbers
716 +++ numbers
717 @@ -1,5 +1,5 @@
719 -2
720 +a
724 EOF
725 cmp -s $testroot/stdout.expected $testroot/stdout
726 ret=$?
727 if [ $ret -ne 0 ]; then
728 diff -u $testroot/stdout.expected $testroot/stdout
729 fi
730 test_done "$testroot" "$ret"
733 test_revert_patch_added() {
734 local testroot=`test_init revert_patch_added`
735 local commit_id=`git_show_head $testroot/repo`
737 got checkout $testroot/repo $testroot/wt > /dev/null
738 ret=$?
739 if [ $ret -ne 0 ]; then
740 test_done "$testroot" "$ret"
741 return 1
742 fi
744 echo "new" > $testroot/wt/epsilon/new
745 (cd $testroot/wt && got add epsilon/new > /dev/null)
747 printf "n\n" > $testroot/patchscript
748 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
749 epsilon/new > $testroot/stdout)
751 echo "A epsilon/new" > $testroot/stdout.expected
752 echo "revert this addition? [y/n] n" >> $testroot/stdout.expected
753 cmp -s $testroot/stdout.expected $testroot/stdout
754 ret=$?
755 if [ $ret -ne 0 ]; then
756 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
758 return 1
759 fi
761 (cd $testroot/wt && got status > $testroot/stdout)
762 echo "A epsilon/new" > $testroot/stdout.expected
763 cmp -s $testroot/stdout.expected $testroot/stdout
764 ret=$?
765 if [ $ret -ne 0 ]; then
766 diff -u $testroot/stdout.expected $testroot/stdout
767 test_done "$testroot" "$ret"
768 return 1
769 fi
771 printf "y\n" > $testroot/patchscript
772 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
773 epsilon/new > $testroot/stdout)
775 echo "A epsilon/new" > $testroot/stdout.expected
776 echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
777 echo "R epsilon/new" >> $testroot/stdout.expected
778 cmp -s $testroot/stdout.expected $testroot/stdout
779 ret=$?
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
782 test_done "$testroot" "$ret"
783 return 1
784 fi
786 (cd $testroot/wt && got status > $testroot/stdout)
787 echo "? epsilon/new" > $testroot/stdout.expected
788 cmp -s $testroot/stdout.expected $testroot/stdout
789 ret=$?
790 if [ $ret -ne 0 ]; then
791 diff -u $testroot/stdout.expected $testroot/stdout
792 fi
793 test_done "$testroot" "$ret"
796 test_revert_patch_removed() {
797 local testroot=`test_init revert_patch_removed`
798 local commit_id=`git_show_head $testroot/repo`
800 got checkout $testroot/repo $testroot/wt > /dev/null
801 ret=$?
802 if [ $ret -ne 0 ]; then
803 test_done "$testroot" "$ret"
804 return 1
805 fi
807 (cd $testroot/wt && got rm beta > /dev/null)
809 printf "n\n" > $testroot/patchscript
810 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
811 beta > $testroot/stdout)
812 echo "D beta" > $testroot/stdout.expected
813 echo "revert this deletion? [y/n] n" >> $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected $testroot/stdout
815 ret=$?
816 if [ $ret -ne 0 ]; then
817 diff -u $testroot/stdout.expected $testroot/stdout
818 test_done "$testroot" "$ret"
819 return 1
820 fi
822 (cd $testroot/wt && got status > $testroot/stdout)
823 echo "D beta" > $testroot/stdout.expected
824 cmp -s $testroot/stdout.expected $testroot/stdout
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 diff -u $testroot/stdout.expected $testroot/stdout
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 printf "y\n" > $testroot/patchscript
833 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
834 beta > $testroot/stdout)
836 echo "D beta" > $testroot/stdout.expected
837 echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
838 echo "R beta" >> $testroot/stdout.expected
839 cmp -s $testroot/stdout.expected $testroot/stdout
840 ret=$?
841 if [ $ret -ne 0 ]; then
842 diff -u $testroot/stdout.expected $testroot/stdout
843 test_done "$testroot" "$ret"
844 return 1
845 fi
847 (cd $testroot/wt && got status > $testroot/stdout)
848 echo -n > $testroot/stdout.expected
849 cmp -s $testroot/stdout.expected $testroot/stdout
850 ret=$?
851 if [ $ret -ne 0 ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
853 fi
854 test_done "$testroot" "$ret"
857 test_revert_patch_one_change() {
858 local testroot=`test_init revert_patch_one_change`
860 jot 16 > $testroot/repo/numbers
861 (cd $testroot/repo && git add numbers)
862 git_commit $testroot/repo -m "added numbers file"
863 local commit_id=`git_show_head $testroot/repo`
865 got checkout $testroot/repo $testroot/wt > /dev/null
866 ret=$?
867 if [ $ret -ne 0 ]; then
868 test_done "$testroot" "$ret"
869 return 1
870 fi
872 # Ensure file size is changed. Avoids race condition causing test
873 # failures where 'got revert' does not see changes to revert if
874 # timestamps and size in stat info remain unchanged.
875 ed -s $testroot/wt/numbers <<-\EOF
876 ,s/^2$/aa/
878 EOF
880 # revert change with -p
881 printf "y\n" > $testroot/patchscript
882 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
883 numbers > $testroot/stdout)
884 ret=$?
885 if [ $ret -ne 0 ]; then
886 echo "got revert command failed unexpectedly" >&2
887 test_done "$testroot" "1"
888 return 1
889 fi
890 cat > $testroot/stdout.expected <<EOF
891 -----------------------------------------------
892 @@ -1,5 +1,5 @@
894 -2
895 +aa
899 -----------------------------------------------
900 M numbers (change 1 of 1)
901 revert this change? [y/n/q] y
902 EOF
903 ret=$?
904 if [ $ret -ne 0 ]; then
905 echo "got revert command failed unexpectedly" >&2
906 test_done "$testroot" "1"
907 return 1
908 fi
910 cmp -s $testroot/stdout.expected $testroot/stdout
911 ret=$?
912 if [ $ret -ne 0 ]; then
913 diff -u $testroot/stdout.expected $testroot/stdout
914 test_done "$testroot" "$ret"
915 return 1
916 fi
918 (cd $testroot/wt && got status > $testroot/stdout)
919 echo -n > $testroot/stdout.expected
920 cmp -s $testroot/stdout.expected $testroot/stdout
921 ret=$?
922 if [ $ret -ne 0 ]; then
923 diff -u $testroot/stdout.expected $testroot/stdout
924 test_done "$testroot" "$ret"
925 return 1
926 fi
928 (cd $testroot/wt && got diff > $testroot/stdout)
929 echo -n > $testroot/stdout.expected
930 cmp -s $testroot/stdout.expected $testroot/stdout
931 ret=$?
932 if [ $ret -ne 0 ]; then
933 diff -u $testroot/stdout.expected $testroot/stdout
934 fi
935 test_done "$testroot" "$ret"
938 test_revert_added_subtree() {
939 local testroot=`test_init revert_added_subtree`
941 got checkout $testroot/repo $testroot/wt > /dev/null
942 ret=$?
943 if [ $ret -ne 0 ]; then
944 test_done "$testroot" "$ret"
945 return 1
946 fi
948 mkdir -p $testroot/wt/epsilon/foo/bar/baz
949 mkdir -p $testroot/wt/epsilon/foo/bar/bax
950 echo "new file" > $testroot/wt/epsilon/foo/a.o
951 echo "new file" > $testroot/wt/epsilon/foo/a.o
952 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
953 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
954 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
955 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
956 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
957 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
958 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
959 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
960 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
961 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
962 (cd $testroot/wt && got add -R epsilon >/dev/null)
964 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
965 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
966 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
967 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
968 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
969 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
970 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
971 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
972 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
973 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
974 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
976 (cd $testroot/wt && got revert -R . > $testroot/stdout)
978 cmp -s $testroot/stdout.expected $testroot/stdout
979 ret=$?
980 if [ $ret -ne 0 ]; then
981 diff -u $testroot/stdout.expected $testroot/stdout
982 test_done "$testroot" "$ret"
983 return 1
984 fi
986 echo "? epsilon/foo/a.o" > $testroot/stdout.expected
987 echo "? epsilon/foo/bar/b.d" >> $testroot/stdout.expected
988 echo "? epsilon/foo/bar/b.o" >> $testroot/stdout.expected
989 echo "? epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
990 echo "? epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
991 echo "? epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
992 echo "? epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
993 echo "? epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
994 echo "? epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
995 echo "? epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
996 echo "? epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
998 (cd $testroot/wt && got status > $testroot/stdout)
1000 cmp -s $testroot/stdout.expected $testroot/stdout
1001 ret=$?
1002 if [ $ret -ne 0 ]; then
1003 diff -u $testroot/stdout.expected $testroot/stdout
1005 test_done "$testroot" "$ret"
1008 test_revert_deleted_subtree() {
1009 local testroot=`test_init revert_deleted_subtree`
1011 got checkout $testroot/repo $testroot/wt > /dev/null
1012 ret=$?
1013 if [ $ret -ne 0 ]; then
1014 test_done "$testroot" "$ret"
1015 return 1
1018 mkdir -p $testroot/wt/epsilon/foo/bar/baz
1019 mkdir -p $testroot/wt/epsilon/foo/bar/bax
1020 echo "new file" > $testroot/wt/epsilon/foo/a.o
1021 echo "new file" > $testroot/wt/epsilon/foo/a.o
1022 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
1023 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
1024 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
1025 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
1026 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
1027 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
1028 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
1029 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
1030 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
1031 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
1032 (cd $testroot/wt && got add -R epsilon >/dev/null)
1033 (cd $testroot/wt && got commit -m "add subtree" >/dev/null)
1035 # now delete and revert the entire subtree
1036 (cd $testroot/wt && got rm -R epsilon/foo >/dev/null)
1038 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
1039 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
1040 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
1041 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
1042 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
1043 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
1044 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
1045 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
1046 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
1047 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
1048 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
1050 (cd $testroot/wt && got revert -R . > $testroot/stdout)
1052 cmp -s $testroot/stdout.expected $testroot/stdout
1053 ret=$?
1054 if [ $ret -ne 0 ]; then
1055 diff -u $testroot/stdout.expected $testroot/stdout
1056 test_done "$testroot" "$ret"
1057 return 1
1060 echo -n > $testroot/stdout.expected
1061 (cd $testroot/wt && got status > $testroot/stdout)
1063 cmp -s $testroot/stdout.expected $testroot/stdout
1064 ret=$?
1065 if [ $ret -ne 0 ]; then
1066 diff -u $testroot/stdout.expected $testroot/stdout
1068 test_done "$testroot" "$ret"
1071 test_revert_symlink() {
1072 local testroot=`test_init revert_symlink`
1074 (cd $testroot/repo && ln -s alpha alpha.link)
1075 (cd $testroot/repo && ln -s epsilon epsilon.link)
1076 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1077 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1078 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1079 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1080 (cd $testroot/repo && git add .)
1081 git_commit $testroot/repo -m "add symlinks"
1082 local commit_id1=`git_show_head $testroot/repo`
1084 got checkout $testroot/repo $testroot/wt > /dev/null
1086 # symlink to file A now points to file B
1087 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1088 # symlink to a directory A now points to file B
1089 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1090 # "bad" symlink now contains a different target path
1091 echo "foo" > $testroot/wt/passwd.link
1092 # relative symlink to directory A now points to relative directory B
1093 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1094 epsilon/beta.link)
1095 # an unversioned symlink
1096 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1097 # symlink to file A now points to non-existent file B
1098 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1099 # removed symlink
1100 (cd $testroot/wt && got rm zeta.link > /dev/null)
1101 # added symlink
1102 (cd $testroot/wt && ln -sf beta new.link)
1103 (cd $testroot/wt && got add new.link > /dev/null)
1105 (cd $testroot/wt && got revert alpha.link epsilon.link \
1106 passwd.link epsilon/beta.link dotgotfoo.link \
1107 nonexistent.link zeta.link new.link > $testroot/stdout)
1109 cat > $testroot/stdout.expected <<EOF
1110 R alpha.link
1111 R epsilon/beta.link
1112 R epsilon.link
1113 R new.link
1114 R nonexistent.link
1115 R passwd.link
1116 R zeta.link
1117 EOF
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/alpha.link ]; then
1127 echo "alpha.link is not a symlink"
1128 test_done "$testroot" "1"
1129 return 1
1132 readlink $testroot/wt/alpha.link > $testroot/stdout
1133 echo "alpha" > $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/epsilon.link ]; then
1143 echo "epsilon.link is not a symlink"
1144 test_done "$testroot" "1"
1145 return 1
1148 readlink $testroot/wt/epsilon.link > $testroot/stdout
1149 echo "epsilon" > $testroot/stdout.expected
1150 cmp -s $testroot/stdout.expected $testroot/stdout
1151 ret=$?
1152 if [ $ret -ne 0 ]; then
1153 diff -u $testroot/stdout.expected $testroot/stdout
1154 test_done "$testroot" "$ret"
1155 return 1
1158 if [ -h $testroot/wt/passwd.link ]; then
1159 echo "passwd.link should not be a symlink" >&2
1160 test_done "$testroot" "1"
1161 return 1
1164 echo -n "/etc/passwd" > $testroot/content.expected
1165 cp $testroot/wt/passwd.link $testroot/content
1167 cmp -s $testroot/content.expected $testroot/content
1168 ret=$?
1169 if [ $ret -ne 0 ]; then
1170 diff -u $testroot/content.expected $testroot/content
1171 test_done "$testroot" "$ret"
1172 return 1
1175 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1176 echo "../beta" > $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 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1186 echo "nonexistent" > $testroot/stdout.expected
1187 cmp -s $testroot/stdout.expected $testroot/stdout
1188 ret=$?
1189 if [ $ret -ne 0 ]; then
1190 diff -u $testroot/stdout.expected $testroot/stdout
1191 test_done "$testroot" "$ret"
1192 return 1
1195 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1196 echo "dotgotfoo.link is not a symlink " >&2
1197 test_done "$testroot" "1"
1198 return 1
1200 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1201 echo ".got/foo" > $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/zeta.link ]; then
1211 echo -n "zeta.link is not a symlink" >&2
1212 test_done "$testroot" "1"
1213 return 1
1216 readlink $testroot/wt/zeta.link > $testroot/stdout
1217 echo "epsilon/zeta" > $testroot/stdout.expected
1218 cmp -s $testroot/stdout.expected $testroot/stdout
1219 ret=$?
1220 if [ $ret -ne 0 ]; then
1221 diff -u $testroot/stdout.expected $testroot/stdout
1222 test_done "$testroot" "$ret"
1223 return 1
1226 if [ ! -h $testroot/wt/new.link ]; then
1227 echo -n "new.link is not a symlink" >&2
1228 test_done "$testroot" "1"
1229 return 1
1232 (cd $testroot/wt && got status > $testroot/stdout)
1233 echo "? dotgotfoo.link" > $testroot/stdout.expected
1234 echo "? new.link" >> $testroot/stdout.expected
1235 cmp -s $testroot/stdout.expected $testroot/stdout
1236 ret=$?
1237 if [ $ret -ne 0 ]; then
1238 diff -u $testroot/stdout.expected $testroot/stdout
1239 return 1
1241 test_done "$testroot" "$ret"
1244 test_revert_patch_symlink() {
1245 local testroot=`test_init revert_patch_symlink`
1247 (cd $testroot/repo && ln -s alpha alpha.link)
1248 (cd $testroot/repo && ln -s epsilon epsilon.link)
1249 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1250 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1251 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1252 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1253 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1254 (cd $testroot/repo && git add .)
1255 git_commit $testroot/repo -m "add symlinks"
1256 local commit_id1=`git_show_head $testroot/repo`
1258 got checkout $testroot/repo $testroot/wt > /dev/null
1260 # symlink to file A now points to file B
1261 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1262 # symlink to a directory A now points to file B
1263 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1264 # "bad" symlink now contains a different target path
1265 echo "foo" > $testroot/wt/passwd.link
1266 # relative symlink to directory A now points to relative directory B
1267 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1268 epsilon/beta.link)
1269 # an unversioned symlink
1270 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1271 # symlink to file A now points to non-existent file B
1272 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1273 # removed symlink
1274 (cd $testroot/wt && got rm zeta.link > /dev/null)
1275 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1276 # added symlink
1277 (cd $testroot/wt && ln -sf beta new.link)
1278 (cd $testroot/wt && got add new.link > /dev/null)
1279 (cd $testroot/wt && ln -sf beta zeta3.link)
1280 (cd $testroot/wt && got add zeta3.link > /dev/null)
1282 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1283 (cd $testroot/wt && got revert -F $testroot/patchscript -p -R . \
1284 > $testroot/stdout)
1285 ret=$?
1286 if [ $ret -ne 0 ]; then
1287 echo "got revert command failed unexpectedly" >&2
1288 test_done "$testroot" "1"
1289 return 1
1291 cat > $testroot/stdout.expected <<EOF
1292 -----------------------------------------------
1293 @@ -1 +1 @@
1294 -alpha
1295 \ No newline at end of file
1296 +gamma/delta
1297 \ No newline at end of file
1298 -----------------------------------------------
1299 M alpha.link (change 1 of 1)
1300 revert this change? [y/n/q] y
1301 R alpha.link
1302 -----------------------------------------------
1303 @@ -1 +1 @@
1304 -../beta
1305 \ No newline at end of file
1306 +../gamma
1307 \ No newline at end of file
1308 -----------------------------------------------
1309 M epsilon/beta.link (change 1 of 1)
1310 revert this change? [y/n/q] n
1311 -----------------------------------------------
1312 @@ -1 +1 @@
1313 -epsilon
1314 \ No newline at end of file
1315 +beta
1316 \ No newline at end of file
1317 -----------------------------------------------
1318 M epsilon.link (change 1 of 1)
1319 revert this change? [y/n/q] y
1320 R epsilon.link
1321 A new.link
1322 revert this addition? [y/n] n
1323 -----------------------------------------------
1324 @@ -1 +1 @@
1325 -nonexistent
1326 \ No newline at end of file
1327 +nonexistent2
1328 \ No newline at end of file
1329 -----------------------------------------------
1330 M nonexistent.link (change 1 of 1)
1331 revert this change? [y/n/q] y
1332 R nonexistent.link
1333 -----------------------------------------------
1334 @@ -1 +1 @@
1335 -/etc/passwd
1336 \ No newline at end of file
1337 +foo
1338 -----------------------------------------------
1339 M passwd.link (change 1 of 1)
1340 revert this change? [y/n/q] y
1341 R passwd.link
1342 D zeta.link
1343 revert this deletion? [y/n] n
1344 D zeta2.link
1345 revert this deletion? [y/n] y
1346 R zeta2.link
1347 A zeta3.link
1348 revert this addition? [y/n] y
1349 R zeta3.link
1350 EOF
1351 cmp -s $testroot/stdout.expected $testroot/stdout
1352 ret=$?
1353 if [ $ret -ne 0 ]; then
1354 diff -u $testroot/stdout.expected $testroot/stdout
1355 test_done "$testroot" "$ret"
1356 return 1
1359 if ! [ -h $testroot/wt/alpha.link ]; then
1360 echo "alpha.link is not a symlink"
1361 test_done "$testroot" "1"
1362 return 1
1365 readlink $testroot/wt/alpha.link > $testroot/stdout
1366 echo "alpha" > $testroot/stdout.expected
1367 cmp -s $testroot/stdout.expected $testroot/stdout
1368 ret=$?
1369 if [ $ret -ne 0 ]; then
1370 diff -u $testroot/stdout.expected $testroot/stdout
1371 test_done "$testroot" "$ret"
1372 return 1
1375 if ! [ -h $testroot/wt/epsilon.link ]; then
1376 echo "epsilon.link is not a symlink"
1377 test_done "$testroot" "1"
1378 return 1
1381 readlink $testroot/wt/epsilon.link > $testroot/stdout
1382 echo "epsilon" > $testroot/stdout.expected
1383 cmp -s $testroot/stdout.expected $testroot/stdout
1384 ret=$?
1385 if [ $ret -ne 0 ]; then
1386 diff -u $testroot/stdout.expected $testroot/stdout
1387 test_done "$testroot" "$ret"
1388 return 1
1391 if [ -h $testroot/wt/passwd.link ]; then
1392 echo "passwd.link should not be a symlink" >&2
1393 test_done "$testroot" "1"
1394 return 1
1397 echo -n "/etc/passwd" > $testroot/content.expected
1398 cp $testroot/wt/passwd.link $testroot/content
1400 cmp -s $testroot/content.expected $testroot/content
1401 ret=$?
1402 if [ $ret -ne 0 ]; then
1403 diff -u $testroot/content.expected $testroot/content
1404 test_done "$testroot" "$ret"
1405 return 1
1408 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1409 echo "../gamma" > $testroot/stdout.expected
1410 cmp -s $testroot/stdout.expected $testroot/stdout
1411 ret=$?
1412 if [ $ret -ne 0 ]; then
1413 diff -u $testroot/stdout.expected $testroot/stdout
1414 test_done "$testroot" "$ret"
1415 return 1
1418 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1419 echo "nonexistent" > $testroot/stdout.expected
1420 cmp -s $testroot/stdout.expected $testroot/stdout
1421 ret=$?
1422 if [ $ret -ne 0 ]; then
1423 diff -u $testroot/stdout.expected $testroot/stdout
1424 test_done "$testroot" "$ret"
1425 return 1
1428 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1429 echo "dotgotfoo.link is not a symlink " >&2
1430 test_done "$testroot" "1"
1431 return 1
1433 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1434 echo ".got/foo" > $testroot/stdout.expected
1435 cmp -s $testroot/stdout.expected $testroot/stdout
1436 ret=$?
1437 if [ $ret -ne 0 ]; then
1438 diff -u $testroot/stdout.expected $testroot/stdout
1439 test_done "$testroot" "$ret"
1440 return 1
1444 if [ -e $testroot/wt/zeta.link ]; then
1445 echo -n "zeta.link should not exist on disk" >&2
1446 test_done "$testroot" "1"
1447 return 1
1450 if [ ! -h $testroot/wt/zeta2.link ]; then
1451 echo -n "zeta2.link is not a symlink" >&2
1452 test_done "$testroot" "1"
1453 return 1
1456 readlink $testroot/wt/zeta2.link > $testroot/stdout
1457 echo "epsilon/zeta" > $testroot/stdout.expected
1458 cmp -s $testroot/stdout.expected $testroot/stdout
1459 ret=$?
1460 if [ $ret -ne 0 ]; then
1461 diff -u $testroot/stdout.expected $testroot/stdout
1462 test_done "$testroot" "$ret"
1463 return 1
1466 if [ ! -h $testroot/wt/zeta3.link ]; then
1467 echo -n "zeta3.link is not a symlink" >&2
1468 test_done "$testroot" "1"
1469 return 1
1472 readlink $testroot/wt/zeta3.link > $testroot/stdout
1473 echo "beta" > $testroot/stdout.expected
1474 cmp -s $testroot/stdout.expected $testroot/stdout
1475 ret=$?
1476 if [ $ret -ne 0 ]; then
1477 diff -u $testroot/stdout.expected $testroot/stdout
1478 test_done "$testroot" "$ret"
1479 return 1
1482 if [ ! -h $testroot/wt/new.link ]; then
1483 echo -n "new.link is not a symlink" >&2
1484 test_done "$testroot" "1"
1485 return 1
1488 (cd $testroot/wt && got status > $testroot/stdout)
1489 echo "? dotgotfoo.link" > $testroot/stdout.expected
1490 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1491 echo "A new.link" >> $testroot/stdout.expected
1492 echo "D zeta.link" >> $testroot/stdout.expected
1493 echo "? zeta3.link" >> $testroot/stdout.expected
1494 cmp -s $testroot/stdout.expected $testroot/stdout
1495 ret=$?
1496 if [ $ret -ne 0 ]; then
1497 diff -u $testroot/stdout.expected $testroot/stdout
1498 return 1
1500 test_done "$testroot" "$ret"
1503 test_revert_umask() {
1504 local testroot=`test_init revert_umask`
1506 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1507 echo "edit alpha" > $testroot/wt/alpha
1509 # using a subshell to avoid clobbering global umask
1510 (umask 077 && cd "$testroot/wt" && got revert alpha) \
1511 >/dev/null
1512 ret=$?
1513 if [ $ret -ne 0 ]; then
1514 test_done "$testroot" $ret
1515 return 1
1518 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1519 echo "alpha is not 0600 after revert" >&2
1520 ls -l "$testroot/wt/alpha" >&2
1521 test_done "$testroot" 1
1522 return 1
1524 test_done "$testroot" 0
1527 test_parseargs "$@"
1528 run_test test_revert_basic
1529 run_test test_revert_rm
1530 run_test test_revert_add
1531 run_test test_revert_multiple
1532 run_test test_revert_file_in_new_subdir
1533 run_test test_revert_no_arguments
1534 run_test test_revert_directory
1535 run_test test_revert_directory_unknown
1536 run_test test_revert_patch
1537 run_test test_revert_patch_added
1538 run_test test_revert_patch_removed
1539 run_test test_revert_patch_one_change
1540 run_test test_revert_added_subtree
1541 run_test test_revert_deleted_subtree
1542 run_test test_revert_symlink
1543 run_test test_revert_patch_symlink
1544 run_test test_revert_umask