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 'M alpha' > $testroot/stdout.expected
1386 echo 'A epsilon/new' >> $testroot/stdout.expected
1387 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1388 echo 'M foo' >> $testroot/stdout.expected
1389 echo 'M gamma/delta' >> $testroot/stdout.expected
1391 (cd $testroot/wt && got status > $testroot/stdout)
1392 cmp -s $testroot/stdout.expected $testroot/stdout
1393 ret="$?"
1394 if [ "$ret" != "0" ]; then
1395 diff -u $testroot/stdout.expected $testroot/stdout
1397 test_done "$testroot" "$ret"
1400 function test_stage_patch {
1401 local testroot=`test_init stage_patch`
1403 jot 16 > $testroot/repo/numbers
1404 (cd $testroot/repo && git add numbers)
1405 git_commit $testroot/repo -m "added numbers file"
1406 local commit_id=`git_show_head $testroot/repo`
1408 got checkout $testroot/repo $testroot/wt > /dev/null
1409 ret="$?"
1410 if [ "$ret" != "0" ]; then
1411 test_done "$testroot" "$ret"
1412 return 1
1415 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1416 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1417 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1419 # don't stage any hunks
1420 printf "n\nn\nn\n" > $testroot/patchscript
1421 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1422 numbers > $testroot/stdout)
1423 ret="$?"
1424 if [ "$ret" != "0" ]; then
1425 echo "got stage command failed unexpectedly" >&2
1426 test_done "$testroot" "1"
1427 return 1
1429 cat > $testroot/stdout.expected <<EOF
1430 -----------------------------------------------
1431 @@ -1,5 +1,5 @@
1438 -----------------------------------------------
1439 M numbers (change 1 of 3)
1440 stage this change? [y/n/q] n
1441 -----------------------------------------------
1442 @@ -4,7 +4,7 @@
1451 -----------------------------------------------
1452 M numbers (change 2 of 3)
1453 stage this change? [y/n/q] n
1454 -----------------------------------------------
1455 @@ -13,4 +13,4 @@
1459 -16
1461 -----------------------------------------------
1462 M numbers (change 3 of 3)
1463 stage this change? [y/n/q] n
1464 EOF
1465 cmp -s $testroot/stdout.expected $testroot/stdout
1466 ret="$?"
1467 if [ "$ret" != "0" ]; then
1468 diff -u $testroot/stdout.expected $testroot/stdout
1469 test_done "$testroot" "$ret"
1470 return 1
1473 (cd $testroot/wt && got status > $testroot/stdout)
1474 echo "M numbers" > $testroot/stdout.expected
1475 cmp -s $testroot/stdout.expected $testroot/stdout
1476 ret="$?"
1477 if [ "$ret" != "0" ]; then
1478 diff -u $testroot/stdout.expected $testroot/stdout
1479 test_done "$testroot" "$ret"
1480 return 1
1483 # stage middle hunk
1484 printf "n\ny\nn\n" > $testroot/patchscript
1485 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1486 numbers > $testroot/stdout)
1488 cat > $testroot/stdout.expected <<EOF
1489 -----------------------------------------------
1490 @@ -1,5 +1,5 @@
1497 -----------------------------------------------
1498 M numbers (change 1 of 3)
1499 stage this change? [y/n/q] n
1500 -----------------------------------------------
1501 @@ -4,7 +4,7 @@
1510 -----------------------------------------------
1511 M numbers (change 2 of 3)
1512 stage this change? [y/n/q] y
1513 -----------------------------------------------
1514 @@ -13,4 +13,4 @@
1518 -16
1520 -----------------------------------------------
1521 M numbers (change 3 of 3)
1522 stage this change? [y/n/q] n
1523 EOF
1524 cmp -s $testroot/stdout.expected $testroot/stdout
1525 ret="$?"
1526 if [ "$ret" != "0" ]; then
1527 diff -u $testroot/stdout.expected $testroot/stdout
1528 test_done "$testroot" "$ret"
1529 return 1
1532 (cd $testroot/wt && got status > $testroot/stdout)
1533 echo "MM numbers" > $testroot/stdout.expected
1534 cmp -s $testroot/stdout.expected $testroot/stdout
1535 ret="$?"
1536 if [ "$ret" != "0" ]; then
1537 diff -u $testroot/stdout.expected $testroot/stdout
1538 test_done "$testroot" "$ret"
1539 return 1
1542 (cd $testroot/wt && got diff -s > $testroot/stdout)
1544 echo "diff $commit_id $testroot/wt (staged changes)" \
1545 > $testroot/stdout.expected
1546 echo -n 'blob - ' >> $testroot/stdout.expected
1547 got tree -r $testroot/repo -i -c $commit_id \
1548 | grep 'numbers$' | cut -d' ' -f 1 \
1549 >> $testroot/stdout.expected
1550 echo -n 'blob + ' >> $testroot/stdout.expected
1551 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1552 >> $testroot/stdout.expected
1553 echo "--- numbers" >> $testroot/stdout.expected
1554 echo "+++ numbers" >> $testroot/stdout.expected
1555 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1556 echo " 4" >> $testroot/stdout.expected
1557 echo " 5" >> $testroot/stdout.expected
1558 echo " 6" >> $testroot/stdout.expected
1559 echo "-7" >> $testroot/stdout.expected
1560 echo "+b" >> $testroot/stdout.expected
1561 echo " 8" >> $testroot/stdout.expected
1562 echo " 9" >> $testroot/stdout.expected
1563 echo " 10" >> $testroot/stdout.expected
1564 cmp -s $testroot/stdout.expected $testroot/stdout
1565 ret="$?"
1566 if [ "$ret" != "0" ]; then
1567 diff -u $testroot/stdout.expected $testroot/stdout
1568 test_done "$testroot" "$ret"
1569 return 1
1572 (cd $testroot/wt && got unstage >/dev/null)
1573 ret="$?"
1574 if [ "$ret" != "0" ]; then
1575 echo "got stage command failed unexpectedly" >&2
1576 test_done "$testroot" "1"
1577 return 1
1579 (cd $testroot/wt && got status > $testroot/stdout)
1580 echo "M numbers" > $testroot/stdout.expected
1581 cmp -s $testroot/stdout.expected $testroot/stdout
1582 ret="$?"
1583 if [ "$ret" != "0" ]; then
1584 diff -u $testroot/stdout.expected $testroot/stdout
1585 test_done "$testroot" "$ret"
1586 return 1
1589 # stage last hunk
1590 printf "n\nn\ny\n" > $testroot/patchscript
1591 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1592 numbers > $testroot/stdout)
1594 cat > $testroot/stdout.expected <<EOF
1595 -----------------------------------------------
1596 @@ -1,5 +1,5 @@
1603 -----------------------------------------------
1604 M numbers (change 1 of 3)
1605 stage this change? [y/n/q] n
1606 -----------------------------------------------
1607 @@ -4,7 +4,7 @@
1616 -----------------------------------------------
1617 M numbers (change 2 of 3)
1618 stage this change? [y/n/q] n
1619 -----------------------------------------------
1620 @@ -13,4 +13,4 @@
1624 -16
1626 -----------------------------------------------
1627 M numbers (change 3 of 3)
1628 stage this change? [y/n/q] y
1629 EOF
1630 cmp -s $testroot/stdout.expected $testroot/stdout
1631 ret="$?"
1632 if [ "$ret" != "0" ]; then
1633 diff -u $testroot/stdout.expected $testroot/stdout
1634 test_done "$testroot" "$ret"
1635 return 1
1638 (cd $testroot/wt && got status > $testroot/stdout)
1639 echo "MM numbers" > $testroot/stdout.expected
1640 cmp -s $testroot/stdout.expected $testroot/stdout
1641 ret="$?"
1642 if [ "$ret" != "0" ]; then
1643 diff -u $testroot/stdout.expected $testroot/stdout
1644 test_done "$testroot" "$ret"
1645 return 1
1648 (cd $testroot/wt && got diff -s > $testroot/stdout)
1650 echo "diff $commit_id $testroot/wt (staged changes)" \
1651 > $testroot/stdout.expected
1652 echo -n 'blob - ' >> $testroot/stdout.expected
1653 got tree -r $testroot/repo -i -c $commit_id \
1654 | grep 'numbers$' | cut -d' ' -f 1 \
1655 >> $testroot/stdout.expected
1656 echo -n 'blob + ' >> $testroot/stdout.expected
1657 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1658 >> $testroot/stdout.expected
1659 echo "--- numbers" >> $testroot/stdout.expected
1660 echo "+++ numbers" >> $testroot/stdout.expected
1661 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1662 echo " 13" >> $testroot/stdout.expected
1663 echo " 14" >> $testroot/stdout.expected
1664 echo " 15" >> $testroot/stdout.expected
1665 echo "-16" >> $testroot/stdout.expected
1666 echo "+c" >> $testroot/stdout.expected
1667 cmp -s $testroot/stdout.expected $testroot/stdout
1668 ret="$?"
1669 if [ "$ret" != "0" ]; then
1670 diff -u $testroot/stdout.expected $testroot/stdout
1672 test_done "$testroot" "$ret"
1675 function test_stage_patch_twice {
1676 local testroot=`test_init stage_patch_twice`
1678 jot 16 > $testroot/repo/numbers
1679 (cd $testroot/repo && git add numbers)
1680 git_commit $testroot/repo -m "added numbers file"
1681 local commit_id=`git_show_head $testroot/repo`
1683 got checkout $testroot/repo $testroot/wt > /dev/null
1684 ret="$?"
1685 if [ "$ret" != "0" ]; then
1686 test_done "$testroot" "$ret"
1687 return 1
1690 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1691 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1692 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1694 # stage middle hunk
1695 printf "n\ny\nn\n" > $testroot/patchscript
1696 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1697 numbers > $testroot/stdout)
1699 cat > $testroot/stdout.expected <<EOF
1700 -----------------------------------------------
1701 @@ -1,5 +1,5 @@
1708 -----------------------------------------------
1709 M numbers (change 1 of 3)
1710 stage this change? [y/n/q] n
1711 -----------------------------------------------
1712 @@ -4,7 +4,7 @@
1721 -----------------------------------------------
1722 M numbers (change 2 of 3)
1723 stage this change? [y/n/q] y
1724 -----------------------------------------------
1725 @@ -13,4 +13,4 @@
1729 -16
1731 -----------------------------------------------
1732 M numbers (change 3 of 3)
1733 stage this change? [y/n/q] n
1734 EOF
1735 cmp -s $testroot/stdout.expected $testroot/stdout
1736 ret="$?"
1737 if [ "$ret" != "0" ]; then
1738 diff -u $testroot/stdout.expected $testroot/stdout
1739 test_done "$testroot" "$ret"
1740 return 1
1743 (cd $testroot/wt && got status > $testroot/stdout)
1744 echo "MM numbers" > $testroot/stdout.expected
1745 cmp -s $testroot/stdout.expected $testroot/stdout
1746 ret="$?"
1747 if [ "$ret" != "0" ]; then
1748 diff -u $testroot/stdout.expected $testroot/stdout
1749 test_done "$testroot" "$ret"
1750 return 1
1753 # stage last hunk
1754 printf "n\ny\n" > $testroot/patchscript
1755 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1756 numbers > $testroot/stdout)
1758 cat > $testroot/stdout.expected <<EOF
1759 -----------------------------------------------
1760 @@ -1,5 +1,5 @@ b
1767 -----------------------------------------------
1768 M numbers (change 1 of 2)
1769 stage this change? [y/n/q] n
1770 -----------------------------------------------
1771 @@ -13,4 +13,4 @@ b
1775 -16
1777 -----------------------------------------------
1778 M numbers (change 2 of 2)
1779 stage this change? [y/n/q] y
1780 EOF
1781 cmp -s $testroot/stdout.expected $testroot/stdout
1782 ret="$?"
1783 if [ "$ret" != "0" ]; then
1784 diff -u $testroot/stdout.expected $testroot/stdout
1785 test_done "$testroot" "$ret"
1786 return 1
1789 (cd $testroot/wt && got status > $testroot/stdout)
1790 echo "MM numbers" > $testroot/stdout.expected
1791 cmp -s $testroot/stdout.expected $testroot/stdout
1792 ret="$?"
1793 if [ "$ret" != "0" ]; then
1794 diff -u $testroot/stdout.expected $testroot/stdout
1795 test_done "$testroot" "$ret"
1796 return 1
1799 (cd $testroot/wt && got diff -s > $testroot/stdout)
1801 echo "diff $commit_id $testroot/wt (staged changes)" \
1802 > $testroot/stdout.expected
1803 echo -n 'blob - ' >> $testroot/stdout.expected
1804 got tree -r $testroot/repo -i -c $commit_id \
1805 | grep 'numbers$' | cut -d' ' -f 1 \
1806 >> $testroot/stdout.expected
1807 echo -n 'blob + ' >> $testroot/stdout.expected
1808 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1809 >> $testroot/stdout.expected
1810 echo "--- numbers" >> $testroot/stdout.expected
1811 echo "+++ numbers" >> $testroot/stdout.expected
1812 cat >> $testroot/stdout.expected <<EOF
1813 @@ -4,7 +4,7 @@
1822 @@ -13,4 +13,4 @@
1826 -16
1828 EOF
1829 cmp -s $testroot/stdout.expected $testroot/stdout
1830 ret="$?"
1831 if [ "$ret" != "0" ]; then
1832 diff -u $testroot/stdout.expected $testroot/stdout
1833 test_done "$testroot" "$ret"
1834 return 1
1837 (cd $testroot/wt && got diff > $testroot/stdout)
1839 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1840 echo -n 'blob - ' >> $testroot/stdout.expected
1841 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1842 tr -d '\n' >> $testroot/stdout.expected
1843 echo " (staged)" >> $testroot/stdout.expected
1844 echo 'file + numbers' >> $testroot/stdout.expected
1845 echo "--- numbers" >> $testroot/stdout.expected
1846 echo "+++ numbers" >> $testroot/stdout.expected
1847 cat >> $testroot/stdout.expected <<EOF
1848 @@ -1,5 +1,5 @@
1855 EOF
1856 cmp -s $testroot/stdout.expected $testroot/stdout
1857 ret="$?"
1858 if [ "$ret" != "0" ]; then
1859 diff -u $testroot/stdout.expected $testroot/stdout
1861 test_done "$testroot" "$ret"
1864 function test_stage_patch_added {
1865 local testroot=`test_init stage_patch_added`
1866 local commit_id=`git_show_head $testroot/repo`
1868 got checkout $testroot/repo $testroot/wt > /dev/null
1869 ret="$?"
1870 if [ "$ret" != "0" ]; then
1871 test_done "$testroot" "$ret"
1872 return 1
1875 echo "new" > $testroot/wt/epsilon/new
1876 (cd $testroot/wt && got add epsilon/new > /dev/null)
1878 printf "y\n" > $testroot/patchscript
1879 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1880 epsilon/new > $testroot/stdout)
1882 echo "A epsilon/new" > $testroot/stdout.expected
1883 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1884 cmp -s $testroot/stdout.expected $testroot/stdout
1885 ret="$?"
1886 if [ "$ret" != "0" ]; then
1887 diff -u $testroot/stdout.expected $testroot/stdout
1888 test_done "$testroot" "$ret"
1889 return 1
1892 (cd $testroot/wt && got status > $testroot/stdout)
1893 echo " A epsilon/new" > $testroot/stdout.expected
1894 cmp -s $testroot/stdout.expected $testroot/stdout
1895 ret="$?"
1896 if [ "$ret" != "0" ]; then
1897 diff -u $testroot/stdout.expected $testroot/stdout
1898 test_done "$testroot" "$ret"
1899 return 1
1902 (cd $testroot/wt && got diff -s > $testroot/stdout)
1904 echo "diff $commit_id $testroot/wt (staged changes)" \
1905 > $testroot/stdout.expected
1906 echo 'blob - /dev/null' >> $testroot/stdout.expected
1907 echo -n 'blob + ' >> $testroot/stdout.expected
1908 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1909 >> $testroot/stdout.expected
1910 echo "--- /dev/null" >> $testroot/stdout.expected
1911 echo "+++ epsilon/new" >> $testroot/stdout.expected
1912 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1913 echo "+new" >> $testroot/stdout.expected
1914 cmp -s $testroot/stdout.expected $testroot/stdout
1915 ret="$?"
1916 if [ "$ret" != "0" ]; then
1917 diff -u $testroot/stdout.expected $testroot/stdout
1919 test_done "$testroot" "$ret"
1922 function test_stage_patch_added_twice {
1923 local testroot=`test_init stage_patch_added_twice`
1924 local commit_id=`git_show_head $testroot/repo`
1926 got checkout $testroot/repo $testroot/wt > /dev/null
1927 ret="$?"
1928 if [ "$ret" != "0" ]; then
1929 test_done "$testroot" "$ret"
1930 return 1
1933 echo "new" > $testroot/wt/epsilon/new
1934 (cd $testroot/wt && got add epsilon/new > /dev/null)
1936 printf "y\n" > $testroot/patchscript
1937 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1938 epsilon/new > $testroot/stdout)
1940 echo "A epsilon/new" > $testroot/stdout.expected
1941 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1942 cmp -s $testroot/stdout.expected $testroot/stdout
1943 ret="$?"
1944 if [ "$ret" != "0" ]; then
1945 diff -u $testroot/stdout.expected $testroot/stdout
1946 test_done "$testroot" "$ret"
1947 return 1
1950 (cd $testroot/wt && got status > $testroot/stdout)
1951 echo " A epsilon/new" > $testroot/stdout.expected
1952 cmp -s $testroot/stdout.expected $testroot/stdout
1953 ret="$?"
1954 if [ "$ret" != "0" ]; then
1955 diff -u $testroot/stdout.expected $testroot/stdout
1956 test_done "$testroot" "$ret"
1957 return 1
1960 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1961 epsilon/new > $testroot/stdout 2> $testroot/stderr)
1962 ret="$?"
1963 if [ "$ret" == "0" ]; then
1964 echo "got stage command succeeded unexpectedly" >&2
1965 test_done "$testroot" "1"
1966 return 1
1969 echo "got: epsilon/new: no changes to stage" > $testroot/stderr.expected
1970 cmp -s $testroot/stderr.expected $testroot/stderr
1971 ret="$?"
1972 if [ "$ret" != "0" ]; then
1973 diff -u $testroot/stderr.expected $testroot/stderr
1974 test_done "$testroot" "$ret"
1975 return 1
1978 echo -n > $testroot/stdout.expected
1979 cmp -s $testroot/stdout.expected $testroot/stdout
1980 ret="$?"
1981 if [ "$ret" != "0" ]; then
1982 diff -u $testroot/stdout.expected $testroot/stdout
1984 test_done "$testroot" "$ret"
1987 function test_stage_patch_removed {
1988 local testroot=`test_init stage_patch_removed`
1989 local commit_id=`git_show_head $testroot/repo`
1991 got checkout $testroot/repo $testroot/wt > /dev/null
1992 ret="$?"
1993 if [ "$ret" != "0" ]; then
1994 test_done "$testroot" "$ret"
1995 return 1
1998 (cd $testroot/wt && got rm beta > /dev/null)
2000 printf "y\n" > $testroot/patchscript
2001 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2002 beta > $testroot/stdout)
2004 echo -n > $testroot/stdout.expected
2006 echo "D beta" > $testroot/stdout.expected
2007 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2008 cmp -s $testroot/stdout.expected $testroot/stdout
2009 ret="$?"
2010 if [ "$ret" != "0" ]; then
2011 diff -u $testroot/stdout.expected $testroot/stdout
2012 test_done "$testroot" "$ret"
2013 return 1
2016 (cd $testroot/wt && got status > $testroot/stdout)
2017 echo " D beta" > $testroot/stdout.expected
2018 cmp -s $testroot/stdout.expected $testroot/stdout
2019 ret="$?"
2020 if [ "$ret" != "0" ]; then
2021 diff -u $testroot/stdout.expected $testroot/stdout
2022 test_done "$testroot" "$ret"
2023 return 1
2026 (cd $testroot/wt && got diff -s > $testroot/stdout)
2028 echo "diff $commit_id $testroot/wt (staged changes)" \
2029 > $testroot/stdout.expected
2030 echo -n 'blob - ' >> $testroot/stdout.expected
2031 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2032 >> $testroot/stdout.expected
2033 echo 'blob + /dev/null' >> $testroot/stdout.expected
2034 echo "--- beta" >> $testroot/stdout.expected
2035 echo "+++ /dev/null" >> $testroot/stdout.expected
2036 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2037 echo "-beta" >> $testroot/stdout.expected
2038 cmp -s $testroot/stdout.expected $testroot/stdout
2039 ret="$?"
2040 if [ "$ret" != "0" ]; then
2041 diff -u $testroot/stdout.expected $testroot/stdout
2043 test_done "$testroot" "$ret"
2046 function test_stage_patch_removed_twice {
2047 local testroot=`test_init stage_patch_removed_twice`
2048 local commit_id=`git_show_head $testroot/repo`
2050 got checkout $testroot/repo $testroot/wt > /dev/null
2051 ret="$?"
2052 if [ "$ret" != "0" ]; then
2053 test_done "$testroot" "$ret"
2054 return 1
2057 (cd $testroot/wt && got rm beta > /dev/null)
2059 printf "y\n" > $testroot/patchscript
2060 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2061 beta > $testroot/stdout)
2063 echo -n > $testroot/stdout.expected
2065 echo "D beta" > $testroot/stdout.expected
2066 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2067 cmp -s $testroot/stdout.expected $testroot/stdout
2068 ret="$?"
2069 if [ "$ret" != "0" ]; then
2070 diff -u $testroot/stdout.expected $testroot/stdout
2071 test_done "$testroot" "$ret"
2072 return 1
2075 (cd $testroot/wt && got status > $testroot/stdout)
2076 echo " D beta" > $testroot/stdout.expected
2077 cmp -s $testroot/stdout.expected $testroot/stdout
2078 ret="$?"
2079 if [ "$ret" != "0" ]; then
2080 diff -u $testroot/stdout.expected $testroot/stdout
2081 test_done "$testroot" "$ret"
2082 return 1
2085 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2086 > $testroot/stdout 2> $testroot/stderr)
2087 ret="$?"
2088 if [ "$ret" != "0" ]; then
2089 echo "got stage command failed unexpectedly" >&2
2090 test_done "$testroot" "$ret"
2091 return 1
2094 echo -n > $testroot/stderr.expected
2095 cmp -s $testroot/stderr.expected $testroot/stderr
2096 ret="$?"
2097 if [ "$ret" != "0" ]; then
2098 diff -u $testroot/stderr.expected $testroot/stderr
2099 test_done "$testroot" "$ret"
2100 return 1
2103 echo -n > $testroot/stdout.expected
2104 cmp -s $testroot/stdout.expected $testroot/stdout
2105 ret="$?"
2106 if [ "$ret" != "0" ]; then
2107 diff -u $testroot/stdout.expected $testroot/stdout
2109 test_done "$testroot" "$ret"
2112 function test_stage_patch_quit {
2113 local testroot=`test_init stage_patch_quit`
2115 jot 16 > $testroot/repo/numbers
2116 echo zzz > $testroot/repo/zzz
2117 (cd $testroot/repo && git add numbers zzz)
2118 git_commit $testroot/repo -m "added files"
2119 local commit_id=`git_show_head $testroot/repo`
2121 got checkout $testroot/repo $testroot/wt > /dev/null
2122 ret="$?"
2123 if [ "$ret" != "0" ]; then
2124 test_done "$testroot" "$ret"
2125 return 1
2128 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2129 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2130 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2131 (cd $testroot/wt && got rm zzz > /dev/null)
2133 # stage first hunk and quit; and don't pass a path argument to
2134 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2135 printf "y\nq\nn\n" > $testroot/patchscript
2136 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2137 > $testroot/stdout)
2138 ret="$?"
2139 if [ "$ret" != "0" ]; then
2140 echo "got stage command failed unexpectedly" >&2
2141 test_done "$testroot" "1"
2142 return 1
2144 cat > $testroot/stdout.expected <<EOF
2145 -----------------------------------------------
2146 @@ -1,5 +1,5 @@
2153 -----------------------------------------------
2154 M numbers (change 1 of 3)
2155 stage this change? [y/n/q] y
2156 -----------------------------------------------
2157 @@ -4,7 +4,7 @@
2166 -----------------------------------------------
2167 M numbers (change 2 of 3)
2168 stage this change? [y/n/q] q
2169 D zzz
2170 stage this deletion? [y/n] n
2171 EOF
2172 cmp -s $testroot/stdout.expected $testroot/stdout
2173 ret="$?"
2174 if [ "$ret" != "0" ]; then
2175 diff -u $testroot/stdout.expected $testroot/stdout
2176 test_done "$testroot" "$ret"
2177 return 1
2180 (cd $testroot/wt && got status > $testroot/stdout)
2181 echo "MM numbers" > $testroot/stdout.expected
2182 echo "D zzz" >> $testroot/stdout.expected
2183 cmp -s $testroot/stdout.expected $testroot/stdout
2184 ret="$?"
2185 if [ "$ret" != "0" ]; then
2186 diff -u $testroot/stdout.expected $testroot/stdout
2187 test_done "$testroot" "$ret"
2188 return 1
2191 (cd $testroot/wt && got diff -s > $testroot/stdout)
2193 echo "diff $commit_id $testroot/wt (staged changes)" \
2194 > $testroot/stdout.expected
2195 echo -n 'blob - ' >> $testroot/stdout.expected
2196 got tree -r $testroot/repo -i -c $commit_id \
2197 | grep 'numbers$' | cut -d' ' -f 1 \
2198 >> $testroot/stdout.expected
2199 echo -n 'blob + ' >> $testroot/stdout.expected
2200 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2201 >> $testroot/stdout.expected
2202 echo "--- numbers" >> $testroot/stdout.expected
2203 echo "+++ numbers" >> $testroot/stdout.expected
2204 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2205 echo " 1" >> $testroot/stdout.expected
2206 echo "-2" >> $testroot/stdout.expected
2207 echo "+a" >> $testroot/stdout.expected
2208 echo " 3" >> $testroot/stdout.expected
2209 echo " 4" >> $testroot/stdout.expected
2210 echo " 5" >> $testroot/stdout.expected
2211 cmp -s $testroot/stdout.expected $testroot/stdout
2212 ret="$?"
2213 if [ "$ret" != "0" ]; then
2214 diff -u $testroot/stdout.expected $testroot/stdout
2216 test_done "$testroot" "$ret"
2220 function test_stage_patch_incomplete_script {
2221 local testroot=`test_init stage_incomplete_script`
2223 jot 16 > $testroot/repo/numbers
2224 echo zzz > $testroot/repo/zzz
2225 (cd $testroot/repo && git add numbers zzz)
2226 git_commit $testroot/repo -m "added files"
2227 local commit_id=`git_show_head $testroot/repo`
2229 got checkout $testroot/repo $testroot/wt > /dev/null
2230 ret="$?"
2231 if [ "$ret" != "0" ]; then
2232 test_done "$testroot" "$ret"
2233 return 1
2236 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2237 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2238 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2240 # stage first hunk and then stop responding; got should error out
2241 printf "y\n" > $testroot/patchscript
2242 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2243 > $testroot/stdout 2> $testroot/stderr)
2244 ret="$?"
2245 if [ "$ret" == "0" ]; then
2246 echo "got stage command succeeded unexpectedly" >&2
2247 test_done "$testroot" "1"
2248 return 1
2250 cat > $testroot/stdout.expected <<EOF
2251 -----------------------------------------------
2252 @@ -1,5 +1,5 @@
2259 -----------------------------------------------
2260 M numbers (change 1 of 3)
2261 stage this change? [y/n/q] y
2262 -----------------------------------------------
2263 @@ -4,7 +4,7 @@
2272 -----------------------------------------------
2273 M numbers (change 2 of 3)
2274 EOF
2275 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2276 echo "got: invalid patch choice" > $testroot/stderr.expected
2277 cmp -s $testroot/stderr.expected $testroot/stderr
2278 ret="$?"
2279 if [ "$ret" != "0" ]; then
2280 diff -u $testroot/stderr.expected $testroot/stderr
2281 test_done "$testroot" "$ret"
2282 return 1
2285 cmp -s $testroot/stdout.expected $testroot/stdout
2286 ret="$?"
2287 if [ "$ret" != "0" ]; then
2288 diff -u $testroot/stdout.expected $testroot/stdout
2289 test_done "$testroot" "$ret"
2290 return 1
2293 (cd $testroot/wt && got status > $testroot/stdout)
2294 echo "M numbers" > $testroot/stdout.expected
2295 cmp -s $testroot/stdout.expected $testroot/stdout
2296 ret="$?"
2297 if [ "$ret" != "0" ]; then
2298 diff -u $testroot/stdout.expected $testroot/stdout
2299 test_done "$testroot" "$ret"
2300 return 1
2303 (cd $testroot/wt && got diff -s > $testroot/stdout)
2304 echo -n > $testroot/stdout.expected
2305 cmp -s $testroot/stdout.expected $testroot/stdout
2306 ret="$?"
2307 if [ "$ret" != "0" ]; then
2308 diff -u $testroot/stdout.expected $testroot/stdout
2310 test_done "$testroot" "$ret"
2314 run_test test_stage_basic
2315 run_test test_stage_no_changes
2316 run_test test_stage_unversioned
2317 run_test test_stage_nonexistent
2318 run_test test_stage_list
2319 run_test test_stage_conflict
2320 run_test test_stage_out_of_date
2321 run_test test_double_stage
2322 run_test test_stage_status
2323 run_test test_stage_add_already_staged_file
2324 run_test test_stage_rm_already_staged_file
2325 run_test test_stage_revert
2326 run_test test_stage_diff
2327 run_test test_stage_histedit
2328 run_test test_stage_rebase
2329 run_test test_stage_update
2330 run_test test_stage_commit_non_staged
2331 run_test test_stage_commit_out_of_date
2332 run_test test_stage_commit
2333 run_test test_stage_patch
2334 run_test test_stage_patch_twice
2335 run_test test_stage_patch_added
2336 run_test test_stage_patch_added_twice
2337 run_test test_stage_patch_removed
2338 run_test test_stage_patch_removed_twice
2339 run_test test_stage_patch_quit
2340 run_test test_stage_patch_incomplete_script