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 succeeded unexpectedly" >&2
713 test_done "$testroot" "1"
717 echo "got: beta: file is staged" > $testroot/stderr.expected
718 cmp -s $testroot/stderr.expected $testroot/stderr
720 if [ "$ret" != "0" ]; then
721 diff -u $testroot/stderr.expected $testroot/stderr
722 test_done "$testroot" "$ret"
726 (cd $testroot/wt && got revert foo > $testroot/stdout)
728 if [ "$ret" != "0" ]; then
729 echo "revert command failed unexpectedly" >&2
730 test_done "$testroot" "$ret"
734 echo "R foo" > $testroot/stdout.expected
735 cmp -s $testroot/stdout.expected $testroot/stdout
737 if [ "$ret" != "0" ]; then
738 diff -u $testroot/stdout.expected $testroot/stdout
739 test_done "$testroot" "$ret"
743 echo "new file" > $testroot/content.expected
744 cat $testroot/wt/foo > $testroot/content
745 cmp -s $testroot/content.expected $testroot/content
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/content.expected $testroot/content
749 test_done "$testroot" "$ret"
753 echo ' M alpha' > $testroot/stdout.expected
754 echo ' D beta' >> $testroot/stdout.expected
755 echo ' A foo' >> $testroot/stdout.expected
756 (cd $testroot/wt && got status > $testroot/stdout)
757 cmp -s $testroot/stdout.expected $testroot/stdout
759 if [ "$ret" != "0" ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
761 test_done "$testroot" "$ret"
765 (cd $testroot/wt && got revert foo > $testroot/stdout)
767 if [ "$ret" != "0" ]; then
768 echo "revert command failed unexpectedly" >&2
769 test_done "$testroot" "$ret"
773 echo -n > $testroot/stdout.expected
774 cmp -s $testroot/stdout.expected $testroot/stdout
776 if [ "$ret" != "0" ]; then
777 diff -u $testroot/stdout.expected $testroot/stdout
778 test_done "$testroot" "$ret"
782 echo "new file" > $testroot/content.expected
783 cat $testroot/wt/foo > $testroot/content
784 cmp -s $testroot/content.expected $testroot/content
786 if [ "$ret" != "0" ]; then
787 diff -u $testroot/content.expected $testroot/content
788 test_done "$testroot" "$ret"
792 echo ' M alpha' > $testroot/stdout.expected
793 echo ' D beta' >> $testroot/stdout.expected
794 echo ' A foo' >> $testroot/stdout.expected
795 (cd $testroot/wt && got status > $testroot/stdout)
796 cmp -s $testroot/stdout.expected $testroot/stdout
798 if [ "$ret" != "0" ]; then
799 diff -u $testroot/stdout.expected $testroot/stdout
801 test_done "$testroot" "$ret"
804 function test_stage_diff {
805 local testroot=`test_init stage_diff`
806 local head_commit=`git_show_head $testroot/repo`
808 got checkout $testroot/repo $testroot/wt > /dev/null
810 if [ "$ret" != "0" ]; then
811 test_done "$testroot" "$ret"
815 echo "modified file" > $testroot/wt/alpha
816 (cd $testroot/wt && got rm beta > /dev/null)
817 echo "new file" > $testroot/wt/foo
818 (cd $testroot/wt && got add foo > /dev/null)
820 (cd $testroot/wt && got diff -s > $testroot/stdout)
821 echo -n > $testroot/stdout.expected
822 cmp -s $testroot/stdout.expected $testroot/stdout
824 if [ "$ret" != "0" ]; then
825 diff -u $testroot/stdout.expected $testroot/stdout
826 test_done "$testroot" "$ret"
830 echo ' M alpha' > $testroot/stdout.expected
831 echo ' D beta' >> $testroot/stdout.expected
832 echo ' A foo' >> $testroot/stdout.expected
833 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
835 (cd $testroot/wt && got diff > $testroot/stdout)
836 echo -n > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
841 test_done "$testroot" "$ret"
845 echo "modified file again" > $testroot/wt/alpha
846 echo "new file changed" > $testroot/wt/foo
848 (cd $testroot/wt && got diff > $testroot/stdout)
850 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
851 echo -n 'blob - ' >> $testroot/stdout.expected
852 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
853 >> $testroot/stdout.expected
854 echo ' (staged)' >> $testroot/stdout.expected
855 echo 'file + alpha' >> $testroot/stdout.expected
856 echo '--- alpha' >> $testroot/stdout.expected
857 echo '+++ alpha' >> $testroot/stdout.expected
858 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
859 echo '-modified file' >> $testroot/stdout.expected
860 echo '+modified file again' >> $testroot/stdout.expected
861 echo -n 'blob - ' >> $testroot/stdout.expected
862 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
863 >> $testroot/stdout.expected
864 echo " (staged)" >> $testroot/stdout.expected
865 echo 'file + foo' >> $testroot/stdout.expected
866 echo '--- foo' >> $testroot/stdout.expected
867 echo '+++ foo' >> $testroot/stdout.expected
868 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
869 echo '-new file' >> $testroot/stdout.expected
870 echo '+new file changed' >> $testroot/stdout.expected
872 cmp -s $testroot/stdout.expected $testroot/stdout
874 if [ "$ret" != "0" ]; then
875 diff -u $testroot/stdout.expected $testroot/stdout
876 test_done "$testroot" "$ret"
880 (cd $testroot/wt && got diff -s > $testroot/stdout)
882 echo "diff $head_commit $testroot/wt (staged changes)" \
883 > $testroot/stdout.expected
884 echo -n 'blob - ' >> $testroot/stdout.expected
885 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
886 >> $testroot/stdout.expected
887 echo -n 'blob + ' >> $testroot/stdout.expected
888 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
889 >> $testroot/stdout.expected
890 echo '--- alpha' >> $testroot/stdout.expected
891 echo '+++ alpha' >> $testroot/stdout.expected
892 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
893 echo '-alpha' >> $testroot/stdout.expected
894 echo '+modified file' >> $testroot/stdout.expected
895 echo -n 'blob - ' >> $testroot/stdout.expected
896 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
897 >> $testroot/stdout.expected
898 echo 'blob + /dev/null' >> $testroot/stdout.expected
899 echo '--- beta' >> $testroot/stdout.expected
900 echo '+++ /dev/null' >> $testroot/stdout.expected
901 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
902 echo '-beta' >> $testroot/stdout.expected
903 echo 'blob - /dev/null' >> $testroot/stdout.expected
904 echo -n 'blob + ' >> $testroot/stdout.expected
905 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
906 >> $testroot/stdout.expected
907 echo '--- /dev/null' >> $testroot/stdout.expected
908 echo '+++ foo' >> $testroot/stdout.expected
909 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
910 echo '+new file' >> $testroot/stdout.expected
912 cmp -s $testroot/stdout.expected $testroot/stdout
914 if [ "$ret" != "0" ]; then
915 diff -u $testroot/stdout.expected $testroot/stdout
917 test_done "$testroot" "$ret"
921 function test_stage_histedit {
922 local testroot=`test_init stage_histedit`
923 local orig_commit=`git_show_head $testroot/repo`
925 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
927 if [ "$ret" != "0" ]; then
928 test_done "$testroot" "$ret"
932 echo "modified file" > $testroot/wt/alpha
933 (cd $testroot/wt && got stage alpha > /dev/null)
935 echo "modified alpha on master" > $testroot/repo/alpha
936 (cd $testroot/repo && git rm -q beta)
937 echo "new file on master" > $testroot/repo/epsilon/new
938 (cd $testroot/repo && git add epsilon/new)
939 git_commit $testroot/repo -m "committing changes"
940 local old_commit1=`git_show_head $testroot/repo`
942 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
943 git_commit $testroot/repo -m "committing to zeta on master"
944 local old_commit2=`git_show_head $testroot/repo`
946 echo "pick $old_commit1" > $testroot/histedit-script
947 echo "pick $old_commit2" >> $testroot/histedit-script
949 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
950 > $testroot/stdout 2> $testroot/stderr)
952 if [ "$ret" == "0" ]; then
953 echo "got histedit command succeeded unexpectedly" >&2
954 test_done "$testroot" "1"
958 echo -n > $testroot/stdout.expected
959 echo "got: alpha: file is staged" > $testroot/stderr.expected
961 cmp -s $testroot/stderr.expected $testroot/stderr
963 if [ "$ret" != "0" ]; then
964 diff -u $testroot/stderr.expected $testroot/stderr
965 test_done "$testroot" "$ret"
968 cmp -s $testroot/stdout.expected $testroot/stdout
970 if [ "$ret" != "0" ]; then
971 diff -u $testroot/stdout.expected $testroot/stdout
973 test_done "$testroot" "$ret"
977 function test_stage_rebase {
978 local testroot=`test_init stage_rebase`
980 (cd $testroot/repo && git checkout -q -b newbranch)
981 echo "modified delta on branch" > $testroot/repo/gamma/delta
982 git_commit $testroot/repo -m "committing to delta on newbranch"
984 echo "modified alpha on branch" > $testroot/repo/alpha
985 (cd $testroot/repo && git rm -q beta)
986 echo "new file on branch" > $testroot/repo/epsilon/new
987 (cd $testroot/repo && git add epsilon/new)
988 git_commit $testroot/repo -m "committing more changes on newbranch"
990 local orig_commit1=`git_show_parent_commit $testroot/repo`
991 local orig_commit2=`git_show_head $testroot/repo`
993 (cd $testroot/repo && git checkout -q master)
994 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
995 git_commit $testroot/repo -m "committing to zeta on master"
996 local master_commit=`git_show_head $testroot/repo`
998 got checkout $testroot/repo $testroot/wt > /dev/null
1000 if [ "$ret" != "0" ]; then
1001 test_done "$testroot" "$ret"
1005 echo "modified file" > $testroot/wt/alpha
1006 (cd $testroot/wt && got stage alpha > /dev/null)
1008 (cd $testroot/wt && got rebase newbranch \
1009 > $testroot/stdout 2> $testroot/stderr)
1011 if [ "$ret" == "0" ]; then
1012 echo "got rebase command succeeded unexpectedly" >&2
1013 test_done "$testroot" "1"
1017 echo -n > $testroot/stdout.expected
1018 echo "got: alpha: file is staged" > $testroot/stderr.expected
1020 cmp -s $testroot/stderr.expected $testroot/stderr
1022 if [ "$ret" != "0" ]; then
1023 diff -u $testroot/stderr.expected $testroot/stderr
1024 test_done "$testroot" "$ret"
1027 cmp -s $testroot/stdout.expected $testroot/stdout
1029 if [ "$ret" != "0" ]; then
1030 diff -u $testroot/stdout.expected $testroot/stdout
1032 test_done "$testroot" "$ret"
1035 function test_stage_update {
1036 local testroot=`test_init stage_update`
1038 got checkout $testroot/repo $testroot/wt > /dev/null
1040 if [ "$ret" != "0" ]; then
1041 test_done "$testroot" "$ret"
1045 echo "modified file" > $testroot/wt/alpha
1046 (cd $testroot/wt && got stage alpha > /dev/null)
1048 echo "modified alpha" > $testroot/repo/alpha
1049 git_commit $testroot/repo -m "modified alpha"
1051 (cd $testroot/wt && got update > $testroot/stdout \
1052 2> $testroot/stderr)
1054 if [ "$ret" == "0" ]; then
1055 echo "got update command succeeded unexpectedly" >&2
1056 test_done "$testroot" "1"
1060 echo -n > $testroot/stdout.expected
1061 echo "got: alpha: file is staged" > $testroot/stderr.expected
1063 cmp -s $testroot/stderr.expected $testroot/stderr
1065 if [ "$ret" != "0" ]; then
1066 diff -u $testroot/stderr.expected $testroot/stderr
1067 test_done "$testroot" "$ret"
1070 cmp -s $testroot/stdout.expected $testroot/stdout
1072 if [ "$ret" != "0" ]; then
1073 diff -u $testroot/stdout.expected $testroot/stdout
1075 test_done "$testroot" "$ret"
1078 function test_stage_commit_non_staged {
1079 local testroot=`test_init stage_commit_non_staged`
1081 got checkout $testroot/repo $testroot/wt > /dev/null
1083 if [ "$ret" != "0" ]; then
1084 test_done "$testroot" "$ret"
1088 echo "modified file" > $testroot/wt/alpha
1089 (cd $testroot/wt && got rm beta > /dev/null)
1090 echo "new file" > $testroot/wt/foo
1091 (cd $testroot/wt && got add foo > /dev/null)
1092 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1094 echo "modified file" > $testroot/wt/gamma/delta
1095 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1096 > $testroot/stdout 2> $testroot/stderr)
1098 if [ "$ret" == "0" ]; then
1099 echo "got commit command succeeded unexpectedly" >&2
1100 test_done "$testroot" "1"
1104 echo -n > $testroot/stdout.expected
1105 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1107 cmp -s $testroot/stderr.expected $testroot/stderr
1109 if [ "$ret" != "0" ]; then
1110 diff -u $testroot/stderr.expected $testroot/stderr
1111 test_done "$testroot" "$ret"
1114 cmp -s $testroot/stdout.expected $testroot/stdout
1116 if [ "$ret" != "0" ]; then
1117 diff -u $testroot/stdout.expected $testroot/stdout
1119 test_done "$testroot" "$ret"
1122 function test_stage_commit {
1123 local testroot=`test_init stage_commit`
1124 local first_commit=`git_show_head $testroot/repo`
1126 got checkout $testroot/repo $testroot/wt > /dev/null
1128 if [ "$ret" != "0" ]; then
1129 test_done "$testroot" "$ret"
1133 echo "modified file" > $testroot/wt/alpha
1134 (cd $testroot/wt && got rm beta > /dev/null)
1135 echo "new file" > $testroot/wt/foo
1136 (cd $testroot/wt && got add foo > /dev/null)
1137 echo "modified file" > $testroot/wt/alpha
1138 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1140 echo "modified file again" > $testroot/wt/alpha
1141 echo "new file changed" > $testroot/wt/foo
1142 echo "non-staged change" > $testroot/wt/gamma/delta
1143 echo "non-staged new file" > $testroot/wt/epsilon/new
1144 (cd $testroot/wt && got add epsilon/new > /dev/null)
1145 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1147 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1148 > $testroot/blob_id_alpha
1149 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1150 > $testroot/blob_id_foo
1152 (cd $testroot/wt && got commit -m "staged changes" \
1155 if [ "$ret" != "0" ]; then
1156 echo "got commit command failed unexpectedly" >&2
1157 test_done "$testroot" "1"
1161 local head_commit=`git_show_head $testroot/repo`
1162 echo "A foo" > $testroot/stdout.expected
1163 echo "M alpha" >> $testroot/stdout.expected
1164 echo "D beta" >> $testroot/stdout.expected
1165 echo "Created commit $head_commit" >> $testroot/stdout.expected
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1169 if [ "$ret" != "0" ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1171 test_done "$testroot" "$ret"
1175 got diff -r $testroot/repo $first_commit $head_commit \
1178 echo "diff $first_commit $head_commit" \
1179 > $testroot/stdout.expected
1180 echo -n 'blob - ' >> $testroot/stdout.expected
1181 got tree -r $testroot/repo -i -c $first_commit | \
1182 grep 'alpha$' | cut -d' ' -f 1 \
1183 >> $testroot/stdout.expected
1184 echo -n 'blob + ' >> $testroot/stdout.expected
1185 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1186 echo '--- alpha' >> $testroot/stdout.expected
1187 echo '+++ alpha' >> $testroot/stdout.expected
1188 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1189 echo '-alpha' >> $testroot/stdout.expected
1190 echo '+modified file' >> $testroot/stdout.expected
1191 echo -n 'blob - ' >> $testroot/stdout.expected
1192 got tree -r $testroot/repo -i -c $first_commit \
1193 | grep 'beta$' | cut -d' ' -f 1 \
1194 >> $testroot/stdout.expected
1195 echo 'blob + /dev/null' >> $testroot/stdout.expected
1196 echo '--- beta' >> $testroot/stdout.expected
1197 echo '+++ /dev/null' >> $testroot/stdout.expected
1198 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1199 echo '-beta' >> $testroot/stdout.expected
1200 echo 'blob - /dev/null' >> $testroot/stdout.expected
1201 echo -n 'blob + ' >> $testroot/stdout.expected
1202 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1203 echo '--- /dev/null' >> $testroot/stdout.expected
1204 echo '+++ foo' >> $testroot/stdout.expected
1205 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1206 echo '+new file' >> $testroot/stdout.expected
1208 cmp -s $testroot/stdout.expected $testroot/stdout
1210 if [ "$ret" != "0" ]; then
1211 diff -u $testroot/stdout.expected $testroot/stdout
1212 test_done "$testroot" "$ret"
1216 echo 'A epsilon/new' > $testroot/stdout.expected
1217 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1218 echo 'M gamma/delta' >> $testroot/stdout.expected
1220 (cd $testroot/wt && got status > $testroot/stdout)
1221 cmp -s $testroot/stdout.expected $testroot/stdout
1223 if [ "$ret" != "0" ]; then
1224 diff -u $testroot/stdout.expected $testroot/stdout
1226 test_done "$testroot" "$ret"
1229 function test_stage_patch {
1230 local testroot=`test_init stage_patch`
1232 jot 16 > $testroot/repo/numbers
1233 (cd $testroot/repo && git add numbers)
1234 git_commit $testroot/repo -m "added numbers file"
1235 local commit_id=`git_show_head $testroot/repo`
1237 got checkout $testroot/repo $testroot/wt > /dev/null
1239 if [ "$ret" != "0" ]; then
1240 test_done "$testroot" "$ret"
1244 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1245 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1246 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1248 # don't stage any hunks
1249 printf "n\nn\nn\n" > $testroot/patchscript
1250 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1251 numbers > $testroot/stdout)
1253 if [ "$ret" != "0" ]; then
1254 echo "got stage command failed unexpectedly" >&2
1255 test_done "$testroot" "1"
1258 cat > $testroot/stdout.expected <<EOF
1259 -----------------------------------------------
1267 -----------------------------------------------
1268 M numbers (change 1 of 3)
1269 stage this change? [y/n/q] n
1270 -----------------------------------------------
1280 -----------------------------------------------
1281 M numbers (change 2 of 3)
1282 stage this change? [y/n/q] n
1283 -----------------------------------------------
1290 -----------------------------------------------
1291 M numbers (change 3 of 3)
1292 stage this change? [y/n/q] n
1294 cmp -s $testroot/stdout.expected $testroot/stdout
1296 if [ "$ret" != "0" ]; then
1297 diff -u $testroot/stdout.expected $testroot/stdout
1298 test_done "$testroot" "$ret"
1302 (cd $testroot/wt && got status > $testroot/stdout)
1303 echo "M numbers" > $testroot/stdout.expected
1304 cmp -s $testroot/stdout.expected $testroot/stdout
1306 if [ "$ret" != "0" ]; then
1307 diff -u $testroot/stdout.expected $testroot/stdout
1308 test_done "$testroot" "$ret"
1313 printf "n\ny\nn\n" > $testroot/patchscript
1314 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1315 numbers > $testroot/stdout)
1317 cat > $testroot/stdout.expected <<EOF
1318 -----------------------------------------------
1326 -----------------------------------------------
1327 M numbers (change 1 of 3)
1328 stage this change? [y/n/q] n
1329 -----------------------------------------------
1339 -----------------------------------------------
1340 M numbers (change 2 of 3)
1341 stage this change? [y/n/q] y
1342 -----------------------------------------------
1349 -----------------------------------------------
1350 M numbers (change 3 of 3)
1351 stage this change? [y/n/q] n
1353 cmp -s $testroot/stdout.expected $testroot/stdout
1355 if [ "$ret" != "0" ]; then
1356 diff -u $testroot/stdout.expected $testroot/stdout
1357 test_done "$testroot" "$ret"
1361 (cd $testroot/wt && got status > $testroot/stdout)
1362 echo "MM numbers" > $testroot/stdout.expected
1363 cmp -s $testroot/stdout.expected $testroot/stdout
1365 if [ "$ret" != "0" ]; then
1366 diff -u $testroot/stdout.expected $testroot/stdout
1367 test_done "$testroot" "$ret"
1371 (cd $testroot/wt && got diff -s > $testroot/stdout)
1373 echo "diff $commit_id $testroot/wt (staged changes)" \
1374 > $testroot/stdout.expected
1375 echo -n 'blob - ' >> $testroot/stdout.expected
1376 got tree -r $testroot/repo -i -c $commit_id \
1377 | grep 'numbers$' | cut -d' ' -f 1 \
1378 >> $testroot/stdout.expected
1379 echo -n 'blob + ' >> $testroot/stdout.expected
1380 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1381 >> $testroot/stdout.expected
1382 echo "--- numbers" >> $testroot/stdout.expected
1383 echo "+++ numbers" >> $testroot/stdout.expected
1384 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1385 echo " 4" >> $testroot/stdout.expected
1386 echo " 5" >> $testroot/stdout.expected
1387 echo " 6" >> $testroot/stdout.expected
1388 echo "-7" >> $testroot/stdout.expected
1389 echo "+b" >> $testroot/stdout.expected
1390 echo " 8" >> $testroot/stdout.expected
1391 echo " 9" >> $testroot/stdout.expected
1392 echo " 10" >> $testroot/stdout.expected
1393 cmp -s $testroot/stdout.expected $testroot/stdout
1395 if [ "$ret" != "0" ]; then
1396 diff -u $testroot/stdout.expected $testroot/stdout
1397 test_done "$testroot" "$ret"
1401 (cd $testroot/wt && got unstage >/dev/null)
1403 if [ "$ret" != "0" ]; then
1404 echo "got stage command failed unexpectedly" >&2
1405 test_done "$testroot" "1"
1408 (cd $testroot/wt && got status > $testroot/stdout)
1409 echo "M numbers" > $testroot/stdout.expected
1410 cmp -s $testroot/stdout.expected $testroot/stdout
1412 if [ "$ret" != "0" ]; then
1413 diff -u $testroot/stdout.expected $testroot/stdout
1414 test_done "$testroot" "$ret"
1419 printf "n\nn\ny\n" > $testroot/patchscript
1420 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1421 numbers > $testroot/stdout)
1423 cat > $testroot/stdout.expected <<EOF
1424 -----------------------------------------------
1432 -----------------------------------------------
1433 M numbers (change 1 of 3)
1434 stage this change? [y/n/q] n
1435 -----------------------------------------------
1445 -----------------------------------------------
1446 M numbers (change 2 of 3)
1447 stage this change? [y/n/q] n
1448 -----------------------------------------------
1455 -----------------------------------------------
1456 M numbers (change 3 of 3)
1457 stage this change? [y/n/q] y
1459 cmp -s $testroot/stdout.expected $testroot/stdout
1461 if [ "$ret" != "0" ]; then
1462 diff -u $testroot/stdout.expected $testroot/stdout
1463 test_done "$testroot" "$ret"
1467 (cd $testroot/wt && got status > $testroot/stdout)
1468 echo "MM numbers" > $testroot/stdout.expected
1469 cmp -s $testroot/stdout.expected $testroot/stdout
1471 if [ "$ret" != "0" ]; then
1472 diff -u $testroot/stdout.expected $testroot/stdout
1473 test_done "$testroot" "$ret"
1477 (cd $testroot/wt && got diff -s > $testroot/stdout)
1479 echo "diff $commit_id $testroot/wt (staged changes)" \
1480 > $testroot/stdout.expected
1481 echo -n 'blob - ' >> $testroot/stdout.expected
1482 got tree -r $testroot/repo -i -c $commit_id \
1483 | grep 'numbers$' | cut -d' ' -f 1 \
1484 >> $testroot/stdout.expected
1485 echo -n 'blob + ' >> $testroot/stdout.expected
1486 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1487 >> $testroot/stdout.expected
1488 echo "--- numbers" >> $testroot/stdout.expected
1489 echo "+++ numbers" >> $testroot/stdout.expected
1490 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1491 echo " 13" >> $testroot/stdout.expected
1492 echo " 14" >> $testroot/stdout.expected
1493 echo " 15" >> $testroot/stdout.expected
1494 echo "-16" >> $testroot/stdout.expected
1495 echo "+c" >> $testroot/stdout.expected
1496 cmp -s $testroot/stdout.expected $testroot/stdout
1498 if [ "$ret" != "0" ]; then
1499 diff -u $testroot/stdout.expected $testroot/stdout
1501 test_done "$testroot" "$ret"
1504 function test_stage_patch_added {
1505 local testroot=`test_init stage_patch_added`
1506 local commit_id=`git_show_head $testroot/repo`
1508 got checkout $testroot/repo $testroot/wt > /dev/null
1510 if [ "$ret" != "0" ]; then
1511 test_done "$testroot" "$ret"
1515 echo "new" > $testroot/wt/epsilon/new
1516 (cd $testroot/wt && got add epsilon/new > /dev/null)
1518 printf "y\n" > $testroot/patchscript
1519 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1520 epsilon/new > $testroot/stdout)
1522 echo "A epsilon/new" > $testroot/stdout.expected
1523 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1524 cmp -s $testroot/stdout.expected $testroot/stdout
1526 if [ "$ret" != "0" ]; then
1527 diff -u $testroot/stdout.expected $testroot/stdout
1528 test_done "$testroot" "$ret"
1532 (cd $testroot/wt && got status > $testroot/stdout)
1533 echo " A epsilon/new" > $testroot/stdout.expected
1534 cmp -s $testroot/stdout.expected $testroot/stdout
1536 if [ "$ret" != "0" ]; then
1537 diff -u $testroot/stdout.expected $testroot/stdout
1538 test_done "$testroot" "$ret"
1542 (cd $testroot/wt && got diff -s > $testroot/stdout)
1544 echo "diff $commit_id $testroot/wt (staged changes)" \
1545 > $testroot/stdout.expected
1546 echo 'blob - /dev/null' >> $testroot/stdout.expected
1547 echo -n 'blob + ' >> $testroot/stdout.expected
1548 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1549 >> $testroot/stdout.expected
1550 echo "--- /dev/null" >> $testroot/stdout.expected
1551 echo "+++ epsilon/new" >> $testroot/stdout.expected
1552 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1553 echo "+new" >> $testroot/stdout.expected
1554 cmp -s $testroot/stdout.expected $testroot/stdout
1556 if [ "$ret" != "0" ]; then
1557 diff -u $testroot/stdout.expected $testroot/stdout
1559 test_done "$testroot" "$ret"
1562 function test_stage_patch_removed {
1563 local testroot=`test_init stage_patch_removed`
1564 local commit_id=`git_show_head $testroot/repo`
1566 got checkout $testroot/repo $testroot/wt > /dev/null
1568 if [ "$ret" != "0" ]; then
1569 test_done "$testroot" "$ret"
1573 (cd $testroot/wt && got rm beta > /dev/null)
1575 printf "y\n" > $testroot/patchscript
1576 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1577 beta > $testroot/stdout)
1579 echo -n > $testroot/stdout.expected
1581 echo "D beta" > $testroot/stdout.expected
1582 echo "stage this deletion? [y/n] y" >> $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"
1591 (cd $testroot/wt && got status > $testroot/stdout)
1592 echo " D beta" > $testroot/stdout.expected
1593 cmp -s $testroot/stdout.expected $testroot/stdout
1595 if [ "$ret" != "0" ]; then
1596 diff -u $testroot/stdout.expected $testroot/stdout
1597 test_done "$testroot" "$ret"
1601 (cd $testroot/wt && got diff -s > $testroot/stdout)
1603 echo "diff $commit_id $testroot/wt (staged changes)" \
1604 > $testroot/stdout.expected
1605 echo -n 'blob - ' >> $testroot/stdout.expected
1606 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
1607 >> $testroot/stdout.expected
1608 echo 'blob + /dev/null' >> $testroot/stdout.expected
1609 echo "--- beta" >> $testroot/stdout.expected
1610 echo "+++ /dev/null" >> $testroot/stdout.expected
1611 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
1612 echo "-beta" >> $testroot/stdout.expected
1613 cmp -s $testroot/stdout.expected $testroot/stdout
1615 if [ "$ret" != "0" ]; then
1616 diff -u $testroot/stdout.expected $testroot/stdout
1618 test_done "$testroot" "$ret"
1621 function test_stage_patch_quit {
1622 local testroot=`test_init stage_patch_quit`
1624 jot 16 > $testroot/repo/numbers
1625 echo zzz > $testroot/repo/zzz
1626 (cd $testroot/repo && git add numbers zzz)
1627 git_commit $testroot/repo -m "added files"
1628 local commit_id=`git_show_head $testroot/repo`
1630 got checkout $testroot/repo $testroot/wt > /dev/null
1632 if [ "$ret" != "0" ]; then
1633 test_done "$testroot" "$ret"
1637 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1638 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1639 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1640 (cd $testroot/wt && got rm zzz > /dev/null)
1642 # stage first hunk and quit; and don't pass a path argument to
1643 # ensure that we don't skip asking about the 'zzz' file after 'quit'
1644 printf "y\nq\nn\n" > $testroot/patchscript
1645 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1648 if [ "$ret" != "0" ]; then
1649 echo "got stage command failed unexpectedly" >&2
1650 test_done "$testroot" "1"
1653 cat > $testroot/stdout.expected <<EOF
1654 -----------------------------------------------
1662 -----------------------------------------------
1663 M numbers (change 1 of 3)
1664 stage this change? [y/n/q] y
1665 -----------------------------------------------
1675 -----------------------------------------------
1676 M numbers (change 2 of 3)
1677 stage this change? [y/n/q] q
1679 stage this deletion? [y/n] n
1681 cmp -s $testroot/stdout.expected $testroot/stdout
1683 if [ "$ret" != "0" ]; then
1684 diff -u $testroot/stdout.expected $testroot/stdout
1685 test_done "$testroot" "$ret"
1689 (cd $testroot/wt && got status > $testroot/stdout)
1690 echo "MM numbers" > $testroot/stdout.expected
1691 echo "D zzz" >> $testroot/stdout.expected
1692 cmp -s $testroot/stdout.expected $testroot/stdout
1694 if [ "$ret" != "0" ]; then
1695 diff -u $testroot/stdout.expected $testroot/stdout
1696 test_done "$testroot" "$ret"
1700 (cd $testroot/wt && got diff -s > $testroot/stdout)
1702 echo "diff $commit_id $testroot/wt (staged changes)" \
1703 > $testroot/stdout.expected
1704 echo -n 'blob - ' >> $testroot/stdout.expected
1705 got tree -r $testroot/repo -i -c $commit_id \
1706 | grep 'numbers$' | cut -d' ' -f 1 \
1707 >> $testroot/stdout.expected
1708 echo -n 'blob + ' >> $testroot/stdout.expected
1709 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1710 >> $testroot/stdout.expected
1711 echo "--- numbers" >> $testroot/stdout.expected
1712 echo "+++ numbers" >> $testroot/stdout.expected
1713 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
1714 echo " 1" >> $testroot/stdout.expected
1715 echo "-2" >> $testroot/stdout.expected
1716 echo "+a" >> $testroot/stdout.expected
1717 echo " 3" >> $testroot/stdout.expected
1718 echo " 4" >> $testroot/stdout.expected
1719 echo " 5" >> $testroot/stdout.expected
1720 cmp -s $testroot/stdout.expected $testroot/stdout
1722 if [ "$ret" != "0" ]; then
1723 diff -u $testroot/stdout.expected $testroot/stdout
1725 test_done "$testroot" "$ret"
1729 function test_stage_patch_incomplete_script {
1730 local testroot=`test_init stage_incomplete_script`
1732 jot 16 > $testroot/repo/numbers
1733 echo zzz > $testroot/repo/zzz
1734 (cd $testroot/repo && git add numbers zzz)
1735 git_commit $testroot/repo -m "added files"
1736 local commit_id=`git_show_head $testroot/repo`
1738 got checkout $testroot/repo $testroot/wt > /dev/null
1740 if [ "$ret" != "0" ]; then
1741 test_done "$testroot" "$ret"
1745 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1746 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1747 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1749 # stage first hunk and then stop responding; got should error out
1750 printf "y\n" > $testroot/patchscript
1751 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1752 > $testroot/stdout 2> $testroot/stderr)
1754 if [ "$ret" == "0" ]; then
1755 echo "got stage command succeeded unexpectedly" >&2
1756 test_done "$testroot" "1"
1759 cat > $testroot/stdout.expected <<EOF
1760 -----------------------------------------------
1768 -----------------------------------------------
1769 M numbers (change 1 of 3)
1770 stage this change? [y/n/q] y
1771 -----------------------------------------------
1781 -----------------------------------------------
1782 M numbers (change 2 of 3)
1784 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
1785 echo "got: invalid patch choice" > $testroot/stderr.expected
1786 cmp -s $testroot/stderr.expected $testroot/stderr
1788 if [ "$ret" != "0" ]; then
1789 diff -u $testroot/stderr.expected $testroot/stderr
1790 test_done "$testroot" "$ret"
1794 cmp -s $testroot/stdout.expected $testroot/stdout
1796 if [ "$ret" != "0" ]; then
1797 diff -u $testroot/stdout.expected $testroot/stdout
1798 test_done "$testroot" "$ret"
1802 (cd $testroot/wt && got status > $testroot/stdout)
1803 echo "M numbers" > $testroot/stdout.expected
1804 cmp -s $testroot/stdout.expected $testroot/stdout
1806 if [ "$ret" != "0" ]; then
1807 diff -u $testroot/stdout.expected $testroot/stdout
1808 test_done "$testroot" "$ret"
1812 (cd $testroot/wt && got diff -s > $testroot/stdout)
1813 echo -n > $testroot/stdout.expected
1814 cmp -s $testroot/stdout.expected $testroot/stdout
1816 if [ "$ret" != "0" ]; then
1817 diff -u $testroot/stdout.expected $testroot/stdout
1819 test_done "$testroot" "$ret"
1823 run_test test_stage_basic
1824 run_test test_stage_no_changes
1825 run_test test_stage_unversioned
1826 run_test test_stage_nonexistent
1827 run_test test_stage_list
1828 run_test test_stage_conflict
1829 run_test test_stage_out_of_date
1830 run_test test_double_stage
1831 run_test test_stage_status
1832 run_test test_stage_add_already_staged_file
1833 run_test test_stage_rm_already_staged_file
1834 run_test test_stage_revert
1835 run_test test_stage_diff
1836 run_test test_stage_histedit
1837 run_test test_stage_rebase
1838 run_test test_stage_update
1839 run_test test_stage_commit_non_staged
1840 run_test test_stage_commit
1841 run_test test_stage_patch
1842 run_test test_stage_patch_added
1843 run_test test_stage_patch_removed
1844 run_test test_stage_patch_quit
1845 run_test test_stage_patch_incomplete_script