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 > $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_no_changes {
48 local testroot=`test_init stage_no_changes`
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 (cd $testroot/wt && got stage alpha beta > $testroot/stdout \
58 2> $testroot/stderr)
59 ret="$?"
60 if [ "$ret" == "0" ]; then
61 echo "got stage command succeeded unexpectedly" >&2
62 test_done "$testroot" "1"
63 return 1
64 fi
66 echo "got: no changes to stage" > $testroot/stderr.expected
68 cmp -s $testroot/stderr.expected $testroot/stderr
69 ret="$?"
70 if [ "$ret" != "0" ]; then
71 diff -u $testroot/stderr.expected $testroot/stderr
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 echo -n > $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 fi
82 test_done "$testroot" "$ret"
83 }
85 function test_stage_unversioned {
86 local testroot=`test_init stage_unversioned`
88 got checkout $testroot/repo $testroot/wt > /dev/null
89 ret="$?"
90 if [ "$ret" != "0" ]; then
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 echo "modified file" > $testroot/wt/alpha
96 touch $testroot/wt/unversioned-file
98 (cd $testroot/wt && got status > $testroot/stdout)
99 echo "M alpha" > $testroot/stdout.expected
100 echo "? unversioned-file" >> $testroot/stdout.expected
101 cmp -s $testroot/stdout.expected $testroot/stdout
102 ret="$?"
103 if [ "$ret" != "0" ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/wt && got stage > $testroot/stdout)
110 ret="$?"
111 if [ "$ret" != "0" ]; then
112 echo "got stage command failed unexpectedly" >&2
113 test_done "$testroot" "$ret"
114 return 1
115 fi
117 echo " M alpha" > $testroot/stdout.expected
118 cmp -s $testroot/stdout.expected $testroot/stdout
119 ret="$?"
120 if [ "$ret" != "0" ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 test_done "$testroot" "$ret"
123 return 1
124 fi
126 echo "modified file again" > $testroot/wt/alpha
128 (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
129 2> $testroot/stderr)
130 ret="$?"
131 if [ "$ret" == "0" ]; then
132 echo "got stage command succeed unexpectedly" >&2
133 test_done "$testroot" "1"
134 return 1
135 fi
137 echo "got: no changes to stage" > $testroot/stderr.expected
138 cmp -s $testroot/stderr.expected $testroot/stderr
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 diff -u $testroot/stderr.expected $testroot/stderr
142 fi
143 test_done "$testroot" "$ret"
147 function test_stage_nonexistent {
148 local testroot=`test_init stage_nonexistent`
150 got checkout $testroot/repo $testroot/wt > /dev/null
151 ret="$?"
152 if [ "$ret" != "0" ]; then
153 test_done "$testroot" "$ret"
154 return 1
155 fi
157 (cd $testroot/wt && got stage nonexistent-file \
158 > $testroot/stdout 2> $testroot/stderr)
159 echo "got: no changes to stage" > $testroot/stderr.expected
160 cmp -s $testroot/stderr.expected $testroot/stderr
161 ret="$?"
162 if [ "$ret" != "0" ]; then
163 diff -u $testroot/stderr.expected $testroot/stderr
164 fi
165 test_done "$testroot" "$ret"
168 function test_stage_list {
169 local testroot=`test_init stage_list`
171 got checkout $testroot/repo $testroot/wt > /dev/null
172 ret="$?"
173 if [ "$ret" != "0" ]; then
174 test_done "$testroot" "$ret"
175 return 1
176 fi
178 echo "modified file" > $testroot/wt/alpha
179 (cd $testroot/wt && got rm beta > /dev/null)
180 echo "new file" > $testroot/wt/foo
181 (cd $testroot/wt && got add foo > /dev/null)
183 echo ' M alpha' > $testroot/stdout.expected
184 echo ' D beta' >> $testroot/stdout.expected
185 echo ' A foo' >> $testroot/stdout.expected
186 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
188 (cd $testroot/wt && got stage -l > $testroot/stdout)
189 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
190 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
191 echo " M alpha" >> $testroot/stdout.expected
192 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
193 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
194 echo " D beta" >> $testroot/stdout.expected
195 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
196 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
197 echo " A foo" >> $testroot/stdout.expected
198 cmp -s $testroot/stdout.expected $testroot/stdout
199 ret="$?"
200 if [ "$ret" != "0" ]; then
201 diff -u $testroot/stdout.expected $testroot/stdout
202 test_done "$testroot" "$ret"
203 return 1
204 fi
206 (cd $testroot/wt && got stage -l epsilon nonexistent \
207 > $testroot/stdout)
209 echo -n > $testroot/stdout.expected
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 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
220 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
221 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
222 echo " M alpha" >> $testroot/stdout.expected
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"
232 function test_stage_conflict {
233 local testroot=`test_init stage_conflict`
234 local initial_commit=`git_show_head $testroot/repo`
236 got checkout $testroot/repo $testroot/wt > /dev/null
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 test_done "$testroot" "$ret"
240 return 1
241 fi
243 echo "modified alpha" > $testroot/wt/alpha
244 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
246 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
248 echo "modified alpha, too" > $testroot/wt/alpha
250 echo "C alpha" > $testroot/stdout.expected
251 echo -n "Updated to commit " >> $testroot/stdout.expected
252 git_show_head $testroot/repo >> $testroot/stdout.expected
253 echo >> $testroot/stdout.expected
255 (cd $testroot/wt && got update > $testroot/stdout)
257 cmp -s $testroot/stdout.expected $testroot/stdout
258 ret="$?"
259 if [ "$ret" != "0" ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 test_done "$testroot" "$ret"
262 return 1
263 fi
265 (cd $testroot/wt && got stage alpha > $testroot/stdout \
266 2> $testroot/stderr)
267 ret="$?"
268 if [ "$ret" == "0" ]; then
269 echo "got stage command succeeded unexpectedly" >&2
270 test_done "$testroot" "1"
271 return 1
272 fi
274 echo -n > $testroot/stdout.expected
275 echo "got: alpha: cannot stage file in conflicted status" \
276 > $testroot/stderr.expected
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
285 cmp -s $testroot/stderr.expected $testroot/stderr
286 ret="$?"
287 if [ "$ret" != "0" ]; then
288 diff -u $testroot/stderr.expected $testroot/stderr
289 fi
290 test_done "$testroot" "$ret"
293 function test_stage_out_of_date {
294 local testroot=`test_init stage_out_of_date`
295 local initial_commit=`git_show_head $testroot/repo`
297 got checkout $testroot/repo $testroot/wt > /dev/null
298 ret="$?"
299 if [ "$ret" != "0" ]; then
300 test_done "$testroot" "$ret"
301 return 1
302 fi
304 echo "modified alpha" > $testroot/wt/alpha
305 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
307 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
309 echo "modified alpha again" > $testroot/wt/alpha
310 (cd $testroot/wt && got stage alpha > $testroot/stdout \
311 2> $testroot/stderr)
312 ret="$?"
313 if [ "$ret" == "0" ]; then
314 echo "got stage command succeeded unexpectedly" >&2
315 test_done "$testroot" "1"
316 return 1
317 fi
319 echo -n > $testroot/stdout.expected
320 echo "got: work tree must be updated before changes can be staged" \
321 > $testroot/stderr.expected
323 cmp -s $testroot/stdout.expected $testroot/stdout
324 ret="$?"
325 if [ "$ret" != "0" ]; then
326 diff -u $testroot/stdout.expected $testroot/stdout
327 test_done "$testroot" "$ret"
328 return 1
329 fi
330 cmp -s $testroot/stderr.expected $testroot/stderr
331 ret="$?"
332 if [ "$ret" != "0" ]; then
333 diff -u $testroot/stderr.expected $testroot/stderr
334 fi
335 test_done "$testroot" "$ret"
339 function test_double_stage {
340 local testroot=`test_init double_stage`
342 got checkout $testroot/repo $testroot/wt > /dev/null
343 ret="$?"
344 if [ "$ret" != "0" ]; then
345 test_done "$testroot" "$ret"
346 return 1
347 fi
348 echo "modified file" > $testroot/wt/alpha
349 (cd $testroot/wt && got rm beta > /dev/null)
350 echo "new file" > $testroot/wt/foo
351 (cd $testroot/wt && got add foo > /dev/null)
352 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
354 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
355 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
356 cmp -s $testroot/stderr.expected $testroot/stderr
357 ret="$?"
358 if [ "$ret" != "0" ]; then
359 diff -u $testroot/stderr.expected $testroot/stderr
360 test_done "$testroot" "$ret"
361 return 1
362 fi
364 (cd $testroot/wt && got stage beta > $testroot/stdout)
365 ret="$?"
366 if [ "$ret" != "0" ]; then
367 echo "got stage command failed unexpectedly" >&2
368 test_done "$testroot" "1"
369 return 1
370 fi
371 echo -n > $testroot/stdout.expected
372 cmp -s $testroot/stdout.expected $testroot/stdout
373 ret="$?"
374 if [ "$ret" != "0" ]; then
375 diff -u $testroot/stdout.expected $testroot/stdout
376 test_done "$testroot" "$ret"
377 return 1
378 fi
380 echo "got: foo: no changes to stage" > $testroot/stderr.expected
381 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
382 cmp -s $testroot/stderr.expected $testroot/stderr
383 ret="$?"
384 if [ "$ret" != "0" ]; then
385 diff -u $testroot/stderr.expected $testroot/stderr
386 test_done "$testroot" "$ret"
387 return 1
388 fi
390 echo "modified file again" > $testroot/wt/alpha
391 echo "modified new file" > $testroot/wt/foo
393 echo ' M alpha' > $testroot/stdout.expected
394 echo ' A foo' >> $testroot/stdout.expected
395 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
396 cmp -s $testroot/stdout.expected $testroot/stdout
397 ret="$?"
398 if [ "$ret" != "0" ]; then
399 diff -u $testroot/stdout.expected $testroot/stdout
400 test_done "$testroot" "$ret"
401 return 1
402 fi
404 echo ' M alpha' > $testroot/stdout.expected
405 echo ' D beta' >> $testroot/stdout.expected
406 echo ' A foo' >> $testroot/stdout.expected
408 (cd $testroot/wt && got status > $testroot/stdout)
409 cmp -s $testroot/stdout.expected $testroot/stdout
410 ret="$?"
411 if [ "$ret" != "0" ]; then
412 diff -u $testroot/stdout.expected $testroot/stdout
413 fi
414 test_done "$testroot" "$ret"
417 function test_stage_status {
418 local testroot=`test_init stage_status`
420 got checkout $testroot/repo $testroot/wt > /dev/null
421 ret="$?"
422 if [ "$ret" != "0" ]; then
423 test_done "$testroot" "$ret"
424 return 1
425 fi
427 echo "modified file" > $testroot/wt/alpha
428 (cd $testroot/wt && got rm beta > /dev/null)
429 echo "new file" > $testroot/wt/foo
430 (cd $testroot/wt && got add foo > /dev/null)
431 echo "new file" > $testroot/wt/epsilon/new
432 (cd $testroot/wt && got add epsilon/new > /dev/null)
433 echo "modified file" > $testroot/wt/epsilon/zeta
434 (cd $testroot/wt && got rm gamma/delta > /dev/null)
436 echo ' M alpha' > $testroot/stdout.expected
437 echo ' D beta' >> $testroot/stdout.expected
438 echo 'A epsilon/new' >> $testroot/stdout.expected
439 echo 'M epsilon/zeta' >> $testroot/stdout.expected
440 echo ' A foo' >> $testroot/stdout.expected
441 echo 'D gamma/delta' >> $testroot/stdout.expected
442 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
444 (cd $testroot/wt && got status > $testroot/stdout)
445 cmp -s $testroot/stdout.expected $testroot/stdout
446 ret="$?"
447 if [ "$ret" != "0" ]; then
448 diff -u $testroot/stdout.expected $testroot/stdout
449 test_done "$testroot" "$ret"
450 return 1
451 fi
453 echo "modified file again" >> $testroot/wt/alpha
454 echo "modified added file again" >> $testroot/wt/foo
456 echo 'MM alpha' > $testroot/stdout.expected
457 echo ' D beta' >> $testroot/stdout.expected
458 echo 'A epsilon/new' >> $testroot/stdout.expected
459 echo 'M epsilon/zeta' >> $testroot/stdout.expected
460 echo 'MA foo' >> $testroot/stdout.expected
461 echo 'D gamma/delta' >> $testroot/stdout.expected
463 (cd $testroot/wt && got status > $testroot/stdout)
464 cmp -s $testroot/stdout.expected $testroot/stdout
465 ret="$?"
466 if [ "$ret" != "0" ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 # test no-op change of added file with new stat(2) timestamp
473 echo "new file" > $testroot/wt/foo
474 echo ' A foo' > $testroot/stdout.expected
475 (cd $testroot/wt && got status foo > $testroot/stdout)
476 cmp -s $testroot/stdout.expected $testroot/stdout
477 ret="$?"
478 if [ "$ret" != "0" ]; then
479 diff -u $testroot/stdout.expected $testroot/stdout
480 test_done "$testroot" "$ret"
481 return 1
482 fi
484 # test staged deleted file which is restored on disk
485 echo "new file" > $testroot/wt/beta
486 echo ' D beta' > $testroot/stdout.expected
487 (cd $testroot/wt && got status beta > $testroot/stdout)
488 cmp -s $testroot/stdout.expected $testroot/stdout
489 ret="$?"
490 if [ "$ret" != "0" ]; then
491 diff -u $testroot/stdout.expected $testroot/stdout
492 fi
493 test_done "$testroot" "$ret"
497 function test_stage_add_already_staged_file {
498 local testroot=`test_init stage_add_already_staged_file`
500 got checkout $testroot/repo $testroot/wt > /dev/null
501 ret="$?"
502 if [ "$ret" != "0" ]; then
503 test_done "$testroot" "$ret"
504 return 1
505 fi
507 echo "modified file" > $testroot/wt/alpha
508 (cd $testroot/wt && got rm beta > /dev/null)
509 echo "new file" > $testroot/wt/foo
510 (cd $testroot/wt && got add foo > /dev/null)
512 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
514 echo -n > $testroot/stdout.expected
515 for f in alpha beta foo; do
516 (cd $testroot/wt && got add $f \
517 > $testroot/stdout 2> $testroot/stderr)
518 echo "got: $f: file has unexpected status" \
519 > $testroot/stderr.expected
520 cmp -s $testroot/stderr.expected $testroot/stderr
521 ret="$?"
522 if [ "$ret" != "0" ]; then
523 diff -u $testroot/stderr.expected $testroot/stderr
524 test_done "$testroot" "$ret"
525 return 1
526 fi
527 cmp -s $testroot/stdout.expected $testroot/stdout
528 ret="$?"
529 if [ "$ret" != "0" ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 test_done "$testroot" "$ret"
532 return 1
533 fi
534 done
536 echo ' M alpha' > $testroot/stdout.expected
537 echo ' D beta' >> $testroot/stdout.expected
538 echo ' A foo' >> $testroot/stdout.expected
540 (cd $testroot/wt && got status > $testroot/stdout)
541 cmp -s $testroot/stdout.expected $testroot/stdout
542 ret="$?"
543 if [ "$ret" != "0" ]; then
544 diff -u $testroot/stdout.expected $testroot/stdout
545 fi
546 test_done "$testroot" "$ret"
549 function test_stage_rm_already_staged_file {
550 local testroot=`test_init stage_rm_already_staged_file`
552 got checkout $testroot/repo $testroot/wt > /dev/null
553 ret="$?"
554 if [ "$ret" != "0" ]; then
555 test_done "$testroot" "$ret"
556 return 1
557 fi
559 echo "modified file" > $testroot/wt/alpha
560 (cd $testroot/wt && got rm beta > /dev/null)
561 echo "new file" > $testroot/wt/foo
562 (cd $testroot/wt && got add foo > /dev/null)
564 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
566 (cd $testroot/wt && got rm beta \
567 > $testroot/stdout 2> $testroot/stderr)
568 ret="$?"
569 if [ "$ret" != "0" ]; then
570 echo "got rm command failed unexpectedly" >&2
571 test_done "$testroot" "1"
572 return 1
573 fi
574 echo -n > $testroot/stdout.expected
575 cmp -s $testroot/stdout.expected $testroot/stdout
576 ret="$?"
577 if [ "$ret" != "0" ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 test_done "$testroot" "$ret"
580 return 1
581 fi
582 echo -n > $testroot/stderr.expected
583 cmp -s $testroot/stderr.expected $testroot/stderr
584 ret="$?"
585 if [ "$ret" != "0" ]; then
586 diff -u $testroot/stderr.expected $testroot/stderr
587 test_done "$testroot" "$ret"
588 return 1
589 fi
591 for f in alpha foo; do
592 echo "got: $f: file is staged" > $testroot/stderr.expected
593 (cd $testroot/wt && got rm $f \
594 > $testroot/stdout 2> $testroot/stderr)
595 ret="$?"
596 if [ "$ret" == "0" ]; then
597 echo "got rm command succeeded unexpectedly" >&2
598 test_done "$testroot" "1"
599 return 1
600 fi
601 cmp -s $testroot/stderr.expected $testroot/stderr
602 ret="$?"
603 if [ "$ret" != "0" ]; then
604 diff -u $testroot/stderr.expected $testroot/stderr
605 test_done "$testroot" "$ret"
606 return 1
607 fi
608 done
610 echo ' M alpha' > $testroot/stdout.expected
611 echo ' D beta' >> $testroot/stdout.expected
612 echo ' A foo' >> $testroot/stdout.expected
614 (cd $testroot/wt && got status > $testroot/stdout)
615 cmp -s $testroot/stdout.expected $testroot/stdout
616 ret="$?"
617 if [ "$ret" != "0" ]; then
618 diff -u $testroot/stdout.expected $testroot/stdout
619 fi
620 test_done "$testroot" "$ret"
623 function test_stage_revert {
624 local testroot=`test_init stage_revert`
626 got checkout $testroot/repo $testroot/wt > /dev/null
627 ret="$?"
628 if [ "$ret" != "0" ]; then
629 test_done "$testroot" "$ret"
630 return 1
631 fi
633 echo "modified alpha" > $testroot/wt/alpha
634 (cd $testroot/wt && got rm beta > /dev/null)
635 echo "new file" > $testroot/wt/foo
636 (cd $testroot/wt && got add foo > /dev/null)
637 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
639 echo "modified file again" >> $testroot/wt/alpha
640 echo "modified added file again" >> $testroot/wt/foo
642 (cd $testroot/wt && got revert alpha > $testroot/stdout)
643 ret="$?"
644 if [ "$ret" != "0" ]; then
645 echo "revert command failed unexpectedly" >&2
646 test_done "$testroot" "$ret"
647 return 1
648 fi
650 echo "R alpha" > $testroot/stdout.expected
651 cmp -s $testroot/stdout.expected $testroot/stdout
652 ret="$?"
653 if [ "$ret" != "0" ]; then
654 diff -u $testroot/stdout.expected $testroot/stdout
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 echo "modified alpha" > $testroot/content.expected
660 cat $testroot/wt/alpha > $testroot/content
661 cmp -s $testroot/content.expected $testroot/content
662 ret="$?"
663 if [ "$ret" != "0" ]; then
664 diff -u $testroot/content.expected $testroot/content
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 echo ' M alpha' > $testroot/stdout.expected
670 echo ' D beta' >> $testroot/stdout.expected
671 echo 'MA foo' >> $testroot/stdout.expected
672 (cd $testroot/wt && got status > $testroot/stdout)
673 cmp -s $testroot/stdout.expected $testroot/stdout
674 ret="$?"
675 if [ "$ret" != "0" ]; then
676 diff -u $testroot/stdout.expected $testroot/stdout
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 (cd $testroot/wt && got revert alpha > $testroot/stdout)
682 ret="$?"
683 if [ "$ret" != "0" ]; then
684 echo "revert command failed unexpectedly" >&2
685 test_done "$testroot" "$ret"
686 return 1
687 fi
689 echo -n > $testroot/stdout.expected
690 cmp -s $testroot/stdout.expected $testroot/stdout
691 ret="$?"
692 if [ "$ret" != "0" ]; then
693 diff -u $testroot/stdout.expected $testroot/stdout
694 test_done "$testroot" "$ret"
695 return 1
696 fi
698 echo "modified alpha" > $testroot/content.expected
699 cat $testroot/wt/alpha > $testroot/content
700 cmp -s $testroot/content.expected $testroot/content
701 ret="$?"
702 if [ "$ret" != "0" ]; then
703 diff -u $testroot/content.expected $testroot/content
704 test_done "$testroot" "$ret"
705 return 1
706 fi
708 (cd $testroot/wt && got revert beta > $testroot/stdout \
709 2> $testroot/stderr)
710 ret="$?"
711 if [ "$ret" == "0" ]; then
712 echo "revert command succeeded unexpectedly" >&2
713 test_done "$testroot" "1"
714 return 1
715 fi
717 echo "got: beta: file is staged" > $testroot/stderr.expected
718 cmp -s $testroot/stderr.expected $testroot/stderr
719 ret="$?"
720 if [ "$ret" != "0" ]; then
721 diff -u $testroot/stderr.expected $testroot/stderr
722 test_done "$testroot" "$ret"
723 return 1
724 fi
726 (cd $testroot/wt && got revert foo > $testroot/stdout)
727 ret="$?"
728 if [ "$ret" != "0" ]; then
729 echo "revert command failed unexpectedly" >&2
730 test_done "$testroot" "$ret"
731 return 1
732 fi
734 echo "R foo" > $testroot/stdout.expected
735 cmp -s $testroot/stdout.expected $testroot/stdout
736 ret="$?"
737 if [ "$ret" != "0" ]; then
738 diff -u $testroot/stdout.expected $testroot/stdout
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 echo "new file" > $testroot/content.expected
744 cat $testroot/wt/foo > $testroot/content
745 cmp -s $testroot/content.expected $testroot/content
746 ret="$?"
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/content.expected $testroot/content
749 test_done "$testroot" "$ret"
750 return 1
751 fi
753 echo ' M alpha' > $testroot/stdout.expected
754 echo ' D beta' >> $testroot/stdout.expected
755 echo ' A foo' >> $testroot/stdout.expected
756 (cd $testroot/wt && got status > $testroot/stdout)
757 cmp -s $testroot/stdout.expected $testroot/stdout
758 ret="$?"
759 if [ "$ret" != "0" ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
761 test_done "$testroot" "$ret"
762 return 1
763 fi
765 (cd $testroot/wt && got revert foo > $testroot/stdout)
766 ret="$?"
767 if [ "$ret" != "0" ]; then
768 echo "revert command failed unexpectedly" >&2
769 test_done "$testroot" "$ret"
770 return 1
771 fi
773 echo -n > $testroot/stdout.expected
774 cmp -s $testroot/stdout.expected $testroot/stdout
775 ret="$?"
776 if [ "$ret" != "0" ]; then
777 diff -u $testroot/stdout.expected $testroot/stdout
778 test_done "$testroot" "$ret"
779 return 1
780 fi
782 echo "new file" > $testroot/content.expected
783 cat $testroot/wt/foo > $testroot/content
784 cmp -s $testroot/content.expected $testroot/content
785 ret="$?"
786 if [ "$ret" != "0" ]; then
787 diff -u $testroot/content.expected $testroot/content
788 test_done "$testroot" "$ret"
789 return 1
790 fi
792 echo ' M alpha' > $testroot/stdout.expected
793 echo ' D beta' >> $testroot/stdout.expected
794 echo ' A foo' >> $testroot/stdout.expected
795 (cd $testroot/wt && got status > $testroot/stdout)
796 cmp -s $testroot/stdout.expected $testroot/stdout
797 ret="$?"
798 if [ "$ret" != "0" ]; then
799 diff -u $testroot/stdout.expected $testroot/stdout
800 fi
801 test_done "$testroot" "$ret"
804 function test_stage_diff {
805 local testroot=`test_init stage_diff`
806 local head_commit=`git_show_head $testroot/repo`
808 got checkout $testroot/repo $testroot/wt > /dev/null
809 ret="$?"
810 if [ "$ret" != "0" ]; then
811 test_done "$testroot" "$ret"
812 return 1
813 fi
815 echo "modified file" > $testroot/wt/alpha
816 (cd $testroot/wt && got rm beta > /dev/null)
817 echo "new file" > $testroot/wt/foo
818 (cd $testroot/wt && got add foo > /dev/null)
820 (cd $testroot/wt && got diff -s > $testroot/stdout)
821 echo -n > $testroot/stdout.expected
822 cmp -s $testroot/stdout.expected $testroot/stdout
823 ret="$?"
824 if [ "$ret" != "0" ]; then
825 diff -u $testroot/stdout.expected $testroot/stdout
826 test_done "$testroot" "$ret"
827 return 1
828 fi
830 echo ' M alpha' > $testroot/stdout.expected
831 echo ' D beta' >> $testroot/stdout.expected
832 echo ' A foo' >> $testroot/stdout.expected
833 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
835 (cd $testroot/wt && got diff > $testroot/stdout)
836 echo -n > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
838 ret="$?"
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
841 test_done "$testroot" "$ret"
842 return 1
843 fi
845 echo "modified file again" > $testroot/wt/alpha
846 echo "new file changed" > $testroot/wt/foo
848 (cd $testroot/wt && got diff > $testroot/stdout)
850 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
851 echo -n 'blob - ' >> $testroot/stdout.expected
852 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
853 >> $testroot/stdout.expected
854 echo ' (staged)' >> $testroot/stdout.expected
855 echo 'file + alpha' >> $testroot/stdout.expected
856 echo '--- alpha' >> $testroot/stdout.expected
857 echo '+++ alpha' >> $testroot/stdout.expected
858 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
859 echo '-modified file' >> $testroot/stdout.expected
860 echo '+modified file again' >> $testroot/stdout.expected
861 echo -n 'blob - ' >> $testroot/stdout.expected
862 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
863 >> $testroot/stdout.expected
864 echo " (staged)" >> $testroot/stdout.expected
865 echo 'file + foo' >> $testroot/stdout.expected
866 echo '--- foo' >> $testroot/stdout.expected
867 echo '+++ foo' >> $testroot/stdout.expected
868 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
869 echo '-new file' >> $testroot/stdout.expected
870 echo '+new file changed' >> $testroot/stdout.expected
872 cmp -s $testroot/stdout.expected $testroot/stdout
873 ret="$?"
874 if [ "$ret" != "0" ]; then
875 diff -u $testroot/stdout.expected $testroot/stdout
876 test_done "$testroot" "$ret"
877 return 1
878 fi
880 (cd $testroot/wt && got diff -s > $testroot/stdout)
882 echo "diff $head_commit $testroot/wt (staged changes)" \
883 > $testroot/stdout.expected
884 echo -n 'blob - ' >> $testroot/stdout.expected
885 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
886 >> $testroot/stdout.expected
887 echo -n 'blob + ' >> $testroot/stdout.expected
888 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
889 >> $testroot/stdout.expected
890 echo '--- alpha' >> $testroot/stdout.expected
891 echo '+++ alpha' >> $testroot/stdout.expected
892 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
893 echo '-alpha' >> $testroot/stdout.expected
894 echo '+modified file' >> $testroot/stdout.expected
895 echo -n 'blob - ' >> $testroot/stdout.expected
896 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
897 >> $testroot/stdout.expected
898 echo 'blob + /dev/null' >> $testroot/stdout.expected
899 echo '--- beta' >> $testroot/stdout.expected
900 echo '+++ /dev/null' >> $testroot/stdout.expected
901 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
902 echo '-beta' >> $testroot/stdout.expected
903 echo 'blob - /dev/null' >> $testroot/stdout.expected
904 echo -n 'blob + ' >> $testroot/stdout.expected
905 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
906 >> $testroot/stdout.expected
907 echo '--- /dev/null' >> $testroot/stdout.expected
908 echo '+++ foo' >> $testroot/stdout.expected
909 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
910 echo '+new file' >> $testroot/stdout.expected
912 cmp -s $testroot/stdout.expected $testroot/stdout
913 ret="$?"
914 if [ "$ret" != "0" ]; then
915 diff -u $testroot/stdout.expected $testroot/stdout
916 fi
917 test_done "$testroot" "$ret"
921 function test_stage_histedit {
922 local testroot=`test_init stage_histedit`
923 local orig_commit=`git_show_head $testroot/repo`
925 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
926 ret="$?"
927 if [ "$ret" != "0" ]; then
928 test_done "$testroot" "$ret"
929 return 1
930 fi
932 echo "modified file" > $testroot/wt/alpha
933 (cd $testroot/wt && got stage alpha > /dev/null)
935 echo "modified alpha on master" > $testroot/repo/alpha
936 (cd $testroot/repo && git rm -q beta)
937 echo "new file on master" > $testroot/repo/epsilon/new
938 (cd $testroot/repo && git add epsilon/new)
939 git_commit $testroot/repo -m "committing changes"
940 local old_commit1=`git_show_head $testroot/repo`
942 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
943 git_commit $testroot/repo -m "committing to zeta on master"
944 local old_commit2=`git_show_head $testroot/repo`
946 echo "pick $old_commit1" > $testroot/histedit-script
947 echo "pick $old_commit2" >> $testroot/histedit-script
949 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
950 > $testroot/stdout 2> $testroot/stderr)
951 ret="$?"
952 if [ "$ret" == "0" ]; then
953 echo "got histedit command succeeded unexpectedly" >&2
954 test_done "$testroot" "1"
955 return 1
956 fi
958 echo -n > $testroot/stdout.expected
959 echo "got: alpha: file is staged" > $testroot/stderr.expected
961 cmp -s $testroot/stderr.expected $testroot/stderr
962 ret="$?"
963 if [ "$ret" != "0" ]; then
964 diff -u $testroot/stderr.expected $testroot/stderr
965 test_done "$testroot" "$ret"
966 return 1
967 fi
968 cmp -s $testroot/stdout.expected $testroot/stdout
969 ret="$?"
970 if [ "$ret" != "0" ]; then
971 diff -u $testroot/stdout.expected $testroot/stdout
972 fi
973 test_done "$testroot" "$ret"
977 function test_stage_rebase {
978 local testroot=`test_init stage_rebase`
980 (cd $testroot/repo && git checkout -q -b newbranch)
981 echo "modified delta on branch" > $testroot/repo/gamma/delta
982 git_commit $testroot/repo -m "committing to delta on newbranch"
984 echo "modified alpha on branch" > $testroot/repo/alpha
985 (cd $testroot/repo && git rm -q beta)
986 echo "new file on branch" > $testroot/repo/epsilon/new
987 (cd $testroot/repo && git add epsilon/new)
988 git_commit $testroot/repo -m "committing more changes on newbranch"
990 local orig_commit1=`git_show_parent_commit $testroot/repo`
991 local orig_commit2=`git_show_head $testroot/repo`
993 (cd $testroot/repo && git checkout -q master)
994 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
995 git_commit $testroot/repo -m "committing to zeta on master"
996 local master_commit=`git_show_head $testroot/repo`
998 got checkout $testroot/repo $testroot/wt > /dev/null
999 ret="$?"
1000 if [ "$ret" != "0" ]; then
1001 test_done "$testroot" "$ret"
1002 return 1
1005 echo "modified file" > $testroot/wt/alpha
1006 (cd $testroot/wt && got stage alpha > /dev/null)
1008 (cd $testroot/wt && got rebase newbranch \
1009 > $testroot/stdout 2> $testroot/stderr)
1010 ret="$?"
1011 if [ "$ret" == "0" ]; then
1012 echo "got rebase command succeeded unexpectedly" >&2
1013 test_done "$testroot" "1"
1014 return 1
1017 echo -n > $testroot/stdout.expected
1018 echo "got: alpha: file is staged" > $testroot/stderr.expected
1020 cmp -s $testroot/stderr.expected $testroot/stderr
1021 ret="$?"
1022 if [ "$ret" != "0" ]; then
1023 diff -u $testroot/stderr.expected $testroot/stderr
1024 test_done "$testroot" "$ret"
1025 return 1
1027 cmp -s $testroot/stdout.expected $testroot/stdout
1028 ret="$?"
1029 if [ "$ret" != "0" ]; then
1030 diff -u $testroot/stdout.expected $testroot/stdout
1032 test_done "$testroot" "$ret"
1035 function test_stage_update {
1036 local testroot=`test_init stage_update`
1038 got checkout $testroot/repo $testroot/wt > /dev/null
1039 ret="$?"
1040 if [ "$ret" != "0" ]; then
1041 test_done "$testroot" "$ret"
1042 return 1
1045 echo "modified file" > $testroot/wt/alpha
1046 (cd $testroot/wt && got stage alpha > /dev/null)
1048 echo "modified alpha" > $testroot/repo/alpha
1049 git_commit $testroot/repo -m "modified alpha"
1051 (cd $testroot/wt && got update > $testroot/stdout \
1052 2> $testroot/stderr)
1053 ret="$?"
1054 if [ "$ret" == "0" ]; then
1055 echo "got update command succeeded unexpectedly" >&2
1056 test_done "$testroot" "1"
1057 return 1
1060 echo -n > $testroot/stdout.expected
1061 echo "got: alpha: file is staged" > $testroot/stderr.expected
1063 cmp -s $testroot/stderr.expected $testroot/stderr
1064 ret="$?"
1065 if [ "$ret" != "0" ]; then
1066 diff -u $testroot/stderr.expected $testroot/stderr
1067 test_done "$testroot" "$ret"
1068 return 1
1070 cmp -s $testroot/stdout.expected $testroot/stdout
1071 ret="$?"
1072 if [ "$ret" != "0" ]; then
1073 diff -u $testroot/stdout.expected $testroot/stdout
1075 test_done "$testroot" "$ret"
1078 function test_stage_commit_non_staged {
1079 local testroot=`test_init stage_commit_non_staged`
1081 got checkout $testroot/repo $testroot/wt > /dev/null
1082 ret="$?"
1083 if [ "$ret" != "0" ]; then
1084 test_done "$testroot" "$ret"
1085 return 1
1088 echo "modified file" > $testroot/wt/alpha
1089 (cd $testroot/wt && got rm beta > /dev/null)
1090 echo "new file" > $testroot/wt/foo
1091 (cd $testroot/wt && got add foo > /dev/null)
1092 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1094 echo "modified file" > $testroot/wt/gamma/delta
1095 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1096 > $testroot/stdout 2> $testroot/stderr)
1097 ret="$?"
1098 if [ "$ret" == "0" ]; then
1099 echo "got commit command succeeded unexpectedly" >&2
1100 test_done "$testroot" "1"
1101 return 1
1104 echo -n > $testroot/stdout.expected
1105 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1107 cmp -s $testroot/stderr.expected $testroot/stderr
1108 ret="$?"
1109 if [ "$ret" != "0" ]; then
1110 diff -u $testroot/stderr.expected $testroot/stderr
1111 test_done "$testroot" "$ret"
1112 return 1
1114 cmp -s $testroot/stdout.expected $testroot/stdout
1115 ret="$?"
1116 if [ "$ret" != "0" ]; then
1117 diff -u $testroot/stdout.expected $testroot/stdout
1119 test_done "$testroot" "$ret"
1122 function test_stage_commit_out_of_date {
1123 local testroot=`test_init stage_commit_out_of_date`
1125 got checkout $testroot/repo $testroot/wt > /dev/null
1126 ret="$?"
1127 if [ "$ret" != "0" ]; then
1128 test_done "$testroot" "$ret"
1129 return 1
1132 echo "modified file" > $testroot/wt/alpha
1133 (cd $testroot/wt && got rm beta > /dev/null)
1134 echo "new file" > $testroot/wt/foo
1135 (cd $testroot/wt && got add foo > /dev/null)
1136 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1138 echo "changed file" > $testroot/repo/alpha
1139 git_commit $testroot/repo -m "changed alpha in repo"
1141 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1142 2> $testroot/stderr)
1143 ret="$?"
1144 if [ "$ret" == "0" ]; then
1145 echo "got commit command succeeded unexpectedly" >&2
1146 test_done "$testroot" "1"
1147 return 1
1150 echo -n > $testroot/stdout.expected
1151 echo -n "got: work tree must be updated before these changes " \
1152 > $testroot/stderr.expected
1153 echo "can be committed" >> $testroot/stderr.expected
1155 cmp -s $testroot/stderr.expected $testroot/stderr
1156 ret="$?"
1157 if [ "$ret" != "0" ]; then
1158 diff -u $testroot/stderr.expected $testroot/stderr
1159 test_done "$testroot" "$ret"
1160 return 1
1162 cmp -s $testroot/stdout.expected $testroot/stdout
1163 ret="$?"
1164 if [ "$ret" != "0" ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1166 test_done "$testroot" "$ret"
1167 return 1
1170 (cd $testroot/wt && got update > $testroot/stdout \
1171 2> $testroot/stderr)
1172 echo -n > $testroot/stdout.expected
1173 echo "got: alpha: file is staged" > $testroot/stderr.expected
1175 cmp -s $testroot/stderr.expected $testroot/stderr
1176 ret="$?"
1177 if [ "$ret" != "0" ]; then
1178 diff -u $testroot/stderr.expected $testroot/stderr
1179 test_done "$testroot" "$ret"
1180 return 1
1182 cmp -s $testroot/stdout.expected $testroot/stdout
1183 ret="$?"
1184 if [ "$ret" != "0" ]; then
1185 diff -u $testroot/stdout.expected $testroot/stdout
1186 test_done "$testroot" "$ret"
1187 return 1
1190 (cd $testroot/wt && got unstage > /dev/null)
1191 (cd $testroot/wt && got update > $testroot/stdout)
1192 ret="$?"
1193 if [ "$ret" != "0" ]; then
1194 echo "got update command failed unexpectedly" >&2
1195 test_done "$testroot" "$ret"
1196 return 1
1199 (cd $testroot/wt && got status > $testroot/stdout)
1200 echo "C alpha" > $testroot/stdout.expected
1201 echo "D beta" >> $testroot/stdout.expected
1202 echo "A foo" >> $testroot/stdout.expected
1203 cmp -s $testroot/stdout.expected $testroot/stdout
1204 ret="$?"
1205 if [ "$ret" != "0" ]; then
1206 diff -u $testroot/stdout.expected $testroot/stdout
1207 test_done "$testroot" "$ret"
1208 return 1
1211 # resolve conflict
1212 echo "resolved file" > $testroot/wt/alpha
1214 (cd $testroot/wt && got stage > /dev/null)
1216 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1217 ret="$?"
1218 if [ "$ret" != "0" ]; then
1219 echo "got commit command failed unexpectedly" >&2
1220 test_done "$testroot" "$ret"
1221 return 1
1224 local commit_id=`git_show_head $testroot/repo`
1225 echo "A foo" > $testroot/stdout.expected
1226 echo "M alpha" >> $testroot/stdout.expected
1227 echo "D beta" >> $testroot/stdout.expected
1228 echo "Created commit $commit_id" >> $testroot/stdout.expected
1229 cmp -s $testroot/stdout.expected $testroot/stdout
1230 ret="$?"
1231 if [ "$ret" != "0" ]; then
1232 diff -u $testroot/stdout.expected $testroot/stdout
1234 test_done "$testroot" "$ret"
1238 function test_stage_commit {
1239 local testroot=`test_init stage_commit`
1240 local first_commit=`git_show_head $testroot/repo`
1242 got checkout $testroot/repo $testroot/wt > /dev/null
1243 ret="$?"
1244 if [ "$ret" != "0" ]; then
1245 test_done "$testroot" "$ret"
1246 return 1
1249 echo "modified file" > $testroot/wt/alpha
1250 (cd $testroot/wt && got rm beta > /dev/null)
1251 echo "new file" > $testroot/wt/foo
1252 (cd $testroot/wt && got add foo > /dev/null)
1253 echo "modified file" > $testroot/wt/alpha
1254 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1256 echo "modified file again" > $testroot/wt/alpha
1257 echo "new file changed" > $testroot/wt/foo
1258 echo "non-staged change" > $testroot/wt/gamma/delta
1259 echo "non-staged new file" > $testroot/wt/epsilon/new
1260 (cd $testroot/wt && got add epsilon/new > /dev/null)
1261 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1263 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1264 > $testroot/blob_id_alpha
1265 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1266 > $testroot/blob_id_foo
1268 (cd $testroot/wt && got commit -m "staged changes" \
1269 > $testroot/stdout)
1270 ret="$?"
1271 if [ "$ret" != "0" ]; then
1272 echo "got commit command failed unexpectedly" >&2
1273 test_done "$testroot" "1"
1274 return 1
1277 local head_commit=`git_show_head $testroot/repo`
1278 echo "A foo" > $testroot/stdout.expected
1279 echo "M alpha" >> $testroot/stdout.expected
1280 echo "D beta" >> $testroot/stdout.expected
1281 echo "Created commit $head_commit" >> $testroot/stdout.expected
1283 cmp -s $testroot/stdout.expected $testroot/stdout
1284 ret="$?"
1285 if [ "$ret" != "0" ]; then
1286 diff -u $testroot/stdout.expected $testroot/stdout
1287 test_done "$testroot" "$ret"
1288 return 1
1291 got diff -r $testroot/repo $first_commit $head_commit \
1292 > $testroot/stdout
1294 echo "diff $first_commit $head_commit" \
1295 > $testroot/stdout.expected
1296 echo -n 'blob - ' >> $testroot/stdout.expected
1297 got tree -r $testroot/repo -i -c $first_commit | \
1298 grep 'alpha$' | cut -d' ' -f 1 \
1299 >> $testroot/stdout.expected
1300 echo -n 'blob + ' >> $testroot/stdout.expected
1301 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1302 echo '--- alpha' >> $testroot/stdout.expected
1303 echo '+++ alpha' >> $testroot/stdout.expected
1304 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1305 echo '-alpha' >> $testroot/stdout.expected
1306 echo '+modified file' >> $testroot/stdout.expected
1307 echo -n 'blob - ' >> $testroot/stdout.expected
1308 got tree -r $testroot/repo -i -c $first_commit \
1309 | grep 'beta$' | cut -d' ' -f 1 \
1310 >> $testroot/stdout.expected
1311 echo 'blob + /dev/null' >> $testroot/stdout.expected
1312 echo '--- beta' >> $testroot/stdout.expected
1313 echo '+++ /dev/null' >> $testroot/stdout.expected
1314 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1315 echo '-beta' >> $testroot/stdout.expected
1316 echo 'blob - /dev/null' >> $testroot/stdout.expected
1317 echo -n 'blob + ' >> $testroot/stdout.expected
1318 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1319 echo '--- /dev/null' >> $testroot/stdout.expected
1320 echo '+++ foo' >> $testroot/stdout.expected
1321 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1322 echo '+new file' >> $testroot/stdout.expected
1324 cmp -s $testroot/stdout.expected $testroot/stdout
1325 ret="$?"
1326 if [ "$ret" != "0" ]; then
1327 diff -u $testroot/stdout.expected $testroot/stdout
1328 test_done "$testroot" "$ret"
1329 return 1
1332 echo 'A epsilon/new' > $testroot/stdout.expected
1333 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1334 echo 'M gamma/delta' >> $testroot/stdout.expected
1336 (cd $testroot/wt && got status > $testroot/stdout)
1337 cmp -s $testroot/stdout.expected $testroot/stdout
1338 ret="$?"
1339 if [ "$ret" != "0" ]; then
1340 diff -u $testroot/stdout.expected $testroot/stdout
1342 test_done "$testroot" "$ret"
1345 function test_stage_patch {
1346 local testroot=`test_init stage_patch`
1348 jot 16 > $testroot/repo/numbers
1349 (cd $testroot/repo && git add numbers)
1350 git_commit $testroot/repo -m "added numbers file"
1351 local commit_id=`git_show_head $testroot/repo`
1353 got checkout $testroot/repo $testroot/wt > /dev/null
1354 ret="$?"
1355 if [ "$ret" != "0" ]; then
1356 test_done "$testroot" "$ret"
1357 return 1
1360 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1361 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1362 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1364 # don't stage any hunks
1365 printf "n\nn\nn\n" > $testroot/patchscript
1366 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1367 numbers > $testroot/stdout)
1368 ret="$?"
1369 if [ "$ret" != "0" ]; then
1370 echo "got stage command failed unexpectedly" >&2
1371 test_done "$testroot" "1"
1372 return 1
1374 cat > $testroot/stdout.expected <<EOF
1375 -----------------------------------------------
1376 @@ -1,5 +1,5 @@
1383 -----------------------------------------------
1384 M numbers (change 1 of 3)
1385 stage this change? [y/n/q] n
1386 -----------------------------------------------
1387 @@ -4,7 +4,7 @@
1396 -----------------------------------------------
1397 M numbers (change 2 of 3)
1398 stage this change? [y/n/q] n
1399 -----------------------------------------------
1400 @@ -13,4 +13,4 @@
1404 -16
1406 -----------------------------------------------
1407 M numbers (change 3 of 3)
1408 stage this change? [y/n/q] n
1409 EOF
1410 cmp -s $testroot/stdout.expected $testroot/stdout
1411 ret="$?"
1412 if [ "$ret" != "0" ]; then
1413 diff -u $testroot/stdout.expected $testroot/stdout
1414 test_done "$testroot" "$ret"
1415 return 1
1418 (cd $testroot/wt && got status > $testroot/stdout)
1419 echo "M numbers" > $testroot/stdout.expected
1420 cmp -s $testroot/stdout.expected $testroot/stdout
1421 ret="$?"
1422 if [ "$ret" != "0" ]; then
1423 diff -u $testroot/stdout.expected $testroot/stdout
1424 test_done "$testroot" "$ret"
1425 return 1
1428 # stage middle hunk
1429 printf "n\ny\nn\n" > $testroot/patchscript
1430 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1431 numbers > $testroot/stdout)
1433 cat > $testroot/stdout.expected <<EOF
1434 -----------------------------------------------
1435 @@ -1,5 +1,5 @@
1442 -----------------------------------------------
1443 M numbers (change 1 of 3)
1444 stage this change? [y/n/q] n
1445 -----------------------------------------------
1446 @@ -4,7 +4,7 @@
1455 -----------------------------------------------
1456 M numbers (change 2 of 3)
1457 stage this change? [y/n/q] y
1458 -----------------------------------------------
1459 @@ -13,4 +13,4 @@
1463 -16
1465 -----------------------------------------------
1466 M numbers (change 3 of 3)
1467 stage this change? [y/n/q] n
1468 EOF
1469 cmp -s $testroot/stdout.expected $testroot/stdout
1470 ret="$?"
1471 if [ "$ret" != "0" ]; then
1472 diff -u $testroot/stdout.expected $testroot/stdout
1473 test_done "$testroot" "$ret"
1474 return 1
1477 (cd $testroot/wt && got status > $testroot/stdout)
1478 echo "MM numbers" > $testroot/stdout.expected
1479 cmp -s $testroot/stdout.expected $testroot/stdout
1480 ret="$?"
1481 if [ "$ret" != "0" ]; then
1482 diff -u $testroot/stdout.expected $testroot/stdout
1483 test_done "$testroot" "$ret"
1484 return 1
1487 (cd $testroot/wt && got diff -s > $testroot/stdout)
1489 echo "diff $commit_id $testroot/wt (staged changes)" \
1490 > $testroot/stdout.expected
1491 echo -n 'blob - ' >> $testroot/stdout.expected
1492 got tree -r $testroot/repo -i -c $commit_id \
1493 | grep 'numbers$' | cut -d' ' -f 1 \
1494 >> $testroot/stdout.expected
1495 echo -n 'blob + ' >> $testroot/stdout.expected
1496 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1497 >> $testroot/stdout.expected
1498 echo "--- numbers" >> $testroot/stdout.expected
1499 echo "+++ numbers" >> $testroot/stdout.expected
1500 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1501 echo " 4" >> $testroot/stdout.expected
1502 echo " 5" >> $testroot/stdout.expected
1503 echo " 6" >> $testroot/stdout.expected
1504 echo "-7" >> $testroot/stdout.expected
1505 echo "+b" >> $testroot/stdout.expected
1506 echo " 8" >> $testroot/stdout.expected
1507 echo " 9" >> $testroot/stdout.expected
1508 echo " 10" >> $testroot/stdout.expected
1509 cmp -s $testroot/stdout.expected $testroot/stdout
1510 ret="$?"
1511 if [ "$ret" != "0" ]; then
1512 diff -u $testroot/stdout.expected $testroot/stdout
1513 test_done "$testroot" "$ret"
1514 return 1
1517 (cd $testroot/wt && got unstage >/dev/null)
1518 ret="$?"
1519 if [ "$ret" != "0" ]; then
1520 echo "got stage command failed unexpectedly" >&2
1521 test_done "$testroot" "1"
1522 return 1
1524 (cd $testroot/wt && got status > $testroot/stdout)
1525 echo "M numbers" > $testroot/stdout.expected
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1527 ret="$?"
1528 if [ "$ret" != "0" ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1531 return 1
1534 # stage last hunk
1535 printf "n\nn\ny\n" > $testroot/patchscript
1536 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1537 numbers > $testroot/stdout)
1539 cat > $testroot/stdout.expected <<EOF
1540 -----------------------------------------------
1541 @@ -1,5 +1,5 @@
1548 -----------------------------------------------
1549 M numbers (change 1 of 3)
1550 stage this change? [y/n/q] n
1551 -----------------------------------------------
1552 @@ -4,7 +4,7 @@
1561 -----------------------------------------------
1562 M numbers (change 2 of 3)
1563 stage this change? [y/n/q] n
1564 -----------------------------------------------
1565 @@ -13,4 +13,4 @@
1569 -16
1571 -----------------------------------------------
1572 M numbers (change 3 of 3)
1573 stage this change? [y/n/q] y
1574 EOF
1575 cmp -s $testroot/stdout.expected $testroot/stdout
1576 ret="$?"
1577 if [ "$ret" != "0" ]; then
1578 diff -u $testroot/stdout.expected $testroot/stdout
1579 test_done "$testroot" "$ret"
1580 return 1
1583 (cd $testroot/wt && got status > $testroot/stdout)
1584 echo "MM numbers" > $testroot/stdout.expected
1585 cmp -s $testroot/stdout.expected $testroot/stdout
1586 ret="$?"
1587 if [ "$ret" != "0" ]; then
1588 diff -u $testroot/stdout.expected $testroot/stdout
1589 test_done "$testroot" "$ret"
1590 return 1
1593 (cd $testroot/wt && got diff -s > $testroot/stdout)
1595 echo "diff $commit_id $testroot/wt (staged changes)" \
1596 > $testroot/stdout.expected
1597 echo -n 'blob - ' >> $testroot/stdout.expected
1598 got tree -r $testroot/repo -i -c $commit_id \
1599 | grep 'numbers$' | cut -d' ' -f 1 \
1600 >> $testroot/stdout.expected
1601 echo -n 'blob + ' >> $testroot/stdout.expected
1602 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1603 >> $testroot/stdout.expected
1604 echo "--- numbers" >> $testroot/stdout.expected
1605 echo "+++ numbers" >> $testroot/stdout.expected
1606 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1607 echo " 13" >> $testroot/stdout.expected
1608 echo " 14" >> $testroot/stdout.expected
1609 echo " 15" >> $testroot/stdout.expected
1610 echo "-16" >> $testroot/stdout.expected
1611 echo "+c" >> $testroot/stdout.expected
1612 cmp -s $testroot/stdout.expected $testroot/stdout
1613 ret="$?"
1614 if [ "$ret" != "0" ]; then
1615 diff -u $testroot/stdout.expected $testroot/stdout
1617 test_done "$testroot" "$ret"
1620 function test_stage_patch_added {
1621 local testroot=`test_init stage_patch_added`
1622 local commit_id=`git_show_head $testroot/repo`
1624 got checkout $testroot/repo $testroot/wt > /dev/null
1625 ret="$?"
1626 if [ "$ret" != "0" ]; then
1627 test_done "$testroot" "$ret"
1628 return 1
1631 echo "new" > $testroot/wt/epsilon/new
1632 (cd $testroot/wt && got add epsilon/new > /dev/null)
1634 printf "y\n" > $testroot/patchscript
1635 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1636 epsilon/new > $testroot/stdout)
1638 echo "A epsilon/new" > $testroot/stdout.expected
1639 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1640 cmp -s $testroot/stdout.expected $testroot/stdout
1641 ret="$?"
1642 if [ "$ret" != "0" ]; then
1643 diff -u $testroot/stdout.expected $testroot/stdout
1644 test_done "$testroot" "$ret"
1645 return 1
1648 (cd $testroot/wt && got status > $testroot/stdout)
1649 echo " A epsilon/new" > $testroot/stdout.expected
1650 cmp -s $testroot/stdout.expected $testroot/stdout
1651 ret="$?"
1652 if [ "$ret" != "0" ]; then
1653 diff -u $testroot/stdout.expected $testroot/stdout
1654 test_done "$testroot" "$ret"
1655 return 1
1658 (cd $testroot/wt && got diff -s > $testroot/stdout)
1660 echo "diff $commit_id $testroot/wt (staged changes)" \
1661 > $testroot/stdout.expected
1662 echo 'blob - /dev/null' >> $testroot/stdout.expected
1663 echo -n 'blob + ' >> $testroot/stdout.expected
1664 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1665 >> $testroot/stdout.expected
1666 echo "--- /dev/null" >> $testroot/stdout.expected
1667 echo "+++ epsilon/new" >> $testroot/stdout.expected
1668 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1669 echo "+new" >> $testroot/stdout.expected
1670 cmp -s $testroot/stdout.expected $testroot/stdout
1671 ret="$?"
1672 if [ "$ret" != "0" ]; then
1673 diff -u $testroot/stdout.expected $testroot/stdout
1675 test_done "$testroot" "$ret"
1678 function test_stage_patch_removed {
1679 local testroot=`test_init stage_patch_removed`
1680 local commit_id=`git_show_head $testroot/repo`
1682 got checkout $testroot/repo $testroot/wt > /dev/null
1683 ret="$?"
1684 if [ "$ret" != "0" ]; then
1685 test_done "$testroot" "$ret"
1686 return 1
1689 (cd $testroot/wt && got rm beta > /dev/null)
1691 printf "y\n" > $testroot/patchscript
1692 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1693 beta > $testroot/stdout)
1695 echo -n > $testroot/stdout.expected
1697 echo "D beta" > $testroot/stdout.expected
1698 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
1699 cmp -s $testroot/stdout.expected $testroot/stdout
1700 ret="$?"
1701 if [ "$ret" != "0" ]; then
1702 diff -u $testroot/stdout.expected $testroot/stdout
1703 test_done "$testroot" "$ret"
1704 return 1
1707 (cd $testroot/wt && got status > $testroot/stdout)
1708 echo " D beta" > $testroot/stdout.expected
1709 cmp -s $testroot/stdout.expected $testroot/stdout
1710 ret="$?"
1711 if [ "$ret" != "0" ]; then
1712 diff -u $testroot/stdout.expected $testroot/stdout
1713 test_done "$testroot" "$ret"
1714 return 1
1717 (cd $testroot/wt && got diff -s > $testroot/stdout)
1719 echo "diff $commit_id $testroot/wt (staged changes)" \
1720 > $testroot/stdout.expected
1721 echo -n 'blob - ' >> $testroot/stdout.expected
1722 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
1723 >> $testroot/stdout.expected
1724 echo 'blob + /dev/null' >> $testroot/stdout.expected
1725 echo "--- beta" >> $testroot/stdout.expected
1726 echo "+++ /dev/null" >> $testroot/stdout.expected
1727 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
1728 echo "-beta" >> $testroot/stdout.expected
1729 cmp -s $testroot/stdout.expected $testroot/stdout
1730 ret="$?"
1731 if [ "$ret" != "0" ]; then
1732 diff -u $testroot/stdout.expected $testroot/stdout
1734 test_done "$testroot" "$ret"
1737 function test_stage_patch_quit {
1738 local testroot=`test_init stage_patch_quit`
1740 jot 16 > $testroot/repo/numbers
1741 echo zzz > $testroot/repo/zzz
1742 (cd $testroot/repo && git add numbers zzz)
1743 git_commit $testroot/repo -m "added files"
1744 local commit_id=`git_show_head $testroot/repo`
1746 got checkout $testroot/repo $testroot/wt > /dev/null
1747 ret="$?"
1748 if [ "$ret" != "0" ]; then
1749 test_done "$testroot" "$ret"
1750 return 1
1753 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1754 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1755 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1756 (cd $testroot/wt && got rm zzz > /dev/null)
1758 # stage first hunk and quit; and don't pass a path argument to
1759 # ensure that we don't skip asking about the 'zzz' file after 'quit'
1760 printf "y\nq\nn\n" > $testroot/patchscript
1761 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1762 > $testroot/stdout)
1763 ret="$?"
1764 if [ "$ret" != "0" ]; then
1765 echo "got stage command failed unexpectedly" >&2
1766 test_done "$testroot" "1"
1767 return 1
1769 cat > $testroot/stdout.expected <<EOF
1770 -----------------------------------------------
1771 @@ -1,5 +1,5 @@
1778 -----------------------------------------------
1779 M numbers (change 1 of 3)
1780 stage this change? [y/n/q] y
1781 -----------------------------------------------
1782 @@ -4,7 +4,7 @@
1791 -----------------------------------------------
1792 M numbers (change 2 of 3)
1793 stage this change? [y/n/q] q
1794 D zzz
1795 stage this deletion? [y/n] n
1796 EOF
1797 cmp -s $testroot/stdout.expected $testroot/stdout
1798 ret="$?"
1799 if [ "$ret" != "0" ]; then
1800 diff -u $testroot/stdout.expected $testroot/stdout
1801 test_done "$testroot" "$ret"
1802 return 1
1805 (cd $testroot/wt && got status > $testroot/stdout)
1806 echo "MM numbers" > $testroot/stdout.expected
1807 echo "D zzz" >> $testroot/stdout.expected
1808 cmp -s $testroot/stdout.expected $testroot/stdout
1809 ret="$?"
1810 if [ "$ret" != "0" ]; then
1811 diff -u $testroot/stdout.expected $testroot/stdout
1812 test_done "$testroot" "$ret"
1813 return 1
1816 (cd $testroot/wt && got diff -s > $testroot/stdout)
1818 echo "diff $commit_id $testroot/wt (staged changes)" \
1819 > $testroot/stdout.expected
1820 echo -n 'blob - ' >> $testroot/stdout.expected
1821 got tree -r $testroot/repo -i -c $commit_id \
1822 | grep 'numbers$' | cut -d' ' -f 1 \
1823 >> $testroot/stdout.expected
1824 echo -n 'blob + ' >> $testroot/stdout.expected
1825 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1826 >> $testroot/stdout.expected
1827 echo "--- numbers" >> $testroot/stdout.expected
1828 echo "+++ numbers" >> $testroot/stdout.expected
1829 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
1830 echo " 1" >> $testroot/stdout.expected
1831 echo "-2" >> $testroot/stdout.expected
1832 echo "+a" >> $testroot/stdout.expected
1833 echo " 3" >> $testroot/stdout.expected
1834 echo " 4" >> $testroot/stdout.expected
1835 echo " 5" >> $testroot/stdout.expected
1836 cmp -s $testroot/stdout.expected $testroot/stdout
1837 ret="$?"
1838 if [ "$ret" != "0" ]; then
1839 diff -u $testroot/stdout.expected $testroot/stdout
1841 test_done "$testroot" "$ret"
1845 function test_stage_patch_incomplete_script {
1846 local testroot=`test_init stage_incomplete_script`
1848 jot 16 > $testroot/repo/numbers
1849 echo zzz > $testroot/repo/zzz
1850 (cd $testroot/repo && git add numbers zzz)
1851 git_commit $testroot/repo -m "added files"
1852 local commit_id=`git_show_head $testroot/repo`
1854 got checkout $testroot/repo $testroot/wt > /dev/null
1855 ret="$?"
1856 if [ "$ret" != "0" ]; then
1857 test_done "$testroot" "$ret"
1858 return 1
1861 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1862 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1863 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1865 # stage first hunk and then stop responding; got should error out
1866 printf "y\n" > $testroot/patchscript
1867 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1868 > $testroot/stdout 2> $testroot/stderr)
1869 ret="$?"
1870 if [ "$ret" == "0" ]; then
1871 echo "got stage command succeeded unexpectedly" >&2
1872 test_done "$testroot" "1"
1873 return 1
1875 cat > $testroot/stdout.expected <<EOF
1876 -----------------------------------------------
1877 @@ -1,5 +1,5 @@
1884 -----------------------------------------------
1885 M numbers (change 1 of 3)
1886 stage this change? [y/n/q] y
1887 -----------------------------------------------
1888 @@ -4,7 +4,7 @@
1897 -----------------------------------------------
1898 M numbers (change 2 of 3)
1899 EOF
1900 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
1901 echo "got: invalid patch choice" > $testroot/stderr.expected
1902 cmp -s $testroot/stderr.expected $testroot/stderr
1903 ret="$?"
1904 if [ "$ret" != "0" ]; then
1905 diff -u $testroot/stderr.expected $testroot/stderr
1906 test_done "$testroot" "$ret"
1907 return 1
1910 cmp -s $testroot/stdout.expected $testroot/stdout
1911 ret="$?"
1912 if [ "$ret" != "0" ]; then
1913 diff -u $testroot/stdout.expected $testroot/stdout
1914 test_done "$testroot" "$ret"
1915 return 1
1918 (cd $testroot/wt && got status > $testroot/stdout)
1919 echo "M numbers" > $testroot/stdout.expected
1920 cmp -s $testroot/stdout.expected $testroot/stdout
1921 ret="$?"
1922 if [ "$ret" != "0" ]; then
1923 diff -u $testroot/stdout.expected $testroot/stdout
1924 test_done "$testroot" "$ret"
1925 return 1
1928 (cd $testroot/wt && got diff -s > $testroot/stdout)
1929 echo -n > $testroot/stdout.expected
1930 cmp -s $testroot/stdout.expected $testroot/stdout
1931 ret="$?"
1932 if [ "$ret" != "0" ]; then
1933 diff -u $testroot/stdout.expected $testroot/stdout
1935 test_done "$testroot" "$ret"
1939 run_test test_stage_basic
1940 run_test test_stage_no_changes
1941 run_test test_stage_unversioned
1942 run_test test_stage_nonexistent
1943 run_test test_stage_list
1944 run_test test_stage_conflict
1945 run_test test_stage_out_of_date
1946 run_test test_double_stage
1947 run_test test_stage_status
1948 run_test test_stage_add_already_staged_file
1949 run_test test_stage_rm_already_staged_file
1950 run_test test_stage_revert
1951 run_test test_stage_diff
1952 run_test test_stage_histedit
1953 run_test test_stage_rebase
1954 run_test test_stage_update
1955 run_test test_stage_commit_non_staged
1956 run_test test_stage_commit_out_of_date
1957 run_test test_stage_commit
1958 run_test test_stage_patch
1959 run_test test_stage_patch_added
1960 run_test test_stage_patch_removed
1961 run_test test_stage_patch_quit
1962 run_test test_stage_patch_incomplete_script