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 function test_revert_basic {
20 local testroot=`test_init revert_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "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" != "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" != "0" ]; then
49 diff -u $testroot/content.expected $testroot/content
50 fi
51 test_done "$testroot" "$ret"
53 }
55 function test_revert_rm {
56 local testroot=`test_init revert_rm`
58 got checkout $testroot/repo $testroot/wt > /dev/null
59 ret="$?"
60 if [ "$ret" != "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" != "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" != "0" ]; then
85 diff -u $testroot/content.expected $testroot/content
86 fi
87 test_done "$testroot" "$ret"
88 }
90 function test_revert_add {
91 local testroot=`test_init revert_add`
93 got checkout $testroot/repo $testroot/wt > /dev/null
94 ret="$?"
95 if [ "$ret" != "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" != "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" != "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" != "0" ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
134 fi
135 test_done "$testroot" "$ret"
138 function test_revert_multiple {
139 local testroot=`test_init revert_multiple`
141 got checkout $testroot/repo $testroot/wt > /dev/null
142 ret="$?"
143 if [ "$ret" != "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" != "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" != "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" != "0" ]; then
181 diff -u $testroot/content.expected $testroot/content
182 fi
183 test_done "$testroot" "$ret"
186 function 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" != "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" != "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" != "0" ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
219 fi
220 test_done "$testroot" "$ret"
224 function 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" != "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" == "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" != "0" ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 echo "usage: got revert [-p] [-F response-script] [-R] path ..." \
254 > $testroot/stderr.expected
255 cmp -s $testroot/stderr.expected $testroot/stderr
256 ret="$?"
257 if [ "$ret" != "0" ]; then
258 diff -u $testroot/stderr.expected $testroot/stderr
259 fi
260 test_done "$testroot" "$ret"
263 function test_revert_directory {
264 local testroot=`test_init revert_directory`
266 got checkout $testroot/repo $testroot/wt > /dev/null
267 ret="$?"
268 if [ "$ret" != "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" == "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" != "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" != "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" != "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" != "0" ]; then
318 diff -u $testroot/content.expected $testroot/content
319 fi
320 test_done "$testroot" "$ret"
323 function 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" != "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 '? epsilon/new_file' >> $testroot/stdout.expected
341 echo 'R epsilon/zeta' >> $testroot/stdout.expected
342 cmp -s $testroot/stdout.expected $testroot/stdout
343 ret="$?"
344 if [ "$ret" != "0" ]; then
345 diff -u $testroot/stdout.expected $testroot/stdout
346 test_done "$testroot" "$ret"
347 return 1
348 fi
350 echo "new untracked file" > $testroot/content.expected
351 cat $testroot/wt/epsilon/new_file > $testroot/content
353 cmp -s $testroot/content.expected $testroot/content
354 ret="$?"
355 if [ "$ret" != "0" ]; then
356 diff -u $testroot/content.expected $testroot/content
357 test_done "$testroot" "$ret"
358 return 1
359 fi
361 echo "zeta" > $testroot/content.expected
362 cat $testroot/wt/epsilon/zeta > $testroot/content
364 cmp -s $testroot/content.expected $testroot/content
365 ret="$?"
366 if [ "$ret" != "0" ]; then
367 diff -u $testroot/content.expected $testroot/content
368 fi
370 test_done "$testroot" "$ret"
373 function test_revert_patch {
374 local testroot=`test_init revert_patch`
376 jot 16 > $testroot/repo/numbers
377 (cd $testroot/repo && git add numbers)
378 git_commit $testroot/repo -m "added numbers file"
379 local commit_id=`git_show_head $testroot/repo`
381 got checkout $testroot/repo $testroot/wt > /dev/null
382 ret="$?"
383 if [ "$ret" != "0" ]; then
384 test_done "$testroot" "$ret"
385 return 1
386 fi
388 sed -i -e 's/^2$/a/' $testroot/wt/numbers
389 sed -i -e 's/^7$/b/' $testroot/wt/numbers
390 sed -i -e 's/^16$/c/' $testroot/wt/numbers
392 (cd $testroot/wt && got diff > $testroot/numbers.diff)
394 # don't revert any hunks
395 printf "n\nn\nn\n" > $testroot/patchscript
396 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
397 numbers > $testroot/stdout)
398 ret="$?"
399 if [ "$ret" != "0" ]; then
400 echo "got revert command failed unexpectedly" >&2
401 test_done "$testroot" "1"
402 return 1
403 fi
404 cat > $testroot/stdout.expected <<EOF
405 -----------------------------------------------
406 @@ -1,5 +1,5 @@
408 -2
409 +a
413 -----------------------------------------------
414 M numbers (change 1 of 3)
415 revert this change? [y/n/q] n
416 -----------------------------------------------
417 @@ -4,7 +4,7 @@
421 -7
422 +b
425 10
426 -----------------------------------------------
427 M numbers (change 2 of 3)
428 revert this change? [y/n/q] n
429 -----------------------------------------------
430 @@ -13,4 +13,4 @@
431 13
432 14
433 15
434 -16
435 +c
436 -----------------------------------------------
437 M numbers (change 3 of 3)
438 revert this change? [y/n/q] n
439 EOF
440 cmp -s $testroot/stdout.expected $testroot/stdout
441 ret="$?"
442 if [ "$ret" != "0" ]; then
443 diff -u $testroot/stdout.expected $testroot/stdout
444 test_done "$testroot" "$ret"
445 return 1
446 fi
448 (cd $testroot/wt && got status > $testroot/stdout)
449 echo "M numbers" > $testroot/stdout.expected
450 cmp -s $testroot/stdout.expected $testroot/stdout
451 ret="$?"
452 if [ "$ret" != "0" ]; then
453 diff -u $testroot/stdout.expected $testroot/stdout
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 (cd $testroot/wt && got diff > $testroot/stdout)
459 cmp -s $testroot/numbers.diff $testroot/stdout
460 ret="$?"
461 if [ "$ret" != "0" ]; then
462 diff -u $testroot/numbers.diff $testroot/stdout
463 test_done "$testroot" "$ret"
464 return 1
465 fi
467 # revert first hunk
468 printf "y\nn\nn\n" > $testroot/patchscript
469 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
470 numbers > $testroot/stdout)
471 ret="$?"
472 if [ "$ret" != "0" ]; then
473 echo "got revert command failed unexpectedly" >&2
474 test_done "$testroot" "1"
475 return 1
476 fi
477 cat > $testroot/stdout.expected <<EOF
478 -----------------------------------------------
479 @@ -1,5 +1,5 @@
481 -2
482 +a
486 -----------------------------------------------
487 M numbers (change 1 of 3)
488 revert this change? [y/n/q] y
489 -----------------------------------------------
490 @@ -4,7 +4,7 @@
494 -7
495 +b
498 10
499 -----------------------------------------------
500 M numbers (change 2 of 3)
501 revert this change? [y/n/q] n
502 -----------------------------------------------
503 @@ -13,4 +13,4 @@
504 13
505 14
506 15
507 -16
508 +c
509 -----------------------------------------------
510 M numbers (change 3 of 3)
511 revert this change? [y/n/q] n
512 EOF
513 cmp -s $testroot/stdout.expected $testroot/stdout
514 ret="$?"
515 if [ "$ret" != "0" ]; then
516 diff -u $testroot/stdout.expected $testroot/stdout
517 test_done "$testroot" "$ret"
518 return 1
519 fi
521 (cd $testroot/wt && got status > $testroot/stdout)
522 echo "M numbers" > $testroot/stdout.expected
523 cmp -s $testroot/stdout.expected $testroot/stdout
524 ret="$?"
525 if [ "$ret" != "0" ]; then
526 diff -u $testroot/stdout.expected $testroot/stdout
527 test_done "$testroot" "$ret"
528 return 1
529 fi
531 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
532 echo -n 'blob - ' >> $testroot/stdout.expected
533 got tree -r $testroot/repo -i -c $commit_id \
534 | grep 'numbers$' | cut -d' ' -f 1 \
535 >> $testroot/stdout.expected
536 echo 'file + numbers' >> $testroot/stdout.expected
537 cat >> $testroot/stdout.expected <<EOF
538 --- numbers
539 +++ numbers
540 @@ -4,7 +4,7 @@
544 -7
545 +b
548 10
549 @@ -13,4 +13,4 @@
550 13
551 14
552 15
553 -16
554 +c
555 EOF
556 (cd $testroot/wt && got diff > $testroot/stdout)
557 cmp -s $testroot/stdout.expected $testroot/stdout
558 ret="$?"
559 if [ "$ret" != "0" ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
562 return 1
563 fi
565 # put first hunk back
566 sed -i -e 's/^2$/a/' $testroot/wt/numbers
568 # revert middle hunk
569 printf "n\ny\nn\n" > $testroot/patchscript
570 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
571 numbers > $testroot/stdout)
573 cat > $testroot/stdout.expected <<EOF
574 -----------------------------------------------
575 @@ -1,5 +1,5 @@
577 -2
578 +a
582 -----------------------------------------------
583 M numbers (change 1 of 3)
584 revert this change? [y/n/q] n
585 -----------------------------------------------
586 @@ -4,7 +4,7 @@
590 -7
591 +b
594 10
595 -----------------------------------------------
596 M numbers (change 2 of 3)
597 revert this change? [y/n/q] y
598 -----------------------------------------------
599 @@ -13,4 +13,4 @@
600 13
601 14
602 15
603 -16
604 +c
605 -----------------------------------------------
606 M numbers (change 3 of 3)
607 revert this change? [y/n/q] n
608 EOF
609 cmp -s $testroot/stdout.expected $testroot/stdout
610 ret="$?"
611 if [ "$ret" != "0" ]; then
612 diff -u $testroot/stdout.expected $testroot/stdout
613 test_done "$testroot" "$ret"
614 return 1
615 fi
617 (cd $testroot/wt && got status > $testroot/stdout)
618 echo "M numbers" > $testroot/stdout.expected
619 cmp -s $testroot/stdout.expected $testroot/stdout
620 ret="$?"
621 if [ "$ret" != "0" ]; then
622 diff -u $testroot/stdout.expected $testroot/stdout
623 test_done "$testroot" "$ret"
624 return 1
625 fi
627 (cd $testroot/wt && got diff > $testroot/stdout)
629 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
630 echo -n 'blob - ' >> $testroot/stdout.expected
631 got tree -r $testroot/repo -i -c $commit_id \
632 | grep 'numbers$' | cut -d' ' -f 1 \
633 >> $testroot/stdout.expected
634 echo 'file + numbers' >> $testroot/stdout.expected
635 cat >> $testroot/stdout.expected <<EOF
636 --- numbers
637 +++ numbers
638 @@ -1,5 +1,5 @@
640 -2
641 +a
645 @@ -13,4 +13,4 @@
646 13
647 14
648 15
649 -16
650 +c
651 EOF
652 cmp -s $testroot/stdout.expected $testroot/stdout
653 ret="$?"
654 if [ "$ret" != "0" ]; then
655 diff -u $testroot/stdout.expected $testroot/stdout
656 test_done "$testroot" "$ret"
657 return 1
658 fi
660 # revert last hunk
661 printf "n\ny\n" > $testroot/patchscript
662 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
663 numbers > $testroot/stdout)
664 cat > $testroot/stdout.expected <<EOF
665 -----------------------------------------------
666 @@ -1,5 +1,5 @@
668 -2
669 +a
673 -----------------------------------------------
674 M numbers (change 1 of 2)
675 revert this change? [y/n/q] n
676 -----------------------------------------------
677 @@ -13,4 +13,4 @@
678 13
679 14
680 15
681 -16
682 +c
683 -----------------------------------------------
684 M numbers (change 2 of 2)
685 revert this change? [y/n/q] y
686 EOF
687 cmp -s $testroot/stdout.expected $testroot/stdout
688 ret="$?"
689 if [ "$ret" != "0" ]; then
690 diff -u $testroot/stdout.expected $testroot/stdout
691 test_done "$testroot" "$ret"
692 return 1
693 fi
695 (cd $testroot/wt && got diff > $testroot/stdout)
697 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
698 echo -n 'blob - ' >> $testroot/stdout.expected
699 got tree -r $testroot/repo -i -c $commit_id \
700 | grep 'numbers$' | cut -d' ' -f 1 \
701 >> $testroot/stdout.expected
702 echo 'file + numbers' >> $testroot/stdout.expected
703 cat >> $testroot/stdout.expected <<EOF
704 --- numbers
705 +++ numbers
706 @@ -1,5 +1,5 @@
708 -2
709 +a
713 EOF
714 cmp -s $testroot/stdout.expected $testroot/stdout
715 ret="$?"
716 if [ "$ret" != "0" ]; then
717 diff -u $testroot/stdout.expected $testroot/stdout
718 fi
719 test_done "$testroot" "$ret"
722 function test_revert_patch_added {
723 local testroot=`test_init revert_patch_added`
724 local commit_id=`git_show_head $testroot/repo`
726 got checkout $testroot/repo $testroot/wt > /dev/null
727 ret="$?"
728 if [ "$ret" != "0" ]; then
729 test_done "$testroot" "$ret"
730 return 1
731 fi
733 echo "new" > $testroot/wt/epsilon/new
734 (cd $testroot/wt && got add epsilon/new > /dev/null)
736 printf "n\n" > $testroot/patchscript
737 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
738 epsilon/new > $testroot/stdout)
740 echo "A epsilon/new" > $testroot/stdout.expected
741 echo "revert this addition? [y/n] n" >> $testroot/stdout.expected
742 cmp -s $testroot/stdout.expected $testroot/stdout
743 ret="$?"
744 if [ "$ret" != "0" ]; then
745 diff -u $testroot/stdout.expected $testroot/stdout
746 test_done "$testroot" "$ret"
747 return 1
748 fi
750 (cd $testroot/wt && got status > $testroot/stdout)
751 echo "A epsilon/new" > $testroot/stdout.expected
752 cmp -s $testroot/stdout.expected $testroot/stdout
753 ret="$?"
754 if [ "$ret" != "0" ]; then
755 diff -u $testroot/stdout.expected $testroot/stdout
756 test_done "$testroot" "$ret"
757 return 1
758 fi
760 printf "y\n" > $testroot/patchscript
761 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
762 epsilon/new > $testroot/stdout)
764 echo "A epsilon/new" > $testroot/stdout.expected
765 echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
766 echo "R epsilon/new" >> $testroot/stdout.expected
767 cmp -s $testroot/stdout.expected $testroot/stdout
768 ret="$?"
769 if [ "$ret" != "0" ]; then
770 diff -u $testroot/stdout.expected $testroot/stdout
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 (cd $testroot/wt && got status > $testroot/stdout)
776 echo "? epsilon/new" > $testroot/stdout.expected
777 cmp -s $testroot/stdout.expected $testroot/stdout
778 ret="$?"
779 if [ "$ret" != "0" ]; then
780 diff -u $testroot/stdout.expected $testroot/stdout
781 fi
782 test_done "$testroot" "$ret"
785 function test_revert_patch_removed {
786 local testroot=`test_init revert_patch_removed`
787 local commit_id=`git_show_head $testroot/repo`
789 got checkout $testroot/repo $testroot/wt > /dev/null
790 ret="$?"
791 if [ "$ret" != "0" ]; then
792 test_done "$testroot" "$ret"
793 return 1
794 fi
796 (cd $testroot/wt && got rm beta > /dev/null)
798 printf "n\n" > $testroot/patchscript
799 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
800 beta > $testroot/stdout)
801 echo "D beta" > $testroot/stdout.expected
802 echo "revert this deletion? [y/n] n" >> $testroot/stdout.expected
803 cmp -s $testroot/stdout.expected $testroot/stdout
804 ret="$?"
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/stdout.expected $testroot/stdout
807 test_done "$testroot" "$ret"
808 return 1
809 fi
811 (cd $testroot/wt && got status > $testroot/stdout)
812 echo "D beta" > $testroot/stdout.expected
813 cmp -s $testroot/stdout.expected $testroot/stdout
814 ret="$?"
815 if [ "$ret" != "0" ]; then
816 diff -u $testroot/stdout.expected $testroot/stdout
817 test_done "$testroot" "$ret"
818 return 1
819 fi
821 printf "y\n" > $testroot/patchscript
822 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
823 beta > $testroot/stdout)
825 echo "D beta" > $testroot/stdout.expected
826 echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
827 echo "R beta" >> $testroot/stdout.expected
828 cmp -s $testroot/stdout.expected $testroot/stdout
829 ret="$?"
830 if [ "$ret" != "0" ]; then
831 diff -u $testroot/stdout.expected $testroot/stdout
832 test_done "$testroot" "$ret"
833 return 1
834 fi
836 (cd $testroot/wt && got status > $testroot/stdout)
837 echo -n > $testroot/stdout.expected
838 cmp -s $testroot/stdout.expected $testroot/stdout
839 ret="$?"
840 if [ "$ret" != "0" ]; then
841 diff -u $testroot/stdout.expected $testroot/stdout
842 fi
843 test_done "$testroot" "$ret"
846 function test_revert_patch_one_change {
847 local testroot=`test_init revert_patch_one_change`
849 jot 16 > $testroot/repo/numbers
850 (cd $testroot/repo && git add numbers)
851 git_commit $testroot/repo -m "added numbers file"
852 local commit_id=`git_show_head $testroot/repo`
854 got checkout $testroot/repo $testroot/wt > /dev/null
855 ret="$?"
856 if [ "$ret" != "0" ]; then
857 test_done "$testroot" "$ret"
858 return 1
859 fi
861 # Ensure file size is changed. Avoids race condition causing test
862 # failures where 'got revert' does not see changes to revert if
863 # timestamps and size in stat info remain unchanged.
864 sed -i -e 's/^2$/aa/' $testroot/wt/numbers
866 # revert change with -p
867 printf "y\n" > $testroot/patchscript
868 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
869 numbers > $testroot/stdout)
870 ret="$?"
871 if [ "$ret" != "0" ]; then
872 echo "got revert command failed unexpectedly" >&2
873 test_done "$testroot" "1"
874 return 1
875 fi
876 cat > $testroot/stdout.expected <<EOF
877 -----------------------------------------------
878 @@ -1,5 +1,5 @@
880 -2
881 +aa
885 -----------------------------------------------
886 M numbers (change 1 of 1)
887 revert this change? [y/n/q] y
888 EOF
889 ret="$?"
890 if [ "$ret" != "0" ]; then
891 echo "got revert command failed unexpectedly" >&2
892 test_done "$testroot" "1"
893 return 1
894 fi
896 cmp -s $testroot/stdout.expected $testroot/stdout
897 ret="$?"
898 if [ "$ret" != "0" ]; then
899 diff -u $testroot/stdout.expected $testroot/stdout
900 test_done "$testroot" "$ret"
901 return 1
902 fi
904 (cd $testroot/wt && got status > $testroot/stdout)
905 echo -n > $testroot/stdout.expected
906 cmp -s $testroot/stdout.expected $testroot/stdout
907 ret="$?"
908 if [ "$ret" != "0" ]; then
909 diff -u $testroot/stdout.expected $testroot/stdout
910 test_done "$testroot" "$ret"
911 return 1
912 fi
914 (cd $testroot/wt && got diff > $testroot/stdout)
915 echo -n > $testroot/stdout.expected
916 cmp -s $testroot/stdout.expected $testroot/stdout
917 ret="$?"
918 if [ "$ret" != "0" ]; then
919 diff -u $testroot/stdout.expected $testroot/stdout
920 fi
921 test_done "$testroot" "$ret"
924 run_test test_revert_basic
925 run_test test_revert_rm
926 run_test test_revert_add
927 run_test test_revert_multiple
928 run_test test_revert_file_in_new_subdir
929 run_test test_revert_no_arguments
930 run_test test_revert_directory
931 run_test test_revert_directory_unknown
932 run_test test_revert_patch
933 run_test test_revert_patch_added
934 run_test test_revert_patch_removed
935 run_test test_revert_patch_one_change