3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
19 function test_unstage_basic {
20 local testroot=`test_init unstage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
29 echo "modified file" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta > /dev/null)
31 echo "new file" > $testroot/wt/foo
32 (cd $testroot/wt && got add foo > /dev/null)
34 echo ' M alpha' > $testroot/stdout.expected
35 echo ' D beta' >> $testroot/stdout.expected
36 echo ' A foo' >> $testroot/stdout.expected
37 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
39 (cd $testroot/wt && got unstage > $testroot/stdout)
41 if [ "$ret" != "0" ]; then
42 echo "got unstage command failed unexpectedly" >&2
43 test_done "$testroot" "1"
47 echo 'G alpha' > $testroot/stdout.expected
48 echo 'D beta' >> $testroot/stdout.expected
49 echo 'G foo' >> $testroot/stdout.expected
50 cmp -s $testroot/stdout.expected $testroot/stdout
52 if [ "$ret" != "0" ]; then
53 diff -u $testroot/stdout.expected $testroot/stdout
54 test_done "$testroot" "$ret"
58 echo 'M alpha' > $testroot/stdout.expected
59 echo 'D beta' >> $testroot/stdout.expected
60 echo 'A foo' >> $testroot/stdout.expected
61 (cd $testroot/wt && got status > $testroot/stdout)
62 cmp -s $testroot/stdout.expected $testroot/stdout
64 if [ "$ret" != "0" ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
67 test_done "$testroot" "$ret"
70 function test_unstage_unversioned {
71 local testroot=`test_init unstage_unversioned`
73 got checkout $testroot/repo $testroot/wt > /dev/null
75 if [ "$ret" != "0" ]; then
76 test_done "$testroot" "$ret"
80 echo "modified file" > $testroot/wt/alpha
81 (cd $testroot/wt && got rm beta > /dev/null)
82 echo "new file" > $testroot/wt/foo
83 (cd $testroot/wt && got add foo > /dev/null)
85 echo ' M alpha' > $testroot/stdout.expected
86 echo ' D beta' >> $testroot/stdout.expected
87 echo ' A foo' >> $testroot/stdout.expected
88 (cd $testroot/wt && got stage > /dev/null)
90 touch $testroot/wt/unversioned-file
92 (cd $testroot/wt && got status > $testroot/stdout)
93 echo ' M alpha' > $testroot/stdout.expected
94 echo ' D beta' >> $testroot/stdout.expected
95 echo ' A foo' >> $testroot/stdout.expected
96 echo "? unversioned-file" >> $testroot/stdout.expected
97 cmp -s $testroot/stdout.expected $testroot/stdout
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 test_done "$testroot" "$ret"
105 (cd $testroot/wt && got unstage > $testroot/stdout)
107 if [ "$ret" != "0" ]; then
108 echo "got unstage command failed unexpectedly" >&2
109 test_done "$testroot" "1"
113 echo 'G alpha' > $testroot/stdout.expected
114 echo 'D beta' >> $testroot/stdout.expected
115 echo 'G foo' >> $testroot/stdout.expected
116 cmp -s $testroot/stdout.expected $testroot/stdout
118 if [ "$ret" != "0" ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
124 (cd $testroot/wt && got stage > /dev/null)
126 # unstaging an unversioned path is a no-op
127 (cd $testroot/wt && got unstage unversioned > $testroot/stdout)
129 if [ "$ret" != "0" ]; then
130 echo "got unstage command failed unexpectedly" >&2
131 test_done "$testroot" "$ret"
135 echo ' M alpha' > $testroot/stdout.expected
136 echo ' D beta' >> $testroot/stdout.expected
137 echo ' A foo' >> $testroot/stdout.expected
138 echo "? unversioned-file" >> $testroot/stdout.expected
139 (cd $testroot/wt && got status > $testroot/stdout)
140 cmp -s $testroot/stdout.expected $testroot/stdout
142 if [ "$ret" != "0" ]; then
143 diff -u $testroot/stdout.expected $testroot/stdout
145 test_done "$testroot" "$ret"
148 function test_unstage_nonexistent {
149 local testroot=`test_init unstage_nonexistent`
151 got checkout $testroot/repo $testroot/wt > /dev/null
153 if [ "$ret" != "0" ]; then
154 test_done "$testroot" "$ret"
158 echo "modified file" > $testroot/wt/alpha
159 (cd $testroot/wt && got rm beta > /dev/null)
160 echo "new file" > $testroot/wt/foo
161 (cd $testroot/wt && got add foo > /dev/null)
163 echo ' M alpha' > $testroot/stdout.expected
164 echo ' D beta' >> $testroot/stdout.expected
165 echo ' A foo' >> $testroot/stdout.expected
166 (cd $testroot/wt && got stage > /dev/null)
168 # unstaging a non-existent file is a no-op
169 (cd $testroot/wt && got unstage nonexistent-file > $testroot/stdout)
171 if [ "$ret" != "0" ]; then
172 echo "got unstage command failed unexpectedly" >&2
173 test_done "$testroot" "1"
177 echo -n > $testroot/stdout.expected
178 cmp -s $testroot/stdout.expected $testroot/stdout
180 if [ "$ret" != "0" ]; then
181 diff -u $testroot/stdout.expected $testroot/stdout
183 test_done "$testroot" "$ret"
186 function test_unstage_patch {
187 local testroot=`test_init unstage_patch`
189 jot 16 > $testroot/repo/numbers
190 (cd $testroot/repo && git add numbers)
191 git_commit $testroot/repo -m "added numbers file"
192 local commit_id=`git_show_head $testroot/repo`
194 got checkout $testroot/repo $testroot/wt > /dev/null
196 if [ "$ret" != "0" ]; then
197 test_done "$testroot" "$ret"
201 sed -i -e 's/^2$/a/' $testroot/wt/numbers
202 sed -i -e 's/^7$/b/' $testroot/wt/numbers
203 sed -i -e 's/^16$/c/' $testroot/wt/numbers
205 (cd $testroot/wt && got stage > /dev/null)
207 if [ "$ret" != "0" ]; then
208 echo "got stage command failed unexpectedly" >&2
209 test_done "$testroot" "1"
213 # don't unstage any hunks
214 printf "n\nn\nn\n" > $testroot/patchscript
215 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
216 numbers > $testroot/stdout)
218 if [ "$ret" != "0" ]; then
219 echo "got unstage command failed unexpectedly" >&2
220 test_done "$testroot" "1"
223 cat > $testroot/stdout.expected <<EOF
224 -----------------------------------------------
232 -----------------------------------------------
233 M numbers (change 1 of 3)
234 unstage this change? [y/n/q] n
235 -----------------------------------------------
245 -----------------------------------------------
246 M numbers (change 2 of 3)
247 unstage this change? [y/n/q] n
248 -----------------------------------------------
255 -----------------------------------------------
256 M numbers (change 3 of 3)
257 unstage this change? [y/n/q] n
259 cmp -s $testroot/stdout.expected $testroot/stdout
261 if [ "$ret" != "0" ]; then
262 diff -u $testroot/stdout.expected $testroot/stdout
263 test_done "$testroot" "$ret"
267 (cd $testroot/wt && got status > $testroot/stdout)
268 echo " M numbers" > $testroot/stdout.expected
269 cmp -s $testroot/stdout.expected $testroot/stdout
271 if [ "$ret" != "0" ]; then
272 diff -u $testroot/stdout.expected $testroot/stdout
273 test_done "$testroot" "$ret"
277 # unstage middle hunk
278 printf "n\ny\nn\n" > $testroot/patchscript
279 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
280 numbers > $testroot/stdout)
282 cat > $testroot/stdout.expected <<EOF
283 -----------------------------------------------
291 -----------------------------------------------
292 M numbers (change 1 of 3)
293 unstage this change? [y/n/q] n
294 -----------------------------------------------
304 -----------------------------------------------
305 M numbers (change 2 of 3)
306 unstage this change? [y/n/q] y
307 -----------------------------------------------
314 -----------------------------------------------
315 M numbers (change 3 of 3)
316 unstage this change? [y/n/q] n
319 cmp -s $testroot/stdout.expected $testroot/stdout
321 if [ "$ret" != "0" ]; then
322 diff -u $testroot/stdout.expected $testroot/stdout
323 test_done "$testroot" "$ret"
327 (cd $testroot/wt && got status > $testroot/stdout)
328 echo "MM numbers" > $testroot/stdout.expected
329 cmp -s $testroot/stdout.expected $testroot/stdout
331 if [ "$ret" != "0" ]; then
332 diff -u $testroot/stdout.expected $testroot/stdout
333 test_done "$testroot" "$ret"
337 (cd $testroot/wt && got diff -s > $testroot/stdout)
339 echo "diff $commit_id $testroot/wt (staged changes)" \
340 > $testroot/stdout.expected
341 echo -n 'blob - ' >> $testroot/stdout.expected
342 got tree -r $testroot/repo -i -c $commit_id \
343 | grep 'numbers$' | cut -d' ' -f 1 \
344 >> $testroot/stdout.expected
345 echo -n 'blob + ' >> $testroot/stdout.expected
346 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
347 >> $testroot/stdout.expected
348 cat >> $testroot/stdout.expected <<EOF
365 cmp -s $testroot/stdout.expected $testroot/stdout
367 if [ "$ret" != "0" ]; then
368 diff -u $testroot/stdout.expected $testroot/stdout
369 test_done "$testroot" "$ret"
373 (cd $testroot/wt && got diff > $testroot/stdout)
374 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
375 echo -n 'blob - ' >> $testroot/stdout.expected
376 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
377 tr -d '\n' >> $testroot/stdout.expected
378 echo " (staged)" >> $testroot/stdout.expected
379 echo "file + numbers" >> $testroot/stdout.expected
380 cat >> $testroot/stdout.expected <<EOF
393 cmp -s $testroot/stdout.expected $testroot/stdout
395 if [ "$ret" != "0" ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
401 (cd $testroot/wt && got stage >/dev/null)
403 if [ "$ret" != "0" ]; then
404 echo "got stage command failed unexpectedly" >&2
405 test_done "$testroot" "1"
409 (cd $testroot/wt && got status > $testroot/stdout)
410 echo " M numbers" > $testroot/stdout.expected
411 cmp -s $testroot/stdout.expected $testroot/stdout
413 if [ "$ret" != "0" ]; then
414 diff -u $testroot/stdout.expected $testroot/stdout
415 test_done "$testroot" "$ret"
420 printf "n\nn\ny\n" > $testroot/patchscript
421 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
422 numbers > $testroot/stdout)
424 cat > $testroot/stdout.expected <<EOF
425 -----------------------------------------------
433 -----------------------------------------------
434 M numbers (change 1 of 3)
435 unstage this change? [y/n/q] n
436 -----------------------------------------------
446 -----------------------------------------------
447 M numbers (change 2 of 3)
448 unstage this change? [y/n/q] n
449 -----------------------------------------------
456 -----------------------------------------------
457 M numbers (change 3 of 3)
458 unstage this change? [y/n/q] y
461 cmp -s $testroot/stdout.expected $testroot/stdout
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/stdout.expected $testroot/stdout
465 test_done "$testroot" "$ret"
469 (cd $testroot/wt && got status > $testroot/stdout)
470 echo "MM numbers" > $testroot/stdout.expected
471 cmp -s $testroot/stdout.expected $testroot/stdout
473 if [ "$ret" != "0" ]; then
474 diff -u $testroot/stdout.expected $testroot/stdout
475 test_done "$testroot" "$ret"
479 (cd $testroot/wt && got diff -s > $testroot/stdout)
481 echo "diff $commit_id $testroot/wt (staged changes)" \
482 > $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 -n 'blob + ' >> $testroot/stdout.expected
488 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
489 >> $testroot/stdout.expected
490 cat >> $testroot/stdout.expected <<EOF
507 cmp -s $testroot/stdout.expected $testroot/stdout
509 if [ "$ret" != "0" ]; then
510 diff -u $testroot/stdout.expected $testroot/stdout
511 test_done "$testroot" "$ret"
515 (cd $testroot/wt && got diff > $testroot/stdout)
516 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
517 echo -n 'blob - ' >> $testroot/stdout.expected
518 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
519 tr -d '\n' >> $testroot/stdout.expected
520 echo " (staged)" >> $testroot/stdout.expected
521 echo "file + numbers" >> $testroot/stdout.expected
522 cat >> $testroot/stdout.expected <<EOF
532 cmp -s $testroot/stdout.expected $testroot/stdout
534 if [ "$ret" != "0" ]; then
535 diff -u $testroot/stdout.expected $testroot/stdout
536 test_done "$testroot" "$ret"
540 (cd $testroot/wt && got stage >/dev/null)
542 if [ "$ret" != "0" ]; then
543 echo "got stage command failed unexpectedly" >&2
544 test_done "$testroot" "1"
548 (cd $testroot/wt && got status > $testroot/stdout)
549 echo " M numbers" > $testroot/stdout.expected
550 cmp -s $testroot/stdout.expected $testroot/stdout
552 if [ "$ret" != "0" ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done "$testroot" "$ret"
559 printf "y\ny\ny\n" > $testroot/patchscript
560 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
561 numbers > $testroot/stdout)
563 cat > $testroot/stdout.expected <<EOF
564 -----------------------------------------------
572 -----------------------------------------------
573 M numbers (change 1 of 3)
574 unstage this change? [y/n/q] y
575 -----------------------------------------------
585 -----------------------------------------------
586 M numbers (change 2 of 3)
587 unstage this change? [y/n/q] y
588 -----------------------------------------------
595 -----------------------------------------------
596 M numbers (change 3 of 3)
597 unstage this change? [y/n/q] y
600 cmp -s $testroot/stdout.expected $testroot/stdout
602 if [ "$ret" != "0" ]; then
603 diff -u $testroot/stdout.expected $testroot/stdout
604 test_done "$testroot" "$ret"
608 (cd $testroot/wt && got status > $testroot/stdout)
609 echo "M numbers" > $testroot/stdout.expected
610 cmp -s $testroot/stdout.expected $testroot/stdout
612 if [ "$ret" != "0" ]; then
613 diff -u $testroot/stdout.expected $testroot/stdout
614 test_done "$testroot" "$ret"
618 (cd $testroot/wt && got diff -s > $testroot/stdout)
619 echo -n > $testroot/stdout.expected
620 cmp -s $testroot/stdout.expected $testroot/stdout
622 if [ "$ret" != "0" ]; then
623 diff -u $testroot/stdout.expected $testroot/stdout
624 test_done "$testroot" "$ret"
628 (cd $testroot/wt && got diff > $testroot/stdout)
630 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
631 echo -n 'blob - ' >> $testroot/stdout.expected
632 got tree -r $testroot/repo -i -c $commit_id \
633 | grep 'numbers$' | cut -d' ' -f 1 \
634 >> $testroot/stdout.expected
635 echo 'file + numbers' >> $testroot/stdout.expected
636 cat >> $testroot/stdout.expected <<EOF
659 cmp -s $testroot/stdout.expected $testroot/stdout
661 if [ "$ret" != "0" ]; then
662 diff -u $testroot/stdout.expected $testroot/stdout
664 test_done "$testroot" "$ret"
668 function test_unstage_patch_added {
669 local testroot=`test_init unstage_patch_added`
670 local commit_id=`git_show_head $testroot/repo`
672 got checkout $testroot/repo $testroot/wt > /dev/null
674 if [ "$ret" != "0" ]; then
675 test_done "$testroot" "$ret"
679 echo "new" > $testroot/wt/epsilon/new
680 (cd $testroot/wt && got add epsilon/new > /dev/null)
682 (cd $testroot/wt && got stage > /dev/null)
684 printf "y\n" > $testroot/patchscript
685 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
686 epsilon/new > $testroot/stdout)
688 echo "A epsilon/new" > $testroot/stdout.expected
689 echo "unstage this addition? [y/n] y" >> $testroot/stdout.expected
690 echo "G epsilon/new" >> $testroot/stdout.expected
691 cmp -s $testroot/stdout.expected $testroot/stdout
693 if [ "$ret" != "0" ]; then
694 diff -u $testroot/stdout.expected $testroot/stdout
695 test_done "$testroot" "$ret"
699 (cd $testroot/wt && got status > $testroot/stdout)
700 echo "A epsilon/new" > $testroot/stdout.expected
701 cmp -s $testroot/stdout.expected $testroot/stdout
703 if [ "$ret" != "0" ]; then
704 diff -u $testroot/stdout.expected $testroot/stdout
705 test_done "$testroot" "$ret"
709 (cd $testroot/wt && got diff -s > $testroot/stdout)
710 echo -n > $testroot/stdout.expected
711 cmp -s $testroot/stdout.expected $testroot/stdout
713 if [ "$ret" != "0" ]; then
714 diff -u $testroot/stdout.expected $testroot/stdout
715 test_done "$testroot" "$ret"
719 (cd $testroot/wt && got diff > $testroot/stdout)
721 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
722 echo 'blob - /dev/null' >> $testroot/stdout.expected
723 echo 'file + epsilon/new' >> $testroot/stdout.expected
724 echo "--- epsilon/new" >> $testroot/stdout.expected
725 echo "+++ epsilon/new" >> $testroot/stdout.expected
726 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
727 echo "+new" >> $testroot/stdout.expected
728 cmp -s $testroot/stdout.expected $testroot/stdout
730 if [ "$ret" != "0" ]; then
731 diff -u $testroot/stdout.expected $testroot/stdout
733 test_done "$testroot" "$ret"
736 function test_unstage_patch_removed {
737 local testroot=`test_init unstage_patch_removed`
738 local commit_id=`git_show_head $testroot/repo`
740 got checkout $testroot/repo $testroot/wt > /dev/null
742 if [ "$ret" != "0" ]; then
743 test_done "$testroot" "$ret"
747 (cd $testroot/wt && got rm beta > /dev/null)
748 (cd $testroot/wt && got stage > /dev/null)
750 printf "y\n" > $testroot/patchscript
751 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
752 beta > $testroot/stdout)
754 echo "D beta" > $testroot/stdout.expected
755 echo "unstage this deletion? [y/n] y" >> $testroot/stdout.expected
756 echo "D beta" >> $testroot/stdout.expected
757 cmp -s $testroot/stdout.expected $testroot/stdout
759 if [ "$ret" != "0" ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
761 test_done "$testroot" "$ret"
765 (cd $testroot/wt && got status > $testroot/stdout)
766 echo "D beta" > $testroot/stdout.expected
767 cmp -s $testroot/stdout.expected $testroot/stdout
769 if [ "$ret" != "0" ]; then
770 diff -u $testroot/stdout.expected $testroot/stdout
771 test_done "$testroot" "$ret"
775 (cd $testroot/wt && got diff -s > $testroot/stdout)
776 echo -n > $testroot/stdout.expected
777 cmp -s $testroot/stdout.expected $testroot/stdout
779 if [ "$ret" != "0" ]; then
780 diff -u $testroot/stdout.expected $testroot/stdout
781 test_done "$testroot" "$ret"
785 (cd $testroot/wt && got diff > $testroot/stdout)
787 echo "diff $commit_id $testroot/wt" \
788 > $testroot/stdout.expected
789 echo -n 'blob - ' >> $testroot/stdout.expected
790 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
791 >> $testroot/stdout.expected
792 echo 'file + /dev/null' >> $testroot/stdout.expected
793 echo "--- beta" >> $testroot/stdout.expected
794 echo "+++ beta" >> $testroot/stdout.expected
795 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
796 echo "-beta" >> $testroot/stdout.expected
797 cmp -s $testroot/stdout.expected $testroot/stdout
799 if [ "$ret" != "0" ]; then
800 diff -u $testroot/stdout.expected $testroot/stdout
802 test_done "$testroot" "$ret"
805 function test_unstage_patch_quit {
806 local testroot=`test_init unstage_patch_quit`
808 jot 16 > $testroot/repo/numbers
809 echo zzz > $testroot/repo/zzz
810 (cd $testroot/repo && git add numbers zzz)
811 git_commit $testroot/repo -m "added files"
812 local commit_id=`git_show_head $testroot/repo`
814 got checkout $testroot/repo $testroot/wt > /dev/null
816 if [ "$ret" != "0" ]; then
817 test_done "$testroot" "$ret"
821 sed -i -e 's/^2$/a/' $testroot/wt/numbers
822 sed -i -e 's/^7$/b/' $testroot/wt/numbers
823 sed -i -e 's/^16$/c/' $testroot/wt/numbers
824 (cd $testroot/wt && got rm zzz > /dev/null)
825 (cd $testroot/wt && got stage > /dev/null)
827 # unstage first hunk and quit; and don't pass a path argument to
828 # ensure that we don't skip asking about the 'zzz' file after 'quit'
829 printf "y\nq\nn\n" > $testroot/patchscript
830 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
833 if [ "$ret" != "0" ]; then
834 echo "got unstage command failed unexpectedly" >&2
835 test_done "$testroot" "1"
838 cat > $testroot/stdout.expected <<EOF
839 -----------------------------------------------
847 -----------------------------------------------
848 M numbers (change 1 of 3)
849 unstage this change? [y/n/q] y
850 -----------------------------------------------
860 -----------------------------------------------
861 M numbers (change 2 of 3)
862 unstage this change? [y/n/q] q
865 unstage this deletion? [y/n] n
867 cmp -s $testroot/stdout.expected $testroot/stdout
869 if [ "$ret" != "0" ]; then
870 diff -u $testroot/stdout.expected $testroot/stdout
871 test_done "$testroot" "$ret"
875 (cd $testroot/wt && got status > $testroot/stdout)
876 echo "MM numbers" > $testroot/stdout.expected
877 echo " D zzz" >> $testroot/stdout.expected
878 cmp -s $testroot/stdout.expected $testroot/stdout
880 if [ "$ret" != "0" ]; then
881 diff -u $testroot/stdout.expected $testroot/stdout
882 test_done "$testroot" "$ret"
886 (cd $testroot/wt && got diff > $testroot/stdout)
888 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
889 echo -n 'blob - ' >> $testroot/stdout.expected
890 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
891 tr -d '\n' >> $testroot/stdout.expected
892 echo " (staged)" >> $testroot/stdout.expected
893 echo "file + numbers" >> $testroot/stdout.expected
894 echo "--- numbers" >> $testroot/stdout.expected
895 echo "+++ numbers" >> $testroot/stdout.expected
896 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
897 echo " 1" >> $testroot/stdout.expected
898 echo "-2" >> $testroot/stdout.expected
899 echo "+a" >> $testroot/stdout.expected
900 echo " 3" >> $testroot/stdout.expected
901 echo " 4" >> $testroot/stdout.expected
902 echo " 5" >> $testroot/stdout.expected
903 cmp -s $testroot/stdout.expected $testroot/stdout
905 if [ "$ret" != "0" ]; then
906 diff -u $testroot/stdout.expected $testroot/stdout
907 test_done "$testroot" "$ret"
911 (cd $testroot/wt && got diff -s > $testroot/stdout)
912 echo "diff $commit_id $testroot/wt (staged changes)" \
913 > $testroot/stdout.expected
914 echo -n 'blob - ' >> $testroot/stdout.expected
915 got tree -r $testroot/repo -i -c $commit_id \
916 | grep 'numbers$' | cut -d' ' -f 1 \
917 >> $testroot/stdout.expected
918 echo -n 'blob + ' >> $testroot/stdout.expected
919 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
920 >> $testroot/stdout.expected
921 cat >> $testroot/stdout.expected <<EOF
940 echo -n 'blob - ' >> $testroot/stdout.expected
941 got tree -r $testroot/repo -i | grep 'zzz$' | cut -d' ' -f 1 \
942 >> $testroot/stdout.expected
943 echo 'blob + /dev/null' >> $testroot/stdout.expected
944 echo "--- zzz" >> $testroot/stdout.expected
945 echo "+++ /dev/null" >> $testroot/stdout.expected
946 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
947 echo "-zzz" >> $testroot/stdout.expected
948 cmp -s $testroot/stdout.expected $testroot/stdout
950 if [ "$ret" != "0" ]; then
951 diff -u $testroot/stdout.expected $testroot/stdout
953 test_done "$testroot" "$ret"
956 run_test test_unstage_basic
957 run_test test_unstage_unversioned
958 run_test test_unstage_nonexistent
959 run_test test_unstage_patch
960 run_test test_unstage_patch_added
961 run_test test_unstage_patch_removed
962 run_test test_unstage_patch_quit