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_list {
48 local testroot=`test_init stage_list`
50 got checkout $testroot/repo $testroot/wt > /dev/null
51 ret="$?"
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
54 return 1
55 fi
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
78 ret="$?"
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
81 test_done "$testroot" "$ret"
82 return 1
83 fi
85 (cd $testroot/wt && got stage -l epsilon nonexistent \
86 > $testroot/stdout)
88 echo -n > $testroot/stdout.expected
89 cmp -s $testroot/stdout.expected $testroot/stdout
90 ret="$?"
91 if [ "$ret" != "0" ]; then
92 diff -u $testroot/stdout.expected $testroot/stdout
93 test_done "$testroot" "$ret"
94 return 1
95 fi
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
103 ret="$?"
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
106 fi
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
116 ret="$?"
117 if [ "$ret" != "0" ]; then
118 test_done "$testroot" "$ret"
119 return 1
120 fi
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
137 ret="$?"
138 if [ "$ret" != "0" ]; then
139 diff -u $testroot/stdout.expected $testroot/stdout
140 test_done "$testroot" "$ret"
141 return 1
142 fi
144 (cd $testroot/wt && got stage alpha > $testroot/stdout \
145 2> $testroot/stderr)
146 ret="$?"
147 if [ "$ret" == "0" ]; then
148 echo "got stage command succeeded unexpectedly" >&2
149 test_done "$testroot" "1"
150 return 1
151 fi
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
158 ret="$?"
159 if [ "$ret" != "0" ]; then
160 diff -u $testroot/stdout.expected $testroot/stdout
161 test_done "$testroot" "$ret"
162 return 1
163 fi
164 cmp -s $testroot/stderr.expected $testroot/stderr
165 ret="$?"
166 if [ "$ret" != "0" ]; then
167 diff -u $testroot/stderr.expected $testroot/stderr
168 fi
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
177 ret="$?"
178 if [ "$ret" != "0" ]; then
179 test_done "$testroot" "$ret"
180 return 1
181 fi
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 \
190 2> $testroot/stderr)
191 ret="$?"
192 if [ "$ret" == "0" ]; then
193 echo "got stage command succeeded unexpectedly" >&2
194 test_done "$testroot" "1"
195 return 1
196 fi
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
203 ret="$?"
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 test_done "$testroot" "$ret"
207 return 1
208 fi
209 cmp -s $testroot/stderr.expected $testroot/stderr
210 ret="$?"
211 if [ "$ret" != "0" ]; then
212 diff -u $testroot/stderr.expected $testroot/stderr
213 fi
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
222 ret="$?"
223 if [ "$ret" != "0" ]; then
224 test_done "$testroot" "$ret"
225 return 1
226 fi
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
236 ret="$?"
237 if [ "$ret" != "0" ]; then
238 diff -u $testroot/stderr.expected $testroot/stderr
239 test_done "$testroot" "$ret"
240 return 1
241 fi
243 (cd $testroot/wt && got stage beta > $testroot/stdout)
244 ret="$?"
245 if [ "$ret" != "0" ]; then
246 echo "got stage command failed unexpectedly" >&2
247 test_done "$testroot" "1"
248 return 1
249 fi
250 echo -n > $testroot/stdout.expected
251 cmp -s $testroot/stdout.expected $testroot/stdout
252 ret="$?"
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/stdout.expected $testroot/stdout
255 test_done "$testroot" "$ret"
256 return 1
257 fi
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
262 ret="$?"
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stderr.expected $testroot/stderr
265 test_done "$testroot" "$ret"
266 return 1
267 fi
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
276 ret="$?"
277 if [ "$ret" != "0" ]; then
278 diff -u $testroot/stdout.expected $testroot/stdout
279 test_done "$testroot" "$ret"
280 return 1
281 fi
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
289 ret="$?"
290 if [ "$ret" != "0" ]; then
291 diff -u $testroot/stdout.expected $testroot/stdout
292 fi
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
300 ret="$?"
301 if [ "$ret" != "0" ]; then
302 test_done "$testroot" "$ret"
303 return 1
304 fi
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
325 ret="$?"
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
329 return 1
330 fi
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
344 ret="$?"
345 if [ "$ret" != "0" ]; then
346 diff -u $testroot/stdout.expected $testroot/stdout
347 test_done "$testroot" "$ret"
348 return 1
349 fi
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
356 ret="$?"
357 if [ "$ret" != "0" ]; then
358 diff -u $testroot/stdout.expected $testroot/stdout
359 test_done "$testroot" "$ret"
360 return 1
361 fi
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
368 ret="$?"
369 if [ "$ret" != "0" ]; then
370 diff -u $testroot/stdout.expected $testroot/stdout
371 fi
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
380 ret="$?"
381 if [ "$ret" != "0" ]; then
382 test_done "$testroot" "$ret"
383 return 1
384 fi
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
400 ret="$?"
401 if [ "$ret" != "0" ]; then
402 diff -u $testroot/stderr.expected $testroot/stderr
403 test_done "$testroot" "$ret"
404 return 1
405 fi
406 cmp -s $testroot/stdout.expected $testroot/stdout
407 ret="$?"
408 if [ "$ret" != "0" ]; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
411 return 1
412 fi
413 done
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
421 ret="$?"
422 if [ "$ret" != "0" ]; then
423 diff -u $testroot/stdout.expected $testroot/stdout
424 fi
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
432 ret="$?"
433 if [ "$ret" != "0" ]; then
434 test_done "$testroot" "$ret"
435 return 1
436 fi
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)
447 ret="$?"
448 if [ "$ret" != "0" ]; then
449 echo "got rm command failed unexpectedly" >&2
450 test_done "$testroot" "1"
451 return 1
452 fi
453 echo -n > $testroot/stdout.expected
454 cmp -s $testroot/stdout.expected $testroot/stdout
455 ret="$?"
456 if [ "$ret" != "0" ]; then
457 diff -u $testroot/stdout.expected $testroot/stdout
458 test_done "$testroot" "$ret"
459 return 1
460 fi
461 echo -n > $testroot/stderr.expected
462 cmp -s $testroot/stderr.expected $testroot/stderr
463 ret="$?"
464 if [ "$ret" != "0" ]; then
465 diff -u $testroot/stderr.expected $testroot/stderr
466 test_done "$testroot" "$ret"
467 return 1
468 fi
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)
474 ret="$?"
475 if [ "$ret" == "0" ]; then
476 echo "got rm command succeeded unexpectedly" >&2
477 test_done "$testroot" "1"
478 return 1
479 fi
480 cmp -s $testroot/stderr.expected $testroot/stderr
481 ret="$?"
482 if [ "$ret" != "0" ]; then
483 diff -u $testroot/stderr.expected $testroot/stderr
484 test_done "$testroot" "$ret"
485 return 1
486 fi
487 done
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
495 ret="$?"
496 if [ "$ret" != "0" ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
498 fi
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
506 ret="$?"
507 if [ "$ret" != "0" ]; then
508 test_done "$testroot" "$ret"
509 return 1
510 fi
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)
522 ret="$?"
523 if [ "$ret" != "0" ]; then
524 echo "revert command failed unexpectedly" >&2
525 test_done "$testroot" "$ret"
526 return 1
527 fi
529 echo "R alpha" > $testroot/stdout.expected
530 cmp -s $testroot/stdout.expected $testroot/stdout
531 ret="$?"
532 if [ "$ret" != "0" ]; then
533 diff -u $testroot/stdout.expected $testroot/stdout
534 test_done "$testroot" "$ret"
535 return 1
536 fi
538 echo "modified alpha" > $testroot/content.expected
539 cat $testroot/wt/alpha > $testroot/content
540 cmp -s $testroot/content.expected $testroot/content
541 ret="$?"
542 if [ "$ret" != "0" ]; then
543 diff -u $testroot/content.expected $testroot/content
544 test_done "$testroot" "$ret"
545 return 1
546 fi
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
553 ret="$?"
554 if [ "$ret" != "0" ]; then
555 diff -u $testroot/stdout.expected $testroot/stdout
556 test_done "$testroot" "$ret"
557 return 1
558 fi
560 (cd $testroot/wt && got revert alpha > $testroot/stdout)
561 ret="$?"
562 if [ "$ret" != "0" ]; then
563 echo "revert command failed unexpectedly" >&2
564 test_done "$testroot" "$ret"
565 return 1
566 fi
568 echo -n > $testroot/stdout.expected
569 cmp -s $testroot/stdout.expected $testroot/stdout
570 ret="$?"
571 if [ "$ret" != "0" ]; then
572 diff -u $testroot/stdout.expected $testroot/stdout
573 test_done "$testroot" "$ret"
574 return 1
575 fi
577 echo "modified alpha" > $testroot/content.expected
578 cat $testroot/wt/alpha > $testroot/content
579 cmp -s $testroot/content.expected $testroot/content
580 ret="$?"
581 if [ "$ret" != "0" ]; then
582 diff -u $testroot/content.expected $testroot/content
583 test_done "$testroot" "$ret"
584 return 1
585 fi
587 (cd $testroot/wt && got revert beta > $testroot/stdout \
588 2> $testroot/stderr)
589 ret="$?"
590 if [ "$ret" == "0" ]; then
591 echo "revert command succeeded unexpectedly" >&2
592 test_done "$testroot" "1"
593 return 1
594 fi
596 echo "got: beta: file is staged" > $testroot/stderr.expected
597 cmp -s $testroot/stderr.expected $testroot/stderr
598 ret="$?"
599 if [ "$ret" != "0" ]; then
600 diff -u $testroot/stderr.expected $testroot/stderr
601 test_done "$testroot" "$ret"
602 return 1
603 fi
605 (cd $testroot/wt && got revert foo > $testroot/stdout)
606 ret="$?"
607 if [ "$ret" != "0" ]; then
608 echo "revert command failed unexpectedly" >&2
609 test_done "$testroot" "$ret"
610 return 1
611 fi
613 echo "R foo" > $testroot/stdout.expected
614 cmp -s $testroot/stdout.expected $testroot/stdout
615 ret="$?"
616 if [ "$ret" != "0" ]; then
617 diff -u $testroot/stdout.expected $testroot/stdout
618 test_done "$testroot" "$ret"
619 return 1
620 fi
622 echo "new file" > $testroot/content.expected
623 cat $testroot/wt/foo > $testroot/content
624 cmp -s $testroot/content.expected $testroot/content
625 ret="$?"
626 if [ "$ret" != "0" ]; then
627 diff -u $testroot/content.expected $testroot/content
628 test_done "$testroot" "$ret"
629 return 1
630 fi
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
637 ret="$?"
638 if [ "$ret" != "0" ]; then
639 diff -u $testroot/stdout.expected $testroot/stdout
640 test_done "$testroot" "$ret"
641 return 1
642 fi
644 (cd $testroot/wt && got revert foo > $testroot/stdout)
645 ret="$?"
646 if [ "$ret" != "0" ]; then
647 echo "revert command failed unexpectedly" >&2
648 test_done "$testroot" "$ret"
649 return 1
650 fi
652 echo -n > $testroot/stdout.expected
653 cmp -s $testroot/stdout.expected $testroot/stdout
654 ret="$?"
655 if [ "$ret" != "0" ]; then
656 diff -u $testroot/stdout.expected $testroot/stdout
657 test_done "$testroot" "$ret"
658 return 1
659 fi
661 echo "new file" > $testroot/content.expected
662 cat $testroot/wt/foo > $testroot/content
663 cmp -s $testroot/content.expected $testroot/content
664 ret="$?"
665 if [ "$ret" != "0" ]; then
666 diff -u $testroot/content.expected $testroot/content
667 test_done "$testroot" "$ret"
668 return 1
669 fi
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
676 ret="$?"
677 if [ "$ret" != "0" ]; then
678 diff -u $testroot/stdout.expected $testroot/stdout
679 fi
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
688 ret="$?"
689 if [ "$ret" != "0" ]; then
690 test_done "$testroot" "$ret"
691 return 1
692 fi
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
702 ret="$?"
703 if [ "$ret" != "0" ]; then
704 diff -u $testroot/stdout.expected $testroot/stdout
705 test_done "$testroot" "$ret"
706 return 1
707 fi
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
717 ret="$?"
718 if [ "$ret" != "0" ]; then
719 diff -u $testroot/stdout.expected $testroot/stdout
720 test_done "$testroot" "$ret"
721 return 1
722 fi
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
750 ret="$?"
751 if [ "$ret" != "0" ]; then
752 diff -u $testroot/stdout.expected $testroot/stdout
753 test_done "$testroot" "$ret"
754 return 1
755 fi
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
790 ret="$?"
791 if [ "$ret" != "0" ]; then
792 diff -u $testroot/stdout.expected $testroot/stdout
793 fi
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
803 ret="$?"
804 if [ "$ret" != "0" ]; then
805 test_done "$testroot" "$ret"
806 return 1
807 fi
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)
828 ret="$?"
829 if [ "$ret" == "0" ]; then
830 echo "got histedit command succeeded unexpectedly" >&2
831 test_done "$testroot" "1"
832 return 1
833 fi
835 echo -n > $testroot/stdout.expected
836 echo "got: alpha: file is staged" > $testroot/stderr.expected
838 cmp -s $testroot/stderr.expected $testroot/stderr
839 ret="$?"
840 if [ "$ret" != "0" ]; then
841 diff -u $testroot/stderr.expected $testroot/stderr
842 test_done "$testroot" "$ret"
843 return 1
844 fi
845 cmp -s $testroot/stdout.expected $testroot/stdout
846 ret="$?"
847 if [ "$ret" != "0" ]; then
848 diff -u $testroot/stdout.expected $testroot/stdout
849 fi
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
876 ret="$?"
877 if [ "$ret" != "0" ]; then
878 test_done "$testroot" "$ret"
879 return 1
880 fi
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)
887 ret="$?"
888 if [ "$ret" == "0" ]; then
889 echo "got rebase command succeeded unexpectedly" >&2
890 test_done "$testroot" "1"
891 return 1
892 fi
894 echo -n > $testroot/stdout.expected
895 echo "got: alpha: file is staged" > $testroot/stderr.expected
897 cmp -s $testroot/stderr.expected $testroot/stderr
898 ret="$?"
899 if [ "$ret" != "0" ]; then
900 diff -u $testroot/stderr.expected $testroot/stderr
901 test_done "$testroot" "$ret"
902 return 1
903 fi
904 cmp -s $testroot/stdout.expected $testroot/stdout
905 ret="$?"
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 fi
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
916 ret="$?"
917 if [ "$ret" != "0" ]; then
918 test_done "$testroot" "$ret"
919 return 1
920 fi
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 \
929 2> $testroot/stderr)
930 ret="$?"
931 if [ "$ret" == "0" ]; then
932 echo "got update command succeeded unexpectedly" >&2
933 test_done "$testroot" "1"
934 return 1
935 fi
937 echo -n > $testroot/stdout.expected
938 echo "got: alpha: file is staged" > $testroot/stderr.expected
940 cmp -s $testroot/stderr.expected $testroot/stderr
941 ret="$?"
942 if [ "$ret" != "0" ]; then
943 diff -u $testroot/stderr.expected $testroot/stderr
944 test_done "$testroot" "$ret"
945 return 1
946 fi
947 cmp -s $testroot/stdout.expected $testroot/stdout
948 ret="$?"
949 if [ "$ret" != "0" ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
951 fi
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
959 ret="$?"
960 if [ "$ret" != "0" ]; then
961 test_done "$testroot" "$ret"
962 return 1
963 fi
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)
974 ret="$?"
975 if [ "$ret" == "0" ]; then
976 echo "got commit command succeeded unexpectedly" >&2
977 test_done "$testroot" "1"
978 return 1
979 fi
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
985 ret="$?"
986 if [ "$ret" != "0" ]; then
987 diff -u $testroot/stderr.expected $testroot/stderr
988 test_done "$testroot" "$ret"
989 return 1
990 fi
991 cmp -s $testroot/stdout.expected $testroot/stdout
992 ret="$?"
993 if [ "$ret" != "0" ]; then
994 diff -u $testroot/stdout.expected $testroot/stdout
995 fi
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
1004 ret="$?"
1005 if [ "$ret" != "0" ]; then
1006 test_done "$testroot" "$ret"
1007 return 1
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" \
1030 > $testroot/stdout)
1031 ret="$?"
1032 if [ "$ret" != "0" ]; then
1033 echo "got commit command failed unexpectedly" >&2
1034 test_done "$testroot" "1"
1035 return 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
1045 ret="$?"
1046 if [ "$ret" != "0" ]; then
1047 diff -u $testroot/stdout.expected $testroot/stdout
1048 test_done "$testroot" "$ret"
1049 return 1
1052 got diff -r $testroot/repo $first_commit $head_commit \
1053 > $testroot/stdout
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
1086 ret="$?"
1087 if [ "$ret" != "0" ]; then
1088 diff -u $testroot/stdout.expected $testroot/stdout
1089 test_done "$testroot" "$ret"
1090 return 1
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
1099 ret="$?"
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