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"
324 function test_revert_patch {
325 local testroot=`test_init revert_patch`
327 jot 16 > $testroot/repo/numbers
328 (cd $testroot/repo && git add numbers)
329 git_commit $testroot/repo -m "added numbers file"
330 local commit_id=`git_show_head $testroot/repo`
332 got checkout $testroot/repo $testroot/wt > /dev/null
333 ret="$?"
334 if [ "$ret" != "0" ]; then
335 test_done "$testroot" "$ret"
336 return 1
337 fi
339 sed -i -e 's/^2$/a/' $testroot/wt/numbers
340 sed -i -e 's/^7$/b/' $testroot/wt/numbers
341 sed -i -e 's/^16$/c/' $testroot/wt/numbers
343 (cd $testroot/wt && got diff > $testroot/numbers.diff)
345 # don't revert any hunks
346 printf "n\nn\nn\n" > $testroot/patchscript
347 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
348 numbers > $testroot/stdout)
349 ret="$?"
350 if [ "$ret" != "0" ]; then
351 echo "got revert command failed unexpectedly" >&2
352 test_done "$testroot" "1"
353 return 1
354 fi
355 cat > $testroot/stdout.expected <<EOF
356 -----------------------------------------------
357 @@ -1,5 +1,5 @@
359 -2
360 +a
364 -----------------------------------------------
365 M numbers (change 1 of 3)
366 revert this change? [y/n/q] n
367 -----------------------------------------------
368 @@ -4,7 +4,7 @@
372 -7
373 +b
376 10
377 -----------------------------------------------
378 M numbers (change 2 of 3)
379 revert this change? [y/n/q] n
380 -----------------------------------------------
381 @@ -13,4 +13,4 @@
382 13
383 14
384 15
385 -16
386 +c
387 -----------------------------------------------
388 M numbers (change 3 of 3)
389 revert this change? [y/n/q] n
390 EOF
391 cmp -s $testroot/stdout.expected $testroot/stdout
392 ret="$?"
393 if [ "$ret" != "0" ]; then
394 diff -u $testroot/stdout.expected $testroot/stdout
395 test_done "$testroot" "$ret"
396 return 1
397 fi
399 (cd $testroot/wt && got status > $testroot/stdout)
400 echo "M numbers" > $testroot/stdout.expected
401 cmp -s $testroot/stdout.expected $testroot/stdout
402 ret="$?"
403 if [ "$ret" != "0" ]; then
404 diff -u $testroot/stdout.expected $testroot/stdout
405 test_done "$testroot" "$ret"
406 return 1
407 fi
409 (cd $testroot/wt && got diff > $testroot/stdout)
410 cmp -s $testroot/numbers.diff $testroot/stdout
411 ret="$?"
412 if [ "$ret" != "0" ]; then
413 diff -u $testroot/numbers.diff $testroot/stdout
414 test_done "$testroot" "$ret"
415 return 1
416 fi
418 # revert first hunk
419 printf "y\nn\nn\n" > $testroot/patchscript
420 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
421 numbers > $testroot/stdout)
422 ret="$?"
423 if [ "$ret" != "0" ]; then
424 echo "got revert command failed unexpectedly" >&2
425 test_done "$testroot" "1"
426 return 1
427 fi
428 cat > $testroot/stdout.expected <<EOF
429 -----------------------------------------------
430 @@ -1,5 +1,5 @@
432 -2
433 +a
437 -----------------------------------------------
438 M numbers (change 1 of 3)
439 revert this change? [y/n/q] y
440 -----------------------------------------------
441 @@ -4,7 +4,7 @@
445 -7
446 +b
449 10
450 -----------------------------------------------
451 M numbers (change 2 of 3)
452 revert this change? [y/n/q] n
453 -----------------------------------------------
454 @@ -13,4 +13,4 @@
455 13
456 14
457 15
458 -16
459 +c
460 -----------------------------------------------
461 M numbers (change 3 of 3)
462 revert this change? [y/n/q] n
463 EOF
464 cmp -s $testroot/stdout.expected $testroot/stdout
465 ret="$?"
466 if [ "$ret" != "0" ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 (cd $testroot/wt && got status > $testroot/stdout)
473 echo "M numbers" > $testroot/stdout.expected
474 cmp -s $testroot/stdout.expected $testroot/stdout
475 ret="$?"
476 if [ "$ret" != "0" ]; then
477 diff -u $testroot/stdout.expected $testroot/stdout
478 test_done "$testroot" "$ret"
479 return 1
480 fi
482 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
483 echo -n 'blob - ' >> $testroot/stdout.expected
484 got tree -r $testroot/repo -i -c $commit_id \
485 | grep 'numbers$' | cut -d' ' -f 1 \
486 >> $testroot/stdout.expected
487 echo 'file + numbers' >> $testroot/stdout.expected
488 cat >> $testroot/stdout.expected <<EOF
489 --- numbers
490 +++ numbers
491 @@ -4,7 +4,7 @@
495 -7
496 +b
499 10
500 @@ -13,4 +13,4 @@
501 13
502 14
503 15
504 -16
505 +c
506 EOF
507 (cd $testroot/wt && got diff > $testroot/stdout)
508 cmp -s $testroot/stdout.expected $testroot/stdout
509 ret="$?"
510 if [ "$ret" != "0" ]; then
511 diff -u $testroot/stdout.expected $testroot/stdout
512 test_done "$testroot" "$ret"
513 return 1
514 fi
516 # put first hunk back
517 sed -i -e 's/^2$/a/' $testroot/wt/numbers
519 # revert middle hunk
520 printf "n\ny\nn\n" > $testroot/patchscript
521 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
522 numbers > $testroot/stdout)
524 cat > $testroot/stdout.expected <<EOF
525 -----------------------------------------------
526 @@ -1,5 +1,5 @@
528 -2
529 +a
533 -----------------------------------------------
534 M numbers (change 1 of 3)
535 revert this change? [y/n/q] n
536 -----------------------------------------------
537 @@ -4,7 +4,7 @@
541 -7
542 +b
545 10
546 -----------------------------------------------
547 M numbers (change 2 of 3)
548 revert this change? [y/n/q] y
549 -----------------------------------------------
550 @@ -13,4 +13,4 @@
551 13
552 14
553 15
554 -16
555 +c
556 -----------------------------------------------
557 M numbers (change 3 of 3)
558 revert this change? [y/n/q] n
559 EOF
560 cmp -s $testroot/stdout.expected $testroot/stdout
561 ret="$?"
562 if [ "$ret" != "0" ]; then
563 diff -u $testroot/stdout.expected $testroot/stdout
564 test_done "$testroot" "$ret"
565 return 1
566 fi
568 (cd $testroot/wt && got status > $testroot/stdout)
569 echo "M numbers" > $testroot/stdout.expected
570 cmp -s $testroot/stdout.expected $testroot/stdout
571 ret="$?"
572 if [ "$ret" != "0" ]; then
573 diff -u $testroot/stdout.expected $testroot/stdout
574 test_done "$testroot" "$ret"
575 return 1
576 fi
578 (cd $testroot/wt && got diff > $testroot/stdout)
580 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
581 echo -n 'blob - ' >> $testroot/stdout.expected
582 got tree -r $testroot/repo -i -c $commit_id \
583 | grep 'numbers$' | cut -d' ' -f 1 \
584 >> $testroot/stdout.expected
585 echo 'file + numbers' >> $testroot/stdout.expected
586 cat >> $testroot/stdout.expected <<EOF
587 --- numbers
588 +++ numbers
589 @@ -1,5 +1,5 @@
591 -2
592 +a
596 @@ -13,4 +13,4 @@
597 13
598 14
599 15
600 -16
601 +c
602 EOF
603 cmp -s $testroot/stdout.expected $testroot/stdout
604 ret="$?"
605 if [ "$ret" != "0" ]; then
606 diff -u $testroot/stdout.expected $testroot/stdout
607 test_done "$testroot" "$ret"
608 return 1
609 fi
611 # revert last hunk
612 printf "n\ny\n" > $testroot/patchscript
613 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
614 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 2)
626 revert this change? [y/n/q] n
627 -----------------------------------------------
628 @@ -13,4 +13,4 @@
629 13
630 14
631 15
632 -16
633 +c
634 -----------------------------------------------
635 M numbers (change 2 of 2)
636 revert this change? [y/n/q] y
637 EOF
638 cmp -s $testroot/stdout.expected $testroot/stdout
639 ret="$?"
640 if [ "$ret" != "0" ]; then
641 diff -u $testroot/stdout.expected $testroot/stdout
642 test_done "$testroot" "$ret"
643 return 1
644 fi
646 (cd $testroot/wt && got diff > $testroot/stdout)
648 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
649 echo -n 'blob - ' >> $testroot/stdout.expected
650 got tree -r $testroot/repo -i -c $commit_id \
651 | grep 'numbers$' | cut -d' ' -f 1 \
652 >> $testroot/stdout.expected
653 echo 'file + numbers' >> $testroot/stdout.expected
654 cat >> $testroot/stdout.expected <<EOF
655 --- numbers
656 +++ numbers
657 @@ -1,5 +1,5 @@
659 -2
660 +a
664 EOF
665 cmp -s $testroot/stdout.expected $testroot/stdout
666 ret="$?"
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/stdout.expected $testroot/stdout
669 fi
670 test_done "$testroot" "$ret"
673 function test_revert_patch_added {
674 local testroot=`test_init revert_patch_added`
675 local commit_id=`git_show_head $testroot/repo`
677 got checkout $testroot/repo $testroot/wt > /dev/null
678 ret="$?"
679 if [ "$ret" != "0" ]; then
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 echo "new" > $testroot/wt/epsilon/new
685 (cd $testroot/wt && got add epsilon/new > /dev/null)
687 printf "n\n" > $testroot/patchscript
688 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
689 epsilon/new > $testroot/stdout)
691 echo "A epsilon/new" > $testroot/stdout.expected
692 echo "revert this addition? [y/n] n" >> $testroot/stdout.expected
693 cmp -s $testroot/stdout.expected $testroot/stdout
694 ret="$?"
695 if [ "$ret" != "0" ]; then
696 diff -u $testroot/stdout.expected $testroot/stdout
697 test_done "$testroot" "$ret"
698 return 1
699 fi
701 (cd $testroot/wt && got status > $testroot/stdout)
702 echo "A epsilon/new" > $testroot/stdout.expected
703 cmp -s $testroot/stdout.expected $testroot/stdout
704 ret="$?"
705 if [ "$ret" != "0" ]; then
706 diff -u $testroot/stdout.expected $testroot/stdout
707 test_done "$testroot" "$ret"
708 return 1
709 fi
711 printf "y\n" > $testroot/patchscript
712 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
713 epsilon/new > $testroot/stdout)
715 echo "A epsilon/new" > $testroot/stdout.expected
716 echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
717 echo "R epsilon/new" >> $testroot/stdout.expected
718 cmp -s $testroot/stdout.expected $testroot/stdout
719 ret="$?"
720 if [ "$ret" != "0" ]; then
721 diff -u $testroot/stdout.expected $testroot/stdout
722 test_done "$testroot" "$ret"
723 return 1
724 fi
726 (cd $testroot/wt && got status > $testroot/stdout)
727 echo "? epsilon/new" > $testroot/stdout.expected
728 cmp -s $testroot/stdout.expected $testroot/stdout
729 ret="$?"
730 if [ "$ret" != "0" ]; then
731 diff -u $testroot/stdout.expected $testroot/stdout
732 fi
733 test_done "$testroot" "$ret"
736 function test_revert_patch_removed {
737 local testroot=`test_init revert_patch_removed`
738 local commit_id=`git_show_head $testroot/repo`
740 got checkout $testroot/repo $testroot/wt > /dev/null
741 ret="$?"
742 if [ "$ret" != "0" ]; then
743 test_done "$testroot" "$ret"
744 return 1
745 fi
747 (cd $testroot/wt && got rm beta > /dev/null)
749 printf "n\n" > $testroot/patchscript
750 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
751 beta > $testroot/stdout)
752 echo "D beta" > $testroot/stdout.expected
753 echo "revert this deletion? [y/n] n" >> $testroot/stdout.expected
754 cmp -s $testroot/stdout.expected $testroot/stdout
755 ret="$?"
756 if [ "$ret" != "0" ]; then
757 diff -u $testroot/stdout.expected $testroot/stdout
758 test_done "$testroot" "$ret"
759 return 1
760 fi
762 (cd $testroot/wt && got status > $testroot/stdout)
763 echo "D beta" > $testroot/stdout.expected
764 cmp -s $testroot/stdout.expected $testroot/stdout
765 ret="$?"
766 if [ "$ret" != "0" ]; then
767 diff -u $testroot/stdout.expected $testroot/stdout
768 test_done "$testroot" "$ret"
769 return 1
770 fi
772 printf "y\n" > $testroot/patchscript
773 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
774 beta > $testroot/stdout)
776 echo "D beta" > $testroot/stdout.expected
777 echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
778 echo "R beta" >> $testroot/stdout.expected
779 cmp -s $testroot/stdout.expected $testroot/stdout
780 ret="$?"
781 if [ "$ret" != "0" ]; then
782 diff -u $testroot/stdout.expected $testroot/stdout
783 test_done "$testroot" "$ret"
784 return 1
785 fi
787 (cd $testroot/wt && got status > $testroot/stdout)
788 echo -n > $testroot/stdout.expected
789 cmp -s $testroot/stdout.expected $testroot/stdout
790 ret="$?"
791 if [ "$ret" != "0" ]; then
792 diff -u $testroot/stdout.expected $testroot/stdout
793 fi
794 test_done "$testroot" "$ret"
797 function test_revert_patch_one_change {
798 local testroot=`test_init revert_patch_one_change`
800 jot 16 > $testroot/repo/numbers
801 (cd $testroot/repo && git add numbers)
802 git_commit $testroot/repo -m "added numbers file"
803 local commit_id=`git_show_head $testroot/repo`
805 got checkout $testroot/repo $testroot/wt > /dev/null
806 ret="$?"
807 if [ "$ret" != "0" ]; then
808 test_done "$testroot" "$ret"
809 return 1
810 fi
812 # Ensure file size is changed. Avoids race condition causing test
813 # failures where 'got revert' does not see changes to revert if
814 # timestamps and size in stat info remain unchanged.
815 sed -i -e 's/^2$/aa/' $testroot/wt/numbers
817 # revert change with -p
818 printf "y\n" > $testroot/patchscript
819 (cd $testroot/wt && got revert -F $testroot/patchscript -p \
820 numbers > $testroot/stdout)
821 ret="$?"
822 if [ "$ret" != "0" ]; then
823 echo "got revert command failed unexpectedly" >&2
824 test_done "$testroot" "1"
825 return 1
826 fi
827 cat > $testroot/stdout.expected <<EOF
828 -----------------------------------------------
829 @@ -1,5 +1,5 @@
831 -2
832 +aa
836 -----------------------------------------------
837 M numbers (change 1 of 1)
838 revert this change? [y/n/q] y
839 EOF
840 ret="$?"
841 if [ "$ret" != "0" ]; then
842 echo "got revert command failed unexpectedly" >&2
843 test_done "$testroot" "1"
844 return 1
845 fi
847 cmp -s $testroot/stdout.expected $testroot/stdout
848 ret="$?"
849 if [ "$ret" != "0" ]; then
850 diff -u $testroot/stdout.expected $testroot/stdout
851 test_done "$testroot" "$ret"
852 return 1
853 fi
855 (cd $testroot/wt && got status > $testroot/stdout)
856 echo -n > $testroot/stdout.expected
857 cmp -s $testroot/stdout.expected $testroot/stdout
858 ret="$?"
859 if [ "$ret" != "0" ]; then
860 diff -u $testroot/stdout.expected $testroot/stdout
861 test_done "$testroot" "$ret"
862 return 1
863 fi
865 (cd $testroot/wt && got diff > $testroot/stdout)
866 echo -n > $testroot/stdout.expected
867 cmp -s $testroot/stdout.expected $testroot/stdout
868 ret="$?"
869 if [ "$ret" != "0" ]; then
870 diff -u $testroot/stdout.expected $testroot/stdout
871 fi
872 test_done "$testroot" "$ret"
875 run_test test_revert_basic
876 run_test test_revert_rm
877 run_test test_revert_add
878 run_test test_revert_multiple
879 run_test test_revert_file_in_new_subdir
880 run_test test_revert_no_arguments
881 run_test test_revert_directory
882 run_test test_revert_patch
883 run_test test_revert_patch_added
884 run_test test_revert_patch_removed
885 run_test test_revert_patch_one_change