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_stage_basic {
20 local testroot=`test_init stage_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 > $testroot/stdout)
39 cmp -s $testroot/stdout.expected $testroot/stdout
41 if [ "$ret" != "0" ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
44 test_done "$testroot" "$ret"
47 function test_stage_no_changes {
48 local testroot=`test_init stage_no_changes`
50 got checkout $testroot/repo $testroot/wt > /dev/null
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
57 (cd $testroot/wt && got stage alpha beta > $testroot/stdout \
60 if [ "$ret" == "0" ]; then
61 echo "got stage command succeeded unexpectedly" >&2
62 test_done "$testroot" "1"
66 echo "got: no changes to stage" > $testroot/stderr.expected
68 cmp -s $testroot/stderr.expected $testroot/stderr
70 if [ "$ret" != "0" ]; then
71 diff -u $testroot/stderr.expected $testroot/stderr
72 test_done "$testroot" "$ret"
76 echo -n > $testroot/stdout.expected
77 cmp -s $testroot/stdout.expected $testroot/stdout
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
82 test_done "$testroot" "$ret"
85 function test_stage_unversioned {
86 local testroot=`test_init stage_unversioned`
88 got checkout $testroot/repo $testroot/wt > /dev/null
90 if [ "$ret" != "0" ]; then
91 test_done "$testroot" "$ret"
95 echo "modified file" > $testroot/wt/alpha
96 touch $testroot/wt/unversioned-file
98 (cd $testroot/wt && got status > $testroot/stdout)
99 echo "M alpha" > $testroot/stdout.expected
100 echo "? unversioned-file" >> $testroot/stdout.expected
101 cmp -s $testroot/stdout.expected $testroot/stdout
103 if [ "$ret" != "0" ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
109 (cd $testroot/wt && got stage > $testroot/stdout)
111 if [ "$ret" != "0" ]; then
112 echo "got stage command failed unexpectedly" >&2
113 test_done "$testroot" "$ret"
117 echo " M alpha" > $testroot/stdout.expected
118 cmp -s $testroot/stdout.expected $testroot/stdout
120 if [ "$ret" != "0" ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 test_done "$testroot" "$ret"
126 echo "modified file again" > $testroot/wt/alpha
128 (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
131 if [ "$ret" == "0" ]; then
132 echo "got stage command succeed unexpectedly" >&2
133 test_done "$testroot" "1"
137 echo "got: no changes to stage" > $testroot/stderr.expected
138 cmp -s $testroot/stderr.expected $testroot/stderr
140 if [ "$ret" != "0" ]; then
141 diff -u $testroot/stderr.expected $testroot/stderr
143 test_done "$testroot" "$ret"
147 function test_stage_nonexistent {
148 local testroot=`test_init stage_nonexistent`
150 got checkout $testroot/repo $testroot/wt > /dev/null
152 if [ "$ret" != "0" ]; then
153 test_done "$testroot" "$ret"
157 (cd $testroot/wt && got stage nonexistent-file \
158 > $testroot/stdout 2> $testroot/stderr)
159 echo "got: nonexistent-file: No such file or directory" \
160 > $testroot/stderr.expected
161 cmp -s $testroot/stderr.expected $testroot/stderr
163 if [ "$ret" != "0" ]; then
164 diff -u $testroot/stderr.expected $testroot/stderr
166 test_done "$testroot" "$ret"
169 function test_stage_list {
170 local testroot=`test_init stage_list`
172 got checkout $testroot/repo $testroot/wt > /dev/null
174 if [ "$ret" != "0" ]; then
175 test_done "$testroot" "$ret"
179 echo "modified file" > $testroot/wt/alpha
180 (cd $testroot/wt && got rm beta > /dev/null)
181 echo "new file" > $testroot/wt/foo
182 (cd $testroot/wt && got add foo > /dev/null)
184 echo ' M alpha' > $testroot/stdout.expected
185 echo ' D beta' >> $testroot/stdout.expected
186 echo ' A foo' >> $testroot/stdout.expected
187 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
189 (cd $testroot/wt && got stage -l > $testroot/stdout)
190 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
191 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
192 echo " M alpha" >> $testroot/stdout.expected
193 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
194 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
195 echo " D beta" >> $testroot/stdout.expected
196 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
197 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
198 echo " A foo" >> $testroot/stdout.expected
199 cmp -s $testroot/stdout.expected $testroot/stdout
201 if [ "$ret" != "0" ]; then
202 diff -u $testroot/stdout.expected $testroot/stdout
203 test_done "$testroot" "$ret"
207 (cd $testroot/wt && got stage -l epsilon nonexistent \
210 echo -n > $testroot/stdout.expected
211 cmp -s $testroot/stdout.expected $testroot/stdout
213 if [ "$ret" != "0" ]; then
214 diff -u $testroot/stdout.expected $testroot/stdout
215 test_done "$testroot" "$ret"
219 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
221 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
222 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
223 echo " M alpha" >> $testroot/stdout.expected
224 cmp -s $testroot/stdout.expected $testroot/stdout
226 if [ "$ret" != "0" ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
229 test_done "$testroot" "$ret"
233 function test_stage_conflict {
234 local testroot=`test_init stage_conflict`
235 local initial_commit=`git_show_head $testroot/repo`
237 got checkout $testroot/repo $testroot/wt > /dev/null
239 if [ "$ret" != "0" ]; then
240 test_done "$testroot" "$ret"
244 echo "modified alpha" > $testroot/wt/alpha
245 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
247 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
249 echo "modified alpha, too" > $testroot/wt/alpha
251 echo "C alpha" > $testroot/stdout.expected
252 echo -n "Updated to commit " >> $testroot/stdout.expected
253 git_show_head $testroot/repo >> $testroot/stdout.expected
254 echo >> $testroot/stdout.expected
256 (cd $testroot/wt && got update > $testroot/stdout)
258 cmp -s $testroot/stdout.expected $testroot/stdout
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 test_done "$testroot" "$ret"
266 (cd $testroot/wt && got stage alpha > $testroot/stdout \
269 if [ "$ret" == "0" ]; then
270 echo "got stage command succeeded unexpectedly" >&2
271 test_done "$testroot" "1"
275 echo -n > $testroot/stdout.expected
276 echo "got: alpha: cannot stage file in conflicted status" \
277 > $testroot/stderr.expected
279 cmp -s $testroot/stdout.expected $testroot/stdout
281 if [ "$ret" != "0" ]; then
282 diff -u $testroot/stdout.expected $testroot/stdout
283 test_done "$testroot" "$ret"
286 cmp -s $testroot/stderr.expected $testroot/stderr
288 if [ "$ret" != "0" ]; then
289 diff -u $testroot/stderr.expected $testroot/stderr
291 test_done "$testroot" "$ret"
294 function test_stage_out_of_date {
295 local testroot=`test_init stage_out_of_date`
296 local initial_commit=`git_show_head $testroot/repo`
298 got checkout $testroot/repo $testroot/wt > /dev/null
300 if [ "$ret" != "0" ]; then
301 test_done "$testroot" "$ret"
305 echo "modified alpha" > $testroot/wt/alpha
306 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
308 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
310 echo "modified alpha again" > $testroot/wt/alpha
311 (cd $testroot/wt && got stage alpha > $testroot/stdout \
314 if [ "$ret" == "0" ]; then
315 echo "got stage command succeeded unexpectedly" >&2
316 test_done "$testroot" "1"
320 echo -n > $testroot/stdout.expected
321 echo "got: work tree must be updated before changes can be staged" \
322 > $testroot/stderr.expected
324 cmp -s $testroot/stdout.expected $testroot/stdout
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
331 cmp -s $testroot/stderr.expected $testroot/stderr
333 if [ "$ret" != "0" ]; then
334 diff -u $testroot/stderr.expected $testroot/stderr
336 test_done "$testroot" "$ret"
340 function test_double_stage {
341 local testroot=`test_init double_stage`
343 got checkout $testroot/repo $testroot/wt > /dev/null
345 if [ "$ret" != "0" ]; then
346 test_done "$testroot" "$ret"
349 echo "modified file" > $testroot/wt/alpha
350 (cd $testroot/wt && got rm beta > /dev/null)
351 echo "new file" > $testroot/wt/foo
352 (cd $testroot/wt && got add foo > /dev/null)
353 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
355 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
356 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
357 cmp -s $testroot/stderr.expected $testroot/stderr
359 if [ "$ret" != "0" ]; then
360 diff -u $testroot/stderr.expected $testroot/stderr
361 test_done "$testroot" "$ret"
365 (cd $testroot/wt && got stage beta > $testroot/stdout)
367 if [ "$ret" != "0" ]; then
368 echo "got stage command failed unexpectedly" >&2
369 test_done "$testroot" "1"
372 echo -n > $testroot/stdout.expected
373 cmp -s $testroot/stdout.expected $testroot/stdout
375 if [ "$ret" != "0" ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 test_done "$testroot" "$ret"
381 echo "got: foo: no changes to stage" > $testroot/stderr.expected
382 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
383 cmp -s $testroot/stderr.expected $testroot/stderr
385 if [ "$ret" != "0" ]; then
386 diff -u $testroot/stderr.expected $testroot/stderr
387 test_done "$testroot" "$ret"
391 echo "modified file again" > $testroot/wt/alpha
392 echo "modified new file" > $testroot/wt/foo
394 echo ' M alpha' > $testroot/stdout.expected
395 echo ' A foo' >> $testroot/stdout.expected
396 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
397 cmp -s $testroot/stdout.expected $testroot/stdout
399 if [ "$ret" != "0" ]; then
400 diff -u $testroot/stdout.expected $testroot/stdout
401 test_done "$testroot" "$ret"
405 echo ' M alpha' > $testroot/stdout.expected
406 echo ' D beta' >> $testroot/stdout.expected
407 echo ' A foo' >> $testroot/stdout.expected
409 (cd $testroot/wt && got status > $testroot/stdout)
410 cmp -s $testroot/stdout.expected $testroot/stdout
412 if [ "$ret" != "0" ]; then
413 diff -u $testroot/stdout.expected $testroot/stdout
415 test_done "$testroot" "$ret"
418 function test_stage_status {
419 local testroot=`test_init stage_status`
421 got checkout $testroot/repo $testroot/wt > /dev/null
423 if [ "$ret" != "0" ]; then
424 test_done "$testroot" "$ret"
428 echo "modified file" > $testroot/wt/alpha
429 (cd $testroot/wt && got rm beta > /dev/null)
430 echo "new file" > $testroot/wt/foo
431 (cd $testroot/wt && got add foo > /dev/null)
432 echo "new file" > $testroot/wt/epsilon/new
433 (cd $testroot/wt && got add epsilon/new > /dev/null)
434 echo "modified file" > $testroot/wt/epsilon/zeta
435 (cd $testroot/wt && got rm gamma/delta > /dev/null)
437 echo ' M alpha' > $testroot/stdout.expected
438 echo ' D beta' >> $testroot/stdout.expected
439 echo 'A epsilon/new' >> $testroot/stdout.expected
440 echo 'M epsilon/zeta' >> $testroot/stdout.expected
441 echo ' A foo' >> $testroot/stdout.expected
442 echo 'D gamma/delta' >> $testroot/stdout.expected
443 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
445 (cd $testroot/wt && got status > $testroot/stdout)
446 cmp -s $testroot/stdout.expected $testroot/stdout
448 if [ "$ret" != "0" ]; then
449 diff -u $testroot/stdout.expected $testroot/stdout
450 test_done "$testroot" "$ret"
454 echo "modified file again" >> $testroot/wt/alpha
455 echo "modified added file again" >> $testroot/wt/foo
457 echo 'MM alpha' > $testroot/stdout.expected
458 echo ' D beta' >> $testroot/stdout.expected
459 echo 'A epsilon/new' >> $testroot/stdout.expected
460 echo 'M epsilon/zeta' >> $testroot/stdout.expected
461 echo 'MA foo' >> $testroot/stdout.expected
462 echo 'D gamma/delta' >> $testroot/stdout.expected
464 (cd $testroot/wt && got status > $testroot/stdout)
465 cmp -s $testroot/stdout.expected $testroot/stdout
467 if [ "$ret" != "0" ]; then
468 diff -u $testroot/stdout.expected $testroot/stdout
469 test_done "$testroot" "$ret"
473 # test no-op change of added file with new stat(2) timestamp
474 echo "new file" > $testroot/wt/foo
475 echo ' A foo' > $testroot/stdout.expected
476 (cd $testroot/wt && got status foo > $testroot/stdout)
477 cmp -s $testroot/stdout.expected $testroot/stdout
479 if [ "$ret" != "0" ]; then
480 diff -u $testroot/stdout.expected $testroot/stdout
481 test_done "$testroot" "$ret"
485 # test staged deleted file which is restored on disk
486 echo "new file" > $testroot/wt/beta
487 echo ' D beta' > $testroot/stdout.expected
488 (cd $testroot/wt && got status beta > $testroot/stdout)
489 cmp -s $testroot/stdout.expected $testroot/stdout
491 if [ "$ret" != "0" ]; then
492 diff -u $testroot/stdout.expected $testroot/stdout
494 test_done "$testroot" "$ret"
498 function test_stage_add_already_staged_file {
499 local testroot=`test_init stage_add_already_staged_file`
501 got checkout $testroot/repo $testroot/wt > /dev/null
503 if [ "$ret" != "0" ]; then
504 test_done "$testroot" "$ret"
508 echo "modified file" > $testroot/wt/alpha
509 (cd $testroot/wt && got rm beta > /dev/null)
510 echo "new file" > $testroot/wt/foo
511 (cd $testroot/wt && got add foo > /dev/null)
513 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
515 echo -n > $testroot/stdout.expected
516 for f in alpha beta foo; do
517 (cd $testroot/wt && got add $f \
518 > $testroot/stdout 2> $testroot/stderr)
519 echo "got: $f: file has unexpected status" \
520 > $testroot/stderr.expected
521 cmp -s $testroot/stderr.expected $testroot/stderr
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/stderr.expected $testroot/stderr
525 test_done "$testroot" "$ret"
528 cmp -s $testroot/stdout.expected $testroot/stdout
530 if [ "$ret" != "0" ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done "$testroot" "$ret"
537 echo ' M alpha' > $testroot/stdout.expected
538 echo ' D beta' >> $testroot/stdout.expected
539 echo ' A foo' >> $testroot/stdout.expected
541 (cd $testroot/wt && got status > $testroot/stdout)
542 cmp -s $testroot/stdout.expected $testroot/stdout
544 if [ "$ret" != "0" ]; then
545 diff -u $testroot/stdout.expected $testroot/stdout
547 test_done "$testroot" "$ret"
550 function test_stage_rm_already_staged_file {
551 local testroot=`test_init stage_rm_already_staged_file`
553 got checkout $testroot/repo $testroot/wt > /dev/null
555 if [ "$ret" != "0" ]; then
556 test_done "$testroot" "$ret"
560 echo "modified file" > $testroot/wt/alpha
561 (cd $testroot/wt && got rm beta > /dev/null)
562 echo "new file" > $testroot/wt/foo
563 (cd $testroot/wt && got add foo > /dev/null)
565 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
567 (cd $testroot/wt && got rm beta \
568 > $testroot/stdout 2> $testroot/stderr)
570 if [ "$ret" != "0" ]; then
571 echo "got rm command failed unexpectedly" >&2
572 test_done "$testroot" "1"
575 echo -n > $testroot/stdout.expected
576 cmp -s $testroot/stdout.expected $testroot/stdout
578 if [ "$ret" != "0" ]; then
579 diff -u $testroot/stdout.expected $testroot/stdout
580 test_done "$testroot" "$ret"
583 echo -n > $testroot/stderr.expected
584 cmp -s $testroot/stderr.expected $testroot/stderr
586 if [ "$ret" != "0" ]; then
587 diff -u $testroot/stderr.expected $testroot/stderr
588 test_done "$testroot" "$ret"
592 for f in alpha foo; do
593 echo "got: $f: file is staged" > $testroot/stderr.expected
594 (cd $testroot/wt && got rm $f \
595 > $testroot/stdout 2> $testroot/stderr)
597 if [ "$ret" == "0" ]; then
598 echo "got rm command succeeded unexpectedly" >&2
599 test_done "$testroot" "1"
602 cmp -s $testroot/stderr.expected $testroot/stderr
604 if [ "$ret" != "0" ]; then
605 diff -u $testroot/stderr.expected $testroot/stderr
606 test_done "$testroot" "$ret"
611 echo ' M alpha' > $testroot/stdout.expected
612 echo ' D beta' >> $testroot/stdout.expected
613 echo ' A foo' >> $testroot/stdout.expected
615 (cd $testroot/wt && got status > $testroot/stdout)
616 cmp -s $testroot/stdout.expected $testroot/stdout
618 if [ "$ret" != "0" ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
621 test_done "$testroot" "$ret"
624 function test_stage_revert {
625 local testroot=`test_init stage_revert`
627 got checkout $testroot/repo $testroot/wt > /dev/null
629 if [ "$ret" != "0" ]; then
630 test_done "$testroot" "$ret"
634 echo "modified alpha" > $testroot/wt/alpha
635 (cd $testroot/wt && got rm beta > /dev/null)
636 echo "new file" > $testroot/wt/foo
637 (cd $testroot/wt && got add foo > /dev/null)
638 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
640 echo "modified file again" >> $testroot/wt/alpha
641 echo "modified added file again" >> $testroot/wt/foo
643 (cd $testroot/wt && got revert alpha > $testroot/stdout)
645 if [ "$ret" != "0" ]; then
646 echo "revert command failed unexpectedly" >&2
647 test_done "$testroot" "$ret"
651 echo "R alpha" > $testroot/stdout.expected
652 cmp -s $testroot/stdout.expected $testroot/stdout
654 if [ "$ret" != "0" ]; then
655 diff -u $testroot/stdout.expected $testroot/stdout
656 test_done "$testroot" "$ret"
660 echo "modified alpha" > $testroot/content.expected
661 cat $testroot/wt/alpha > $testroot/content
662 cmp -s $testroot/content.expected $testroot/content
664 if [ "$ret" != "0" ]; then
665 diff -u $testroot/content.expected $testroot/content
666 test_done "$testroot" "$ret"
670 echo ' M alpha' > $testroot/stdout.expected
671 echo ' D beta' >> $testroot/stdout.expected
672 echo 'MA foo' >> $testroot/stdout.expected
673 (cd $testroot/wt && got status > $testroot/stdout)
674 cmp -s $testroot/stdout.expected $testroot/stdout
676 if [ "$ret" != "0" ]; then
677 diff -u $testroot/stdout.expected $testroot/stdout
678 test_done "$testroot" "$ret"
682 (cd $testroot/wt && got revert alpha > $testroot/stdout)
684 if [ "$ret" != "0" ]; then
685 echo "revert command failed unexpectedly" >&2
686 test_done "$testroot" "$ret"
690 echo -n > $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 echo "modified alpha" > $testroot/content.expected
700 cat $testroot/wt/alpha > $testroot/content
701 cmp -s $testroot/content.expected $testroot/content
703 if [ "$ret" != "0" ]; then
704 diff -u $testroot/content.expected $testroot/content
705 test_done "$testroot" "$ret"
709 (cd $testroot/wt && got revert beta > $testroot/stdout \
712 if [ "$ret" != "0" ]; then
713 echo "revert command failed unexpectedly" >&2
714 test_done "$testroot" "$ret"
718 echo -n > $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
721 if [ "$ret" != "0" ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done "$testroot" "$ret"
727 echo -n > $testroot/stderr.expected
728 cmp -s $testroot/stderr.expected $testroot/stderr
730 if [ "$ret" != "0" ]; then
731 diff -u $testroot/stderr.expected $testroot/stderr
732 test_done "$testroot" "$ret"
736 (cd $testroot/wt && got revert foo > $testroot/stdout)
738 if [ "$ret" != "0" ]; then
739 echo "revert command failed unexpectedly" >&2
740 test_done "$testroot" "$ret"
744 echo "R foo" > $testroot/stdout.expected
745 cmp -s $testroot/stdout.expected $testroot/stdout
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/stdout.expected $testroot/stdout
749 test_done "$testroot" "$ret"
753 echo "new file" > $testroot/content.expected
754 cat $testroot/wt/foo > $testroot/content
755 cmp -s $testroot/content.expected $testroot/content
757 if [ "$ret" != "0" ]; then
758 diff -u $testroot/content.expected $testroot/content
759 test_done "$testroot" "$ret"
763 echo ' M alpha' > $testroot/stdout.expected
764 echo ' D beta' >> $testroot/stdout.expected
765 echo ' A foo' >> $testroot/stdout.expected
766 (cd $testroot/wt && got status > $testroot/stdout)
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 revert foo > $testroot/stdout)
777 if [ "$ret" != "0" ]; then
778 echo "revert command failed unexpectedly" >&2
779 test_done "$testroot" "$ret"
783 echo -n > $testroot/stdout.expected
784 cmp -s $testroot/stdout.expected $testroot/stdout
786 if [ "$ret" != "0" ]; then
787 diff -u $testroot/stdout.expected $testroot/stdout
788 test_done "$testroot" "$ret"
792 echo "new file" > $testroot/content.expected
793 cat $testroot/wt/foo > $testroot/content
794 cmp -s $testroot/content.expected $testroot/content
796 if [ "$ret" != "0" ]; then
797 diff -u $testroot/content.expected $testroot/content
798 test_done "$testroot" "$ret"
802 echo ' M alpha' > $testroot/stdout.expected
803 echo ' D beta' >> $testroot/stdout.expected
804 echo ' A foo' >> $testroot/stdout.expected
805 (cd $testroot/wt && got status > $testroot/stdout)
806 cmp -s $testroot/stdout.expected $testroot/stdout
808 if [ "$ret" != "0" ]; then
809 diff -u $testroot/stdout.expected $testroot/stdout
810 test_done "$testroot" "$ret"
814 echo "modified file again" >> $testroot/wt/alpha
815 echo "modified added file again" >> $testroot/wt/foo
817 (cd $testroot/wt && got revert -R . > $testroot/stdout \
820 if [ "$ret" != "0" ]; then
821 echo "revert command failed unexpectedly" >&2
822 test_done "$testroot" "$ret"
826 echo "R alpha" > $testroot/stdout.expected
827 echo "R foo" >> $testroot/stdout.expected
828 cmp -s $testroot/stdout.expected $testroot/stdout
830 if [ "$ret" != "0" ]; then
831 diff -u $testroot/stdout.expected $testroot/stdout
832 test_done "$testroot" "$ret"
836 echo -n > $testroot/stderr.expected
837 cmp -s $testroot/stderr.expected $testroot/stderr
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/stderr.expected $testroot/stderr
841 test_done "$testroot" "$ret"
845 echo ' M alpha' > $testroot/stdout.expected
846 echo ' D beta' >> $testroot/stdout.expected
847 echo ' A foo' >> $testroot/stdout.expected
848 (cd $testroot/wt && got status > $testroot/stdout)
849 cmp -s $testroot/stdout.expected $testroot/stdout
851 if [ "$ret" != "0" ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
854 test_done "$testroot" "$ret"
857 function test_stage_diff {
858 local testroot=`test_init stage_diff`
859 local head_commit=`git_show_head $testroot/repo`
861 got checkout $testroot/repo $testroot/wt > /dev/null
863 if [ "$ret" != "0" ]; then
864 test_done "$testroot" "$ret"
868 echo "modified file" > $testroot/wt/alpha
869 (cd $testroot/wt && got rm beta > /dev/null)
870 echo "new file" > $testroot/wt/foo
871 (cd $testroot/wt && got add foo > /dev/null)
873 (cd $testroot/wt && got diff -s > $testroot/stdout)
874 echo -n > $testroot/stdout.expected
875 cmp -s $testroot/stdout.expected $testroot/stdout
877 if [ "$ret" != "0" ]; then
878 diff -u $testroot/stdout.expected $testroot/stdout
879 test_done "$testroot" "$ret"
883 echo ' M alpha' > $testroot/stdout.expected
884 echo ' D beta' >> $testroot/stdout.expected
885 echo ' A foo' >> $testroot/stdout.expected
886 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
888 (cd $testroot/wt && got diff > $testroot/stdout)
889 echo -n > $testroot/stdout.expected
890 cmp -s $testroot/stdout.expected $testroot/stdout
892 if [ "$ret" != "0" ]; then
893 diff -u $testroot/stdout.expected $testroot/stdout
894 test_done "$testroot" "$ret"
898 echo "modified file again" > $testroot/wt/alpha
899 echo "new file changed" > $testroot/wt/foo
901 (cd $testroot/wt && got diff > $testroot/stdout)
903 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
904 echo -n 'blob - ' >> $testroot/stdout.expected
905 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
906 >> $testroot/stdout.expected
907 echo ' (staged)' >> $testroot/stdout.expected
908 echo 'file + alpha' >> $testroot/stdout.expected
909 echo '--- alpha' >> $testroot/stdout.expected
910 echo '+++ alpha' >> $testroot/stdout.expected
911 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
912 echo '-modified file' >> $testroot/stdout.expected
913 echo '+modified file again' >> $testroot/stdout.expected
914 echo -n 'blob - ' >> $testroot/stdout.expected
915 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
916 >> $testroot/stdout.expected
917 echo " (staged)" >> $testroot/stdout.expected
918 echo 'file + foo' >> $testroot/stdout.expected
919 echo '--- foo' >> $testroot/stdout.expected
920 echo '+++ foo' >> $testroot/stdout.expected
921 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
922 echo '-new file' >> $testroot/stdout.expected
923 echo '+new file changed' >> $testroot/stdout.expected
925 cmp -s $testroot/stdout.expected $testroot/stdout
927 if [ "$ret" != "0" ]; then
928 diff -u $testroot/stdout.expected $testroot/stdout
929 test_done "$testroot" "$ret"
933 (cd $testroot/wt && got diff -s > $testroot/stdout)
935 echo "diff $head_commit $testroot/wt (staged changes)" \
936 > $testroot/stdout.expected
937 echo -n 'blob - ' >> $testroot/stdout.expected
938 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
939 >> $testroot/stdout.expected
940 echo -n 'blob + ' >> $testroot/stdout.expected
941 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
942 >> $testroot/stdout.expected
943 echo '--- alpha' >> $testroot/stdout.expected
944 echo '+++ alpha' >> $testroot/stdout.expected
945 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
946 echo '-alpha' >> $testroot/stdout.expected
947 echo '+modified file' >> $testroot/stdout.expected
948 echo -n 'blob - ' >> $testroot/stdout.expected
949 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
950 >> $testroot/stdout.expected
951 echo 'blob + /dev/null' >> $testroot/stdout.expected
952 echo '--- beta' >> $testroot/stdout.expected
953 echo '+++ /dev/null' >> $testroot/stdout.expected
954 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
955 echo '-beta' >> $testroot/stdout.expected
956 echo 'blob - /dev/null' >> $testroot/stdout.expected
957 echo -n 'blob + ' >> $testroot/stdout.expected
958 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
959 >> $testroot/stdout.expected
960 echo '--- /dev/null' >> $testroot/stdout.expected
961 echo '+++ foo' >> $testroot/stdout.expected
962 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
963 echo '+new file' >> $testroot/stdout.expected
965 cmp -s $testroot/stdout.expected $testroot/stdout
967 if [ "$ret" != "0" ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
970 test_done "$testroot" "$ret"
974 function test_stage_histedit {
975 local testroot=`test_init stage_histedit`
976 local orig_commit=`git_show_head $testroot/repo`
978 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
980 if [ "$ret" != "0" ]; then
981 test_done "$testroot" "$ret"
985 echo "modified file" > $testroot/wt/alpha
986 (cd $testroot/wt && got stage alpha > /dev/null)
988 echo "modified alpha on master" > $testroot/repo/alpha
989 (cd $testroot/repo && git rm -q beta)
990 echo "new file on master" > $testroot/repo/epsilon/new
991 (cd $testroot/repo && git add epsilon/new)
992 git_commit $testroot/repo -m "committing changes"
993 local old_commit1=`git_show_head $testroot/repo`
995 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
996 git_commit $testroot/repo -m "committing to zeta on master"
997 local old_commit2=`git_show_head $testroot/repo`
999 echo "pick $old_commit1" > $testroot/histedit-script
1000 echo "pick $old_commit2" >> $testroot/histedit-script
1002 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1003 > $testroot/stdout 2> $testroot/stderr)
1005 if [ "$ret" == "0" ]; then
1006 echo "got histedit command succeeded unexpectedly" >&2
1007 test_done "$testroot" "1"
1011 echo -n > $testroot/stdout.expected
1012 echo "got: alpha: file is staged" > $testroot/stderr.expected
1014 cmp -s $testroot/stderr.expected $testroot/stderr
1016 if [ "$ret" != "0" ]; then
1017 diff -u $testroot/stderr.expected $testroot/stderr
1018 test_done "$testroot" "$ret"
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1023 if [ "$ret" != "0" ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1030 function test_stage_rebase {
1031 local testroot=`test_init stage_rebase`
1033 (cd $testroot/repo && git checkout -q -b newbranch)
1034 echo "modified delta on branch" > $testroot/repo/gamma/delta
1035 git_commit $testroot/repo -m "committing to delta on newbranch"
1037 echo "modified alpha on branch" > $testroot/repo/alpha
1038 (cd $testroot/repo && git rm -q beta)
1039 echo "new file on branch" > $testroot/repo/epsilon/new
1040 (cd $testroot/repo && git add epsilon/new)
1041 git_commit $testroot/repo -m "committing more changes on newbranch"
1043 local orig_commit1=`git_show_parent_commit $testroot/repo`
1044 local orig_commit2=`git_show_head $testroot/repo`
1046 (cd $testroot/repo && git checkout -q master)
1047 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1048 git_commit $testroot/repo -m "committing to zeta on master"
1049 local master_commit=`git_show_head $testroot/repo`
1051 got checkout $testroot/repo $testroot/wt > /dev/null
1053 if [ "$ret" != "0" ]; then
1054 test_done "$testroot" "$ret"
1058 echo "modified file" > $testroot/wt/alpha
1059 (cd $testroot/wt && got stage alpha > /dev/null)
1061 (cd $testroot/wt && got rebase newbranch \
1062 > $testroot/stdout 2> $testroot/stderr)
1064 if [ "$ret" == "0" ]; then
1065 echo "got rebase command succeeded unexpectedly" >&2
1066 test_done "$testroot" "1"
1070 echo -n > $testroot/stdout.expected
1071 echo "got: alpha: file is staged" > $testroot/stderr.expected
1073 cmp -s $testroot/stderr.expected $testroot/stderr
1075 if [ "$ret" != "0" ]; then
1076 diff -u $testroot/stderr.expected $testroot/stderr
1077 test_done "$testroot" "$ret"
1080 cmp -s $testroot/stdout.expected $testroot/stdout
1082 if [ "$ret" != "0" ]; then
1083 diff -u $testroot/stdout.expected $testroot/stdout
1085 test_done "$testroot" "$ret"
1088 function test_stage_update {
1089 local testroot=`test_init stage_update`
1091 got checkout $testroot/repo $testroot/wt > /dev/null
1093 if [ "$ret" != "0" ]; then
1094 test_done "$testroot" "$ret"
1098 echo "modified file" > $testroot/wt/alpha
1099 (cd $testroot/wt && got stage alpha > /dev/null)
1101 echo "modified alpha" > $testroot/repo/alpha
1102 git_commit $testroot/repo -m "modified alpha"
1104 (cd $testroot/wt && got update > $testroot/stdout \
1105 2> $testroot/stderr)
1107 if [ "$ret" == "0" ]; then
1108 echo "got update command succeeded unexpectedly" >&2
1109 test_done "$testroot" "1"
1113 echo -n > $testroot/stdout.expected
1114 echo "got: alpha: file is staged" > $testroot/stderr.expected
1116 cmp -s $testroot/stderr.expected $testroot/stderr
1118 if [ "$ret" != "0" ]; then
1119 diff -u $testroot/stderr.expected $testroot/stderr
1120 test_done "$testroot" "$ret"
1123 cmp -s $testroot/stdout.expected $testroot/stdout
1125 if [ "$ret" != "0" ]; then
1126 diff -u $testroot/stdout.expected $testroot/stdout
1128 test_done "$testroot" "$ret"
1131 function test_stage_commit_non_staged {
1132 local testroot=`test_init stage_commit_non_staged`
1134 got checkout $testroot/repo $testroot/wt > /dev/null
1136 if [ "$ret" != "0" ]; then
1137 test_done "$testroot" "$ret"
1141 echo "modified file" > $testroot/wt/alpha
1142 (cd $testroot/wt && got rm beta > /dev/null)
1143 echo "new file" > $testroot/wt/foo
1144 (cd $testroot/wt && got add foo > /dev/null)
1145 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1147 echo "modified file" > $testroot/wt/gamma/delta
1148 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1149 > $testroot/stdout 2> $testroot/stderr)
1151 if [ "$ret" == "0" ]; then
1152 echo "got commit command succeeded unexpectedly" >&2
1153 test_done "$testroot" "1"
1157 echo -n > $testroot/stdout.expected
1158 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1160 cmp -s $testroot/stderr.expected $testroot/stderr
1162 if [ "$ret" != "0" ]; then
1163 diff -u $testroot/stderr.expected $testroot/stderr
1164 test_done "$testroot" "$ret"
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1169 if [ "$ret" != "0" ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1172 test_done "$testroot" "$ret"
1175 function test_stage_commit_out_of_date {
1176 local testroot=`test_init stage_commit_out_of_date`
1178 got checkout $testroot/repo $testroot/wt > /dev/null
1180 if [ "$ret" != "0" ]; then
1181 test_done "$testroot" "$ret"
1185 echo "modified file" > $testroot/wt/alpha
1186 (cd $testroot/wt && got rm beta > /dev/null)
1187 echo "new file" > $testroot/wt/foo
1188 (cd $testroot/wt && got add foo > /dev/null)
1189 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1191 echo "changed file" > $testroot/repo/alpha
1192 git_commit $testroot/repo -m "changed alpha in repo"
1194 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1195 2> $testroot/stderr)
1197 if [ "$ret" == "0" ]; then
1198 echo "got commit command succeeded unexpectedly" >&2
1199 test_done "$testroot" "1"
1203 echo -n > $testroot/stdout.expected
1204 echo -n "got: work tree must be updated before these changes " \
1205 > $testroot/stderr.expected
1206 echo "can be committed" >> $testroot/stderr.expected
1208 cmp -s $testroot/stderr.expected $testroot/stderr
1210 if [ "$ret" != "0" ]; then
1211 diff -u $testroot/stderr.expected $testroot/stderr
1212 test_done "$testroot" "$ret"
1215 cmp -s $testroot/stdout.expected $testroot/stdout
1217 if [ "$ret" != "0" ]; then
1218 diff -u $testroot/stdout.expected $testroot/stdout
1219 test_done "$testroot" "$ret"
1223 (cd $testroot/wt && got update > $testroot/stdout \
1224 2> $testroot/stderr)
1225 echo -n > $testroot/stdout.expected
1226 echo "got: alpha: file is staged" > $testroot/stderr.expected
1228 cmp -s $testroot/stderr.expected $testroot/stderr
1230 if [ "$ret" != "0" ]; then
1231 diff -u $testroot/stderr.expected $testroot/stderr
1232 test_done "$testroot" "$ret"
1235 cmp -s $testroot/stdout.expected $testroot/stdout
1237 if [ "$ret" != "0" ]; then
1238 diff -u $testroot/stdout.expected $testroot/stdout
1239 test_done "$testroot" "$ret"
1243 (cd $testroot/wt && got unstage > /dev/null)
1244 (cd $testroot/wt && got update > $testroot/stdout)
1246 if [ "$ret" != "0" ]; then
1247 echo "got update command failed unexpectedly" >&2
1248 test_done "$testroot" "$ret"
1252 (cd $testroot/wt && got status > $testroot/stdout)
1253 echo "C alpha" > $testroot/stdout.expected
1254 echo "D beta" >> $testroot/stdout.expected
1255 echo "A foo" >> $testroot/stdout.expected
1256 cmp -s $testroot/stdout.expected $testroot/stdout
1258 if [ "$ret" != "0" ]; then
1259 diff -u $testroot/stdout.expected $testroot/stdout
1260 test_done "$testroot" "$ret"
1265 echo "resolved file" > $testroot/wt/alpha
1267 (cd $testroot/wt && got stage > /dev/null)
1269 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1271 if [ "$ret" != "0" ]; then
1272 echo "got commit command failed unexpectedly" >&2
1273 test_done "$testroot" "$ret"
1277 local commit_id=`git_show_head $testroot/repo`
1278 echo "A foo" > $testroot/stdout.expected
1279 echo "M alpha" >> $testroot/stdout.expected
1280 echo "D beta" >> $testroot/stdout.expected
1281 echo "Created commit $commit_id" >> $testroot/stdout.expected
1282 cmp -s $testroot/stdout.expected $testroot/stdout
1284 if [ "$ret" != "0" ]; then
1285 diff -u $testroot/stdout.expected $testroot/stdout
1287 test_done "$testroot" "$ret"
1291 function test_stage_commit {
1292 local testroot=`test_init stage_commit`
1293 local first_commit=`git_show_head $testroot/repo`
1295 got checkout $testroot/repo $testroot/wt > /dev/null
1297 if [ "$ret" != "0" ]; then
1298 test_done "$testroot" "$ret"
1302 echo "modified file" > $testroot/wt/alpha
1303 (cd $testroot/wt && got rm beta > /dev/null)
1304 echo "new file" > $testroot/wt/foo
1305 (cd $testroot/wt && got add foo > /dev/null)
1306 echo "modified file" > $testroot/wt/alpha
1307 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1309 echo "modified file again" > $testroot/wt/alpha
1310 echo "new file changed" > $testroot/wt/foo
1311 echo "non-staged change" > $testroot/wt/gamma/delta
1312 echo "non-staged new file" > $testroot/wt/epsilon/new
1313 (cd $testroot/wt && got add epsilon/new > /dev/null)
1314 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1316 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1317 > $testroot/blob_id_alpha
1318 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1319 > $testroot/blob_id_foo
1321 (cd $testroot/wt && got commit -m "staged changes" \
1324 if [ "$ret" != "0" ]; then
1325 echo "got commit command failed unexpectedly" >&2
1326 test_done "$testroot" "1"
1330 local head_commit=`git_show_head $testroot/repo`
1331 echo "A foo" > $testroot/stdout.expected
1332 echo "M alpha" >> $testroot/stdout.expected
1333 echo "D beta" >> $testroot/stdout.expected
1334 echo "Created commit $head_commit" >> $testroot/stdout.expected
1336 cmp -s $testroot/stdout.expected $testroot/stdout
1338 if [ "$ret" != "0" ]; then
1339 diff -u $testroot/stdout.expected $testroot/stdout
1340 test_done "$testroot" "$ret"
1344 got diff -r $testroot/repo $first_commit $head_commit \
1347 echo "diff $first_commit $head_commit" \
1348 > $testroot/stdout.expected
1349 echo -n 'blob - ' >> $testroot/stdout.expected
1350 got tree -r $testroot/repo -i -c $first_commit | \
1351 grep 'alpha$' | cut -d' ' -f 1 \
1352 >> $testroot/stdout.expected
1353 echo -n 'blob + ' >> $testroot/stdout.expected
1354 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1355 echo '--- alpha' >> $testroot/stdout.expected
1356 echo '+++ alpha' >> $testroot/stdout.expected
1357 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1358 echo '-alpha' >> $testroot/stdout.expected
1359 echo '+modified file' >> $testroot/stdout.expected
1360 echo -n 'blob - ' >> $testroot/stdout.expected
1361 got tree -r $testroot/repo -i -c $first_commit \
1362 | grep 'beta$' | cut -d' ' -f 1 | tr -d '\n' \
1363 >> $testroot/stdout.expected
1364 echo " (mode 644)" >> $testroot/stdout.expected
1365 echo 'blob + /dev/null' >> $testroot/stdout.expected
1366 echo '--- beta' >> $testroot/stdout.expected
1367 echo '+++ /dev/null' >> $testroot/stdout.expected
1368 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1369 echo '-beta' >> $testroot/stdout.expected
1370 echo 'blob - /dev/null' >> $testroot/stdout.expected
1371 echo -n 'blob + ' >> $testroot/stdout.expected
1372 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1373 echo " (mode 644)" >> $testroot/stdout.expected
1374 echo '--- /dev/null' >> $testroot/stdout.expected
1375 echo '+++ foo' >> $testroot/stdout.expected
1376 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1377 echo '+new file' >> $testroot/stdout.expected
1379 cmp -s $testroot/stdout.expected $testroot/stdout
1381 if [ "$ret" != "0" ]; then
1382 diff -u $testroot/stdout.expected $testroot/stdout
1383 test_done "$testroot" "$ret"
1387 echo 'M alpha' > $testroot/stdout.expected
1388 echo 'A epsilon/new' >> $testroot/stdout.expected
1389 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1390 echo 'M foo' >> $testroot/stdout.expected
1391 echo 'M gamma/delta' >> $testroot/stdout.expected
1393 (cd $testroot/wt && got status > $testroot/stdout)
1394 cmp -s $testroot/stdout.expected $testroot/stdout
1396 if [ "$ret" != "0" ]; then
1397 diff -u $testroot/stdout.expected $testroot/stdout
1399 test_done "$testroot" "$ret"
1402 function test_stage_patch {
1403 local testroot=`test_init stage_patch`
1405 jot 16 > $testroot/repo/numbers
1406 (cd $testroot/repo && git add numbers)
1407 git_commit $testroot/repo -m "added numbers file"
1408 local commit_id=`git_show_head $testroot/repo`
1410 got checkout $testroot/repo $testroot/wt > /dev/null
1412 if [ "$ret" != "0" ]; then
1413 test_done "$testroot" "$ret"
1417 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1418 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1419 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1421 # don't stage any hunks
1422 printf "n\nn\nn\n" > $testroot/patchscript
1423 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1424 numbers > $testroot/stdout)
1426 if [ "$ret" != "0" ]; then
1427 echo "got stage command failed unexpectedly" >&2
1428 test_done "$testroot" "1"
1431 cat > $testroot/stdout.expected <<EOF
1432 -----------------------------------------------
1440 -----------------------------------------------
1441 M numbers (change 1 of 3)
1442 stage this change? [y/n/q] n
1443 -----------------------------------------------
1453 -----------------------------------------------
1454 M numbers (change 2 of 3)
1455 stage this change? [y/n/q] n
1456 -----------------------------------------------
1463 -----------------------------------------------
1464 M numbers (change 3 of 3)
1465 stage this change? [y/n/q] n
1467 cmp -s $testroot/stdout.expected $testroot/stdout
1469 if [ "$ret" != "0" ]; then
1470 diff -u $testroot/stdout.expected $testroot/stdout
1471 test_done "$testroot" "$ret"
1475 (cd $testroot/wt && got status > $testroot/stdout)
1476 echo "M numbers" > $testroot/stdout.expected
1477 cmp -s $testroot/stdout.expected $testroot/stdout
1479 if [ "$ret" != "0" ]; then
1480 diff -u $testroot/stdout.expected $testroot/stdout
1481 test_done "$testroot" "$ret"
1486 printf "n\ny\nn\n" > $testroot/patchscript
1487 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1488 numbers > $testroot/stdout)
1490 cat > $testroot/stdout.expected <<EOF
1491 -----------------------------------------------
1499 -----------------------------------------------
1500 M numbers (change 1 of 3)
1501 stage this change? [y/n/q] n
1502 -----------------------------------------------
1512 -----------------------------------------------
1513 M numbers (change 2 of 3)
1514 stage this change? [y/n/q] y
1515 -----------------------------------------------
1522 -----------------------------------------------
1523 M numbers (change 3 of 3)
1524 stage this change? [y/n/q] n
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1528 if [ "$ret" != "0" ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1534 (cd $testroot/wt && got status > $testroot/stdout)
1535 echo "MM numbers" > $testroot/stdout.expected
1536 cmp -s $testroot/stdout.expected $testroot/stdout
1538 if [ "$ret" != "0" ]; then
1539 diff -u $testroot/stdout.expected $testroot/stdout
1540 test_done "$testroot" "$ret"
1544 (cd $testroot/wt && got diff -s > $testroot/stdout)
1546 echo "diff $commit_id $testroot/wt (staged changes)" \
1547 > $testroot/stdout.expected
1548 echo -n 'blob - ' >> $testroot/stdout.expected
1549 got tree -r $testroot/repo -i -c $commit_id \
1550 | grep 'numbers$' | cut -d' ' -f 1 \
1551 >> $testroot/stdout.expected
1552 echo -n 'blob + ' >> $testroot/stdout.expected
1553 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1554 >> $testroot/stdout.expected
1555 echo "--- numbers" >> $testroot/stdout.expected
1556 echo "+++ numbers" >> $testroot/stdout.expected
1557 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1558 echo " 4" >> $testroot/stdout.expected
1559 echo " 5" >> $testroot/stdout.expected
1560 echo " 6" >> $testroot/stdout.expected
1561 echo "-7" >> $testroot/stdout.expected
1562 echo "+b" >> $testroot/stdout.expected
1563 echo " 8" >> $testroot/stdout.expected
1564 echo " 9" >> $testroot/stdout.expected
1565 echo " 10" >> $testroot/stdout.expected
1566 cmp -s $testroot/stdout.expected $testroot/stdout
1568 if [ "$ret" != "0" ]; then
1569 diff -u $testroot/stdout.expected $testroot/stdout
1570 test_done "$testroot" "$ret"
1574 (cd $testroot/wt && got unstage >/dev/null)
1576 if [ "$ret" != "0" ]; then
1577 echo "got stage command failed unexpectedly" >&2
1578 test_done "$testroot" "1"
1581 (cd $testroot/wt && got status > $testroot/stdout)
1582 echo "M numbers" > $testroot/stdout.expected
1583 cmp -s $testroot/stdout.expected $testroot/stdout
1585 if [ "$ret" != "0" ]; then
1586 diff -u $testroot/stdout.expected $testroot/stdout
1587 test_done "$testroot" "$ret"
1592 printf "n\nn\ny\n" > $testroot/patchscript
1593 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1594 numbers > $testroot/stdout)
1596 cat > $testroot/stdout.expected <<EOF
1597 -----------------------------------------------
1605 -----------------------------------------------
1606 M numbers (change 1 of 3)
1607 stage this change? [y/n/q] n
1608 -----------------------------------------------
1618 -----------------------------------------------
1619 M numbers (change 2 of 3)
1620 stage this change? [y/n/q] n
1621 -----------------------------------------------
1628 -----------------------------------------------
1629 M numbers (change 3 of 3)
1630 stage this change? [y/n/q] y
1632 cmp -s $testroot/stdout.expected $testroot/stdout
1634 if [ "$ret" != "0" ]; then
1635 diff -u $testroot/stdout.expected $testroot/stdout
1636 test_done "$testroot" "$ret"
1640 (cd $testroot/wt && got status > $testroot/stdout)
1641 echo "MM numbers" > $testroot/stdout.expected
1642 cmp -s $testroot/stdout.expected $testroot/stdout
1644 if [ "$ret" != "0" ]; then
1645 diff -u $testroot/stdout.expected $testroot/stdout
1646 test_done "$testroot" "$ret"
1650 (cd $testroot/wt && got diff -s > $testroot/stdout)
1652 echo "diff $commit_id $testroot/wt (staged changes)" \
1653 > $testroot/stdout.expected
1654 echo -n 'blob - ' >> $testroot/stdout.expected
1655 got tree -r $testroot/repo -i -c $commit_id \
1656 | grep 'numbers$' | cut -d' ' -f 1 \
1657 >> $testroot/stdout.expected
1658 echo -n 'blob + ' >> $testroot/stdout.expected
1659 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1660 >> $testroot/stdout.expected
1661 echo "--- numbers" >> $testroot/stdout.expected
1662 echo "+++ numbers" >> $testroot/stdout.expected
1663 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1664 echo " 13" >> $testroot/stdout.expected
1665 echo " 14" >> $testroot/stdout.expected
1666 echo " 15" >> $testroot/stdout.expected
1667 echo "-16" >> $testroot/stdout.expected
1668 echo "+c" >> $testroot/stdout.expected
1669 cmp -s $testroot/stdout.expected $testroot/stdout
1671 if [ "$ret" != "0" ]; then
1672 diff -u $testroot/stdout.expected $testroot/stdout
1674 test_done "$testroot" "$ret"
1677 function test_stage_patch_twice {
1678 local testroot=`test_init stage_patch_twice`
1680 jot 16 > $testroot/repo/numbers
1681 (cd $testroot/repo && git add numbers)
1682 git_commit $testroot/repo -m "added numbers file"
1683 local commit_id=`git_show_head $testroot/repo`
1685 got checkout $testroot/repo $testroot/wt > /dev/null
1687 if [ "$ret" != "0" ]; then
1688 test_done "$testroot" "$ret"
1692 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1693 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1694 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1697 printf "n\ny\nn\n" > $testroot/patchscript
1698 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1699 numbers > $testroot/stdout)
1701 cat > $testroot/stdout.expected <<EOF
1702 -----------------------------------------------
1710 -----------------------------------------------
1711 M numbers (change 1 of 3)
1712 stage this change? [y/n/q] n
1713 -----------------------------------------------
1723 -----------------------------------------------
1724 M numbers (change 2 of 3)
1725 stage this change? [y/n/q] y
1726 -----------------------------------------------
1733 -----------------------------------------------
1734 M numbers (change 3 of 3)
1735 stage this change? [y/n/q] n
1737 cmp -s $testroot/stdout.expected $testroot/stdout
1739 if [ "$ret" != "0" ]; then
1740 diff -u $testroot/stdout.expected $testroot/stdout
1741 test_done "$testroot" "$ret"
1745 (cd $testroot/wt && got status > $testroot/stdout)
1746 echo "MM numbers" > $testroot/stdout.expected
1747 cmp -s $testroot/stdout.expected $testroot/stdout
1749 if [ "$ret" != "0" ]; then
1750 diff -u $testroot/stdout.expected $testroot/stdout
1751 test_done "$testroot" "$ret"
1756 printf "n\ny\n" > $testroot/patchscript
1757 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1758 numbers > $testroot/stdout)
1760 cat > $testroot/stdout.expected <<EOF
1761 -----------------------------------------------
1769 -----------------------------------------------
1770 M numbers (change 1 of 2)
1771 stage this change? [y/n/q] n
1772 -----------------------------------------------
1779 -----------------------------------------------
1780 M numbers (change 2 of 2)
1781 stage this change? [y/n/q] y
1783 cmp -s $testroot/stdout.expected $testroot/stdout
1785 if [ "$ret" != "0" ]; then
1786 diff -u $testroot/stdout.expected $testroot/stdout
1787 test_done "$testroot" "$ret"
1791 (cd $testroot/wt && got status > $testroot/stdout)
1792 echo "MM numbers" > $testroot/stdout.expected
1793 cmp -s $testroot/stdout.expected $testroot/stdout
1795 if [ "$ret" != "0" ]; then
1796 diff -u $testroot/stdout.expected $testroot/stdout
1797 test_done "$testroot" "$ret"
1801 (cd $testroot/wt && got diff -s > $testroot/stdout)
1803 echo "diff $commit_id $testroot/wt (staged changes)" \
1804 > $testroot/stdout.expected
1805 echo -n 'blob - ' >> $testroot/stdout.expected
1806 got tree -r $testroot/repo -i -c $commit_id \
1807 | grep 'numbers$' | cut -d' ' -f 1 \
1808 >> $testroot/stdout.expected
1809 echo -n 'blob + ' >> $testroot/stdout.expected
1810 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1811 >> $testroot/stdout.expected
1812 echo "--- numbers" >> $testroot/stdout.expected
1813 echo "+++ numbers" >> $testroot/stdout.expected
1814 cat >> $testroot/stdout.expected <<EOF
1831 cmp -s $testroot/stdout.expected $testroot/stdout
1833 if [ "$ret" != "0" ]; then
1834 diff -u $testroot/stdout.expected $testroot/stdout
1835 test_done "$testroot" "$ret"
1839 (cd $testroot/wt && got diff > $testroot/stdout)
1841 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1842 echo -n 'blob - ' >> $testroot/stdout.expected
1843 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1844 tr -d '\n' >> $testroot/stdout.expected
1845 echo " (staged)" >> $testroot/stdout.expected
1846 echo 'file + numbers' >> $testroot/stdout.expected
1847 echo "--- numbers" >> $testroot/stdout.expected
1848 echo "+++ numbers" >> $testroot/stdout.expected
1849 cat >> $testroot/stdout.expected <<EOF
1858 cmp -s $testroot/stdout.expected $testroot/stdout
1860 if [ "$ret" != "0" ]; then
1861 diff -u $testroot/stdout.expected $testroot/stdout
1863 test_done "$testroot" "$ret"
1866 function test_stage_patch_added {
1867 local testroot=`test_init stage_patch_added`
1868 local commit_id=`git_show_head $testroot/repo`
1870 got checkout $testroot/repo $testroot/wt > /dev/null
1872 if [ "$ret" != "0" ]; then
1873 test_done "$testroot" "$ret"
1877 echo "new" > $testroot/wt/epsilon/new
1878 (cd $testroot/wt && got add epsilon/new > /dev/null)
1880 printf "y\n" > $testroot/patchscript
1881 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1882 epsilon/new > $testroot/stdout)
1884 echo "A epsilon/new" > $testroot/stdout.expected
1885 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1886 cmp -s $testroot/stdout.expected $testroot/stdout
1888 if [ "$ret" != "0" ]; then
1889 diff -u $testroot/stdout.expected $testroot/stdout
1890 test_done "$testroot" "$ret"
1894 (cd $testroot/wt && got status > $testroot/stdout)
1895 echo " A epsilon/new" > $testroot/stdout.expected
1896 cmp -s $testroot/stdout.expected $testroot/stdout
1898 if [ "$ret" != "0" ]; then
1899 diff -u $testroot/stdout.expected $testroot/stdout
1900 test_done "$testroot" "$ret"
1904 (cd $testroot/wt && got diff -s > $testroot/stdout)
1906 echo "diff $commit_id $testroot/wt (staged changes)" \
1907 > $testroot/stdout.expected
1908 echo 'blob - /dev/null' >> $testroot/stdout.expected
1909 echo -n 'blob + ' >> $testroot/stdout.expected
1910 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1911 >> $testroot/stdout.expected
1912 echo "--- /dev/null" >> $testroot/stdout.expected
1913 echo "+++ epsilon/new" >> $testroot/stdout.expected
1914 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1915 echo "+new" >> $testroot/stdout.expected
1916 cmp -s $testroot/stdout.expected $testroot/stdout
1918 if [ "$ret" != "0" ]; then
1919 diff -u $testroot/stdout.expected $testroot/stdout
1921 test_done "$testroot" "$ret"
1924 function test_stage_patch_added_twice {
1925 local testroot=`test_init stage_patch_added_twice`
1926 local commit_id=`git_show_head $testroot/repo`
1928 got checkout $testroot/repo $testroot/wt > /dev/null
1930 if [ "$ret" != "0" ]; then
1931 test_done "$testroot" "$ret"
1935 echo "new" > $testroot/wt/epsilon/new
1936 (cd $testroot/wt && got add epsilon/new > /dev/null)
1938 printf "y\n" > $testroot/patchscript
1939 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1940 epsilon/new > $testroot/stdout)
1942 echo "A epsilon/new" > $testroot/stdout.expected
1943 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1944 cmp -s $testroot/stdout.expected $testroot/stdout
1946 if [ "$ret" != "0" ]; then
1947 diff -u $testroot/stdout.expected $testroot/stdout
1948 test_done "$testroot" "$ret"
1952 (cd $testroot/wt && got status > $testroot/stdout)
1953 echo " A epsilon/new" > $testroot/stdout.expected
1954 cmp -s $testroot/stdout.expected $testroot/stdout
1956 if [ "$ret" != "0" ]; then
1957 diff -u $testroot/stdout.expected $testroot/stdout
1958 test_done "$testroot" "$ret"
1962 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1963 epsilon/new > $testroot/stdout 2> $testroot/stderr)
1965 if [ "$ret" == "0" ]; then
1966 echo "got stage command succeeded unexpectedly" >&2
1967 test_done "$testroot" "1"
1971 echo "got: epsilon/new: no changes to stage" > $testroot/stderr.expected
1972 cmp -s $testroot/stderr.expected $testroot/stderr
1974 if [ "$ret" != "0" ]; then
1975 diff -u $testroot/stderr.expected $testroot/stderr
1976 test_done "$testroot" "$ret"
1980 echo -n > $testroot/stdout.expected
1981 cmp -s $testroot/stdout.expected $testroot/stdout
1983 if [ "$ret" != "0" ]; then
1984 diff -u $testroot/stdout.expected $testroot/stdout
1986 test_done "$testroot" "$ret"
1989 function test_stage_patch_removed {
1990 local testroot=`test_init stage_patch_removed`
1991 local commit_id=`git_show_head $testroot/repo`
1993 got checkout $testroot/repo $testroot/wt > /dev/null
1995 if [ "$ret" != "0" ]; then
1996 test_done "$testroot" "$ret"
2000 (cd $testroot/wt && got rm beta > /dev/null)
2002 printf "y\n" > $testroot/patchscript
2003 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2004 beta > $testroot/stdout)
2006 echo -n > $testroot/stdout.expected
2008 echo "D beta" > $testroot/stdout.expected
2009 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2010 cmp -s $testroot/stdout.expected $testroot/stdout
2012 if [ "$ret" != "0" ]; then
2013 diff -u $testroot/stdout.expected $testroot/stdout
2014 test_done "$testroot" "$ret"
2018 (cd $testroot/wt && got status > $testroot/stdout)
2019 echo " D beta" > $testroot/stdout.expected
2020 cmp -s $testroot/stdout.expected $testroot/stdout
2022 if [ "$ret" != "0" ]; then
2023 diff -u $testroot/stdout.expected $testroot/stdout
2024 test_done "$testroot" "$ret"
2028 (cd $testroot/wt && got diff -s > $testroot/stdout)
2030 echo "diff $commit_id $testroot/wt (staged changes)" \
2031 > $testroot/stdout.expected
2032 echo -n 'blob - ' >> $testroot/stdout.expected
2033 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2034 >> $testroot/stdout.expected
2035 echo 'blob + /dev/null' >> $testroot/stdout.expected
2036 echo "--- beta" >> $testroot/stdout.expected
2037 echo "+++ /dev/null" >> $testroot/stdout.expected
2038 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2039 echo "-beta" >> $testroot/stdout.expected
2040 cmp -s $testroot/stdout.expected $testroot/stdout
2042 if [ "$ret" != "0" ]; then
2043 diff -u $testroot/stdout.expected $testroot/stdout
2045 test_done "$testroot" "$ret"
2048 function test_stage_patch_removed_twice {
2049 local testroot=`test_init stage_patch_removed_twice`
2050 local commit_id=`git_show_head $testroot/repo`
2052 got checkout $testroot/repo $testroot/wt > /dev/null
2054 if [ "$ret" != "0" ]; then
2055 test_done "$testroot" "$ret"
2059 (cd $testroot/wt && got rm beta > /dev/null)
2061 printf "y\n" > $testroot/patchscript
2062 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2063 beta > $testroot/stdout)
2065 echo -n > $testroot/stdout.expected
2067 echo "D beta" > $testroot/stdout.expected
2068 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2069 cmp -s $testroot/stdout.expected $testroot/stdout
2071 if [ "$ret" != "0" ]; then
2072 diff -u $testroot/stdout.expected $testroot/stdout
2073 test_done "$testroot" "$ret"
2077 (cd $testroot/wt && got status > $testroot/stdout)
2078 echo " D beta" > $testroot/stdout.expected
2079 cmp -s $testroot/stdout.expected $testroot/stdout
2081 if [ "$ret" != "0" ]; then
2082 diff -u $testroot/stdout.expected $testroot/stdout
2083 test_done "$testroot" "$ret"
2087 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2088 > $testroot/stdout 2> $testroot/stderr)
2090 if [ "$ret" != "0" ]; then
2091 echo "got stage command failed unexpectedly" >&2
2092 test_done "$testroot" "$ret"
2096 echo -n > $testroot/stderr.expected
2097 cmp -s $testroot/stderr.expected $testroot/stderr
2099 if [ "$ret" != "0" ]; then
2100 diff -u $testroot/stderr.expected $testroot/stderr
2101 test_done "$testroot" "$ret"
2105 echo -n > $testroot/stdout.expected
2106 cmp -s $testroot/stdout.expected $testroot/stdout
2108 if [ "$ret" != "0" ]; then
2109 diff -u $testroot/stdout.expected $testroot/stdout
2111 test_done "$testroot" "$ret"
2114 function test_stage_patch_quit {
2115 local testroot=`test_init stage_patch_quit`
2117 jot 16 > $testroot/repo/numbers
2118 echo zzz > $testroot/repo/zzz
2119 (cd $testroot/repo && git add numbers zzz)
2120 git_commit $testroot/repo -m "added files"
2121 local commit_id=`git_show_head $testroot/repo`
2123 got checkout $testroot/repo $testroot/wt > /dev/null
2125 if [ "$ret" != "0" ]; then
2126 test_done "$testroot" "$ret"
2130 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2131 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2132 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2133 (cd $testroot/wt && got rm zzz > /dev/null)
2135 # stage first hunk and quit; and don't pass a path argument to
2136 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2137 printf "y\nq\nn\n" > $testroot/patchscript
2138 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2141 if [ "$ret" != "0" ]; then
2142 echo "got stage command failed unexpectedly" >&2
2143 test_done "$testroot" "1"
2146 cat > $testroot/stdout.expected <<EOF
2147 -----------------------------------------------
2155 -----------------------------------------------
2156 M numbers (change 1 of 3)
2157 stage this change? [y/n/q] y
2158 -----------------------------------------------
2168 -----------------------------------------------
2169 M numbers (change 2 of 3)
2170 stage this change? [y/n/q] q
2172 stage this deletion? [y/n] n
2174 cmp -s $testroot/stdout.expected $testroot/stdout
2176 if [ "$ret" != "0" ]; then
2177 diff -u $testroot/stdout.expected $testroot/stdout
2178 test_done "$testroot" "$ret"
2182 (cd $testroot/wt && got status > $testroot/stdout)
2183 echo "MM numbers" > $testroot/stdout.expected
2184 echo "D zzz" >> $testroot/stdout.expected
2185 cmp -s $testroot/stdout.expected $testroot/stdout
2187 if [ "$ret" != "0" ]; then
2188 diff -u $testroot/stdout.expected $testroot/stdout
2189 test_done "$testroot" "$ret"
2193 (cd $testroot/wt && got diff -s > $testroot/stdout)
2195 echo "diff $commit_id $testroot/wt (staged changes)" \
2196 > $testroot/stdout.expected
2197 echo -n 'blob - ' >> $testroot/stdout.expected
2198 got tree -r $testroot/repo -i -c $commit_id \
2199 | grep 'numbers$' | cut -d' ' -f 1 \
2200 >> $testroot/stdout.expected
2201 echo -n 'blob + ' >> $testroot/stdout.expected
2202 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2203 >> $testroot/stdout.expected
2204 echo "--- numbers" >> $testroot/stdout.expected
2205 echo "+++ numbers" >> $testroot/stdout.expected
2206 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2207 echo " 1" >> $testroot/stdout.expected
2208 echo "-2" >> $testroot/stdout.expected
2209 echo "+a" >> $testroot/stdout.expected
2210 echo " 3" >> $testroot/stdout.expected
2211 echo " 4" >> $testroot/stdout.expected
2212 echo " 5" >> $testroot/stdout.expected
2213 cmp -s $testroot/stdout.expected $testroot/stdout
2215 if [ "$ret" != "0" ]; then
2216 diff -u $testroot/stdout.expected $testroot/stdout
2218 test_done "$testroot" "$ret"
2222 function test_stage_patch_incomplete_script {
2223 local testroot=`test_init stage_incomplete_script`
2225 jot 16 > $testroot/repo/numbers
2226 echo zzz > $testroot/repo/zzz
2227 (cd $testroot/repo && git add numbers zzz)
2228 git_commit $testroot/repo -m "added files"
2229 local commit_id=`git_show_head $testroot/repo`
2231 got checkout $testroot/repo $testroot/wt > /dev/null
2233 if [ "$ret" != "0" ]; then
2234 test_done "$testroot" "$ret"
2238 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2239 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2240 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2242 # stage first hunk and then stop responding; got should error out
2243 printf "y\n" > $testroot/patchscript
2244 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2245 > $testroot/stdout 2> $testroot/stderr)
2247 if [ "$ret" == "0" ]; then
2248 echo "got stage command succeeded unexpectedly" >&2
2249 test_done "$testroot" "1"
2252 cat > $testroot/stdout.expected <<EOF
2253 -----------------------------------------------
2261 -----------------------------------------------
2262 M numbers (change 1 of 3)
2263 stage this change? [y/n/q] y
2264 -----------------------------------------------
2274 -----------------------------------------------
2275 M numbers (change 2 of 3)
2277 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2278 echo "got: invalid patch choice" > $testroot/stderr.expected
2279 cmp -s $testroot/stderr.expected $testroot/stderr
2281 if [ "$ret" != "0" ]; then
2282 diff -u $testroot/stderr.expected $testroot/stderr
2283 test_done "$testroot" "$ret"
2287 cmp -s $testroot/stdout.expected $testroot/stdout
2289 if [ "$ret" != "0" ]; then
2290 diff -u $testroot/stdout.expected $testroot/stdout
2291 test_done "$testroot" "$ret"
2295 (cd $testroot/wt && got status > $testroot/stdout)
2296 echo "M numbers" > $testroot/stdout.expected
2297 cmp -s $testroot/stdout.expected $testroot/stdout
2299 if [ "$ret" != "0" ]; then
2300 diff -u $testroot/stdout.expected $testroot/stdout
2301 test_done "$testroot" "$ret"
2305 (cd $testroot/wt && got diff -s > $testroot/stdout)
2306 echo -n > $testroot/stdout.expected
2307 cmp -s $testroot/stdout.expected $testroot/stdout
2309 if [ "$ret" != "0" ]; then
2310 diff -u $testroot/stdout.expected $testroot/stdout
2312 test_done "$testroot" "$ret"
2316 run_test test_stage_basic
2317 run_test test_stage_no_changes
2318 run_test test_stage_unversioned
2319 run_test test_stage_nonexistent
2320 run_test test_stage_list
2321 run_test test_stage_conflict
2322 run_test test_stage_out_of_date
2323 run_test test_double_stage
2324 run_test test_stage_status
2325 run_test test_stage_add_already_staged_file
2326 run_test test_stage_rm_already_staged_file
2327 run_test test_stage_revert
2328 run_test test_stage_diff
2329 run_test test_stage_histedit
2330 run_test test_stage_rebase
2331 run_test test_stage_update
2332 run_test test_stage_commit_non_staged
2333 run_test test_stage_commit_out_of_date
2334 run_test test_stage_commit
2335 run_test test_stage_patch
2336 run_test test_stage_patch_twice
2337 run_test test_stage_patch_added
2338 run_test test_stage_patch_added_twice
2339 run_test test_stage_patch_removed
2340 run_test test_stage_patch_removed_twice
2341 run_test test_stage_patch_quit
2342 run_test test_stage_patch_incomplete_script