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 alpha beta foo > $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: alpha: 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_list {
86 local testroot=`test_init stage_list`
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 (cd $testroot/wt && got rm beta > /dev/null)
97 echo "new file" > $testroot/wt/foo
98 (cd $testroot/wt && got add foo > /dev/null)
100 echo ' M alpha' > $testroot/stdout.expected
101 echo ' D beta' >> $testroot/stdout.expected
102 echo ' A foo' >> $testroot/stdout.expected
103 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
105 (cd $testroot/wt && got stage -l > $testroot/stdout)
106 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
107 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
108 echo " M alpha" >> $testroot/stdout.expected
109 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
110 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
111 echo " D beta" >> $testroot/stdout.expected
112 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
113 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
114 echo " A foo" >> $testroot/stdout.expected
115 cmp -s $testroot/stdout.expected $testroot/stdout
117 if [ "$ret" != "0" ]; then
118 diff -u $testroot/stdout.expected $testroot/stdout
119 test_done "$testroot" "$ret"
123 (cd $testroot/wt && got stage -l epsilon nonexistent \
126 echo -n > $testroot/stdout.expected
127 cmp -s $testroot/stdout.expected $testroot/stdout
129 if [ "$ret" != "0" ]; then
130 diff -u $testroot/stdout.expected $testroot/stdout
131 test_done "$testroot" "$ret"
135 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
137 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
138 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
139 echo " M alpha" >> $testroot/stdout.expected
140 cmp -s $testroot/stdout.expected $testroot/stdout
142 if [ "$ret" != "0" ]; then
143 diff -u $testroot/stdout.expected $testroot/stdout
145 test_done "$testroot" "$ret"
149 function test_stage_conflict {
150 local testroot=`test_init stage_conflict`
151 local initial_commit=`git_show_head $testroot/repo`
153 got checkout $testroot/repo $testroot/wt > /dev/null
155 if [ "$ret" != "0" ]; then
156 test_done "$testroot" "$ret"
160 echo "modified alpha" > $testroot/wt/alpha
161 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
163 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
165 echo "modified alpha, too" > $testroot/wt/alpha
167 echo "C alpha" > $testroot/stdout.expected
168 echo -n "Updated to commit " >> $testroot/stdout.expected
169 git_show_head $testroot/repo >> $testroot/stdout.expected
170 echo >> $testroot/stdout.expected
172 (cd $testroot/wt && got update > $testroot/stdout)
174 cmp -s $testroot/stdout.expected $testroot/stdout
176 if [ "$ret" != "0" ]; then
177 diff -u $testroot/stdout.expected $testroot/stdout
178 test_done "$testroot" "$ret"
182 (cd $testroot/wt && got stage alpha > $testroot/stdout \
185 if [ "$ret" == "0" ]; then
186 echo "got stage command succeeded unexpectedly" >&2
187 test_done "$testroot" "1"
191 echo -n > $testroot/stdout.expected
192 echo "got: alpha: cannot stage file in conflicted status" \
193 > $testroot/stderr.expected
195 cmp -s $testroot/stdout.expected $testroot/stdout
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
202 cmp -s $testroot/stderr.expected $testroot/stderr
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stderr.expected $testroot/stderr
207 test_done "$testroot" "$ret"
210 function test_stage_out_of_date {
211 local testroot=`test_init stage_out_of_date`
212 local initial_commit=`git_show_head $testroot/repo`
214 got checkout $testroot/repo $testroot/wt > /dev/null
216 if [ "$ret" != "0" ]; then
217 test_done "$testroot" "$ret"
221 echo "modified alpha" > $testroot/wt/alpha
222 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
224 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
226 echo "modified alpha again" > $testroot/wt/alpha
227 (cd $testroot/wt && got stage alpha > $testroot/stdout \
230 if [ "$ret" == "0" ]; then
231 echo "got stage command succeeded unexpectedly" >&2
232 test_done "$testroot" "1"
236 echo -n > $testroot/stdout.expected
237 echo "got: work tree must be updated before changes can be staged" \
238 > $testroot/stderr.expected
240 cmp -s $testroot/stdout.expected $testroot/stdout
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/stdout.expected $testroot/stdout
244 test_done "$testroot" "$ret"
247 cmp -s $testroot/stderr.expected $testroot/stderr
249 if [ "$ret" != "0" ]; then
250 diff -u $testroot/stderr.expected $testroot/stderr
252 test_done "$testroot" "$ret"
256 function test_double_stage {
257 local testroot=`test_init double_stage`
259 got checkout $testroot/repo $testroot/wt > /dev/null
261 if [ "$ret" != "0" ]; then
262 test_done "$testroot" "$ret"
265 echo "modified file" > $testroot/wt/alpha
266 (cd $testroot/wt && got rm beta > /dev/null)
267 echo "new file" > $testroot/wt/foo
268 (cd $testroot/wt && got add foo > /dev/null)
269 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
271 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
272 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
273 cmp -s $testroot/stderr.expected $testroot/stderr
275 if [ "$ret" != "0" ]; then
276 diff -u $testroot/stderr.expected $testroot/stderr
277 test_done "$testroot" "$ret"
281 (cd $testroot/wt && got stage beta > $testroot/stdout)
283 if [ "$ret" != "0" ]; then
284 echo "got stage command failed unexpectedly" >&2
285 test_done "$testroot" "1"
288 echo -n > $testroot/stdout.expected
289 cmp -s $testroot/stdout.expected $testroot/stdout
291 if [ "$ret" != "0" ]; then
292 diff -u $testroot/stdout.expected $testroot/stdout
293 test_done "$testroot" "$ret"
297 echo "got: foo: no changes to stage" > $testroot/stderr.expected
298 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
299 cmp -s $testroot/stderr.expected $testroot/stderr
301 if [ "$ret" != "0" ]; then
302 diff -u $testroot/stderr.expected $testroot/stderr
303 test_done "$testroot" "$ret"
307 echo "modified file again" > $testroot/wt/alpha
308 echo "modified new file" > $testroot/wt/foo
310 echo ' M alpha' > $testroot/stdout.expected
311 echo ' A foo' >> $testroot/stdout.expected
312 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
313 cmp -s $testroot/stdout.expected $testroot/stdout
315 if [ "$ret" != "0" ]; then
316 diff -u $testroot/stdout.expected $testroot/stdout
317 test_done "$testroot" "$ret"
321 echo ' M alpha' > $testroot/stdout.expected
322 echo ' D beta' >> $testroot/stdout.expected
323 echo ' A foo' >> $testroot/stdout.expected
325 (cd $testroot/wt && got status > $testroot/stdout)
326 cmp -s $testroot/stdout.expected $testroot/stdout
328 if [ "$ret" != "0" ]; then
329 diff -u $testroot/stdout.expected $testroot/stdout
331 test_done "$testroot" "$ret"
334 function test_stage_status {
335 local testroot=`test_init stage_status`
337 got checkout $testroot/repo $testroot/wt > /dev/null
339 if [ "$ret" != "0" ]; then
340 test_done "$testroot" "$ret"
344 echo "modified file" > $testroot/wt/alpha
345 (cd $testroot/wt && got rm beta > /dev/null)
346 echo "new file" > $testroot/wt/foo
347 (cd $testroot/wt && got add foo > /dev/null)
348 echo "new file" > $testroot/wt/epsilon/new
349 (cd $testroot/wt && got add epsilon/new > /dev/null)
350 echo "modified file" > $testroot/wt/epsilon/zeta
351 (cd $testroot/wt && got rm gamma/delta > /dev/null)
353 echo ' M alpha' > $testroot/stdout.expected
354 echo ' D beta' >> $testroot/stdout.expected
355 echo 'A epsilon/new' >> $testroot/stdout.expected
356 echo 'M epsilon/zeta' >> $testroot/stdout.expected
357 echo ' A foo' >> $testroot/stdout.expected
358 echo 'D gamma/delta' >> $testroot/stdout.expected
359 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
361 (cd $testroot/wt && got status > $testroot/stdout)
362 cmp -s $testroot/stdout.expected $testroot/stdout
364 if [ "$ret" != "0" ]; then
365 diff -u $testroot/stdout.expected $testroot/stdout
366 test_done "$testroot" "$ret"
370 echo "modified file again" >> $testroot/wt/alpha
371 echo "modified added file again" >> $testroot/wt/foo
373 echo 'MM alpha' > $testroot/stdout.expected
374 echo ' D beta' >> $testroot/stdout.expected
375 echo 'A epsilon/new' >> $testroot/stdout.expected
376 echo 'M epsilon/zeta' >> $testroot/stdout.expected
377 echo 'MA foo' >> $testroot/stdout.expected
378 echo 'D gamma/delta' >> $testroot/stdout.expected
380 (cd $testroot/wt && got status > $testroot/stdout)
381 cmp -s $testroot/stdout.expected $testroot/stdout
383 if [ "$ret" != "0" ]; then
384 diff -u $testroot/stdout.expected $testroot/stdout
385 test_done "$testroot" "$ret"
389 # test no-op change of added file with new stat(2) timestamp
390 echo "new file" > $testroot/wt/foo
391 echo ' A foo' > $testroot/stdout.expected
392 (cd $testroot/wt && got status foo > $testroot/stdout)
393 cmp -s $testroot/stdout.expected $testroot/stdout
395 if [ "$ret" != "0" ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
401 # test staged deleted file which is restored on disk
402 echo "new file" > $testroot/wt/beta
403 echo ' D beta' > $testroot/stdout.expected
404 (cd $testroot/wt && got status beta > $testroot/stdout)
405 cmp -s $testroot/stdout.expected $testroot/stdout
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
414 function test_stage_add_already_staged_file {
415 local testroot=`test_init stage_add_already_staged_file`
417 got checkout $testroot/repo $testroot/wt > /dev/null
419 if [ "$ret" != "0" ]; then
420 test_done "$testroot" "$ret"
424 echo "modified file" > $testroot/wt/alpha
425 (cd $testroot/wt && got rm beta > /dev/null)
426 echo "new file" > $testroot/wt/foo
427 (cd $testroot/wt && got add foo > /dev/null)
429 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
431 echo -n > $testroot/stdout.expected
432 for f in alpha beta foo; do
433 (cd $testroot/wt && got add $f \
434 > $testroot/stdout 2> $testroot/stderr)
435 echo "got: $f: file has unexpected status" \
436 > $testroot/stderr.expected
437 cmp -s $testroot/stderr.expected $testroot/stderr
439 if [ "$ret" != "0" ]; then
440 diff -u $testroot/stderr.expected $testroot/stderr
441 test_done "$testroot" "$ret"
444 cmp -s $testroot/stdout.expected $testroot/stdout
446 if [ "$ret" != "0" ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
453 echo ' M alpha' > $testroot/stdout.expected
454 echo ' D beta' >> $testroot/stdout.expected
455 echo ' A foo' >> $testroot/stdout.expected
457 (cd $testroot/wt && got status > $testroot/stdout)
458 cmp -s $testroot/stdout.expected $testroot/stdout
460 if [ "$ret" != "0" ]; then
461 diff -u $testroot/stdout.expected $testroot/stdout
463 test_done "$testroot" "$ret"
466 function test_stage_rm_already_staged_file {
467 local testroot=`test_init stage_rm_already_staged_file`
469 got checkout $testroot/repo $testroot/wt > /dev/null
471 if [ "$ret" != "0" ]; then
472 test_done "$testroot" "$ret"
476 echo "modified file" > $testroot/wt/alpha
477 (cd $testroot/wt && got rm beta > /dev/null)
478 echo "new file" > $testroot/wt/foo
479 (cd $testroot/wt && got add foo > /dev/null)
481 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
483 (cd $testroot/wt && got rm beta \
484 > $testroot/stdout 2> $testroot/stderr)
486 if [ "$ret" != "0" ]; then
487 echo "got rm command failed unexpectedly" >&2
488 test_done "$testroot" "1"
491 echo -n > $testroot/stdout.expected
492 cmp -s $testroot/stdout.expected $testroot/stdout
494 if [ "$ret" != "0" ]; then
495 diff -u $testroot/stdout.expected $testroot/stdout
496 test_done "$testroot" "$ret"
499 echo -n > $testroot/stderr.expected
500 cmp -s $testroot/stderr.expected $testroot/stderr
502 if [ "$ret" != "0" ]; then
503 diff -u $testroot/stderr.expected $testroot/stderr
504 test_done "$testroot" "$ret"
508 for f in alpha foo; do
509 echo "got: $f: file is staged" > $testroot/stderr.expected
510 (cd $testroot/wt && got rm $f \
511 > $testroot/stdout 2> $testroot/stderr)
513 if [ "$ret" == "0" ]; then
514 echo "got rm command succeeded unexpectedly" >&2
515 test_done "$testroot" "1"
518 cmp -s $testroot/stderr.expected $testroot/stderr
520 if [ "$ret" != "0" ]; then
521 diff -u $testroot/stderr.expected $testroot/stderr
522 test_done "$testroot" "$ret"
527 echo ' M alpha' > $testroot/stdout.expected
528 echo ' D beta' >> $testroot/stdout.expected
529 echo ' A foo' >> $testroot/stdout.expected
531 (cd $testroot/wt && got status > $testroot/stdout)
532 cmp -s $testroot/stdout.expected $testroot/stdout
534 if [ "$ret" != "0" ]; then
535 diff -u $testroot/stdout.expected $testroot/stdout
537 test_done "$testroot" "$ret"
540 function test_stage_revert {
541 local testroot=`test_init stage_revert`
543 got checkout $testroot/repo $testroot/wt > /dev/null
545 if [ "$ret" != "0" ]; then
546 test_done "$testroot" "$ret"
550 echo "modified alpha" > $testroot/wt/alpha
551 (cd $testroot/wt && got rm beta > /dev/null)
552 echo "new file" > $testroot/wt/foo
553 (cd $testroot/wt && got add foo > /dev/null)
554 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
556 echo "modified file again" >> $testroot/wt/alpha
557 echo "modified added file again" >> $testroot/wt/foo
559 (cd $testroot/wt && got revert alpha > $testroot/stdout)
561 if [ "$ret" != "0" ]; then
562 echo "revert command failed unexpectedly" >&2
563 test_done "$testroot" "$ret"
567 echo "R alpha" > $testroot/stdout.expected
568 cmp -s $testroot/stdout.expected $testroot/stdout
570 if [ "$ret" != "0" ]; then
571 diff -u $testroot/stdout.expected $testroot/stdout
572 test_done "$testroot" "$ret"
576 echo "modified alpha" > $testroot/content.expected
577 cat $testroot/wt/alpha > $testroot/content
578 cmp -s $testroot/content.expected $testroot/content
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/content.expected $testroot/content
582 test_done "$testroot" "$ret"
586 echo ' M alpha' > $testroot/stdout.expected
587 echo ' D beta' >> $testroot/stdout.expected
588 echo 'MA foo' >> $testroot/stdout.expected
589 (cd $testroot/wt && got status > $testroot/stdout)
590 cmp -s $testroot/stdout.expected $testroot/stdout
592 if [ "$ret" != "0" ]; then
593 diff -u $testroot/stdout.expected $testroot/stdout
594 test_done "$testroot" "$ret"
598 (cd $testroot/wt && got revert alpha > $testroot/stdout)
600 if [ "$ret" != "0" ]; then
601 echo "revert command failed unexpectedly" >&2
602 test_done "$testroot" "$ret"
606 echo -n > $testroot/stdout.expected
607 cmp -s $testroot/stdout.expected $testroot/stdout
609 if [ "$ret" != "0" ]; then
610 diff -u $testroot/stdout.expected $testroot/stdout
611 test_done "$testroot" "$ret"
615 echo "modified alpha" > $testroot/content.expected
616 cat $testroot/wt/alpha > $testroot/content
617 cmp -s $testroot/content.expected $testroot/content
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/content.expected $testroot/content
621 test_done "$testroot" "$ret"
625 (cd $testroot/wt && got revert beta > $testroot/stdout \
628 if [ "$ret" == "0" ]; then
629 echo "revert command succeeded unexpectedly" >&2
630 test_done "$testroot" "1"
634 echo "got: beta: file is staged" > $testroot/stderr.expected
635 cmp -s $testroot/stderr.expected $testroot/stderr
637 if [ "$ret" != "0" ]; then
638 diff -u $testroot/stderr.expected $testroot/stderr
639 test_done "$testroot" "$ret"
643 (cd $testroot/wt && got revert foo > $testroot/stdout)
645 if [ "$ret" != "0" ]; then
646 echo "revert command failed unexpectedly" >&2
647 test_done "$testroot" "$ret"
651 echo "R foo" > $testroot/stdout.expected
652 cmp -s $testroot/stdout.expected $testroot/stdout
654 if [ "$ret" != "0" ]; then
655 diff -u $testroot/stdout.expected $testroot/stdout
656 test_done "$testroot" "$ret"
660 echo "new file" > $testroot/content.expected
661 cat $testroot/wt/foo > $testroot/content
662 cmp -s $testroot/content.expected $testroot/content
664 if [ "$ret" != "0" ]; then
665 diff -u $testroot/content.expected $testroot/content
666 test_done "$testroot" "$ret"
670 echo ' M alpha' > $testroot/stdout.expected
671 echo ' D beta' >> $testroot/stdout.expected
672 echo ' A foo' >> $testroot/stdout.expected
673 (cd $testroot/wt && got status > $testroot/stdout)
674 cmp -s $testroot/stdout.expected $testroot/stdout
676 if [ "$ret" != "0" ]; then
677 diff -u $testroot/stdout.expected $testroot/stdout
678 test_done "$testroot" "$ret"
682 (cd $testroot/wt && got revert foo > $testroot/stdout)
684 if [ "$ret" != "0" ]; then
685 echo "revert command failed unexpectedly" >&2
686 test_done "$testroot" "$ret"
690 echo -n > $testroot/stdout.expected
691 cmp -s $testroot/stdout.expected $testroot/stdout
693 if [ "$ret" != "0" ]; then
694 diff -u $testroot/stdout.expected $testroot/stdout
695 test_done "$testroot" "$ret"
699 echo "new file" > $testroot/content.expected
700 cat $testroot/wt/foo > $testroot/content
701 cmp -s $testroot/content.expected $testroot/content
703 if [ "$ret" != "0" ]; then
704 diff -u $testroot/content.expected $testroot/content
705 test_done "$testroot" "$ret"
709 echo ' M alpha' > $testroot/stdout.expected
710 echo ' D beta' >> $testroot/stdout.expected
711 echo ' A foo' >> $testroot/stdout.expected
712 (cd $testroot/wt && got status > $testroot/stdout)
713 cmp -s $testroot/stdout.expected $testroot/stdout
715 if [ "$ret" != "0" ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
718 test_done "$testroot" "$ret"
721 function test_stage_diff {
722 local testroot=`test_init stage_diff`
723 local head_commit=`git_show_head $testroot/repo`
725 got checkout $testroot/repo $testroot/wt > /dev/null
727 if [ "$ret" != "0" ]; then
728 test_done "$testroot" "$ret"
732 echo "modified file" > $testroot/wt/alpha
733 (cd $testroot/wt && got rm beta > /dev/null)
734 echo "new file" > $testroot/wt/foo
735 (cd $testroot/wt && got add foo > /dev/null)
737 (cd $testroot/wt && got diff -s > $testroot/stdout)
738 echo -n > $testroot/stdout.expected
739 cmp -s $testroot/stdout.expected $testroot/stdout
741 if [ "$ret" != "0" ]; then
742 diff -u $testroot/stdout.expected $testroot/stdout
743 test_done "$testroot" "$ret"
747 echo ' M alpha' > $testroot/stdout.expected
748 echo ' D beta' >> $testroot/stdout.expected
749 echo ' A foo' >> $testroot/stdout.expected
750 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
752 (cd $testroot/wt && got diff > $testroot/stdout)
753 echo -n > $testroot/stdout.expected
754 cmp -s $testroot/stdout.expected $testroot/stdout
756 if [ "$ret" != "0" ]; then
757 diff -u $testroot/stdout.expected $testroot/stdout
758 test_done "$testroot" "$ret"
762 echo "modified file again" > $testroot/wt/alpha
763 echo "new file changed" > $testroot/wt/foo
765 (cd $testroot/wt && got diff > $testroot/stdout)
767 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
768 echo -n 'blob - ' >> $testroot/stdout.expected
769 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
770 >> $testroot/stdout.expected
771 echo 'file + alpha' >> $testroot/stdout.expected
772 echo '--- alpha' >> $testroot/stdout.expected
773 echo '+++ alpha' >> $testroot/stdout.expected
774 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
775 echo '-modified file' >> $testroot/stdout.expected
776 echo '+modified file again' >> $testroot/stdout.expected
777 echo -n 'blob - ' >> $testroot/stdout.expected
778 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
779 >> $testroot/stdout.expected
780 echo 'file + foo' >> $testroot/stdout.expected
781 echo '--- foo' >> $testroot/stdout.expected
782 echo '+++ foo' >> $testroot/stdout.expected
783 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
784 echo '-new file' >> $testroot/stdout.expected
785 echo '+new file changed' >> $testroot/stdout.expected
787 cmp -s $testroot/stdout.expected $testroot/stdout
789 if [ "$ret" != "0" ]; then
790 diff -u $testroot/stdout.expected $testroot/stdout
791 test_done "$testroot" "$ret"
795 (cd $testroot/wt && got diff -s > $testroot/stdout)
797 echo "diff $head_commit $testroot/wt (staged changes)" \
798 > $testroot/stdout.expected
799 echo -n 'blob - ' >> $testroot/stdout.expected
800 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
801 >> $testroot/stdout.expected
802 echo -n 'blob + ' >> $testroot/stdout.expected
803 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
804 >> $testroot/stdout.expected
805 echo '--- alpha' >> $testroot/stdout.expected
806 echo '+++ alpha' >> $testroot/stdout.expected
807 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
808 echo '-alpha' >> $testroot/stdout.expected
809 echo '+modified file' >> $testroot/stdout.expected
810 echo -n 'blob - ' >> $testroot/stdout.expected
811 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
812 >> $testroot/stdout.expected
813 echo 'blob + /dev/null' >> $testroot/stdout.expected
814 echo '--- beta' >> $testroot/stdout.expected
815 echo '+++ /dev/null' >> $testroot/stdout.expected
816 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
817 echo '-beta' >> $testroot/stdout.expected
818 echo 'blob - /dev/null' >> $testroot/stdout.expected
819 echo -n 'blob + ' >> $testroot/stdout.expected
820 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
821 >> $testroot/stdout.expected
822 echo '--- /dev/null' >> $testroot/stdout.expected
823 echo '+++ foo' >> $testroot/stdout.expected
824 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
825 echo '+new file' >> $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
829 if [ "$ret" != "0" ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
832 test_done "$testroot" "$ret"
836 function test_stage_histedit {
837 local testroot=`test_init stage_histedit`
838 local orig_commit=`git_show_head $testroot/repo`
840 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
842 if [ "$ret" != "0" ]; then
843 test_done "$testroot" "$ret"
847 echo "modified file" > $testroot/wt/alpha
848 (cd $testroot/wt && got stage alpha > /dev/null)
850 echo "modified alpha on master" > $testroot/repo/alpha
851 (cd $testroot/repo && git rm -q beta)
852 echo "new file on master" > $testroot/repo/epsilon/new
853 (cd $testroot/repo && git add epsilon/new)
854 git_commit $testroot/repo -m "committing changes"
855 local old_commit1=`git_show_head $testroot/repo`
857 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
858 git_commit $testroot/repo -m "committing to zeta on master"
859 local old_commit2=`git_show_head $testroot/repo`
861 echo "pick $old_commit1" > $testroot/histedit-script
862 echo "pick $old_commit2" >> $testroot/histedit-script
864 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
865 > $testroot/stdout 2> $testroot/stderr)
867 if [ "$ret" == "0" ]; then
868 echo "got histedit command succeeded unexpectedly" >&2
869 test_done "$testroot" "1"
873 echo -n > $testroot/stdout.expected
874 echo "got: alpha: file is staged" > $testroot/stderr.expected
876 cmp -s $testroot/stderr.expected $testroot/stderr
878 if [ "$ret" != "0" ]; then
879 diff -u $testroot/stderr.expected $testroot/stderr
880 test_done "$testroot" "$ret"
883 cmp -s $testroot/stdout.expected $testroot/stdout
885 if [ "$ret" != "0" ]; then
886 diff -u $testroot/stdout.expected $testroot/stdout
888 test_done "$testroot" "$ret"
892 function test_stage_rebase {
893 local testroot=`test_init stage_rebase`
895 (cd $testroot/repo && git checkout -q -b newbranch)
896 echo "modified delta on branch" > $testroot/repo/gamma/delta
897 git_commit $testroot/repo -m "committing to delta on newbranch"
899 echo "modified alpha on branch" > $testroot/repo/alpha
900 (cd $testroot/repo && git rm -q beta)
901 echo "new file on branch" > $testroot/repo/epsilon/new
902 (cd $testroot/repo && git add epsilon/new)
903 git_commit $testroot/repo -m "committing more changes on newbranch"
905 local orig_commit1=`git_show_parent_commit $testroot/repo`
906 local orig_commit2=`git_show_head $testroot/repo`
908 (cd $testroot/repo && git checkout -q master)
909 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
910 git_commit $testroot/repo -m "committing to zeta on master"
911 local master_commit=`git_show_head $testroot/repo`
913 got checkout $testroot/repo $testroot/wt > /dev/null
915 if [ "$ret" != "0" ]; then
916 test_done "$testroot" "$ret"
920 echo "modified file" > $testroot/wt/alpha
921 (cd $testroot/wt && got stage alpha > /dev/null)
923 (cd $testroot/wt && got rebase newbranch \
924 > $testroot/stdout 2> $testroot/stderr)
926 if [ "$ret" == "0" ]; then
927 echo "got rebase command succeeded unexpectedly" >&2
928 test_done "$testroot" "1"
932 echo -n > $testroot/stdout.expected
933 echo "got: alpha: file is staged" > $testroot/stderr.expected
935 cmp -s $testroot/stderr.expected $testroot/stderr
937 if [ "$ret" != "0" ]; then
938 diff -u $testroot/stderr.expected $testroot/stderr
939 test_done "$testroot" "$ret"
942 cmp -s $testroot/stdout.expected $testroot/stdout
944 if [ "$ret" != "0" ]; then
945 diff -u $testroot/stdout.expected $testroot/stdout
947 test_done "$testroot" "$ret"
950 function test_stage_update {
951 local testroot=`test_init stage_update`
953 got checkout $testroot/repo $testroot/wt > /dev/null
955 if [ "$ret" != "0" ]; then
956 test_done "$testroot" "$ret"
960 echo "modified file" > $testroot/wt/alpha
961 (cd $testroot/wt && got stage alpha > /dev/null)
963 echo "modified alpha" > $testroot/repo/alpha
964 git_commit $testroot/repo -m "modified alpha"
966 (cd $testroot/wt && got update > $testroot/stdout \
969 if [ "$ret" == "0" ]; then
970 echo "got update command succeeded unexpectedly" >&2
971 test_done "$testroot" "1"
975 echo -n > $testroot/stdout.expected
976 echo "got: alpha: file is staged" > $testroot/stderr.expected
978 cmp -s $testroot/stderr.expected $testroot/stderr
980 if [ "$ret" != "0" ]; then
981 diff -u $testroot/stderr.expected $testroot/stderr
982 test_done "$testroot" "$ret"
985 cmp -s $testroot/stdout.expected $testroot/stdout
987 if [ "$ret" != "0" ]; then
988 diff -u $testroot/stdout.expected $testroot/stdout
990 test_done "$testroot" "$ret"
993 function test_stage_commit_non_staged {
994 local testroot=`test_init stage_commit_non_staged`
996 got checkout $testroot/repo $testroot/wt > /dev/null
998 if [ "$ret" != "0" ]; then
999 test_done "$testroot" "$ret"
1003 echo "modified file" > $testroot/wt/alpha
1004 (cd $testroot/wt && got rm beta > /dev/null)
1005 echo "new file" > $testroot/wt/foo
1006 (cd $testroot/wt && got add foo > /dev/null)
1007 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1009 echo "modified file" > $testroot/wt/gamma/delta
1010 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1011 > $testroot/stdout 2> $testroot/stderr)
1013 if [ "$ret" == "0" ]; then
1014 echo "got commit command succeeded unexpectedly" >&2
1015 test_done "$testroot" "1"
1019 echo -n > $testroot/stdout.expected
1020 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1022 cmp -s $testroot/stderr.expected $testroot/stderr
1024 if [ "$ret" != "0" ]; then
1025 diff -u $testroot/stderr.expected $testroot/stderr
1026 test_done "$testroot" "$ret"
1029 cmp -s $testroot/stdout.expected $testroot/stdout
1031 if [ "$ret" != "0" ]; then
1032 diff -u $testroot/stdout.expected $testroot/stdout
1034 test_done "$testroot" "$ret"
1037 function test_stage_commit {
1038 local testroot=`test_init stage_commit`
1039 local first_commit=`git_show_head $testroot/repo`
1041 got checkout $testroot/repo $testroot/wt > /dev/null
1043 if [ "$ret" != "0" ]; then
1044 test_done "$testroot" "$ret"
1048 echo "modified file" > $testroot/wt/alpha
1049 (cd $testroot/wt && got rm beta > /dev/null)
1050 echo "new file" > $testroot/wt/foo
1051 (cd $testroot/wt && got add foo > /dev/null)
1052 echo "modified file" > $testroot/wt/alpha
1053 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1055 echo "modified file again" > $testroot/wt/alpha
1056 echo "new file changed" > $testroot/wt/foo
1057 echo "non-staged change" > $testroot/wt/gamma/delta
1058 echo "non-staged new file" > $testroot/wt/epsilon/new
1059 (cd $testroot/wt && got add epsilon/new > /dev/null)
1060 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1062 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1063 > $testroot/blob_id_alpha
1064 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1065 > $testroot/blob_id_foo
1067 (cd $testroot/wt && got commit -m "staged changes" \
1070 if [ "$ret" != "0" ]; then
1071 echo "got commit command failed unexpectedly" >&2
1072 test_done "$testroot" "1"
1076 local head_commit=`git_show_head $testroot/repo`
1077 echo "A foo" > $testroot/stdout.expected
1078 echo "M alpha" >> $testroot/stdout.expected
1079 echo "D beta" >> $testroot/stdout.expected
1080 echo "Created commit $head_commit" >> $testroot/stdout.expected
1082 cmp -s $testroot/stdout.expected $testroot/stdout
1084 if [ "$ret" != "0" ]; then
1085 diff -u $testroot/stdout.expected $testroot/stdout
1086 test_done "$testroot" "$ret"
1090 got diff -r $testroot/repo $first_commit $head_commit \
1093 echo "diff $first_commit $head_commit" \
1094 > $testroot/stdout.expected
1095 echo -n 'blob - ' >> $testroot/stdout.expected
1096 got tree -r $testroot/repo -i -c $first_commit | \
1097 grep 'alpha$' | cut -d' ' -f 1 \
1098 >> $testroot/stdout.expected
1099 echo -n 'blob + ' >> $testroot/stdout.expected
1100 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1101 echo '--- alpha' >> $testroot/stdout.expected
1102 echo '+++ alpha' >> $testroot/stdout.expected
1103 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1104 echo '-alpha' >> $testroot/stdout.expected
1105 echo '+modified file' >> $testroot/stdout.expected
1106 echo -n 'blob - ' >> $testroot/stdout.expected
1107 got tree -r $testroot/repo -i -c $first_commit \
1108 | grep 'beta$' | cut -d' ' -f 1 \
1109 >> $testroot/stdout.expected
1110 echo 'blob + /dev/null' >> $testroot/stdout.expected
1111 echo '--- beta' >> $testroot/stdout.expected
1112 echo '+++ /dev/null' >> $testroot/stdout.expected
1113 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1114 echo '-beta' >> $testroot/stdout.expected
1115 echo 'blob - /dev/null' >> $testroot/stdout.expected
1116 echo -n 'blob + ' >> $testroot/stdout.expected
1117 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1118 echo '--- /dev/null' >> $testroot/stdout.expected
1119 echo '+++ foo' >> $testroot/stdout.expected
1120 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1121 echo '+new file' >> $testroot/stdout.expected
1123 cmp -s $testroot/stdout.expected $testroot/stdout
1125 if [ "$ret" != "0" ]; then
1126 diff -u $testroot/stdout.expected $testroot/stdout
1127 test_done "$testroot" "$ret"
1131 echo 'A epsilon/new' > $testroot/stdout.expected
1132 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1133 echo 'M gamma/delta' >> $testroot/stdout.expected
1135 (cd $testroot/wt && got status > $testroot/stdout)
1136 cmp -s $testroot/stdout.expected $testroot/stdout
1138 if [ "$ret" != "0" ]; then
1139 diff -u $testroot/stdout.expected $testroot/stdout
1141 test_done "$testroot" "$ret"
1144 run_test test_stage_basic
1145 run_test test_stage_no_changes
1146 run_test test_stage_list
1147 run_test test_stage_conflict
1148 run_test test_stage_out_of_date
1149 run_test test_double_stage
1150 run_test test_stage_status
1151 run_test test_stage_add_already_staged_file
1152 run_test test_stage_rm_already_staged_file
1153 run_test test_stage_revert
1154 run_test test_stage_diff
1155 run_test test_stage_histedit
1156 run_test test_stage_rebase
1157 run_test test_stage_update
1158 run_test test_stage_commit_non_staged
1159 run_test test_stage_commit