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: nonexistent-file: No such file or directory" \
160 > $testroot/stderr.expected
161 cmp -s $testroot/stderr.expected $testroot/stderr
162 ret="$?"
163 if [ "$ret" != "0" ]; then
164 diff -u $testroot/stderr.expected $testroot/stderr
165 fi
166 test_done "$testroot" "$ret"
169 function test_stage_list {
170 local testroot=`test_init stage_list`
172 got checkout $testroot/repo $testroot/wt > /dev/null
173 ret="$?"
174 if [ "$ret" != "0" ]; then
175 test_done "$testroot" "$ret"
176 return 1
177 fi
179 echo "modified file" > $testroot/wt/alpha
180 (cd $testroot/wt && got rm beta > /dev/null)
181 echo "new file" > $testroot/wt/foo
182 (cd $testroot/wt && got add foo > /dev/null)
184 echo ' M alpha' > $testroot/stdout.expected
185 echo ' D beta' >> $testroot/stdout.expected
186 echo ' A foo' >> $testroot/stdout.expected
187 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
189 (cd $testroot/wt && got stage -l > $testroot/stdout)
190 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
191 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
192 echo " M alpha" >> $testroot/stdout.expected
193 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
194 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
195 echo " D beta" >> $testroot/stdout.expected
196 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
197 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
198 echo " A foo" >> $testroot/stdout.expected
199 cmp -s $testroot/stdout.expected $testroot/stdout
200 ret="$?"
201 if [ "$ret" != "0" ]; then
202 diff -u $testroot/stdout.expected $testroot/stdout
203 test_done "$testroot" "$ret"
204 return 1
205 fi
207 (cd $testroot/wt && got stage -l epsilon nonexistent \
208 > $testroot/stdout)
210 echo -n > $testroot/stdout.expected
211 cmp -s $testroot/stdout.expected $testroot/stdout
212 ret="$?"
213 if [ "$ret" != "0" ]; then
214 diff -u $testroot/stdout.expected $testroot/stdout
215 test_done "$testroot" "$ret"
216 return 1
217 fi
219 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
221 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
222 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
223 echo " M alpha" >> $testroot/stdout.expected
224 cmp -s $testroot/stdout.expected $testroot/stdout
225 ret="$?"
226 if [ "$ret" != "0" ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
228 fi
229 test_done "$testroot" "$ret"
233 function test_stage_conflict {
234 local testroot=`test_init stage_conflict`
235 local initial_commit=`git_show_head $testroot/repo`
237 got checkout $testroot/repo $testroot/wt > /dev/null
238 ret="$?"
239 if [ "$ret" != "0" ]; then
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 echo "modified alpha" > $testroot/wt/alpha
245 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
247 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
249 echo "modified alpha, too" > $testroot/wt/alpha
251 echo "C alpha" > $testroot/stdout.expected
252 echo -n "Updated to commit " >> $testroot/stdout.expected
253 git_show_head $testroot/repo >> $testroot/stdout.expected
254 echo >> $testroot/stdout.expected
256 (cd $testroot/wt && got update > $testroot/stdout)
258 cmp -s $testroot/stdout.expected $testroot/stdout
259 ret="$?"
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 test_done "$testroot" "$ret"
263 return 1
264 fi
266 (cd $testroot/wt && got stage alpha > $testroot/stdout \
267 2> $testroot/stderr)
268 ret="$?"
269 if [ "$ret" == "0" ]; then
270 echo "got stage command succeeded unexpectedly" >&2
271 test_done "$testroot" "1"
272 return 1
273 fi
275 echo -n > $testroot/stdout.expected
276 echo "got: alpha: cannot stage file in conflicted status" \
277 > $testroot/stderr.expected
279 cmp -s $testroot/stdout.expected $testroot/stdout
280 ret="$?"
281 if [ "$ret" != "0" ]; then
282 diff -u $testroot/stdout.expected $testroot/stdout
283 test_done "$testroot" "$ret"
284 return 1
285 fi
286 cmp -s $testroot/stderr.expected $testroot/stderr
287 ret="$?"
288 if [ "$ret" != "0" ]; then
289 diff -u $testroot/stderr.expected $testroot/stderr
290 fi
291 test_done "$testroot" "$ret"
294 function test_stage_out_of_date {
295 local testroot=`test_init stage_out_of_date`
296 local initial_commit=`git_show_head $testroot/repo`
298 got checkout $testroot/repo $testroot/wt > /dev/null
299 ret="$?"
300 if [ "$ret" != "0" ]; then
301 test_done "$testroot" "$ret"
302 return 1
303 fi
305 echo "modified alpha" > $testroot/wt/alpha
306 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
308 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
310 echo "modified alpha again" > $testroot/wt/alpha
311 (cd $testroot/wt && got stage alpha > $testroot/stdout \
312 2> $testroot/stderr)
313 ret="$?"
314 if [ "$ret" == "0" ]; then
315 echo "got stage command succeeded unexpectedly" >&2
316 test_done "$testroot" "1"
317 return 1
318 fi
320 echo -n > $testroot/stdout.expected
321 echo "got: work tree must be updated before changes can be staged" \
322 > $testroot/stderr.expected
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
331 cmp -s $testroot/stderr.expected $testroot/stderr
332 ret="$?"
333 if [ "$ret" != "0" ]; then
334 diff -u $testroot/stderr.expected $testroot/stderr
335 fi
336 test_done "$testroot" "$ret"
340 function test_double_stage {
341 local testroot=`test_init double_stage`
343 got checkout $testroot/repo $testroot/wt > /dev/null
344 ret="$?"
345 if [ "$ret" != "0" ]; then
346 test_done "$testroot" "$ret"
347 return 1
348 fi
349 echo "modified file" > $testroot/wt/alpha
350 (cd $testroot/wt && got rm beta > /dev/null)
351 echo "new file" > $testroot/wt/foo
352 (cd $testroot/wt && got add foo > /dev/null)
353 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
355 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
356 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
357 cmp -s $testroot/stderr.expected $testroot/stderr
358 ret="$?"
359 if [ "$ret" != "0" ]; then
360 diff -u $testroot/stderr.expected $testroot/stderr
361 test_done "$testroot" "$ret"
362 return 1
363 fi
365 (cd $testroot/wt && got stage beta > $testroot/stdout)
366 ret="$?"
367 if [ "$ret" != "0" ]; then
368 echo "got stage command failed unexpectedly" >&2
369 test_done "$testroot" "1"
370 return 1
371 fi
372 echo -n > $testroot/stdout.expected
373 cmp -s $testroot/stdout.expected $testroot/stdout
374 ret="$?"
375 if [ "$ret" != "0" ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 test_done "$testroot" "$ret"
378 return 1
379 fi
381 echo "got: foo: no changes to stage" > $testroot/stderr.expected
382 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
383 cmp -s $testroot/stderr.expected $testroot/stderr
384 ret="$?"
385 if [ "$ret" != "0" ]; then
386 diff -u $testroot/stderr.expected $testroot/stderr
387 test_done "$testroot" "$ret"
388 return 1
389 fi
391 echo "modified file again" > $testroot/wt/alpha
392 echo "modified new file" > $testroot/wt/foo
394 echo ' M alpha' > $testroot/stdout.expected
395 echo ' A foo' >> $testroot/stdout.expected
396 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
397 cmp -s $testroot/stdout.expected $testroot/stdout
398 ret="$?"
399 if [ "$ret" != "0" ]; then
400 diff -u $testroot/stdout.expected $testroot/stdout
401 test_done "$testroot" "$ret"
402 return 1
403 fi
405 echo ' M alpha' > $testroot/stdout.expected
406 echo ' D beta' >> $testroot/stdout.expected
407 echo ' A foo' >> $testroot/stdout.expected
409 (cd $testroot/wt && got status > $testroot/stdout)
410 cmp -s $testroot/stdout.expected $testroot/stdout
411 ret="$?"
412 if [ "$ret" != "0" ]; then
413 diff -u $testroot/stdout.expected $testroot/stdout
414 fi
415 test_done "$testroot" "$ret"
418 function test_stage_status {
419 local testroot=`test_init stage_status`
421 got checkout $testroot/repo $testroot/wt > /dev/null
422 ret="$?"
423 if [ "$ret" != "0" ]; then
424 test_done "$testroot" "$ret"
425 return 1
426 fi
428 echo "modified file" > $testroot/wt/alpha
429 (cd $testroot/wt && got rm beta > /dev/null)
430 echo "new file" > $testroot/wt/foo
431 (cd $testroot/wt && got add foo > /dev/null)
432 echo "new file" > $testroot/wt/epsilon/new
433 (cd $testroot/wt && got add epsilon/new > /dev/null)
434 echo "modified file" > $testroot/wt/epsilon/zeta
435 (cd $testroot/wt && got rm gamma/delta > /dev/null)
437 echo ' M alpha' > $testroot/stdout.expected
438 echo ' D beta' >> $testroot/stdout.expected
439 echo 'A epsilon/new' >> $testroot/stdout.expected
440 echo 'M epsilon/zeta' >> $testroot/stdout.expected
441 echo ' A foo' >> $testroot/stdout.expected
442 echo 'D gamma/delta' >> $testroot/stdout.expected
443 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
445 (cd $testroot/wt && got status > $testroot/stdout)
446 cmp -s $testroot/stdout.expected $testroot/stdout
447 ret="$?"
448 if [ "$ret" != "0" ]; then
449 diff -u $testroot/stdout.expected $testroot/stdout
450 test_done "$testroot" "$ret"
451 return 1
452 fi
454 echo "modified file again" >> $testroot/wt/alpha
455 echo "modified added file again" >> $testroot/wt/foo
457 echo 'MM alpha' > $testroot/stdout.expected
458 echo ' D beta' >> $testroot/stdout.expected
459 echo 'A epsilon/new' >> $testroot/stdout.expected
460 echo 'M epsilon/zeta' >> $testroot/stdout.expected
461 echo 'MA foo' >> $testroot/stdout.expected
462 echo 'D gamma/delta' >> $testroot/stdout.expected
464 (cd $testroot/wt && got status > $testroot/stdout)
465 cmp -s $testroot/stdout.expected $testroot/stdout
466 ret="$?"
467 if [ "$ret" != "0" ]; then
468 diff -u $testroot/stdout.expected $testroot/stdout
469 test_done "$testroot" "$ret"
470 return 1
471 fi
473 # test no-op change of added file with new stat(2) timestamp
474 echo "new file" > $testroot/wt/foo
475 echo ' A foo' > $testroot/stdout.expected
476 (cd $testroot/wt && got status foo > $testroot/stdout)
477 cmp -s $testroot/stdout.expected $testroot/stdout
478 ret="$?"
479 if [ "$ret" != "0" ]; then
480 diff -u $testroot/stdout.expected $testroot/stdout
481 test_done "$testroot" "$ret"
482 return 1
483 fi
485 # test staged deleted file which is restored on disk
486 echo "new file" > $testroot/wt/beta
487 echo ' D beta' > $testroot/stdout.expected
488 (cd $testroot/wt && got status beta > $testroot/stdout)
489 cmp -s $testroot/stdout.expected $testroot/stdout
490 ret="$?"
491 if [ "$ret" != "0" ]; then
492 diff -u $testroot/stdout.expected $testroot/stdout
493 fi
494 test_done "$testroot" "$ret"
498 function test_stage_add_already_staged_file {
499 local testroot=`test_init stage_add_already_staged_file`
501 got checkout $testroot/repo $testroot/wt > /dev/null
502 ret="$?"
503 if [ "$ret" != "0" ]; then
504 test_done "$testroot" "$ret"
505 return 1
506 fi
508 echo "modified file" > $testroot/wt/alpha
509 (cd $testroot/wt && got rm beta > /dev/null)
510 echo "new file" > $testroot/wt/foo
511 (cd $testroot/wt && got add foo > /dev/null)
513 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
515 echo -n > $testroot/stdout.expected
516 for f in alpha beta foo; do
517 (cd $testroot/wt && got add $f \
518 > $testroot/stdout 2> $testroot/stderr)
519 echo "got: $f: file has unexpected status" \
520 > $testroot/stderr.expected
521 cmp -s $testroot/stderr.expected $testroot/stderr
522 ret="$?"
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/stderr.expected $testroot/stderr
525 test_done "$testroot" "$ret"
526 return 1
527 fi
528 cmp -s $testroot/stdout.expected $testroot/stdout
529 ret="$?"
530 if [ "$ret" != "0" ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done "$testroot" "$ret"
533 return 1
534 fi
535 done
537 echo ' M alpha' > $testroot/stdout.expected
538 echo ' D beta' >> $testroot/stdout.expected
539 echo ' A foo' >> $testroot/stdout.expected
541 (cd $testroot/wt && got status > $testroot/stdout)
542 cmp -s $testroot/stdout.expected $testroot/stdout
543 ret="$?"
544 if [ "$ret" != "0" ]; then
545 diff -u $testroot/stdout.expected $testroot/stdout
546 fi
547 test_done "$testroot" "$ret"
550 function test_stage_rm_already_staged_file {
551 local testroot=`test_init stage_rm_already_staged_file`
553 got checkout $testroot/repo $testroot/wt > /dev/null
554 ret="$?"
555 if [ "$ret" != "0" ]; then
556 test_done "$testroot" "$ret"
557 return 1
558 fi
560 echo "modified file" > $testroot/wt/alpha
561 (cd $testroot/wt && got rm beta > /dev/null)
562 echo "new file" > $testroot/wt/foo
563 (cd $testroot/wt && got add foo > /dev/null)
565 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
567 (cd $testroot/wt && got rm beta \
568 > $testroot/stdout 2> $testroot/stderr)
569 ret="$?"
570 if [ "$ret" != "0" ]; then
571 echo "got rm command failed unexpectedly" >&2
572 test_done "$testroot" "1"
573 return 1
574 fi
575 echo -n > $testroot/stdout.expected
576 cmp -s $testroot/stdout.expected $testroot/stdout
577 ret="$?"
578 if [ "$ret" != "0" ]; then
579 diff -u $testroot/stdout.expected $testroot/stdout
580 test_done "$testroot" "$ret"
581 return 1
582 fi
583 echo -n > $testroot/stderr.expected
584 cmp -s $testroot/stderr.expected $testroot/stderr
585 ret="$?"
586 if [ "$ret" != "0" ]; then
587 diff -u $testroot/stderr.expected $testroot/stderr
588 test_done "$testroot" "$ret"
589 return 1
590 fi
592 for f in alpha foo; do
593 echo "got: $f: file is staged" > $testroot/stderr.expected
594 (cd $testroot/wt && got rm $f \
595 > $testroot/stdout 2> $testroot/stderr)
596 ret="$?"
597 if [ "$ret" == "0" ]; then
598 echo "got rm command succeeded unexpectedly" >&2
599 test_done "$testroot" "1"
600 return 1
601 fi
602 cmp -s $testroot/stderr.expected $testroot/stderr
603 ret="$?"
604 if [ "$ret" != "0" ]; then
605 diff -u $testroot/stderr.expected $testroot/stderr
606 test_done "$testroot" "$ret"
607 return 1
608 fi
609 done
611 echo ' M alpha' > $testroot/stdout.expected
612 echo ' D beta' >> $testroot/stdout.expected
613 echo ' A foo' >> $testroot/stdout.expected
615 (cd $testroot/wt && got status > $testroot/stdout)
616 cmp -s $testroot/stdout.expected $testroot/stdout
617 ret="$?"
618 if [ "$ret" != "0" ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 fi
621 test_done "$testroot" "$ret"
624 function test_stage_revert {
625 local testroot=`test_init stage_revert`
627 got checkout $testroot/repo $testroot/wt > /dev/null
628 ret="$?"
629 if [ "$ret" != "0" ]; then
630 test_done "$testroot" "$ret"
631 return 1
632 fi
634 echo "modified alpha" > $testroot/wt/alpha
635 (cd $testroot/wt && got rm beta > /dev/null)
636 echo "new file" > $testroot/wt/foo
637 (cd $testroot/wt && got add foo > /dev/null)
638 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
640 echo "modified file again" >> $testroot/wt/alpha
641 echo "modified added file again" >> $testroot/wt/foo
643 (cd $testroot/wt && got revert alpha > $testroot/stdout)
644 ret="$?"
645 if [ "$ret" != "0" ]; then
646 echo "revert command failed unexpectedly" >&2
647 test_done "$testroot" "$ret"
648 return 1
649 fi
651 echo "R alpha" > $testroot/stdout.expected
652 cmp -s $testroot/stdout.expected $testroot/stdout
653 ret="$?"
654 if [ "$ret" != "0" ]; then
655 diff -u $testroot/stdout.expected $testroot/stdout
656 test_done "$testroot" "$ret"
657 return 1
658 fi
660 echo "modified alpha" > $testroot/content.expected
661 cat $testroot/wt/alpha > $testroot/content
662 cmp -s $testroot/content.expected $testroot/content
663 ret="$?"
664 if [ "$ret" != "0" ]; then
665 diff -u $testroot/content.expected $testroot/content
666 test_done "$testroot" "$ret"
667 return 1
668 fi
670 echo ' M alpha' > $testroot/stdout.expected
671 echo ' D beta' >> $testroot/stdout.expected
672 echo 'MA foo' >> $testroot/stdout.expected
673 (cd $testroot/wt && got status > $testroot/stdout)
674 cmp -s $testroot/stdout.expected $testroot/stdout
675 ret="$?"
676 if [ "$ret" != "0" ]; then
677 diff -u $testroot/stdout.expected $testroot/stdout
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 (cd $testroot/wt && got revert alpha > $testroot/stdout)
683 ret="$?"
684 if [ "$ret" != "0" ]; then
685 echo "revert command failed unexpectedly" >&2
686 test_done "$testroot" "$ret"
687 return 1
688 fi
690 echo -n > $testroot/stdout.expected
691 cmp -s $testroot/stdout.expected $testroot/stdout
692 ret="$?"
693 if [ "$ret" != "0" ]; then
694 diff -u $testroot/stdout.expected $testroot/stdout
695 test_done "$testroot" "$ret"
696 return 1
697 fi
699 echo "modified alpha" > $testroot/content.expected
700 cat $testroot/wt/alpha > $testroot/content
701 cmp -s $testroot/content.expected $testroot/content
702 ret="$?"
703 if [ "$ret" != "0" ]; then
704 diff -u $testroot/content.expected $testroot/content
705 test_done "$testroot" "$ret"
706 return 1
707 fi
709 (cd $testroot/wt && got revert beta > $testroot/stdout \
710 2> $testroot/stderr)
711 ret="$?"
712 if [ "$ret" != "0" ]; then
713 echo "revert command failed unexpectedly" >&2
714 test_done "$testroot" "$ret"
715 return 1
716 fi
718 echo -n > $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
720 ret="$?"
721 if [ "$ret" != "0" ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done "$testroot" "$ret"
724 return 1
725 fi
727 echo -n > $testroot/stderr.expected
728 cmp -s $testroot/stderr.expected $testroot/stderr
729 ret="$?"
730 if [ "$ret" != "0" ]; then
731 diff -u $testroot/stderr.expected $testroot/stderr
732 test_done "$testroot" "$ret"
733 return 1
734 fi
736 (cd $testroot/wt && got revert foo > $testroot/stdout)
737 ret="$?"
738 if [ "$ret" != "0" ]; then
739 echo "revert command failed unexpectedly" >&2
740 test_done "$testroot" "$ret"
741 return 1
742 fi
744 echo "R foo" > $testroot/stdout.expected
745 cmp -s $testroot/stdout.expected $testroot/stdout
746 ret="$?"
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/stdout.expected $testroot/stdout
749 test_done "$testroot" "$ret"
750 return 1
751 fi
753 echo "new file" > $testroot/content.expected
754 cat $testroot/wt/foo > $testroot/content
755 cmp -s $testroot/content.expected $testroot/content
756 ret="$?"
757 if [ "$ret" != "0" ]; then
758 diff -u $testroot/content.expected $testroot/content
759 test_done "$testroot" "$ret"
760 return 1
761 fi
763 echo ' M alpha' > $testroot/stdout.expected
764 echo ' D beta' >> $testroot/stdout.expected
765 echo ' A foo' >> $testroot/stdout.expected
766 (cd $testroot/wt && got status > $testroot/stdout)
767 cmp -s $testroot/stdout.expected $testroot/stdout
768 ret="$?"
769 if [ "$ret" != "0" ]; then
770 diff -u $testroot/stdout.expected $testroot/stdout
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 (cd $testroot/wt && got revert foo > $testroot/stdout)
776 ret="$?"
777 if [ "$ret" != "0" ]; then
778 echo "revert command failed unexpectedly" >&2
779 test_done "$testroot" "$ret"
780 return 1
781 fi
783 echo -n > $testroot/stdout.expected
784 cmp -s $testroot/stdout.expected $testroot/stdout
785 ret="$?"
786 if [ "$ret" != "0" ]; then
787 diff -u $testroot/stdout.expected $testroot/stdout
788 test_done "$testroot" "$ret"
789 return 1
790 fi
792 echo "new file" > $testroot/content.expected
793 cat $testroot/wt/foo > $testroot/content
794 cmp -s $testroot/content.expected $testroot/content
795 ret="$?"
796 if [ "$ret" != "0" ]; then
797 diff -u $testroot/content.expected $testroot/content
798 test_done "$testroot" "$ret"
799 return 1
800 fi
802 echo ' M alpha' > $testroot/stdout.expected
803 echo ' D beta' >> $testroot/stdout.expected
804 echo ' A foo' >> $testroot/stdout.expected
805 (cd $testroot/wt && got status > $testroot/stdout)
806 cmp -s $testroot/stdout.expected $testroot/stdout
807 ret="$?"
808 if [ "$ret" != "0" ]; then
809 diff -u $testroot/stdout.expected $testroot/stdout
810 test_done "$testroot" "$ret"
811 return 1
812 fi
814 echo "modified file again" >> $testroot/wt/alpha
815 echo "modified added file again" >> $testroot/wt/foo
817 (cd $testroot/wt && got revert -R . > $testroot/stdout \
818 2> $testroot/stderr)
819 ret="$?"
820 if [ "$ret" != "0" ]; then
821 echo "revert command failed unexpectedly" >&2
822 test_done "$testroot" "$ret"
823 return 1
824 fi
826 echo "R alpha" > $testroot/stdout.expected
827 echo "R foo" >> $testroot/stdout.expected
828 cmp -s $testroot/stdout.expected $testroot/stdout
829 ret="$?"
830 if [ "$ret" != "0" ]; then
831 diff -u $testroot/stdout.expected $testroot/stdout
832 test_done "$testroot" "$ret"
833 return 1
834 fi
836 echo -n > $testroot/stderr.expected
837 cmp -s $testroot/stderr.expected $testroot/stderr
838 ret="$?"
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/stderr.expected $testroot/stderr
841 test_done "$testroot" "$ret"
842 return 1
843 fi
845 echo ' M alpha' > $testroot/stdout.expected
846 echo ' D beta' >> $testroot/stdout.expected
847 echo ' A foo' >> $testroot/stdout.expected
848 (cd $testroot/wt && got status > $testroot/stdout)
849 cmp -s $testroot/stdout.expected $testroot/stdout
850 ret="$?"
851 if [ "$ret" != "0" ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
853 fi
854 test_done "$testroot" "$ret"
857 function test_stage_diff {
858 local testroot=`test_init stage_diff`
859 local head_commit=`git_show_head $testroot/repo`
861 got checkout $testroot/repo $testroot/wt > /dev/null
862 ret="$?"
863 if [ "$ret" != "0" ]; then
864 test_done "$testroot" "$ret"
865 return 1
866 fi
868 echo "modified file" > $testroot/wt/alpha
869 (cd $testroot/wt && got rm beta > /dev/null)
870 echo "new file" > $testroot/wt/foo
871 (cd $testroot/wt && got add foo > /dev/null)
873 (cd $testroot/wt && got diff -s > $testroot/stdout)
874 echo -n > $testroot/stdout.expected
875 cmp -s $testroot/stdout.expected $testroot/stdout
876 ret="$?"
877 if [ "$ret" != "0" ]; then
878 diff -u $testroot/stdout.expected $testroot/stdout
879 test_done "$testroot" "$ret"
880 return 1
881 fi
883 echo ' M alpha' > $testroot/stdout.expected
884 echo ' D beta' >> $testroot/stdout.expected
885 echo ' A foo' >> $testroot/stdout.expected
886 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
888 (cd $testroot/wt && got diff > $testroot/stdout)
889 echo -n > $testroot/stdout.expected
890 cmp -s $testroot/stdout.expected $testroot/stdout
891 ret="$?"
892 if [ "$ret" != "0" ]; then
893 diff -u $testroot/stdout.expected $testroot/stdout
894 test_done "$testroot" "$ret"
895 return 1
896 fi
898 echo "modified file again" > $testroot/wt/alpha
899 echo "new file changed" > $testroot/wt/foo
901 (cd $testroot/wt && got diff > $testroot/stdout)
903 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
904 echo -n 'blob - ' >> $testroot/stdout.expected
905 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
906 >> $testroot/stdout.expected
907 echo ' (staged)' >> $testroot/stdout.expected
908 echo 'file + alpha' >> $testroot/stdout.expected
909 echo '--- alpha' >> $testroot/stdout.expected
910 echo '+++ alpha' >> $testroot/stdout.expected
911 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
912 echo '-modified file' >> $testroot/stdout.expected
913 echo '+modified file again' >> $testroot/stdout.expected
914 echo -n 'blob - ' >> $testroot/stdout.expected
915 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
916 >> $testroot/stdout.expected
917 echo " (staged)" >> $testroot/stdout.expected
918 echo 'file + foo' >> $testroot/stdout.expected
919 echo '--- foo' >> $testroot/stdout.expected
920 echo '+++ foo' >> $testroot/stdout.expected
921 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
922 echo '-new file' >> $testroot/stdout.expected
923 echo '+new file changed' >> $testroot/stdout.expected
925 cmp -s $testroot/stdout.expected $testroot/stdout
926 ret="$?"
927 if [ "$ret" != "0" ]; then
928 diff -u $testroot/stdout.expected $testroot/stdout
929 test_done "$testroot" "$ret"
930 return 1
931 fi
933 (cd $testroot/wt && got diff -s > $testroot/stdout)
935 echo "diff $head_commit $testroot/wt (staged changes)" \
936 > $testroot/stdout.expected
937 echo -n 'blob - ' >> $testroot/stdout.expected
938 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
939 >> $testroot/stdout.expected
940 echo -n 'blob + ' >> $testroot/stdout.expected
941 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
942 >> $testroot/stdout.expected
943 echo '--- alpha' >> $testroot/stdout.expected
944 echo '+++ alpha' >> $testroot/stdout.expected
945 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
946 echo '-alpha' >> $testroot/stdout.expected
947 echo '+modified file' >> $testroot/stdout.expected
948 echo -n 'blob - ' >> $testroot/stdout.expected
949 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
950 >> $testroot/stdout.expected
951 echo 'blob + /dev/null' >> $testroot/stdout.expected
952 echo '--- beta' >> $testroot/stdout.expected
953 echo '+++ /dev/null' >> $testroot/stdout.expected
954 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
955 echo '-beta' >> $testroot/stdout.expected
956 echo 'blob - /dev/null' >> $testroot/stdout.expected
957 echo -n 'blob + ' >> $testroot/stdout.expected
958 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
959 >> $testroot/stdout.expected
960 echo '--- /dev/null' >> $testroot/stdout.expected
961 echo '+++ foo' >> $testroot/stdout.expected
962 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
963 echo '+new file' >> $testroot/stdout.expected
965 cmp -s $testroot/stdout.expected $testroot/stdout
966 ret="$?"
967 if [ "$ret" != "0" ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
969 fi
970 test_done "$testroot" "$ret"
974 function test_stage_histedit {
975 local testroot=`test_init stage_histedit`
976 local orig_commit=`git_show_head $testroot/repo`
978 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
979 ret="$?"
980 if [ "$ret" != "0" ]; then
981 test_done "$testroot" "$ret"
982 return 1
983 fi
985 echo "modified file" > $testroot/wt/alpha
986 (cd $testroot/wt && got stage alpha > /dev/null)
988 echo "modified alpha on master" > $testroot/repo/alpha
989 (cd $testroot/repo && git rm -q beta)
990 echo "new file on master" > $testroot/repo/epsilon/new
991 (cd $testroot/repo && git add epsilon/new)
992 git_commit $testroot/repo -m "committing changes"
993 local old_commit1=`git_show_head $testroot/repo`
995 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
996 git_commit $testroot/repo -m "committing to zeta on master"
997 local old_commit2=`git_show_head $testroot/repo`
999 echo "pick $old_commit1" > $testroot/histedit-script
1000 echo "pick $old_commit2" >> $testroot/histedit-script
1002 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1003 > $testroot/stdout 2> $testroot/stderr)
1004 ret="$?"
1005 if [ "$ret" == "0" ]; then
1006 echo "got histedit command succeeded unexpectedly" >&2
1007 test_done "$testroot" "1"
1008 return 1
1011 echo -n > $testroot/stdout.expected
1012 echo "got: alpha: file is staged" > $testroot/stderr.expected
1014 cmp -s $testroot/stderr.expected $testroot/stderr
1015 ret="$?"
1016 if [ "$ret" != "0" ]; then
1017 diff -u $testroot/stderr.expected $testroot/stderr
1018 test_done "$testroot" "$ret"
1019 return 1
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1022 ret="$?"
1023 if [ "$ret" != "0" ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1030 function test_stage_rebase {
1031 local testroot=`test_init stage_rebase`
1033 (cd $testroot/repo && git checkout -q -b newbranch)
1034 echo "modified delta on branch" > $testroot/repo/gamma/delta
1035 git_commit $testroot/repo -m "committing to delta on newbranch"
1037 echo "modified alpha on branch" > $testroot/repo/alpha
1038 (cd $testroot/repo && git rm -q beta)
1039 echo "new file on branch" > $testroot/repo/epsilon/new
1040 (cd $testroot/repo && git add epsilon/new)
1041 git_commit $testroot/repo -m "committing more changes on newbranch"
1043 local orig_commit1=`git_show_parent_commit $testroot/repo`
1044 local orig_commit2=`git_show_head $testroot/repo`
1046 (cd $testroot/repo && git checkout -q master)
1047 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1048 git_commit $testroot/repo -m "committing to zeta on master"
1049 local master_commit=`git_show_head $testroot/repo`
1051 got checkout $testroot/repo $testroot/wt > /dev/null
1052 ret="$?"
1053 if [ "$ret" != "0" ]; then
1054 test_done "$testroot" "$ret"
1055 return 1
1058 echo "modified file" > $testroot/wt/alpha
1059 (cd $testroot/wt && got stage alpha > /dev/null)
1061 (cd $testroot/wt && got rebase newbranch \
1062 > $testroot/stdout 2> $testroot/stderr)
1063 ret="$?"
1064 if [ "$ret" == "0" ]; then
1065 echo "got rebase command succeeded unexpectedly" >&2
1066 test_done "$testroot" "1"
1067 return 1
1070 echo -n > $testroot/stdout.expected
1071 echo "got: alpha: file is staged" > $testroot/stderr.expected
1073 cmp -s $testroot/stderr.expected $testroot/stderr
1074 ret="$?"
1075 if [ "$ret" != "0" ]; then
1076 diff -u $testroot/stderr.expected $testroot/stderr
1077 test_done "$testroot" "$ret"
1078 return 1
1080 cmp -s $testroot/stdout.expected $testroot/stdout
1081 ret="$?"
1082 if [ "$ret" != "0" ]; then
1083 diff -u $testroot/stdout.expected $testroot/stdout
1085 test_done "$testroot" "$ret"
1088 function test_stage_update {
1089 local testroot=`test_init stage_update`
1091 got checkout $testroot/repo $testroot/wt > /dev/null
1092 ret="$?"
1093 if [ "$ret" != "0" ]; then
1094 test_done "$testroot" "$ret"
1095 return 1
1098 echo "modified file" > $testroot/wt/alpha
1099 (cd $testroot/wt && got stage alpha > /dev/null)
1101 echo "modified alpha" > $testroot/repo/alpha
1102 git_commit $testroot/repo -m "modified alpha"
1104 (cd $testroot/wt && got update > $testroot/stdout \
1105 2> $testroot/stderr)
1106 ret="$?"
1107 if [ "$ret" == "0" ]; then
1108 echo "got update command succeeded unexpectedly" >&2
1109 test_done "$testroot" "1"
1110 return 1
1113 echo -n > $testroot/stdout.expected
1114 echo "got: alpha: file is staged" > $testroot/stderr.expected
1116 cmp -s $testroot/stderr.expected $testroot/stderr
1117 ret="$?"
1118 if [ "$ret" != "0" ]; then
1119 diff -u $testroot/stderr.expected $testroot/stderr
1120 test_done "$testroot" "$ret"
1121 return 1
1123 cmp -s $testroot/stdout.expected $testroot/stdout
1124 ret="$?"
1125 if [ "$ret" != "0" ]; then
1126 diff -u $testroot/stdout.expected $testroot/stdout
1128 test_done "$testroot" "$ret"
1131 function test_stage_commit_non_staged {
1132 local testroot=`test_init stage_commit_non_staged`
1134 got checkout $testroot/repo $testroot/wt > /dev/null
1135 ret="$?"
1136 if [ "$ret" != "0" ]; then
1137 test_done "$testroot" "$ret"
1138 return 1
1141 echo "modified file" > $testroot/wt/alpha
1142 (cd $testroot/wt && got rm beta > /dev/null)
1143 echo "new file" > $testroot/wt/foo
1144 (cd $testroot/wt && got add foo > /dev/null)
1145 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1147 echo "modified file" > $testroot/wt/gamma/delta
1148 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1149 > $testroot/stdout 2> $testroot/stderr)
1150 ret="$?"
1151 if [ "$ret" == "0" ]; then
1152 echo "got commit command succeeded unexpectedly" >&2
1153 test_done "$testroot" "1"
1154 return 1
1157 echo -n > $testroot/stdout.expected
1158 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1160 cmp -s $testroot/stderr.expected $testroot/stderr
1161 ret="$?"
1162 if [ "$ret" != "0" ]; then
1163 diff -u $testroot/stderr.expected $testroot/stderr
1164 test_done "$testroot" "$ret"
1165 return 1
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1168 ret="$?"
1169 if [ "$ret" != "0" ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1172 test_done "$testroot" "$ret"
1175 function test_stage_commit_out_of_date {
1176 local testroot=`test_init stage_commit_out_of_date`
1178 got checkout $testroot/repo $testroot/wt > /dev/null
1179 ret="$?"
1180 if [ "$ret" != "0" ]; then
1181 test_done "$testroot" "$ret"
1182 return 1
1185 echo "modified file" > $testroot/wt/alpha
1186 (cd $testroot/wt && got rm beta > /dev/null)
1187 echo "new file" > $testroot/wt/foo
1188 (cd $testroot/wt && got add foo > /dev/null)
1189 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1191 echo "changed file" > $testroot/repo/alpha
1192 git_commit $testroot/repo -m "changed alpha in repo"
1194 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1195 2> $testroot/stderr)
1196 ret="$?"
1197 if [ "$ret" == "0" ]; then
1198 echo "got commit command succeeded unexpectedly" >&2
1199 test_done "$testroot" "1"
1200 return 1
1203 echo -n > $testroot/stdout.expected
1204 echo -n "got: work tree must be updated before these changes " \
1205 > $testroot/stderr.expected
1206 echo "can be committed" >> $testroot/stderr.expected
1208 cmp -s $testroot/stderr.expected $testroot/stderr
1209 ret="$?"
1210 if [ "$ret" != "0" ]; then
1211 diff -u $testroot/stderr.expected $testroot/stderr
1212 test_done "$testroot" "$ret"
1213 return 1
1215 cmp -s $testroot/stdout.expected $testroot/stdout
1216 ret="$?"
1217 if [ "$ret" != "0" ]; then
1218 diff -u $testroot/stdout.expected $testroot/stdout
1219 test_done "$testroot" "$ret"
1220 return 1
1223 (cd $testroot/wt && got update > $testroot/stdout \
1224 2> $testroot/stderr)
1225 echo -n > $testroot/stdout.expected
1226 echo "got: alpha: file is staged" > $testroot/stderr.expected
1228 cmp -s $testroot/stderr.expected $testroot/stderr
1229 ret="$?"
1230 if [ "$ret" != "0" ]; then
1231 diff -u $testroot/stderr.expected $testroot/stderr
1232 test_done "$testroot" "$ret"
1233 return 1
1235 cmp -s $testroot/stdout.expected $testroot/stdout
1236 ret="$?"
1237 if [ "$ret" != "0" ]; then
1238 diff -u $testroot/stdout.expected $testroot/stdout
1239 test_done "$testroot" "$ret"
1240 return 1
1243 (cd $testroot/wt && got unstage > /dev/null)
1244 (cd $testroot/wt && got update > $testroot/stdout)
1245 ret="$?"
1246 if [ "$ret" != "0" ]; then
1247 echo "got update command failed unexpectedly" >&2
1248 test_done "$testroot" "$ret"
1249 return 1
1252 (cd $testroot/wt && got status > $testroot/stdout)
1253 echo "C alpha" > $testroot/stdout.expected
1254 echo "D beta" >> $testroot/stdout.expected
1255 echo "A foo" >> $testroot/stdout.expected
1256 cmp -s $testroot/stdout.expected $testroot/stdout
1257 ret="$?"
1258 if [ "$ret" != "0" ]; then
1259 diff -u $testroot/stdout.expected $testroot/stdout
1260 test_done "$testroot" "$ret"
1261 return 1
1264 # resolve conflict
1265 echo "resolved file" > $testroot/wt/alpha
1267 (cd $testroot/wt && got stage > /dev/null)
1269 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1270 ret="$?"
1271 if [ "$ret" != "0" ]; then
1272 echo "got commit command failed unexpectedly" >&2
1273 test_done "$testroot" "$ret"
1274 return 1
1277 local commit_id=`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 $commit_id" >> $testroot/stdout.expected
1282 cmp -s $testroot/stdout.expected $testroot/stdout
1283 ret="$?"
1284 if [ "$ret" != "0" ]; then
1285 diff -u $testroot/stdout.expected $testroot/stdout
1287 test_done "$testroot" "$ret"
1291 function test_stage_commit {
1292 local testroot=`test_init stage_commit`
1293 local first_commit=`git_show_head $testroot/repo`
1295 got checkout $testroot/repo $testroot/wt > /dev/null
1296 ret="$?"
1297 if [ "$ret" != "0" ]; then
1298 test_done "$testroot" "$ret"
1299 return 1
1302 echo "modified file" > $testroot/wt/alpha
1303 (cd $testroot/wt && got rm beta > /dev/null)
1304 echo "new file" > $testroot/wt/foo
1305 (cd $testroot/wt && got add foo > /dev/null)
1306 echo "modified file" > $testroot/wt/alpha
1307 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1309 echo "modified file again" > $testroot/wt/alpha
1310 echo "new file changed" > $testroot/wt/foo
1311 echo "non-staged change" > $testroot/wt/gamma/delta
1312 echo "non-staged new file" > $testroot/wt/epsilon/new
1313 (cd $testroot/wt && got add epsilon/new > /dev/null)
1314 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1316 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1317 > $testroot/blob_id_alpha
1318 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1319 > $testroot/blob_id_foo
1321 (cd $testroot/wt && got commit -m "staged changes" \
1322 > $testroot/stdout)
1323 ret="$?"
1324 if [ "$ret" != "0" ]; then
1325 echo "got commit command failed unexpectedly" >&2
1326 test_done "$testroot" "1"
1327 return 1
1330 local head_commit=`git_show_head $testroot/repo`
1331 echo "A foo" > $testroot/stdout.expected
1332 echo "M alpha" >> $testroot/stdout.expected
1333 echo "D beta" >> $testroot/stdout.expected
1334 echo "Created commit $head_commit" >> $testroot/stdout.expected
1336 cmp -s $testroot/stdout.expected $testroot/stdout
1337 ret="$?"
1338 if [ "$ret" != "0" ]; then
1339 diff -u $testroot/stdout.expected $testroot/stdout
1340 test_done "$testroot" "$ret"
1341 return 1
1344 got diff -r $testroot/repo $first_commit $head_commit \
1345 > $testroot/stdout
1347 echo "diff $first_commit $head_commit" \
1348 > $testroot/stdout.expected
1349 echo -n 'blob - ' >> $testroot/stdout.expected
1350 got tree -r $testroot/repo -i -c $first_commit | \
1351 grep 'alpha$' | cut -d' ' -f 1 \
1352 >> $testroot/stdout.expected
1353 echo -n 'blob + ' >> $testroot/stdout.expected
1354 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1355 echo '--- alpha' >> $testroot/stdout.expected
1356 echo '+++ alpha' >> $testroot/stdout.expected
1357 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1358 echo '-alpha' >> $testroot/stdout.expected
1359 echo '+modified file' >> $testroot/stdout.expected
1360 echo -n 'blob - ' >> $testroot/stdout.expected
1361 got tree -r $testroot/repo -i -c $first_commit \
1362 | grep 'beta$' | cut -d' ' -f 1 \
1363 >> $testroot/stdout.expected
1364 echo 'blob + /dev/null' >> $testroot/stdout.expected
1365 echo '--- beta' >> $testroot/stdout.expected
1366 echo '+++ /dev/null' >> $testroot/stdout.expected
1367 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1368 echo '-beta' >> $testroot/stdout.expected
1369 echo 'blob - /dev/null' >> $testroot/stdout.expected
1370 echo -n 'blob + ' >> $testroot/stdout.expected
1371 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1372 echo '--- /dev/null' >> $testroot/stdout.expected
1373 echo '+++ foo' >> $testroot/stdout.expected
1374 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1375 echo '+new file' >> $testroot/stdout.expected
1377 cmp -s $testroot/stdout.expected $testroot/stdout
1378 ret="$?"
1379 if [ "$ret" != "0" ]; then
1380 diff -u $testroot/stdout.expected $testroot/stdout
1381 test_done "$testroot" "$ret"
1382 return 1
1385 echo 'A epsilon/new' > $testroot/stdout.expected
1386 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1387 echo 'M gamma/delta' >> $testroot/stdout.expected
1389 (cd $testroot/wt && got status > $testroot/stdout)
1390 cmp -s $testroot/stdout.expected $testroot/stdout
1391 ret="$?"
1392 if [ "$ret" != "0" ]; then
1393 diff -u $testroot/stdout.expected $testroot/stdout
1395 test_done "$testroot" "$ret"
1398 function test_stage_patch {
1399 local testroot=`test_init stage_patch`
1401 jot 16 > $testroot/repo/numbers
1402 (cd $testroot/repo && git add numbers)
1403 git_commit $testroot/repo -m "added numbers file"
1404 local commit_id=`git_show_head $testroot/repo`
1406 got checkout $testroot/repo $testroot/wt > /dev/null
1407 ret="$?"
1408 if [ "$ret" != "0" ]; then
1409 test_done "$testroot" "$ret"
1410 return 1
1413 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1414 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1415 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1417 # don't stage any hunks
1418 printf "n\nn\nn\n" > $testroot/patchscript
1419 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1420 numbers > $testroot/stdout)
1421 ret="$?"
1422 if [ "$ret" != "0" ]; then
1423 echo "got stage command failed unexpectedly" >&2
1424 test_done "$testroot" "1"
1425 return 1
1427 cat > $testroot/stdout.expected <<EOF
1428 -----------------------------------------------
1429 @@ -1,5 +1,5 @@
1436 -----------------------------------------------
1437 M numbers (change 1 of 3)
1438 stage this change? [y/n/q] n
1439 -----------------------------------------------
1440 @@ -4,7 +4,7 @@
1449 -----------------------------------------------
1450 M numbers (change 2 of 3)
1451 stage this change? [y/n/q] n
1452 -----------------------------------------------
1453 @@ -13,4 +13,4 @@
1457 -16
1459 -----------------------------------------------
1460 M numbers (change 3 of 3)
1461 stage this change? [y/n/q] n
1462 EOF
1463 cmp -s $testroot/stdout.expected $testroot/stdout
1464 ret="$?"
1465 if [ "$ret" != "0" ]; then
1466 diff -u $testroot/stdout.expected $testroot/stdout
1467 test_done "$testroot" "$ret"
1468 return 1
1471 (cd $testroot/wt && got status > $testroot/stdout)
1472 echo "M numbers" > $testroot/stdout.expected
1473 cmp -s $testroot/stdout.expected $testroot/stdout
1474 ret="$?"
1475 if [ "$ret" != "0" ]; then
1476 diff -u $testroot/stdout.expected $testroot/stdout
1477 test_done "$testroot" "$ret"
1478 return 1
1481 # stage middle hunk
1482 printf "n\ny\nn\n" > $testroot/patchscript
1483 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1484 numbers > $testroot/stdout)
1486 cat > $testroot/stdout.expected <<EOF
1487 -----------------------------------------------
1488 @@ -1,5 +1,5 @@
1495 -----------------------------------------------
1496 M numbers (change 1 of 3)
1497 stage this change? [y/n/q] n
1498 -----------------------------------------------
1499 @@ -4,7 +4,7 @@
1508 -----------------------------------------------
1509 M numbers (change 2 of 3)
1510 stage this change? [y/n/q] y
1511 -----------------------------------------------
1512 @@ -13,4 +13,4 @@
1516 -16
1518 -----------------------------------------------
1519 M numbers (change 3 of 3)
1520 stage this change? [y/n/q] n
1521 EOF
1522 cmp -s $testroot/stdout.expected $testroot/stdout
1523 ret="$?"
1524 if [ "$ret" != "0" ]; then
1525 diff -u $testroot/stdout.expected $testroot/stdout
1526 test_done "$testroot" "$ret"
1527 return 1
1530 (cd $testroot/wt && got status > $testroot/stdout)
1531 echo "MM numbers" > $testroot/stdout.expected
1532 cmp -s $testroot/stdout.expected $testroot/stdout
1533 ret="$?"
1534 if [ "$ret" != "0" ]; then
1535 diff -u $testroot/stdout.expected $testroot/stdout
1536 test_done "$testroot" "$ret"
1537 return 1
1540 (cd $testroot/wt && got diff -s > $testroot/stdout)
1542 echo "diff $commit_id $testroot/wt (staged changes)" \
1543 > $testroot/stdout.expected
1544 echo -n 'blob - ' >> $testroot/stdout.expected
1545 got tree -r $testroot/repo -i -c $commit_id \
1546 | grep 'numbers$' | cut -d' ' -f 1 \
1547 >> $testroot/stdout.expected
1548 echo -n 'blob + ' >> $testroot/stdout.expected
1549 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1550 >> $testroot/stdout.expected
1551 echo "--- numbers" >> $testroot/stdout.expected
1552 echo "+++ numbers" >> $testroot/stdout.expected
1553 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1554 echo " 4" >> $testroot/stdout.expected
1555 echo " 5" >> $testroot/stdout.expected
1556 echo " 6" >> $testroot/stdout.expected
1557 echo "-7" >> $testroot/stdout.expected
1558 echo "+b" >> $testroot/stdout.expected
1559 echo " 8" >> $testroot/stdout.expected
1560 echo " 9" >> $testroot/stdout.expected
1561 echo " 10" >> $testroot/stdout.expected
1562 cmp -s $testroot/stdout.expected $testroot/stdout
1563 ret="$?"
1564 if [ "$ret" != "0" ]; then
1565 diff -u $testroot/stdout.expected $testroot/stdout
1566 test_done "$testroot" "$ret"
1567 return 1
1570 (cd $testroot/wt && got unstage >/dev/null)
1571 ret="$?"
1572 if [ "$ret" != "0" ]; then
1573 echo "got stage command failed unexpectedly" >&2
1574 test_done "$testroot" "1"
1575 return 1
1577 (cd $testroot/wt && got status > $testroot/stdout)
1578 echo "M numbers" > $testroot/stdout.expected
1579 cmp -s $testroot/stdout.expected $testroot/stdout
1580 ret="$?"
1581 if [ "$ret" != "0" ]; then
1582 diff -u $testroot/stdout.expected $testroot/stdout
1583 test_done "$testroot" "$ret"
1584 return 1
1587 # stage last hunk
1588 printf "n\nn\ny\n" > $testroot/patchscript
1589 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1590 numbers > $testroot/stdout)
1592 cat > $testroot/stdout.expected <<EOF
1593 -----------------------------------------------
1594 @@ -1,5 +1,5 @@
1601 -----------------------------------------------
1602 M numbers (change 1 of 3)
1603 stage this change? [y/n/q] n
1604 -----------------------------------------------
1605 @@ -4,7 +4,7 @@
1614 -----------------------------------------------
1615 M numbers (change 2 of 3)
1616 stage this change? [y/n/q] n
1617 -----------------------------------------------
1618 @@ -13,4 +13,4 @@
1622 -16
1624 -----------------------------------------------
1625 M numbers (change 3 of 3)
1626 stage this change? [y/n/q] y
1627 EOF
1628 cmp -s $testroot/stdout.expected $testroot/stdout
1629 ret="$?"
1630 if [ "$ret" != "0" ]; then
1631 diff -u $testroot/stdout.expected $testroot/stdout
1632 test_done "$testroot" "$ret"
1633 return 1
1636 (cd $testroot/wt && got status > $testroot/stdout)
1637 echo "MM numbers" > $testroot/stdout.expected
1638 cmp -s $testroot/stdout.expected $testroot/stdout
1639 ret="$?"
1640 if [ "$ret" != "0" ]; then
1641 diff -u $testroot/stdout.expected $testroot/stdout
1642 test_done "$testroot" "$ret"
1643 return 1
1646 (cd $testroot/wt && got diff -s > $testroot/stdout)
1648 echo "diff $commit_id $testroot/wt (staged changes)" \
1649 > $testroot/stdout.expected
1650 echo -n 'blob - ' >> $testroot/stdout.expected
1651 got tree -r $testroot/repo -i -c $commit_id \
1652 | grep 'numbers$' | cut -d' ' -f 1 \
1653 >> $testroot/stdout.expected
1654 echo -n 'blob + ' >> $testroot/stdout.expected
1655 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1656 >> $testroot/stdout.expected
1657 echo "--- numbers" >> $testroot/stdout.expected
1658 echo "+++ numbers" >> $testroot/stdout.expected
1659 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1660 echo " 13" >> $testroot/stdout.expected
1661 echo " 14" >> $testroot/stdout.expected
1662 echo " 15" >> $testroot/stdout.expected
1663 echo "-16" >> $testroot/stdout.expected
1664 echo "+c" >> $testroot/stdout.expected
1665 cmp -s $testroot/stdout.expected $testroot/stdout
1666 ret="$?"
1667 if [ "$ret" != "0" ]; then
1668 diff -u $testroot/stdout.expected $testroot/stdout
1670 test_done "$testroot" "$ret"
1673 function test_stage_patch_twice {
1674 local testroot=`test_init stage_patch_twice`
1676 jot 16 > $testroot/repo/numbers
1677 (cd $testroot/repo && git add numbers)
1678 git_commit $testroot/repo -m "added numbers file"
1679 local commit_id=`git_show_head $testroot/repo`
1681 got checkout $testroot/repo $testroot/wt > /dev/null
1682 ret="$?"
1683 if [ "$ret" != "0" ]; then
1684 test_done "$testroot" "$ret"
1685 return 1
1688 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1689 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1690 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1692 # stage middle hunk
1693 printf "n\ny\nn\n" > $testroot/patchscript
1694 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1695 numbers > $testroot/stdout)
1697 cat > $testroot/stdout.expected <<EOF
1698 -----------------------------------------------
1699 @@ -1,5 +1,5 @@
1706 -----------------------------------------------
1707 M numbers (change 1 of 3)
1708 stage this change? [y/n/q] n
1709 -----------------------------------------------
1710 @@ -4,7 +4,7 @@
1719 -----------------------------------------------
1720 M numbers (change 2 of 3)
1721 stage this change? [y/n/q] y
1722 -----------------------------------------------
1723 @@ -13,4 +13,4 @@
1727 -16
1729 -----------------------------------------------
1730 M numbers (change 3 of 3)
1731 stage this change? [y/n/q] n
1732 EOF
1733 cmp -s $testroot/stdout.expected $testroot/stdout
1734 ret="$?"
1735 if [ "$ret" != "0" ]; then
1736 diff -u $testroot/stdout.expected $testroot/stdout
1737 test_done "$testroot" "$ret"
1738 return 1
1741 (cd $testroot/wt && got status > $testroot/stdout)
1742 echo "MM numbers" > $testroot/stdout.expected
1743 cmp -s $testroot/stdout.expected $testroot/stdout
1744 ret="$?"
1745 if [ "$ret" != "0" ]; then
1746 diff -u $testroot/stdout.expected $testroot/stdout
1747 test_done "$testroot" "$ret"
1748 return 1
1751 # stage last hunk
1752 printf "n\ny\n" > $testroot/patchscript
1753 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1754 numbers > $testroot/stdout)
1756 cat > $testroot/stdout.expected <<EOF
1757 -----------------------------------------------
1758 @@ -1,5 +1,5 @@ b
1765 -----------------------------------------------
1766 M numbers (change 1 of 2)
1767 stage this change? [y/n/q] n
1768 -----------------------------------------------
1769 @@ -13,4 +13,4 @@ b
1773 -16
1775 -----------------------------------------------
1776 M numbers (change 2 of 2)
1777 stage this change? [y/n/q] y
1778 EOF
1779 cmp -s $testroot/stdout.expected $testroot/stdout
1780 ret="$?"
1781 if [ "$ret" != "0" ]; then
1782 diff -u $testroot/stdout.expected $testroot/stdout
1783 test_done "$testroot" "$ret"
1784 return 1
1787 (cd $testroot/wt && got status > $testroot/stdout)
1788 echo "MM numbers" > $testroot/stdout.expected
1789 cmp -s $testroot/stdout.expected $testroot/stdout
1790 ret="$?"
1791 if [ "$ret" != "0" ]; then
1792 diff -u $testroot/stdout.expected $testroot/stdout
1793 test_done "$testroot" "$ret"
1794 return 1
1797 (cd $testroot/wt && got diff -s > $testroot/stdout)
1799 echo "diff $commit_id $testroot/wt (staged changes)" \
1800 > $testroot/stdout.expected
1801 echo -n 'blob - ' >> $testroot/stdout.expected
1802 got tree -r $testroot/repo -i -c $commit_id \
1803 | grep 'numbers$' | cut -d' ' -f 1 \
1804 >> $testroot/stdout.expected
1805 echo -n 'blob + ' >> $testroot/stdout.expected
1806 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1807 >> $testroot/stdout.expected
1808 echo "--- numbers" >> $testroot/stdout.expected
1809 echo "+++ numbers" >> $testroot/stdout.expected
1810 cat >> $testroot/stdout.expected <<EOF
1811 @@ -4,7 +4,7 @@
1820 @@ -13,4 +13,4 @@
1824 -16
1826 EOF
1827 cmp -s $testroot/stdout.expected $testroot/stdout
1828 ret="$?"
1829 if [ "$ret" != "0" ]; then
1830 diff -u $testroot/stdout.expected $testroot/stdout
1831 test_done "$testroot" "$ret"
1832 return 1
1835 (cd $testroot/wt && got diff > $testroot/stdout)
1837 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1838 echo -n 'blob - ' >> $testroot/stdout.expected
1839 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1840 tr -d '\n' >> $testroot/stdout.expected
1841 echo " (staged)" >> $testroot/stdout.expected
1842 echo 'file + numbers' >> $testroot/stdout.expected
1843 echo "--- numbers" >> $testroot/stdout.expected
1844 echo "+++ numbers" >> $testroot/stdout.expected
1845 cat >> $testroot/stdout.expected <<EOF
1846 @@ -1,5 +1,5 @@
1853 EOF
1854 cmp -s $testroot/stdout.expected $testroot/stdout
1855 ret="$?"
1856 if [ "$ret" != "0" ]; then
1857 diff -u $testroot/stdout.expected $testroot/stdout
1859 test_done "$testroot" "$ret"
1862 function test_stage_patch_added {
1863 local testroot=`test_init stage_patch_added`
1864 local commit_id=`git_show_head $testroot/repo`
1866 got checkout $testroot/repo $testroot/wt > /dev/null
1867 ret="$?"
1868 if [ "$ret" != "0" ]; then
1869 test_done "$testroot" "$ret"
1870 return 1
1873 echo "new" > $testroot/wt/epsilon/new
1874 (cd $testroot/wt && got add epsilon/new > /dev/null)
1876 printf "y\n" > $testroot/patchscript
1877 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1878 epsilon/new > $testroot/stdout)
1880 echo "A epsilon/new" > $testroot/stdout.expected
1881 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1882 cmp -s $testroot/stdout.expected $testroot/stdout
1883 ret="$?"
1884 if [ "$ret" != "0" ]; then
1885 diff -u $testroot/stdout.expected $testroot/stdout
1886 test_done "$testroot" "$ret"
1887 return 1
1890 (cd $testroot/wt && got status > $testroot/stdout)
1891 echo " A epsilon/new" > $testroot/stdout.expected
1892 cmp -s $testroot/stdout.expected $testroot/stdout
1893 ret="$?"
1894 if [ "$ret" != "0" ]; then
1895 diff -u $testroot/stdout.expected $testroot/stdout
1896 test_done "$testroot" "$ret"
1897 return 1
1900 (cd $testroot/wt && got diff -s > $testroot/stdout)
1902 echo "diff $commit_id $testroot/wt (staged changes)" \
1903 > $testroot/stdout.expected
1904 echo 'blob - /dev/null' >> $testroot/stdout.expected
1905 echo -n 'blob + ' >> $testroot/stdout.expected
1906 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1907 >> $testroot/stdout.expected
1908 echo "--- /dev/null" >> $testroot/stdout.expected
1909 echo "+++ epsilon/new" >> $testroot/stdout.expected
1910 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1911 echo "+new" >> $testroot/stdout.expected
1912 cmp -s $testroot/stdout.expected $testroot/stdout
1913 ret="$?"
1914 if [ "$ret" != "0" ]; then
1915 diff -u $testroot/stdout.expected $testroot/stdout
1917 test_done "$testroot" "$ret"
1920 function test_stage_patch_added_twice {
1921 local testroot=`test_init stage_patch_added_twice`
1922 local commit_id=`git_show_head $testroot/repo`
1924 got checkout $testroot/repo $testroot/wt > /dev/null
1925 ret="$?"
1926 if [ "$ret" != "0" ]; then
1927 test_done "$testroot" "$ret"
1928 return 1
1931 echo "new" > $testroot/wt/epsilon/new
1932 (cd $testroot/wt && got add epsilon/new > /dev/null)
1934 printf "y\n" > $testroot/patchscript
1935 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1936 epsilon/new > $testroot/stdout)
1938 echo "A epsilon/new" > $testroot/stdout.expected
1939 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1940 cmp -s $testroot/stdout.expected $testroot/stdout
1941 ret="$?"
1942 if [ "$ret" != "0" ]; then
1943 diff -u $testroot/stdout.expected $testroot/stdout
1944 test_done "$testroot" "$ret"
1945 return 1
1948 (cd $testroot/wt && got status > $testroot/stdout)
1949 echo " A epsilon/new" > $testroot/stdout.expected
1950 cmp -s $testroot/stdout.expected $testroot/stdout
1951 ret="$?"
1952 if [ "$ret" != "0" ]; then
1953 diff -u $testroot/stdout.expected $testroot/stdout
1954 test_done "$testroot" "$ret"
1955 return 1
1958 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1959 epsilon/new > $testroot/stdout 2> $testroot/stderr)
1960 ret="$?"
1961 if [ "$ret" == "0" ]; then
1962 echo "got stage command succeeded unexpectedly" >&2
1963 test_done "$testroot" "1"
1964 return 1
1967 echo "got: epsilon/new: no changes to stage" > $testroot/stderr.expected
1968 cmp -s $testroot/stderr.expected $testroot/stderr
1969 ret="$?"
1970 if [ "$ret" != "0" ]; then
1971 diff -u $testroot/stderr.expected $testroot/stderr
1972 test_done "$testroot" "$ret"
1973 return 1
1976 echo -n > $testroot/stdout.expected
1977 cmp -s $testroot/stdout.expected $testroot/stdout
1978 ret="$?"
1979 if [ "$ret" != "0" ]; then
1980 diff -u $testroot/stdout.expected $testroot/stdout
1982 test_done "$testroot" "$ret"
1985 function test_stage_patch_removed {
1986 local testroot=`test_init stage_patch_removed`
1987 local commit_id=`git_show_head $testroot/repo`
1989 got checkout $testroot/repo $testroot/wt > /dev/null
1990 ret="$?"
1991 if [ "$ret" != "0" ]; then
1992 test_done "$testroot" "$ret"
1993 return 1
1996 (cd $testroot/wt && got rm beta > /dev/null)
1998 printf "y\n" > $testroot/patchscript
1999 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2000 beta > $testroot/stdout)
2002 echo -n > $testroot/stdout.expected
2004 echo "D beta" > $testroot/stdout.expected
2005 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2006 cmp -s $testroot/stdout.expected $testroot/stdout
2007 ret="$?"
2008 if [ "$ret" != "0" ]; then
2009 diff -u $testroot/stdout.expected $testroot/stdout
2010 test_done "$testroot" "$ret"
2011 return 1
2014 (cd $testroot/wt && got status > $testroot/stdout)
2015 echo " D beta" > $testroot/stdout.expected
2016 cmp -s $testroot/stdout.expected $testroot/stdout
2017 ret="$?"
2018 if [ "$ret" != "0" ]; then
2019 diff -u $testroot/stdout.expected $testroot/stdout
2020 test_done "$testroot" "$ret"
2021 return 1
2024 (cd $testroot/wt && got diff -s > $testroot/stdout)
2026 echo "diff $commit_id $testroot/wt (staged changes)" \
2027 > $testroot/stdout.expected
2028 echo -n 'blob - ' >> $testroot/stdout.expected
2029 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2030 >> $testroot/stdout.expected
2031 echo 'blob + /dev/null' >> $testroot/stdout.expected
2032 echo "--- beta" >> $testroot/stdout.expected
2033 echo "+++ /dev/null" >> $testroot/stdout.expected
2034 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2035 echo "-beta" >> $testroot/stdout.expected
2036 cmp -s $testroot/stdout.expected $testroot/stdout
2037 ret="$?"
2038 if [ "$ret" != "0" ]; then
2039 diff -u $testroot/stdout.expected $testroot/stdout
2041 test_done "$testroot" "$ret"
2044 function test_stage_patch_removed_twice {
2045 local testroot=`test_init stage_patch_removed_twice`
2046 local commit_id=`git_show_head $testroot/repo`
2048 got checkout $testroot/repo $testroot/wt > /dev/null
2049 ret="$?"
2050 if [ "$ret" != "0" ]; then
2051 test_done "$testroot" "$ret"
2052 return 1
2055 (cd $testroot/wt && got rm beta > /dev/null)
2057 printf "y\n" > $testroot/patchscript
2058 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2059 beta > $testroot/stdout)
2061 echo -n > $testroot/stdout.expected
2063 echo "D beta" > $testroot/stdout.expected
2064 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2065 cmp -s $testroot/stdout.expected $testroot/stdout
2066 ret="$?"
2067 if [ "$ret" != "0" ]; then
2068 diff -u $testroot/stdout.expected $testroot/stdout
2069 test_done "$testroot" "$ret"
2070 return 1
2073 (cd $testroot/wt && got status > $testroot/stdout)
2074 echo " D beta" > $testroot/stdout.expected
2075 cmp -s $testroot/stdout.expected $testroot/stdout
2076 ret="$?"
2077 if [ "$ret" != "0" ]; then
2078 diff -u $testroot/stdout.expected $testroot/stdout
2079 test_done "$testroot" "$ret"
2080 return 1
2083 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2084 > $testroot/stdout 2> $testroot/stderr)
2085 ret="$?"
2086 if [ "$ret" != "0" ]; then
2087 echo "got stage command failed unexpectedly" >&2
2088 test_done "$testroot" "$ret"
2089 return 1
2092 echo -n > $testroot/stderr.expected
2093 cmp -s $testroot/stderr.expected $testroot/stderr
2094 ret="$?"
2095 if [ "$ret" != "0" ]; then
2096 diff -u $testroot/stderr.expected $testroot/stderr
2097 test_done "$testroot" "$ret"
2098 return 1
2101 echo -n > $testroot/stdout.expected
2102 cmp -s $testroot/stdout.expected $testroot/stdout
2103 ret="$?"
2104 if [ "$ret" != "0" ]; then
2105 diff -u $testroot/stdout.expected $testroot/stdout
2107 test_done "$testroot" "$ret"
2110 function test_stage_patch_quit {
2111 local testroot=`test_init stage_patch_quit`
2113 jot 16 > $testroot/repo/numbers
2114 echo zzz > $testroot/repo/zzz
2115 (cd $testroot/repo && git add numbers zzz)
2116 git_commit $testroot/repo -m "added files"
2117 local commit_id=`git_show_head $testroot/repo`
2119 got checkout $testroot/repo $testroot/wt > /dev/null
2120 ret="$?"
2121 if [ "$ret" != "0" ]; then
2122 test_done "$testroot" "$ret"
2123 return 1
2126 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2127 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2128 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2129 (cd $testroot/wt && got rm zzz > /dev/null)
2131 # stage first hunk and quit; and don't pass a path argument to
2132 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2133 printf "y\nq\nn\n" > $testroot/patchscript
2134 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2135 > $testroot/stdout)
2136 ret="$?"
2137 if [ "$ret" != "0" ]; then
2138 echo "got stage command failed unexpectedly" >&2
2139 test_done "$testroot" "1"
2140 return 1
2142 cat > $testroot/stdout.expected <<EOF
2143 -----------------------------------------------
2144 @@ -1,5 +1,5 @@
2151 -----------------------------------------------
2152 M numbers (change 1 of 3)
2153 stage this change? [y/n/q] y
2154 -----------------------------------------------
2155 @@ -4,7 +4,7 @@
2164 -----------------------------------------------
2165 M numbers (change 2 of 3)
2166 stage this change? [y/n/q] q
2167 D zzz
2168 stage this deletion? [y/n] n
2169 EOF
2170 cmp -s $testroot/stdout.expected $testroot/stdout
2171 ret="$?"
2172 if [ "$ret" != "0" ]; then
2173 diff -u $testroot/stdout.expected $testroot/stdout
2174 test_done "$testroot" "$ret"
2175 return 1
2178 (cd $testroot/wt && got status > $testroot/stdout)
2179 echo "MM numbers" > $testroot/stdout.expected
2180 echo "D zzz" >> $testroot/stdout.expected
2181 cmp -s $testroot/stdout.expected $testroot/stdout
2182 ret="$?"
2183 if [ "$ret" != "0" ]; then
2184 diff -u $testroot/stdout.expected $testroot/stdout
2185 test_done "$testroot" "$ret"
2186 return 1
2189 (cd $testroot/wt && got diff -s > $testroot/stdout)
2191 echo "diff $commit_id $testroot/wt (staged changes)" \
2192 > $testroot/stdout.expected
2193 echo -n 'blob - ' >> $testroot/stdout.expected
2194 got tree -r $testroot/repo -i -c $commit_id \
2195 | grep 'numbers$' | cut -d' ' -f 1 \
2196 >> $testroot/stdout.expected
2197 echo -n 'blob + ' >> $testroot/stdout.expected
2198 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2199 >> $testroot/stdout.expected
2200 echo "--- numbers" >> $testroot/stdout.expected
2201 echo "+++ numbers" >> $testroot/stdout.expected
2202 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2203 echo " 1" >> $testroot/stdout.expected
2204 echo "-2" >> $testroot/stdout.expected
2205 echo "+a" >> $testroot/stdout.expected
2206 echo " 3" >> $testroot/stdout.expected
2207 echo " 4" >> $testroot/stdout.expected
2208 echo " 5" >> $testroot/stdout.expected
2209 cmp -s $testroot/stdout.expected $testroot/stdout
2210 ret="$?"
2211 if [ "$ret" != "0" ]; then
2212 diff -u $testroot/stdout.expected $testroot/stdout
2214 test_done "$testroot" "$ret"
2218 function test_stage_patch_incomplete_script {
2219 local testroot=`test_init stage_incomplete_script`
2221 jot 16 > $testroot/repo/numbers
2222 echo zzz > $testroot/repo/zzz
2223 (cd $testroot/repo && git add numbers zzz)
2224 git_commit $testroot/repo -m "added files"
2225 local commit_id=`git_show_head $testroot/repo`
2227 got checkout $testroot/repo $testroot/wt > /dev/null
2228 ret="$?"
2229 if [ "$ret" != "0" ]; then
2230 test_done "$testroot" "$ret"
2231 return 1
2234 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2235 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2236 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2238 # stage first hunk and then stop responding; got should error out
2239 printf "y\n" > $testroot/patchscript
2240 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2241 > $testroot/stdout 2> $testroot/stderr)
2242 ret="$?"
2243 if [ "$ret" == "0" ]; then
2244 echo "got stage command succeeded unexpectedly" >&2
2245 test_done "$testroot" "1"
2246 return 1
2248 cat > $testroot/stdout.expected <<EOF
2249 -----------------------------------------------
2250 @@ -1,5 +1,5 @@
2257 -----------------------------------------------
2258 M numbers (change 1 of 3)
2259 stage this change? [y/n/q] y
2260 -----------------------------------------------
2261 @@ -4,7 +4,7 @@
2270 -----------------------------------------------
2271 M numbers (change 2 of 3)
2272 EOF
2273 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2274 echo "got: invalid patch choice" > $testroot/stderr.expected
2275 cmp -s $testroot/stderr.expected $testroot/stderr
2276 ret="$?"
2277 if [ "$ret" != "0" ]; then
2278 diff -u $testroot/stderr.expected $testroot/stderr
2279 test_done "$testroot" "$ret"
2280 return 1
2283 cmp -s $testroot/stdout.expected $testroot/stdout
2284 ret="$?"
2285 if [ "$ret" != "0" ]; then
2286 diff -u $testroot/stdout.expected $testroot/stdout
2287 test_done "$testroot" "$ret"
2288 return 1
2291 (cd $testroot/wt && got status > $testroot/stdout)
2292 echo "M numbers" > $testroot/stdout.expected
2293 cmp -s $testroot/stdout.expected $testroot/stdout
2294 ret="$?"
2295 if [ "$ret" != "0" ]; then
2296 diff -u $testroot/stdout.expected $testroot/stdout
2297 test_done "$testroot" "$ret"
2298 return 1
2301 (cd $testroot/wt && got diff -s > $testroot/stdout)
2302 echo -n > $testroot/stdout.expected
2303 cmp -s $testroot/stdout.expected $testroot/stdout
2304 ret="$?"
2305 if [ "$ret" != "0" ]; then
2306 diff -u $testroot/stdout.expected $testroot/stdout
2308 test_done "$testroot" "$ret"
2312 run_test test_stage_basic
2313 run_test test_stage_no_changes
2314 run_test test_stage_unversioned
2315 run_test test_stage_nonexistent
2316 run_test test_stage_list
2317 run_test test_stage_conflict
2318 run_test test_stage_out_of_date
2319 run_test test_double_stage
2320 run_test test_stage_status
2321 run_test test_stage_add_already_staged_file
2322 run_test test_stage_rm_already_staged_file
2323 run_test test_stage_revert
2324 run_test test_stage_diff
2325 run_test test_stage_histedit
2326 run_test test_stage_rebase
2327 run_test test_stage_update
2328 run_test test_stage_commit_non_staged
2329 run_test test_stage_commit_out_of_date
2330 run_test test_stage_commit
2331 run_test test_stage_patch
2332 run_test test_stage_patch_twice
2333 run_test test_stage_patch_added
2334 run_test test_stage_patch_added_twice
2335 run_test test_stage_patch_removed
2336 run_test test_stage_patch_removed_twice
2337 run_test test_stage_patch_quit
2338 run_test test_stage_patch_incomplete_script