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_out_of_date {
1123 local testroot=`test_init stage_commit_out_of_date`
1125 got checkout $testroot/repo $testroot/wt > /dev/null
1127 if [ "$ret" != "0" ]; then
1128 test_done "$testroot" "$ret"
1132 echo "modified file" > $testroot/wt/alpha
1133 (cd $testroot/wt && got rm beta > /dev/null)
1134 echo "new file" > $testroot/wt/foo
1135 (cd $testroot/wt && got add foo > /dev/null)
1136 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1138 echo "changed file" > $testroot/repo/alpha
1139 git_commit $testroot/repo -m "changed alpha in repo"
1141 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1142 2> $testroot/stderr)
1144 if [ "$ret" == "0" ]; then
1145 echo "got commit command succeeded unexpectedly" >&2
1146 test_done "$testroot" "1"
1150 echo -n > $testroot/stdout.expected
1151 echo -n "got: work tree must be updated before these changes " \
1152 > $testroot/stderr.expected
1153 echo "can be committed" >> $testroot/stderr.expected
1155 cmp -s $testroot/stderr.expected $testroot/stderr
1157 if [ "$ret" != "0" ]; then
1158 diff -u $testroot/stderr.expected $testroot/stderr
1159 test_done "$testroot" "$ret"
1162 cmp -s $testroot/stdout.expected $testroot/stdout
1164 if [ "$ret" != "0" ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1166 test_done "$testroot" "$ret"
1170 (cd $testroot/wt && got update > $testroot/stdout \
1171 2> $testroot/stderr)
1172 echo -n > $testroot/stdout.expected
1173 echo "got: alpha: file is staged" > $testroot/stderr.expected
1175 cmp -s $testroot/stderr.expected $testroot/stderr
1177 if [ "$ret" != "0" ]; then
1178 diff -u $testroot/stderr.expected $testroot/stderr
1179 test_done "$testroot" "$ret"
1182 cmp -s $testroot/stdout.expected $testroot/stdout
1184 if [ "$ret" != "0" ]; then
1185 diff -u $testroot/stdout.expected $testroot/stdout
1186 test_done "$testroot" "$ret"
1190 (cd $testroot/wt && got unstage > /dev/null)
1191 (cd $testroot/wt && got update > $testroot/stdout)
1193 if [ "$ret" != "0" ]; then
1194 echo "got update command failed unexpectedly" >&2
1195 test_done "$testroot" "$ret"
1199 (cd $testroot/wt && got status > $testroot/stdout)
1200 echo "C alpha" > $testroot/stdout.expected
1201 echo "D beta" >> $testroot/stdout.expected
1202 echo "A foo" >> $testroot/stdout.expected
1203 cmp -s $testroot/stdout.expected $testroot/stdout
1205 if [ "$ret" != "0" ]; then
1206 diff -u $testroot/stdout.expected $testroot/stdout
1207 test_done "$testroot" "$ret"
1212 echo "resolved file" > $testroot/wt/alpha
1214 (cd $testroot/wt && got stage > /dev/null)
1216 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1218 if [ "$ret" != "0" ]; then
1219 echo "got commit command failed unexpectedly" >&2
1220 test_done "$testroot" "$ret"
1224 local commit_id=`git_show_head $testroot/repo`
1225 echo "A foo" > $testroot/stdout.expected
1226 echo "M alpha" >> $testroot/stdout.expected
1227 echo "D beta" >> $testroot/stdout.expected
1228 echo "Created commit $commit_id" >> $testroot/stdout.expected
1229 cmp -s $testroot/stdout.expected $testroot/stdout
1231 if [ "$ret" != "0" ]; then
1232 diff -u $testroot/stdout.expected $testroot/stdout
1234 test_done "$testroot" "$ret"
1238 function test_stage_commit {
1239 local testroot=`test_init stage_commit`
1240 local first_commit=`git_show_head $testroot/repo`
1242 got checkout $testroot/repo $testroot/wt > /dev/null
1244 if [ "$ret" != "0" ]; then
1245 test_done "$testroot" "$ret"
1249 echo "modified file" > $testroot/wt/alpha
1250 (cd $testroot/wt && got rm beta > /dev/null)
1251 echo "new file" > $testroot/wt/foo
1252 (cd $testroot/wt && got add foo > /dev/null)
1253 echo "modified file" > $testroot/wt/alpha
1254 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1256 echo "modified file again" > $testroot/wt/alpha
1257 echo "new file changed" > $testroot/wt/foo
1258 echo "non-staged change" > $testroot/wt/gamma/delta
1259 echo "non-staged new file" > $testroot/wt/epsilon/new
1260 (cd $testroot/wt && got add epsilon/new > /dev/null)
1261 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1263 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1264 > $testroot/blob_id_alpha
1265 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1266 > $testroot/blob_id_foo
1268 (cd $testroot/wt && got commit -m "staged changes" \
1271 if [ "$ret" != "0" ]; then
1272 echo "got commit command failed unexpectedly" >&2
1273 test_done "$testroot" "1"
1277 local head_commit=`git_show_head $testroot/repo`
1278 echo "A foo" > $testroot/stdout.expected
1279 echo "M alpha" >> $testroot/stdout.expected
1280 echo "D beta" >> $testroot/stdout.expected
1281 echo "Created commit $head_commit" >> $testroot/stdout.expected
1283 cmp -s $testroot/stdout.expected $testroot/stdout
1285 if [ "$ret" != "0" ]; then
1286 diff -u $testroot/stdout.expected $testroot/stdout
1287 test_done "$testroot" "$ret"
1291 got diff -r $testroot/repo $first_commit $head_commit \
1294 echo "diff $first_commit $head_commit" \
1295 > $testroot/stdout.expected
1296 echo -n 'blob - ' >> $testroot/stdout.expected
1297 got tree -r $testroot/repo -i -c $first_commit | \
1298 grep 'alpha$' | cut -d' ' -f 1 \
1299 >> $testroot/stdout.expected
1300 echo -n 'blob + ' >> $testroot/stdout.expected
1301 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1302 echo '--- alpha' >> $testroot/stdout.expected
1303 echo '+++ alpha' >> $testroot/stdout.expected
1304 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1305 echo '-alpha' >> $testroot/stdout.expected
1306 echo '+modified file' >> $testroot/stdout.expected
1307 echo -n 'blob - ' >> $testroot/stdout.expected
1308 got tree -r $testroot/repo -i -c $first_commit \
1309 | grep 'beta$' | cut -d' ' -f 1 \
1310 >> $testroot/stdout.expected
1311 echo 'blob + /dev/null' >> $testroot/stdout.expected
1312 echo '--- beta' >> $testroot/stdout.expected
1313 echo '+++ /dev/null' >> $testroot/stdout.expected
1314 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1315 echo '-beta' >> $testroot/stdout.expected
1316 echo 'blob - /dev/null' >> $testroot/stdout.expected
1317 echo -n 'blob + ' >> $testroot/stdout.expected
1318 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1319 echo '--- /dev/null' >> $testroot/stdout.expected
1320 echo '+++ foo' >> $testroot/stdout.expected
1321 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1322 echo '+new file' >> $testroot/stdout.expected
1324 cmp -s $testroot/stdout.expected $testroot/stdout
1326 if [ "$ret" != "0" ]; then
1327 diff -u $testroot/stdout.expected $testroot/stdout
1328 test_done "$testroot" "$ret"
1332 echo 'A epsilon/new' > $testroot/stdout.expected
1333 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1334 echo 'M gamma/delta' >> $testroot/stdout.expected
1336 (cd $testroot/wt && got status > $testroot/stdout)
1337 cmp -s $testroot/stdout.expected $testroot/stdout
1339 if [ "$ret" != "0" ]; then
1340 diff -u $testroot/stdout.expected $testroot/stdout
1342 test_done "$testroot" "$ret"
1345 function test_stage_patch {
1346 local testroot=`test_init stage_patch`
1348 jot 16 > $testroot/repo/numbers
1349 (cd $testroot/repo && git add numbers)
1350 git_commit $testroot/repo -m "added numbers file"
1351 local commit_id=`git_show_head $testroot/repo`
1353 got checkout $testroot/repo $testroot/wt > /dev/null
1355 if [ "$ret" != "0" ]; then
1356 test_done "$testroot" "$ret"
1360 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1361 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1362 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1364 # don't stage any hunks
1365 printf "n\nn\nn\n" > $testroot/patchscript
1366 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1367 numbers > $testroot/stdout)
1369 if [ "$ret" != "0" ]; then
1370 echo "got stage command failed unexpectedly" >&2
1371 test_done "$testroot" "1"
1374 cat > $testroot/stdout.expected <<EOF
1375 -----------------------------------------------
1383 -----------------------------------------------
1384 M numbers (change 1 of 3)
1385 stage this change? [y/n/q] n
1386 -----------------------------------------------
1396 -----------------------------------------------
1397 M numbers (change 2 of 3)
1398 stage this change? [y/n/q] n
1399 -----------------------------------------------
1406 -----------------------------------------------
1407 M numbers (change 3 of 3)
1408 stage this change? [y/n/q] n
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"
1418 (cd $testroot/wt && got status > $testroot/stdout)
1419 echo "M numbers" > $testroot/stdout.expected
1420 cmp -s $testroot/stdout.expected $testroot/stdout
1422 if [ "$ret" != "0" ]; then
1423 diff -u $testroot/stdout.expected $testroot/stdout
1424 test_done "$testroot" "$ret"
1429 printf "n\ny\nn\n" > $testroot/patchscript
1430 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1431 numbers > $testroot/stdout)
1433 cat > $testroot/stdout.expected <<EOF
1434 -----------------------------------------------
1442 -----------------------------------------------
1443 M numbers (change 1 of 3)
1444 stage this change? [y/n/q] n
1445 -----------------------------------------------
1455 -----------------------------------------------
1456 M numbers (change 2 of 3)
1457 stage this change? [y/n/q] y
1458 -----------------------------------------------
1465 -----------------------------------------------
1466 M numbers (change 3 of 3)
1467 stage this change? [y/n/q] n
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 status > $testroot/stdout)
1478 echo "MM numbers" > $testroot/stdout.expected
1479 cmp -s $testroot/stdout.expected $testroot/stdout
1481 if [ "$ret" != "0" ]; then
1482 diff -u $testroot/stdout.expected $testroot/stdout
1483 test_done "$testroot" "$ret"
1487 (cd $testroot/wt && got diff -s > $testroot/stdout)
1489 echo "diff $commit_id $testroot/wt (staged changes)" \
1490 > $testroot/stdout.expected
1491 echo -n 'blob - ' >> $testroot/stdout.expected
1492 got tree -r $testroot/repo -i -c $commit_id \
1493 | grep 'numbers$' | cut -d' ' -f 1 \
1494 >> $testroot/stdout.expected
1495 echo -n 'blob + ' >> $testroot/stdout.expected
1496 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1497 >> $testroot/stdout.expected
1498 echo "--- numbers" >> $testroot/stdout.expected
1499 echo "+++ numbers" >> $testroot/stdout.expected
1500 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1501 echo " 4" >> $testroot/stdout.expected
1502 echo " 5" >> $testroot/stdout.expected
1503 echo " 6" >> $testroot/stdout.expected
1504 echo "-7" >> $testroot/stdout.expected
1505 echo "+b" >> $testroot/stdout.expected
1506 echo " 8" >> $testroot/stdout.expected
1507 echo " 9" >> $testroot/stdout.expected
1508 echo " 10" >> $testroot/stdout.expected
1509 cmp -s $testroot/stdout.expected $testroot/stdout
1511 if [ "$ret" != "0" ]; then
1512 diff -u $testroot/stdout.expected $testroot/stdout
1513 test_done "$testroot" "$ret"
1517 (cd $testroot/wt && got unstage >/dev/null)
1519 if [ "$ret" != "0" ]; then
1520 echo "got stage command failed unexpectedly" >&2
1521 test_done "$testroot" "1"
1524 (cd $testroot/wt && got status > $testroot/stdout)
1525 echo "M numbers" > $testroot/stdout.expected
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1528 if [ "$ret" != "0" ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1535 printf "n\nn\ny\n" > $testroot/patchscript
1536 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1537 numbers > $testroot/stdout)
1539 cat > $testroot/stdout.expected <<EOF
1540 -----------------------------------------------
1548 -----------------------------------------------
1549 M numbers (change 1 of 3)
1550 stage this change? [y/n/q] n
1551 -----------------------------------------------
1561 -----------------------------------------------
1562 M numbers (change 2 of 3)
1563 stage this change? [y/n/q] n
1564 -----------------------------------------------
1571 -----------------------------------------------
1572 M numbers (change 3 of 3)
1573 stage this change? [y/n/q] y
1575 cmp -s $testroot/stdout.expected $testroot/stdout
1577 if [ "$ret" != "0" ]; then
1578 diff -u $testroot/stdout.expected $testroot/stdout
1579 test_done "$testroot" "$ret"
1583 (cd $testroot/wt && got status > $testroot/stdout)
1584 echo "MM numbers" > $testroot/stdout.expected
1585 cmp -s $testroot/stdout.expected $testroot/stdout
1587 if [ "$ret" != "0" ]; then
1588 diff -u $testroot/stdout.expected $testroot/stdout
1589 test_done "$testroot" "$ret"
1593 (cd $testroot/wt && got diff -s > $testroot/stdout)
1595 echo "diff $commit_id $testroot/wt (staged changes)" \
1596 > $testroot/stdout.expected
1597 echo -n 'blob - ' >> $testroot/stdout.expected
1598 got tree -r $testroot/repo -i -c $commit_id \
1599 | grep 'numbers$' | cut -d' ' -f 1 \
1600 >> $testroot/stdout.expected
1601 echo -n 'blob + ' >> $testroot/stdout.expected
1602 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1603 >> $testroot/stdout.expected
1604 echo "--- numbers" >> $testroot/stdout.expected
1605 echo "+++ numbers" >> $testroot/stdout.expected
1606 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1607 echo " 13" >> $testroot/stdout.expected
1608 echo " 14" >> $testroot/stdout.expected
1609 echo " 15" >> $testroot/stdout.expected
1610 echo "-16" >> $testroot/stdout.expected
1611 echo "+c" >> $testroot/stdout.expected
1612 cmp -s $testroot/stdout.expected $testroot/stdout
1614 if [ "$ret" != "0" ]; then
1615 diff -u $testroot/stdout.expected $testroot/stdout
1617 test_done "$testroot" "$ret"
1620 function test_stage_patch_added {
1621 local testroot=`test_init stage_patch_added`
1622 local commit_id=`git_show_head $testroot/repo`
1624 got checkout $testroot/repo $testroot/wt > /dev/null
1626 if [ "$ret" != "0" ]; then
1627 test_done "$testroot" "$ret"
1631 echo "new" > $testroot/wt/epsilon/new
1632 (cd $testroot/wt && got add epsilon/new > /dev/null)
1634 printf "y\n" > $testroot/patchscript
1635 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1636 epsilon/new > $testroot/stdout)
1638 echo "A epsilon/new" > $testroot/stdout.expected
1639 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1640 cmp -s $testroot/stdout.expected $testroot/stdout
1642 if [ "$ret" != "0" ]; then
1643 diff -u $testroot/stdout.expected $testroot/stdout
1644 test_done "$testroot" "$ret"
1648 (cd $testroot/wt && got status > $testroot/stdout)
1649 echo " A epsilon/new" > $testroot/stdout.expected
1650 cmp -s $testroot/stdout.expected $testroot/stdout
1652 if [ "$ret" != "0" ]; then
1653 diff -u $testroot/stdout.expected $testroot/stdout
1654 test_done "$testroot" "$ret"
1658 (cd $testroot/wt && got diff -s > $testroot/stdout)
1660 echo "diff $commit_id $testroot/wt (staged changes)" \
1661 > $testroot/stdout.expected
1662 echo 'blob - /dev/null' >> $testroot/stdout.expected
1663 echo -n 'blob + ' >> $testroot/stdout.expected
1664 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1665 >> $testroot/stdout.expected
1666 echo "--- /dev/null" >> $testroot/stdout.expected
1667 echo "+++ epsilon/new" >> $testroot/stdout.expected
1668 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1669 echo "+new" >> $testroot/stdout.expected
1670 cmp -s $testroot/stdout.expected $testroot/stdout
1672 if [ "$ret" != "0" ]; then
1673 diff -u $testroot/stdout.expected $testroot/stdout
1675 test_done "$testroot" "$ret"
1678 function test_stage_patch_removed {
1679 local testroot=`test_init stage_patch_removed`
1680 local commit_id=`git_show_head $testroot/repo`
1682 got checkout $testroot/repo $testroot/wt > /dev/null
1684 if [ "$ret" != "0" ]; then
1685 test_done "$testroot" "$ret"
1689 (cd $testroot/wt && got rm beta > /dev/null)
1691 printf "y\n" > $testroot/patchscript
1692 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1693 beta > $testroot/stdout)
1695 echo -n > $testroot/stdout.expected
1697 echo "D beta" > $testroot/stdout.expected
1698 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
1699 cmp -s $testroot/stdout.expected $testroot/stdout
1701 if [ "$ret" != "0" ]; then
1702 diff -u $testroot/stdout.expected $testroot/stdout
1703 test_done "$testroot" "$ret"
1707 (cd $testroot/wt && got status > $testroot/stdout)
1708 echo " D beta" > $testroot/stdout.expected
1709 cmp -s $testroot/stdout.expected $testroot/stdout
1711 if [ "$ret" != "0" ]; then
1712 diff -u $testroot/stdout.expected $testroot/stdout
1713 test_done "$testroot" "$ret"
1717 (cd $testroot/wt && got diff -s > $testroot/stdout)
1719 echo "diff $commit_id $testroot/wt (staged changes)" \
1720 > $testroot/stdout.expected
1721 echo -n 'blob - ' >> $testroot/stdout.expected
1722 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
1723 >> $testroot/stdout.expected
1724 echo 'blob + /dev/null' >> $testroot/stdout.expected
1725 echo "--- beta" >> $testroot/stdout.expected
1726 echo "+++ /dev/null" >> $testroot/stdout.expected
1727 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
1728 echo "-beta" >> $testroot/stdout.expected
1729 cmp -s $testroot/stdout.expected $testroot/stdout
1731 if [ "$ret" != "0" ]; then
1732 diff -u $testroot/stdout.expected $testroot/stdout
1734 test_done "$testroot" "$ret"
1737 function test_stage_patch_quit {
1738 local testroot=`test_init stage_patch_quit`
1740 jot 16 > $testroot/repo/numbers
1741 echo zzz > $testroot/repo/zzz
1742 (cd $testroot/repo && git add numbers zzz)
1743 git_commit $testroot/repo -m "added files"
1744 local commit_id=`git_show_head $testroot/repo`
1746 got checkout $testroot/repo $testroot/wt > /dev/null
1748 if [ "$ret" != "0" ]; then
1749 test_done "$testroot" "$ret"
1753 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1754 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1755 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1756 (cd $testroot/wt && got rm zzz > /dev/null)
1758 # stage first hunk and quit; and don't pass a path argument to
1759 # ensure that we don't skip asking about the 'zzz' file after 'quit'
1760 printf "y\nq\nn\n" > $testroot/patchscript
1761 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1764 if [ "$ret" != "0" ]; then
1765 echo "got stage command failed unexpectedly" >&2
1766 test_done "$testroot" "1"
1769 cat > $testroot/stdout.expected <<EOF
1770 -----------------------------------------------
1778 -----------------------------------------------
1779 M numbers (change 1 of 3)
1780 stage this change? [y/n/q] y
1781 -----------------------------------------------
1791 -----------------------------------------------
1792 M numbers (change 2 of 3)
1793 stage this change? [y/n/q] q
1795 stage this deletion? [y/n] n
1797 cmp -s $testroot/stdout.expected $testroot/stdout
1799 if [ "$ret" != "0" ]; then
1800 diff -u $testroot/stdout.expected $testroot/stdout
1801 test_done "$testroot" "$ret"
1805 (cd $testroot/wt && got status > $testroot/stdout)
1806 echo "MM numbers" > $testroot/stdout.expected
1807 echo "D zzz" >> $testroot/stdout.expected
1808 cmp -s $testroot/stdout.expected $testroot/stdout
1810 if [ "$ret" != "0" ]; then
1811 diff -u $testroot/stdout.expected $testroot/stdout
1812 test_done "$testroot" "$ret"
1816 (cd $testroot/wt && got diff -s > $testroot/stdout)
1818 echo "diff $commit_id $testroot/wt (staged changes)" \
1819 > $testroot/stdout.expected
1820 echo -n 'blob - ' >> $testroot/stdout.expected
1821 got tree -r $testroot/repo -i -c $commit_id \
1822 | grep 'numbers$' | cut -d' ' -f 1 \
1823 >> $testroot/stdout.expected
1824 echo -n 'blob + ' >> $testroot/stdout.expected
1825 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1826 >> $testroot/stdout.expected
1827 echo "--- numbers" >> $testroot/stdout.expected
1828 echo "+++ numbers" >> $testroot/stdout.expected
1829 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
1830 echo " 1" >> $testroot/stdout.expected
1831 echo "-2" >> $testroot/stdout.expected
1832 echo "+a" >> $testroot/stdout.expected
1833 echo " 3" >> $testroot/stdout.expected
1834 echo " 4" >> $testroot/stdout.expected
1835 echo " 5" >> $testroot/stdout.expected
1836 cmp -s $testroot/stdout.expected $testroot/stdout
1838 if [ "$ret" != "0" ]; then
1839 diff -u $testroot/stdout.expected $testroot/stdout
1841 test_done "$testroot" "$ret"
1845 function test_stage_patch_incomplete_script {
1846 local testroot=`test_init stage_incomplete_script`
1848 jot 16 > $testroot/repo/numbers
1849 echo zzz > $testroot/repo/zzz
1850 (cd $testroot/repo && git add numbers zzz)
1851 git_commit $testroot/repo -m "added files"
1852 local commit_id=`git_show_head $testroot/repo`
1854 got checkout $testroot/repo $testroot/wt > /dev/null
1856 if [ "$ret" != "0" ]; then
1857 test_done "$testroot" "$ret"
1861 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1862 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1863 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1865 # stage first hunk and then stop responding; got should error out
1866 printf "y\n" > $testroot/patchscript
1867 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1868 > $testroot/stdout 2> $testroot/stderr)
1870 if [ "$ret" == "0" ]; then
1871 echo "got stage command succeeded unexpectedly" >&2
1872 test_done "$testroot" "1"
1875 cat > $testroot/stdout.expected <<EOF
1876 -----------------------------------------------
1884 -----------------------------------------------
1885 M numbers (change 1 of 3)
1886 stage this change? [y/n/q] y
1887 -----------------------------------------------
1897 -----------------------------------------------
1898 M numbers (change 2 of 3)
1900 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
1901 echo "got: invalid patch choice" > $testroot/stderr.expected
1902 cmp -s $testroot/stderr.expected $testroot/stderr
1904 if [ "$ret" != "0" ]; then
1905 diff -u $testroot/stderr.expected $testroot/stderr
1906 test_done "$testroot" "$ret"
1910 cmp -s $testroot/stdout.expected $testroot/stdout
1912 if [ "$ret" != "0" ]; then
1913 diff -u $testroot/stdout.expected $testroot/stdout
1914 test_done "$testroot" "$ret"
1918 (cd $testroot/wt && got status > $testroot/stdout)
1919 echo "M numbers" > $testroot/stdout.expected
1920 cmp -s $testroot/stdout.expected $testroot/stdout
1922 if [ "$ret" != "0" ]; then
1923 diff -u $testroot/stdout.expected $testroot/stdout
1924 test_done "$testroot" "$ret"
1928 (cd $testroot/wt && got diff -s > $testroot/stdout)
1929 echo -n > $testroot/stdout.expected
1930 cmp -s $testroot/stdout.expected $testroot/stdout
1932 if [ "$ret" != "0" ]; then
1933 diff -u $testroot/stdout.expected $testroot/stdout
1935 test_done "$testroot" "$ret"
1939 run_test test_stage_basic
1940 run_test test_stage_no_changes
1941 run_test test_stage_unversioned
1942 run_test test_stage_nonexistent
1943 run_test test_stage_list
1944 run_test test_stage_conflict
1945 run_test test_stage_out_of_date
1946 run_test test_double_stage
1947 run_test test_stage_status
1948 run_test test_stage_add_already_staged_file
1949 run_test test_stage_rm_already_staged_file
1950 run_test test_stage_revert
1951 run_test test_stage_diff
1952 run_test test_stage_histedit
1953 run_test test_stage_rebase
1954 run_test test_stage_update
1955 run_test test_stage_commit_non_staged
1956 run_test test_stage_commit_out_of_date
1957 run_test test_stage_commit
1958 run_test test_stage_patch
1959 run_test test_stage_patch_added
1960 run_test test_stage_patch_removed
1961 run_test test_stage_patch_quit
1962 run_test test_stage_patch_incomplete_script