Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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.
17 . ./common.sh
19 function test_stage_basic {
20 local testroot=`test_init stage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
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
40 ret="$?"
41 if [ "$ret" != "0" ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
43 fi
44 test_done "$testroot" "$ret"
45 }
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
52 ret="$?"
53 if [ "$ret" != "0" ]; then
54 test_done "$testroot" "$ret"
55 return 1
56 fi
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
73 ret="$?"
74 if [ "$ret" != "0" ]; then
75 diff -u $testroot/stdout.expected $testroot/stdout
76 test_done "$testroot" "$ret"
77 return 1
78 fi
80 (cd $testroot/wt && got stage alpha > $testroot/stdout \
81 2> $testroot/stderr)
82 ret="$?"
83 if [ "$ret" == "0" ]; then
84 echo "got stage command succeeded unexpectedly" >&2
85 test_done "$testroot" "1"
86 return 1
87 fi
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
94 ret="$?"
95 if [ "$ret" != "0" ]; then
96 diff -u $testroot/stdout.expected $testroot/stdout
97 test_done "$testroot" "$ret"
98 return 1
99 fi
100 cmp -s $testroot/stderr.expected $testroot/stderr
101 ret="$?"
102 if [ "$ret" != "0" ]; then
103 diff -u $testroot/stderr.expected $testroot/stderr
104 fi
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
113 ret="$?"
114 if [ "$ret" != "0" ]; then
115 test_done "$testroot" "$ret"
116 return 1
117 fi
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 \
126 2> $testroot/stderr)
127 ret="$?"
128 if [ "$ret" == "0" ]; then
129 echo "got stage command succeeded unexpectedly" >&2
130 test_done "$testroot" "1"
131 return 1
132 fi
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
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 diff -u $testroot/stdout.expected $testroot/stdout
142 test_done "$testroot" "$ret"
143 return 1
144 fi
145 cmp -s $testroot/stderr.expected $testroot/stderr
146 ret="$?"
147 if [ "$ret" != "0" ]; then
148 diff -u $testroot/stderr.expected $testroot/stderr
149 fi
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
158 ret="$?"
159 if [ "$ret" != "0" ]; then
160 test_done "$testroot" "$ret"
161 return 1
162 fi
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
172 ret="$?"
173 if [ "$ret" != "0" ]; then
174 diff -u $testroot/stderr.expected $testroot/stderr
175 test_done "$testroot" "$ret"
176 return 1
177 fi
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"
183 return 1
184 fi
185 echo -n > $testroot/stdout.expected
186 cmp -s $testroot/stdout.expected $testroot/stdout
187 ret="$?"
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
191 return 1
192 fi
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
197 ret="$?"
198 if [ "$ret" != "0" ]; then
199 diff -u $testroot/stderr.expected $testroot/stderr
200 test_done "$testroot" "$ret"
201 return 1
202 fi
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
211 ret="$?"
212 if [ "$ret" != "0" ]; then
213 diff -u $testroot/stdout.expected $testroot/stdout
214 test_done "$testroot" "$ret"
215 return 1
216 fi
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
224 ret="$?"
225 if [ "$ret" != "0" ]; then
226 diff -u $testroot/stdout.expected $testroot/stdout
227 fi
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
235 ret="$?"
236 if [ "$ret" != "0" ]; then
237 test_done "$testroot" "$ret"
238 return 1
239 fi
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
260 ret="$?"
261 if [ "$ret" != "0" ]; then
262 diff -u $testroot/stdout.expected $testroot/stdout
263 test_done "$testroot" "$ret"
264 return 1
265 fi
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
279 ret="$?"
280 if [ "$ret" != "0" ]; then
281 diff -u $testroot/stdout.expected $testroot/stdout
282 test_done "$testroot" "$ret"
283 return 1
284 fi
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
291 ret="$?"
292 if [ "$ret" != "0" ]; then
293 diff -u $testroot/stdout.expected $testroot/stdout
294 test_done "$testroot" "$ret"
295 return 1
296 fi
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
303 ret="$?"
304 if [ "$ret" != "0" ]; then
305 diff -u $testroot/stdout.expected $testroot/stdout
306 fi
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
315 ret="$?"
316 if [ "$ret" != "0" ]; then
317 test_done "$testroot" "$ret"
318 return 1
319 fi
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)
330 ret="$?"
331 if [ "$ret" == "0" ]; then
332 echo "got add command succeeded unexpectedly" >&2
333 test_done "$testroot" "1"
334 return 1
335 fi
336 echo "got: realpath: beta: No such file or directory" \
337 > $testroot/stderr.expected
338 cmp -s $testroot/stderr.expected $testroot/stderr
339 ret="$?"
340 if [ "$ret" != "0" ]; then
341 diff -u $testroot/stderr.expected $testroot/stderr
342 test_done "$testroot" "$ret"
343 return 1
344 fi
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)
350 ret="$?"
351 if [ "$ret" != "0" ]; then
352 echo "got add command failed unexpectedly" >&2
353 test_done "$testroot" "1"
354 return 1
355 fi
356 cmp -s $testroot/stdout.expected $testroot/stdout
357 ret="$?"
358 if [ "$ret" != "0" ]; then
359 diff -u $testroot/stdout.expected $testroot/stdout
360 test_done "$testroot" "$ret"
361 return 1
362 fi
363 done
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
371 ret="$?"
372 if [ "$ret" != "0" ]; then
373 diff -u $testroot/stdout.expected $testroot/stdout
374 fi
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
382 ret="$?"
383 if [ "$ret" != "0" ]; then
384 test_done "$testroot" "$ret"
385 return 1
386 fi
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)
397 ret="$?"
398 if [ "$ret" == "0" ]; then
399 echo "got rm command succeeded unexpectedly" >&2
400 test_done "$testroot" "1"
401 return 1
402 fi
403 echo "got: realpath: beta: No such file or directory" \
404 > $testroot/stderr.expected
405 cmp -s $testroot/stderr.expected $testroot/stderr
406 ret="$?"
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stderr.expected $testroot/stderr
409 test_done "$testroot" "$ret"
410 return 1
411 fi
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)
417 ret="$?"
418 if [ "$ret" == "0" ]; then
419 echo "got rm command succeeded unexpectedly" >&2
420 test_done "$testroot" "1"
421 return 1
422 fi
423 cmp -s $testroot/stderr.expected $testroot/stderr
424 ret="$?"
425 if [ "$ret" != "0" ]; then
426 diff -u $testroot/stderr.expected $testroot/stderr
427 test_done "$testroot" "$ret"
428 return 1
429 fi
430 done
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
438 ret="$?"
439 if [ "$ret" != "0" ]; then
440 diff -u $testroot/stdout.expected $testroot/stdout
441 fi
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
449 ret="$?"
450 if [ "$ret" != "0" ]; then
451 test_done "$testroot" "$ret"
452 return 1
453 fi
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)
465 ret="$?"
466 if [ "$ret" != "0" ]; then
467 echo "revert command failed unexpectedly" >&2
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 echo "R alpha" > $testroot/stdout.expected
473 cmp -s $testroot/stdout.expected $testroot/stdout
474 ret="$?"
475 if [ "$ret" != "0" ]; then
476 diff -u $testroot/stdout.expected $testroot/stdout
477 test_done "$testroot" "$ret"
478 return 1
479 fi
481 echo "modified alpha" > $testroot/content.expected
482 cat $testroot/wt/alpha > $testroot/content
483 cmp -s $testroot/content.expected $testroot/content
484 ret="$?"
485 if [ "$ret" != "0" ]; then
486 diff -u $testroot/content.expected $testroot/content
487 test_done "$testroot" "$ret"
488 return 1
489 fi
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
496 ret="$?"
497 if [ "$ret" != "0" ]; then
498 diff -u $testroot/stdout.expected $testroot/stdout
499 test_done "$testroot" "$ret"
500 return 1
501 fi
503 (cd $testroot/wt && got revert alpha > $testroot/stdout)
504 ret="$?"
505 if [ "$ret" != "0" ]; then
506 echo "revert command failed unexpectedly" >&2
507 test_done "$testroot" "$ret"
508 return 1
509 fi
511 echo -n > $testroot/stdout.expected
512 cmp -s $testroot/stdout.expected $testroot/stdout
513 ret="$?"
514 if [ "$ret" != "0" ]; then
515 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
517 return 1
518 fi
520 echo "modified alpha" > $testroot/content.expected
521 cat $testroot/wt/alpha > $testroot/content
522 cmp -s $testroot/content.expected $testroot/content
523 ret="$?"
524 if [ "$ret" != "0" ]; then
525 diff -u $testroot/content.expected $testroot/content
526 test_done "$testroot" "$ret"
527 return 1
528 fi
530 (cd $testroot/wt && got revert beta > $testroot/stdout \
531 2> $testroot/stderr)
532 ret="$?"
533 if [ "$ret" == "0" ]; then
534 echo "revert command succeeded unexpectedly" >&2
535 test_done "$testroot" "1"
536 return 1
537 fi
539 echo "got: beta: file is staged" > $testroot/stderr.expected
540 cmp -s $testroot/stderr.expected $testroot/stderr
541 ret="$?"
542 if [ "$ret" != "0" ]; then
543 diff -u $testroot/stderr.expected $testroot/stderr
544 test_done "$testroot" "$ret"
545 return 1
546 fi
548 (cd $testroot/wt && got revert foo > $testroot/stdout)
549 ret="$?"
550 if [ "$ret" != "0" ]; then
551 echo "revert command failed unexpectedly" >&2
552 test_done "$testroot" "$ret"
553 return 1
554 fi
556 echo "R foo" > $testroot/stdout.expected
557 cmp -s $testroot/stdout.expected $testroot/stdout
558 ret="$?"
559 if [ "$ret" != "0" ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
562 return 1
563 fi
565 echo "new file" > $testroot/content.expected
566 cat $testroot/wt/foo > $testroot/content
567 cmp -s $testroot/content.expected $testroot/content
568 ret="$?"
569 if [ "$ret" != "0" ]; then
570 diff -u $testroot/content.expected $testroot/content
571 test_done "$testroot" "$ret"
572 return 1
573 fi
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
580 ret="$?"
581 if [ "$ret" != "0" ]; then
582 diff -u $testroot/stdout.expected $testroot/stdout
583 test_done "$testroot" "$ret"
584 return 1
585 fi
587 (cd $testroot/wt && got revert foo > $testroot/stdout)
588 ret="$?"
589 if [ "$ret" != "0" ]; then
590 echo "revert command failed unexpectedly" >&2
591 test_done "$testroot" "$ret"
592 return 1
593 fi
595 echo -n > $testroot/stdout.expected
596 cmp -s $testroot/stdout.expected $testroot/stdout
597 ret="$?"
598 if [ "$ret" != "0" ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 test_done "$testroot" "$ret"
601 return 1
602 fi
604 echo "new file" > $testroot/content.expected
605 cat $testroot/wt/foo > $testroot/content
606 cmp -s $testroot/content.expected $testroot/content
607 ret="$?"
608 if [ "$ret" != "0" ]; then
609 diff -u $testroot/content.expected $testroot/content
610 test_done "$testroot" "$ret"
611 return 1
612 fi
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
619 ret="$?"
620 if [ "$ret" != "0" ]; then
621 diff -u $testroot/stdout.expected $testroot/stdout
622 fi
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
631 ret="$?"
632 if [ "$ret" != "0" ]; then
633 test_done "$testroot" "$ret"
634 return 1
635 fi
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
645 ret="$?"
646 if [ "$ret" != "0" ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
648 test_done "$testroot" "$ret"
649 return 1
650 fi
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
660 ret="$?"
661 if [ "$ret" != "0" ]; then
662 diff -u $testroot/stdout.expected $testroot/stdout
663 test_done "$testroot" "$ret"
664 return 1
665 fi
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
693 ret="$?"
694 if [ "$ret" != "0" ]; then
695 diff -u $testroot/stdout.expected $testroot/stdout
696 test_done "$testroot" "$ret"
697 return 1
698 fi
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
733 ret="$?"
734 if [ "$ret" != "0" ]; then
735 diff -u $testroot/stdout.expected $testroot/stdout
736 fi
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
746 ret="$?"
747 if [ "$ret" != "0" ]; then
748 test_done "$testroot" "$ret"
749 return 1
750 fi
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)
771 ret="$?"
772 if [ "$ret" == "0" ]; then
773 echo "got histedit command succeeded unexpectedly" >&2
774 test_done "$testroot" "1"
775 return 1
776 fi
778 echo -n > $testroot/stdout.expected
779 echo "got: alpha: file is staged" > $testroot/stderr.expected
781 cmp -s $testroot/stderr.expected $testroot/stderr
782 ret="$?"
783 if [ "$ret" != "0" ]; then
784 diff -u $testroot/stderr.expected $testroot/stderr
785 test_done "$testroot" "$ret"
786 return 1
787 fi
788 cmp -s $testroot/stdout.expected $testroot/stdout
789 ret="$?"
790 if [ "$ret" != "0" ]; then
791 diff -u $testroot/stdout.expected $testroot/stdout
792 fi
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
819 ret="$?"
820 if [ "$ret" != "0" ]; then
821 test_done "$testroot" "$ret"
822 return 1
823 fi
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)
830 ret="$?"
831 if [ "$ret" == "0" ]; then
832 echo "got rebase command succeeded unexpectedly" >&2
833 test_done "$testroot" "1"
834 return 1
835 fi
837 echo -n > $testroot/stdout.expected
838 echo "got: alpha: file is staged" > $testroot/stderr.expected
840 cmp -s $testroot/stderr.expected $testroot/stderr
841 ret="$?"
842 if [ "$ret" != "0" ]; then
843 diff -u $testroot/stderr.expected $testroot/stderr
844 test_done "$testroot" "$ret"
845 return 1
846 fi
847 cmp -s $testroot/stdout.expected $testroot/stdout
848 ret="$?"
849 if [ "$ret" != "0" ]; then
850 diff -u $testroot/stdout.expected $testroot/stdout
851 fi
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
859 ret="$?"
860 if [ "$ret" != "0" ]; then
861 test_done "$testroot" "$ret"
862 return 1
863 fi
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 \
872 2> $testroot/stderr)
873 ret="$?"
874 if [ "$ret" == "0" ]; then
875 echo "got update command succeeded unexpectedly" >&2
876 test_done "$testroot" "1"
877 return 1
878 fi
880 echo -n > $testroot/stdout.expected
881 echo "got: alpha: file is staged" > $testroot/stderr.expected
883 cmp -s $testroot/stderr.expected $testroot/stderr
884 ret="$?"
885 if [ "$ret" != "0" ]; then
886 diff -u $testroot/stderr.expected $testroot/stderr
887 test_done "$testroot" "$ret"
888 return 1
889 fi
890 cmp -s $testroot/stdout.expected $testroot/stdout
891 ret="$?"
892 if [ "$ret" != "0" ]; then
893 diff -u $testroot/stdout.expected $testroot/stdout
894 fi
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