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_unstage_basic {
20 local testroot=`test_init unstage_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 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)
40 ret="$?"
41 if [ "$ret" != "0" ]; then
42 echo "got stage command succeeded unexpectedly" >&2
43 test_done "$testroot" "1"
44 return 1
45 fi
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
51 ret="$?"
52 if [ "$ret" != "0" ]; then
53 diff -u $testroot/stdout.expected $testroot/stdout
54 test_done "$testroot" "$ret"
55 return 1
56 fi
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
63 ret="$?"
64 if [ "$ret" != "0" ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 fi
67 test_done "$testroot" "$ret"
68 }
70 function test_unstage_patch {
71 local testroot=`test_init unstage_patch`
73 jot 16 > $testroot/repo/numbers
74 (cd $testroot/repo && git add numbers)
75 git_commit $testroot/repo -m "added numbers file"
76 local commit_id=`git_show_head $testroot/repo`
78 got checkout $testroot/repo $testroot/wt > /dev/null
79 ret="$?"
80 if [ "$ret" != "0" ]; then
81 test_done "$testroot" "$ret"
82 return 1
83 fi
85 sed -i -e 's/^2$/a/' $testroot/wt/numbers
86 sed -i -e 's/^7$/b/' $testroot/wt/numbers
87 sed -i -e 's/^16$/c/' $testroot/wt/numbers
89 (cd $testroot/wt && got stage > /dev/null)
90 ret="$?"
91 if [ "$ret" != "0" ]; then
92 echo "got stage command failed unexpectedly" >&2
93 test_done "$testroot" "1"
94 return 1
95 fi
97 # don't unstage any hunks
98 printf "n\nn\nn\n" > $testroot/patchscript
99 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
100 numbers > $testroot/stdout)
101 ret="$?"
102 if [ "$ret" != "0" ]; then
103 echo "got stage command failed unexpectedly" >&2
104 test_done "$testroot" "1"
105 return 1
106 fi
107 cat > $testroot/stdout.expected <<EOF
108 -----------------------------------------------
109 @@ -1,5 +1,5 @@
111 -2
112 +a
116 -----------------------------------------------
117 M numbers (change 1 of 3)
118 unstage this change? [y/n/q] n
119 -----------------------------------------------
120 @@ -4,7 +4,7 @@
124 -7
125 +b
128 10
129 -----------------------------------------------
130 M numbers (change 2 of 3)
131 unstage this change? [y/n/q] n
132 -----------------------------------------------
133 @@ -13,4 +13,4 @@
134 13
135 14
136 15
137 -16
138 +c
139 -----------------------------------------------
140 M numbers (change 3 of 3)
141 unstage this change? [y/n/q] n
142 EOF
143 cmp -s $testroot/stdout.expected $testroot/stdout
144 ret="$?"
145 if [ "$ret" != "0" ]; then
146 diff -u $testroot/stdout.expected $testroot/stdout
147 test_done "$testroot" "$ret"
148 return 1
149 fi
151 (cd $testroot/wt && got status > $testroot/stdout)
152 echo " M numbers" > $testroot/stdout.expected
153 cmp -s $testroot/stdout.expected $testroot/stdout
154 ret="$?"
155 if [ "$ret" != "0" ]; then
156 diff -u $testroot/stdout.expected $testroot/stdout
157 test_done "$testroot" "$ret"
158 return 1
159 fi
161 # unstage middle hunk
162 printf "n\ny\nn\n" > $testroot/patchscript
163 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
164 numbers > $testroot/stdout)
166 cat > $testroot/stdout.expected <<EOF
167 -----------------------------------------------
168 @@ -1,5 +1,5 @@
170 -2
171 +a
175 -----------------------------------------------
176 M numbers (change 1 of 3)
177 unstage this change? [y/n/q] n
178 -----------------------------------------------
179 @@ -4,7 +4,7 @@
183 -7
184 +b
187 10
188 -----------------------------------------------
189 M numbers (change 2 of 3)
190 unstage this change? [y/n/q] y
191 -----------------------------------------------
192 @@ -13,4 +13,4 @@
193 13
194 14
195 15
196 -16
197 +c
198 -----------------------------------------------
199 M numbers (change 3 of 3)
200 unstage this change? [y/n/q] n
201 G numbers
202 EOF
203 cmp -s $testroot/stdout.expected $testroot/stdout
204 ret="$?"
205 if [ "$ret" != "0" ]; then
206 diff -u $testroot/stdout.expected $testroot/stdout
207 test_done "$testroot" "$ret"
208 return 1
209 fi
211 (cd $testroot/wt && got status > $testroot/stdout)
212 echo "MM numbers" > $testroot/stdout.expected
213 cmp -s $testroot/stdout.expected $testroot/stdout
214 ret="$?"
215 if [ "$ret" != "0" ]; then
216 diff -u $testroot/stdout.expected $testroot/stdout
217 test_done "$testroot" "$ret"
218 return 1
219 fi
221 (cd $testroot/wt && got diff -s > $testroot/stdout)
223 echo "diff $commit_id $testroot/wt (staged changes)" \
224 > $testroot/stdout.expected
225 echo -n 'blob - ' >> $testroot/stdout.expected
226 got tree -r $testroot/repo -i -c $commit_id \
227 | grep 'numbers$' | cut -d' ' -f 1 \
228 >> $testroot/stdout.expected
229 echo -n 'blob + ' >> $testroot/stdout.expected
230 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
231 >> $testroot/stdout.expected
232 cat >> $testroot/stdout.expected <<EOF
233 --- numbers
234 +++ numbers
235 @@ -1,5 +1,5 @@
237 -2
238 +a
242 @@ -13,4 +13,4 @@
243 13
244 14
245 15
246 -16
247 +c
248 EOF
249 cmp -s $testroot/stdout.expected $testroot/stdout
250 ret="$?"
251 if [ "$ret" != "0" ]; then
252 diff -u $testroot/stdout.expected $testroot/stdout
253 test_done "$testroot" "$ret"
254 return 1
255 fi
257 (cd $testroot/wt && got diff > $testroot/stdout)
258 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
259 echo -n 'blob - ' >> $testroot/stdout.expected
260 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
261 >> $testroot/stdout.expected
262 echo "file + numbers" >> $testroot/stdout.expected
263 cat >> $testroot/stdout.expected <<EOF
264 --- numbers
265 +++ numbers
266 @@ -4,7 +4,7 @@ a
270 -7
271 +b
274 10
275 EOF
276 cmp -s $testroot/stdout.expected $testroot/stdout
277 ret="$?"
278 if [ "$ret" != "0" ]; then
279 diff -u $testroot/stdout.expected $testroot/stdout
280 test_done "$testroot" "$ret"
281 return 1
282 fi
284 (cd $testroot/wt && got stage >/dev/null)
285 ret="$?"
286 if [ "$ret" != "0" ]; then
287 echo "got stage command failed unexpectedly" >&2
288 test_done "$testroot" "1"
289 return 1
290 fi
292 (cd $testroot/wt && got status > $testroot/stdout)
293 echo " M numbers" > $testroot/stdout.expected
294 cmp -s $testroot/stdout.expected $testroot/stdout
295 ret="$?"
296 if [ "$ret" != "0" ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 # unstage last hunk
303 printf "n\nn\ny\n" > $testroot/patchscript
304 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
305 numbers > $testroot/stdout)
307 cat > $testroot/stdout.expected <<EOF
308 -----------------------------------------------
309 @@ -1,5 +1,5 @@
311 -2
312 +a
316 -----------------------------------------------
317 M numbers (change 1 of 3)
318 unstage this change? [y/n/q] n
319 -----------------------------------------------
320 @@ -4,7 +4,7 @@
324 -7
325 +b
328 10
329 -----------------------------------------------
330 M numbers (change 2 of 3)
331 unstage this change? [y/n/q] n
332 -----------------------------------------------
333 @@ -13,4 +13,4 @@
334 13
335 14
336 15
337 -16
338 +c
339 -----------------------------------------------
340 M numbers (change 3 of 3)
341 unstage this change? [y/n/q] y
342 G numbers
343 EOF
344 cmp -s $testroot/stdout.expected $testroot/stdout
345 ret="$?"
346 if [ "$ret" != "0" ]; then
347 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$ret"
349 return 1
350 fi
352 (cd $testroot/wt && got status > $testroot/stdout)
353 echo "MM numbers" > $testroot/stdout.expected
354 cmp -s $testroot/stdout.expected $testroot/stdout
355 ret="$?"
356 if [ "$ret" != "0" ]; then
357 diff -u $testroot/stdout.expected $testroot/stdout
358 test_done "$testroot" "$ret"
359 return 1
360 fi
362 (cd $testroot/wt && got diff -s > $testroot/stdout)
364 echo "diff $commit_id $testroot/wt (staged changes)" \
365 > $testroot/stdout.expected
366 echo -n 'blob - ' >> $testroot/stdout.expected
367 got tree -r $testroot/repo -i -c $commit_id \
368 | grep 'numbers$' | cut -d' ' -f 1 \
369 >> $testroot/stdout.expected
370 echo -n 'blob + ' >> $testroot/stdout.expected
371 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
372 >> $testroot/stdout.expected
373 cat >> $testroot/stdout.expected <<EOF
374 --- numbers
375 +++ numbers
376 @@ -1,10 +1,10 @@
378 -2
379 +a
384 -7
385 +b
388 10
389 EOF
390 cmp -s $testroot/stdout.expected $testroot/stdout
391 ret="$?"
392 if [ "$ret" != "0" ]; then
393 diff -u $testroot/stdout.expected $testroot/stdout
394 test_done "$testroot" "$ret"
395 return 1
396 fi
398 (cd $testroot/wt && got diff > $testroot/stdout)
399 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
400 echo -n 'blob - ' >> $testroot/stdout.expected
401 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
402 >> $testroot/stdout.expected
403 echo "file + numbers" >> $testroot/stdout.expected
404 cat >> $testroot/stdout.expected <<EOF
405 --- numbers
406 +++ numbers
407 @@ -13,4 +13,4 @@ b
408 13
409 14
410 15
411 -16
412 +c
413 EOF
414 cmp -s $testroot/stdout.expected $testroot/stdout
415 ret="$?"
416 if [ "$ret" != "0" ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
418 test_done "$testroot" "$ret"
419 return 1
420 fi
422 (cd $testroot/wt && got stage >/dev/null)
423 ret="$?"
424 if [ "$ret" != "0" ]; then
425 echo "got stage command failed unexpectedly" >&2
426 test_done "$testroot" "1"
427 return 1
428 fi
430 (cd $testroot/wt && got status > $testroot/stdout)
431 echo " M numbers" > $testroot/stdout.expected
432 cmp -s $testroot/stdout.expected $testroot/stdout
433 ret="$?"
434 if [ "$ret" != "0" ]; then
435 diff -u $testroot/stdout.expected $testroot/stdout
436 test_done "$testroot" "$ret"
437 return 1
438 fi
440 # unstage all hunks
441 printf "y\ny\ny\n" > $testroot/patchscript
442 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
443 numbers > $testroot/stdout)
445 cat > $testroot/stdout.expected <<EOF
446 -----------------------------------------------
447 @@ -1,5 +1,5 @@
449 -2
450 +a
454 -----------------------------------------------
455 M numbers (change 1 of 3)
456 unstage this change? [y/n/q] y
457 -----------------------------------------------
458 @@ -4,7 +4,7 @@
462 -7
463 +b
466 10
467 -----------------------------------------------
468 M numbers (change 2 of 3)
469 unstage this change? [y/n/q] y
470 -----------------------------------------------
471 @@ -13,4 +13,4 @@
472 13
473 14
474 15
475 -16
476 +c
477 -----------------------------------------------
478 M numbers (change 3 of 3)
479 unstage this change? [y/n/q] y
480 G numbers
481 EOF
482 cmp -s $testroot/stdout.expected $testroot/stdout
483 ret="$?"
484 if [ "$ret" != "0" ]; then
485 diff -u $testroot/stdout.expected $testroot/stdout
486 test_done "$testroot" "$ret"
487 return 1
488 fi
490 (cd $testroot/wt && got status > $testroot/stdout)
491 echo "M numbers" > $testroot/stdout.expected
492 cmp -s $testroot/stdout.expected $testroot/stdout
493 ret="$?"
494 if [ "$ret" != "0" ]; then
495 diff -u $testroot/stdout.expected $testroot/stdout
496 test_done "$testroot" "$ret"
497 return 1
498 fi
500 (cd $testroot/wt && got diff -s > $testroot/stdout)
501 echo -n > $testroot/stdout.expected
502 cmp -s $testroot/stdout.expected $testroot/stdout
503 ret="$?"
504 if [ "$ret" != "0" ]; then
505 diff -u $testroot/stdout.expected $testroot/stdout
506 test_done "$testroot" "$ret"
507 return 1
508 fi
510 (cd $testroot/wt && got diff > $testroot/stdout)
512 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
513 echo -n 'blob - ' >> $testroot/stdout.expected
514 got tree -r $testroot/repo -i -c $commit_id \
515 | grep 'numbers$' | cut -d' ' -f 1 \
516 >> $testroot/stdout.expected
517 echo 'file + numbers' >> $testroot/stdout.expected
518 cat >> $testroot/stdout.expected <<EOF
519 --- numbers
520 +++ numbers
521 @@ -1,10 +1,10 @@
523 -2
524 +a
529 -7
530 +b
533 10
534 @@ -13,4 +13,4 @@
535 13
536 14
537 15
538 -16
539 +c
540 EOF
541 cmp -s $testroot/stdout.expected $testroot/stdout
542 ret="$?"
543 if [ "$ret" != "0" ]; then
544 diff -u $testroot/stdout.expected $testroot/stdout
545 fi
546 test_done "$testroot" "$ret"
550 function test_unstage_patch_added {
551 local testroot=`test_init unstage_patch_added`
552 local commit_id=`git_show_head $testroot/repo`
554 got checkout $testroot/repo $testroot/wt > /dev/null
555 ret="$?"
556 if [ "$ret" != "0" ]; then
557 test_done "$testroot" "$ret"
558 return 1
559 fi
561 echo "new" > $testroot/wt/epsilon/new
562 (cd $testroot/wt && got add epsilon/new > /dev/null)
564 (cd $testroot/wt && got stage > /dev/null)
566 printf "y\n" > $testroot/patchscript
567 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
568 epsilon/new > $testroot/stdout)
570 echo "A epsilon/new" > $testroot/stdout.expected
571 echo "unstage this addition? [y/n] y" >> $testroot/stdout.expected
572 echo "G epsilon/new" >> $testroot/stdout.expected
573 cmp -s $testroot/stdout.expected $testroot/stdout
574 ret="$?"
575 if [ "$ret" != "0" ]; then
576 diff -u $testroot/stdout.expected $testroot/stdout
577 test_done "$testroot" "$ret"
578 return 1
579 fi
581 (cd $testroot/wt && got status > $testroot/stdout)
582 echo "A epsilon/new" > $testroot/stdout.expected
583 cmp -s $testroot/stdout.expected $testroot/stdout
584 ret="$?"
585 if [ "$ret" != "0" ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 test_done "$testroot" "$ret"
588 return 1
589 fi
591 (cd $testroot/wt && got diff -s > $testroot/stdout)
592 echo -n > $testroot/stdout.expected
593 cmp -s $testroot/stdout.expected $testroot/stdout
594 ret="$?"
595 if [ "$ret" != "0" ]; then
596 diff -u $testroot/stdout.expected $testroot/stdout
597 test_done "$testroot" "$ret"
598 return 1
599 fi
601 (cd $testroot/wt && got diff > $testroot/stdout)
603 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
604 echo 'blob - /dev/null' >> $testroot/stdout.expected
605 echo 'file + epsilon/new' >> $testroot/stdout.expected
606 echo "--- epsilon/new" >> $testroot/stdout.expected
607 echo "+++ epsilon/new" >> $testroot/stdout.expected
608 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
609 echo "+new" >> $testroot/stdout.expected
610 cmp -s $testroot/stdout.expected $testroot/stdout
611 ret="$?"
612 if [ "$ret" != "0" ]; then
613 diff -u $testroot/stdout.expected $testroot/stdout
614 fi
615 test_done "$testroot" "$ret"
618 function test_unstage_patch_removed {
619 local testroot=`test_init unstage_patch_removed`
620 local commit_id=`git_show_head $testroot/repo`
622 got checkout $testroot/repo $testroot/wt > /dev/null
623 ret="$?"
624 if [ "$ret" != "0" ]; then
625 test_done "$testroot" "$ret"
626 return 1
627 fi
629 (cd $testroot/wt && got rm beta > /dev/null)
630 (cd $testroot/wt && got stage > /dev/null)
632 printf "y\n" > $testroot/patchscript
633 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
634 beta > $testroot/stdout)
636 echo "D beta" > $testroot/stdout.expected
637 echo "unstage this deletion? [y/n] y" >> $testroot/stdout.expected
638 echo "D beta" >> $testroot/stdout.expected
639 cmp -s $testroot/stdout.expected $testroot/stdout
640 ret="$?"
641 if [ "$ret" != "0" ]; then
642 diff -u $testroot/stdout.expected $testroot/stdout
643 test_done "$testroot" "$ret"
644 return 1
645 fi
647 (cd $testroot/wt && got status > $testroot/stdout)
648 echo "D beta" > $testroot/stdout.expected
649 cmp -s $testroot/stdout.expected $testroot/stdout
650 ret="$?"
651 if [ "$ret" != "0" ]; then
652 diff -u $testroot/stdout.expected $testroot/stdout
653 test_done "$testroot" "$ret"
654 return 1
655 fi
657 (cd $testroot/wt && got diff -s > $testroot/stdout)
658 echo -n > $testroot/stdout.expected
659 cmp -s $testroot/stdout.expected $testroot/stdout
660 ret="$?"
661 if [ "$ret" != "0" ]; then
662 diff -u $testroot/stdout.expected $testroot/stdout
663 test_done "$testroot" "$ret"
664 return 1
665 fi
667 (cd $testroot/wt && got diff > $testroot/stdout)
669 echo "diff $commit_id $testroot/wt" \
670 > $testroot/stdout.expected
671 echo -n 'blob - ' >> $testroot/stdout.expected
672 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
673 >> $testroot/stdout.expected
674 echo 'file + /dev/null' >> $testroot/stdout.expected
675 echo "--- beta" >> $testroot/stdout.expected
676 echo "+++ beta" >> $testroot/stdout.expected
677 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
678 echo "-beta" >> $testroot/stdout.expected
679 cmp -s $testroot/stdout.expected $testroot/stdout
680 ret="$?"
681 if [ "$ret" != "0" ]; then
682 diff -u $testroot/stdout.expected $testroot/stdout
683 fi
684 test_done "$testroot" "$ret"
687 function test_unstage_patch_quit {
688 local testroot=`test_init unstage_patch_quit`
690 jot 16 > $testroot/repo/numbers
691 echo zzz > $testroot/repo/zzz
692 (cd $testroot/repo && git add numbers zzz)
693 git_commit $testroot/repo -m "added files"
694 local commit_id=`git_show_head $testroot/repo`
696 got checkout $testroot/repo $testroot/wt > /dev/null
697 ret="$?"
698 if [ "$ret" != "0" ]; then
699 test_done "$testroot" "$ret"
700 return 1
701 fi
703 sed -i -e 's/^2$/a/' $testroot/wt/numbers
704 sed -i -e 's/^7$/b/' $testroot/wt/numbers
705 sed -i -e 's/^16$/c/' $testroot/wt/numbers
706 (cd $testroot/wt && got rm zzz > /dev/null)
707 (cd $testroot/wt && got stage > /dev/null)
709 # unstage first hunk and quit; and don't pass a path argument to
710 # ensure that we don't skip asking about the 'zzz' file after 'quit'
711 printf "y\nq\nn\n" > $testroot/patchscript
712 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
713 > $testroot/stdout)
714 ret="$?"
715 if [ "$ret" != "0" ]; then
716 echo "got stage command failed unexpectedly" >&2
717 test_done "$testroot" "1"
718 return 1
719 fi
720 cat > $testroot/stdout.expected <<EOF
721 -----------------------------------------------
722 @@ -1,5 +1,5 @@
724 -2
725 +a
729 -----------------------------------------------
730 M numbers (change 1 of 3)
731 unstage this change? [y/n/q] y
732 -----------------------------------------------
733 @@ -4,7 +4,7 @@
737 -7
738 +b
741 10
742 -----------------------------------------------
743 M numbers (change 2 of 3)
744 unstage this change? [y/n/q] q
745 G numbers
746 D zzz
747 unstage this deletion? [y/n] n
748 EOF
749 cmp -s $testroot/stdout.expected $testroot/stdout
750 ret="$?"
751 if [ "$ret" != "0" ]; then
752 diff -u $testroot/stdout.expected $testroot/stdout
753 test_done "$testroot" "$ret"
754 return 1
755 fi
757 (cd $testroot/wt && got status > $testroot/stdout)
758 echo "MM numbers" > $testroot/stdout.expected
759 echo " D zzz" >> $testroot/stdout.expected
760 cmp -s $testroot/stdout.expected $testroot/stdout
761 ret="$?"
762 if [ "$ret" != "0" ]; then
763 diff -u $testroot/stdout.expected $testroot/stdout
764 test_done "$testroot" "$ret"
765 return 1
766 fi
768 (cd $testroot/wt && got diff > $testroot/stdout)
770 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
771 echo -n 'blob - ' >> $testroot/stdout.expected
772 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
773 >> $testroot/stdout.expected
774 echo "file + numbers" >> $testroot/stdout.expected
775 echo "--- numbers" >> $testroot/stdout.expected
776 echo "+++ numbers" >> $testroot/stdout.expected
777 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
778 echo " 1" >> $testroot/stdout.expected
779 echo "-2" >> $testroot/stdout.expected
780 echo "+a" >> $testroot/stdout.expected
781 echo " 3" >> $testroot/stdout.expected
782 echo " 4" >> $testroot/stdout.expected
783 echo " 5" >> $testroot/stdout.expected
784 cmp -s $testroot/stdout.expected $testroot/stdout
785 ret="$?"
786 if [ "$ret" != "0" ]; then
787 diff -u $testroot/stdout.expected $testroot/stdout
788 test_done "$testroot" "$ret"
789 return 1
790 fi
792 (cd $testroot/wt && got diff -s > $testroot/stdout)
793 echo "diff $commit_id $testroot/wt (staged changes)" \
794 > $testroot/stdout.expected
795 echo -n 'blob - ' >> $testroot/stdout.expected
796 got tree -r $testroot/repo -i -c $commit_id \
797 | grep 'numbers$' | cut -d' ' -f 1 \
798 >> $testroot/stdout.expected
799 echo -n 'blob + ' >> $testroot/stdout.expected
800 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
801 >> $testroot/stdout.expected
802 cat >> $testroot/stdout.expected <<EOF
803 --- numbers
804 +++ numbers
805 @@ -4,7 +4,7 @@
809 -7
810 +b
813 10
814 @@ -13,4 +13,4 @@
815 13
816 14
817 15
818 -16
819 +c
820 EOF
821 echo -n 'blob - ' >> $testroot/stdout.expected
822 got tree -r $testroot/repo -i | grep 'zzz$' | cut -d' ' -f 1 \
823 >> $testroot/stdout.expected
824 echo 'blob + /dev/null' >> $testroot/stdout.expected
825 echo "--- zzz" >> $testroot/stdout.expected
826 echo "+++ /dev/null" >> $testroot/stdout.expected
827 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
828 echo "-zzz" >> $testroot/stdout.expected
829 cmp -s $testroot/stdout.expected $testroot/stdout
830 ret="$?"
831 if [ "$ret" != "0" ]; then
832 diff -u $testroot/stdout.expected $testroot/stdout
833 fi
834 test_done "$testroot" "$ret"
837 run_test test_unstage_basic
838 run_test test_unstage_patch
839 run_test test_unstage_patch_added
840 run_test test_unstage_patch_removed
841 run_test test_unstage_patch_quit