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 && rm epsilon.link && ln -s beta epsilon.link)
1081 # "bad" symlink now contains a different target path
1082 echo "foo" > $testroot/wt/passwd.link
1083 # relative symlink to directory A now points to relative directory B
1084 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1085 epsilon/beta.link)
1086 # an unversioned symlink
1087 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1088 # symlink to file A now points to non-existent file B
1089 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1090 # removed symlink
1091 (cd $testroot/wt && got rm zeta.link > /dev/null)
1092 # added symlink
1093 (cd $testroot/wt && ln -sf beta new.link)
1094 (cd $testroot/wt && got add new.link > /dev/null)
1096 (cd $testroot/wt && got revert alpha.link epsilon.link \
1097 passwd.link epsilon/beta.link dotgotfoo.link \
1098 nonexistent.link zeta.link new.link > $testroot/stdout)
1100 cat > $testroot/stdout.expected <<EOF
1101 R alpha.link
1102 R epsilon/beta.link
1103 R epsilon.link
1104 R new.link
1105 R nonexistent.link
1106 R passwd.link
1107 R zeta.link
1108 EOF
1109 cmp -s $testroot/stdout.expected $testroot/stdout
1110 ret=$?
1111 if [ $ret -ne 0 ]; then
1112 diff -u $testroot/stdout.expected $testroot/stdout
1113 test_done "$testroot" "$ret"
1114 return 1
1117 if ! [ -h $testroot/wt/alpha.link ]; then
1118 echo "alpha.link is not a symlink"
1119 test_done "$testroot" "1"
1120 return 1
1123 readlink $testroot/wt/alpha.link > $testroot/stdout
1124 echo "alpha" > $testroot/stdout.expected
1125 cmp -s $testroot/stdout.expected $testroot/stdout
1126 ret=$?
1127 if [ $ret -ne 0 ]; then
1128 diff -u $testroot/stdout.expected $testroot/stdout
1129 test_done "$testroot" "$ret"
1130 return 1
1133 if ! [ -h $testroot/wt/epsilon.link ]; then
1134 echo "epsilon.link is not a symlink"
1135 test_done "$testroot" "1"
1136 return 1
1139 readlink $testroot/wt/epsilon.link > $testroot/stdout
1140 echo "epsilon" > $testroot/stdout.expected
1141 cmp -s $testroot/stdout.expected $testroot/stdout
1142 ret=$?
1143 if [ $ret -ne 0 ]; then
1144 diff -u $testroot/stdout.expected $testroot/stdout
1145 test_done "$testroot" "$ret"
1146 return 1
1149 if [ -h $testroot/wt/passwd.link ]; then
1150 echo "passwd.link should not be a symlink" >&2
1151 test_done "$testroot" "1"
1152 return 1
1155 echo -n "/etc/passwd" > $testroot/content.expected
1156 cp $testroot/wt/passwd.link $testroot/content
1158 cmp -s $testroot/content.expected $testroot/content
1159 ret=$?
1160 if [ $ret -ne 0 ]; then
1161 diff -u $testroot/content.expected $testroot/content
1162 test_done "$testroot" "$ret"
1163 return 1
1166 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1167 echo "../beta" > $testroot/stdout.expected
1168 cmp -s $testroot/stdout.expected $testroot/stdout
1169 ret=$?
1170 if [ $ret -ne 0 ]; then
1171 diff -u $testroot/stdout.expected $testroot/stdout
1172 test_done "$testroot" "$ret"
1173 return 1
1176 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1177 echo "nonexistent" > $testroot/stdout.expected
1178 cmp -s $testroot/stdout.expected $testroot/stdout
1179 ret=$?
1180 if [ $ret -ne 0 ]; then
1181 diff -u $testroot/stdout.expected $testroot/stdout
1182 test_done "$testroot" "$ret"
1183 return 1
1186 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1187 echo "dotgotfoo.link is not a symlink " >&2
1188 test_done "$testroot" "1"
1189 return 1
1191 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1192 echo ".got/foo" > $testroot/stdout.expected
1193 cmp -s $testroot/stdout.expected $testroot/stdout
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 diff -u $testroot/stdout.expected $testroot/stdout
1197 test_done "$testroot" "$ret"
1198 return 1
1201 if [ ! -h $testroot/wt/zeta.link ]; then
1202 echo -n "zeta.link is not a symlink" >&2
1203 test_done "$testroot" "1"
1204 return 1
1207 readlink $testroot/wt/zeta.link > $testroot/stdout
1208 echo "epsilon/zeta" > $testroot/stdout.expected
1209 cmp -s $testroot/stdout.expected $testroot/stdout
1210 ret=$?
1211 if [ $ret -ne 0 ]; then
1212 diff -u $testroot/stdout.expected $testroot/stdout
1213 test_done "$testroot" "$ret"
1214 return 1
1217 if [ ! -h $testroot/wt/new.link ]; then
1218 echo -n "new.link is not a symlink" >&2
1219 test_done "$testroot" "1"
1220 return 1
1223 (cd $testroot/wt && got status > $testroot/stdout)
1224 echo "? dotgotfoo.link" > $testroot/stdout.expected
1225 echo "? new.link" >> $testroot/stdout.expected
1226 cmp -s $testroot/stdout.expected $testroot/stdout
1227 ret=$?
1228 if [ $ret -ne 0 ]; then
1229 diff -u $testroot/stdout.expected $testroot/stdout
1230 return 1
1232 test_done "$testroot" "$ret"
1235 test_revert_patch_symlink() {
1236 local testroot=`test_init revert_patch_symlink`
1238 (cd $testroot/repo && ln -s alpha alpha.link)
1239 (cd $testroot/repo && ln -s epsilon epsilon.link)
1240 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1241 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1242 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1243 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1244 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1245 (cd $testroot/repo && git add .)
1246 git_commit $testroot/repo -m "add symlinks"
1247 local commit_id1=`git_show_head $testroot/repo`
1249 got checkout $testroot/repo $testroot/wt > /dev/null
1251 # symlink to file A now points to file B
1252 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1253 # symlink to a directory A now points to file B
1254 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1255 # "bad" symlink now contains a different target path
1256 echo "foo" > $testroot/wt/passwd.link
1257 # relative symlink to directory A now points to relative directory B
1258 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1259 epsilon/beta.link)
1260 # an unversioned symlink
1261 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1262 # symlink to file A now points to non-existent file B
1263 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1264 # removed symlink
1265 (cd $testroot/wt && got rm zeta.link > /dev/null)
1266 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1267 # added symlink
1268 (cd $testroot/wt && ln -sf beta new.link)
1269 (cd $testroot/wt && got add new.link > /dev/null)
1270 (cd $testroot/wt && ln -sf beta zeta3.link)
1271 (cd $testroot/wt && got add zeta3.link > /dev/null)
1273 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1274 (cd $testroot/wt && got revert -F $testroot/patchscript -p -R . \
1275 > $testroot/stdout)
1276 ret=$?
1277 if [ $ret -ne 0 ]; then
1278 echo "got revert command failed unexpectedly" >&2
1279 test_done "$testroot" "1"
1280 return 1
1282 cat > $testroot/stdout.expected <<EOF
1283 -----------------------------------------------
1284 @@ -1 +1 @@
1285 -alpha
1286 \ No newline at end of file
1287 +gamma/delta
1288 \ No newline at end of file
1289 -----------------------------------------------
1290 M alpha.link (change 1 of 1)
1291 revert this change? [y/n/q] y
1292 R alpha.link
1293 -----------------------------------------------
1294 @@ -1 +1 @@
1295 -../beta
1296 \ No newline at end of file
1297 +../gamma
1298 \ No newline at end of file
1299 -----------------------------------------------
1300 M epsilon/beta.link (change 1 of 1)
1301 revert this change? [y/n/q] n
1302 -----------------------------------------------
1303 @@ -1 +1 @@
1304 -epsilon
1305 \ No newline at end of file
1306 +beta
1307 \ No newline at end of file
1308 -----------------------------------------------
1309 M epsilon.link (change 1 of 1)
1310 revert this change? [y/n/q] y
1311 R epsilon.link
1312 A new.link
1313 revert this addition? [y/n] n
1314 -----------------------------------------------
1315 @@ -1 +1 @@
1316 -nonexistent
1317 \ No newline at end of file
1318 +nonexistent2
1319 \ No newline at end of file
1320 -----------------------------------------------
1321 M nonexistent.link (change 1 of 1)
1322 revert this change? [y/n/q] y
1323 R nonexistent.link
1324 -----------------------------------------------
1325 @@ -1 +1 @@
1326 -/etc/passwd
1327 \ No newline at end of file
1328 +foo
1329 -----------------------------------------------
1330 M passwd.link (change 1 of 1)
1331 revert this change? [y/n/q] y
1332 R passwd.link
1333 D zeta.link
1334 revert this deletion? [y/n] n
1335 D zeta2.link
1336 revert this deletion? [y/n] y
1337 R zeta2.link
1338 A zeta3.link
1339 revert this addition? [y/n] y
1340 R zeta3.link
1341 EOF
1342 cmp -s $testroot/stdout.expected $testroot/stdout
1343 ret=$?
1344 if [ $ret -ne 0 ]; then
1345 diff -u $testroot/stdout.expected $testroot/stdout
1346 test_done "$testroot" "$ret"
1347 return 1
1350 if ! [ -h $testroot/wt/alpha.link ]; then
1351 echo "alpha.link is not a symlink"
1352 test_done "$testroot" "1"
1353 return 1
1356 readlink $testroot/wt/alpha.link > $testroot/stdout
1357 echo "alpha" > $testroot/stdout.expected
1358 cmp -s $testroot/stdout.expected $testroot/stdout
1359 ret=$?
1360 if [ $ret -ne 0 ]; then
1361 diff -u $testroot/stdout.expected $testroot/stdout
1362 test_done "$testroot" "$ret"
1363 return 1
1366 if ! [ -h $testroot/wt/epsilon.link ]; then
1367 echo "epsilon.link is not a symlink"
1368 test_done "$testroot" "1"
1369 return 1
1372 readlink $testroot/wt/epsilon.link > $testroot/stdout
1373 echo "epsilon" > $testroot/stdout.expected
1374 cmp -s $testroot/stdout.expected $testroot/stdout
1375 ret=$?
1376 if [ $ret -ne 0 ]; then
1377 diff -u $testroot/stdout.expected $testroot/stdout
1378 test_done "$testroot" "$ret"
1379 return 1
1382 if [ -h $testroot/wt/passwd.link ]; then
1383 echo "passwd.link should not be a symlink" >&2
1384 test_done "$testroot" "1"
1385 return 1
1388 echo -n "/etc/passwd" > $testroot/content.expected
1389 cp $testroot/wt/passwd.link $testroot/content
1391 cmp -s $testroot/content.expected $testroot/content
1392 ret=$?
1393 if [ $ret -ne 0 ]; then
1394 diff -u $testroot/content.expected $testroot/content
1395 test_done "$testroot" "$ret"
1396 return 1
1399 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1400 echo "../gamma" > $testroot/stdout.expected
1401 cmp -s $testroot/stdout.expected $testroot/stdout
1402 ret=$?
1403 if [ $ret -ne 0 ]; then
1404 diff -u $testroot/stdout.expected $testroot/stdout
1405 test_done "$testroot" "$ret"
1406 return 1
1409 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1410 echo "nonexistent" > $testroot/stdout.expected
1411 cmp -s $testroot/stdout.expected $testroot/stdout
1412 ret=$?
1413 if [ $ret -ne 0 ]; then
1414 diff -u $testroot/stdout.expected $testroot/stdout
1415 test_done "$testroot" "$ret"
1416 return 1
1419 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1420 echo "dotgotfoo.link is not a symlink " >&2
1421 test_done "$testroot" "1"
1422 return 1
1424 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1425 echo ".got/foo" > $testroot/stdout.expected
1426 cmp -s $testroot/stdout.expected $testroot/stdout
1427 ret=$?
1428 if [ $ret -ne 0 ]; then
1429 diff -u $testroot/stdout.expected $testroot/stdout
1430 test_done "$testroot" "$ret"
1431 return 1
1435 if [ -e $testroot/wt/zeta.link ]; then
1436 echo -n "zeta.link should not exist on disk" >&2
1437 test_done "$testroot" "1"
1438 return 1
1441 if [ ! -h $testroot/wt/zeta2.link ]; then
1442 echo -n "zeta2.link is not a symlink" >&2
1443 test_done "$testroot" "1"
1444 return 1
1447 readlink $testroot/wt/zeta2.link > $testroot/stdout
1448 echo "epsilon/zeta" > $testroot/stdout.expected
1449 cmp -s $testroot/stdout.expected $testroot/stdout
1450 ret=$?
1451 if [ $ret -ne 0 ]; then
1452 diff -u $testroot/stdout.expected $testroot/stdout
1453 test_done "$testroot" "$ret"
1454 return 1
1457 if [ ! -h $testroot/wt/zeta3.link ]; then
1458 echo -n "zeta3.link is not a symlink" >&2
1459 test_done "$testroot" "1"
1460 return 1
1463 readlink $testroot/wt/zeta3.link > $testroot/stdout
1464 echo "beta" > $testroot/stdout.expected
1465 cmp -s $testroot/stdout.expected $testroot/stdout
1466 ret=$?
1467 if [ $ret -ne 0 ]; then
1468 diff -u $testroot/stdout.expected $testroot/stdout
1469 test_done "$testroot" "$ret"
1470 return 1
1473 if [ ! -h $testroot/wt/new.link ]; then
1474 echo -n "new.link is not a symlink" >&2
1475 test_done "$testroot" "1"
1476 return 1
1479 (cd $testroot/wt && got status > $testroot/stdout)
1480 echo "? dotgotfoo.link" > $testroot/stdout.expected
1481 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1482 echo "A new.link" >> $testroot/stdout.expected
1483 echo "D zeta.link" >> $testroot/stdout.expected
1484 echo "? zeta3.link" >> $testroot/stdout.expected
1485 cmp -s $testroot/stdout.expected $testroot/stdout
1486 ret=$?
1487 if [ $ret -ne 0 ]; then
1488 diff -u $testroot/stdout.expected $testroot/stdout
1489 return 1
1491 test_done "$testroot" "$ret"
1494 test_revert_umask() {
1495 local testroot=`test_init revert_umask`
1497 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1498 echo "edit alpha" > $testroot/wt/alpha
1500 # using a subshell to avoid clobbering global umask
1501 (umask 077 && cd "$testroot/wt" && got revert alpha) \
1502 >/dev/null
1503 ret=$?
1504 if [ $ret -ne 0 ]; then
1505 test_done "$testroot" $ret
1506 return 1
1509 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1510 echo "alpha is not 0600 after revert" >&2
1511 ls -l "$testroot/wt/alpha" >&2
1512 test_done "$testroot" 1
1513 return 1
1515 test_done "$testroot" 0
1518 test_parseargs "$@"
1519 run_test test_revert_basic
1520 run_test test_revert_rm
1521 run_test test_revert_add
1522 run_test test_revert_multiple
1523 run_test test_revert_file_in_new_subdir
1524 run_test test_revert_no_arguments
1525 run_test test_revert_directory
1526 run_test test_revert_directory_unknown
1527 run_test test_revert_patch
1528 run_test test_revert_patch_added
1529 run_test test_revert_patch_removed
1530 run_test test_revert_patch_one_change
1531 run_test test_revert_added_subtree
1532 run_test test_revert_deleted_subtree
1533 run_test test_revert_symlink
1534 run_test test_revert_patch_symlink
1535 run_test test_revert_umask