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: no changes to stage" > $testroot/stderr.expected
160 cmp -s $testroot/stderr.expected $testroot/stderr
162 if [ "$ret" != "0" ]; then
163 diff -u $testroot/stderr.expected $testroot/stderr
165 test_done "$testroot" "$ret"
168 function test_stage_list {
169 local testroot=`test_init stage_list`
171 got checkout $testroot/repo $testroot/wt > /dev/null
173 if [ "$ret" != "0" ]; then
174 test_done "$testroot" "$ret"
178 echo "modified file" > $testroot/wt/alpha
179 (cd $testroot/wt && got rm beta > /dev/null)
180 echo "new file" > $testroot/wt/foo
181 (cd $testroot/wt && got add foo > /dev/null)
183 echo ' M alpha' > $testroot/stdout.expected
184 echo ' D beta' >> $testroot/stdout.expected
185 echo ' A foo' >> $testroot/stdout.expected
186 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
188 (cd $testroot/wt && got stage -l > $testroot/stdout)
189 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
190 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
191 echo " M alpha" >> $testroot/stdout.expected
192 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
193 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
194 echo " D beta" >> $testroot/stdout.expected
195 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
196 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
197 echo " A foo" >> $testroot/stdout.expected
198 cmp -s $testroot/stdout.expected $testroot/stdout
200 if [ "$ret" != "0" ]; then
201 diff -u $testroot/stdout.expected $testroot/stdout
202 test_done "$testroot" "$ret"
206 (cd $testroot/wt && got stage -l epsilon nonexistent \
209 echo -n > $testroot/stdout.expected
210 cmp -s $testroot/stdout.expected $testroot/stdout
212 if [ "$ret" != "0" ]; then
213 diff -u $testroot/stdout.expected $testroot/stdout
214 test_done "$testroot" "$ret"
218 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
220 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
221 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
222 echo " M alpha" >> $testroot/stdout.expected
223 cmp -s $testroot/stdout.expected $testroot/stdout
225 if [ "$ret" != "0" ]; then
226 diff -u $testroot/stdout.expected $testroot/stdout
228 test_done "$testroot" "$ret"
232 function test_stage_conflict {
233 local testroot=`test_init stage_conflict`
234 local initial_commit=`git_show_head $testroot/repo`
236 got checkout $testroot/repo $testroot/wt > /dev/null
238 if [ "$ret" != "0" ]; then
239 test_done "$testroot" "$ret"
243 echo "modified alpha" > $testroot/wt/alpha
244 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
246 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
248 echo "modified alpha, too" > $testroot/wt/alpha
250 echo "C alpha" > $testroot/stdout.expected
251 echo -n "Updated to commit " >> $testroot/stdout.expected
252 git_show_head $testroot/repo >> $testroot/stdout.expected
253 echo >> $testroot/stdout.expected
255 (cd $testroot/wt && got update > $testroot/stdout)
257 cmp -s $testroot/stdout.expected $testroot/stdout
259 if [ "$ret" != "0" ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 test_done "$testroot" "$ret"
265 (cd $testroot/wt && got stage alpha > $testroot/stdout \
268 if [ "$ret" == "0" ]; then
269 echo "got stage command succeeded unexpectedly" >&2
270 test_done "$testroot" "1"
274 echo -n > $testroot/stdout.expected
275 echo "got: alpha: cannot stage file in conflicted status" \
276 > $testroot/stderr.expected
278 cmp -s $testroot/stdout.expected $testroot/stdout
280 if [ "$ret" != "0" ]; then
281 diff -u $testroot/stdout.expected $testroot/stdout
282 test_done "$testroot" "$ret"
285 cmp -s $testroot/stderr.expected $testroot/stderr
287 if [ "$ret" != "0" ]; then
288 diff -u $testroot/stderr.expected $testroot/stderr
290 test_done "$testroot" "$ret"
293 function test_stage_out_of_date {
294 local testroot=`test_init stage_out_of_date`
295 local initial_commit=`git_show_head $testroot/repo`
297 got checkout $testroot/repo $testroot/wt > /dev/null
299 if [ "$ret" != "0" ]; then
300 test_done "$testroot" "$ret"
304 echo "modified alpha" > $testroot/wt/alpha
305 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
307 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
309 echo "modified alpha again" > $testroot/wt/alpha
310 (cd $testroot/wt && got stage alpha > $testroot/stdout \
313 if [ "$ret" == "0" ]; then
314 echo "got stage command succeeded unexpectedly" >&2
315 test_done "$testroot" "1"
319 echo -n > $testroot/stdout.expected
320 echo "got: work tree must be updated before changes can be staged" \
321 > $testroot/stderr.expected
323 cmp -s $testroot/stdout.expected $testroot/stdout
325 if [ "$ret" != "0" ]; then
326 diff -u $testroot/stdout.expected $testroot/stdout
327 test_done "$testroot" "$ret"
330 cmp -s $testroot/stderr.expected $testroot/stderr
332 if [ "$ret" != "0" ]; then
333 diff -u $testroot/stderr.expected $testroot/stderr
335 test_done "$testroot" "$ret"
339 function test_double_stage {
340 local testroot=`test_init double_stage`
342 got checkout $testroot/repo $testroot/wt > /dev/null
344 if [ "$ret" != "0" ]; then
345 test_done "$testroot" "$ret"
348 echo "modified file" > $testroot/wt/alpha
349 (cd $testroot/wt && got rm beta > /dev/null)
350 echo "new file" > $testroot/wt/foo
351 (cd $testroot/wt && got add foo > /dev/null)
352 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
354 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
355 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
356 cmp -s $testroot/stderr.expected $testroot/stderr
358 if [ "$ret" != "0" ]; then
359 diff -u $testroot/stderr.expected $testroot/stderr
360 test_done "$testroot" "$ret"
364 (cd $testroot/wt && got stage beta > $testroot/stdout)
366 if [ "$ret" != "0" ]; then
367 echo "got stage command failed unexpectedly" >&2
368 test_done "$testroot" "1"
371 echo -n > $testroot/stdout.expected
372 cmp -s $testroot/stdout.expected $testroot/stdout
374 if [ "$ret" != "0" ]; then
375 diff -u $testroot/stdout.expected $testroot/stdout
376 test_done "$testroot" "$ret"
380 echo "got: foo: no changes to stage" > $testroot/stderr.expected
381 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
382 cmp -s $testroot/stderr.expected $testroot/stderr
384 if [ "$ret" != "0" ]; then
385 diff -u $testroot/stderr.expected $testroot/stderr
386 test_done "$testroot" "$ret"
390 echo "modified file again" > $testroot/wt/alpha
391 echo "modified new file" > $testroot/wt/foo
393 echo ' M alpha' > $testroot/stdout.expected
394 echo ' A foo' >> $testroot/stdout.expected
395 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
396 cmp -s $testroot/stdout.expected $testroot/stdout
398 if [ "$ret" != "0" ]; then
399 diff -u $testroot/stdout.expected $testroot/stdout
400 test_done "$testroot" "$ret"
404 echo ' M alpha' > $testroot/stdout.expected
405 echo ' D beta' >> $testroot/stdout.expected
406 echo ' A foo' >> $testroot/stdout.expected
408 (cd $testroot/wt && got status > $testroot/stdout)
409 cmp -s $testroot/stdout.expected $testroot/stdout
411 if [ "$ret" != "0" ]; then
412 diff -u $testroot/stdout.expected $testroot/stdout
414 test_done "$testroot" "$ret"
417 function test_stage_status {
418 local testroot=`test_init stage_status`
420 got checkout $testroot/repo $testroot/wt > /dev/null
422 if [ "$ret" != "0" ]; then
423 test_done "$testroot" "$ret"
427 echo "modified file" > $testroot/wt/alpha
428 (cd $testroot/wt && got rm beta > /dev/null)
429 echo "new file" > $testroot/wt/foo
430 (cd $testroot/wt && got add foo > /dev/null)
431 echo "new file" > $testroot/wt/epsilon/new
432 (cd $testroot/wt && got add epsilon/new > /dev/null)
433 echo "modified file" > $testroot/wt/epsilon/zeta
434 (cd $testroot/wt && got rm gamma/delta > /dev/null)
436 echo ' M alpha' > $testroot/stdout.expected
437 echo ' D beta' >> $testroot/stdout.expected
438 echo 'A epsilon/new' >> $testroot/stdout.expected
439 echo 'M epsilon/zeta' >> $testroot/stdout.expected
440 echo ' A foo' >> $testroot/stdout.expected
441 echo 'D gamma/delta' >> $testroot/stdout.expected
442 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
444 (cd $testroot/wt && got status > $testroot/stdout)
445 cmp -s $testroot/stdout.expected $testroot/stdout
447 if [ "$ret" != "0" ]; then
448 diff -u $testroot/stdout.expected $testroot/stdout
449 test_done "$testroot" "$ret"
453 echo "modified file again" >> $testroot/wt/alpha
454 echo "modified added file again" >> $testroot/wt/foo
456 echo 'MM alpha' > $testroot/stdout.expected
457 echo ' D beta' >> $testroot/stdout.expected
458 echo 'A epsilon/new' >> $testroot/stdout.expected
459 echo 'M epsilon/zeta' >> $testroot/stdout.expected
460 echo 'MA foo' >> $testroot/stdout.expected
461 echo 'D gamma/delta' >> $testroot/stdout.expected
463 (cd $testroot/wt && got status > $testroot/stdout)
464 cmp -s $testroot/stdout.expected $testroot/stdout
466 if [ "$ret" != "0" ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
472 # test no-op change of added file with new stat(2) timestamp
473 echo "new file" > $testroot/wt/foo
474 echo ' A foo' > $testroot/stdout.expected
475 (cd $testroot/wt && got status foo > $testroot/stdout)
476 cmp -s $testroot/stdout.expected $testroot/stdout
478 if [ "$ret" != "0" ]; then
479 diff -u $testroot/stdout.expected $testroot/stdout
480 test_done "$testroot" "$ret"
484 # test staged deleted file which is restored on disk
485 echo "new file" > $testroot/wt/beta
486 echo ' D beta' > $testroot/stdout.expected
487 (cd $testroot/wt && got status beta > $testroot/stdout)
488 cmp -s $testroot/stdout.expected $testroot/stdout
490 if [ "$ret" != "0" ]; then
491 diff -u $testroot/stdout.expected $testroot/stdout
493 test_done "$testroot" "$ret"
497 function test_stage_add_already_staged_file {
498 local testroot=`test_init stage_add_already_staged_file`
500 got checkout $testroot/repo $testroot/wt > /dev/null
502 if [ "$ret" != "0" ]; then
503 test_done "$testroot" "$ret"
507 echo "modified file" > $testroot/wt/alpha
508 (cd $testroot/wt && got rm beta > /dev/null)
509 echo "new file" > $testroot/wt/foo
510 (cd $testroot/wt && got add foo > /dev/null)
512 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
514 echo -n > $testroot/stdout.expected
515 for f in alpha beta foo; do
516 (cd $testroot/wt && got add $f \
517 > $testroot/stdout 2> $testroot/stderr)
518 echo "got: $f: file has unexpected status" \
519 > $testroot/stderr.expected
520 cmp -s $testroot/stderr.expected $testroot/stderr
522 if [ "$ret" != "0" ]; then
523 diff -u $testroot/stderr.expected $testroot/stderr
524 test_done "$testroot" "$ret"
527 cmp -s $testroot/stdout.expected $testroot/stdout
529 if [ "$ret" != "0" ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 test_done "$testroot" "$ret"
536 echo ' M alpha' > $testroot/stdout.expected
537 echo ' D beta' >> $testroot/stdout.expected
538 echo ' A foo' >> $testroot/stdout.expected
540 (cd $testroot/wt && got status > $testroot/stdout)
541 cmp -s $testroot/stdout.expected $testroot/stdout
543 if [ "$ret" != "0" ]; then
544 diff -u $testroot/stdout.expected $testroot/stdout
546 test_done "$testroot" "$ret"
549 function test_stage_rm_already_staged_file {
550 local testroot=`test_init stage_rm_already_staged_file`
552 got checkout $testroot/repo $testroot/wt > /dev/null
554 if [ "$ret" != "0" ]; then
555 test_done "$testroot" "$ret"
559 echo "modified file" > $testroot/wt/alpha
560 (cd $testroot/wt && got rm beta > /dev/null)
561 echo "new file" > $testroot/wt/foo
562 (cd $testroot/wt && got add foo > /dev/null)
564 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
566 (cd $testroot/wt && got rm beta \
567 > $testroot/stdout 2> $testroot/stderr)
569 if [ "$ret" != "0" ]; then
570 echo "got rm command failed unexpectedly" >&2
571 test_done "$testroot" "1"
574 echo -n > $testroot/stdout.expected
575 cmp -s $testroot/stdout.expected $testroot/stdout
577 if [ "$ret" != "0" ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 test_done "$testroot" "$ret"
582 echo -n > $testroot/stderr.expected
583 cmp -s $testroot/stderr.expected $testroot/stderr
585 if [ "$ret" != "0" ]; then
586 diff -u $testroot/stderr.expected $testroot/stderr
587 test_done "$testroot" "$ret"
591 for f in alpha foo; do
592 echo "got: $f: file is staged" > $testroot/stderr.expected
593 (cd $testroot/wt && got rm $f \
594 > $testroot/stdout 2> $testroot/stderr)
596 if [ "$ret" == "0" ]; then
597 echo "got rm command succeeded unexpectedly" >&2
598 test_done "$testroot" "1"
601 cmp -s $testroot/stderr.expected $testroot/stderr
603 if [ "$ret" != "0" ]; then
604 diff -u $testroot/stderr.expected $testroot/stderr
605 test_done "$testroot" "$ret"
610 echo ' M alpha' > $testroot/stdout.expected
611 echo ' D beta' >> $testroot/stdout.expected
612 echo ' A foo' >> $testroot/stdout.expected
614 (cd $testroot/wt && got status > $testroot/stdout)
615 cmp -s $testroot/stdout.expected $testroot/stdout
617 if [ "$ret" != "0" ]; then
618 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
623 function test_stage_revert {
624 local testroot=`test_init stage_revert`
626 got checkout $testroot/repo $testroot/wt > /dev/null
628 if [ "$ret" != "0" ]; then
629 test_done "$testroot" "$ret"
633 echo "modified alpha" > $testroot/wt/alpha
634 (cd $testroot/wt && got rm beta > /dev/null)
635 echo "new file" > $testroot/wt/foo
636 (cd $testroot/wt && got add foo > /dev/null)
637 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
639 echo "modified file again" >> $testroot/wt/alpha
640 echo "modified added file again" >> $testroot/wt/foo
642 (cd $testroot/wt && got revert alpha > $testroot/stdout)
644 if [ "$ret" != "0" ]; then
645 echo "revert command failed unexpectedly" >&2
646 test_done "$testroot" "$ret"
650 echo "R alpha" > $testroot/stdout.expected
651 cmp -s $testroot/stdout.expected $testroot/stdout
653 if [ "$ret" != "0" ]; then
654 diff -u $testroot/stdout.expected $testroot/stdout
655 test_done "$testroot" "$ret"
659 echo "modified alpha" > $testroot/content.expected
660 cat $testroot/wt/alpha > $testroot/content
661 cmp -s $testroot/content.expected $testroot/content
663 if [ "$ret" != "0" ]; then
664 diff -u $testroot/content.expected $testroot/content
665 test_done "$testroot" "$ret"
669 echo ' M alpha' > $testroot/stdout.expected
670 echo ' D beta' >> $testroot/stdout.expected
671 echo 'MA foo' >> $testroot/stdout.expected
672 (cd $testroot/wt && got status > $testroot/stdout)
673 cmp -s $testroot/stdout.expected $testroot/stdout
675 if [ "$ret" != "0" ]; then
676 diff -u $testroot/stdout.expected $testroot/stdout
677 test_done "$testroot" "$ret"
681 (cd $testroot/wt && got revert alpha > $testroot/stdout)
683 if [ "$ret" != "0" ]; then
684 echo "revert command failed unexpectedly" >&2
685 test_done "$testroot" "$ret"
689 echo -n > $testroot/stdout.expected
690 cmp -s $testroot/stdout.expected $testroot/stdout
692 if [ "$ret" != "0" ]; then
693 diff -u $testroot/stdout.expected $testroot/stdout
694 test_done "$testroot" "$ret"
698 echo "modified alpha" > $testroot/content.expected
699 cat $testroot/wt/alpha > $testroot/content
700 cmp -s $testroot/content.expected $testroot/content
702 if [ "$ret" != "0" ]; then
703 diff -u $testroot/content.expected $testroot/content
704 test_done "$testroot" "$ret"
708 (cd $testroot/wt && got revert beta > $testroot/stdout \
711 if [ "$ret" != "0" ]; then
712 echo "revert command failed unexpectedly" >&2
713 test_done "$testroot" "$ret"
717 echo -n > $testroot/stdout.expected
718 cmp -s $testroot/stdout.expected $testroot/stdout
720 if [ "$ret" != "0" ]; then
721 diff -u $testroot/stdout.expected $testroot/stdout
722 test_done "$testroot" "$ret"
726 echo -n > $testroot/stderr.expected
727 cmp -s $testroot/stderr.expected $testroot/stderr
729 if [ "$ret" != "0" ]; then
730 diff -u $testroot/stderr.expected $testroot/stderr
731 test_done "$testroot" "$ret"
735 (cd $testroot/wt && got revert foo > $testroot/stdout)
737 if [ "$ret" != "0" ]; then
738 echo "revert command failed unexpectedly" >&2
739 test_done "$testroot" "$ret"
743 echo "R foo" > $testroot/stdout.expected
744 cmp -s $testroot/stdout.expected $testroot/stdout
746 if [ "$ret" != "0" ]; then
747 diff -u $testroot/stdout.expected $testroot/stdout
748 test_done "$testroot" "$ret"
752 echo "new file" > $testroot/content.expected
753 cat $testroot/wt/foo > $testroot/content
754 cmp -s $testroot/content.expected $testroot/content
756 if [ "$ret" != "0" ]; then
757 diff -u $testroot/content.expected $testroot/content
758 test_done "$testroot" "$ret"
762 echo ' M alpha' > $testroot/stdout.expected
763 echo ' D beta' >> $testroot/stdout.expected
764 echo ' A foo' >> $testroot/stdout.expected
765 (cd $testroot/wt && got status > $testroot/stdout)
766 cmp -s $testroot/stdout.expected $testroot/stdout
768 if [ "$ret" != "0" ]; then
769 diff -u $testroot/stdout.expected $testroot/stdout
770 test_done "$testroot" "$ret"
774 (cd $testroot/wt && got revert foo > $testroot/stdout)
776 if [ "$ret" != "0" ]; then
777 echo "revert command failed unexpectedly" >&2
778 test_done "$testroot" "$ret"
782 echo -n > $testroot/stdout.expected
783 cmp -s $testroot/stdout.expected $testroot/stdout
785 if [ "$ret" != "0" ]; then
786 diff -u $testroot/stdout.expected $testroot/stdout
787 test_done "$testroot" "$ret"
791 echo "new file" > $testroot/content.expected
792 cat $testroot/wt/foo > $testroot/content
793 cmp -s $testroot/content.expected $testroot/content
795 if [ "$ret" != "0" ]; then
796 diff -u $testroot/content.expected $testroot/content
797 test_done "$testroot" "$ret"
801 echo ' M alpha' > $testroot/stdout.expected
802 echo ' D beta' >> $testroot/stdout.expected
803 echo ' A foo' >> $testroot/stdout.expected
804 (cd $testroot/wt && got status > $testroot/stdout)
805 cmp -s $testroot/stdout.expected $testroot/stdout
807 if [ "$ret" != "0" ]; then
808 diff -u $testroot/stdout.expected $testroot/stdout
809 test_done "$testroot" "$ret"
813 echo "modified file again" >> $testroot/wt/alpha
814 echo "modified added file again" >> $testroot/wt/foo
816 (cd $testroot/wt && got revert -R . > $testroot/stdout \
819 if [ "$ret" != "0" ]; then
820 echo "revert command failed unexpectedly" >&2
821 test_done "$testroot" "$ret"
825 echo "R alpha" > $testroot/stdout.expected
826 echo "R foo" >> $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
829 if [ "$ret" != "0" ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
831 test_done "$testroot" "$ret"
835 echo -n > $testroot/stderr.expected
836 cmp -s $testroot/stderr.expected $testroot/stderr
838 if [ "$ret" != "0" ]; then
839 diff -u $testroot/stderr.expected $testroot/stderr
840 test_done "$testroot" "$ret"
844 echo ' M alpha' > $testroot/stdout.expected
845 echo ' D beta' >> $testroot/stdout.expected
846 echo ' A foo' >> $testroot/stdout.expected
847 (cd $testroot/wt && got status > $testroot/stdout)
848 cmp -s $testroot/stdout.expected $testroot/stdout
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
853 test_done "$testroot" "$ret"
856 function test_stage_diff {
857 local testroot=`test_init stage_diff`
858 local head_commit=`git_show_head $testroot/repo`
860 got checkout $testroot/repo $testroot/wt > /dev/null
862 if [ "$ret" != "0" ]; then
863 test_done "$testroot" "$ret"
867 echo "modified file" > $testroot/wt/alpha
868 (cd $testroot/wt && got rm beta > /dev/null)
869 echo "new file" > $testroot/wt/foo
870 (cd $testroot/wt && got add foo > /dev/null)
872 (cd $testroot/wt && got diff -s > $testroot/stdout)
873 echo -n > $testroot/stdout.expected
874 cmp -s $testroot/stdout.expected $testroot/stdout
876 if [ "$ret" != "0" ]; then
877 diff -u $testroot/stdout.expected $testroot/stdout
878 test_done "$testroot" "$ret"
882 echo ' M alpha' > $testroot/stdout.expected
883 echo ' D beta' >> $testroot/stdout.expected
884 echo ' A foo' >> $testroot/stdout.expected
885 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
887 (cd $testroot/wt && got diff > $testroot/stdout)
888 echo -n > $testroot/stdout.expected
889 cmp -s $testroot/stdout.expected $testroot/stdout
891 if [ "$ret" != "0" ]; then
892 diff -u $testroot/stdout.expected $testroot/stdout
893 test_done "$testroot" "$ret"
897 echo "modified file again" > $testroot/wt/alpha
898 echo "new file changed" > $testroot/wt/foo
900 (cd $testroot/wt && got diff > $testroot/stdout)
902 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
903 echo -n 'blob - ' >> $testroot/stdout.expected
904 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
905 >> $testroot/stdout.expected
906 echo ' (staged)' >> $testroot/stdout.expected
907 echo 'file + alpha' >> $testroot/stdout.expected
908 echo '--- alpha' >> $testroot/stdout.expected
909 echo '+++ alpha' >> $testroot/stdout.expected
910 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
911 echo '-modified file' >> $testroot/stdout.expected
912 echo '+modified file again' >> $testroot/stdout.expected
913 echo -n 'blob - ' >> $testroot/stdout.expected
914 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
915 >> $testroot/stdout.expected
916 echo " (staged)" >> $testroot/stdout.expected
917 echo 'file + foo' >> $testroot/stdout.expected
918 echo '--- foo' >> $testroot/stdout.expected
919 echo '+++ foo' >> $testroot/stdout.expected
920 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
921 echo '-new file' >> $testroot/stdout.expected
922 echo '+new file changed' >> $testroot/stdout.expected
924 cmp -s $testroot/stdout.expected $testroot/stdout
926 if [ "$ret" != "0" ]; then
927 diff -u $testroot/stdout.expected $testroot/stdout
928 test_done "$testroot" "$ret"
932 (cd $testroot/wt && got diff -s > $testroot/stdout)
934 echo "diff $head_commit $testroot/wt (staged changes)" \
935 > $testroot/stdout.expected
936 echo -n 'blob - ' >> $testroot/stdout.expected
937 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
938 >> $testroot/stdout.expected
939 echo -n 'blob + ' >> $testroot/stdout.expected
940 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
941 >> $testroot/stdout.expected
942 echo '--- alpha' >> $testroot/stdout.expected
943 echo '+++ alpha' >> $testroot/stdout.expected
944 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
945 echo '-alpha' >> $testroot/stdout.expected
946 echo '+modified file' >> $testroot/stdout.expected
947 echo -n 'blob - ' >> $testroot/stdout.expected
948 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
949 >> $testroot/stdout.expected
950 echo 'blob + /dev/null' >> $testroot/stdout.expected
951 echo '--- beta' >> $testroot/stdout.expected
952 echo '+++ /dev/null' >> $testroot/stdout.expected
953 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
954 echo '-beta' >> $testroot/stdout.expected
955 echo 'blob - /dev/null' >> $testroot/stdout.expected
956 echo -n 'blob + ' >> $testroot/stdout.expected
957 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
958 >> $testroot/stdout.expected
959 echo '--- /dev/null' >> $testroot/stdout.expected
960 echo '+++ foo' >> $testroot/stdout.expected
961 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
962 echo '+new file' >> $testroot/stdout.expected
964 cmp -s $testroot/stdout.expected $testroot/stdout
966 if [ "$ret" != "0" ]; then
967 diff -u $testroot/stdout.expected $testroot/stdout
969 test_done "$testroot" "$ret"
973 function test_stage_histedit {
974 local testroot=`test_init stage_histedit`
975 local orig_commit=`git_show_head $testroot/repo`
977 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
979 if [ "$ret" != "0" ]; then
980 test_done "$testroot" "$ret"
984 echo "modified file" > $testroot/wt/alpha
985 (cd $testroot/wt && got stage alpha > /dev/null)
987 echo "modified alpha on master" > $testroot/repo/alpha
988 (cd $testroot/repo && git rm -q beta)
989 echo "new file on master" > $testroot/repo/epsilon/new
990 (cd $testroot/repo && git add epsilon/new)
991 git_commit $testroot/repo -m "committing changes"
992 local old_commit1=`git_show_head $testroot/repo`
994 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
995 git_commit $testroot/repo -m "committing to zeta on master"
996 local old_commit2=`git_show_head $testroot/repo`
998 echo "pick $old_commit1" > $testroot/histedit-script
999 echo "pick $old_commit2" >> $testroot/histedit-script
1001 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1002 > $testroot/stdout 2> $testroot/stderr)
1004 if [ "$ret" == "0" ]; then
1005 echo "got histedit command succeeded unexpectedly" >&2
1006 test_done "$testroot" "1"
1010 echo -n > $testroot/stdout.expected
1011 echo "got: alpha: file is staged" > $testroot/stderr.expected
1013 cmp -s $testroot/stderr.expected $testroot/stderr
1015 if [ "$ret" != "0" ]; then
1016 diff -u $testroot/stderr.expected $testroot/stderr
1017 test_done "$testroot" "$ret"
1020 cmp -s $testroot/stdout.expected $testroot/stdout
1022 if [ "$ret" != "0" ]; then
1023 diff -u $testroot/stdout.expected $testroot/stdout
1025 test_done "$testroot" "$ret"
1029 function test_stage_rebase {
1030 local testroot=`test_init stage_rebase`
1032 (cd $testroot/repo && git checkout -q -b newbranch)
1033 echo "modified delta on branch" > $testroot/repo/gamma/delta
1034 git_commit $testroot/repo -m "committing to delta on newbranch"
1036 echo "modified alpha on branch" > $testroot/repo/alpha
1037 (cd $testroot/repo && git rm -q beta)
1038 echo "new file on branch" > $testroot/repo/epsilon/new
1039 (cd $testroot/repo && git add epsilon/new)
1040 git_commit $testroot/repo -m "committing more changes on newbranch"
1042 local orig_commit1=`git_show_parent_commit $testroot/repo`
1043 local orig_commit2=`git_show_head $testroot/repo`
1045 (cd $testroot/repo && git checkout -q master)
1046 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1047 git_commit $testroot/repo -m "committing to zeta on master"
1048 local master_commit=`git_show_head $testroot/repo`
1050 got checkout $testroot/repo $testroot/wt > /dev/null
1052 if [ "$ret" != "0" ]; then
1053 test_done "$testroot" "$ret"
1057 echo "modified file" > $testroot/wt/alpha
1058 (cd $testroot/wt && got stage alpha > /dev/null)
1060 (cd $testroot/wt && got rebase newbranch \
1061 > $testroot/stdout 2> $testroot/stderr)
1063 if [ "$ret" == "0" ]; then
1064 echo "got rebase command succeeded unexpectedly" >&2
1065 test_done "$testroot" "1"
1069 echo -n > $testroot/stdout.expected
1070 echo "got: alpha: file is staged" > $testroot/stderr.expected
1072 cmp -s $testroot/stderr.expected $testroot/stderr
1074 if [ "$ret" != "0" ]; then
1075 diff -u $testroot/stderr.expected $testroot/stderr
1076 test_done "$testroot" "$ret"
1079 cmp -s $testroot/stdout.expected $testroot/stdout
1081 if [ "$ret" != "0" ]; then
1082 diff -u $testroot/stdout.expected $testroot/stdout
1084 test_done "$testroot" "$ret"
1087 function test_stage_update {
1088 local testroot=`test_init stage_update`
1090 got checkout $testroot/repo $testroot/wt > /dev/null
1092 if [ "$ret" != "0" ]; then
1093 test_done "$testroot" "$ret"
1097 echo "modified file" > $testroot/wt/alpha
1098 (cd $testroot/wt && got stage alpha > /dev/null)
1100 echo "modified alpha" > $testroot/repo/alpha
1101 git_commit $testroot/repo -m "modified alpha"
1103 (cd $testroot/wt && got update > $testroot/stdout \
1104 2> $testroot/stderr)
1106 if [ "$ret" == "0" ]; then
1107 echo "got update command succeeded unexpectedly" >&2
1108 test_done "$testroot" "1"
1112 echo -n > $testroot/stdout.expected
1113 echo "got: alpha: file is staged" > $testroot/stderr.expected
1115 cmp -s $testroot/stderr.expected $testroot/stderr
1117 if [ "$ret" != "0" ]; then
1118 diff -u $testroot/stderr.expected $testroot/stderr
1119 test_done "$testroot" "$ret"
1122 cmp -s $testroot/stdout.expected $testroot/stdout
1124 if [ "$ret" != "0" ]; then
1125 diff -u $testroot/stdout.expected $testroot/stdout
1127 test_done "$testroot" "$ret"
1130 function test_stage_commit_non_staged {
1131 local testroot=`test_init stage_commit_non_staged`
1133 got checkout $testroot/repo $testroot/wt > /dev/null
1135 if [ "$ret" != "0" ]; then
1136 test_done "$testroot" "$ret"
1140 echo "modified file" > $testroot/wt/alpha
1141 (cd $testroot/wt && got rm beta > /dev/null)
1142 echo "new file" > $testroot/wt/foo
1143 (cd $testroot/wt && got add foo > /dev/null)
1144 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1146 echo "modified file" > $testroot/wt/gamma/delta
1147 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1148 > $testroot/stdout 2> $testroot/stderr)
1150 if [ "$ret" == "0" ]; then
1151 echo "got commit command succeeded unexpectedly" >&2
1152 test_done "$testroot" "1"
1156 echo -n > $testroot/stdout.expected
1157 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1159 cmp -s $testroot/stderr.expected $testroot/stderr
1161 if [ "$ret" != "0" ]; then
1162 diff -u $testroot/stderr.expected $testroot/stderr
1163 test_done "$testroot" "$ret"
1166 cmp -s $testroot/stdout.expected $testroot/stdout
1168 if [ "$ret" != "0" ]; then
1169 diff -u $testroot/stdout.expected $testroot/stdout
1171 test_done "$testroot" "$ret"
1174 function test_stage_commit_out_of_date {
1175 local testroot=`test_init stage_commit_out_of_date`
1177 got checkout $testroot/repo $testroot/wt > /dev/null
1179 if [ "$ret" != "0" ]; then
1180 test_done "$testroot" "$ret"
1184 echo "modified file" > $testroot/wt/alpha
1185 (cd $testroot/wt && got rm beta > /dev/null)
1186 echo "new file" > $testroot/wt/foo
1187 (cd $testroot/wt && got add foo > /dev/null)
1188 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1190 echo "changed file" > $testroot/repo/alpha
1191 git_commit $testroot/repo -m "changed alpha in repo"
1193 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1194 2> $testroot/stderr)
1196 if [ "$ret" == "0" ]; then
1197 echo "got commit command succeeded unexpectedly" >&2
1198 test_done "$testroot" "1"
1202 echo -n > $testroot/stdout.expected
1203 echo -n "got: work tree must be updated before these changes " \
1204 > $testroot/stderr.expected
1205 echo "can be committed" >> $testroot/stderr.expected
1207 cmp -s $testroot/stderr.expected $testroot/stderr
1209 if [ "$ret" != "0" ]; then
1210 diff -u $testroot/stderr.expected $testroot/stderr
1211 test_done "$testroot" "$ret"
1214 cmp -s $testroot/stdout.expected $testroot/stdout
1216 if [ "$ret" != "0" ]; then
1217 diff -u $testroot/stdout.expected $testroot/stdout
1218 test_done "$testroot" "$ret"
1222 (cd $testroot/wt && got update > $testroot/stdout \
1223 2> $testroot/stderr)
1224 echo -n > $testroot/stdout.expected
1225 echo "got: alpha: file is staged" > $testroot/stderr.expected
1227 cmp -s $testroot/stderr.expected $testroot/stderr
1229 if [ "$ret" != "0" ]; then
1230 diff -u $testroot/stderr.expected $testroot/stderr
1231 test_done "$testroot" "$ret"
1234 cmp -s $testroot/stdout.expected $testroot/stdout
1236 if [ "$ret" != "0" ]; then
1237 diff -u $testroot/stdout.expected $testroot/stdout
1238 test_done "$testroot" "$ret"
1242 (cd $testroot/wt && got unstage > /dev/null)
1243 (cd $testroot/wt && got update > $testroot/stdout)
1245 if [ "$ret" != "0" ]; then
1246 echo "got update command failed unexpectedly" >&2
1247 test_done "$testroot" "$ret"
1251 (cd $testroot/wt && got status > $testroot/stdout)
1252 echo "C alpha" > $testroot/stdout.expected
1253 echo "D beta" >> $testroot/stdout.expected
1254 echo "A foo" >> $testroot/stdout.expected
1255 cmp -s $testroot/stdout.expected $testroot/stdout
1257 if [ "$ret" != "0" ]; then
1258 diff -u $testroot/stdout.expected $testroot/stdout
1259 test_done "$testroot" "$ret"
1264 echo "resolved file" > $testroot/wt/alpha
1266 (cd $testroot/wt && got stage > /dev/null)
1268 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1270 if [ "$ret" != "0" ]; then
1271 echo "got commit command failed unexpectedly" >&2
1272 test_done "$testroot" "$ret"
1276 local commit_id=`git_show_head $testroot/repo`
1277 echo "A foo" > $testroot/stdout.expected
1278 echo "M alpha" >> $testroot/stdout.expected
1279 echo "D beta" >> $testroot/stdout.expected
1280 echo "Created commit $commit_id" >> $testroot/stdout.expected
1281 cmp -s $testroot/stdout.expected $testroot/stdout
1283 if [ "$ret" != "0" ]; then
1284 diff -u $testroot/stdout.expected $testroot/stdout
1286 test_done "$testroot" "$ret"
1290 function test_stage_commit {
1291 local testroot=`test_init stage_commit`
1292 local first_commit=`git_show_head $testroot/repo`
1294 got checkout $testroot/repo $testroot/wt > /dev/null
1296 if [ "$ret" != "0" ]; then
1297 test_done "$testroot" "$ret"
1301 echo "modified file" > $testroot/wt/alpha
1302 (cd $testroot/wt && got rm beta > /dev/null)
1303 echo "new file" > $testroot/wt/foo
1304 (cd $testroot/wt && got add foo > /dev/null)
1305 echo "modified file" > $testroot/wt/alpha
1306 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1308 echo "modified file again" > $testroot/wt/alpha
1309 echo "new file changed" > $testroot/wt/foo
1310 echo "non-staged change" > $testroot/wt/gamma/delta
1311 echo "non-staged new file" > $testroot/wt/epsilon/new
1312 (cd $testroot/wt && got add epsilon/new > /dev/null)
1313 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1315 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1316 > $testroot/blob_id_alpha
1317 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1318 > $testroot/blob_id_foo
1320 (cd $testroot/wt && got commit -m "staged changes" \
1323 if [ "$ret" != "0" ]; then
1324 echo "got commit command failed unexpectedly" >&2
1325 test_done "$testroot" "1"
1329 local head_commit=`git_show_head $testroot/repo`
1330 echo "A foo" > $testroot/stdout.expected
1331 echo "M alpha" >> $testroot/stdout.expected
1332 echo "D beta" >> $testroot/stdout.expected
1333 echo "Created commit $head_commit" >> $testroot/stdout.expected
1335 cmp -s $testroot/stdout.expected $testroot/stdout
1337 if [ "$ret" != "0" ]; then
1338 diff -u $testroot/stdout.expected $testroot/stdout
1339 test_done "$testroot" "$ret"
1343 got diff -r $testroot/repo $first_commit $head_commit \
1346 echo "diff $first_commit $head_commit" \
1347 > $testroot/stdout.expected
1348 echo -n 'blob - ' >> $testroot/stdout.expected
1349 got tree -r $testroot/repo -i -c $first_commit | \
1350 grep 'alpha$' | cut -d' ' -f 1 \
1351 >> $testroot/stdout.expected
1352 echo -n 'blob + ' >> $testroot/stdout.expected
1353 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1354 echo '--- alpha' >> $testroot/stdout.expected
1355 echo '+++ alpha' >> $testroot/stdout.expected
1356 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1357 echo '-alpha' >> $testroot/stdout.expected
1358 echo '+modified file' >> $testroot/stdout.expected
1359 echo -n 'blob - ' >> $testroot/stdout.expected
1360 got tree -r $testroot/repo -i -c $first_commit \
1361 | grep 'beta$' | cut -d' ' -f 1 \
1362 >> $testroot/stdout.expected
1363 echo 'blob + /dev/null' >> $testroot/stdout.expected
1364 echo '--- beta' >> $testroot/stdout.expected
1365 echo '+++ /dev/null' >> $testroot/stdout.expected
1366 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1367 echo '-beta' >> $testroot/stdout.expected
1368 echo 'blob - /dev/null' >> $testroot/stdout.expected
1369 echo -n 'blob + ' >> $testroot/stdout.expected
1370 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1371 echo '--- /dev/null' >> $testroot/stdout.expected
1372 echo '+++ foo' >> $testroot/stdout.expected
1373 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1374 echo '+new file' >> $testroot/stdout.expected
1376 cmp -s $testroot/stdout.expected $testroot/stdout
1378 if [ "$ret" != "0" ]; then
1379 diff -u $testroot/stdout.expected $testroot/stdout
1380 test_done "$testroot" "$ret"
1384 echo 'A epsilon/new' > $testroot/stdout.expected
1385 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1386 echo 'M gamma/delta' >> $testroot/stdout.expected
1388 (cd $testroot/wt && got status > $testroot/stdout)
1389 cmp -s $testroot/stdout.expected $testroot/stdout
1391 if [ "$ret" != "0" ]; then
1392 diff -u $testroot/stdout.expected $testroot/stdout
1394 test_done "$testroot" "$ret"
1397 function test_stage_patch {
1398 local testroot=`test_init stage_patch`
1400 jot 16 > $testroot/repo/numbers
1401 (cd $testroot/repo && git add numbers)
1402 git_commit $testroot/repo -m "added numbers file"
1403 local commit_id=`git_show_head $testroot/repo`
1405 got checkout $testroot/repo $testroot/wt > /dev/null
1407 if [ "$ret" != "0" ]; then
1408 test_done "$testroot" "$ret"
1412 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1413 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1414 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1416 # don't stage any hunks
1417 printf "n\nn\nn\n" > $testroot/patchscript
1418 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1419 numbers > $testroot/stdout)
1421 if [ "$ret" != "0" ]; then
1422 echo "got stage command failed unexpectedly" >&2
1423 test_done "$testroot" "1"
1426 cat > $testroot/stdout.expected <<EOF
1427 -----------------------------------------------
1435 -----------------------------------------------
1436 M numbers (change 1 of 3)
1437 stage this change? [y/n/q] n
1438 -----------------------------------------------
1448 -----------------------------------------------
1449 M numbers (change 2 of 3)
1450 stage this change? [y/n/q] n
1451 -----------------------------------------------
1458 -----------------------------------------------
1459 M numbers (change 3 of 3)
1460 stage this change? [y/n/q] n
1462 cmp -s $testroot/stdout.expected $testroot/stdout
1464 if [ "$ret" != "0" ]; then
1465 diff -u $testroot/stdout.expected $testroot/stdout
1466 test_done "$testroot" "$ret"
1470 (cd $testroot/wt && got status > $testroot/stdout)
1471 echo "M numbers" > $testroot/stdout.expected
1472 cmp -s $testroot/stdout.expected $testroot/stdout
1474 if [ "$ret" != "0" ]; then
1475 diff -u $testroot/stdout.expected $testroot/stdout
1476 test_done "$testroot" "$ret"
1481 printf "n\ny\nn\n" > $testroot/patchscript
1482 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1483 numbers > $testroot/stdout)
1485 cat > $testroot/stdout.expected <<EOF
1486 -----------------------------------------------
1494 -----------------------------------------------
1495 M numbers (change 1 of 3)
1496 stage this change? [y/n/q] n
1497 -----------------------------------------------
1507 -----------------------------------------------
1508 M numbers (change 2 of 3)
1509 stage this change? [y/n/q] y
1510 -----------------------------------------------
1517 -----------------------------------------------
1518 M numbers (change 3 of 3)
1519 stage this change? [y/n/q] n
1521 cmp -s $testroot/stdout.expected $testroot/stdout
1523 if [ "$ret" != "0" ]; then
1524 diff -u $testroot/stdout.expected $testroot/stdout
1525 test_done "$testroot" "$ret"
1529 (cd $testroot/wt && got status > $testroot/stdout)
1530 echo "MM numbers" > $testroot/stdout.expected
1531 cmp -s $testroot/stdout.expected $testroot/stdout
1533 if [ "$ret" != "0" ]; then
1534 diff -u $testroot/stdout.expected $testroot/stdout
1535 test_done "$testroot" "$ret"
1539 (cd $testroot/wt && got diff -s > $testroot/stdout)
1541 echo "diff $commit_id $testroot/wt (staged changes)" \
1542 > $testroot/stdout.expected
1543 echo -n 'blob - ' >> $testroot/stdout.expected
1544 got tree -r $testroot/repo -i -c $commit_id \
1545 | grep 'numbers$' | cut -d' ' -f 1 \
1546 >> $testroot/stdout.expected
1547 echo -n 'blob + ' >> $testroot/stdout.expected
1548 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1549 >> $testroot/stdout.expected
1550 echo "--- numbers" >> $testroot/stdout.expected
1551 echo "+++ numbers" >> $testroot/stdout.expected
1552 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1553 echo " 4" >> $testroot/stdout.expected
1554 echo " 5" >> $testroot/stdout.expected
1555 echo " 6" >> $testroot/stdout.expected
1556 echo "-7" >> $testroot/stdout.expected
1557 echo "+b" >> $testroot/stdout.expected
1558 echo " 8" >> $testroot/stdout.expected
1559 echo " 9" >> $testroot/stdout.expected
1560 echo " 10" >> $testroot/stdout.expected
1561 cmp -s $testroot/stdout.expected $testroot/stdout
1563 if [ "$ret" != "0" ]; then
1564 diff -u $testroot/stdout.expected $testroot/stdout
1565 test_done "$testroot" "$ret"
1569 (cd $testroot/wt && got unstage >/dev/null)
1571 if [ "$ret" != "0" ]; then
1572 echo "got stage command failed unexpectedly" >&2
1573 test_done "$testroot" "1"
1576 (cd $testroot/wt && got status > $testroot/stdout)
1577 echo "M numbers" > $testroot/stdout.expected
1578 cmp -s $testroot/stdout.expected $testroot/stdout
1580 if [ "$ret" != "0" ]; then
1581 diff -u $testroot/stdout.expected $testroot/stdout
1582 test_done "$testroot" "$ret"
1587 printf "n\nn\ny\n" > $testroot/patchscript
1588 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1589 numbers > $testroot/stdout)
1591 cat > $testroot/stdout.expected <<EOF
1592 -----------------------------------------------
1600 -----------------------------------------------
1601 M numbers (change 1 of 3)
1602 stage this change? [y/n/q] n
1603 -----------------------------------------------
1613 -----------------------------------------------
1614 M numbers (change 2 of 3)
1615 stage this change? [y/n/q] n
1616 -----------------------------------------------
1623 -----------------------------------------------
1624 M numbers (change 3 of 3)
1625 stage this change? [y/n/q] y
1627 cmp -s $testroot/stdout.expected $testroot/stdout
1629 if [ "$ret" != "0" ]; then
1630 diff -u $testroot/stdout.expected $testroot/stdout
1631 test_done "$testroot" "$ret"
1635 (cd $testroot/wt && got status > $testroot/stdout)
1636 echo "MM numbers" > $testroot/stdout.expected
1637 cmp -s $testroot/stdout.expected $testroot/stdout
1639 if [ "$ret" != "0" ]; then
1640 diff -u $testroot/stdout.expected $testroot/stdout
1641 test_done "$testroot" "$ret"
1645 (cd $testroot/wt && got diff -s > $testroot/stdout)
1647 echo "diff $commit_id $testroot/wt (staged changes)" \
1648 > $testroot/stdout.expected
1649 echo -n 'blob - ' >> $testroot/stdout.expected
1650 got tree -r $testroot/repo -i -c $commit_id \
1651 | grep 'numbers$' | cut -d' ' -f 1 \
1652 >> $testroot/stdout.expected
1653 echo -n 'blob + ' >> $testroot/stdout.expected
1654 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1655 >> $testroot/stdout.expected
1656 echo "--- numbers" >> $testroot/stdout.expected
1657 echo "+++ numbers" >> $testroot/stdout.expected
1658 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1659 echo " 13" >> $testroot/stdout.expected
1660 echo " 14" >> $testroot/stdout.expected
1661 echo " 15" >> $testroot/stdout.expected
1662 echo "-16" >> $testroot/stdout.expected
1663 echo "+c" >> $testroot/stdout.expected
1664 cmp -s $testroot/stdout.expected $testroot/stdout
1666 if [ "$ret" != "0" ]; then
1667 diff -u $testroot/stdout.expected $testroot/stdout
1669 test_done "$testroot" "$ret"
1672 function test_stage_patch_twice {
1673 local testroot=`test_init stage_patch_twice`
1675 jot 16 > $testroot/repo/numbers
1676 (cd $testroot/repo && git add numbers)
1677 git_commit $testroot/repo -m "added numbers file"
1678 local commit_id=`git_show_head $testroot/repo`
1680 got checkout $testroot/repo $testroot/wt > /dev/null
1682 if [ "$ret" != "0" ]; then
1683 test_done "$testroot" "$ret"
1687 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1688 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1689 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1692 printf "n\ny\nn\n" > $testroot/patchscript
1693 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1694 numbers > $testroot/stdout)
1696 cat > $testroot/stdout.expected <<EOF
1697 -----------------------------------------------
1705 -----------------------------------------------
1706 M numbers (change 1 of 3)
1707 stage this change? [y/n/q] n
1708 -----------------------------------------------
1718 -----------------------------------------------
1719 M numbers (change 2 of 3)
1720 stage this change? [y/n/q] y
1721 -----------------------------------------------
1728 -----------------------------------------------
1729 M numbers (change 3 of 3)
1730 stage this change? [y/n/q] n
1732 cmp -s $testroot/stdout.expected $testroot/stdout
1734 if [ "$ret" != "0" ]; then
1735 diff -u $testroot/stdout.expected $testroot/stdout
1736 test_done "$testroot" "$ret"
1740 (cd $testroot/wt && got status > $testroot/stdout)
1741 echo "MM numbers" > $testroot/stdout.expected
1742 cmp -s $testroot/stdout.expected $testroot/stdout
1744 if [ "$ret" != "0" ]; then
1745 diff -u $testroot/stdout.expected $testroot/stdout
1746 test_done "$testroot" "$ret"
1751 printf "n\ny\n" > $testroot/patchscript
1752 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1753 numbers > $testroot/stdout)
1755 cat > $testroot/stdout.expected <<EOF
1756 -----------------------------------------------
1764 -----------------------------------------------
1765 M numbers (change 1 of 2)
1766 stage this change? [y/n/q] n
1767 -----------------------------------------------
1774 -----------------------------------------------
1775 M numbers (change 2 of 2)
1776 stage this change? [y/n/q] y
1778 cmp -s $testroot/stdout.expected $testroot/stdout
1780 if [ "$ret" != "0" ]; then
1781 diff -u $testroot/stdout.expected $testroot/stdout
1782 test_done "$testroot" "$ret"
1786 (cd $testroot/wt && got status > $testroot/stdout)
1787 echo "MM numbers" > $testroot/stdout.expected
1788 cmp -s $testroot/stdout.expected $testroot/stdout
1790 if [ "$ret" != "0" ]; then
1791 diff -u $testroot/stdout.expected $testroot/stdout
1792 test_done "$testroot" "$ret"
1796 (cd $testroot/wt && got diff -s > $testroot/stdout)
1798 echo "diff $commit_id $testroot/wt (staged changes)" \
1799 > $testroot/stdout.expected
1800 echo -n 'blob - ' >> $testroot/stdout.expected
1801 got tree -r $testroot/repo -i -c $commit_id \
1802 | grep 'numbers$' | cut -d' ' -f 1 \
1803 >> $testroot/stdout.expected
1804 echo -n 'blob + ' >> $testroot/stdout.expected
1805 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1806 >> $testroot/stdout.expected
1807 echo "--- numbers" >> $testroot/stdout.expected
1808 echo "+++ numbers" >> $testroot/stdout.expected
1809 cat >> $testroot/stdout.expected <<EOF
1826 cmp -s $testroot/stdout.expected $testroot/stdout
1828 if [ "$ret" != "0" ]; then
1829 diff -u $testroot/stdout.expected $testroot/stdout
1830 test_done "$testroot" "$ret"
1834 (cd $testroot/wt && got diff > $testroot/stdout)
1836 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1837 echo -n 'blob - ' >> $testroot/stdout.expected
1838 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1839 tr -d '\n' >> $testroot/stdout.expected
1840 echo " (staged)" >> $testroot/stdout.expected
1841 echo 'file + numbers' >> $testroot/stdout.expected
1842 echo "--- numbers" >> $testroot/stdout.expected
1843 echo "+++ numbers" >> $testroot/stdout.expected
1844 cat >> $testroot/stdout.expected <<EOF
1853 cmp -s $testroot/stdout.expected $testroot/stdout
1855 if [ "$ret" != "0" ]; then
1856 diff -u $testroot/stdout.expected $testroot/stdout
1858 test_done "$testroot" "$ret"
1861 function test_stage_patch_added {
1862 local testroot=`test_init stage_patch_added`
1863 local commit_id=`git_show_head $testroot/repo`
1865 got checkout $testroot/repo $testroot/wt > /dev/null
1867 if [ "$ret" != "0" ]; then
1868 test_done "$testroot" "$ret"
1872 echo "new" > $testroot/wt/epsilon/new
1873 (cd $testroot/wt && got add epsilon/new > /dev/null)
1875 printf "y\n" > $testroot/patchscript
1876 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1877 epsilon/new > $testroot/stdout)
1879 echo "A epsilon/new" > $testroot/stdout.expected
1880 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1881 cmp -s $testroot/stdout.expected $testroot/stdout
1883 if [ "$ret" != "0" ]; then
1884 diff -u $testroot/stdout.expected $testroot/stdout
1885 test_done "$testroot" "$ret"
1889 (cd $testroot/wt && got status > $testroot/stdout)
1890 echo " A epsilon/new" > $testroot/stdout.expected
1891 cmp -s $testroot/stdout.expected $testroot/stdout
1893 if [ "$ret" != "0" ]; then
1894 diff -u $testroot/stdout.expected $testroot/stdout
1895 test_done "$testroot" "$ret"
1899 (cd $testroot/wt && got diff -s > $testroot/stdout)
1901 echo "diff $commit_id $testroot/wt (staged changes)" \
1902 > $testroot/stdout.expected
1903 echo 'blob - /dev/null' >> $testroot/stdout.expected
1904 echo -n 'blob + ' >> $testroot/stdout.expected
1905 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1906 >> $testroot/stdout.expected
1907 echo "--- /dev/null" >> $testroot/stdout.expected
1908 echo "+++ epsilon/new" >> $testroot/stdout.expected
1909 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1910 echo "+new" >> $testroot/stdout.expected
1911 cmp -s $testroot/stdout.expected $testroot/stdout
1913 if [ "$ret" != "0" ]; then
1914 diff -u $testroot/stdout.expected $testroot/stdout
1916 test_done "$testroot" "$ret"
1919 function test_stage_patch_added_twice {
1920 local testroot=`test_init stage_patch_added_twice`
1921 local commit_id=`git_show_head $testroot/repo`
1923 got checkout $testroot/repo $testroot/wt > /dev/null
1925 if [ "$ret" != "0" ]; then
1926 test_done "$testroot" "$ret"
1930 echo "new" > $testroot/wt/epsilon/new
1931 (cd $testroot/wt && got add epsilon/new > /dev/null)
1933 printf "y\n" > $testroot/patchscript
1934 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1935 epsilon/new > $testroot/stdout)
1937 echo "A epsilon/new" > $testroot/stdout.expected
1938 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1939 cmp -s $testroot/stdout.expected $testroot/stdout
1941 if [ "$ret" != "0" ]; then
1942 diff -u $testroot/stdout.expected $testroot/stdout
1943 test_done "$testroot" "$ret"
1947 (cd $testroot/wt && got status > $testroot/stdout)
1948 echo " A epsilon/new" > $testroot/stdout.expected
1949 cmp -s $testroot/stdout.expected $testroot/stdout
1951 if [ "$ret" != "0" ]; then
1952 diff -u $testroot/stdout.expected $testroot/stdout
1953 test_done "$testroot" "$ret"
1957 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1958 epsilon/new > $testroot/stdout 2> $testroot/stderr)
1960 if [ "$ret" == "0" ]; then
1961 echo "got stage command succeeded unexpectedly" >&2
1962 test_done "$testroot" "1"
1966 echo "got: epsilon/new: no changes to stage" > $testroot/stderr.expected
1967 cmp -s $testroot/stderr.expected $testroot/stderr
1969 if [ "$ret" != "0" ]; then
1970 diff -u $testroot/stderr.expected $testroot/stderr
1971 test_done "$testroot" "$ret"
1975 echo -n > $testroot/stdout.expected
1976 cmp -s $testroot/stdout.expected $testroot/stdout
1978 if [ "$ret" != "0" ]; then
1979 diff -u $testroot/stdout.expected $testroot/stdout
1981 test_done "$testroot" "$ret"
1984 function test_stage_patch_removed {
1985 local testroot=`test_init stage_patch_removed`
1986 local commit_id=`git_show_head $testroot/repo`
1988 got checkout $testroot/repo $testroot/wt > /dev/null
1990 if [ "$ret" != "0" ]; then
1991 test_done "$testroot" "$ret"
1995 (cd $testroot/wt && got rm beta > /dev/null)
1997 printf "y\n" > $testroot/patchscript
1998 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1999 beta > $testroot/stdout)
2001 echo -n > $testroot/stdout.expected
2003 echo "D beta" > $testroot/stdout.expected
2004 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2005 cmp -s $testroot/stdout.expected $testroot/stdout
2007 if [ "$ret" != "0" ]; then
2008 diff -u $testroot/stdout.expected $testroot/stdout
2009 test_done "$testroot" "$ret"
2013 (cd $testroot/wt && got status > $testroot/stdout)
2014 echo " D beta" > $testroot/stdout.expected
2015 cmp -s $testroot/stdout.expected $testroot/stdout
2017 if [ "$ret" != "0" ]; then
2018 diff -u $testroot/stdout.expected $testroot/stdout
2019 test_done "$testroot" "$ret"
2023 (cd $testroot/wt && got diff -s > $testroot/stdout)
2025 echo "diff $commit_id $testroot/wt (staged changes)" \
2026 > $testroot/stdout.expected
2027 echo -n 'blob - ' >> $testroot/stdout.expected
2028 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2029 >> $testroot/stdout.expected
2030 echo 'blob + /dev/null' >> $testroot/stdout.expected
2031 echo "--- beta" >> $testroot/stdout.expected
2032 echo "+++ /dev/null" >> $testroot/stdout.expected
2033 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2034 echo "-beta" >> $testroot/stdout.expected
2035 cmp -s $testroot/stdout.expected $testroot/stdout
2037 if [ "$ret" != "0" ]; then
2038 diff -u $testroot/stdout.expected $testroot/stdout
2040 test_done "$testroot" "$ret"
2043 function test_stage_patch_removed_twice {
2044 local testroot=`test_init stage_patch_removed_twice`
2045 local commit_id=`git_show_head $testroot/repo`
2047 got checkout $testroot/repo $testroot/wt > /dev/null
2049 if [ "$ret" != "0" ]; then
2050 test_done "$testroot" "$ret"
2054 (cd $testroot/wt && got rm beta > /dev/null)
2056 printf "y\n" > $testroot/patchscript
2057 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2058 beta > $testroot/stdout)
2060 echo -n > $testroot/stdout.expected
2062 echo "D beta" > $testroot/stdout.expected
2063 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2064 cmp -s $testroot/stdout.expected $testroot/stdout
2066 if [ "$ret" != "0" ]; then
2067 diff -u $testroot/stdout.expected $testroot/stdout
2068 test_done "$testroot" "$ret"
2072 (cd $testroot/wt && got status > $testroot/stdout)
2073 echo " D beta" > $testroot/stdout.expected
2074 cmp -s $testroot/stdout.expected $testroot/stdout
2076 if [ "$ret" != "0" ]; then
2077 diff -u $testroot/stdout.expected $testroot/stdout
2078 test_done "$testroot" "$ret"
2082 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2083 > $testroot/stdout 2> $testroot/stderr)
2085 if [ "$ret" != "0" ]; then
2086 echo "got stage command failed unexpectedly" >&2
2087 test_done "$testroot" "$ret"
2091 echo -n > $testroot/stderr.expected
2092 cmp -s $testroot/stderr.expected $testroot/stderr
2094 if [ "$ret" != "0" ]; then
2095 diff -u $testroot/stderr.expected $testroot/stderr
2096 test_done "$testroot" "$ret"
2100 echo -n > $testroot/stdout.expected
2101 cmp -s $testroot/stdout.expected $testroot/stdout
2103 if [ "$ret" != "0" ]; then
2104 diff -u $testroot/stdout.expected $testroot/stdout
2106 test_done "$testroot" "$ret"
2109 function test_stage_patch_quit {
2110 local testroot=`test_init stage_patch_quit`
2112 jot 16 > $testroot/repo/numbers
2113 echo zzz > $testroot/repo/zzz
2114 (cd $testroot/repo && git add numbers zzz)
2115 git_commit $testroot/repo -m "added files"
2116 local commit_id=`git_show_head $testroot/repo`
2118 got checkout $testroot/repo $testroot/wt > /dev/null
2120 if [ "$ret" != "0" ]; then
2121 test_done "$testroot" "$ret"
2125 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2126 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2127 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2128 (cd $testroot/wt && got rm zzz > /dev/null)
2130 # stage first hunk and quit; and don't pass a path argument to
2131 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2132 printf "y\nq\nn\n" > $testroot/patchscript
2133 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2136 if [ "$ret" != "0" ]; then
2137 echo "got stage command failed unexpectedly" >&2
2138 test_done "$testroot" "1"
2141 cat > $testroot/stdout.expected <<EOF
2142 -----------------------------------------------
2150 -----------------------------------------------
2151 M numbers (change 1 of 3)
2152 stage this change? [y/n/q] y
2153 -----------------------------------------------
2163 -----------------------------------------------
2164 M numbers (change 2 of 3)
2165 stage this change? [y/n/q] q
2167 stage this deletion? [y/n] n
2169 cmp -s $testroot/stdout.expected $testroot/stdout
2171 if [ "$ret" != "0" ]; then
2172 diff -u $testroot/stdout.expected $testroot/stdout
2173 test_done "$testroot" "$ret"
2177 (cd $testroot/wt && got status > $testroot/stdout)
2178 echo "MM numbers" > $testroot/stdout.expected
2179 echo "D zzz" >> $testroot/stdout.expected
2180 cmp -s $testroot/stdout.expected $testroot/stdout
2182 if [ "$ret" != "0" ]; then
2183 diff -u $testroot/stdout.expected $testroot/stdout
2184 test_done "$testroot" "$ret"
2188 (cd $testroot/wt && got diff -s > $testroot/stdout)
2190 echo "diff $commit_id $testroot/wt (staged changes)" \
2191 > $testroot/stdout.expected
2192 echo -n 'blob - ' >> $testroot/stdout.expected
2193 got tree -r $testroot/repo -i -c $commit_id \
2194 | grep 'numbers$' | cut -d' ' -f 1 \
2195 >> $testroot/stdout.expected
2196 echo -n 'blob + ' >> $testroot/stdout.expected
2197 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2198 >> $testroot/stdout.expected
2199 echo "--- numbers" >> $testroot/stdout.expected
2200 echo "+++ numbers" >> $testroot/stdout.expected
2201 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2202 echo " 1" >> $testroot/stdout.expected
2203 echo "-2" >> $testroot/stdout.expected
2204 echo "+a" >> $testroot/stdout.expected
2205 echo " 3" >> $testroot/stdout.expected
2206 echo " 4" >> $testroot/stdout.expected
2207 echo " 5" >> $testroot/stdout.expected
2208 cmp -s $testroot/stdout.expected $testroot/stdout
2210 if [ "$ret" != "0" ]; then
2211 diff -u $testroot/stdout.expected $testroot/stdout
2213 test_done "$testroot" "$ret"
2217 function test_stage_patch_incomplete_script {
2218 local testroot=`test_init stage_incomplete_script`
2220 jot 16 > $testroot/repo/numbers
2221 echo zzz > $testroot/repo/zzz
2222 (cd $testroot/repo && git add numbers zzz)
2223 git_commit $testroot/repo -m "added files"
2224 local commit_id=`git_show_head $testroot/repo`
2226 got checkout $testroot/repo $testroot/wt > /dev/null
2228 if [ "$ret" != "0" ]; then
2229 test_done "$testroot" "$ret"
2233 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2234 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2235 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2237 # stage first hunk and then stop responding; got should error out
2238 printf "y\n" > $testroot/patchscript
2239 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2240 > $testroot/stdout 2> $testroot/stderr)
2242 if [ "$ret" == "0" ]; then
2243 echo "got stage command succeeded unexpectedly" >&2
2244 test_done "$testroot" "1"
2247 cat > $testroot/stdout.expected <<EOF
2248 -----------------------------------------------
2256 -----------------------------------------------
2257 M numbers (change 1 of 3)
2258 stage this change? [y/n/q] y
2259 -----------------------------------------------
2269 -----------------------------------------------
2270 M numbers (change 2 of 3)
2272 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2273 echo "got: invalid patch choice" > $testroot/stderr.expected
2274 cmp -s $testroot/stderr.expected $testroot/stderr
2276 if [ "$ret" != "0" ]; then
2277 diff -u $testroot/stderr.expected $testroot/stderr
2278 test_done "$testroot" "$ret"
2282 cmp -s $testroot/stdout.expected $testroot/stdout
2284 if [ "$ret" != "0" ]; then
2285 diff -u $testroot/stdout.expected $testroot/stdout
2286 test_done "$testroot" "$ret"
2290 (cd $testroot/wt && got status > $testroot/stdout)
2291 echo "M numbers" > $testroot/stdout.expected
2292 cmp -s $testroot/stdout.expected $testroot/stdout
2294 if [ "$ret" != "0" ]; then
2295 diff -u $testroot/stdout.expected $testroot/stdout
2296 test_done "$testroot" "$ret"
2300 (cd $testroot/wt && got diff -s > $testroot/stdout)
2301 echo -n > $testroot/stdout.expected
2302 cmp -s $testroot/stdout.expected $testroot/stdout
2304 if [ "$ret" != "0" ]; then
2305 diff -u $testroot/stdout.expected $testroot/stdout
2307 test_done "$testroot" "$ret"
2311 run_test test_stage_basic
2312 run_test test_stage_no_changes
2313 run_test test_stage_unversioned
2314 run_test test_stage_nonexistent
2315 run_test test_stage_list
2316 run_test test_stage_conflict
2317 run_test test_stage_out_of_date
2318 run_test test_double_stage
2319 run_test test_stage_status
2320 run_test test_stage_add_already_staged_file
2321 run_test test_stage_rm_already_staged_file
2322 run_test test_stage_revert
2323 run_test test_stage_diff
2324 run_test test_stage_histedit
2325 run_test test_stage_rebase
2326 run_test test_stage_update
2327 run_test test_stage_commit_non_staged
2328 run_test test_stage_commit_out_of_date
2329 run_test test_stage_commit
2330 run_test test_stage_patch
2331 run_test test_stage_patch_twice
2332 run_test test_stage_patch_added
2333 run_test test_stage_patch_added_twice
2334 run_test test_stage_patch_removed
2335 run_test test_stage_patch_removed_twice
2336 run_test test_stage_patch_quit
2337 run_test test_stage_patch_incomplete_script