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_conflict {
48 local testroot=`test_init stage_conflict`
49 local initial_commit=`git_show_head $testroot/repo`
51 got checkout $testroot/repo $testroot/wt > /dev/null
53 if [ "$ret" != "0" ]; then
54 test_done "$testroot" "$ret"
58 echo "modified alpha" > $testroot/wt/alpha
59 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
61 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
63 echo "modified alpha, too" > $testroot/wt/alpha
65 echo "C alpha" > $testroot/stdout.expected
66 echo -n "Updated to commit " >> $testroot/stdout.expected
67 git_show_head $testroot/repo >> $testroot/stdout.expected
68 echo >> $testroot/stdout.expected
70 (cd $testroot/wt && got update > $testroot/stdout)
72 cmp -s $testroot/stdout.expected $testroot/stdout
74 if [ "$ret" != "0" ]; then
75 diff -u $testroot/stdout.expected $testroot/stdout
76 test_done "$testroot" "$ret"
80 (cd $testroot/wt && got stage alpha > $testroot/stdout \
83 if [ "$ret" == "0" ]; then
84 echo "got stage command succeeded unexpectedly" >&2
85 test_done "$testroot" "1"
89 echo -n > $testroot/stdout.expected
90 echo "got: alpha: cannot stage file in conflicted status" \
91 > $testroot/stderr.expected
93 cmp -s $testroot/stdout.expected $testroot/stdout
95 if [ "$ret" != "0" ]; then
96 diff -u $testroot/stdout.expected $testroot/stdout
97 test_done "$testroot" "$ret"
100 cmp -s $testroot/stderr.expected $testroot/stderr
102 if [ "$ret" != "0" ]; then
103 diff -u $testroot/stderr.expected $testroot/stderr
105 test_done "$testroot" "$ret"
108 function test_stage_out_of_date {
109 local testroot=`test_init stage_out_of_date`
110 local initial_commit=`git_show_head $testroot/repo`
112 got checkout $testroot/repo $testroot/wt > /dev/null
114 if [ "$ret" != "0" ]; then
115 test_done "$testroot" "$ret"
119 echo "modified alpha" > $testroot/wt/alpha
120 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
122 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
124 echo "modified alpha again" > $testroot/wt/alpha
125 (cd $testroot/wt && got stage alpha > $testroot/stdout \
128 if [ "$ret" == "0" ]; then
129 echo "got stage command succeeded unexpectedly" >&2
130 test_done "$testroot" "1"
134 echo -n > $testroot/stdout.expected
135 echo "got: work tree must be updated before changes can be staged" \
136 > $testroot/stderr.expected
138 cmp -s $testroot/stdout.expected $testroot/stdout
140 if [ "$ret" != "0" ]; then
141 diff -u $testroot/stdout.expected $testroot/stdout
142 test_done "$testroot" "$ret"
145 cmp -s $testroot/stderr.expected $testroot/stderr
147 if [ "$ret" != "0" ]; then
148 diff -u $testroot/stderr.expected $testroot/stderr
150 test_done "$testroot" "$ret"
154 function test_double_stage {
155 local testroot=`test_init double_stage`
157 got checkout $testroot/repo $testroot/wt > /dev/null
159 if [ "$ret" != "0" ]; then
160 test_done "$testroot" "$ret"
163 echo "modified file" > $testroot/wt/alpha
164 (cd $testroot/wt && got rm beta > /dev/null)
165 echo "new file" > $testroot/wt/foo
166 (cd $testroot/wt && got add foo > /dev/null)
167 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
169 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
170 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
171 cmp -s $testroot/stderr.expected $testroot/stderr
173 if [ "$ret" != "0" ]; then
174 diff -u $testroot/stderr.expected $testroot/stderr
175 test_done "$testroot" "$ret"
179 (cd $testroot/wt && got stage beta > $testroot/stdout)
180 if [ "$ret" != "0" ]; then
181 echo "got stage command failed unexpectedly" >&2
182 test_done "$testroot" "1"
185 echo -n > $testroot/stdout.expected
186 cmp -s $testroot/stdout.expected $testroot/stdout
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
194 echo "got: foo: no changes to stage" > $testroot/stderr.expected
195 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
196 cmp -s $testroot/stderr.expected $testroot/stderr
198 if [ "$ret" != "0" ]; then
199 diff -u $testroot/stderr.expected $testroot/stderr
200 test_done "$testroot" "$ret"
204 echo "modified file again" > $testroot/wt/alpha
205 echo "modified new file" > $testroot/wt/foo
207 echo ' M alpha' > $testroot/stdout.expected
208 echo ' A foo' >> $testroot/stdout.expected
209 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
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 echo ' M alpha' > $testroot/stdout.expected
219 echo ' D beta' >> $testroot/stdout.expected
220 echo ' A foo' >> $testroot/stdout.expected
222 (cd $testroot/wt && got status > $testroot/stdout)
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"
231 function test_stage_status {
232 local testroot=`test_init stage_status`
234 got checkout $testroot/repo $testroot/wt > /dev/null
236 if [ "$ret" != "0" ]; then
237 test_done "$testroot" "$ret"
241 echo "modified file" > $testroot/wt/alpha
242 (cd $testroot/wt && got rm beta > /dev/null)
243 echo "new file" > $testroot/wt/foo
244 (cd $testroot/wt && got add foo > /dev/null)
245 echo "new file" > $testroot/wt/epsilon/new
246 (cd $testroot/wt && got add epsilon/new > /dev/null)
247 echo "modified file" > $testroot/wt/epsilon/zeta
248 (cd $testroot/wt && got rm gamma/delta > /dev/null)
250 echo ' M alpha' > $testroot/stdout.expected
251 echo ' D beta' >> $testroot/stdout.expected
252 echo 'A epsilon/new' >> $testroot/stdout.expected
253 echo 'M epsilon/zeta' >> $testroot/stdout.expected
254 echo ' A foo' >> $testroot/stdout.expected
255 echo 'D gamma/delta' >> $testroot/stdout.expected
256 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
258 (cd $testroot/wt && got status > $testroot/stdout)
259 cmp -s $testroot/stdout.expected $testroot/stdout
261 if [ "$ret" != "0" ]; then
262 diff -u $testroot/stdout.expected $testroot/stdout
263 test_done "$testroot" "$ret"
267 echo "modified file again" >> $testroot/wt/alpha
268 echo "modified added file again" >> $testroot/wt/foo
270 echo 'MM alpha' > $testroot/stdout.expected
271 echo ' D beta' >> $testroot/stdout.expected
272 echo 'A epsilon/new' >> $testroot/stdout.expected
273 echo 'M epsilon/zeta' >> $testroot/stdout.expected
274 echo 'MA foo' >> $testroot/stdout.expected
275 echo 'D gamma/delta' >> $testroot/stdout.expected
277 (cd $testroot/wt && got status > $testroot/stdout)
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"
286 # test no-op change of added file with new stat(2) timestamp
287 echo "new file" > $testroot/wt/foo
288 echo ' A foo' > $testroot/stdout.expected
289 (cd $testroot/wt && got status foo > $testroot/stdout)
290 cmp -s $testroot/stdout.expected $testroot/stdout
292 if [ "$ret" != "0" ]; then
293 diff -u $testroot/stdout.expected $testroot/stdout
294 test_done "$testroot" "$ret"
298 # test staged deleted file which is restored on disk
299 echo "new file" > $testroot/wt/beta
300 echo ' D beta' > $testroot/stdout.expected
301 (cd $testroot/wt && got status beta > $testroot/stdout)
302 cmp -s $testroot/stdout.expected $testroot/stdout
304 if [ "$ret" != "0" ]; then
305 diff -u $testroot/stdout.expected $testroot/stdout
307 test_done "$testroot" "$ret"
311 function test_stage_add_already_staged_file {
312 local testroot=`test_init stage_add_already_staged_file`
314 got checkout $testroot/repo $testroot/wt > /dev/null
316 if [ "$ret" != "0" ]; then
317 test_done "$testroot" "$ret"
321 echo "modified file" > $testroot/wt/alpha
322 (cd $testroot/wt && got rm beta > /dev/null)
323 echo "new file" > $testroot/wt/foo
324 (cd $testroot/wt && got add foo > /dev/null)
326 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
328 (cd $testroot/wt && got add beta \
329 > $testroot/stdout 2> $testroot/stderr)
331 if [ "$ret" == "0" ]; then
332 echo "got add command succeeded unexpectedly" >&2
333 test_done "$testroot" "1"
336 echo "got: realpath: beta: No such file or directory" \
337 > $testroot/stderr.expected
338 cmp -s $testroot/stderr.expected $testroot/stderr
340 if [ "$ret" != "0" ]; then
341 diff -u $testroot/stderr.expected $testroot/stderr
342 test_done "$testroot" "$ret"
346 echo -n > $testroot/stdout.expected
347 for f in alpha foo; do
348 (cd $testroot/wt && got add $f \
349 > $testroot/stdout 2> $testroot/stderr)
351 if [ "$ret" != "0" ]; then
352 echo "got add command failed unexpectedly" >&2
353 test_done "$testroot" "1"
356 cmp -s $testroot/stdout.expected $testroot/stdout
358 if [ "$ret" != "0" ]; then
359 diff -u $testroot/stdout.expected $testroot/stdout
360 test_done "$testroot" "$ret"
365 echo ' M alpha' > $testroot/stdout.expected
366 echo ' D beta' >> $testroot/stdout.expected
367 echo ' A foo' >> $testroot/stdout.expected
369 (cd $testroot/wt && got status > $testroot/stdout)
370 cmp -s $testroot/stdout.expected $testroot/stdout
372 if [ "$ret" != "0" ]; then
373 diff -u $testroot/stdout.expected $testroot/stdout
375 test_done "$testroot" "$ret"
378 function test_stage_rm_already_staged_file {
379 local testroot=`test_init stage_rm_already_staged_file`
381 got checkout $testroot/repo $testroot/wt > /dev/null
383 if [ "$ret" != "0" ]; then
384 test_done "$testroot" "$ret"
388 echo "modified file" > $testroot/wt/alpha
389 (cd $testroot/wt && got rm beta > /dev/null)
390 echo "new file" > $testroot/wt/foo
391 (cd $testroot/wt && got add foo > /dev/null)
393 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
395 (cd $testroot/wt && got rm beta \
396 > $testroot/stdout 2> $testroot/stderr)
398 if [ "$ret" == "0" ]; then
399 echo "got rm command succeeded unexpectedly" >&2
400 test_done "$testroot" "1"
403 echo "got: realpath: beta: No such file or directory" \
404 > $testroot/stderr.expected
405 cmp -s $testroot/stderr.expected $testroot/stderr
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stderr.expected $testroot/stderr
409 test_done "$testroot" "$ret"
413 for f in alpha foo; do
414 echo "got: $f: file is staged" > $testroot/stderr.expected
415 (cd $testroot/wt && got rm $f \
416 > $testroot/stdout 2> $testroot/stderr)
418 if [ "$ret" == "0" ]; then
419 echo "got rm command succeeded unexpectedly" >&2
420 test_done "$testroot" "1"
423 cmp -s $testroot/stderr.expected $testroot/stderr
425 if [ "$ret" != "0" ]; then
426 diff -u $testroot/stderr.expected $testroot/stderr
427 test_done "$testroot" "$ret"
432 echo ' M alpha' > $testroot/stdout.expected
433 echo ' D beta' >> $testroot/stdout.expected
434 echo ' A foo' >> $testroot/stdout.expected
436 (cd $testroot/wt && got status > $testroot/stdout)
437 cmp -s $testroot/stdout.expected $testroot/stdout
439 if [ "$ret" != "0" ]; then
440 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
445 function test_stage_revert {
446 local testroot=`test_init stage_revert`
448 got checkout $testroot/repo $testroot/wt > /dev/null
450 if [ "$ret" != "0" ]; then
451 test_done "$testroot" "$ret"
455 echo "modified alpha" > $testroot/wt/alpha
456 (cd $testroot/wt && got rm beta > /dev/null)
457 echo "new file" > $testroot/wt/foo
458 (cd $testroot/wt && got add foo > /dev/null)
459 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
461 echo "modified file again" >> $testroot/wt/alpha
462 echo "modified added file again" >> $testroot/wt/foo
464 (cd $testroot/wt && got revert alpha > $testroot/stdout)
466 if [ "$ret" != "0" ]; then
467 echo "revert command failed unexpectedly" >&2
468 test_done "$testroot" "$ret"
472 echo "R alpha" > $testroot/stdout.expected
473 cmp -s $testroot/stdout.expected $testroot/stdout
475 if [ "$ret" != "0" ]; then
476 diff -u $testroot/stdout.expected $testroot/stdout
477 test_done "$testroot" "$ret"
481 echo "modified alpha" > $testroot/content.expected
482 cat $testroot/wt/alpha > $testroot/content
483 cmp -s $testroot/content.expected $testroot/content
485 if [ "$ret" != "0" ]; then
486 diff -u $testroot/content.expected $testroot/content
487 test_done "$testroot" "$ret"
491 echo ' M alpha' > $testroot/stdout.expected
492 echo ' D beta' >> $testroot/stdout.expected
493 echo 'MA foo' >> $testroot/stdout.expected
494 (cd $testroot/wt && got status > $testroot/stdout)
495 cmp -s $testroot/stdout.expected $testroot/stdout
497 if [ "$ret" != "0" ]; then
498 diff -u $testroot/stdout.expected $testroot/stdout
499 test_done "$testroot" "$ret"
503 (cd $testroot/wt && got revert alpha > $testroot/stdout)
505 if [ "$ret" != "0" ]; then
506 echo "revert command failed unexpectedly" >&2
507 test_done "$testroot" "$ret"
511 echo -n > $testroot/stdout.expected
512 cmp -s $testroot/stdout.expected $testroot/stdout
514 if [ "$ret" != "0" ]; then
515 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
520 echo "modified alpha" > $testroot/content.expected
521 cat $testroot/wt/alpha > $testroot/content
522 cmp -s $testroot/content.expected $testroot/content
524 if [ "$ret" != "0" ]; then
525 diff -u $testroot/content.expected $testroot/content
526 test_done "$testroot" "$ret"
530 (cd $testroot/wt && got revert beta > $testroot/stdout \
533 if [ "$ret" == "0" ]; then
534 echo "revert command succeeded unexpectedly" >&2
535 test_done "$testroot" "1"
539 echo "got: beta: file is staged" > $testroot/stderr.expected
540 cmp -s $testroot/stderr.expected $testroot/stderr
542 if [ "$ret" != "0" ]; then
543 diff -u $testroot/stderr.expected $testroot/stderr
544 test_done "$testroot" "$ret"
548 (cd $testroot/wt && got revert foo > $testroot/stdout)
550 if [ "$ret" != "0" ]; then
551 echo "revert command failed unexpectedly" >&2
552 test_done "$testroot" "$ret"
556 echo "R foo" > $testroot/stdout.expected
557 cmp -s $testroot/stdout.expected $testroot/stdout
559 if [ "$ret" != "0" ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
565 echo "new file" > $testroot/content.expected
566 cat $testroot/wt/foo > $testroot/content
567 cmp -s $testroot/content.expected $testroot/content
569 if [ "$ret" != "0" ]; then
570 diff -u $testroot/content.expected $testroot/content
571 test_done "$testroot" "$ret"
575 echo ' M alpha' > $testroot/stdout.expected
576 echo ' D beta' >> $testroot/stdout.expected
577 echo ' A foo' >> $testroot/stdout.expected
578 (cd $testroot/wt && got status > $testroot/stdout)
579 cmp -s $testroot/stdout.expected $testroot/stdout
581 if [ "$ret" != "0" ]; then
582 diff -u $testroot/stdout.expected $testroot/stdout
583 test_done "$testroot" "$ret"
587 (cd $testroot/wt && got revert foo > $testroot/stdout)
589 if [ "$ret" != "0" ]; then
590 echo "revert command failed unexpectedly" >&2
591 test_done "$testroot" "$ret"
595 echo -n > $testroot/stdout.expected
596 cmp -s $testroot/stdout.expected $testroot/stdout
598 if [ "$ret" != "0" ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 test_done "$testroot" "$ret"
604 echo "new file" > $testroot/content.expected
605 cat $testroot/wt/foo > $testroot/content
606 cmp -s $testroot/content.expected $testroot/content
608 if [ "$ret" != "0" ]; then
609 diff -u $testroot/content.expected $testroot/content
610 test_done "$testroot" "$ret"
614 echo ' M alpha' > $testroot/stdout.expected
615 echo ' D beta' >> $testroot/stdout.expected
616 echo ' A foo' >> $testroot/stdout.expected
617 (cd $testroot/wt && got status > $testroot/stdout)
618 cmp -s $testroot/stdout.expected $testroot/stdout
620 if [ "$ret" != "0" ]; then
621 diff -u $testroot/stdout.expected $testroot/stdout
623 test_done "$testroot" "$ret"
626 function test_stage_diff {
627 local testroot=`test_init stage_diff`
628 local head_commit=`git_show_head $testroot/repo`
630 got checkout $testroot/repo $testroot/wt > /dev/null
632 if [ "$ret" != "0" ]; then
633 test_done "$testroot" "$ret"
637 echo "modified file" > $testroot/wt/alpha
638 (cd $testroot/wt && got rm beta > /dev/null)
639 echo "new file" > $testroot/wt/foo
640 (cd $testroot/wt && got add foo > /dev/null)
642 (cd $testroot/wt && got diff -s > $testroot/stdout)
643 echo -n > $testroot/stdout.expected
644 cmp -s $testroot/stdout.expected $testroot/stdout
646 if [ "$ret" != "0" ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
648 test_done "$testroot" "$ret"
652 echo ' M alpha' > $testroot/stdout.expected
653 echo ' D beta' >> $testroot/stdout.expected
654 echo ' A foo' >> $testroot/stdout.expected
655 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
657 (cd $testroot/wt && got diff > $testroot/stdout)
658 echo -n > $testroot/stdout.expected
659 cmp -s $testroot/stdout.expected $testroot/stdout
661 if [ "$ret" != "0" ]; then
662 diff -u $testroot/stdout.expected $testroot/stdout
663 test_done "$testroot" "$ret"
667 echo "modified file again" > $testroot/wt/alpha
668 echo "new file changed" > $testroot/wt/foo
670 (cd $testroot/wt && got diff > $testroot/stdout)
672 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
673 echo -n 'blob - ' >> $testroot/stdout.expected
674 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
675 >> $testroot/stdout.expected
676 echo 'file + alpha' >> $testroot/stdout.expected
677 echo '--- alpha' >> $testroot/stdout.expected
678 echo '+++ alpha' >> $testroot/stdout.expected
679 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
680 echo '-modified file' >> $testroot/stdout.expected
681 echo '+modified file again' >> $testroot/stdout.expected
682 echo -n 'blob - ' >> $testroot/stdout.expected
683 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
684 >> $testroot/stdout.expected
685 echo 'file + foo' >> $testroot/stdout.expected
686 echo '--- foo' >> $testroot/stdout.expected
687 echo '+++ foo' >> $testroot/stdout.expected
688 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
689 echo '-new file' >> $testroot/stdout.expected
690 echo '+new file changed' >> $testroot/stdout.expected
692 cmp -s $testroot/stdout.expected $testroot/stdout
694 if [ "$ret" != "0" ]; then
695 diff -u $testroot/stdout.expected $testroot/stdout
696 test_done "$testroot" "$ret"
700 (cd $testroot/wt && got diff -s > $testroot/stdout)
702 echo "diff $head_commit $testroot/wt (staged changes)" \
703 > $testroot/stdout.expected
704 echo -n 'blob - ' >> $testroot/stdout.expected
705 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
706 >> $testroot/stdout.expected
707 echo -n 'blob + ' >> $testroot/stdout.expected
708 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
709 >> $testroot/stdout.expected
710 echo '--- alpha' >> $testroot/stdout.expected
711 echo '+++ alpha' >> $testroot/stdout.expected
712 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
713 echo '-alpha' >> $testroot/stdout.expected
714 echo '+modified file' >> $testroot/stdout.expected
715 echo -n 'blob - ' >> $testroot/stdout.expected
716 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
717 >> $testroot/stdout.expected
718 echo 'blob + /dev/null' >> $testroot/stdout.expected
719 echo '--- beta' >> $testroot/stdout.expected
720 echo '+++ /dev/null' >> $testroot/stdout.expected
721 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
722 echo '-beta' >> $testroot/stdout.expected
723 echo 'blob - /dev/null' >> $testroot/stdout.expected
724 echo -n 'blob + ' >> $testroot/stdout.expected
725 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
726 >> $testroot/stdout.expected
727 echo '--- /dev/null' >> $testroot/stdout.expected
728 echo '+++ foo' >> $testroot/stdout.expected
729 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
730 echo '+new file' >> $testroot/stdout.expected
732 cmp -s $testroot/stdout.expected $testroot/stdout
734 if [ "$ret" != "0" ]; then
735 diff -u $testroot/stdout.expected $testroot/stdout
737 test_done "$testroot" "$ret"
741 function test_stage_histedit {
742 local testroot=`test_init stage_histedit`
743 local orig_commit=`git_show_head $testroot/repo`
745 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
747 if [ "$ret" != "0" ]; then
748 test_done "$testroot" "$ret"
752 echo "modified file" > $testroot/wt/alpha
753 (cd $testroot/wt && got stage alpha > /dev/null)
755 echo "modified alpha on master" > $testroot/repo/alpha
756 (cd $testroot/repo && git rm -q beta)
757 echo "new file on master" > $testroot/repo/epsilon/new
758 (cd $testroot/repo && git add epsilon/new)
759 git_commit $testroot/repo -m "committing changes"
760 local old_commit1=`git_show_head $testroot/repo`
762 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
763 git_commit $testroot/repo -m "committing to zeta on master"
764 local old_commit2=`git_show_head $testroot/repo`
766 echo "pick $old_commit1" > $testroot/histedit-script
767 echo "pick $old_commit2" >> $testroot/histedit-script
769 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
770 > $testroot/stdout 2> $testroot/stderr)
772 if [ "$ret" == "0" ]; then
773 echo "got histedit command succeeded unexpectedly" >&2
774 test_done "$testroot" "1"
778 echo -n > $testroot/stdout.expected
779 echo "got: alpha: file is staged" > $testroot/stderr.expected
781 cmp -s $testroot/stderr.expected $testroot/stderr
783 if [ "$ret" != "0" ]; then
784 diff -u $testroot/stderr.expected $testroot/stderr
785 test_done "$testroot" "$ret"
788 cmp -s $testroot/stdout.expected $testroot/stdout
790 if [ "$ret" != "0" ]; then
791 diff -u $testroot/stdout.expected $testroot/stdout
793 test_done "$testroot" "$ret"
797 function test_stage_rebase {
798 local testroot=`test_init stage_rebase`
800 (cd $testroot/repo && git checkout -q -b newbranch)
801 echo "modified delta on branch" > $testroot/repo/gamma/delta
802 git_commit $testroot/repo -m "committing to delta on newbranch"
804 echo "modified alpha on branch" > $testroot/repo/alpha
805 (cd $testroot/repo && git rm -q beta)
806 echo "new file on branch" > $testroot/repo/epsilon/new
807 (cd $testroot/repo && git add epsilon/new)
808 git_commit $testroot/repo -m "committing more changes on newbranch"
810 local orig_commit1=`git_show_parent_commit $testroot/repo`
811 local orig_commit2=`git_show_head $testroot/repo`
813 (cd $testroot/repo && git checkout -q master)
814 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
815 git_commit $testroot/repo -m "committing to zeta on master"
816 local master_commit=`git_show_head $testroot/repo`
818 got checkout $testroot/repo $testroot/wt > /dev/null
820 if [ "$ret" != "0" ]; then
821 test_done "$testroot" "$ret"
825 echo "modified file" > $testroot/wt/alpha
826 (cd $testroot/wt && got stage alpha > /dev/null)
828 (cd $testroot/wt && got rebase newbranch \
829 > $testroot/stdout 2> $testroot/stderr)
831 if [ "$ret" == "0" ]; then
832 echo "got rebase command succeeded unexpectedly" >&2
833 test_done "$testroot" "1"
837 echo -n > $testroot/stdout.expected
838 echo "got: alpha: file is staged" > $testroot/stderr.expected
840 cmp -s $testroot/stderr.expected $testroot/stderr
842 if [ "$ret" != "0" ]; then
843 diff -u $testroot/stderr.expected $testroot/stderr
844 test_done "$testroot" "$ret"
847 cmp -s $testroot/stdout.expected $testroot/stdout
849 if [ "$ret" != "0" ]; then
850 diff -u $testroot/stdout.expected $testroot/stdout
852 test_done "$testroot" "$ret"
855 function test_stage_update {
856 local testroot=`test_init stage_update`
858 got checkout $testroot/repo $testroot/wt > /dev/null
860 if [ "$ret" != "0" ]; then
861 test_done "$testroot" "$ret"
865 echo "modified file" > $testroot/wt/alpha
866 (cd $testroot/wt && got stage alpha > /dev/null)
868 echo "modified alpha" > $testroot/repo/alpha
869 git_commit $testroot/repo -m "modified alpha"
871 (cd $testroot/wt && got update > $testroot/stdout \
874 if [ "$ret" == "0" ]; then
875 echo "got update command succeeded unexpectedly" >&2
876 test_done "$testroot" "1"
880 echo -n > $testroot/stdout.expected
881 echo "got: alpha: file is staged" > $testroot/stderr.expected
883 cmp -s $testroot/stderr.expected $testroot/stderr
885 if [ "$ret" != "0" ]; then
886 diff -u $testroot/stderr.expected $testroot/stderr
887 test_done "$testroot" "$ret"
890 cmp -s $testroot/stdout.expected $testroot/stdout
892 if [ "$ret" != "0" ]; then
893 diff -u $testroot/stdout.expected $testroot/stdout
895 test_done "$testroot" "$ret"
898 run_test test_stage_basic
899 run_test test_stage_conflict
900 run_test test_stage_out_of_date
901 run_test test_double_stage
902 run_test test_stage_status
903 run_test test_stage_add_already_staged_file
904 run_test test_stage_rm_already_staged_file
905 run_test test_stage_revert
906 run_test test_stage_diff
907 run_test test_stage_histedit
908 run_test test_stage_rebase
909 run_test test_stage_update