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 | tr -d '\n' \
1363 >> $testroot/stdout.expected
1364 echo " (mode 644)" >> $testroot/stdout.expected
1365 echo 'blob + /dev/null' >> $testroot/stdout.expected
1366 echo '--- beta' >> $testroot/stdout.expected
1367 echo '+++ /dev/null' >> $testroot/stdout.expected
1368 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1369 echo '-beta' >> $testroot/stdout.expected
1370 echo 'blob - /dev/null' >> $testroot/stdout.expected
1371 echo -n 'blob + ' >> $testroot/stdout.expected
1372 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1373 echo " (mode 644)" >> $testroot/stdout.expected
1374 echo '--- /dev/null' >> $testroot/stdout.expected
1375 echo '+++ foo' >> $testroot/stdout.expected
1376 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1377 echo '+new file' >> $testroot/stdout.expected
1379 cmp -s $testroot/stdout.expected $testroot/stdout
1380 ret="$?"
1381 if [ "$ret" != "0" ]; then
1382 diff -u $testroot/stdout.expected $testroot/stdout
1383 test_done "$testroot" "$ret"
1384 return 1
1387 echo 'M alpha' > $testroot/stdout.expected
1388 echo 'A epsilon/new' >> $testroot/stdout.expected
1389 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1390 echo 'M foo' >> $testroot/stdout.expected
1391 echo 'M gamma/delta' >> $testroot/stdout.expected
1393 (cd $testroot/wt && got status > $testroot/stdout)
1394 cmp -s $testroot/stdout.expected $testroot/stdout
1395 ret="$?"
1396 if [ "$ret" != "0" ]; then
1397 diff -u $testroot/stdout.expected $testroot/stdout
1399 test_done "$testroot" "$ret"
1402 function test_stage_patch {
1403 local testroot=`test_init stage_patch`
1405 jot 16 > $testroot/repo/numbers
1406 (cd $testroot/repo && git add numbers)
1407 git_commit $testroot/repo -m "added numbers file"
1408 local commit_id=`git_show_head $testroot/repo`
1410 got checkout $testroot/repo $testroot/wt > /dev/null
1411 ret="$?"
1412 if [ "$ret" != "0" ]; then
1413 test_done "$testroot" "$ret"
1414 return 1
1417 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1418 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1419 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1421 # don't stage any hunks
1422 printf "n\nn\nn\n" > $testroot/patchscript
1423 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1424 numbers > $testroot/stdout)
1425 ret="$?"
1426 if [ "$ret" != "0" ]; then
1427 echo "got stage command failed unexpectedly" >&2
1428 test_done "$testroot" "1"
1429 return 1
1431 cat > $testroot/stdout.expected <<EOF
1432 -----------------------------------------------
1433 @@ -1,5 +1,5 @@
1440 -----------------------------------------------
1441 M numbers (change 1 of 3)
1442 stage this change? [y/n/q] n
1443 -----------------------------------------------
1444 @@ -4,7 +4,7 @@
1453 -----------------------------------------------
1454 M numbers (change 2 of 3)
1455 stage this change? [y/n/q] n
1456 -----------------------------------------------
1457 @@ -13,4 +13,4 @@
1461 -16
1463 -----------------------------------------------
1464 M numbers (change 3 of 3)
1465 stage this change? [y/n/q] n
1466 EOF
1467 cmp -s $testroot/stdout.expected $testroot/stdout
1468 ret="$?"
1469 if [ "$ret" != "0" ]; then
1470 diff -u $testroot/stdout.expected $testroot/stdout
1471 test_done "$testroot" "$ret"
1472 return 1
1475 (cd $testroot/wt && got status > $testroot/stdout)
1476 echo "M numbers" > $testroot/stdout.expected
1477 cmp -s $testroot/stdout.expected $testroot/stdout
1478 ret="$?"
1479 if [ "$ret" != "0" ]; then
1480 diff -u $testroot/stdout.expected $testroot/stdout
1481 test_done "$testroot" "$ret"
1482 return 1
1485 # stage middle hunk
1486 printf "n\ny\nn\n" > $testroot/patchscript
1487 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1488 numbers > $testroot/stdout)
1490 cat > $testroot/stdout.expected <<EOF
1491 -----------------------------------------------
1492 @@ -1,5 +1,5 @@
1499 -----------------------------------------------
1500 M numbers (change 1 of 3)
1501 stage this change? [y/n/q] n
1502 -----------------------------------------------
1503 @@ -4,7 +4,7 @@
1512 -----------------------------------------------
1513 M numbers (change 2 of 3)
1514 stage this change? [y/n/q] y
1515 -----------------------------------------------
1516 @@ -13,4 +13,4 @@
1520 -16
1522 -----------------------------------------------
1523 M numbers (change 3 of 3)
1524 stage this change? [y/n/q] n
1525 EOF
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 (cd $testroot/wt && got status > $testroot/stdout)
1535 echo "MM numbers" > $testroot/stdout.expected
1536 cmp -s $testroot/stdout.expected $testroot/stdout
1537 ret="$?"
1538 if [ "$ret" != "0" ]; then
1539 diff -u $testroot/stdout.expected $testroot/stdout
1540 test_done "$testroot" "$ret"
1541 return 1
1544 (cd $testroot/wt && got diff -s > $testroot/stdout)
1546 echo "diff $commit_id $testroot/wt (staged changes)" \
1547 > $testroot/stdout.expected
1548 echo -n 'blob - ' >> $testroot/stdout.expected
1549 got tree -r $testroot/repo -i -c $commit_id \
1550 | grep 'numbers$' | cut -d' ' -f 1 \
1551 >> $testroot/stdout.expected
1552 echo -n 'blob + ' >> $testroot/stdout.expected
1553 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1554 >> $testroot/stdout.expected
1555 echo "--- numbers" >> $testroot/stdout.expected
1556 echo "+++ numbers" >> $testroot/stdout.expected
1557 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1558 echo " 4" >> $testroot/stdout.expected
1559 echo " 5" >> $testroot/stdout.expected
1560 echo " 6" >> $testroot/stdout.expected
1561 echo "-7" >> $testroot/stdout.expected
1562 echo "+b" >> $testroot/stdout.expected
1563 echo " 8" >> $testroot/stdout.expected
1564 echo " 9" >> $testroot/stdout.expected
1565 echo " 10" >> $testroot/stdout.expected
1566 cmp -s $testroot/stdout.expected $testroot/stdout
1567 ret="$?"
1568 if [ "$ret" != "0" ]; then
1569 diff -u $testroot/stdout.expected $testroot/stdout
1570 test_done "$testroot" "$ret"
1571 return 1
1574 (cd $testroot/wt && got unstage >/dev/null)
1575 ret="$?"
1576 if [ "$ret" != "0" ]; then
1577 echo "got stage command failed unexpectedly" >&2
1578 test_done "$testroot" "1"
1579 return 1
1581 (cd $testroot/wt && got status > $testroot/stdout)
1582 echo "M numbers" > $testroot/stdout.expected
1583 cmp -s $testroot/stdout.expected $testroot/stdout
1584 ret="$?"
1585 if [ "$ret" != "0" ]; then
1586 diff -u $testroot/stdout.expected $testroot/stdout
1587 test_done "$testroot" "$ret"
1588 return 1
1591 # stage last hunk
1592 printf "n\nn\ny\n" > $testroot/patchscript
1593 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1594 numbers > $testroot/stdout)
1596 cat > $testroot/stdout.expected <<EOF
1597 -----------------------------------------------
1598 @@ -1,5 +1,5 @@
1605 -----------------------------------------------
1606 M numbers (change 1 of 3)
1607 stage this change? [y/n/q] n
1608 -----------------------------------------------
1609 @@ -4,7 +4,7 @@
1618 -----------------------------------------------
1619 M numbers (change 2 of 3)
1620 stage this change? [y/n/q] n
1621 -----------------------------------------------
1622 @@ -13,4 +13,4 @@
1626 -16
1628 -----------------------------------------------
1629 M numbers (change 3 of 3)
1630 stage this change? [y/n/q] y
1631 EOF
1632 cmp -s $testroot/stdout.expected $testroot/stdout
1633 ret="$?"
1634 if [ "$ret" != "0" ]; then
1635 diff -u $testroot/stdout.expected $testroot/stdout
1636 test_done "$testroot" "$ret"
1637 return 1
1640 (cd $testroot/wt && got status > $testroot/stdout)
1641 echo "MM numbers" > $testroot/stdout.expected
1642 cmp -s $testroot/stdout.expected $testroot/stdout
1643 ret="$?"
1644 if [ "$ret" != "0" ]; then
1645 diff -u $testroot/stdout.expected $testroot/stdout
1646 test_done "$testroot" "$ret"
1647 return 1
1650 (cd $testroot/wt && got diff -s > $testroot/stdout)
1652 echo "diff $commit_id $testroot/wt (staged changes)" \
1653 > $testroot/stdout.expected
1654 echo -n 'blob - ' >> $testroot/stdout.expected
1655 got tree -r $testroot/repo -i -c $commit_id \
1656 | grep 'numbers$' | cut -d' ' -f 1 \
1657 >> $testroot/stdout.expected
1658 echo -n 'blob + ' >> $testroot/stdout.expected
1659 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1660 >> $testroot/stdout.expected
1661 echo "--- numbers" >> $testroot/stdout.expected
1662 echo "+++ numbers" >> $testroot/stdout.expected
1663 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1664 echo " 13" >> $testroot/stdout.expected
1665 echo " 14" >> $testroot/stdout.expected
1666 echo " 15" >> $testroot/stdout.expected
1667 echo "-16" >> $testroot/stdout.expected
1668 echo "+c" >> $testroot/stdout.expected
1669 cmp -s $testroot/stdout.expected $testroot/stdout
1670 ret="$?"
1671 if [ "$ret" != "0" ]; then
1672 diff -u $testroot/stdout.expected $testroot/stdout
1674 test_done "$testroot" "$ret"
1677 function test_stage_patch_twice {
1678 local testroot=`test_init stage_patch_twice`
1680 jot 16 > $testroot/repo/numbers
1681 (cd $testroot/repo && git add numbers)
1682 git_commit $testroot/repo -m "added numbers file"
1683 local commit_id=`git_show_head $testroot/repo`
1685 got checkout $testroot/repo $testroot/wt > /dev/null
1686 ret="$?"
1687 if [ "$ret" != "0" ]; then
1688 test_done "$testroot" "$ret"
1689 return 1
1692 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1693 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1694 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1696 # stage middle hunk
1697 printf "n\ny\nn\n" > $testroot/patchscript
1698 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1699 numbers > $testroot/stdout)
1701 cat > $testroot/stdout.expected <<EOF
1702 -----------------------------------------------
1703 @@ -1,5 +1,5 @@
1710 -----------------------------------------------
1711 M numbers (change 1 of 3)
1712 stage this change? [y/n/q] n
1713 -----------------------------------------------
1714 @@ -4,7 +4,7 @@
1723 -----------------------------------------------
1724 M numbers (change 2 of 3)
1725 stage this change? [y/n/q] y
1726 -----------------------------------------------
1727 @@ -13,4 +13,4 @@
1731 -16
1733 -----------------------------------------------
1734 M numbers (change 3 of 3)
1735 stage this change? [y/n/q] n
1736 EOF
1737 cmp -s $testroot/stdout.expected $testroot/stdout
1738 ret="$?"
1739 if [ "$ret" != "0" ]; then
1740 diff -u $testroot/stdout.expected $testroot/stdout
1741 test_done "$testroot" "$ret"
1742 return 1
1745 (cd $testroot/wt && got status > $testroot/stdout)
1746 echo "MM numbers" > $testroot/stdout.expected
1747 cmp -s $testroot/stdout.expected $testroot/stdout
1748 ret="$?"
1749 if [ "$ret" != "0" ]; then
1750 diff -u $testroot/stdout.expected $testroot/stdout
1751 test_done "$testroot" "$ret"
1752 return 1
1755 # stage last hunk
1756 printf "n\ny\n" > $testroot/patchscript
1757 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1758 numbers > $testroot/stdout)
1760 cat > $testroot/stdout.expected <<EOF
1761 -----------------------------------------------
1762 @@ -1,5 +1,5 @@ b
1769 -----------------------------------------------
1770 M numbers (change 1 of 2)
1771 stage this change? [y/n/q] n
1772 -----------------------------------------------
1773 @@ -13,4 +13,4 @@ b
1777 -16
1779 -----------------------------------------------
1780 M numbers (change 2 of 2)
1781 stage this change? [y/n/q] y
1782 EOF
1783 cmp -s $testroot/stdout.expected $testroot/stdout
1784 ret="$?"
1785 if [ "$ret" != "0" ]; then
1786 diff -u $testroot/stdout.expected $testroot/stdout
1787 test_done "$testroot" "$ret"
1788 return 1
1791 (cd $testroot/wt && got status > $testroot/stdout)
1792 echo "MM numbers" > $testroot/stdout.expected
1793 cmp -s $testroot/stdout.expected $testroot/stdout
1794 ret="$?"
1795 if [ "$ret" != "0" ]; then
1796 diff -u $testroot/stdout.expected $testroot/stdout
1797 test_done "$testroot" "$ret"
1798 return 1
1801 (cd $testroot/wt && got diff -s > $testroot/stdout)
1803 echo "diff $commit_id $testroot/wt (staged changes)" \
1804 > $testroot/stdout.expected
1805 echo -n 'blob - ' >> $testroot/stdout.expected
1806 got tree -r $testroot/repo -i -c $commit_id \
1807 | grep 'numbers$' | cut -d' ' -f 1 \
1808 >> $testroot/stdout.expected
1809 echo -n 'blob + ' >> $testroot/stdout.expected
1810 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1811 >> $testroot/stdout.expected
1812 echo "--- numbers" >> $testroot/stdout.expected
1813 echo "+++ numbers" >> $testroot/stdout.expected
1814 cat >> $testroot/stdout.expected <<EOF
1815 @@ -4,7 +4,7 @@
1824 @@ -13,4 +13,4 @@
1828 -16
1830 EOF
1831 cmp -s $testroot/stdout.expected $testroot/stdout
1832 ret="$?"
1833 if [ "$ret" != "0" ]; then
1834 diff -u $testroot/stdout.expected $testroot/stdout
1835 test_done "$testroot" "$ret"
1836 return 1
1839 (cd $testroot/wt && got diff > $testroot/stdout)
1841 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1842 echo -n 'blob - ' >> $testroot/stdout.expected
1843 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1844 tr -d '\n' >> $testroot/stdout.expected
1845 echo " (staged)" >> $testroot/stdout.expected
1846 echo 'file + numbers' >> $testroot/stdout.expected
1847 echo "--- numbers" >> $testroot/stdout.expected
1848 echo "+++ numbers" >> $testroot/stdout.expected
1849 cat >> $testroot/stdout.expected <<EOF
1850 @@ -1,5 +1,5 @@
1857 EOF
1858 cmp -s $testroot/stdout.expected $testroot/stdout
1859 ret="$?"
1860 if [ "$ret" != "0" ]; then
1861 diff -u $testroot/stdout.expected $testroot/stdout
1863 test_done "$testroot" "$ret"
1866 function test_stage_patch_added {
1867 local testroot=`test_init stage_patch_added`
1868 local commit_id=`git_show_head $testroot/repo`
1870 got checkout $testroot/repo $testroot/wt > /dev/null
1871 ret="$?"
1872 if [ "$ret" != "0" ]; then
1873 test_done "$testroot" "$ret"
1874 return 1
1877 echo "new" > $testroot/wt/epsilon/new
1878 (cd $testroot/wt && got add epsilon/new > /dev/null)
1880 printf "y\n" > $testroot/patchscript
1881 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1882 epsilon/new > $testroot/stdout)
1884 echo "A epsilon/new" > $testroot/stdout.expected
1885 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1886 cmp -s $testroot/stdout.expected $testroot/stdout
1887 ret="$?"
1888 if [ "$ret" != "0" ]; then
1889 diff -u $testroot/stdout.expected $testroot/stdout
1890 test_done "$testroot" "$ret"
1891 return 1
1894 (cd $testroot/wt && got status > $testroot/stdout)
1895 echo " A epsilon/new" > $testroot/stdout.expected
1896 cmp -s $testroot/stdout.expected $testroot/stdout
1897 ret="$?"
1898 if [ "$ret" != "0" ]; then
1899 diff -u $testroot/stdout.expected $testroot/stdout
1900 test_done "$testroot" "$ret"
1901 return 1
1904 (cd $testroot/wt && got diff -s > $testroot/stdout)
1906 echo "diff $commit_id $testroot/wt (staged changes)" \
1907 > $testroot/stdout.expected
1908 echo 'blob - /dev/null' >> $testroot/stdout.expected
1909 echo -n 'blob + ' >> $testroot/stdout.expected
1910 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1911 >> $testroot/stdout.expected
1912 echo "--- /dev/null" >> $testroot/stdout.expected
1913 echo "+++ epsilon/new" >> $testroot/stdout.expected
1914 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1915 echo "+new" >> $testroot/stdout.expected
1916 cmp -s $testroot/stdout.expected $testroot/stdout
1917 ret="$?"
1918 if [ "$ret" != "0" ]; then
1919 diff -u $testroot/stdout.expected $testroot/stdout
1921 test_done "$testroot" "$ret"
1924 function test_stage_patch_added_twice {
1925 local testroot=`test_init stage_patch_added_twice`
1926 local commit_id=`git_show_head $testroot/repo`
1928 got checkout $testroot/repo $testroot/wt > /dev/null
1929 ret="$?"
1930 if [ "$ret" != "0" ]; then
1931 test_done "$testroot" "$ret"
1932 return 1
1935 echo "new" > $testroot/wt/epsilon/new
1936 (cd $testroot/wt && got add epsilon/new > /dev/null)
1938 printf "y\n" > $testroot/patchscript
1939 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1940 epsilon/new > $testroot/stdout)
1942 echo "A epsilon/new" > $testroot/stdout.expected
1943 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1944 cmp -s $testroot/stdout.expected $testroot/stdout
1945 ret="$?"
1946 if [ "$ret" != "0" ]; then
1947 diff -u $testroot/stdout.expected $testroot/stdout
1948 test_done "$testroot" "$ret"
1949 return 1
1952 (cd $testroot/wt && got status > $testroot/stdout)
1953 echo " A epsilon/new" > $testroot/stdout.expected
1954 cmp -s $testroot/stdout.expected $testroot/stdout
1955 ret="$?"
1956 if [ "$ret" != "0" ]; then
1957 diff -u $testroot/stdout.expected $testroot/stdout
1958 test_done "$testroot" "$ret"
1959 return 1
1962 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1963 epsilon/new > $testroot/stdout 2> $testroot/stderr)
1964 ret="$?"
1965 if [ "$ret" == "0" ]; then
1966 echo "got stage command succeeded unexpectedly" >&2
1967 test_done "$testroot" "1"
1968 return 1
1971 echo "got: epsilon/new: no changes to stage" > $testroot/stderr.expected
1972 cmp -s $testroot/stderr.expected $testroot/stderr
1973 ret="$?"
1974 if [ "$ret" != "0" ]; then
1975 diff -u $testroot/stderr.expected $testroot/stderr
1976 test_done "$testroot" "$ret"
1977 return 1
1980 echo -n > $testroot/stdout.expected
1981 cmp -s $testroot/stdout.expected $testroot/stdout
1982 ret="$?"
1983 if [ "$ret" != "0" ]; then
1984 diff -u $testroot/stdout.expected $testroot/stdout
1986 test_done "$testroot" "$ret"
1989 function test_stage_patch_removed {
1990 local testroot=`test_init stage_patch_removed`
1991 local commit_id=`git_show_head $testroot/repo`
1993 got checkout $testroot/repo $testroot/wt > /dev/null
1994 ret="$?"
1995 if [ "$ret" != "0" ]; then
1996 test_done "$testroot" "$ret"
1997 return 1
2000 (cd $testroot/wt && got rm beta > /dev/null)
2002 printf "y\n" > $testroot/patchscript
2003 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2004 beta > $testroot/stdout)
2006 echo -n > $testroot/stdout.expected
2008 echo "D beta" > $testroot/stdout.expected
2009 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2010 cmp -s $testroot/stdout.expected $testroot/stdout
2011 ret="$?"
2012 if [ "$ret" != "0" ]; then
2013 diff -u $testroot/stdout.expected $testroot/stdout
2014 test_done "$testroot" "$ret"
2015 return 1
2018 (cd $testroot/wt && got status > $testroot/stdout)
2019 echo " D beta" > $testroot/stdout.expected
2020 cmp -s $testroot/stdout.expected $testroot/stdout
2021 ret="$?"
2022 if [ "$ret" != "0" ]; then
2023 diff -u $testroot/stdout.expected $testroot/stdout
2024 test_done "$testroot" "$ret"
2025 return 1
2028 (cd $testroot/wt && got diff -s > $testroot/stdout)
2030 echo "diff $commit_id $testroot/wt (staged changes)" \
2031 > $testroot/stdout.expected
2032 echo -n 'blob - ' >> $testroot/stdout.expected
2033 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2034 >> $testroot/stdout.expected
2035 echo 'blob + /dev/null' >> $testroot/stdout.expected
2036 echo "--- beta" >> $testroot/stdout.expected
2037 echo "+++ /dev/null" >> $testroot/stdout.expected
2038 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2039 echo "-beta" >> $testroot/stdout.expected
2040 cmp -s $testroot/stdout.expected $testroot/stdout
2041 ret="$?"
2042 if [ "$ret" != "0" ]; then
2043 diff -u $testroot/stdout.expected $testroot/stdout
2045 test_done "$testroot" "$ret"
2048 function test_stage_patch_removed_twice {
2049 local testroot=`test_init stage_patch_removed_twice`
2050 local commit_id=`git_show_head $testroot/repo`
2052 got checkout $testroot/repo $testroot/wt > /dev/null
2053 ret="$?"
2054 if [ "$ret" != "0" ]; then
2055 test_done "$testroot" "$ret"
2056 return 1
2059 (cd $testroot/wt && got rm beta > /dev/null)
2061 printf "y\n" > $testroot/patchscript
2062 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2063 beta > $testroot/stdout)
2065 echo -n > $testroot/stdout.expected
2067 echo "D beta" > $testroot/stdout.expected
2068 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2069 cmp -s $testroot/stdout.expected $testroot/stdout
2070 ret="$?"
2071 if [ "$ret" != "0" ]; then
2072 diff -u $testroot/stdout.expected $testroot/stdout
2073 test_done "$testroot" "$ret"
2074 return 1
2077 (cd $testroot/wt && got status > $testroot/stdout)
2078 echo " D beta" > $testroot/stdout.expected
2079 cmp -s $testroot/stdout.expected $testroot/stdout
2080 ret="$?"
2081 if [ "$ret" != "0" ]; then
2082 diff -u $testroot/stdout.expected $testroot/stdout
2083 test_done "$testroot" "$ret"
2084 return 1
2087 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2088 > $testroot/stdout 2> $testroot/stderr)
2089 ret="$?"
2090 if [ "$ret" != "0" ]; then
2091 echo "got stage command failed unexpectedly" >&2
2092 test_done "$testroot" "$ret"
2093 return 1
2096 echo -n > $testroot/stderr.expected
2097 cmp -s $testroot/stderr.expected $testroot/stderr
2098 ret="$?"
2099 if [ "$ret" != "0" ]; then
2100 diff -u $testroot/stderr.expected $testroot/stderr
2101 test_done "$testroot" "$ret"
2102 return 1
2105 echo -n > $testroot/stdout.expected
2106 cmp -s $testroot/stdout.expected $testroot/stdout
2107 ret="$?"
2108 if [ "$ret" != "0" ]; then
2109 diff -u $testroot/stdout.expected $testroot/stdout
2111 test_done "$testroot" "$ret"
2114 function test_stage_patch_quit {
2115 local testroot=`test_init stage_patch_quit`
2117 jot 16 > $testroot/repo/numbers
2118 echo zzz > $testroot/repo/zzz
2119 (cd $testroot/repo && git add numbers zzz)
2120 git_commit $testroot/repo -m "added files"
2121 local commit_id=`git_show_head $testroot/repo`
2123 got checkout $testroot/repo $testroot/wt > /dev/null
2124 ret="$?"
2125 if [ "$ret" != "0" ]; then
2126 test_done "$testroot" "$ret"
2127 return 1
2130 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2131 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2132 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2133 (cd $testroot/wt && got rm zzz > /dev/null)
2135 # stage first hunk and quit; and don't pass a path argument to
2136 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2137 printf "y\nq\nn\n" > $testroot/patchscript
2138 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2139 > $testroot/stdout)
2140 ret="$?"
2141 if [ "$ret" != "0" ]; then
2142 echo "got stage command failed unexpectedly" >&2
2143 test_done "$testroot" "1"
2144 return 1
2146 cat > $testroot/stdout.expected <<EOF
2147 -----------------------------------------------
2148 @@ -1,5 +1,5 @@
2155 -----------------------------------------------
2156 M numbers (change 1 of 3)
2157 stage this change? [y/n/q] y
2158 -----------------------------------------------
2159 @@ -4,7 +4,7 @@
2168 -----------------------------------------------
2169 M numbers (change 2 of 3)
2170 stage this change? [y/n/q] q
2171 D zzz
2172 stage this deletion? [y/n] n
2173 EOF
2174 cmp -s $testroot/stdout.expected $testroot/stdout
2175 ret="$?"
2176 if [ "$ret" != "0" ]; then
2177 diff -u $testroot/stdout.expected $testroot/stdout
2178 test_done "$testroot" "$ret"
2179 return 1
2182 (cd $testroot/wt && got status > $testroot/stdout)
2183 echo "MM numbers" > $testroot/stdout.expected
2184 echo "D zzz" >> $testroot/stdout.expected
2185 cmp -s $testroot/stdout.expected $testroot/stdout
2186 ret="$?"
2187 if [ "$ret" != "0" ]; then
2188 diff -u $testroot/stdout.expected $testroot/stdout
2189 test_done "$testroot" "$ret"
2190 return 1
2193 (cd $testroot/wt && got diff -s > $testroot/stdout)
2195 echo "diff $commit_id $testroot/wt (staged changes)" \
2196 > $testroot/stdout.expected
2197 echo -n 'blob - ' >> $testroot/stdout.expected
2198 got tree -r $testroot/repo -i -c $commit_id \
2199 | grep 'numbers$' | cut -d' ' -f 1 \
2200 >> $testroot/stdout.expected
2201 echo -n 'blob + ' >> $testroot/stdout.expected
2202 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2203 >> $testroot/stdout.expected
2204 echo "--- numbers" >> $testroot/stdout.expected
2205 echo "+++ numbers" >> $testroot/stdout.expected
2206 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2207 echo " 1" >> $testroot/stdout.expected
2208 echo "-2" >> $testroot/stdout.expected
2209 echo "+a" >> $testroot/stdout.expected
2210 echo " 3" >> $testroot/stdout.expected
2211 echo " 4" >> $testroot/stdout.expected
2212 echo " 5" >> $testroot/stdout.expected
2213 cmp -s $testroot/stdout.expected $testroot/stdout
2214 ret="$?"
2215 if [ "$ret" != "0" ]; then
2216 diff -u $testroot/stdout.expected $testroot/stdout
2218 test_done "$testroot" "$ret"
2222 function test_stage_patch_incomplete_script {
2223 local testroot=`test_init stage_incomplete_script`
2225 jot 16 > $testroot/repo/numbers
2226 echo zzz > $testroot/repo/zzz
2227 (cd $testroot/repo && git add numbers zzz)
2228 git_commit $testroot/repo -m "added files"
2229 local commit_id=`git_show_head $testroot/repo`
2231 got checkout $testroot/repo $testroot/wt > /dev/null
2232 ret="$?"
2233 if [ "$ret" != "0" ]; then
2234 test_done "$testroot" "$ret"
2235 return 1
2238 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2239 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2240 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2242 # stage first hunk and then stop responding; got should error out
2243 printf "y\n" > $testroot/patchscript
2244 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2245 > $testroot/stdout 2> $testroot/stderr)
2246 ret="$?"
2247 if [ "$ret" == "0" ]; then
2248 echo "got stage command succeeded unexpectedly" >&2
2249 test_done "$testroot" "1"
2250 return 1
2252 cat > $testroot/stdout.expected <<EOF
2253 -----------------------------------------------
2254 @@ -1,5 +1,5 @@
2261 -----------------------------------------------
2262 M numbers (change 1 of 3)
2263 stage this change? [y/n/q] y
2264 -----------------------------------------------
2265 @@ -4,7 +4,7 @@
2274 -----------------------------------------------
2275 M numbers (change 2 of 3)
2276 EOF
2277 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2278 echo "got: invalid patch choice" > $testroot/stderr.expected
2279 cmp -s $testroot/stderr.expected $testroot/stderr
2280 ret="$?"
2281 if [ "$ret" != "0" ]; then
2282 diff -u $testroot/stderr.expected $testroot/stderr
2283 test_done "$testroot" "$ret"
2284 return 1
2287 cmp -s $testroot/stdout.expected $testroot/stdout
2288 ret="$?"
2289 if [ "$ret" != "0" ]; then
2290 diff -u $testroot/stdout.expected $testroot/stdout
2291 test_done "$testroot" "$ret"
2292 return 1
2295 (cd $testroot/wt && got status > $testroot/stdout)
2296 echo "M numbers" > $testroot/stdout.expected
2297 cmp -s $testroot/stdout.expected $testroot/stdout
2298 ret="$?"
2299 if [ "$ret" != "0" ]; then
2300 diff -u $testroot/stdout.expected $testroot/stdout
2301 test_done "$testroot" "$ret"
2302 return 1
2305 (cd $testroot/wt && got diff -s > $testroot/stdout)
2306 echo -n > $testroot/stdout.expected
2307 cmp -s $testroot/stdout.expected $testroot/stdout
2308 ret="$?"
2309 if [ "$ret" != "0" ]; then
2310 diff -u $testroot/stdout.expected $testroot/stdout
2312 test_done "$testroot" "$ret"
2316 run_test test_stage_basic
2317 run_test test_stage_no_changes
2318 run_test test_stage_unversioned
2319 run_test test_stage_nonexistent
2320 run_test test_stage_list
2321 run_test test_stage_conflict
2322 run_test test_stage_out_of_date
2323 run_test test_double_stage
2324 run_test test_stage_status
2325 run_test test_stage_add_already_staged_file
2326 run_test test_stage_rm_already_staged_file
2327 run_test test_stage_revert
2328 run_test test_stage_diff
2329 run_test test_stage_histedit
2330 run_test test_stage_rebase
2331 run_test test_stage_update
2332 run_test test_stage_commit_non_staged
2333 run_test test_stage_commit_out_of_date
2334 run_test test_stage_commit
2335 run_test test_stage_patch
2336 run_test test_stage_patch_twice
2337 run_test test_stage_patch_added
2338 run_test test_stage_patch_added_twice
2339 run_test test_stage_patch_removed
2340 run_test test_stage_patch_removed_twice
2341 run_test test_stage_patch_quit
2342 run_test test_stage_patch_incomplete_script