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_missing_directory() {
373 local testroot=`test_init revert_missing_directory`
375 got checkout $testroot/repo $testroot/wt > /dev/null
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 test_done "$testroot" "$ret"
379 return 1
380 fi
382 rm -r $testroot/wt/epsilon
384 (cd $testroot/wt && got revert -R epsilon > $testroot/stdout)
386 echo 'R epsilon/zeta' >> $testroot/stdout.expected
387 cmp -s $testroot/stdout.expected $testroot/stdout
388 ret=$?
389 if [ $ret -ne 0 ]; then
390 diff -u $testroot/stdout.expected $testroot/stdout
391 test_done "$testroot" "$ret"
392 return 1
393 fi
395 echo "zeta" > $testroot/content.expected
396 cat $testroot/wt/epsilon/zeta > $testroot/content
398 cmp -s $testroot/content.expected $testroot/content
399 ret=$?
400 if [ $ret -ne 0 ]; then
401 diff -u $testroot/content.expected $testroot/content
402 fi
404 test_done "$testroot" "$ret"
407 test_revert_patch() {
408 local testroot=`test_init revert_patch`
410 jot 16 > $testroot/repo/numbers
411 (cd $testroot/repo && git add numbers)
412 git_commit $testroot/repo -m "added numbers file"
413 local commit_id=`git_show_head $testroot/repo`
415 got checkout $testroot/repo $testroot/wt > /dev/null
416 ret=$?
417 if [ $ret -ne 0 ]; then
418 test_done "$testroot" "$ret"
419 return 1
420 fi
422 ed -s $testroot/wt/numbers <<-\EOF
423 ,s/^2$/a/
424 ,s/^7$/b/
425 ,s/^16$/c/
427 EOF
429 (cd $testroot/wt && got diff > $testroot/numbers.diff)
431 # don't revert any hunks
432 printf "n\nn\nn\n" > $testroot/patchscript
433 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
434 numbers > $testroot/stdout)
435 ret=$?
436 if [ $ret -ne 0 ]; then
437 echo "got revert command failed unexpectedly" >&2
438 test_done "$testroot" "1"
439 return 1
440 fi
441 cat > $testroot/stdout.expected <<EOF
442 -----------------------------------------------
443 @@ -1,5 +1,5 @@
445 -2
446 +a
450 -----------------------------------------------
451 M numbers (change 1 of 3)
452 revert this change? [y/n/q] n
453 -----------------------------------------------
454 @@ -4,7 +4,7 @@
458 -7
459 +b
462 10
463 -----------------------------------------------
464 M numbers (change 2 of 3)
465 revert this change? [y/n/q] n
466 -----------------------------------------------
467 @@ -13,4 +13,4 @@
468 13
469 14
470 15
471 -16
472 +c
473 -----------------------------------------------
474 M numbers (change 3 of 3)
475 revert this change? [y/n/q] n
476 EOF
477 cmp -s $testroot/stdout.expected $testroot/stdout
478 ret=$?
479 if [ $ret -ne 0 ]; then
480 diff -u $testroot/stdout.expected $testroot/stdout
481 test_done "$testroot" "$ret"
482 return 1
483 fi
485 (cd $testroot/wt && got status > $testroot/stdout)
486 echo "M numbers" > $testroot/stdout.expected
487 cmp -s $testroot/stdout.expected $testroot/stdout
488 ret=$?
489 if [ $ret -ne 0 ]; then
490 diff -u $testroot/stdout.expected $testroot/stdout
491 test_done "$testroot" "$ret"
492 return 1
493 fi
495 (cd $testroot/wt && got diff > $testroot/stdout)
496 cmp -s $testroot/numbers.diff $testroot/stdout
497 ret=$?
498 if [ $ret -ne 0 ]; then
499 diff -u $testroot/numbers.diff $testroot/stdout
500 test_done "$testroot" "$ret"
501 return 1
502 fi
504 # revert first hunk
505 printf "y\nn\nn\n" > $testroot/patchscript
506 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
507 numbers > $testroot/stdout)
508 ret=$?
509 if [ $ret -ne 0 ]; then
510 echo "got revert command failed unexpectedly" >&2
511 test_done "$testroot" "1"
512 return 1
513 fi
514 cat > $testroot/stdout.expected <<EOF
515 -----------------------------------------------
516 @@ -1,5 +1,5 @@
518 -2
519 +a
523 -----------------------------------------------
524 M numbers (change 1 of 3)
525 revert this change? [y/n/q] y
526 -----------------------------------------------
527 @@ -4,7 +4,7 @@
531 -7
532 +b
535 10
536 -----------------------------------------------
537 M numbers (change 2 of 3)
538 revert this change? [y/n/q] n
539 -----------------------------------------------
540 @@ -13,4 +13,4 @@
541 13
542 14
543 15
544 -16
545 +c
546 -----------------------------------------------
547 M numbers (change 3 of 3)
548 revert this change? [y/n/q] n
549 EOF
550 cmp -s $testroot/stdout.expected $testroot/stdout
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done "$testroot" "$ret"
555 return 1
556 fi
558 (cd $testroot/wt && got status > $testroot/stdout)
559 echo "M numbers" > $testroot/stdout.expected
560 cmp -s $testroot/stdout.expected $testroot/stdout
561 ret=$?
562 if [ $ret -ne 0 ]; then
563 diff -u $testroot/stdout.expected $testroot/stdout
564 test_done "$testroot" "$ret"
565 return 1
566 fi
568 echo "diff $testroot/wt" > $testroot/stdout.expected
569 echo "commit - $commit_id" >> $testroot/stdout.expected
570 echo "path + $testroot/wt" >> $testroot/stdout.expected
571 echo -n 'blob - ' >> $testroot/stdout.expected
572 got tree -r $testroot/repo -i -c $commit_id \
573 | grep 'numbers$' | cut -d' ' -f 1 \
574 >> $testroot/stdout.expected
575 echo 'file + numbers' >> $testroot/stdout.expected
576 cat >> $testroot/stdout.expected <<EOF
577 --- numbers
578 +++ numbers
579 @@ -4,7 +4,7 @@
583 -7
584 +b
587 10
588 @@ -13,4 +13,4 @@
589 13
590 14
591 15
592 -16
593 +c
594 EOF
595 (cd $testroot/wt && got diff > $testroot/stdout)
596 cmp -s $testroot/stdout.expected $testroot/stdout
597 ret=$?
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 test_done "$testroot" "$ret"
601 return 1
602 fi
604 # put first hunk back
605 ed -s $testroot/wt/numbers <<-\EOF
606 ,s/^2$/a/
608 EOF
610 # revert middle hunk
611 printf "n\ny\nn\n" > $testroot/patchscript
612 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
613 numbers > $testroot/stdout)
615 cat > $testroot/stdout.expected <<EOF
616 -----------------------------------------------
617 @@ -1,5 +1,5 @@
619 -2
620 +a
624 -----------------------------------------------
625 M numbers (change 1 of 3)
626 revert this change? [y/n/q] n
627 -----------------------------------------------
628 @@ -4,7 +4,7 @@
632 -7
633 +b
636 10
637 -----------------------------------------------
638 M numbers (change 2 of 3)
639 revert this change? [y/n/q] y
640 -----------------------------------------------
641 @@ -13,4 +13,4 @@
642 13
643 14
644 15
645 -16
646 +c
647 -----------------------------------------------
648 M numbers (change 3 of 3)
649 revert this change? [y/n/q] n
650 EOF
651 cmp -s $testroot/stdout.expected $testroot/stdout
652 ret=$?
653 if [ $ret -ne 0 ]; then
654 diff -u $testroot/stdout.expected $testroot/stdout
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 (cd $testroot/wt && got status > $testroot/stdout)
660 echo "M numbers" > $testroot/stdout.expected
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 (cd $testroot/wt && got diff > $testroot/stdout)
671 echo "diff $testroot/wt" > $testroot/stdout.expected
672 echo "commit - $commit_id" >> $testroot/stdout.expected
673 echo "path + $testroot/wt" >> $testroot/stdout.expected
674 echo -n 'blob - ' >> $testroot/stdout.expected
675 got tree -r $testroot/repo -i -c $commit_id \
676 | grep 'numbers$' | cut -d' ' -f 1 \
677 >> $testroot/stdout.expected
678 echo 'file + numbers' >> $testroot/stdout.expected
679 cat >> $testroot/stdout.expected <<EOF
680 --- numbers
681 +++ numbers
682 @@ -1,5 +1,5 @@
684 -2
685 +a
689 @@ -13,4 +13,4 @@
690 13
691 14
692 15
693 -16
694 +c
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 # revert last hunk
705 printf "n\ny\n" > $testroot/patchscript
706 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
707 numbers > $testroot/stdout)
708 cat > $testroot/stdout.expected <<EOF
709 -----------------------------------------------
710 @@ -1,5 +1,5 @@
712 -2
713 +a
717 -----------------------------------------------
718 M numbers (change 1 of 2)
719 revert this change? [y/n/q] n
720 -----------------------------------------------
721 @@ -13,4 +13,4 @@
722 13
723 14
724 15
725 -16
726 +c
727 -----------------------------------------------
728 M numbers (change 2 of 2)
729 revert this change? [y/n/q] y
730 EOF
731 cmp -s $testroot/stdout.expected $testroot/stdout
732 ret=$?
733 if [ $ret -ne 0 ]; then
734 diff -u $testroot/stdout.expected $testroot/stdout
735 test_done "$testroot" "$ret"
736 return 1
737 fi
739 (cd $testroot/wt && got diff > $testroot/stdout)
741 echo "diff $testroot/wt" > $testroot/stdout.expected
742 echo "commit - $commit_id" >> $testroot/stdout.expected
743 echo "path + $testroot/wt" >> $testroot/stdout.expected
744 echo -n 'blob - ' >> $testroot/stdout.expected
745 got tree -r $testroot/repo -i -c $commit_id \
746 | grep 'numbers$' | cut -d' ' -f 1 \
747 >> $testroot/stdout.expected
748 echo 'file + numbers' >> $testroot/stdout.expected
749 cat >> $testroot/stdout.expected <<EOF
750 --- numbers
751 +++ numbers
752 @@ -1,5 +1,5 @@
754 -2
755 +a
759 EOF
760 cmp -s $testroot/stdout.expected $testroot/stdout
761 ret=$?
762 if [ $ret -ne 0 ]; then
763 diff -u $testroot/stdout.expected $testroot/stdout
764 fi
765 test_done "$testroot" "$ret"
768 test_revert_patch_added() {
769 local testroot=`test_init revert_patch_added`
770 local commit_id=`git_show_head $testroot/repo`
772 got checkout $testroot/repo $testroot/wt > /dev/null
773 ret=$?
774 if [ $ret -ne 0 ]; then
775 test_done "$testroot" "$ret"
776 return 1
777 fi
779 echo "new" > $testroot/wt/epsilon/new
780 (cd $testroot/wt && got add epsilon/new > /dev/null)
782 printf "n\n" > $testroot/patchscript
783 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
784 epsilon/new > $testroot/stdout)
786 echo "A epsilon/new" > $testroot/stdout.expected
787 echo "revert this addition? [y/n] n" >> $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 test_done "$testroot" "$ret"
793 return 1
794 fi
796 (cd $testroot/wt && got status > $testroot/stdout)
797 echo "A epsilon/new" > $testroot/stdout.expected
798 cmp -s $testroot/stdout.expected $testroot/stdout
799 ret=$?
800 if [ $ret -ne 0 ]; then
801 diff -u $testroot/stdout.expected $testroot/stdout
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 printf "y\n" > $testroot/patchscript
807 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
808 epsilon/new > $testroot/stdout)
810 echo "A epsilon/new" > $testroot/stdout.expected
811 echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
812 echo "R epsilon/new" >> $testroot/stdout.expected
813 cmp -s $testroot/stdout.expected $testroot/stdout
814 ret=$?
815 if [ $ret -ne 0 ]; then
816 diff -u $testroot/stdout.expected $testroot/stdout
817 test_done "$testroot" "$ret"
818 return 1
819 fi
821 (cd $testroot/wt && got status > $testroot/stdout)
822 echo "? epsilon/new" > $testroot/stdout.expected
823 cmp -s $testroot/stdout.expected $testroot/stdout
824 ret=$?
825 if [ $ret -ne 0 ]; then
826 diff -u $testroot/stdout.expected $testroot/stdout
827 fi
828 test_done "$testroot" "$ret"
831 test_revert_patch_removed() {
832 local testroot=`test_init revert_patch_removed`
833 local commit_id=`git_show_head $testroot/repo`
835 got checkout $testroot/repo $testroot/wt > /dev/null
836 ret=$?
837 if [ $ret -ne 0 ]; then
838 test_done "$testroot" "$ret"
839 return 1
840 fi
842 (cd $testroot/wt && got rm beta > /dev/null)
844 printf "n\n" > $testroot/patchscript
845 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
846 beta > $testroot/stdout)
847 echo "D beta" > $testroot/stdout.expected
848 echo "revert this deletion? [y/n] 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 test_done "$testroot" "$ret"
854 return 1
855 fi
857 (cd $testroot/wt && got status > $testroot/stdout)
858 echo "D beta" > $testroot/stdout.expected
859 cmp -s $testroot/stdout.expected $testroot/stdout
860 ret=$?
861 if [ $ret -ne 0 ]; then
862 diff -u $testroot/stdout.expected $testroot/stdout
863 test_done "$testroot" "$ret"
864 return 1
865 fi
867 printf "y\n" > $testroot/patchscript
868 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
869 beta > $testroot/stdout)
871 echo "D beta" > $testroot/stdout.expected
872 echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
873 echo "R beta" >> $testroot/stdout.expected
874 cmp -s $testroot/stdout.expected $testroot/stdout
875 ret=$?
876 if [ $ret -ne 0 ]; then
877 diff -u $testroot/stdout.expected $testroot/stdout
878 test_done "$testroot" "$ret"
879 return 1
880 fi
882 (cd $testroot/wt && got status > $testroot/stdout)
883 echo -n > $testroot/stdout.expected
884 cmp -s $testroot/stdout.expected $testroot/stdout
885 ret=$?
886 if [ $ret -ne 0 ]; then
887 diff -u $testroot/stdout.expected $testroot/stdout
888 fi
889 test_done "$testroot" "$ret"
892 test_revert_patch_one_change() {
893 local testroot=`test_init revert_patch_one_change`
895 jot 16 > $testroot/repo/numbers
896 (cd $testroot/repo && git add numbers)
897 git_commit $testroot/repo -m "added numbers file"
898 local commit_id=`git_show_head $testroot/repo`
900 got checkout $testroot/repo $testroot/wt > /dev/null
901 ret=$?
902 if [ $ret -ne 0 ]; then
903 test_done "$testroot" "$ret"
904 return 1
905 fi
907 # Ensure file size is changed. Avoids race condition causing test
908 # failures where 'got revert' does not see changes to revert if
909 # timestamps and size in stat info remain unchanged.
910 ed -s $testroot/wt/numbers <<-\EOF
911 ,s/^2$/aa/
913 EOF
915 # revert change with -p
916 printf "y\n" > $testroot/patchscript
917 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
918 numbers > $testroot/stdout)
919 ret=$?
920 if [ $ret -ne 0 ]; then
921 echo "got revert command failed unexpectedly" >&2
922 test_done "$testroot" "1"
923 return 1
924 fi
925 cat > $testroot/stdout.expected <<EOF
926 -----------------------------------------------
927 @@ -1,5 +1,5 @@
929 -2
930 +aa
934 -----------------------------------------------
935 M numbers (change 1 of 1)
936 revert this change? [y/n/q] y
937 EOF
938 ret=$?
939 if [ $ret -ne 0 ]; then
940 echo "got revert command failed unexpectedly" >&2
941 test_done "$testroot" "1"
942 return 1
943 fi
945 cmp -s $testroot/stdout.expected $testroot/stdout
946 ret=$?
947 if [ $ret -ne 0 ]; then
948 diff -u $testroot/stdout.expected $testroot/stdout
949 test_done "$testroot" "$ret"
950 return 1
951 fi
953 (cd $testroot/wt && got status > $testroot/stdout)
954 echo -n > $testroot/stdout.expected
955 cmp -s $testroot/stdout.expected $testroot/stdout
956 ret=$?
957 if [ $ret -ne 0 ]; then
958 diff -u $testroot/stdout.expected $testroot/stdout
959 test_done "$testroot" "$ret"
960 return 1
961 fi
963 (cd $testroot/wt && got diff > $testroot/stdout)
964 echo -n > $testroot/stdout.expected
965 cmp -s $testroot/stdout.expected $testroot/stdout
966 ret=$?
967 if [ $ret -ne 0 ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
969 fi
970 test_done "$testroot" "$ret"
973 test_revert_added_subtree() {
974 local testroot=`test_init revert_added_subtree`
976 got checkout $testroot/repo $testroot/wt > /dev/null
977 ret=$?
978 if [ $ret -ne 0 ]; then
979 test_done "$testroot" "$ret"
980 return 1
981 fi
983 mkdir -p $testroot/wt/epsilon/foo/bar/baz
984 mkdir -p $testroot/wt/epsilon/foo/bar/bax
985 echo "new file" > $testroot/wt/epsilon/foo/a.o
986 echo "new file" > $testroot/wt/epsilon/foo/a.o
987 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
988 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
989 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
990 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
991 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
992 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
993 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
994 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
995 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
996 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
997 (cd $testroot/wt && got add -R epsilon >/dev/null)
999 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
1000 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
1001 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
1002 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
1003 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
1004 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
1005 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
1006 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
1007 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
1008 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
1009 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
1011 (cd $testroot/wt && got revert -R . > $testroot/stdout)
1013 cmp -s $testroot/stdout.expected $testroot/stdout
1014 ret=$?
1015 if [ $ret -ne 0 ]; then
1016 diff -u $testroot/stdout.expected $testroot/stdout
1017 test_done "$testroot" "$ret"
1018 return 1
1021 echo "? epsilon/foo/a.o" > $testroot/stdout.expected
1022 echo "? epsilon/foo/bar/b.d" >> $testroot/stdout.expected
1023 echo "? epsilon/foo/bar/b.o" >> $testroot/stdout.expected
1024 echo "? epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
1025 echo "? epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
1026 echo "? epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
1027 echo "? epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
1028 echo "? epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
1029 echo "? epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
1030 echo "? epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
1031 echo "? epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
1033 (cd $testroot/wt && got status > $testroot/stdout)
1035 cmp -s $testroot/stdout.expected $testroot/stdout
1036 ret=$?
1037 if [ $ret -ne 0 ]; then
1038 diff -u $testroot/stdout.expected $testroot/stdout
1040 test_done "$testroot" "$ret"
1043 test_revert_deleted_subtree() {
1044 local testroot=`test_init revert_deleted_subtree`
1046 got checkout $testroot/repo $testroot/wt > /dev/null
1047 ret=$?
1048 if [ $ret -ne 0 ]; then
1049 test_done "$testroot" "$ret"
1050 return 1
1053 mkdir -p $testroot/wt/epsilon/foo/bar/baz
1054 mkdir -p $testroot/wt/epsilon/foo/bar/bax
1055 echo "new file" > $testroot/wt/epsilon/foo/a.o
1056 echo "new file" > $testroot/wt/epsilon/foo/a.o
1057 echo "new file" > $testroot/wt/epsilon/foo/bar/b.o
1058 echo "new file" > $testroot/wt/epsilon/foo/bar/b.d
1059 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.o
1060 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/f.d
1061 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.o
1062 echo "new file" > $testroot/wt/epsilon/foo/bar/baz/c.d
1063 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.o
1064 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/e.d
1065 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.o
1066 echo "new file" > $testroot/wt/epsilon/foo/bar/bax/x.d
1067 (cd $testroot/wt && got add -R epsilon >/dev/null)
1068 (cd $testroot/wt && got commit -m "add subtree" >/dev/null)
1070 # now delete and revert the entire subtree
1071 (cd $testroot/wt && got rm -R epsilon/foo >/dev/null)
1073 echo "R epsilon/foo/a.o" > $testroot/stdout.expected
1074 echo "R epsilon/foo/bar/b.d" >> $testroot/stdout.expected
1075 echo "R epsilon/foo/bar/b.o" >> $testroot/stdout.expected
1076 echo "R epsilon/foo/bar/bax/e.d" >> $testroot/stdout.expected
1077 echo "R epsilon/foo/bar/bax/e.o" >> $testroot/stdout.expected
1078 echo "R epsilon/foo/bar/bax/x.d" >> $testroot/stdout.expected
1079 echo "R epsilon/foo/bar/bax/x.o" >> $testroot/stdout.expected
1080 echo "R epsilon/foo/bar/baz/c.d" >> $testroot/stdout.expected
1081 echo "R epsilon/foo/bar/baz/c.o" >> $testroot/stdout.expected
1082 echo "R epsilon/foo/bar/baz/f.d" >> $testroot/stdout.expected
1083 echo "R epsilon/foo/bar/baz/f.o" >> $testroot/stdout.expected
1085 (cd $testroot/wt && got revert -R . > $testroot/stdout)
1087 cmp -s $testroot/stdout.expected $testroot/stdout
1088 ret=$?
1089 if [ $ret -ne 0 ]; then
1090 diff -u $testroot/stdout.expected $testroot/stdout
1091 test_done "$testroot" "$ret"
1092 return 1
1095 echo -n > $testroot/stdout.expected
1096 (cd $testroot/wt && got status > $testroot/stdout)
1098 cmp -s $testroot/stdout.expected $testroot/stdout
1099 ret=$?
1100 if [ $ret -ne 0 ]; then
1101 diff -u $testroot/stdout.expected $testroot/stdout
1103 test_done "$testroot" "$ret"
1106 test_revert_symlink() {
1107 local testroot=`test_init revert_symlink`
1109 (cd $testroot/repo && ln -s alpha alpha.link)
1110 (cd $testroot/repo && ln -s epsilon epsilon.link)
1111 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1112 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1113 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1114 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1115 (cd $testroot/repo && git add .)
1116 git_commit $testroot/repo -m "add symlinks"
1117 local commit_id1=`git_show_head $testroot/repo`
1119 got checkout $testroot/repo $testroot/wt > /dev/null
1121 # symlink to file A now points to file B
1122 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1123 # symlink to a directory A now points to file B
1124 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1125 # "bad" symlink now contains a different target path
1126 echo "foo" > $testroot/wt/passwd.link
1127 # relative symlink to directory A now points to relative directory B
1128 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1129 epsilon/beta.link)
1130 # an unversioned symlink
1131 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1132 # symlink to file A now points to non-existent file B
1133 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1134 # removed symlink
1135 (cd $testroot/wt && got rm zeta.link > /dev/null)
1136 # added symlink
1137 (cd $testroot/wt && ln -sf beta new.link)
1138 (cd $testroot/wt && got add new.link > /dev/null)
1140 (cd $testroot/wt && got revert alpha.link epsilon.link \
1141 passwd.link epsilon/beta.link dotgotfoo.link \
1142 nonexistent.link zeta.link new.link > $testroot/stdout)
1144 cat > $testroot/stdout.expected <<EOF
1145 R alpha.link
1146 R epsilon/beta.link
1147 R epsilon.link
1148 R new.link
1149 R nonexistent.link
1150 R passwd.link
1151 R zeta.link
1152 EOF
1153 cmp -s $testroot/stdout.expected $testroot/stdout
1154 ret=$?
1155 if [ $ret -ne 0 ]; then
1156 diff -u $testroot/stdout.expected $testroot/stdout
1157 test_done "$testroot" "$ret"
1158 return 1
1161 if ! [ -h $testroot/wt/alpha.link ]; then
1162 echo "alpha.link is not a symlink"
1163 test_done "$testroot" "1"
1164 return 1
1167 readlink $testroot/wt/alpha.link > $testroot/stdout
1168 echo "alpha" > $testroot/stdout.expected
1169 cmp -s $testroot/stdout.expected $testroot/stdout
1170 ret=$?
1171 if [ $ret -ne 0 ]; then
1172 diff -u $testroot/stdout.expected $testroot/stdout
1173 test_done "$testroot" "$ret"
1174 return 1
1177 if ! [ -h $testroot/wt/epsilon.link ]; then
1178 echo "epsilon.link is not a symlink"
1179 test_done "$testroot" "1"
1180 return 1
1183 readlink $testroot/wt/epsilon.link > $testroot/stdout
1184 echo "epsilon" > $testroot/stdout.expected
1185 cmp -s $testroot/stdout.expected $testroot/stdout
1186 ret=$?
1187 if [ $ret -ne 0 ]; then
1188 diff -u $testroot/stdout.expected $testroot/stdout
1189 test_done "$testroot" "$ret"
1190 return 1
1193 if [ -h $testroot/wt/passwd.link ]; then
1194 echo "passwd.link should not be a symlink" >&2
1195 test_done "$testroot" "1"
1196 return 1
1199 echo -n "/etc/passwd" > $testroot/content.expected
1200 cp $testroot/wt/passwd.link $testroot/content
1202 cmp -s $testroot/content.expected $testroot/content
1203 ret=$?
1204 if [ $ret -ne 0 ]; then
1205 diff -u $testroot/content.expected $testroot/content
1206 test_done "$testroot" "$ret"
1207 return 1
1210 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1211 echo "../beta" > $testroot/stdout.expected
1212 cmp -s $testroot/stdout.expected $testroot/stdout
1213 ret=$?
1214 if [ $ret -ne 0 ]; then
1215 diff -u $testroot/stdout.expected $testroot/stdout
1216 test_done "$testroot" "$ret"
1217 return 1
1220 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1221 echo "nonexistent" > $testroot/stdout.expected
1222 cmp -s $testroot/stdout.expected $testroot/stdout
1223 ret=$?
1224 if [ $ret -ne 0 ]; then
1225 diff -u $testroot/stdout.expected $testroot/stdout
1226 test_done "$testroot" "$ret"
1227 return 1
1230 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1231 echo "dotgotfoo.link is not a symlink " >&2
1232 test_done "$testroot" "1"
1233 return 1
1235 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1236 echo ".got/foo" > $testroot/stdout.expected
1237 cmp -s $testroot/stdout.expected $testroot/stdout
1238 ret=$?
1239 if [ $ret -ne 0 ]; then
1240 diff -u $testroot/stdout.expected $testroot/stdout
1241 test_done "$testroot" "$ret"
1242 return 1
1245 if [ ! -h $testroot/wt/zeta.link ]; then
1246 echo -n "zeta.link is not a symlink" >&2
1247 test_done "$testroot" "1"
1248 return 1
1251 readlink $testroot/wt/zeta.link > $testroot/stdout
1252 echo "epsilon/zeta" > $testroot/stdout.expected
1253 cmp -s $testroot/stdout.expected $testroot/stdout
1254 ret=$?
1255 if [ $ret -ne 0 ]; then
1256 diff -u $testroot/stdout.expected $testroot/stdout
1257 test_done "$testroot" "$ret"
1258 return 1
1261 if [ ! -h $testroot/wt/new.link ]; then
1262 echo -n "new.link is not a symlink" >&2
1263 test_done "$testroot" "1"
1264 return 1
1267 (cd $testroot/wt && got status > $testroot/stdout)
1268 echo "? dotgotfoo.link" > $testroot/stdout.expected
1269 echo "? new.link" >> $testroot/stdout.expected
1270 cmp -s $testroot/stdout.expected $testroot/stdout
1271 ret=$?
1272 if [ $ret -ne 0 ]; then
1273 diff -u $testroot/stdout.expected $testroot/stdout
1274 return 1
1276 test_done "$testroot" "$ret"
1279 test_revert_patch_symlink() {
1280 local testroot=`test_init revert_patch_symlink`
1282 (cd $testroot/repo && ln -s alpha alpha.link)
1283 (cd $testroot/repo && ln -s epsilon epsilon.link)
1284 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1285 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1286 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1287 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1288 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1289 (cd $testroot/repo && git add .)
1290 git_commit $testroot/repo -m "add symlinks"
1291 local commit_id1=`git_show_head $testroot/repo`
1293 got checkout $testroot/repo $testroot/wt > /dev/null
1295 # symlink to file A now points to file B
1296 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1297 # symlink to a directory A now points to file B
1298 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1299 # "bad" symlink now contains a different target path
1300 echo "foo" > $testroot/wt/passwd.link
1301 # relative symlink to directory A now points to relative directory B
1302 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1303 epsilon/beta.link)
1304 # an unversioned symlink
1305 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1306 # symlink to file A now points to non-existent file B
1307 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1308 # removed symlink
1309 (cd $testroot/wt && got rm zeta.link > /dev/null)
1310 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1311 # added symlink
1312 (cd $testroot/wt && ln -sf beta new.link)
1313 (cd $testroot/wt && got add new.link > /dev/null)
1314 (cd $testroot/wt && ln -sf beta zeta3.link)
1315 (cd $testroot/wt && got add zeta3.link > /dev/null)
1317 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1318 (cd $testroot/wt && got revert -F $testroot/patchscript -p -R . \
1319 > $testroot/stdout)
1320 ret=$?
1321 if [ $ret -ne 0 ]; then
1322 echo "got revert command failed unexpectedly" >&2
1323 test_done "$testroot" "1"
1324 return 1
1326 cat > $testroot/stdout.expected <<EOF
1327 -----------------------------------------------
1328 @@ -1 +1 @@
1329 -alpha
1330 \ No newline at end of file
1331 +gamma/delta
1332 \ No newline at end of file
1333 -----------------------------------------------
1334 M alpha.link (change 1 of 1)
1335 revert this change? [y/n/q] y
1336 R alpha.link
1337 -----------------------------------------------
1338 @@ -1 +1 @@
1339 -../beta
1340 \ No newline at end of file
1341 +../gamma
1342 \ No newline at end of file
1343 -----------------------------------------------
1344 M epsilon/beta.link (change 1 of 1)
1345 revert this change? [y/n/q] n
1346 -----------------------------------------------
1347 @@ -1 +1 @@
1348 -epsilon
1349 \ No newline at end of file
1350 +beta
1351 \ No newline at end of file
1352 -----------------------------------------------
1353 M epsilon.link (change 1 of 1)
1354 revert this change? [y/n/q] y
1355 R epsilon.link
1356 A new.link
1357 revert this addition? [y/n] n
1358 -----------------------------------------------
1359 @@ -1 +1 @@
1360 -nonexistent
1361 \ No newline at end of file
1362 +nonexistent2
1363 \ No newline at end of file
1364 -----------------------------------------------
1365 M nonexistent.link (change 1 of 1)
1366 revert this change? [y/n/q] y
1367 R nonexistent.link
1368 -----------------------------------------------
1369 @@ -1 +1 @@
1370 -/etc/passwd
1371 \ No newline at end of file
1372 +foo
1373 -----------------------------------------------
1374 M passwd.link (change 1 of 1)
1375 revert this change? [y/n/q] y
1376 R passwd.link
1377 D zeta.link
1378 revert this deletion? [y/n] n
1379 D zeta2.link
1380 revert this deletion? [y/n] y
1381 R zeta2.link
1382 A zeta3.link
1383 revert this addition? [y/n] y
1384 R zeta3.link
1385 EOF
1386 cmp -s $testroot/stdout.expected $testroot/stdout
1387 ret=$?
1388 if [ $ret -ne 0 ]; then
1389 diff -u $testroot/stdout.expected $testroot/stdout
1390 test_done "$testroot" "$ret"
1391 return 1
1394 if ! [ -h $testroot/wt/alpha.link ]; then
1395 echo "alpha.link is not a symlink"
1396 test_done "$testroot" "1"
1397 return 1
1400 readlink $testroot/wt/alpha.link > $testroot/stdout
1401 echo "alpha" > $testroot/stdout.expected
1402 cmp -s $testroot/stdout.expected $testroot/stdout
1403 ret=$?
1404 if [ $ret -ne 0 ]; then
1405 diff -u $testroot/stdout.expected $testroot/stdout
1406 test_done "$testroot" "$ret"
1407 return 1
1410 if ! [ -h $testroot/wt/epsilon.link ]; then
1411 echo "epsilon.link is not a symlink"
1412 test_done "$testroot" "1"
1413 return 1
1416 readlink $testroot/wt/epsilon.link > $testroot/stdout
1417 echo "epsilon" > $testroot/stdout.expected
1418 cmp -s $testroot/stdout.expected $testroot/stdout
1419 ret=$?
1420 if [ $ret -ne 0 ]; then
1421 diff -u $testroot/stdout.expected $testroot/stdout
1422 test_done "$testroot" "$ret"
1423 return 1
1426 if [ -h $testroot/wt/passwd.link ]; then
1427 echo "passwd.link should not be a symlink" >&2
1428 test_done "$testroot" "1"
1429 return 1
1432 echo -n "/etc/passwd" > $testroot/content.expected
1433 cp $testroot/wt/passwd.link $testroot/content
1435 cmp -s $testroot/content.expected $testroot/content
1436 ret=$?
1437 if [ $ret -ne 0 ]; then
1438 diff -u $testroot/content.expected $testroot/content
1439 test_done "$testroot" "$ret"
1440 return 1
1443 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1444 echo "../gamma" > $testroot/stdout.expected
1445 cmp -s $testroot/stdout.expected $testroot/stdout
1446 ret=$?
1447 if [ $ret -ne 0 ]; then
1448 diff -u $testroot/stdout.expected $testroot/stdout
1449 test_done "$testroot" "$ret"
1450 return 1
1453 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1454 echo "nonexistent" > $testroot/stdout.expected
1455 cmp -s $testroot/stdout.expected $testroot/stdout
1456 ret=$?
1457 if [ $ret -ne 0 ]; then
1458 diff -u $testroot/stdout.expected $testroot/stdout
1459 test_done "$testroot" "$ret"
1460 return 1
1463 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1464 echo "dotgotfoo.link is not a symlink " >&2
1465 test_done "$testroot" "1"
1466 return 1
1468 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1469 echo ".got/foo" > $testroot/stdout.expected
1470 cmp -s $testroot/stdout.expected $testroot/stdout
1471 ret=$?
1472 if [ $ret -ne 0 ]; then
1473 diff -u $testroot/stdout.expected $testroot/stdout
1474 test_done "$testroot" "$ret"
1475 return 1
1479 if [ -e $testroot/wt/zeta.link ]; then
1480 echo -n "zeta.link should not exist on disk" >&2
1481 test_done "$testroot" "1"
1482 return 1
1485 if [ ! -h $testroot/wt/zeta2.link ]; then
1486 echo -n "zeta2.link is not a symlink" >&2
1487 test_done "$testroot" "1"
1488 return 1
1491 readlink $testroot/wt/zeta2.link > $testroot/stdout
1492 echo "epsilon/zeta" > $testroot/stdout.expected
1493 cmp -s $testroot/stdout.expected $testroot/stdout
1494 ret=$?
1495 if [ $ret -ne 0 ]; then
1496 diff -u $testroot/stdout.expected $testroot/stdout
1497 test_done "$testroot" "$ret"
1498 return 1
1501 if [ ! -h $testroot/wt/zeta3.link ]; then
1502 echo -n "zeta3.link is not a symlink" >&2
1503 test_done "$testroot" "1"
1504 return 1
1507 readlink $testroot/wt/zeta3.link > $testroot/stdout
1508 echo "beta" > $testroot/stdout.expected
1509 cmp -s $testroot/stdout.expected $testroot/stdout
1510 ret=$?
1511 if [ $ret -ne 0 ]; then
1512 diff -u $testroot/stdout.expected $testroot/stdout
1513 test_done "$testroot" "$ret"
1514 return 1
1517 if [ ! -h $testroot/wt/new.link ]; then
1518 echo -n "new.link is not a symlink" >&2
1519 test_done "$testroot" "1"
1520 return 1
1523 (cd $testroot/wt && got status > $testroot/stdout)
1524 echo "? dotgotfoo.link" > $testroot/stdout.expected
1525 echo "M epsilon/beta.link" >> $testroot/stdout.expected
1526 echo "A new.link" >> $testroot/stdout.expected
1527 echo "D zeta.link" >> $testroot/stdout.expected
1528 echo "? zeta3.link" >> $testroot/stdout.expected
1529 cmp -s $testroot/stdout.expected $testroot/stdout
1530 ret=$?
1531 if [ $ret -ne 0 ]; then
1532 diff -u $testroot/stdout.expected $testroot/stdout
1533 return 1
1535 test_done "$testroot" "$ret"
1538 test_revert_umask() {
1539 local testroot=`test_init revert_umask`
1541 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1542 echo "edit alpha" > $testroot/wt/alpha
1544 # using a subshell to avoid clobbering global umask
1545 (umask 077 && cd "$testroot/wt" && got revert alpha) \
1546 >/dev/null
1547 ret=$?
1548 if [ $ret -ne 0 ]; then
1549 test_done "$testroot" $ret
1550 return 1
1553 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
1554 echo "alpha is not 0600 after revert" >&2
1555 ls -l "$testroot/wt/alpha" >&2
1556 test_done "$testroot" 1
1557 return 1
1559 test_done "$testroot" 0
1562 test_parseargs "$@"
1563 run_test test_revert_basic
1564 run_test test_revert_rm
1565 run_test test_revert_add
1566 run_test test_revert_multiple
1567 run_test test_revert_file_in_new_subdir
1568 run_test test_revert_no_arguments
1569 run_test test_revert_directory
1570 run_test test_revert_directory_unknown
1571 run_test test_revert_missing_directory
1572 run_test test_revert_patch
1573 run_test test_revert_patch_added
1574 run_test test_revert_patch_removed
1575 run_test test_revert_patch_one_change
1576 run_test test_revert_added_subtree
1577 run_test test_revert_deleted_subtree
1578 run_test test_revert_symlink
1579 run_test test_revert_patch_symlink
1580 run_test test_revert_umask