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_list {
148 local testroot=`test_init stage_list`
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 echo "modified file" > $testroot/wt/alpha
158 (cd $testroot/wt && got rm beta > /dev/null)
159 echo "new file" > $testroot/wt/foo
160 (cd $testroot/wt && got add foo > /dev/null)
162 echo ' M alpha' > $testroot/stdout.expected
163 echo ' D beta' >> $testroot/stdout.expected
164 echo ' A foo' >> $testroot/stdout.expected
165 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
167 (cd $testroot/wt && got stage -l > $testroot/stdout)
168 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
169 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
170 echo " M alpha" >> $testroot/stdout.expected
171 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
172 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
173 echo " D beta" >> $testroot/stdout.expected
174 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
175 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
176 echo " A foo" >> $testroot/stdout.expected
177 cmp -s $testroot/stdout.expected $testroot/stdout
178 ret="$?"
179 if [ "$ret" != "0" ]; then
180 diff -u $testroot/stdout.expected $testroot/stdout
181 test_done "$testroot" "$ret"
182 return 1
183 fi
185 (cd $testroot/wt && got stage -l epsilon nonexistent \
186 > $testroot/stdout)
188 echo -n > $testroot/stdout.expected
189 cmp -s $testroot/stdout.expected $testroot/stdout
190 ret="$?"
191 if [ "$ret" != "0" ]; then
192 diff -u $testroot/stdout.expected $testroot/stdout
193 test_done "$testroot" "$ret"
194 return 1
195 fi
197 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
199 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
200 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
201 echo " M alpha" >> $testroot/stdout.expected
202 cmp -s $testroot/stdout.expected $testroot/stdout
203 ret="$?"
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 fi
207 test_done "$testroot" "$ret"
211 function test_stage_conflict {
212 local testroot=`test_init stage_conflict`
213 local initial_commit=`git_show_head $testroot/repo`
215 got checkout $testroot/repo $testroot/wt > /dev/null
216 ret="$?"
217 if [ "$ret" != "0" ]; then
218 test_done "$testroot" "$ret"
219 return 1
220 fi
222 echo "modified alpha" > $testroot/wt/alpha
223 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
225 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
227 echo "modified alpha, too" > $testroot/wt/alpha
229 echo "C alpha" > $testroot/stdout.expected
230 echo -n "Updated to commit " >> $testroot/stdout.expected
231 git_show_head $testroot/repo >> $testroot/stdout.expected
232 echo >> $testroot/stdout.expected
234 (cd $testroot/wt && got update > $testroot/stdout)
236 cmp -s $testroot/stdout.expected $testroot/stdout
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 diff -u $testroot/stdout.expected $testroot/stdout
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 (cd $testroot/wt && got stage alpha > $testroot/stdout \
245 2> $testroot/stderr)
246 ret="$?"
247 if [ "$ret" == "0" ]; then
248 echo "got stage command succeeded unexpectedly" >&2
249 test_done "$testroot" "1"
250 return 1
251 fi
253 echo -n > $testroot/stdout.expected
254 echo "got: alpha: cannot stage file in conflicted status" \
255 > $testroot/stderr.expected
257 cmp -s $testroot/stdout.expected $testroot/stdout
258 ret="$?"
259 if [ "$ret" != "0" ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 test_done "$testroot" "$ret"
262 return 1
263 fi
264 cmp -s $testroot/stderr.expected $testroot/stderr
265 ret="$?"
266 if [ "$ret" != "0" ]; then
267 diff -u $testroot/stderr.expected $testroot/stderr
268 fi
269 test_done "$testroot" "$ret"
272 function test_stage_out_of_date {
273 local testroot=`test_init stage_out_of_date`
274 local initial_commit=`git_show_head $testroot/repo`
276 got checkout $testroot/repo $testroot/wt > /dev/null
277 ret="$?"
278 if [ "$ret" != "0" ]; then
279 test_done "$testroot" "$ret"
280 return 1
281 fi
283 echo "modified alpha" > $testroot/wt/alpha
284 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
286 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
288 echo "modified alpha again" > $testroot/wt/alpha
289 (cd $testroot/wt && got stage alpha > $testroot/stdout \
290 2> $testroot/stderr)
291 ret="$?"
292 if [ "$ret" == "0" ]; then
293 echo "got stage command succeeded unexpectedly" >&2
294 test_done "$testroot" "1"
295 return 1
296 fi
298 echo -n > $testroot/stdout.expected
299 echo "got: work tree must be updated before changes can be staged" \
300 > $testroot/stderr.expected
302 cmp -s $testroot/stdout.expected $testroot/stdout
303 ret="$?"
304 if [ "$ret" != "0" ]; then
305 diff -u $testroot/stdout.expected $testroot/stdout
306 test_done "$testroot" "$ret"
307 return 1
308 fi
309 cmp -s $testroot/stderr.expected $testroot/stderr
310 ret="$?"
311 if [ "$ret" != "0" ]; then
312 diff -u $testroot/stderr.expected $testroot/stderr
313 fi
314 test_done "$testroot" "$ret"
318 function test_double_stage {
319 local testroot=`test_init double_stage`
321 got checkout $testroot/repo $testroot/wt > /dev/null
322 ret="$?"
323 if [ "$ret" != "0" ]; then
324 test_done "$testroot" "$ret"
325 return 1
326 fi
327 echo "modified file" > $testroot/wt/alpha
328 (cd $testroot/wt && got rm beta > /dev/null)
329 echo "new file" > $testroot/wt/foo
330 (cd $testroot/wt && got add foo > /dev/null)
331 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
333 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
334 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
335 cmp -s $testroot/stderr.expected $testroot/stderr
336 ret="$?"
337 if [ "$ret" != "0" ]; then
338 diff -u $testroot/stderr.expected $testroot/stderr
339 test_done "$testroot" "$ret"
340 return 1
341 fi
343 (cd $testroot/wt && got stage beta > $testroot/stdout)
344 ret="$?"
345 if [ "$ret" != "0" ]; then
346 echo "got stage command failed unexpectedly" >&2
347 test_done "$testroot" "1"
348 return 1
349 fi
350 echo -n > $testroot/stdout.expected
351 cmp -s $testroot/stdout.expected $testroot/stdout
352 ret="$?"
353 if [ "$ret" != "0" ]; then
354 diff -u $testroot/stdout.expected $testroot/stdout
355 test_done "$testroot" "$ret"
356 return 1
357 fi
359 echo "got: foo: no changes to stage" > $testroot/stderr.expected
360 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
361 cmp -s $testroot/stderr.expected $testroot/stderr
362 ret="$?"
363 if [ "$ret" != "0" ]; then
364 diff -u $testroot/stderr.expected $testroot/stderr
365 test_done "$testroot" "$ret"
366 return 1
367 fi
369 echo "modified file again" > $testroot/wt/alpha
370 echo "modified new file" > $testroot/wt/foo
372 echo ' M alpha' > $testroot/stdout.expected
373 echo ' A foo' >> $testroot/stdout.expected
374 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
375 cmp -s $testroot/stdout.expected $testroot/stdout
376 ret="$?"
377 if [ "$ret" != "0" ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 test_done "$testroot" "$ret"
380 return 1
381 fi
383 echo ' M alpha' > $testroot/stdout.expected
384 echo ' D beta' >> $testroot/stdout.expected
385 echo ' A foo' >> $testroot/stdout.expected
387 (cd $testroot/wt && got status > $testroot/stdout)
388 cmp -s $testroot/stdout.expected $testroot/stdout
389 ret="$?"
390 if [ "$ret" != "0" ]; then
391 diff -u $testroot/stdout.expected $testroot/stdout
392 fi
393 test_done "$testroot" "$ret"
396 function test_stage_status {
397 local testroot=`test_init stage_status`
399 got checkout $testroot/repo $testroot/wt > /dev/null
400 ret="$?"
401 if [ "$ret" != "0" ]; then
402 test_done "$testroot" "$ret"
403 return 1
404 fi
406 echo "modified file" > $testroot/wt/alpha
407 (cd $testroot/wt && got rm beta > /dev/null)
408 echo "new file" > $testroot/wt/foo
409 (cd $testroot/wt && got add foo > /dev/null)
410 echo "new file" > $testroot/wt/epsilon/new
411 (cd $testroot/wt && got add epsilon/new > /dev/null)
412 echo "modified file" > $testroot/wt/epsilon/zeta
413 (cd $testroot/wt && got rm gamma/delta > /dev/null)
415 echo ' M alpha' > $testroot/stdout.expected
416 echo ' D beta' >> $testroot/stdout.expected
417 echo 'A epsilon/new' >> $testroot/stdout.expected
418 echo 'M epsilon/zeta' >> $testroot/stdout.expected
419 echo ' A foo' >> $testroot/stdout.expected
420 echo 'D gamma/delta' >> $testroot/stdout.expected
421 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
423 (cd $testroot/wt && got status > $testroot/stdout)
424 cmp -s $testroot/stdout.expected $testroot/stdout
425 ret="$?"
426 if [ "$ret" != "0" ]; then
427 diff -u $testroot/stdout.expected $testroot/stdout
428 test_done "$testroot" "$ret"
429 return 1
430 fi
432 echo "modified file again" >> $testroot/wt/alpha
433 echo "modified added file again" >> $testroot/wt/foo
435 echo 'MM alpha' > $testroot/stdout.expected
436 echo ' D beta' >> $testroot/stdout.expected
437 echo 'A epsilon/new' >> $testroot/stdout.expected
438 echo 'M epsilon/zeta' >> $testroot/stdout.expected
439 echo 'MA foo' >> $testroot/stdout.expected
440 echo 'D gamma/delta' >> $testroot/stdout.expected
442 (cd $testroot/wt && got status > $testroot/stdout)
443 cmp -s $testroot/stdout.expected $testroot/stdout
444 ret="$?"
445 if [ "$ret" != "0" ]; then
446 diff -u $testroot/stdout.expected $testroot/stdout
447 test_done "$testroot" "$ret"
448 return 1
449 fi
451 # test no-op change of added file with new stat(2) timestamp
452 echo "new file" > $testroot/wt/foo
453 echo ' A foo' > $testroot/stdout.expected
454 (cd $testroot/wt && got status foo > $testroot/stdout)
455 cmp -s $testroot/stdout.expected $testroot/stdout
456 ret="$?"
457 if [ "$ret" != "0" ]; then
458 diff -u $testroot/stdout.expected $testroot/stdout
459 test_done "$testroot" "$ret"
460 return 1
461 fi
463 # test staged deleted file which is restored on disk
464 echo "new file" > $testroot/wt/beta
465 echo ' D beta' > $testroot/stdout.expected
466 (cd $testroot/wt && got status beta > $testroot/stdout)
467 cmp -s $testroot/stdout.expected $testroot/stdout
468 ret="$?"
469 if [ "$ret" != "0" ]; then
470 diff -u $testroot/stdout.expected $testroot/stdout
471 fi
472 test_done "$testroot" "$ret"
476 function test_stage_add_already_staged_file {
477 local testroot=`test_init stage_add_already_staged_file`
479 got checkout $testroot/repo $testroot/wt > /dev/null
480 ret="$?"
481 if [ "$ret" != "0" ]; then
482 test_done "$testroot" "$ret"
483 return 1
484 fi
486 echo "modified file" > $testroot/wt/alpha
487 (cd $testroot/wt && got rm beta > /dev/null)
488 echo "new file" > $testroot/wt/foo
489 (cd $testroot/wt && got add foo > /dev/null)
491 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
493 echo -n > $testroot/stdout.expected
494 for f in alpha beta foo; do
495 (cd $testroot/wt && got add $f \
496 > $testroot/stdout 2> $testroot/stderr)
497 echo "got: $f: file has unexpected status" \
498 > $testroot/stderr.expected
499 cmp -s $testroot/stderr.expected $testroot/stderr
500 ret="$?"
501 if [ "$ret" != "0" ]; then
502 diff -u $testroot/stderr.expected $testroot/stderr
503 test_done "$testroot" "$ret"
504 return 1
505 fi
506 cmp -s $testroot/stdout.expected $testroot/stdout
507 ret="$?"
508 if [ "$ret" != "0" ]; then
509 diff -u $testroot/stdout.expected $testroot/stdout
510 test_done "$testroot" "$ret"
511 return 1
512 fi
513 done
515 echo ' M alpha' > $testroot/stdout.expected
516 echo ' D beta' >> $testroot/stdout.expected
517 echo ' A foo' >> $testroot/stdout.expected
519 (cd $testroot/wt && got status > $testroot/stdout)
520 cmp -s $testroot/stdout.expected $testroot/stdout
521 ret="$?"
522 if [ "$ret" != "0" ]; then
523 diff -u $testroot/stdout.expected $testroot/stdout
524 fi
525 test_done "$testroot" "$ret"
528 function test_stage_rm_already_staged_file {
529 local testroot=`test_init stage_rm_already_staged_file`
531 got checkout $testroot/repo $testroot/wt > /dev/null
532 ret="$?"
533 if [ "$ret" != "0" ]; then
534 test_done "$testroot" "$ret"
535 return 1
536 fi
538 echo "modified file" > $testroot/wt/alpha
539 (cd $testroot/wt && got rm beta > /dev/null)
540 echo "new file" > $testroot/wt/foo
541 (cd $testroot/wt && got add foo > /dev/null)
543 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
545 (cd $testroot/wt && got rm beta \
546 > $testroot/stdout 2> $testroot/stderr)
547 ret="$?"
548 if [ "$ret" != "0" ]; then
549 echo "got rm command failed unexpectedly" >&2
550 test_done "$testroot" "1"
551 return 1
552 fi
553 echo -n > $testroot/stdout.expected
554 cmp -s $testroot/stdout.expected $testroot/stdout
555 ret="$?"
556 if [ "$ret" != "0" ]; then
557 diff -u $testroot/stdout.expected $testroot/stdout
558 test_done "$testroot" "$ret"
559 return 1
560 fi
561 echo -n > $testroot/stderr.expected
562 cmp -s $testroot/stderr.expected $testroot/stderr
563 ret="$?"
564 if [ "$ret" != "0" ]; then
565 diff -u $testroot/stderr.expected $testroot/stderr
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 for f in alpha foo; do
571 echo "got: $f: file is staged" > $testroot/stderr.expected
572 (cd $testroot/wt && got rm $f \
573 > $testroot/stdout 2> $testroot/stderr)
574 ret="$?"
575 if [ "$ret" == "0" ]; then
576 echo "got rm command succeeded unexpectedly" >&2
577 test_done "$testroot" "1"
578 return 1
579 fi
580 cmp -s $testroot/stderr.expected $testroot/stderr
581 ret="$?"
582 if [ "$ret" != "0" ]; then
583 diff -u $testroot/stderr.expected $testroot/stderr
584 test_done "$testroot" "$ret"
585 return 1
586 fi
587 done
589 echo ' M alpha' > $testroot/stdout.expected
590 echo ' D beta' >> $testroot/stdout.expected
591 echo ' A foo' >> $testroot/stdout.expected
593 (cd $testroot/wt && got status > $testroot/stdout)
594 cmp -s $testroot/stdout.expected $testroot/stdout
595 ret="$?"
596 if [ "$ret" != "0" ]; then
597 diff -u $testroot/stdout.expected $testroot/stdout
598 fi
599 test_done "$testroot" "$ret"
602 function test_stage_revert {
603 local testroot=`test_init stage_revert`
605 got checkout $testroot/repo $testroot/wt > /dev/null
606 ret="$?"
607 if [ "$ret" != "0" ]; then
608 test_done "$testroot" "$ret"
609 return 1
610 fi
612 echo "modified alpha" > $testroot/wt/alpha
613 (cd $testroot/wt && got rm beta > /dev/null)
614 echo "new file" > $testroot/wt/foo
615 (cd $testroot/wt && got add foo > /dev/null)
616 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
618 echo "modified file again" >> $testroot/wt/alpha
619 echo "modified added file again" >> $testroot/wt/foo
621 (cd $testroot/wt && got revert alpha > $testroot/stdout)
622 ret="$?"
623 if [ "$ret" != "0" ]; then
624 echo "revert command failed unexpectedly" >&2
625 test_done "$testroot" "$ret"
626 return 1
627 fi
629 echo "R alpha" > $testroot/stdout.expected
630 cmp -s $testroot/stdout.expected $testroot/stdout
631 ret="$?"
632 if [ "$ret" != "0" ]; then
633 diff -u $testroot/stdout.expected $testroot/stdout
634 test_done "$testroot" "$ret"
635 return 1
636 fi
638 echo "modified alpha" > $testroot/content.expected
639 cat $testroot/wt/alpha > $testroot/content
640 cmp -s $testroot/content.expected $testroot/content
641 ret="$?"
642 if [ "$ret" != "0" ]; then
643 diff -u $testroot/content.expected $testroot/content
644 test_done "$testroot" "$ret"
645 return 1
646 fi
648 echo ' M alpha' > $testroot/stdout.expected
649 echo ' D beta' >> $testroot/stdout.expected
650 echo 'MA foo' >> $testroot/stdout.expected
651 (cd $testroot/wt && got status > $testroot/stdout)
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 (cd $testroot/wt && got revert alpha > $testroot/stdout)
661 ret="$?"
662 if [ "$ret" != "0" ]; then
663 echo "revert command failed unexpectedly" >&2
664 test_done "$testroot" "$ret"
665 return 1
666 fi
668 echo -n > $testroot/stdout.expected
669 cmp -s $testroot/stdout.expected $testroot/stdout
670 ret="$?"
671 if [ "$ret" != "0" ]; then
672 diff -u $testroot/stdout.expected $testroot/stdout
673 test_done "$testroot" "$ret"
674 return 1
675 fi
677 echo "modified alpha" > $testroot/content.expected
678 cat $testroot/wt/alpha > $testroot/content
679 cmp -s $testroot/content.expected $testroot/content
680 ret="$?"
681 if [ "$ret" != "0" ]; then
682 diff -u $testroot/content.expected $testroot/content
683 test_done "$testroot" "$ret"
684 return 1
685 fi
687 (cd $testroot/wt && got revert beta > $testroot/stdout \
688 2> $testroot/stderr)
689 ret="$?"
690 if [ "$ret" == "0" ]; then
691 echo "revert command succeeded unexpectedly" >&2
692 test_done "$testroot" "1"
693 return 1
694 fi
696 echo "got: beta: file is staged" > $testroot/stderr.expected
697 cmp -s $testroot/stderr.expected $testroot/stderr
698 ret="$?"
699 if [ "$ret" != "0" ]; then
700 diff -u $testroot/stderr.expected $testroot/stderr
701 test_done "$testroot" "$ret"
702 return 1
703 fi
705 (cd $testroot/wt && got revert foo > $testroot/stdout)
706 ret="$?"
707 if [ "$ret" != "0" ]; then
708 echo "revert command failed unexpectedly" >&2
709 test_done "$testroot" "$ret"
710 return 1
711 fi
713 echo "R foo" > $testroot/stdout.expected
714 cmp -s $testroot/stdout.expected $testroot/stdout
715 ret="$?"
716 if [ "$ret" != "0" ]; then
717 diff -u $testroot/stdout.expected $testroot/stdout
718 test_done "$testroot" "$ret"
719 return 1
720 fi
722 echo "new file" > $testroot/content.expected
723 cat $testroot/wt/foo > $testroot/content
724 cmp -s $testroot/content.expected $testroot/content
725 ret="$?"
726 if [ "$ret" != "0" ]; then
727 diff -u $testroot/content.expected $testroot/content
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 echo ' M alpha' > $testroot/stdout.expected
733 echo ' D beta' >> $testroot/stdout.expected
734 echo ' A foo' >> $testroot/stdout.expected
735 (cd $testroot/wt && got status > $testroot/stdout)
736 cmp -s $testroot/stdout.expected $testroot/stdout
737 ret="$?"
738 if [ "$ret" != "0" ]; then
739 diff -u $testroot/stdout.expected $testroot/stdout
740 test_done "$testroot" "$ret"
741 return 1
742 fi
744 (cd $testroot/wt && got revert foo > $testroot/stdout)
745 ret="$?"
746 if [ "$ret" != "0" ]; then
747 echo "revert command failed unexpectedly" >&2
748 test_done "$testroot" "$ret"
749 return 1
750 fi
752 echo -n > $testroot/stdout.expected
753 cmp -s $testroot/stdout.expected $testroot/stdout
754 ret="$?"
755 if [ "$ret" != "0" ]; then
756 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
758 return 1
759 fi
761 echo "new file" > $testroot/content.expected
762 cat $testroot/wt/foo > $testroot/content
763 cmp -s $testroot/content.expected $testroot/content
764 ret="$?"
765 if [ "$ret" != "0" ]; then
766 diff -u $testroot/content.expected $testroot/content
767 test_done "$testroot" "$ret"
768 return 1
769 fi
771 echo ' M alpha' > $testroot/stdout.expected
772 echo ' D beta' >> $testroot/stdout.expected
773 echo ' A foo' >> $testroot/stdout.expected
774 (cd $testroot/wt && got status > $testroot/stdout)
775 cmp -s $testroot/stdout.expected $testroot/stdout
776 ret="$?"
777 if [ "$ret" != "0" ]; then
778 diff -u $testroot/stdout.expected $testroot/stdout
779 fi
780 test_done "$testroot" "$ret"
783 function test_stage_diff {
784 local testroot=`test_init stage_diff`
785 local head_commit=`git_show_head $testroot/repo`
787 got checkout $testroot/repo $testroot/wt > /dev/null
788 ret="$?"
789 if [ "$ret" != "0" ]; then
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 echo "modified file" > $testroot/wt/alpha
795 (cd $testroot/wt && got rm beta > /dev/null)
796 echo "new file" > $testroot/wt/foo
797 (cd $testroot/wt && got add foo > /dev/null)
799 (cd $testroot/wt && got diff -s > $testroot/stdout)
800 echo -n > $testroot/stdout.expected
801 cmp -s $testroot/stdout.expected $testroot/stdout
802 ret="$?"
803 if [ "$ret" != "0" ]; then
804 diff -u $testroot/stdout.expected $testroot/stdout
805 test_done "$testroot" "$ret"
806 return 1
807 fi
809 echo ' M alpha' > $testroot/stdout.expected
810 echo ' D beta' >> $testroot/stdout.expected
811 echo ' A foo' >> $testroot/stdout.expected
812 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
814 (cd $testroot/wt && got diff > $testroot/stdout)
815 echo -n > $testroot/stdout.expected
816 cmp -s $testroot/stdout.expected $testroot/stdout
817 ret="$?"
818 if [ "$ret" != "0" ]; then
819 diff -u $testroot/stdout.expected $testroot/stdout
820 test_done "$testroot" "$ret"
821 return 1
822 fi
824 echo "modified file again" > $testroot/wt/alpha
825 echo "new file changed" > $testroot/wt/foo
827 (cd $testroot/wt && got diff > $testroot/stdout)
829 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
830 echo -n 'blob - ' >> $testroot/stdout.expected
831 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
832 >> $testroot/stdout.expected
833 echo ' (staged)' >> $testroot/stdout.expected
834 echo 'file + alpha' >> $testroot/stdout.expected
835 echo '--- alpha' >> $testroot/stdout.expected
836 echo '+++ alpha' >> $testroot/stdout.expected
837 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
838 echo '-modified file' >> $testroot/stdout.expected
839 echo '+modified file again' >> $testroot/stdout.expected
840 echo -n 'blob - ' >> $testroot/stdout.expected
841 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
842 >> $testroot/stdout.expected
843 echo " (staged)" >> $testroot/stdout.expected
844 echo 'file + foo' >> $testroot/stdout.expected
845 echo '--- foo' >> $testroot/stdout.expected
846 echo '+++ foo' >> $testroot/stdout.expected
847 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
848 echo '-new file' >> $testroot/stdout.expected
849 echo '+new file changed' >> $testroot/stdout.expected
851 cmp -s $testroot/stdout.expected $testroot/stdout
852 ret="$?"
853 if [ "$ret" != "0" ]; then
854 diff -u $testroot/stdout.expected $testroot/stdout
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 (cd $testroot/wt && got diff -s > $testroot/stdout)
861 echo "diff $head_commit $testroot/wt (staged changes)" \
862 > $testroot/stdout.expected
863 echo -n 'blob - ' >> $testroot/stdout.expected
864 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
865 >> $testroot/stdout.expected
866 echo -n 'blob + ' >> $testroot/stdout.expected
867 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
868 >> $testroot/stdout.expected
869 echo '--- alpha' >> $testroot/stdout.expected
870 echo '+++ alpha' >> $testroot/stdout.expected
871 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
872 echo '-alpha' >> $testroot/stdout.expected
873 echo '+modified file' >> $testroot/stdout.expected
874 echo -n 'blob - ' >> $testroot/stdout.expected
875 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
876 >> $testroot/stdout.expected
877 echo 'blob + /dev/null' >> $testroot/stdout.expected
878 echo '--- beta' >> $testroot/stdout.expected
879 echo '+++ /dev/null' >> $testroot/stdout.expected
880 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
881 echo '-beta' >> $testroot/stdout.expected
882 echo 'blob - /dev/null' >> $testroot/stdout.expected
883 echo -n 'blob + ' >> $testroot/stdout.expected
884 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
885 >> $testroot/stdout.expected
886 echo '--- /dev/null' >> $testroot/stdout.expected
887 echo '+++ foo' >> $testroot/stdout.expected
888 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
889 echo '+new file' >> $testroot/stdout.expected
891 cmp -s $testroot/stdout.expected $testroot/stdout
892 ret="$?"
893 if [ "$ret" != "0" ]; then
894 diff -u $testroot/stdout.expected $testroot/stdout
895 fi
896 test_done "$testroot" "$ret"
900 function test_stage_histedit {
901 local testroot=`test_init stage_histedit`
902 local orig_commit=`git_show_head $testroot/repo`
904 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
905 ret="$?"
906 if [ "$ret" != "0" ]; then
907 test_done "$testroot" "$ret"
908 return 1
909 fi
911 echo "modified file" > $testroot/wt/alpha
912 (cd $testroot/wt && got stage alpha > /dev/null)
914 echo "modified alpha on master" > $testroot/repo/alpha
915 (cd $testroot/repo && git rm -q beta)
916 echo "new file on master" > $testroot/repo/epsilon/new
917 (cd $testroot/repo && git add epsilon/new)
918 git_commit $testroot/repo -m "committing changes"
919 local old_commit1=`git_show_head $testroot/repo`
921 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
922 git_commit $testroot/repo -m "committing to zeta on master"
923 local old_commit2=`git_show_head $testroot/repo`
925 echo "pick $old_commit1" > $testroot/histedit-script
926 echo "pick $old_commit2" >> $testroot/histedit-script
928 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
929 > $testroot/stdout 2> $testroot/stderr)
930 ret="$?"
931 if [ "$ret" == "0" ]; then
932 echo "got histedit command succeeded unexpectedly" >&2
933 test_done "$testroot" "1"
934 return 1
935 fi
937 echo -n > $testroot/stdout.expected
938 echo "got: alpha: file is staged" > $testroot/stderr.expected
940 cmp -s $testroot/stderr.expected $testroot/stderr
941 ret="$?"
942 if [ "$ret" != "0" ]; then
943 diff -u $testroot/stderr.expected $testroot/stderr
944 test_done "$testroot" "$ret"
945 return 1
946 fi
947 cmp -s $testroot/stdout.expected $testroot/stdout
948 ret="$?"
949 if [ "$ret" != "0" ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
951 fi
952 test_done "$testroot" "$ret"
956 function test_stage_rebase {
957 local testroot=`test_init stage_rebase`
959 (cd $testroot/repo && git checkout -q -b newbranch)
960 echo "modified delta on branch" > $testroot/repo/gamma/delta
961 git_commit $testroot/repo -m "committing to delta on newbranch"
963 echo "modified alpha on branch" > $testroot/repo/alpha
964 (cd $testroot/repo && git rm -q beta)
965 echo "new file on branch" > $testroot/repo/epsilon/new
966 (cd $testroot/repo && git add epsilon/new)
967 git_commit $testroot/repo -m "committing more changes on newbranch"
969 local orig_commit1=`git_show_parent_commit $testroot/repo`
970 local orig_commit2=`git_show_head $testroot/repo`
972 (cd $testroot/repo && git checkout -q master)
973 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
974 git_commit $testroot/repo -m "committing to zeta on master"
975 local master_commit=`git_show_head $testroot/repo`
977 got checkout $testroot/repo $testroot/wt > /dev/null
978 ret="$?"
979 if [ "$ret" != "0" ]; then
980 test_done "$testroot" "$ret"
981 return 1
982 fi
984 echo "modified file" > $testroot/wt/alpha
985 (cd $testroot/wt && got stage alpha > /dev/null)
987 (cd $testroot/wt && got rebase newbranch \
988 > $testroot/stdout 2> $testroot/stderr)
989 ret="$?"
990 if [ "$ret" == "0" ]; then
991 echo "got rebase command succeeded unexpectedly" >&2
992 test_done "$testroot" "1"
993 return 1
994 fi
996 echo -n > $testroot/stdout.expected
997 echo "got: alpha: file is staged" > $testroot/stderr.expected
999 cmp -s $testroot/stderr.expected $testroot/stderr
1000 ret="$?"
1001 if [ "$ret" != "0" ]; then
1002 diff -u $testroot/stderr.expected $testroot/stderr
1003 test_done "$testroot" "$ret"
1004 return 1
1006 cmp -s $testroot/stdout.expected $testroot/stdout
1007 ret="$?"
1008 if [ "$ret" != "0" ]; then
1009 diff -u $testroot/stdout.expected $testroot/stdout
1011 test_done "$testroot" "$ret"
1014 function test_stage_update {
1015 local testroot=`test_init stage_update`
1017 got checkout $testroot/repo $testroot/wt > /dev/null
1018 ret="$?"
1019 if [ "$ret" != "0" ]; then
1020 test_done "$testroot" "$ret"
1021 return 1
1024 echo "modified file" > $testroot/wt/alpha
1025 (cd $testroot/wt && got stage alpha > /dev/null)
1027 echo "modified alpha" > $testroot/repo/alpha
1028 git_commit $testroot/repo -m "modified alpha"
1030 (cd $testroot/wt && got update > $testroot/stdout \
1031 2> $testroot/stderr)
1032 ret="$?"
1033 if [ "$ret" == "0" ]; then
1034 echo "got update command succeeded unexpectedly" >&2
1035 test_done "$testroot" "1"
1036 return 1
1039 echo -n > $testroot/stdout.expected
1040 echo "got: alpha: file is staged" > $testroot/stderr.expected
1042 cmp -s $testroot/stderr.expected $testroot/stderr
1043 ret="$?"
1044 if [ "$ret" != "0" ]; then
1045 diff -u $testroot/stderr.expected $testroot/stderr
1046 test_done "$testroot" "$ret"
1047 return 1
1049 cmp -s $testroot/stdout.expected $testroot/stdout
1050 ret="$?"
1051 if [ "$ret" != "0" ]; then
1052 diff -u $testroot/stdout.expected $testroot/stdout
1054 test_done "$testroot" "$ret"
1057 function test_stage_commit_non_staged {
1058 local testroot=`test_init stage_commit_non_staged`
1060 got checkout $testroot/repo $testroot/wt > /dev/null
1061 ret="$?"
1062 if [ "$ret" != "0" ]; then
1063 test_done "$testroot" "$ret"
1064 return 1
1067 echo "modified file" > $testroot/wt/alpha
1068 (cd $testroot/wt && got rm beta > /dev/null)
1069 echo "new file" > $testroot/wt/foo
1070 (cd $testroot/wt && got add foo > /dev/null)
1071 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1073 echo "modified file" > $testroot/wt/gamma/delta
1074 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1075 > $testroot/stdout 2> $testroot/stderr)
1076 ret="$?"
1077 if [ "$ret" == "0" ]; then
1078 echo "got commit command succeeded unexpectedly" >&2
1079 test_done "$testroot" "1"
1080 return 1
1083 echo -n > $testroot/stdout.expected
1084 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1086 cmp -s $testroot/stderr.expected $testroot/stderr
1087 ret="$?"
1088 if [ "$ret" != "0" ]; then
1089 diff -u $testroot/stderr.expected $testroot/stderr
1090 test_done "$testroot" "$ret"
1091 return 1
1093 cmp -s $testroot/stdout.expected $testroot/stdout
1094 ret="$?"
1095 if [ "$ret" != "0" ]; then
1096 diff -u $testroot/stdout.expected $testroot/stdout
1098 test_done "$testroot" "$ret"
1101 function test_stage_commit {
1102 local testroot=`test_init stage_commit`
1103 local first_commit=`git_show_head $testroot/repo`
1105 got checkout $testroot/repo $testroot/wt > /dev/null
1106 ret="$?"
1107 if [ "$ret" != "0" ]; then
1108 test_done "$testroot" "$ret"
1109 return 1
1112 echo "modified file" > $testroot/wt/alpha
1113 (cd $testroot/wt && got rm beta > /dev/null)
1114 echo "new file" > $testroot/wt/foo
1115 (cd $testroot/wt && got add foo > /dev/null)
1116 echo "modified file" > $testroot/wt/alpha
1117 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1119 echo "modified file again" > $testroot/wt/alpha
1120 echo "new file changed" > $testroot/wt/foo
1121 echo "non-staged change" > $testroot/wt/gamma/delta
1122 echo "non-staged new file" > $testroot/wt/epsilon/new
1123 (cd $testroot/wt && got add epsilon/new > /dev/null)
1124 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1126 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1127 > $testroot/blob_id_alpha
1128 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1129 > $testroot/blob_id_foo
1131 (cd $testroot/wt && got commit -m "staged changes" \
1132 > $testroot/stdout)
1133 ret="$?"
1134 if [ "$ret" != "0" ]; then
1135 echo "got commit command failed unexpectedly" >&2
1136 test_done "$testroot" "1"
1137 return 1
1140 local head_commit=`git_show_head $testroot/repo`
1141 echo "A foo" > $testroot/stdout.expected
1142 echo "M alpha" >> $testroot/stdout.expected
1143 echo "D beta" >> $testroot/stdout.expected
1144 echo "Created commit $head_commit" >> $testroot/stdout.expected
1146 cmp -s $testroot/stdout.expected $testroot/stdout
1147 ret="$?"
1148 if [ "$ret" != "0" ]; then
1149 diff -u $testroot/stdout.expected $testroot/stdout
1150 test_done "$testroot" "$ret"
1151 return 1
1154 got diff -r $testroot/repo $first_commit $head_commit \
1155 > $testroot/stdout
1157 echo "diff $first_commit $head_commit" \
1158 > $testroot/stdout.expected
1159 echo -n 'blob - ' >> $testroot/stdout.expected
1160 got tree -r $testroot/repo -i -c $first_commit | \
1161 grep 'alpha$' | cut -d' ' -f 1 \
1162 >> $testroot/stdout.expected
1163 echo -n 'blob + ' >> $testroot/stdout.expected
1164 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1165 echo '--- alpha' >> $testroot/stdout.expected
1166 echo '+++ alpha' >> $testroot/stdout.expected
1167 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1168 echo '-alpha' >> $testroot/stdout.expected
1169 echo '+modified file' >> $testroot/stdout.expected
1170 echo -n 'blob - ' >> $testroot/stdout.expected
1171 got tree -r $testroot/repo -i -c $first_commit \
1172 | grep 'beta$' | cut -d' ' -f 1 \
1173 >> $testroot/stdout.expected
1174 echo 'blob + /dev/null' >> $testroot/stdout.expected
1175 echo '--- beta' >> $testroot/stdout.expected
1176 echo '+++ /dev/null' >> $testroot/stdout.expected
1177 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1178 echo '-beta' >> $testroot/stdout.expected
1179 echo 'blob - /dev/null' >> $testroot/stdout.expected
1180 echo -n 'blob + ' >> $testroot/stdout.expected
1181 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1182 echo '--- /dev/null' >> $testroot/stdout.expected
1183 echo '+++ foo' >> $testroot/stdout.expected
1184 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1185 echo '+new file' >> $testroot/stdout.expected
1187 cmp -s $testroot/stdout.expected $testroot/stdout
1188 ret="$?"
1189 if [ "$ret" != "0" ]; then
1190 diff -u $testroot/stdout.expected $testroot/stdout
1191 test_done "$testroot" "$ret"
1192 return 1
1195 echo 'A epsilon/new' > $testroot/stdout.expected
1196 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1197 echo 'M gamma/delta' >> $testroot/stdout.expected
1199 (cd $testroot/wt && got status > $testroot/stdout)
1200 cmp -s $testroot/stdout.expected $testroot/stdout
1201 ret="$?"
1202 if [ "$ret" != "0" ]; then
1203 diff -u $testroot/stdout.expected $testroot/stdout
1205 test_done "$testroot" "$ret"
1208 function test_stage_patch {
1209 local testroot=`test_init stage_patch`
1211 jot 16 > $testroot/repo/numbers
1212 (cd $testroot/repo && git add numbers)
1213 git_commit $testroot/repo -m "added numbers file"
1214 local commit_id=`git_show_head $testroot/repo`
1216 got checkout $testroot/repo $testroot/wt > /dev/null
1217 ret="$?"
1218 if [ "$ret" != "0" ]; then
1219 test_done "$testroot" "$ret"
1220 return 1
1223 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1224 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1225 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1227 # don't stage any hunks
1228 printf "n\nn\nn\n" > $testroot/patchscript
1229 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1230 numbers > $testroot/stdout)
1231 ret="$?"
1232 if [ "$ret" != "0" ]; then
1233 echo "got stage command failed unexpectedly" >&2
1234 test_done "$testroot" "1"
1235 return 1
1237 cat > $testroot/stdout.expected <<EOF
1238 -----------------------------------------------
1239 @@ -1,5 +1,5 @@
1246 -----------------------------------------------
1247 M numbers (change 1 of 3)
1248 stage this change? [y/n/q] n
1249 -----------------------------------------------
1250 @@ -4,7 +4,7 @@
1259 -----------------------------------------------
1260 M numbers (change 2 of 3)
1261 stage this change? [y/n/q] n
1262 -----------------------------------------------
1263 @@ -13,4 +13,4 @@
1267 -16
1269 -----------------------------------------------
1270 M numbers (change 3 of 3)
1271 stage this change? [y/n/q] n
1272 EOF
1273 cmp -s $testroot/stdout.expected $testroot/stdout
1274 ret="$?"
1275 if [ "$ret" != "0" ]; then
1276 diff -u $testroot/stdout.expected $testroot/stdout
1277 test_done "$testroot" "$ret"
1278 return 1
1281 (cd $testroot/wt && got status > $testroot/stdout)
1282 echo "M numbers" > $testroot/stdout.expected
1283 cmp -s $testroot/stdout.expected $testroot/stdout
1284 ret="$?"
1285 if [ "$ret" != "0" ]; then
1286 diff -u $testroot/stdout.expected $testroot/stdout
1287 test_done "$testroot" "$ret"
1288 return 1
1291 # stage middle hunk
1292 printf "n\ny\nn\n" > $testroot/patchscript
1293 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1294 numbers > $testroot/stdout)
1296 cat > $testroot/stdout.expected <<EOF
1297 -----------------------------------------------
1298 @@ -1,5 +1,5 @@
1305 -----------------------------------------------
1306 M numbers (change 1 of 3)
1307 stage this change? [y/n/q] n
1308 -----------------------------------------------
1309 @@ -4,7 +4,7 @@
1318 -----------------------------------------------
1319 M numbers (change 2 of 3)
1320 stage this change? [y/n/q] y
1321 -----------------------------------------------
1322 @@ -13,4 +13,4 @@
1326 -16
1328 -----------------------------------------------
1329 M numbers (change 3 of 3)
1330 stage this change? [y/n/q] n
1331 EOF
1332 cmp -s $testroot/stdout.expected $testroot/stdout
1333 ret="$?"
1334 if [ "$ret" != "0" ]; then
1335 diff -u $testroot/stdout.expected $testroot/stdout
1336 test_done "$testroot" "$ret"
1337 return 1
1340 (cd $testroot/wt && got status > $testroot/stdout)
1341 echo "MM numbers" > $testroot/stdout.expected
1342 cmp -s $testroot/stdout.expected $testroot/stdout
1343 ret="$?"
1344 if [ "$ret" != "0" ]; then
1345 diff -u $testroot/stdout.expected $testroot/stdout
1346 test_done "$testroot" "$ret"
1347 return 1
1350 (cd $testroot/wt && got diff -s > $testroot/stdout)
1352 echo "diff $commit_id $testroot/wt (staged changes)" \
1353 > $testroot/stdout.expected
1354 echo -n 'blob - ' >> $testroot/stdout.expected
1355 got tree -r $testroot/repo -i -c $commit_id \
1356 | grep 'numbers$' | cut -d' ' -f 1 \
1357 >> $testroot/stdout.expected
1358 echo -n 'blob + ' >> $testroot/stdout.expected
1359 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1360 >> $testroot/stdout.expected
1361 echo "--- numbers" >> $testroot/stdout.expected
1362 echo "+++ numbers" >> $testroot/stdout.expected
1363 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1364 echo " 4" >> $testroot/stdout.expected
1365 echo " 5" >> $testroot/stdout.expected
1366 echo " 6" >> $testroot/stdout.expected
1367 echo "-7" >> $testroot/stdout.expected
1368 echo "+b" >> $testroot/stdout.expected
1369 echo " 8" >> $testroot/stdout.expected
1370 echo " 9" >> $testroot/stdout.expected
1371 echo " 10" >> $testroot/stdout.expected
1372 cmp -s $testroot/stdout.expected $testroot/stdout
1373 ret="$?"
1374 if [ "$ret" != "0" ]; then
1375 diff -u $testroot/stdout.expected $testroot/stdout
1376 test_done "$testroot" "$ret"
1377 return 1
1380 (cd $testroot/wt && got unstage >/dev/null)
1381 ret="$?"
1382 if [ "$ret" != "0" ]; then
1383 echo "got stage command failed unexpectedly" >&2
1384 test_done "$testroot" "1"
1385 return 1
1387 (cd $testroot/wt && got status > $testroot/stdout)
1388 echo "M numbers" > $testroot/stdout.expected
1389 cmp -s $testroot/stdout.expected $testroot/stdout
1390 ret="$?"
1391 if [ "$ret" != "0" ]; then
1392 diff -u $testroot/stdout.expected $testroot/stdout
1393 test_done "$testroot" "$ret"
1394 return 1
1397 # stage last hunk
1398 printf "n\nn\ny\n" > $testroot/patchscript
1399 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1400 numbers > $testroot/stdout)
1402 cat > $testroot/stdout.expected <<EOF
1403 -----------------------------------------------
1404 @@ -1,5 +1,5 @@
1411 -----------------------------------------------
1412 M numbers (change 1 of 3)
1413 stage this change? [y/n/q] n
1414 -----------------------------------------------
1415 @@ -4,7 +4,7 @@
1424 -----------------------------------------------
1425 M numbers (change 2 of 3)
1426 stage this change? [y/n/q] n
1427 -----------------------------------------------
1428 @@ -13,4 +13,4 @@
1432 -16
1434 -----------------------------------------------
1435 M numbers (change 3 of 3)
1436 stage this change? [y/n/q] y
1437 EOF
1438 cmp -s $testroot/stdout.expected $testroot/stdout
1439 ret="$?"
1440 if [ "$ret" != "0" ]; then
1441 diff -u $testroot/stdout.expected $testroot/stdout
1442 test_done "$testroot" "$ret"
1443 return 1
1446 (cd $testroot/wt && got status > $testroot/stdout)
1447 echo "MM numbers" > $testroot/stdout.expected
1448 cmp -s $testroot/stdout.expected $testroot/stdout
1449 ret="$?"
1450 if [ "$ret" != "0" ]; then
1451 diff -u $testroot/stdout.expected $testroot/stdout
1452 test_done "$testroot" "$ret"
1453 return 1
1456 (cd $testroot/wt && got diff -s > $testroot/stdout)
1458 echo "diff $commit_id $testroot/wt (staged changes)" \
1459 > $testroot/stdout.expected
1460 echo -n 'blob - ' >> $testroot/stdout.expected
1461 got tree -r $testroot/repo -i -c $commit_id \
1462 | grep 'numbers$' | cut -d' ' -f 1 \
1463 >> $testroot/stdout.expected
1464 echo -n 'blob + ' >> $testroot/stdout.expected
1465 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1466 >> $testroot/stdout.expected
1467 echo "--- numbers" >> $testroot/stdout.expected
1468 echo "+++ numbers" >> $testroot/stdout.expected
1469 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1470 echo " 13" >> $testroot/stdout.expected
1471 echo " 14" >> $testroot/stdout.expected
1472 echo " 15" >> $testroot/stdout.expected
1473 echo "-16" >> $testroot/stdout.expected
1474 echo "+c" >> $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
1480 test_done "$testroot" "$ret"
1483 function test_stage_patch_added {
1484 local testroot=`test_init stage_patch_added`
1485 local commit_id=`git_show_head $testroot/repo`
1487 got checkout $testroot/repo $testroot/wt > /dev/null
1488 ret="$?"
1489 if [ "$ret" != "0" ]; then
1490 test_done "$testroot" "$ret"
1491 return 1
1494 echo "new" > $testroot/wt/epsilon/new
1495 (cd $testroot/wt && got add epsilon/new > /dev/null)
1497 printf "y\n" > $testroot/patchscript
1498 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1499 epsilon/new > $testroot/stdout)
1501 echo "A epsilon/new" > $testroot/stdout.expected
1502 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1503 cmp -s $testroot/stdout.expected $testroot/stdout
1504 ret="$?"
1505 if [ "$ret" != "0" ]; then
1506 diff -u $testroot/stdout.expected $testroot/stdout
1507 test_done "$testroot" "$ret"
1508 return 1
1511 (cd $testroot/wt && got status > $testroot/stdout)
1512 echo " A epsilon/new" > $testroot/stdout.expected
1513 cmp -s $testroot/stdout.expected $testroot/stdout
1514 ret="$?"
1515 if [ "$ret" != "0" ]; then
1516 diff -u $testroot/stdout.expected $testroot/stdout
1517 test_done "$testroot" "$ret"
1518 return 1
1521 (cd $testroot/wt && got diff -s > $testroot/stdout)
1523 echo "diff $commit_id $testroot/wt (staged changes)" \
1524 > $testroot/stdout.expected
1525 echo 'blob - /dev/null' >> $testroot/stdout.expected
1526 echo -n 'blob + ' >> $testroot/stdout.expected
1527 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1528 >> $testroot/stdout.expected
1529 echo "--- /dev/null" >> $testroot/stdout.expected
1530 echo "+++ epsilon/new" >> $testroot/stdout.expected
1531 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1532 echo "+new" >> $testroot/stdout.expected
1533 cmp -s $testroot/stdout.expected $testroot/stdout
1534 ret="$?"
1535 if [ "$ret" != "0" ]; then
1536 diff -u $testroot/stdout.expected $testroot/stdout
1538 test_done "$testroot" "$ret"
1541 function test_stage_patch_removed {
1542 local testroot=`test_init stage_patch_removed`
1543 local commit_id=`git_show_head $testroot/repo`
1545 got checkout $testroot/repo $testroot/wt > /dev/null
1546 ret="$?"
1547 if [ "$ret" != "0" ]; then
1548 test_done "$testroot" "$ret"
1549 return 1
1552 (cd $testroot/wt && got rm beta > /dev/null)
1554 printf "y\n" > $testroot/patchscript
1555 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1556 beta > $testroot/stdout)
1558 echo -n > $testroot/stdout.expected
1560 echo "D beta" > $testroot/stdout.expected
1561 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
1562 cmp -s $testroot/stdout.expected $testroot/stdout
1563 ret="$?"
1564 if [ "$ret" != "0" ]; then
1565 diff -u $testroot/stdout.expected $testroot/stdout
1566 test_done "$testroot" "$ret"
1567 return 1
1570 (cd $testroot/wt && got status > $testroot/stdout)
1571 echo " D beta" > $testroot/stdout.expected
1572 cmp -s $testroot/stdout.expected $testroot/stdout
1573 ret="$?"
1574 if [ "$ret" != "0" ]; then
1575 diff -u $testroot/stdout.expected $testroot/stdout
1576 test_done "$testroot" "$ret"
1577 return 1
1580 (cd $testroot/wt && got diff -s > $testroot/stdout)
1582 echo "diff $commit_id $testroot/wt (staged changes)" \
1583 > $testroot/stdout.expected
1584 echo -n 'blob - ' >> $testroot/stdout.expected
1585 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
1586 >> $testroot/stdout.expected
1587 echo 'blob + /dev/null' >> $testroot/stdout.expected
1588 echo "--- beta" >> $testroot/stdout.expected
1589 echo "+++ /dev/null" >> $testroot/stdout.expected
1590 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
1591 echo "-beta" >> $testroot/stdout.expected
1592 cmp -s $testroot/stdout.expected $testroot/stdout
1593 ret="$?"
1594 if [ "$ret" != "0" ]; then
1595 diff -u $testroot/stdout.expected $testroot/stdout
1597 test_done "$testroot" "$ret"
1600 function test_stage_patch_quit {
1601 local testroot=`test_init stage_patch_quit`
1603 jot 16 > $testroot/repo/numbers
1604 echo zzz > $testroot/repo/zzz
1605 (cd $testroot/repo && git add numbers zzz)
1606 git_commit $testroot/repo -m "added files"
1607 local commit_id=`git_show_head $testroot/repo`
1609 got checkout $testroot/repo $testroot/wt > /dev/null
1610 ret="$?"
1611 if [ "$ret" != "0" ]; then
1612 test_done "$testroot" "$ret"
1613 return 1
1616 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1617 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1618 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1619 (cd $testroot/wt && got rm zzz > /dev/null)
1621 # stage first hunk and quit; and don't pass a path argument to
1622 # ensure that we don't skip asking about the 'zzz' file after 'quit'
1623 printf "y\nq\nn\n" > $testroot/patchscript
1624 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1625 > $testroot/stdout)
1626 ret="$?"
1627 if [ "$ret" != "0" ]; then
1628 echo "got stage command failed unexpectedly" >&2
1629 test_done "$testroot" "1"
1630 return 1
1632 cat > $testroot/stdout.expected <<EOF
1633 -----------------------------------------------
1634 @@ -1,5 +1,5 @@
1641 -----------------------------------------------
1642 M numbers (change 1 of 3)
1643 stage this change? [y/n/q] y
1644 -----------------------------------------------
1645 @@ -4,7 +4,7 @@
1654 -----------------------------------------------
1655 M numbers (change 2 of 3)
1656 stage this change? [y/n/q] q
1657 D zzz
1658 stage this deletion? [y/n] n
1659 EOF
1660 cmp -s $testroot/stdout.expected $testroot/stdout
1661 ret="$?"
1662 if [ "$ret" != "0" ]; then
1663 diff -u $testroot/stdout.expected $testroot/stdout
1664 test_done "$testroot" "$ret"
1665 return 1
1668 (cd $testroot/wt && got status > $testroot/stdout)
1669 echo "MM numbers" > $testroot/stdout.expected
1670 echo "D zzz" >> $testroot/stdout.expected
1671 cmp -s $testroot/stdout.expected $testroot/stdout
1672 ret="$?"
1673 if [ "$ret" != "0" ]; then
1674 diff -u $testroot/stdout.expected $testroot/stdout
1675 test_done "$testroot" "$ret"
1676 return 1
1679 (cd $testroot/wt && got diff -s > $testroot/stdout)
1681 echo "diff $commit_id $testroot/wt (staged changes)" \
1682 > $testroot/stdout.expected
1683 echo -n 'blob - ' >> $testroot/stdout.expected
1684 got tree -r $testroot/repo -i -c $commit_id \
1685 | grep 'numbers$' | cut -d' ' -f 1 \
1686 >> $testroot/stdout.expected
1687 echo -n 'blob + ' >> $testroot/stdout.expected
1688 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1689 >> $testroot/stdout.expected
1690 echo "--- numbers" >> $testroot/stdout.expected
1691 echo "+++ numbers" >> $testroot/stdout.expected
1692 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
1693 echo " 1" >> $testroot/stdout.expected
1694 echo "-2" >> $testroot/stdout.expected
1695 echo "+a" >> $testroot/stdout.expected
1696 echo " 3" >> $testroot/stdout.expected
1697 echo " 4" >> $testroot/stdout.expected
1698 echo " 5" >> $testroot/stdout.expected
1699 cmp -s $testroot/stdout.expected $testroot/stdout
1700 ret="$?"
1701 if [ "$ret" != "0" ]; then
1702 diff -u $testroot/stdout.expected $testroot/stdout
1704 test_done "$testroot" "$ret"
1708 function test_stage_patch_incomplete_script {
1709 local testroot=`test_init stage_incomplete_script`
1711 jot 16 > $testroot/repo/numbers
1712 echo zzz > $testroot/repo/zzz
1713 (cd $testroot/repo && git add numbers zzz)
1714 git_commit $testroot/repo -m "added files"
1715 local commit_id=`git_show_head $testroot/repo`
1717 got checkout $testroot/repo $testroot/wt > /dev/null
1718 ret="$?"
1719 if [ "$ret" != "0" ]; then
1720 test_done "$testroot" "$ret"
1721 return 1
1724 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1725 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1726 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1728 # stage first hunk and then stop responding; got should error out
1729 printf "y\n" > $testroot/patchscript
1730 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1731 > $testroot/stdout 2> $testroot/stderr)
1732 ret="$?"
1733 if [ "$ret" == "0" ]; then
1734 echo "got stage command succeeded unexpectedly" >&2
1735 test_done "$testroot" "1"
1736 return 1
1738 cat > $testroot/stdout.expected <<EOF
1739 -----------------------------------------------
1740 @@ -1,5 +1,5 @@
1747 -----------------------------------------------
1748 M numbers (change 1 of 3)
1749 stage this change? [y/n/q] y
1750 -----------------------------------------------
1751 @@ -4,7 +4,7 @@
1760 -----------------------------------------------
1761 M numbers (change 2 of 3)
1762 EOF
1763 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
1764 echo "got: invalid patch choice" > $testroot/stderr.expected
1765 cmp -s $testroot/stderr.expected $testroot/stderr
1766 ret="$?"
1767 if [ "$ret" != "0" ]; then
1768 diff -u $testroot/stderr.expected $testroot/stderr
1769 test_done "$testroot" "$ret"
1770 return 1
1773 cmp -s $testroot/stdout.expected $testroot/stdout
1774 ret="$?"
1775 if [ "$ret" != "0" ]; then
1776 diff -u $testroot/stdout.expected $testroot/stdout
1777 test_done "$testroot" "$ret"
1778 return 1
1781 (cd $testroot/wt && got status > $testroot/stdout)
1782 echo "M numbers" > $testroot/stdout.expected
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 diff -s > $testroot/stdout)
1792 echo -n > $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
1798 test_done "$testroot" "$ret"
1802 run_test test_stage_basic
1803 run_test test_stage_no_changes
1804 run_test test_stage_unversioned
1805 run_test test_stage_list
1806 run_test test_stage_conflict
1807 run_test test_stage_out_of_date
1808 run_test test_double_stage
1809 run_test test_stage_status
1810 run_test test_stage_add_already_staged_file
1811 run_test test_stage_rm_already_staged_file
1812 run_test test_stage_revert
1813 run_test test_stage_diff
1814 run_test test_stage_histedit
1815 run_test test_stage_rebase
1816 run_test test_stage_update
1817 run_test test_stage_commit_non_staged
1818 run_test test_stage_commit
1819 run_test test_stage_patch
1820 run_test test_stage_patch_added
1821 run_test test_stage_patch_removed
1822 run_test test_stage_patch_quit
1823 run_test test_stage_patch_incomplete_script