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_list {
48 local testroot=`test_init stage_list`
50 got checkout $testroot/repo $testroot/wt > /dev/null
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
57 echo "modified file" > $testroot/wt/alpha
58 (cd $testroot/wt && got rm beta > /dev/null)
59 echo "new file" > $testroot/wt/foo
60 (cd $testroot/wt && got add foo > /dev/null)
62 echo ' M alpha' > $testroot/stdout.expected
63 echo ' D beta' >> $testroot/stdout.expected
64 echo ' A foo' >> $testroot/stdout.expected
65 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
67 (cd $testroot/wt && got stage -l > $testroot/stdout)
68 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
69 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
70 echo " M alpha" >> $testroot/stdout.expected
71 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
72 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
73 echo " D beta" >> $testroot/stdout.expected
74 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
75 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
76 echo " A foo" >> $testroot/stdout.expected
77 cmp -s $testroot/stdout.expected $testroot/stdout
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
81 test_done "$testroot" "$ret"
85 (cd $testroot/wt && got stage -l epsilon nonexistent \
88 echo -n > $testroot/stdout.expected
89 cmp -s $testroot/stdout.expected $testroot/stdout
91 if [ "$ret" != "0" ]; then
92 diff -u $testroot/stdout.expected $testroot/stdout
93 test_done "$testroot" "$ret"
97 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
99 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
100 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
101 echo " M alpha" >> $testroot/stdout.expected
102 cmp -s $testroot/stdout.expected $testroot/stdout
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
107 test_done "$testroot" "$ret"
111 function test_stage_conflict {
112 local testroot=`test_init stage_conflict`
113 local initial_commit=`git_show_head $testroot/repo`
115 got checkout $testroot/repo $testroot/wt > /dev/null
117 if [ "$ret" != "0" ]; then
118 test_done "$testroot" "$ret"
122 echo "modified alpha" > $testroot/wt/alpha
123 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
125 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
127 echo "modified alpha, too" > $testroot/wt/alpha
129 echo "C alpha" > $testroot/stdout.expected
130 echo -n "Updated to commit " >> $testroot/stdout.expected
131 git_show_head $testroot/repo >> $testroot/stdout.expected
132 echo >> $testroot/stdout.expected
134 (cd $testroot/wt && got update > $testroot/stdout)
136 cmp -s $testroot/stdout.expected $testroot/stdout
138 if [ "$ret" != "0" ]; then
139 diff -u $testroot/stdout.expected $testroot/stdout
140 test_done "$testroot" "$ret"
144 (cd $testroot/wt && got stage alpha > $testroot/stdout \
147 if [ "$ret" == "0" ]; then
148 echo "got stage command succeeded unexpectedly" >&2
149 test_done "$testroot" "1"
153 echo -n > $testroot/stdout.expected
154 echo "got: alpha: cannot stage file in conflicted status" \
155 > $testroot/stderr.expected
157 cmp -s $testroot/stdout.expected $testroot/stdout
159 if [ "$ret" != "0" ]; then
160 diff -u $testroot/stdout.expected $testroot/stdout
161 test_done "$testroot" "$ret"
164 cmp -s $testroot/stderr.expected $testroot/stderr
166 if [ "$ret" != "0" ]; then
167 diff -u $testroot/stderr.expected $testroot/stderr
169 test_done "$testroot" "$ret"
172 function test_stage_out_of_date {
173 local testroot=`test_init stage_out_of_date`
174 local initial_commit=`git_show_head $testroot/repo`
176 got checkout $testroot/repo $testroot/wt > /dev/null
178 if [ "$ret" != "0" ]; then
179 test_done "$testroot" "$ret"
183 echo "modified alpha" > $testroot/wt/alpha
184 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
186 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
188 echo "modified alpha again" > $testroot/wt/alpha
189 (cd $testroot/wt && got stage alpha > $testroot/stdout \
192 if [ "$ret" == "0" ]; then
193 echo "got stage command succeeded unexpectedly" >&2
194 test_done "$testroot" "1"
198 echo -n > $testroot/stdout.expected
199 echo "got: work tree must be updated before changes can be staged" \
200 > $testroot/stderr.expected
202 cmp -s $testroot/stdout.expected $testroot/stdout
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 test_done "$testroot" "$ret"
209 cmp -s $testroot/stderr.expected $testroot/stderr
211 if [ "$ret" != "0" ]; then
212 diff -u $testroot/stderr.expected $testroot/stderr
214 test_done "$testroot" "$ret"
218 function test_double_stage {
219 local testroot=`test_init double_stage`
221 got checkout $testroot/repo $testroot/wt > /dev/null
223 if [ "$ret" != "0" ]; then
224 test_done "$testroot" "$ret"
227 echo "modified file" > $testroot/wt/alpha
228 (cd $testroot/wt && got rm beta > /dev/null)
229 echo "new file" > $testroot/wt/foo
230 (cd $testroot/wt && got add foo > /dev/null)
231 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
233 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
234 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
235 cmp -s $testroot/stderr.expected $testroot/stderr
237 if [ "$ret" != "0" ]; then
238 diff -u $testroot/stderr.expected $testroot/stderr
239 test_done "$testroot" "$ret"
243 (cd $testroot/wt && got stage beta > $testroot/stdout)
245 if [ "$ret" != "0" ]; then
246 echo "got stage command failed unexpectedly" >&2
247 test_done "$testroot" "1"
250 echo -n > $testroot/stdout.expected
251 cmp -s $testroot/stdout.expected $testroot/stdout
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/stdout.expected $testroot/stdout
255 test_done "$testroot" "$ret"
259 echo "got: foo: no changes to stage" > $testroot/stderr.expected
260 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
261 cmp -s $testroot/stderr.expected $testroot/stderr
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stderr.expected $testroot/stderr
265 test_done "$testroot" "$ret"
269 echo "modified file again" > $testroot/wt/alpha
270 echo "modified new file" > $testroot/wt/foo
272 echo ' M alpha' > $testroot/stdout.expected
273 echo ' A foo' >> $testroot/stdout.expected
274 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
275 cmp -s $testroot/stdout.expected $testroot/stdout
277 if [ "$ret" != "0" ]; then
278 diff -u $testroot/stdout.expected $testroot/stdout
279 test_done "$testroot" "$ret"
283 echo ' M alpha' > $testroot/stdout.expected
284 echo ' D beta' >> $testroot/stdout.expected
285 echo ' A foo' >> $testroot/stdout.expected
287 (cd $testroot/wt && got status > $testroot/stdout)
288 cmp -s $testroot/stdout.expected $testroot/stdout
290 if [ "$ret" != "0" ]; then
291 diff -u $testroot/stdout.expected $testroot/stdout
293 test_done "$testroot" "$ret"
296 function test_stage_status {
297 local testroot=`test_init stage_status`
299 got checkout $testroot/repo $testroot/wt > /dev/null
301 if [ "$ret" != "0" ]; then
302 test_done "$testroot" "$ret"
306 echo "modified file" > $testroot/wt/alpha
307 (cd $testroot/wt && got rm beta > /dev/null)
308 echo "new file" > $testroot/wt/foo
309 (cd $testroot/wt && got add foo > /dev/null)
310 echo "new file" > $testroot/wt/epsilon/new
311 (cd $testroot/wt && got add epsilon/new > /dev/null)
312 echo "modified file" > $testroot/wt/epsilon/zeta
313 (cd $testroot/wt && got rm gamma/delta > /dev/null)
315 echo ' M alpha' > $testroot/stdout.expected
316 echo ' D beta' >> $testroot/stdout.expected
317 echo 'A epsilon/new' >> $testroot/stdout.expected
318 echo 'M epsilon/zeta' >> $testroot/stdout.expected
319 echo ' A foo' >> $testroot/stdout.expected
320 echo 'D gamma/delta' >> $testroot/stdout.expected
321 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
323 (cd $testroot/wt && got status > $testroot/stdout)
324 cmp -s $testroot/stdout.expected $testroot/stdout
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
332 echo "modified file again" >> $testroot/wt/alpha
333 echo "modified added file again" >> $testroot/wt/foo
335 echo 'MM alpha' > $testroot/stdout.expected
336 echo ' D beta' >> $testroot/stdout.expected
337 echo 'A epsilon/new' >> $testroot/stdout.expected
338 echo 'M epsilon/zeta' >> $testroot/stdout.expected
339 echo 'MA foo' >> $testroot/stdout.expected
340 echo 'D gamma/delta' >> $testroot/stdout.expected
342 (cd $testroot/wt && got status > $testroot/stdout)
343 cmp -s $testroot/stdout.expected $testroot/stdout
345 if [ "$ret" != "0" ]; then
346 diff -u $testroot/stdout.expected $testroot/stdout
347 test_done "$testroot" "$ret"
351 # test no-op change of added file with new stat(2) timestamp
352 echo "new file" > $testroot/wt/foo
353 echo ' A foo' > $testroot/stdout.expected
354 (cd $testroot/wt && got status foo > $testroot/stdout)
355 cmp -s $testroot/stdout.expected $testroot/stdout
357 if [ "$ret" != "0" ]; then
358 diff -u $testroot/stdout.expected $testroot/stdout
359 test_done "$testroot" "$ret"
363 # test staged deleted file which is restored on disk
364 echo "new file" > $testroot/wt/beta
365 echo ' D beta' > $testroot/stdout.expected
366 (cd $testroot/wt && got status beta > $testroot/stdout)
367 cmp -s $testroot/stdout.expected $testroot/stdout
369 if [ "$ret" != "0" ]; then
370 diff -u $testroot/stdout.expected $testroot/stdout
372 test_done "$testroot" "$ret"
376 function test_stage_add_already_staged_file {
377 local testroot=`test_init stage_add_already_staged_file`
379 got checkout $testroot/repo $testroot/wt > /dev/null
381 if [ "$ret" != "0" ]; then
382 test_done "$testroot" "$ret"
386 echo "modified file" > $testroot/wt/alpha
387 (cd $testroot/wt && got rm beta > /dev/null)
388 echo "new file" > $testroot/wt/foo
389 (cd $testroot/wt && got add foo > /dev/null)
391 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
393 echo -n > $testroot/stdout.expected
394 for f in alpha beta foo; do
395 (cd $testroot/wt && got add $f \
396 > $testroot/stdout 2> $testroot/stderr)
397 echo "got: $f: file has unexpected status" \
398 > $testroot/stderr.expected
399 cmp -s $testroot/stderr.expected $testroot/stderr
401 if [ "$ret" != "0" ]; then
402 diff -u $testroot/stderr.expected $testroot/stderr
403 test_done "$testroot" "$ret"
406 cmp -s $testroot/stdout.expected $testroot/stdout
408 if [ "$ret" != "0" ]; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
415 echo ' M alpha' > $testroot/stdout.expected
416 echo ' D beta' >> $testroot/stdout.expected
417 echo ' A foo' >> $testroot/stdout.expected
419 (cd $testroot/wt && got status > $testroot/stdout)
420 cmp -s $testroot/stdout.expected $testroot/stdout
422 if [ "$ret" != "0" ]; then
423 diff -u $testroot/stdout.expected $testroot/stdout
425 test_done "$testroot" "$ret"
428 function test_stage_rm_already_staged_file {
429 local testroot=`test_init stage_rm_already_staged_file`
431 got checkout $testroot/repo $testroot/wt > /dev/null
433 if [ "$ret" != "0" ]; then
434 test_done "$testroot" "$ret"
438 echo "modified file" > $testroot/wt/alpha
439 (cd $testroot/wt && got rm beta > /dev/null)
440 echo "new file" > $testroot/wt/foo
441 (cd $testroot/wt && got add foo > /dev/null)
443 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
445 (cd $testroot/wt && got rm beta \
446 > $testroot/stdout 2> $testroot/stderr)
448 if [ "$ret" != "0" ]; then
449 echo "got rm command failed unexpectedly" >&2
450 test_done "$testroot" "1"
453 echo -n > $testroot/stdout.expected
454 cmp -s $testroot/stdout.expected $testroot/stdout
456 if [ "$ret" != "0" ]; then
457 diff -u $testroot/stdout.expected $testroot/stdout
458 test_done "$testroot" "$ret"
461 echo -n > $testroot/stderr.expected
462 cmp -s $testroot/stderr.expected $testroot/stderr
464 if [ "$ret" != "0" ]; then
465 diff -u $testroot/stderr.expected $testroot/stderr
466 test_done "$testroot" "$ret"
470 for f in alpha foo; do
471 echo "got: $f: file is staged" > $testroot/stderr.expected
472 (cd $testroot/wt && got rm $f \
473 > $testroot/stdout 2> $testroot/stderr)
475 if [ "$ret" == "0" ]; then
476 echo "got rm command succeeded unexpectedly" >&2
477 test_done "$testroot" "1"
480 cmp -s $testroot/stderr.expected $testroot/stderr
482 if [ "$ret" != "0" ]; then
483 diff -u $testroot/stderr.expected $testroot/stderr
484 test_done "$testroot" "$ret"
489 echo ' M alpha' > $testroot/stdout.expected
490 echo ' D beta' >> $testroot/stdout.expected
491 echo ' A foo' >> $testroot/stdout.expected
493 (cd $testroot/wt && got status > $testroot/stdout)
494 cmp -s $testroot/stdout.expected $testroot/stdout
496 if [ "$ret" != "0" ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
499 test_done "$testroot" "$ret"
502 function test_stage_revert {
503 local testroot=`test_init stage_revert`
505 got checkout $testroot/repo $testroot/wt > /dev/null
507 if [ "$ret" != "0" ]; then
508 test_done "$testroot" "$ret"
512 echo "modified alpha" > $testroot/wt/alpha
513 (cd $testroot/wt && got rm beta > /dev/null)
514 echo "new file" > $testroot/wt/foo
515 (cd $testroot/wt && got add foo > /dev/null)
516 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
518 echo "modified file again" >> $testroot/wt/alpha
519 echo "modified added file again" >> $testroot/wt/foo
521 (cd $testroot/wt && got revert alpha > $testroot/stdout)
523 if [ "$ret" != "0" ]; then
524 echo "revert command failed unexpectedly" >&2
525 test_done "$testroot" "$ret"
529 echo "R alpha" > $testroot/stdout.expected
530 cmp -s $testroot/stdout.expected $testroot/stdout
532 if [ "$ret" != "0" ]; then
533 diff -u $testroot/stdout.expected $testroot/stdout
534 test_done "$testroot" "$ret"
538 echo "modified alpha" > $testroot/content.expected
539 cat $testroot/wt/alpha > $testroot/content
540 cmp -s $testroot/content.expected $testroot/content
542 if [ "$ret" != "0" ]; then
543 diff -u $testroot/content.expected $testroot/content
544 test_done "$testroot" "$ret"
548 echo ' M alpha' > $testroot/stdout.expected
549 echo ' D beta' >> $testroot/stdout.expected
550 echo 'MA foo' >> $testroot/stdout.expected
551 (cd $testroot/wt && got status > $testroot/stdout)
552 cmp -s $testroot/stdout.expected $testroot/stdout
554 if [ "$ret" != "0" ]; then
555 diff -u $testroot/stdout.expected $testroot/stdout
556 test_done "$testroot" "$ret"
560 (cd $testroot/wt && got revert alpha > $testroot/stdout)
562 if [ "$ret" != "0" ]; then
563 echo "revert command failed unexpectedly" >&2
564 test_done "$testroot" "$ret"
568 echo -n > $testroot/stdout.expected
569 cmp -s $testroot/stdout.expected $testroot/stdout
571 if [ "$ret" != "0" ]; then
572 diff -u $testroot/stdout.expected $testroot/stdout
573 test_done "$testroot" "$ret"
577 echo "modified alpha" > $testroot/content.expected
578 cat $testroot/wt/alpha > $testroot/content
579 cmp -s $testroot/content.expected $testroot/content
581 if [ "$ret" != "0" ]; then
582 diff -u $testroot/content.expected $testroot/content
583 test_done "$testroot" "$ret"
587 (cd $testroot/wt && got revert beta > $testroot/stdout \
590 if [ "$ret" == "0" ]; then
591 echo "revert command succeeded unexpectedly" >&2
592 test_done "$testroot" "1"
596 echo "got: beta: file is staged" > $testroot/stderr.expected
597 cmp -s $testroot/stderr.expected $testroot/stderr
599 if [ "$ret" != "0" ]; then
600 diff -u $testroot/stderr.expected $testroot/stderr
601 test_done "$testroot" "$ret"
605 (cd $testroot/wt && got revert foo > $testroot/stdout)
607 if [ "$ret" != "0" ]; then
608 echo "revert command failed unexpectedly" >&2
609 test_done "$testroot" "$ret"
613 echo "R foo" > $testroot/stdout.expected
614 cmp -s $testroot/stdout.expected $testroot/stdout
616 if [ "$ret" != "0" ]; then
617 diff -u $testroot/stdout.expected $testroot/stdout
618 test_done "$testroot" "$ret"
622 echo "new file" > $testroot/content.expected
623 cat $testroot/wt/foo > $testroot/content
624 cmp -s $testroot/content.expected $testroot/content
626 if [ "$ret" != "0" ]; then
627 diff -u $testroot/content.expected $testroot/content
628 test_done "$testroot" "$ret"
632 echo ' M alpha' > $testroot/stdout.expected
633 echo ' D beta' >> $testroot/stdout.expected
634 echo ' A foo' >> $testroot/stdout.expected
635 (cd $testroot/wt && got status > $testroot/stdout)
636 cmp -s $testroot/stdout.expected $testroot/stdout
638 if [ "$ret" != "0" ]; then
639 diff -u $testroot/stdout.expected $testroot/stdout
640 test_done "$testroot" "$ret"
644 (cd $testroot/wt && got revert foo > $testroot/stdout)
646 if [ "$ret" != "0" ]; then
647 echo "revert command failed unexpectedly" >&2
648 test_done "$testroot" "$ret"
652 echo -n > $testroot/stdout.expected
653 cmp -s $testroot/stdout.expected $testroot/stdout
655 if [ "$ret" != "0" ]; then
656 diff -u $testroot/stdout.expected $testroot/stdout
657 test_done "$testroot" "$ret"
661 echo "new file" > $testroot/content.expected
662 cat $testroot/wt/foo > $testroot/content
663 cmp -s $testroot/content.expected $testroot/content
665 if [ "$ret" != "0" ]; then
666 diff -u $testroot/content.expected $testroot/content
667 test_done "$testroot" "$ret"
671 echo ' M alpha' > $testroot/stdout.expected
672 echo ' D beta' >> $testroot/stdout.expected
673 echo ' A foo' >> $testroot/stdout.expected
674 (cd $testroot/wt && got status > $testroot/stdout)
675 cmp -s $testroot/stdout.expected $testroot/stdout
677 if [ "$ret" != "0" ]; then
678 diff -u $testroot/stdout.expected $testroot/stdout
680 test_done "$testroot" "$ret"
683 function test_stage_diff {
684 local testroot=`test_init stage_diff`
685 local head_commit=`git_show_head $testroot/repo`
687 got checkout $testroot/repo $testroot/wt > /dev/null
689 if [ "$ret" != "0" ]; then
690 test_done "$testroot" "$ret"
694 echo "modified file" > $testroot/wt/alpha
695 (cd $testroot/wt && got rm beta > /dev/null)
696 echo "new file" > $testroot/wt/foo
697 (cd $testroot/wt && got add foo > /dev/null)
699 (cd $testroot/wt && got diff -s > $testroot/stdout)
700 echo -n > $testroot/stdout.expected
701 cmp -s $testroot/stdout.expected $testroot/stdout
703 if [ "$ret" != "0" ]; then
704 diff -u $testroot/stdout.expected $testroot/stdout
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 stage alpha beta foo > /dev/null)
714 (cd $testroot/wt && got diff > $testroot/stdout)
715 echo -n > $testroot/stdout.expected
716 cmp -s $testroot/stdout.expected $testroot/stdout
718 if [ "$ret" != "0" ]; then
719 diff -u $testroot/stdout.expected $testroot/stdout
720 test_done "$testroot" "$ret"
724 echo "modified file again" > $testroot/wt/alpha
725 echo "new file changed" > $testroot/wt/foo
727 (cd $testroot/wt && got diff > $testroot/stdout)
729 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
730 echo -n 'blob - ' >> $testroot/stdout.expected
731 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
732 >> $testroot/stdout.expected
733 echo 'file + alpha' >> $testroot/stdout.expected
734 echo '--- alpha' >> $testroot/stdout.expected
735 echo '+++ alpha' >> $testroot/stdout.expected
736 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
737 echo '-modified file' >> $testroot/stdout.expected
738 echo '+modified file again' >> $testroot/stdout.expected
739 echo -n 'blob - ' >> $testroot/stdout.expected
740 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
741 >> $testroot/stdout.expected
742 echo 'file + foo' >> $testroot/stdout.expected
743 echo '--- foo' >> $testroot/stdout.expected
744 echo '+++ foo' >> $testroot/stdout.expected
745 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
746 echo '-new file' >> $testroot/stdout.expected
747 echo '+new file changed' >> $testroot/stdout.expected
749 cmp -s $testroot/stdout.expected $testroot/stdout
751 if [ "$ret" != "0" ]; then
752 diff -u $testroot/stdout.expected $testroot/stdout
753 test_done "$testroot" "$ret"
757 (cd $testroot/wt && got diff -s > $testroot/stdout)
759 echo "diff $head_commit $testroot/wt (staged changes)" \
760 > $testroot/stdout.expected
761 echo -n 'blob - ' >> $testroot/stdout.expected
762 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
763 >> $testroot/stdout.expected
764 echo -n 'blob + ' >> $testroot/stdout.expected
765 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
766 >> $testroot/stdout.expected
767 echo '--- alpha' >> $testroot/stdout.expected
768 echo '+++ alpha' >> $testroot/stdout.expected
769 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
770 echo '-alpha' >> $testroot/stdout.expected
771 echo '+modified file' >> $testroot/stdout.expected
772 echo -n 'blob - ' >> $testroot/stdout.expected
773 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
774 >> $testroot/stdout.expected
775 echo 'blob + /dev/null' >> $testroot/stdout.expected
776 echo '--- beta' >> $testroot/stdout.expected
777 echo '+++ /dev/null' >> $testroot/stdout.expected
778 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
779 echo '-beta' >> $testroot/stdout.expected
780 echo 'blob - /dev/null' >> $testroot/stdout.expected
781 echo -n 'blob + ' >> $testroot/stdout.expected
782 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
783 >> $testroot/stdout.expected
784 echo '--- /dev/null' >> $testroot/stdout.expected
785 echo '+++ foo' >> $testroot/stdout.expected
786 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
787 echo '+new file' >> $testroot/stdout.expected
789 cmp -s $testroot/stdout.expected $testroot/stdout
791 if [ "$ret" != "0" ]; then
792 diff -u $testroot/stdout.expected $testroot/stdout
794 test_done "$testroot" "$ret"
798 function test_stage_histedit {
799 local testroot=`test_init stage_histedit`
800 local orig_commit=`git_show_head $testroot/repo`
802 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
804 if [ "$ret" != "0" ]; then
805 test_done "$testroot" "$ret"
809 echo "modified file" > $testroot/wt/alpha
810 (cd $testroot/wt && got stage alpha > /dev/null)
812 echo "modified alpha on master" > $testroot/repo/alpha
813 (cd $testroot/repo && git rm -q beta)
814 echo "new file on master" > $testroot/repo/epsilon/new
815 (cd $testroot/repo && git add epsilon/new)
816 git_commit $testroot/repo -m "committing changes"
817 local old_commit1=`git_show_head $testroot/repo`
819 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
820 git_commit $testroot/repo -m "committing to zeta on master"
821 local old_commit2=`git_show_head $testroot/repo`
823 echo "pick $old_commit1" > $testroot/histedit-script
824 echo "pick $old_commit2" >> $testroot/histedit-script
826 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
827 > $testroot/stdout 2> $testroot/stderr)
829 if [ "$ret" == "0" ]; then
830 echo "got histedit command succeeded unexpectedly" >&2
831 test_done "$testroot" "1"
835 echo -n > $testroot/stdout.expected
836 echo "got: alpha: file is staged" > $testroot/stderr.expected
838 cmp -s $testroot/stderr.expected $testroot/stderr
840 if [ "$ret" != "0" ]; then
841 diff -u $testroot/stderr.expected $testroot/stderr
842 test_done "$testroot" "$ret"
845 cmp -s $testroot/stdout.expected $testroot/stdout
847 if [ "$ret" != "0" ]; then
848 diff -u $testroot/stdout.expected $testroot/stdout
850 test_done "$testroot" "$ret"
854 function test_stage_rebase {
855 local testroot=`test_init stage_rebase`
857 (cd $testroot/repo && git checkout -q -b newbranch)
858 echo "modified delta on branch" > $testroot/repo/gamma/delta
859 git_commit $testroot/repo -m "committing to delta on newbranch"
861 echo "modified alpha on branch" > $testroot/repo/alpha
862 (cd $testroot/repo && git rm -q beta)
863 echo "new file on branch" > $testroot/repo/epsilon/new
864 (cd $testroot/repo && git add epsilon/new)
865 git_commit $testroot/repo -m "committing more changes on newbranch"
867 local orig_commit1=`git_show_parent_commit $testroot/repo`
868 local orig_commit2=`git_show_head $testroot/repo`
870 (cd $testroot/repo && git checkout -q master)
871 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
872 git_commit $testroot/repo -m "committing to zeta on master"
873 local master_commit=`git_show_head $testroot/repo`
875 got checkout $testroot/repo $testroot/wt > /dev/null
877 if [ "$ret" != "0" ]; then
878 test_done "$testroot" "$ret"
882 echo "modified file" > $testroot/wt/alpha
883 (cd $testroot/wt && got stage alpha > /dev/null)
885 (cd $testroot/wt && got rebase newbranch \
886 > $testroot/stdout 2> $testroot/stderr)
888 if [ "$ret" == "0" ]; then
889 echo "got rebase command succeeded unexpectedly" >&2
890 test_done "$testroot" "1"
894 echo -n > $testroot/stdout.expected
895 echo "got: alpha: file is staged" > $testroot/stderr.expected
897 cmp -s $testroot/stderr.expected $testroot/stderr
899 if [ "$ret" != "0" ]; then
900 diff -u $testroot/stderr.expected $testroot/stderr
901 test_done "$testroot" "$ret"
904 cmp -s $testroot/stdout.expected $testroot/stdout
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
909 test_done "$testroot" "$ret"
912 function test_stage_update {
913 local testroot=`test_init stage_update`
915 got checkout $testroot/repo $testroot/wt > /dev/null
917 if [ "$ret" != "0" ]; then
918 test_done "$testroot" "$ret"
922 echo "modified file" > $testroot/wt/alpha
923 (cd $testroot/wt && got stage alpha > /dev/null)
925 echo "modified alpha" > $testroot/repo/alpha
926 git_commit $testroot/repo -m "modified alpha"
928 (cd $testroot/wt && got update > $testroot/stdout \
931 if [ "$ret" == "0" ]; then
932 echo "got update command succeeded unexpectedly" >&2
933 test_done "$testroot" "1"
937 echo -n > $testroot/stdout.expected
938 echo "got: alpha: file is staged" > $testroot/stderr.expected
940 cmp -s $testroot/stderr.expected $testroot/stderr
942 if [ "$ret" != "0" ]; then
943 diff -u $testroot/stderr.expected $testroot/stderr
944 test_done "$testroot" "$ret"
947 cmp -s $testroot/stdout.expected $testroot/stdout
949 if [ "$ret" != "0" ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
952 test_done "$testroot" "$ret"
955 function test_stage_commit_non_staged {
956 local testroot=`test_init stage_commit_non_staged`
958 got checkout $testroot/repo $testroot/wt > /dev/null
960 if [ "$ret" != "0" ]; then
961 test_done "$testroot" "$ret"
965 echo "modified file" > $testroot/wt/alpha
966 (cd $testroot/wt && got rm beta > /dev/null)
967 echo "new file" > $testroot/wt/foo
968 (cd $testroot/wt && got add foo > /dev/null)
969 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
971 echo "modified file" > $testroot/wt/gamma/delta
972 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
973 > $testroot/stdout 2> $testroot/stderr)
975 if [ "$ret" == "0" ]; then
976 echo "got commit command succeeded unexpectedly" >&2
977 test_done "$testroot" "1"
981 echo -n > $testroot/stdout.expected
982 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
984 cmp -s $testroot/stderr.expected $testroot/stderr
986 if [ "$ret" != "0" ]; then
987 diff -u $testroot/stderr.expected $testroot/stderr
988 test_done "$testroot" "$ret"
991 cmp -s $testroot/stdout.expected $testroot/stdout
993 if [ "$ret" != "0" ]; then
994 diff -u $testroot/stdout.expected $testroot/stdout
996 test_done "$testroot" "$ret"
999 function test_stage_commit {
1000 local testroot=`test_init stage_commit`
1001 local first_commit=`git_show_head $testroot/repo`
1003 got checkout $testroot/repo $testroot/wt > /dev/null
1005 if [ "$ret" != "0" ]; then
1006 test_done "$testroot" "$ret"
1010 echo "modified file" > $testroot/wt/alpha
1011 (cd $testroot/wt && got rm beta > /dev/null)
1012 echo "new file" > $testroot/wt/foo
1013 (cd $testroot/wt && got add foo > /dev/null)
1014 echo "modified file" > $testroot/wt/alpha
1015 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1017 echo "modified file again" > $testroot/wt/alpha
1018 echo "new file changed" > $testroot/wt/foo
1019 echo "non-staged change" > $testroot/wt/gamma/delta
1020 echo "non-staged new file" > $testroot/wt/epsilon/new
1021 (cd $testroot/wt && got add epsilon/new > /dev/null)
1022 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1024 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1025 > $testroot/blob_id_alpha
1026 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1027 > $testroot/blob_id_foo
1029 (cd $testroot/wt && got commit -m "staged changes" \
1032 if [ "$ret" != "0" ]; then
1033 echo "got commit command failed unexpectedly" >&2
1034 test_done "$testroot" "1"
1038 local head_commit=`git_show_head $testroot/repo`
1039 echo "A foo" > $testroot/stdout.expected
1040 echo "M alpha" >> $testroot/stdout.expected
1041 echo "D beta" >> $testroot/stdout.expected
1042 echo "Created commit $head_commit" >> $testroot/stdout.expected
1044 cmp -s $testroot/stdout.expected $testroot/stdout
1046 if [ "$ret" != "0" ]; then
1047 diff -u $testroot/stdout.expected $testroot/stdout
1048 test_done "$testroot" "$ret"
1052 got diff -r $testroot/repo $first_commit $head_commit \
1055 echo "diff $first_commit $head_commit" \
1056 > $testroot/stdout.expected
1057 echo -n 'blob - ' >> $testroot/stdout.expected
1058 got tree -r $testroot/repo -i -c $first_commit | \
1059 grep 'alpha$' | cut -d' ' -f 1 \
1060 >> $testroot/stdout.expected
1061 echo -n 'blob + ' >> $testroot/stdout.expected
1062 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1063 echo '--- alpha' >> $testroot/stdout.expected
1064 echo '+++ alpha' >> $testroot/stdout.expected
1065 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1066 echo '-alpha' >> $testroot/stdout.expected
1067 echo '+modified file' >> $testroot/stdout.expected
1068 echo -n 'blob - ' >> $testroot/stdout.expected
1069 got tree -r $testroot/repo -i -c $first_commit \
1070 | grep 'beta$' | cut -d' ' -f 1 \
1071 >> $testroot/stdout.expected
1072 echo 'blob + /dev/null' >> $testroot/stdout.expected
1073 echo '--- beta' >> $testroot/stdout.expected
1074 echo '+++ /dev/null' >> $testroot/stdout.expected
1075 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1076 echo '-beta' >> $testroot/stdout.expected
1077 echo 'blob - /dev/null' >> $testroot/stdout.expected
1078 echo -n 'blob + ' >> $testroot/stdout.expected
1079 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1080 echo '--- /dev/null' >> $testroot/stdout.expected
1081 echo '+++ foo' >> $testroot/stdout.expected
1082 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1083 echo '+new file' >> $testroot/stdout.expected
1085 cmp -s $testroot/stdout.expected $testroot/stdout
1087 if [ "$ret" != "0" ]; then
1088 diff -u $testroot/stdout.expected $testroot/stdout
1089 test_done "$testroot" "$ret"
1093 echo 'A epsilon/new' > $testroot/stdout.expected
1094 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1095 echo 'M gamma/delta' >> $testroot/stdout.expected
1097 (cd $testroot/wt && got status > $testroot/stdout)
1098 cmp -s $testroot/stdout.expected $testroot/stdout
1100 if [ "$ret" != "0" ]; then
1101 diff -u $testroot/stdout.expected $testroot/stdout
1103 test_done "$testroot" "$ret"
1106 run_test test_stage_basic
1107 run_test test_stage_list
1108 run_test test_stage_conflict
1109 run_test test_stage_out_of_date
1110 run_test test_double_stage
1111 run_test test_stage_status
1112 run_test test_stage_add_already_staged_file
1113 run_test test_stage_rm_already_staged_file
1114 run_test test_stage_revert
1115 run_test test_stage_diff
1116 run_test test_stage_histedit
1117 run_test test_stage_rebase
1118 run_test test_stage_update
1119 run_test test_stage_commit_non_staged
1120 run_test test_stage_commit