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_unversioned {
71 local testroot=`test_init unstage_unversioned`
73 got checkout $testroot/repo $testroot/wt > /dev/null
74 ret="$?"
75 if [ "$ret" != "0" ]; then
76 test_done "$testroot" "$ret"
77 return 1
78 fi
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
98 ret="$?"
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 test_done "$testroot" "$ret"
102 return 1
103 fi
105 (cd $testroot/wt && got unstage > $testroot/stdout)
106 ret="$?"
107 if [ "$ret" != "0" ]; then
108 echo "got unstage command failed unexpectedly" >&2
109 test_done "$testroot" "1"
110 return 1
111 fi
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
117 ret="$?"
118 if [ "$ret" != "0" ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
121 return 1
122 fi
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)
128 ret="$?"
129 if [ "$ret" != "0" ]; then
130 echo "got unstage command failed unexpectedly" >&2
131 test_done "$testroot" "$ret"
132 return 1
133 fi
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
141 ret="$?"
142 if [ "$ret" != "0" ]; then
143 diff -u $testroot/stdout.expected $testroot/stdout
144 fi
145 test_done "$testroot" "$ret"
148 function test_unstage_patch {
149 local testroot=`test_init unstage_patch`
151 jot 16 > $testroot/repo/numbers
152 (cd $testroot/repo && git add numbers)
153 git_commit $testroot/repo -m "added numbers file"
154 local commit_id=`git_show_head $testroot/repo`
156 got checkout $testroot/repo $testroot/wt > /dev/null
157 ret="$?"
158 if [ "$ret" != "0" ]; then
159 test_done "$testroot" "$ret"
160 return 1
161 fi
163 sed -i -e 's/^2$/a/' $testroot/wt/numbers
164 sed -i -e 's/^7$/b/' $testroot/wt/numbers
165 sed -i -e 's/^16$/c/' $testroot/wt/numbers
167 (cd $testroot/wt && got stage > /dev/null)
168 ret="$?"
169 if [ "$ret" != "0" ]; then
170 echo "got stage command failed unexpectedly" >&2
171 test_done "$testroot" "1"
172 return 1
173 fi
175 # don't unstage any hunks
176 printf "n\nn\nn\n" > $testroot/patchscript
177 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
178 numbers > $testroot/stdout)
179 ret="$?"
180 if [ "$ret" != "0" ]; then
181 echo "got stage command failed unexpectedly" >&2
182 test_done "$testroot" "1"
183 return 1
184 fi
185 cat > $testroot/stdout.expected <<EOF
186 -----------------------------------------------
187 @@ -1,5 +1,5 @@
189 -2
190 +a
194 -----------------------------------------------
195 M numbers (change 1 of 3)
196 unstage this change? [y/n/q] n
197 -----------------------------------------------
198 @@ -4,7 +4,7 @@
202 -7
203 +b
206 10
207 -----------------------------------------------
208 M numbers (change 2 of 3)
209 unstage this change? [y/n/q] n
210 -----------------------------------------------
211 @@ -13,4 +13,4 @@
212 13
213 14
214 15
215 -16
216 +c
217 -----------------------------------------------
218 M numbers (change 3 of 3)
219 unstage this change? [y/n/q] n
220 EOF
221 cmp -s $testroot/stdout.expected $testroot/stdout
222 ret="$?"
223 if [ "$ret" != "0" ]; then
224 diff -u $testroot/stdout.expected $testroot/stdout
225 test_done "$testroot" "$ret"
226 return 1
227 fi
229 (cd $testroot/wt && got status > $testroot/stdout)
230 echo " M numbers" > $testroot/stdout.expected
231 cmp -s $testroot/stdout.expected $testroot/stdout
232 ret="$?"
233 if [ "$ret" != "0" ]; then
234 diff -u $testroot/stdout.expected $testroot/stdout
235 test_done "$testroot" "$ret"
236 return 1
237 fi
239 # unstage middle hunk
240 printf "n\ny\nn\n" > $testroot/patchscript
241 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
242 numbers > $testroot/stdout)
244 cat > $testroot/stdout.expected <<EOF
245 -----------------------------------------------
246 @@ -1,5 +1,5 @@
248 -2
249 +a
253 -----------------------------------------------
254 M numbers (change 1 of 3)
255 unstage this change? [y/n/q] n
256 -----------------------------------------------
257 @@ -4,7 +4,7 @@
261 -7
262 +b
265 10
266 -----------------------------------------------
267 M numbers (change 2 of 3)
268 unstage this change? [y/n/q] y
269 -----------------------------------------------
270 @@ -13,4 +13,4 @@
271 13
272 14
273 15
274 -16
275 +c
276 -----------------------------------------------
277 M numbers (change 3 of 3)
278 unstage this change? [y/n/q] n
279 G numbers
280 EOF
281 cmp -s $testroot/stdout.expected $testroot/stdout
282 ret="$?"
283 if [ "$ret" != "0" ]; then
284 diff -u $testroot/stdout.expected $testroot/stdout
285 test_done "$testroot" "$ret"
286 return 1
287 fi
289 (cd $testroot/wt && got status > $testroot/stdout)
290 echo "MM numbers" > $testroot/stdout.expected
291 cmp -s $testroot/stdout.expected $testroot/stdout
292 ret="$?"
293 if [ "$ret" != "0" ]; then
294 diff -u $testroot/stdout.expected $testroot/stdout
295 test_done "$testroot" "$ret"
296 return 1
297 fi
299 (cd $testroot/wt && got diff -s > $testroot/stdout)
301 echo "diff $commit_id $testroot/wt (staged changes)" \
302 > $testroot/stdout.expected
303 echo -n 'blob - ' >> $testroot/stdout.expected
304 got tree -r $testroot/repo -i -c $commit_id \
305 | grep 'numbers$' | cut -d' ' -f 1 \
306 >> $testroot/stdout.expected
307 echo -n 'blob + ' >> $testroot/stdout.expected
308 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
309 >> $testroot/stdout.expected
310 cat >> $testroot/stdout.expected <<EOF
311 --- numbers
312 +++ numbers
313 @@ -1,5 +1,5 @@
315 -2
316 +a
320 @@ -13,4 +13,4 @@
321 13
322 14
323 15
324 -16
325 +c
326 EOF
327 cmp -s $testroot/stdout.expected $testroot/stdout
328 ret="$?"
329 if [ "$ret" != "0" ]; then
330 diff -u $testroot/stdout.expected $testroot/stdout
331 test_done "$testroot" "$ret"
332 return 1
333 fi
335 (cd $testroot/wt && got diff > $testroot/stdout)
336 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
337 echo -n 'blob - ' >> $testroot/stdout.expected
338 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
339 tr -d '\n' >> $testroot/stdout.expected
340 echo " (staged)" >> $testroot/stdout.expected
341 echo "file + numbers" >> $testroot/stdout.expected
342 cat >> $testroot/stdout.expected <<EOF
343 --- numbers
344 +++ numbers
345 @@ -4,7 +4,7 @@ a
349 -7
350 +b
353 10
354 EOF
355 cmp -s $testroot/stdout.expected $testroot/stdout
356 ret="$?"
357 if [ "$ret" != "0" ]; then
358 diff -u $testroot/stdout.expected $testroot/stdout
359 test_done "$testroot" "$ret"
360 return 1
361 fi
363 (cd $testroot/wt && got stage >/dev/null)
364 ret="$?"
365 if [ "$ret" != "0" ]; then
366 echo "got stage command failed unexpectedly" >&2
367 test_done "$testroot" "1"
368 return 1
369 fi
371 (cd $testroot/wt && got status > $testroot/stdout)
372 echo " M numbers" > $testroot/stdout.expected
373 cmp -s $testroot/stdout.expected $testroot/stdout
374 ret="$?"
375 if [ "$ret" != "0" ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 test_done "$testroot" "$ret"
378 return 1
379 fi
381 # unstage last hunk
382 printf "n\nn\ny\n" > $testroot/patchscript
383 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
384 numbers > $testroot/stdout)
386 cat > $testroot/stdout.expected <<EOF
387 -----------------------------------------------
388 @@ -1,5 +1,5 @@
390 -2
391 +a
395 -----------------------------------------------
396 M numbers (change 1 of 3)
397 unstage this change? [y/n/q] n
398 -----------------------------------------------
399 @@ -4,7 +4,7 @@
403 -7
404 +b
407 10
408 -----------------------------------------------
409 M numbers (change 2 of 3)
410 unstage this change? [y/n/q] n
411 -----------------------------------------------
412 @@ -13,4 +13,4 @@
413 13
414 14
415 15
416 -16
417 +c
418 -----------------------------------------------
419 M numbers (change 3 of 3)
420 unstage this change? [y/n/q] y
421 G numbers
422 EOF
423 cmp -s $testroot/stdout.expected $testroot/stdout
424 ret="$?"
425 if [ "$ret" != "0" ]; then
426 diff -u $testroot/stdout.expected $testroot/stdout
427 test_done "$testroot" "$ret"
428 return 1
429 fi
431 (cd $testroot/wt && got status > $testroot/stdout)
432 echo "MM numbers" > $testroot/stdout.expected
433 cmp -s $testroot/stdout.expected $testroot/stdout
434 ret="$?"
435 if [ "$ret" != "0" ]; then
436 diff -u $testroot/stdout.expected $testroot/stdout
437 test_done "$testroot" "$ret"
438 return 1
439 fi
441 (cd $testroot/wt && got diff -s > $testroot/stdout)
443 echo "diff $commit_id $testroot/wt (staged changes)" \
444 > $testroot/stdout.expected
445 echo -n 'blob - ' >> $testroot/stdout.expected
446 got tree -r $testroot/repo -i -c $commit_id \
447 | grep 'numbers$' | cut -d' ' -f 1 \
448 >> $testroot/stdout.expected
449 echo -n 'blob + ' >> $testroot/stdout.expected
450 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
451 >> $testroot/stdout.expected
452 cat >> $testroot/stdout.expected <<EOF
453 --- numbers
454 +++ numbers
455 @@ -1,10 +1,10 @@
457 -2
458 +a
463 -7
464 +b
467 10
468 EOF
469 cmp -s $testroot/stdout.expected $testroot/stdout
470 ret="$?"
471 if [ "$ret" != "0" ]; then
472 diff -u $testroot/stdout.expected $testroot/stdout
473 test_done "$testroot" "$ret"
474 return 1
475 fi
477 (cd $testroot/wt && got diff > $testroot/stdout)
478 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
479 echo -n 'blob - ' >> $testroot/stdout.expected
480 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
481 tr -d '\n' >> $testroot/stdout.expected
482 echo " (staged)" >> $testroot/stdout.expected
483 echo "file + numbers" >> $testroot/stdout.expected
484 cat >> $testroot/stdout.expected <<EOF
485 --- numbers
486 +++ numbers
487 @@ -13,4 +13,4 @@ b
488 13
489 14
490 15
491 -16
492 +c
493 EOF
494 cmp -s $testroot/stdout.expected $testroot/stdout
495 ret="$?"
496 if [ "$ret" != "0" ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
498 test_done "$testroot" "$ret"
499 return 1
500 fi
502 (cd $testroot/wt && got stage >/dev/null)
503 ret="$?"
504 if [ "$ret" != "0" ]; then
505 echo "got stage command failed unexpectedly" >&2
506 test_done "$testroot" "1"
507 return 1
508 fi
510 (cd $testroot/wt && got status > $testroot/stdout)
511 echo " M numbers" > $testroot/stdout.expected
512 cmp -s $testroot/stdout.expected $testroot/stdout
513 ret="$?"
514 if [ "$ret" != "0" ]; then
515 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
517 return 1
518 fi
520 # unstage all hunks
521 printf "y\ny\ny\n" > $testroot/patchscript
522 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
523 numbers > $testroot/stdout)
525 cat > $testroot/stdout.expected <<EOF
526 -----------------------------------------------
527 @@ -1,5 +1,5 @@
529 -2
530 +a
534 -----------------------------------------------
535 M numbers (change 1 of 3)
536 unstage this change? [y/n/q] y
537 -----------------------------------------------
538 @@ -4,7 +4,7 @@
542 -7
543 +b
546 10
547 -----------------------------------------------
548 M numbers (change 2 of 3)
549 unstage this change? [y/n/q] y
550 -----------------------------------------------
551 @@ -13,4 +13,4 @@
552 13
553 14
554 15
555 -16
556 +c
557 -----------------------------------------------
558 M numbers (change 3 of 3)
559 unstage this change? [y/n/q] y
560 G numbers
561 EOF
562 cmp -s $testroot/stdout.expected $testroot/stdout
563 ret="$?"
564 if [ "$ret" != "0" ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 (cd $testroot/wt && got status > $testroot/stdout)
571 echo "M numbers" > $testroot/stdout.expected
572 cmp -s $testroot/stdout.expected $testroot/stdout
573 ret="$?"
574 if [ "$ret" != "0" ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 test_done "$testroot" "$ret"
577 return 1
578 fi
580 (cd $testroot/wt && got diff -s > $testroot/stdout)
581 echo -n > $testroot/stdout.expected
582 cmp -s $testroot/stdout.expected $testroot/stdout
583 ret="$?"
584 if [ "$ret" != "0" ]; then
585 diff -u $testroot/stdout.expected $testroot/stdout
586 test_done "$testroot" "$ret"
587 return 1
588 fi
590 (cd $testroot/wt && got diff > $testroot/stdout)
592 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
593 echo -n 'blob - ' >> $testroot/stdout.expected
594 got tree -r $testroot/repo -i -c $commit_id \
595 | grep 'numbers$' | cut -d' ' -f 1 \
596 >> $testroot/stdout.expected
597 echo 'file + numbers' >> $testroot/stdout.expected
598 cat >> $testroot/stdout.expected <<EOF
599 --- numbers
600 +++ numbers
601 @@ -1,10 +1,10 @@
603 -2
604 +a
609 -7
610 +b
613 10
614 @@ -13,4 +13,4 @@
615 13
616 14
617 15
618 -16
619 +c
620 EOF
621 cmp -s $testroot/stdout.expected $testroot/stdout
622 ret="$?"
623 if [ "$ret" != "0" ]; then
624 diff -u $testroot/stdout.expected $testroot/stdout
625 fi
626 test_done "$testroot" "$ret"
630 function test_unstage_patch_added {
631 local testroot=`test_init unstage_patch_added`
632 local commit_id=`git_show_head $testroot/repo`
634 got checkout $testroot/repo $testroot/wt > /dev/null
635 ret="$?"
636 if [ "$ret" != "0" ]; then
637 test_done "$testroot" "$ret"
638 return 1
639 fi
641 echo "new" > $testroot/wt/epsilon/new
642 (cd $testroot/wt && got add epsilon/new > /dev/null)
644 (cd $testroot/wt && got stage > /dev/null)
646 printf "y\n" > $testroot/patchscript
647 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
648 epsilon/new > $testroot/stdout)
650 echo "A epsilon/new" > $testroot/stdout.expected
651 echo "unstage this addition? [y/n] y" >> $testroot/stdout.expected
652 echo "G epsilon/new" >> $testroot/stdout.expected
653 cmp -s $testroot/stdout.expected $testroot/stdout
654 ret="$?"
655 if [ "$ret" != "0" ]; then
656 diff -u $testroot/stdout.expected $testroot/stdout
657 test_done "$testroot" "$ret"
658 return 1
659 fi
661 (cd $testroot/wt && got status > $testroot/stdout)
662 echo "A epsilon/new" > $testroot/stdout.expected
663 cmp -s $testroot/stdout.expected $testroot/stdout
664 ret="$?"
665 if [ "$ret" != "0" ]; then
666 diff -u $testroot/stdout.expected $testroot/stdout
667 test_done "$testroot" "$ret"
668 return 1
669 fi
671 (cd $testroot/wt && got diff -s > $testroot/stdout)
672 echo -n > $testroot/stdout.expected
673 cmp -s $testroot/stdout.expected $testroot/stdout
674 ret="$?"
675 if [ "$ret" != "0" ]; then
676 diff -u $testroot/stdout.expected $testroot/stdout
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 (cd $testroot/wt && got diff > $testroot/stdout)
683 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
684 echo 'blob - /dev/null' >> $testroot/stdout.expected
685 echo 'file + epsilon/new' >> $testroot/stdout.expected
686 echo "--- epsilon/new" >> $testroot/stdout.expected
687 echo "+++ epsilon/new" >> $testroot/stdout.expected
688 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
689 echo "+new" >> $testroot/stdout.expected
690 cmp -s $testroot/stdout.expected $testroot/stdout
691 ret="$?"
692 if [ "$ret" != "0" ]; then
693 diff -u $testroot/stdout.expected $testroot/stdout
694 fi
695 test_done "$testroot" "$ret"
698 function test_unstage_patch_removed {
699 local testroot=`test_init unstage_patch_removed`
700 local commit_id=`git_show_head $testroot/repo`
702 got checkout $testroot/repo $testroot/wt > /dev/null
703 ret="$?"
704 if [ "$ret" != "0" ]; then
705 test_done "$testroot" "$ret"
706 return 1
707 fi
709 (cd $testroot/wt && got rm beta > /dev/null)
710 (cd $testroot/wt && got stage > /dev/null)
712 printf "y\n" > $testroot/patchscript
713 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
714 beta > $testroot/stdout)
716 echo "D beta" > $testroot/stdout.expected
717 echo "unstage this deletion? [y/n] y" >> $testroot/stdout.expected
718 echo "D beta" >> $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
720 ret="$?"
721 if [ "$ret" != "0" ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done "$testroot" "$ret"
724 return 1
725 fi
727 (cd $testroot/wt && got status > $testroot/stdout)
728 echo "D beta" > $testroot/stdout.expected
729 cmp -s $testroot/stdout.expected $testroot/stdout
730 ret="$?"
731 if [ "$ret" != "0" ]; then
732 diff -u $testroot/stdout.expected $testroot/stdout
733 test_done "$testroot" "$ret"
734 return 1
735 fi
737 (cd $testroot/wt && got diff -s > $testroot/stdout)
738 echo -n > $testroot/stdout.expected
739 cmp -s $testroot/stdout.expected $testroot/stdout
740 ret="$?"
741 if [ "$ret" != "0" ]; then
742 diff -u $testroot/stdout.expected $testroot/stdout
743 test_done "$testroot" "$ret"
744 return 1
745 fi
747 (cd $testroot/wt && got diff > $testroot/stdout)
749 echo "diff $commit_id $testroot/wt" \
750 > $testroot/stdout.expected
751 echo -n 'blob - ' >> $testroot/stdout.expected
752 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
753 >> $testroot/stdout.expected
754 echo 'file + /dev/null' >> $testroot/stdout.expected
755 echo "--- beta" >> $testroot/stdout.expected
756 echo "+++ beta" >> $testroot/stdout.expected
757 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
758 echo "-beta" >> $testroot/stdout.expected
759 cmp -s $testroot/stdout.expected $testroot/stdout
760 ret="$?"
761 if [ "$ret" != "0" ]; then
762 diff -u $testroot/stdout.expected $testroot/stdout
763 fi
764 test_done "$testroot" "$ret"
767 function test_unstage_patch_quit {
768 local testroot=`test_init unstage_patch_quit`
770 jot 16 > $testroot/repo/numbers
771 echo zzz > $testroot/repo/zzz
772 (cd $testroot/repo && git add numbers zzz)
773 git_commit $testroot/repo -m "added files"
774 local commit_id=`git_show_head $testroot/repo`
776 got checkout $testroot/repo $testroot/wt > /dev/null
777 ret="$?"
778 if [ "$ret" != "0" ]; then
779 test_done "$testroot" "$ret"
780 return 1
781 fi
783 sed -i -e 's/^2$/a/' $testroot/wt/numbers
784 sed -i -e 's/^7$/b/' $testroot/wt/numbers
785 sed -i -e 's/^16$/c/' $testroot/wt/numbers
786 (cd $testroot/wt && got rm zzz > /dev/null)
787 (cd $testroot/wt && got stage > /dev/null)
789 # unstage first hunk and quit; and don't pass a path argument to
790 # ensure that we don't skip asking about the 'zzz' file after 'quit'
791 printf "y\nq\nn\n" > $testroot/patchscript
792 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
793 > $testroot/stdout)
794 ret="$?"
795 if [ "$ret" != "0" ]; then
796 echo "got stage command failed unexpectedly" >&2
797 test_done "$testroot" "1"
798 return 1
799 fi
800 cat > $testroot/stdout.expected <<EOF
801 -----------------------------------------------
802 @@ -1,5 +1,5 @@
804 -2
805 +a
809 -----------------------------------------------
810 M numbers (change 1 of 3)
811 unstage this change? [y/n/q] y
812 -----------------------------------------------
813 @@ -4,7 +4,7 @@
817 -7
818 +b
821 10
822 -----------------------------------------------
823 M numbers (change 2 of 3)
824 unstage this change? [y/n/q] q
825 G numbers
826 D zzz
827 unstage this deletion? [y/n] n
828 EOF
829 cmp -s $testroot/stdout.expected $testroot/stdout
830 ret="$?"
831 if [ "$ret" != "0" ]; then
832 diff -u $testroot/stdout.expected $testroot/stdout
833 test_done "$testroot" "$ret"
834 return 1
835 fi
837 (cd $testroot/wt && got status > $testroot/stdout)
838 echo "MM numbers" > $testroot/stdout.expected
839 echo " D zzz" >> $testroot/stdout.expected
840 cmp -s $testroot/stdout.expected $testroot/stdout
841 ret="$?"
842 if [ "$ret" != "0" ]; then
843 diff -u $testroot/stdout.expected $testroot/stdout
844 test_done "$testroot" "$ret"
845 return 1
846 fi
848 (cd $testroot/wt && got diff > $testroot/stdout)
850 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
851 echo -n 'blob - ' >> $testroot/stdout.expected
852 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
853 tr -d '\n' >> $testroot/stdout.expected
854 echo " (staged)" >> $testroot/stdout.expected
855 echo "file + numbers" >> $testroot/stdout.expected
856 echo "--- numbers" >> $testroot/stdout.expected
857 echo "+++ numbers" >> $testroot/stdout.expected
858 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
859 echo " 1" >> $testroot/stdout.expected
860 echo "-2" >> $testroot/stdout.expected
861 echo "+a" >> $testroot/stdout.expected
862 echo " 3" >> $testroot/stdout.expected
863 echo " 4" >> $testroot/stdout.expected
864 echo " 5" >> $testroot/stdout.expected
865 cmp -s $testroot/stdout.expected $testroot/stdout
866 ret="$?"
867 if [ "$ret" != "0" ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 (cd $testroot/wt && got diff -s > $testroot/stdout)
874 echo "diff $commit_id $testroot/wt (staged changes)" \
875 > $testroot/stdout.expected
876 echo -n 'blob - ' >> $testroot/stdout.expected
877 got tree -r $testroot/repo -i -c $commit_id \
878 | grep 'numbers$' | cut -d' ' -f 1 \
879 >> $testroot/stdout.expected
880 echo -n 'blob + ' >> $testroot/stdout.expected
881 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
882 >> $testroot/stdout.expected
883 cat >> $testroot/stdout.expected <<EOF
884 --- numbers
885 +++ numbers
886 @@ -4,7 +4,7 @@
890 -7
891 +b
894 10
895 @@ -13,4 +13,4 @@
896 13
897 14
898 15
899 -16
900 +c
901 EOF
902 echo -n 'blob - ' >> $testroot/stdout.expected
903 got tree -r $testroot/repo -i | grep 'zzz$' | cut -d' ' -f 1 \
904 >> $testroot/stdout.expected
905 echo 'blob + /dev/null' >> $testroot/stdout.expected
906 echo "--- zzz" >> $testroot/stdout.expected
907 echo "+++ /dev/null" >> $testroot/stdout.expected
908 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
909 echo "-zzz" >> $testroot/stdout.expected
910 cmp -s $testroot/stdout.expected $testroot/stdout
911 ret="$?"
912 if [ "$ret" != "0" ]; then
913 diff -u $testroot/stdout.expected $testroot/stdout
914 fi
915 test_done "$testroot" "$ret"
918 run_test test_unstage_basic
919 run_test test_unstage_unversioned
920 run_test test_unstage_patch
921 run_test test_unstage_patch_added
922 run_test test_unstage_patch_removed
923 run_test test_unstage_patch_quit