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 alpha beta foo > $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_list {
86 local testroot=`test_init stage_list`
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 (cd $testroot/wt && got rm beta > /dev/null)
97 echo "new file" > $testroot/wt/foo
98 (cd $testroot/wt && got add foo > /dev/null)
100 echo ' M alpha' > $testroot/stdout.expected
101 echo ' D beta' >> $testroot/stdout.expected
102 echo ' A foo' >> $testroot/stdout.expected
103 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
105 (cd $testroot/wt && got stage -l > $testroot/stdout)
106 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
107 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
108 echo " M alpha" >> $testroot/stdout.expected
109 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
110 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
111 echo " D beta" >> $testroot/stdout.expected
112 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
113 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
114 echo " A foo" >> $testroot/stdout.expected
115 cmp -s $testroot/stdout.expected $testroot/stdout
116 ret="$?"
117 if [ "$ret" != "0" ]; then
118 diff -u $testroot/stdout.expected $testroot/stdout
119 test_done "$testroot" "$ret"
120 return 1
121 fi
123 (cd $testroot/wt && got stage -l epsilon nonexistent \
124 > $testroot/stdout)
126 echo -n > $testroot/stdout.expected
127 cmp -s $testroot/stdout.expected $testroot/stdout
128 ret="$?"
129 if [ "$ret" != "0" ]; then
130 diff -u $testroot/stdout.expected $testroot/stdout
131 test_done "$testroot" "$ret"
132 return 1
133 fi
135 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
137 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
138 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
139 echo " M alpha" >> $testroot/stdout.expected
140 cmp -s $testroot/stdout.expected $testroot/stdout
141 ret="$?"
142 if [ "$ret" != "0" ]; then
143 diff -u $testroot/stdout.expected $testroot/stdout
144 fi
145 test_done "$testroot" "$ret"
149 function test_stage_conflict {
150 local testroot=`test_init stage_conflict`
151 local initial_commit=`git_show_head $testroot/repo`
153 got checkout $testroot/repo $testroot/wt > /dev/null
154 ret="$?"
155 if [ "$ret" != "0" ]; then
156 test_done "$testroot" "$ret"
157 return 1
158 fi
160 echo "modified alpha" > $testroot/wt/alpha
161 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
163 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
165 echo "modified alpha, too" > $testroot/wt/alpha
167 echo "C alpha" > $testroot/stdout.expected
168 echo -n "Updated to commit " >> $testroot/stdout.expected
169 git_show_head $testroot/repo >> $testroot/stdout.expected
170 echo >> $testroot/stdout.expected
172 (cd $testroot/wt && got update > $testroot/stdout)
174 cmp -s $testroot/stdout.expected $testroot/stdout
175 ret="$?"
176 if [ "$ret" != "0" ]; then
177 diff -u $testroot/stdout.expected $testroot/stdout
178 test_done "$testroot" "$ret"
179 return 1
180 fi
182 (cd $testroot/wt && got stage alpha > $testroot/stdout \
183 2> $testroot/stderr)
184 ret="$?"
185 if [ "$ret" == "0" ]; then
186 echo "got stage command succeeded unexpectedly" >&2
187 test_done "$testroot" "1"
188 return 1
189 fi
191 echo -n > $testroot/stdout.expected
192 echo "got: alpha: cannot stage file in conflicted status" \
193 > $testroot/stderr.expected
195 cmp -s $testroot/stdout.expected $testroot/stdout
196 ret="$?"
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
200 return 1
201 fi
202 cmp -s $testroot/stderr.expected $testroot/stderr
203 ret="$?"
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stderr.expected $testroot/stderr
206 fi
207 test_done "$testroot" "$ret"
210 function test_stage_out_of_date {
211 local testroot=`test_init stage_out_of_date`
212 local initial_commit=`git_show_head $testroot/repo`
214 got checkout $testroot/repo $testroot/wt > /dev/null
215 ret="$?"
216 if [ "$ret" != "0" ]; then
217 test_done "$testroot" "$ret"
218 return 1
219 fi
221 echo "modified alpha" > $testroot/wt/alpha
222 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
224 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
226 echo "modified alpha again" > $testroot/wt/alpha
227 (cd $testroot/wt && got stage alpha > $testroot/stdout \
228 2> $testroot/stderr)
229 ret="$?"
230 if [ "$ret" == "0" ]; then
231 echo "got stage command succeeded unexpectedly" >&2
232 test_done "$testroot" "1"
233 return 1
234 fi
236 echo -n > $testroot/stdout.expected
237 echo "got: work tree must be updated before changes can be staged" \
238 > $testroot/stderr.expected
240 cmp -s $testroot/stdout.expected $testroot/stdout
241 ret="$?"
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/stdout.expected $testroot/stdout
244 test_done "$testroot" "$ret"
245 return 1
246 fi
247 cmp -s $testroot/stderr.expected $testroot/stderr
248 ret="$?"
249 if [ "$ret" != "0" ]; then
250 diff -u $testroot/stderr.expected $testroot/stderr
251 fi
252 test_done "$testroot" "$ret"
256 function test_double_stage {
257 local testroot=`test_init double_stage`
259 got checkout $testroot/repo $testroot/wt > /dev/null
260 ret="$?"
261 if [ "$ret" != "0" ]; then
262 test_done "$testroot" "$ret"
263 return 1
264 fi
265 echo "modified file" > $testroot/wt/alpha
266 (cd $testroot/wt && got rm beta > /dev/null)
267 echo "new file" > $testroot/wt/foo
268 (cd $testroot/wt && got add foo > /dev/null)
269 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
271 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
272 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
273 cmp -s $testroot/stderr.expected $testroot/stderr
274 ret="$?"
275 if [ "$ret" != "0" ]; then
276 diff -u $testroot/stderr.expected $testroot/stderr
277 test_done "$testroot" "$ret"
278 return 1
279 fi
281 (cd $testroot/wt && got stage beta > $testroot/stdout)
282 ret="$?"
283 if [ "$ret" != "0" ]; then
284 echo "got stage command failed unexpectedly" >&2
285 test_done "$testroot" "1"
286 return 1
287 fi
288 echo -n > $testroot/stdout.expected
289 cmp -s $testroot/stdout.expected $testroot/stdout
290 ret="$?"
291 if [ "$ret" != "0" ]; then
292 diff -u $testroot/stdout.expected $testroot/stdout
293 test_done "$testroot" "$ret"
294 return 1
295 fi
297 echo "got: foo: no changes to stage" > $testroot/stderr.expected
298 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
299 cmp -s $testroot/stderr.expected $testroot/stderr
300 ret="$?"
301 if [ "$ret" != "0" ]; then
302 diff -u $testroot/stderr.expected $testroot/stderr
303 test_done "$testroot" "$ret"
304 return 1
305 fi
307 echo "modified file again" > $testroot/wt/alpha
308 echo "modified new file" > $testroot/wt/foo
310 echo ' M alpha' > $testroot/stdout.expected
311 echo ' A foo' >> $testroot/stdout.expected
312 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
313 cmp -s $testroot/stdout.expected $testroot/stdout
314 ret="$?"
315 if [ "$ret" != "0" ]; then
316 diff -u $testroot/stdout.expected $testroot/stdout
317 test_done "$testroot" "$ret"
318 return 1
319 fi
321 echo ' M alpha' > $testroot/stdout.expected
322 echo ' D beta' >> $testroot/stdout.expected
323 echo ' A foo' >> $testroot/stdout.expected
325 (cd $testroot/wt && got status > $testroot/stdout)
326 cmp -s $testroot/stdout.expected $testroot/stdout
327 ret="$?"
328 if [ "$ret" != "0" ]; then
329 diff -u $testroot/stdout.expected $testroot/stdout
330 fi
331 test_done "$testroot" "$ret"
334 function test_stage_status {
335 local testroot=`test_init stage_status`
337 got checkout $testroot/repo $testroot/wt > /dev/null
338 ret="$?"
339 if [ "$ret" != "0" ]; then
340 test_done "$testroot" "$ret"
341 return 1
342 fi
344 echo "modified file" > $testroot/wt/alpha
345 (cd $testroot/wt && got rm beta > /dev/null)
346 echo "new file" > $testroot/wt/foo
347 (cd $testroot/wt && got add foo > /dev/null)
348 echo "new file" > $testroot/wt/epsilon/new
349 (cd $testroot/wt && got add epsilon/new > /dev/null)
350 echo "modified file" > $testroot/wt/epsilon/zeta
351 (cd $testroot/wt && got rm gamma/delta > /dev/null)
353 echo ' M alpha' > $testroot/stdout.expected
354 echo ' D beta' >> $testroot/stdout.expected
355 echo 'A epsilon/new' >> $testroot/stdout.expected
356 echo 'M epsilon/zeta' >> $testroot/stdout.expected
357 echo ' A foo' >> $testroot/stdout.expected
358 echo 'D gamma/delta' >> $testroot/stdout.expected
359 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
361 (cd $testroot/wt && got status > $testroot/stdout)
362 cmp -s $testroot/stdout.expected $testroot/stdout
363 ret="$?"
364 if [ "$ret" != "0" ]; then
365 diff -u $testroot/stdout.expected $testroot/stdout
366 test_done "$testroot" "$ret"
367 return 1
368 fi
370 echo "modified file again" >> $testroot/wt/alpha
371 echo "modified added file again" >> $testroot/wt/foo
373 echo 'MM alpha' > $testroot/stdout.expected
374 echo ' D beta' >> $testroot/stdout.expected
375 echo 'A epsilon/new' >> $testroot/stdout.expected
376 echo 'M epsilon/zeta' >> $testroot/stdout.expected
377 echo 'MA foo' >> $testroot/stdout.expected
378 echo 'D gamma/delta' >> $testroot/stdout.expected
380 (cd $testroot/wt && got status > $testroot/stdout)
381 cmp -s $testroot/stdout.expected $testroot/stdout
382 ret="$?"
383 if [ "$ret" != "0" ]; then
384 diff -u $testroot/stdout.expected $testroot/stdout
385 test_done "$testroot" "$ret"
386 return 1
387 fi
389 # test no-op change of added file with new stat(2) timestamp
390 echo "new file" > $testroot/wt/foo
391 echo ' A foo' > $testroot/stdout.expected
392 (cd $testroot/wt && got status foo > $testroot/stdout)
393 cmp -s $testroot/stdout.expected $testroot/stdout
394 ret="$?"
395 if [ "$ret" != "0" ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
398 return 1
399 fi
401 # test staged deleted file which is restored on disk
402 echo "new file" > $testroot/wt/beta
403 echo ' D beta' > $testroot/stdout.expected
404 (cd $testroot/wt && got status beta > $testroot/stdout)
405 cmp -s $testroot/stdout.expected $testroot/stdout
406 ret="$?"
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
409 fi
410 test_done "$testroot" "$ret"
414 function test_stage_add_already_staged_file {
415 local testroot=`test_init stage_add_already_staged_file`
417 got checkout $testroot/repo $testroot/wt > /dev/null
418 ret="$?"
419 if [ "$ret" != "0" ]; then
420 test_done "$testroot" "$ret"
421 return 1
422 fi
424 echo "modified file" > $testroot/wt/alpha
425 (cd $testroot/wt && got rm beta > /dev/null)
426 echo "new file" > $testroot/wt/foo
427 (cd $testroot/wt && got add foo > /dev/null)
429 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
431 echo -n > $testroot/stdout.expected
432 for f in alpha beta foo; do
433 (cd $testroot/wt && got add $f \
434 > $testroot/stdout 2> $testroot/stderr)
435 echo "got: $f: file has unexpected status" \
436 > $testroot/stderr.expected
437 cmp -s $testroot/stderr.expected $testroot/stderr
438 ret="$?"
439 if [ "$ret" != "0" ]; then
440 diff -u $testroot/stderr.expected $testroot/stderr
441 test_done "$testroot" "$ret"
442 return 1
443 fi
444 cmp -s $testroot/stdout.expected $testroot/stdout
445 ret="$?"
446 if [ "$ret" != "0" ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
449 return 1
450 fi
451 done
453 echo ' M alpha' > $testroot/stdout.expected
454 echo ' D beta' >> $testroot/stdout.expected
455 echo ' A foo' >> $testroot/stdout.expected
457 (cd $testroot/wt && got status > $testroot/stdout)
458 cmp -s $testroot/stdout.expected $testroot/stdout
459 ret="$?"
460 if [ "$ret" != "0" ]; then
461 diff -u $testroot/stdout.expected $testroot/stdout
462 fi
463 test_done "$testroot" "$ret"
466 function test_stage_rm_already_staged_file {
467 local testroot=`test_init stage_rm_already_staged_file`
469 got checkout $testroot/repo $testroot/wt > /dev/null
470 ret="$?"
471 if [ "$ret" != "0" ]; then
472 test_done "$testroot" "$ret"
473 return 1
474 fi
476 echo "modified file" > $testroot/wt/alpha
477 (cd $testroot/wt && got rm beta > /dev/null)
478 echo "new file" > $testroot/wt/foo
479 (cd $testroot/wt && got add foo > /dev/null)
481 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
483 (cd $testroot/wt && got rm beta \
484 > $testroot/stdout 2> $testroot/stderr)
485 ret="$?"
486 if [ "$ret" != "0" ]; then
487 echo "got rm command failed unexpectedly" >&2
488 test_done "$testroot" "1"
489 return 1
490 fi
491 echo -n > $testroot/stdout.expected
492 cmp -s $testroot/stdout.expected $testroot/stdout
493 ret="$?"
494 if [ "$ret" != "0" ]; then
495 diff -u $testroot/stdout.expected $testroot/stdout
496 test_done "$testroot" "$ret"
497 return 1
498 fi
499 echo -n > $testroot/stderr.expected
500 cmp -s $testroot/stderr.expected $testroot/stderr
501 ret="$?"
502 if [ "$ret" != "0" ]; then
503 diff -u $testroot/stderr.expected $testroot/stderr
504 test_done "$testroot" "$ret"
505 return 1
506 fi
508 for f in alpha foo; do
509 echo "got: $f: file is staged" > $testroot/stderr.expected
510 (cd $testroot/wt && got rm $f \
511 > $testroot/stdout 2> $testroot/stderr)
512 ret="$?"
513 if [ "$ret" == "0" ]; then
514 echo "got rm command succeeded unexpectedly" >&2
515 test_done "$testroot" "1"
516 return 1
517 fi
518 cmp -s $testroot/stderr.expected $testroot/stderr
519 ret="$?"
520 if [ "$ret" != "0" ]; then
521 diff -u $testroot/stderr.expected $testroot/stderr
522 test_done "$testroot" "$ret"
523 return 1
524 fi
525 done
527 echo ' M alpha' > $testroot/stdout.expected
528 echo ' D beta' >> $testroot/stdout.expected
529 echo ' A foo' >> $testroot/stdout.expected
531 (cd $testroot/wt && got status > $testroot/stdout)
532 cmp -s $testroot/stdout.expected $testroot/stdout
533 ret="$?"
534 if [ "$ret" != "0" ]; then
535 diff -u $testroot/stdout.expected $testroot/stdout
536 fi
537 test_done "$testroot" "$ret"
540 function test_stage_revert {
541 local testroot=`test_init stage_revert`
543 got checkout $testroot/repo $testroot/wt > /dev/null
544 ret="$?"
545 if [ "$ret" != "0" ]; then
546 test_done "$testroot" "$ret"
547 return 1
548 fi
550 echo "modified alpha" > $testroot/wt/alpha
551 (cd $testroot/wt && got rm beta > /dev/null)
552 echo "new file" > $testroot/wt/foo
553 (cd $testroot/wt && got add foo > /dev/null)
554 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
556 echo "modified file again" >> $testroot/wt/alpha
557 echo "modified added file again" >> $testroot/wt/foo
559 (cd $testroot/wt && got revert alpha > $testroot/stdout)
560 ret="$?"
561 if [ "$ret" != "0" ]; then
562 echo "revert command failed unexpectedly" >&2
563 test_done "$testroot" "$ret"
564 return 1
565 fi
567 echo "R alpha" > $testroot/stdout.expected
568 cmp -s $testroot/stdout.expected $testroot/stdout
569 ret="$?"
570 if [ "$ret" != "0" ]; then
571 diff -u $testroot/stdout.expected $testroot/stdout
572 test_done "$testroot" "$ret"
573 return 1
574 fi
576 echo "modified alpha" > $testroot/content.expected
577 cat $testroot/wt/alpha > $testroot/content
578 cmp -s $testroot/content.expected $testroot/content
579 ret="$?"
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/content.expected $testroot/content
582 test_done "$testroot" "$ret"
583 return 1
584 fi
586 echo ' M alpha' > $testroot/stdout.expected
587 echo ' D beta' >> $testroot/stdout.expected
588 echo 'MA foo' >> $testroot/stdout.expected
589 (cd $testroot/wt && got status > $testroot/stdout)
590 cmp -s $testroot/stdout.expected $testroot/stdout
591 ret="$?"
592 if [ "$ret" != "0" ]; then
593 diff -u $testroot/stdout.expected $testroot/stdout
594 test_done "$testroot" "$ret"
595 return 1
596 fi
598 (cd $testroot/wt && got revert alpha > $testroot/stdout)
599 ret="$?"
600 if [ "$ret" != "0" ]; then
601 echo "revert command failed unexpectedly" >&2
602 test_done "$testroot" "$ret"
603 return 1
604 fi
606 echo -n > $testroot/stdout.expected
607 cmp -s $testroot/stdout.expected $testroot/stdout
608 ret="$?"
609 if [ "$ret" != "0" ]; then
610 diff -u $testroot/stdout.expected $testroot/stdout
611 test_done "$testroot" "$ret"
612 return 1
613 fi
615 echo "modified alpha" > $testroot/content.expected
616 cat $testroot/wt/alpha > $testroot/content
617 cmp -s $testroot/content.expected $testroot/content
618 ret="$?"
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/content.expected $testroot/content
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 (cd $testroot/wt && got revert beta > $testroot/stdout \
626 2> $testroot/stderr)
627 ret="$?"
628 if [ "$ret" == "0" ]; then
629 echo "revert command succeeded unexpectedly" >&2
630 test_done "$testroot" "1"
631 return 1
632 fi
634 echo "got: beta: file is staged" > $testroot/stderr.expected
635 cmp -s $testroot/stderr.expected $testroot/stderr
636 ret="$?"
637 if [ "$ret" != "0" ]; then
638 diff -u $testroot/stderr.expected $testroot/stderr
639 test_done "$testroot" "$ret"
640 return 1
641 fi
643 (cd $testroot/wt && got revert foo > $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 foo" > $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 "new file" > $testroot/content.expected
661 cat $testroot/wt/foo > $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 ' A 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 foo > $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 "new file" > $testroot/content.expected
700 cat $testroot/wt/foo > $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 echo ' M alpha' > $testroot/stdout.expected
710 echo ' D beta' >> $testroot/stdout.expected
711 echo ' A foo' >> $testroot/stdout.expected
712 (cd $testroot/wt && got status > $testroot/stdout)
713 cmp -s $testroot/stdout.expected $testroot/stdout
714 ret="$?"
715 if [ "$ret" != "0" ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
717 fi
718 test_done "$testroot" "$ret"
721 function test_stage_diff {
722 local testroot=`test_init stage_diff`
723 local head_commit=`git_show_head $testroot/repo`
725 got checkout $testroot/repo $testroot/wt > /dev/null
726 ret="$?"
727 if [ "$ret" != "0" ]; then
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 echo "modified file" > $testroot/wt/alpha
733 (cd $testroot/wt && got rm beta > /dev/null)
734 echo "new file" > $testroot/wt/foo
735 (cd $testroot/wt && got add foo > /dev/null)
737 (cd $testroot/wt && got diff -s > $testroot/stdout)
738 echo -n > $testroot/stdout.expected
739 cmp -s $testroot/stdout.expected $testroot/stdout
740 ret="$?"
741 if [ "$ret" != "0" ]; then
742 diff -u $testroot/stdout.expected $testroot/stdout
743 test_done "$testroot" "$ret"
744 return 1
745 fi
747 echo ' M alpha' > $testroot/stdout.expected
748 echo ' D beta' >> $testroot/stdout.expected
749 echo ' A foo' >> $testroot/stdout.expected
750 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
752 (cd $testroot/wt && got diff > $testroot/stdout)
753 echo -n > $testroot/stdout.expected
754 cmp -s $testroot/stdout.expected $testroot/stdout
755 ret="$?"
756 if [ "$ret" != "0" ]; then
757 diff -u $testroot/stdout.expected $testroot/stdout
758 test_done "$testroot" "$ret"
759 return 1
760 fi
762 echo "modified file again" > $testroot/wt/alpha
763 echo "new file changed" > $testroot/wt/foo
765 (cd $testroot/wt && got diff > $testroot/stdout)
767 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
768 echo -n 'blob - ' >> $testroot/stdout.expected
769 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
770 >> $testroot/stdout.expected
771 echo 'file + alpha' >> $testroot/stdout.expected
772 echo '--- alpha' >> $testroot/stdout.expected
773 echo '+++ alpha' >> $testroot/stdout.expected
774 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
775 echo '-modified file' >> $testroot/stdout.expected
776 echo '+modified file again' >> $testroot/stdout.expected
777 echo -n 'blob - ' >> $testroot/stdout.expected
778 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
779 >> $testroot/stdout.expected
780 echo 'file + foo' >> $testroot/stdout.expected
781 echo '--- foo' >> $testroot/stdout.expected
782 echo '+++ foo' >> $testroot/stdout.expected
783 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
784 echo '-new file' >> $testroot/stdout.expected
785 echo '+new file changed' >> $testroot/stdout.expected
787 cmp -s $testroot/stdout.expected $testroot/stdout
788 ret="$?"
789 if [ "$ret" != "0" ]; then
790 diff -u $testroot/stdout.expected $testroot/stdout
791 test_done "$testroot" "$ret"
792 return 1
793 fi
795 (cd $testroot/wt && got diff -s > $testroot/stdout)
797 echo "diff $head_commit $testroot/wt (staged changes)" \
798 > $testroot/stdout.expected
799 echo -n 'blob - ' >> $testroot/stdout.expected
800 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
801 >> $testroot/stdout.expected
802 echo -n 'blob + ' >> $testroot/stdout.expected
803 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
804 >> $testroot/stdout.expected
805 echo '--- alpha' >> $testroot/stdout.expected
806 echo '+++ alpha' >> $testroot/stdout.expected
807 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
808 echo '-alpha' >> $testroot/stdout.expected
809 echo '+modified file' >> $testroot/stdout.expected
810 echo -n 'blob - ' >> $testroot/stdout.expected
811 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
812 >> $testroot/stdout.expected
813 echo 'blob + /dev/null' >> $testroot/stdout.expected
814 echo '--- beta' >> $testroot/stdout.expected
815 echo '+++ /dev/null' >> $testroot/stdout.expected
816 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
817 echo '-beta' >> $testroot/stdout.expected
818 echo 'blob - /dev/null' >> $testroot/stdout.expected
819 echo -n 'blob + ' >> $testroot/stdout.expected
820 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
821 >> $testroot/stdout.expected
822 echo '--- /dev/null' >> $testroot/stdout.expected
823 echo '+++ foo' >> $testroot/stdout.expected
824 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
825 echo '+new file' >> $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
828 ret="$?"
829 if [ "$ret" != "0" ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
831 fi
832 test_done "$testroot" "$ret"
836 function test_stage_histedit {
837 local testroot=`test_init stage_histedit`
838 local orig_commit=`git_show_head $testroot/repo`
840 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
841 ret="$?"
842 if [ "$ret" != "0" ]; then
843 test_done "$testroot" "$ret"
844 return 1
845 fi
847 echo "modified file" > $testroot/wt/alpha
848 (cd $testroot/wt && got stage alpha > /dev/null)
850 echo "modified alpha on master" > $testroot/repo/alpha
851 (cd $testroot/repo && git rm -q beta)
852 echo "new file on master" > $testroot/repo/epsilon/new
853 (cd $testroot/repo && git add epsilon/new)
854 git_commit $testroot/repo -m "committing changes"
855 local old_commit1=`git_show_head $testroot/repo`
857 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
858 git_commit $testroot/repo -m "committing to zeta on master"
859 local old_commit2=`git_show_head $testroot/repo`
861 echo "pick $old_commit1" > $testroot/histedit-script
862 echo "pick $old_commit2" >> $testroot/histedit-script
864 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
865 > $testroot/stdout 2> $testroot/stderr)
866 ret="$?"
867 if [ "$ret" == "0" ]; then
868 echo "got histedit command succeeded unexpectedly" >&2
869 test_done "$testroot" "1"
870 return 1
871 fi
873 echo -n > $testroot/stdout.expected
874 echo "got: alpha: file is staged" > $testroot/stderr.expected
876 cmp -s $testroot/stderr.expected $testroot/stderr
877 ret="$?"
878 if [ "$ret" != "0" ]; then
879 diff -u $testroot/stderr.expected $testroot/stderr
880 test_done "$testroot" "$ret"
881 return 1
882 fi
883 cmp -s $testroot/stdout.expected $testroot/stdout
884 ret="$?"
885 if [ "$ret" != "0" ]; then
886 diff -u $testroot/stdout.expected $testroot/stdout
887 fi
888 test_done "$testroot" "$ret"
892 function test_stage_rebase {
893 local testroot=`test_init stage_rebase`
895 (cd $testroot/repo && git checkout -q -b newbranch)
896 echo "modified delta on branch" > $testroot/repo/gamma/delta
897 git_commit $testroot/repo -m "committing to delta on newbranch"
899 echo "modified alpha on branch" > $testroot/repo/alpha
900 (cd $testroot/repo && git rm -q beta)
901 echo "new file on branch" > $testroot/repo/epsilon/new
902 (cd $testroot/repo && git add epsilon/new)
903 git_commit $testroot/repo -m "committing more changes on newbranch"
905 local orig_commit1=`git_show_parent_commit $testroot/repo`
906 local orig_commit2=`git_show_head $testroot/repo`
908 (cd $testroot/repo && git checkout -q master)
909 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
910 git_commit $testroot/repo -m "committing to zeta on master"
911 local master_commit=`git_show_head $testroot/repo`
913 got checkout $testroot/repo $testroot/wt > /dev/null
914 ret="$?"
915 if [ "$ret" != "0" ]; then
916 test_done "$testroot" "$ret"
917 return 1
918 fi
920 echo "modified file" > $testroot/wt/alpha
921 (cd $testroot/wt && got stage alpha > /dev/null)
923 (cd $testroot/wt && got rebase newbranch \
924 > $testroot/stdout 2> $testroot/stderr)
925 ret="$?"
926 if [ "$ret" == "0" ]; then
927 echo "got rebase command succeeded unexpectedly" >&2
928 test_done "$testroot" "1"
929 return 1
930 fi
932 echo -n > $testroot/stdout.expected
933 echo "got: alpha: file is staged" > $testroot/stderr.expected
935 cmp -s $testroot/stderr.expected $testroot/stderr
936 ret="$?"
937 if [ "$ret" != "0" ]; then
938 diff -u $testroot/stderr.expected $testroot/stderr
939 test_done "$testroot" "$ret"
940 return 1
941 fi
942 cmp -s $testroot/stdout.expected $testroot/stdout
943 ret="$?"
944 if [ "$ret" != "0" ]; then
945 diff -u $testroot/stdout.expected $testroot/stdout
946 fi
947 test_done "$testroot" "$ret"
950 function test_stage_update {
951 local testroot=`test_init stage_update`
953 got checkout $testroot/repo $testroot/wt > /dev/null
954 ret="$?"
955 if [ "$ret" != "0" ]; then
956 test_done "$testroot" "$ret"
957 return 1
958 fi
960 echo "modified file" > $testroot/wt/alpha
961 (cd $testroot/wt && got stage alpha > /dev/null)
963 echo "modified alpha" > $testroot/repo/alpha
964 git_commit $testroot/repo -m "modified alpha"
966 (cd $testroot/wt && got update > $testroot/stdout \
967 2> $testroot/stderr)
968 ret="$?"
969 if [ "$ret" == "0" ]; then
970 echo "got update command succeeded unexpectedly" >&2
971 test_done "$testroot" "1"
972 return 1
973 fi
975 echo -n > $testroot/stdout.expected
976 echo "got: alpha: file is staged" > $testroot/stderr.expected
978 cmp -s $testroot/stderr.expected $testroot/stderr
979 ret="$?"
980 if [ "$ret" != "0" ]; then
981 diff -u $testroot/stderr.expected $testroot/stderr
982 test_done "$testroot" "$ret"
983 return 1
984 fi
985 cmp -s $testroot/stdout.expected $testroot/stdout
986 ret="$?"
987 if [ "$ret" != "0" ]; then
988 diff -u $testroot/stdout.expected $testroot/stdout
989 fi
990 test_done "$testroot" "$ret"
993 function test_stage_commit_non_staged {
994 local testroot=`test_init stage_commit_non_staged`
996 got checkout $testroot/repo $testroot/wt > /dev/null
997 ret="$?"
998 if [ "$ret" != "0" ]; then
999 test_done "$testroot" "$ret"
1000 return 1
1003 echo "modified file" > $testroot/wt/alpha
1004 (cd $testroot/wt && got rm beta > /dev/null)
1005 echo "new file" > $testroot/wt/foo
1006 (cd $testroot/wt && got add foo > /dev/null)
1007 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1009 echo "modified file" > $testroot/wt/gamma/delta
1010 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1011 > $testroot/stdout 2> $testroot/stderr)
1012 ret="$?"
1013 if [ "$ret" == "0" ]; then
1014 echo "got commit command succeeded unexpectedly" >&2
1015 test_done "$testroot" "1"
1016 return 1
1019 echo -n > $testroot/stdout.expected
1020 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1022 cmp -s $testroot/stderr.expected $testroot/stderr
1023 ret="$?"
1024 if [ "$ret" != "0" ]; then
1025 diff -u $testroot/stderr.expected $testroot/stderr
1026 test_done "$testroot" "$ret"
1027 return 1
1029 cmp -s $testroot/stdout.expected $testroot/stdout
1030 ret="$?"
1031 if [ "$ret" != "0" ]; then
1032 diff -u $testroot/stdout.expected $testroot/stdout
1034 test_done "$testroot" "$ret"
1037 function test_stage_commit {
1038 local testroot=`test_init stage_commit`
1039 local first_commit=`git_show_head $testroot/repo`
1041 got checkout $testroot/repo $testroot/wt > /dev/null
1042 ret="$?"
1043 if [ "$ret" != "0" ]; then
1044 test_done "$testroot" "$ret"
1045 return 1
1048 echo "modified file" > $testroot/wt/alpha
1049 (cd $testroot/wt && got rm beta > /dev/null)
1050 echo "new file" > $testroot/wt/foo
1051 (cd $testroot/wt && got add foo > /dev/null)
1052 echo "modified file" > $testroot/wt/alpha
1053 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1055 echo "modified file again" > $testroot/wt/alpha
1056 echo "new file changed" > $testroot/wt/foo
1057 echo "non-staged change" > $testroot/wt/gamma/delta
1058 echo "non-staged new file" > $testroot/wt/epsilon/new
1059 (cd $testroot/wt && got add epsilon/new > /dev/null)
1060 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1062 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1063 > $testroot/blob_id_alpha
1064 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1065 > $testroot/blob_id_foo
1067 (cd $testroot/wt && got commit -m "staged changes" \
1068 > $testroot/stdout)
1069 ret="$?"
1070 if [ "$ret" != "0" ]; then
1071 echo "got commit command failed unexpectedly" >&2
1072 test_done "$testroot" "1"
1073 return 1
1076 local head_commit=`git_show_head $testroot/repo`
1077 echo "A foo" > $testroot/stdout.expected
1078 echo "M alpha" >> $testroot/stdout.expected
1079 echo "D beta" >> $testroot/stdout.expected
1080 echo "Created commit $head_commit" >> $testroot/stdout.expected
1082 cmp -s $testroot/stdout.expected $testroot/stdout
1083 ret="$?"
1084 if [ "$ret" != "0" ]; then
1085 diff -u $testroot/stdout.expected $testroot/stdout
1086 test_done "$testroot" "$ret"
1087 return 1
1090 got diff -r $testroot/repo $first_commit $head_commit \
1091 > $testroot/stdout
1093 echo "diff $first_commit $head_commit" \
1094 > $testroot/stdout.expected
1095 echo -n 'blob - ' >> $testroot/stdout.expected
1096 got tree -r $testroot/repo -i -c $first_commit | \
1097 grep 'alpha$' | cut -d' ' -f 1 \
1098 >> $testroot/stdout.expected
1099 echo -n 'blob + ' >> $testroot/stdout.expected
1100 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1101 echo '--- alpha' >> $testroot/stdout.expected
1102 echo '+++ alpha' >> $testroot/stdout.expected
1103 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1104 echo '-alpha' >> $testroot/stdout.expected
1105 echo '+modified file' >> $testroot/stdout.expected
1106 echo -n 'blob - ' >> $testroot/stdout.expected
1107 got tree -r $testroot/repo -i -c $first_commit \
1108 | grep 'beta$' | cut -d' ' -f 1 \
1109 >> $testroot/stdout.expected
1110 echo 'blob + /dev/null' >> $testroot/stdout.expected
1111 echo '--- beta' >> $testroot/stdout.expected
1112 echo '+++ /dev/null' >> $testroot/stdout.expected
1113 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1114 echo '-beta' >> $testroot/stdout.expected
1115 echo 'blob - /dev/null' >> $testroot/stdout.expected
1116 echo -n 'blob + ' >> $testroot/stdout.expected
1117 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1118 echo '--- /dev/null' >> $testroot/stdout.expected
1119 echo '+++ foo' >> $testroot/stdout.expected
1120 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1121 echo '+new file' >> $testroot/stdout.expected
1123 cmp -s $testroot/stdout.expected $testroot/stdout
1124 ret="$?"
1125 if [ "$ret" != "0" ]; then
1126 diff -u $testroot/stdout.expected $testroot/stdout
1127 test_done "$testroot" "$ret"
1128 return 1
1131 echo 'A epsilon/new' > $testroot/stdout.expected
1132 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1133 echo 'M gamma/delta' >> $testroot/stdout.expected
1135 (cd $testroot/wt && got status > $testroot/stdout)
1136 cmp -s $testroot/stdout.expected $testroot/stdout
1137 ret="$?"
1138 if [ "$ret" != "0" ]; then
1139 diff -u $testroot/stdout.expected $testroot/stdout
1141 test_done "$testroot" "$ret"
1144 function test_stage_patch {
1145 local testroot=`test_init stage_patch`
1147 jot 16 > $testroot/repo/numbers
1148 (cd $testroot/repo && git add numbers)
1149 git_commit $testroot/repo -m "added numbers file"
1150 local commit_id=`git_show_head $testroot/repo`
1152 got checkout $testroot/repo $testroot/wt > /dev/null
1153 ret="$?"
1154 if [ "$ret" != "0" ]; then
1155 test_done "$testroot" "$ret"
1156 return 1
1159 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1160 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1161 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1163 # don't stage any hunks
1164 printf "n\nn\nn\n" > $testroot/patchscript
1165 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1166 numbers > $testroot/stdout)
1167 ret="$?"
1168 if [ "$ret" != "0" ]; then
1169 echo "got stage command failed unexpectedly" >&2
1170 test_done "$testroot" "1"
1171 return 1
1173 cat > $testroot/stdout.expected <<EOF
1174 -----------------------------------------------
1175 @@ -1,5 +1,5 @@
1182 -----------------------------------------------
1183 M numbers
1184 stage this change? [y/n/q] n
1185 -----------------------------------------------
1186 @@ -4,7 +4,7 @@
1195 -----------------------------------------------
1196 M numbers
1197 stage this change? [y/n/q] n
1198 -----------------------------------------------
1199 @@ -13,4 +13,4 @@
1203 -16
1205 -----------------------------------------------
1206 M numbers
1207 stage this change? [y/n/q] n
1208 EOF
1209 cmp -s $testroot/stdout.expected $testroot/stdout
1210 ret="$?"
1211 if [ "$ret" != "0" ]; then
1212 diff -u $testroot/stdout.expected $testroot/stdout
1213 test_done "$testroot" "$ret"
1214 return 1
1217 (cd $testroot/wt && got status > $testroot/stdout)
1218 echo "M numbers" > $testroot/stdout.expected
1219 cmp -s $testroot/stdout.expected $testroot/stdout
1220 ret="$?"
1221 if [ "$ret" != "0" ]; then
1222 diff -u $testroot/stdout.expected $testroot/stdout
1223 test_done "$testroot" "$ret"
1224 return 1
1227 # stage middle hunk
1228 printf "n\ny\nn\n" > $testroot/patchscript
1229 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1230 numbers > $testroot/stdout)
1232 cat > $testroot/stdout.expected <<EOF
1233 -----------------------------------------------
1234 @@ -1,5 +1,5 @@
1241 -----------------------------------------------
1242 M numbers
1243 stage this change? [y/n/q] n
1244 -----------------------------------------------
1245 @@ -4,7 +4,7 @@
1254 -----------------------------------------------
1255 M numbers
1256 stage this change? [y/n/q] y
1257 -----------------------------------------------
1258 @@ -13,4 +13,4 @@
1262 -16
1264 -----------------------------------------------
1265 M numbers
1266 stage this change? [y/n/q] n
1267 EOF
1268 cmp -s $testroot/stdout.expected $testroot/stdout
1269 ret="$?"
1270 if [ "$ret" != "0" ]; then
1271 diff -u $testroot/stdout.expected $testroot/stdout
1272 test_done "$testroot" "$ret"
1273 return 1
1276 (cd $testroot/wt && got status > $testroot/stdout)
1277 echo "MM numbers" > $testroot/stdout.expected
1278 cmp -s $testroot/stdout.expected $testroot/stdout
1279 ret="$?"
1280 if [ "$ret" != "0" ]; then
1281 diff -u $testroot/stdout.expected $testroot/stdout
1282 test_done "$testroot" "$ret"
1283 return 1
1286 (cd $testroot/wt && got diff -s > $testroot/stdout)
1288 echo "diff $commit_id $testroot/wt (staged changes)" \
1289 > $testroot/stdout.expected
1290 echo -n 'blob - ' >> $testroot/stdout.expected
1291 got tree -r $testroot/repo -i -c $commit_id \
1292 | grep 'numbers$' | cut -d' ' -f 1 \
1293 >> $testroot/stdout.expected
1294 echo -n 'blob + ' >> $testroot/stdout.expected
1295 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1296 >> $testroot/stdout.expected
1297 echo "--- numbers" >> $testroot/stdout.expected
1298 echo "+++ numbers" >> $testroot/stdout.expected
1299 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1300 echo " 4" >> $testroot/stdout.expected
1301 echo " 5" >> $testroot/stdout.expected
1302 echo " 6" >> $testroot/stdout.expected
1303 echo "-7" >> $testroot/stdout.expected
1304 echo "+b" >> $testroot/stdout.expected
1305 echo " 8" >> $testroot/stdout.expected
1306 echo " 9" >> $testroot/stdout.expected
1307 echo " 10" >> $testroot/stdout.expected
1308 cmp -s $testroot/stdout.expected $testroot/stdout
1309 ret="$?"
1310 if [ "$ret" != "0" ]; then
1311 diff -u $testroot/stdout.expected $testroot/stdout
1312 test_done "$testroot" "$ret"
1313 return 1
1316 (cd $testroot/wt && got unstage >/dev/null)
1317 ret="$?"
1318 if [ "$ret" != "0" ]; then
1319 echo "got stage command failed unexpectedly" >&2
1320 test_done "$testroot" "1"
1321 return 1
1323 (cd $testroot/wt && got status > $testroot/stdout)
1324 echo "M numbers" > $testroot/stdout.expected
1325 cmp -s $testroot/stdout.expected $testroot/stdout
1326 ret="$?"
1327 if [ "$ret" != "0" ]; then
1328 diff -u $testroot/stdout.expected $testroot/stdout
1329 test_done "$testroot" "$ret"
1330 return 1
1333 # stage last hunk
1334 printf "n\nn\ny\n" > $testroot/patchscript
1335 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1336 numbers > $testroot/stdout)
1338 cat > $testroot/stdout.expected <<EOF
1339 -----------------------------------------------
1340 @@ -1,5 +1,5 @@
1347 -----------------------------------------------
1348 M numbers
1349 stage this change? [y/n/q] n
1350 -----------------------------------------------
1351 @@ -4,7 +4,7 @@
1360 -----------------------------------------------
1361 M numbers
1362 stage this change? [y/n/q] n
1363 -----------------------------------------------
1364 @@ -13,4 +13,4 @@
1368 -16
1370 -----------------------------------------------
1371 M numbers
1372 stage this change? [y/n/q] y
1373 EOF
1374 cmp -s $testroot/stdout.expected $testroot/stdout
1375 ret="$?"
1376 if [ "$ret" != "0" ]; then
1377 diff -u $testroot/stdout.expected $testroot/stdout
1378 test_done "$testroot" "$ret"
1379 return 1
1382 (cd $testroot/wt && got status > $testroot/stdout)
1383 echo "MM numbers" > $testroot/stdout.expected
1384 cmp -s $testroot/stdout.expected $testroot/stdout
1385 ret="$?"
1386 if [ "$ret" != "0" ]; then
1387 diff -u $testroot/stdout.expected $testroot/stdout
1388 test_done "$testroot" "$ret"
1389 return 1
1392 (cd $testroot/wt && got diff -s > $testroot/stdout)
1394 echo "diff $commit_id $testroot/wt (staged changes)" \
1395 > $testroot/stdout.expected
1396 echo -n 'blob - ' >> $testroot/stdout.expected
1397 got tree -r $testroot/repo -i -c $commit_id \
1398 | grep 'numbers$' | cut -d' ' -f 1 \
1399 >> $testroot/stdout.expected
1400 echo -n 'blob + ' >> $testroot/stdout.expected
1401 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1402 >> $testroot/stdout.expected
1403 echo "--- numbers" >> $testroot/stdout.expected
1404 echo "+++ numbers" >> $testroot/stdout.expected
1405 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1406 echo " 13" >> $testroot/stdout.expected
1407 echo " 14" >> $testroot/stdout.expected
1408 echo " 15" >> $testroot/stdout.expected
1409 echo "-16" >> $testroot/stdout.expected
1410 echo "+c" >> $testroot/stdout.expected
1411 cmp -s $testroot/stdout.expected $testroot/stdout
1412 ret="$?"
1413 if [ "$ret" != "0" ]; then
1414 diff -u $testroot/stdout.expected $testroot/stdout
1416 test_done "$testroot" "$ret"
1419 function test_stage_patch_added {
1420 local testroot=`test_init stage_patch_added`
1421 local commit_id=`git_show_head $testroot/repo`
1423 got checkout $testroot/repo $testroot/wt > /dev/null
1424 ret="$?"
1425 if [ "$ret" != "0" ]; then
1426 test_done "$testroot" "$ret"
1427 return 1
1430 echo "new" > $testroot/wt/epsilon/new
1431 (cd $testroot/wt && got add epsilon/new > /dev/null)
1433 printf "y\n" > $testroot/patchscript
1434 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1435 epsilon/new > $testroot/stdout)
1437 echo "A epsilon/new" > $testroot/stdout.expected
1438 echo "stage this addition? [y/n/q] y" >> $testroot/stdout.expected
1439 cmp -s $testroot/stdout.expected $testroot/stdout
1440 ret="$?"
1441 if [ "$ret" != "0" ]; then
1442 diff -u $testroot/stdout.expected $testroot/stdout
1443 test_done "$testroot" "$ret"
1444 return 1
1447 (cd $testroot/wt && got status > $testroot/stdout)
1448 echo " A epsilon/new" > $testroot/stdout.expected
1449 cmp -s $testroot/stdout.expected $testroot/stdout
1450 ret="$?"
1451 if [ "$ret" != "0" ]; then
1452 diff -u $testroot/stdout.expected $testroot/stdout
1453 test_done "$testroot" "$ret"
1454 return 1
1457 (cd $testroot/wt && got diff -s > $testroot/stdout)
1459 echo "diff $commit_id $testroot/wt (staged changes)" \
1460 > $testroot/stdout.expected
1461 echo 'blob - /dev/null' >> $testroot/stdout.expected
1462 echo -n 'blob + ' >> $testroot/stdout.expected
1463 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1464 >> $testroot/stdout.expected
1465 echo "--- /dev/null" >> $testroot/stdout.expected
1466 echo "+++ epsilon/new" >> $testroot/stdout.expected
1467 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1468 echo "+new" >> $testroot/stdout.expected
1469 cmp -s $testroot/stdout.expected $testroot/stdout
1470 ret="$?"
1471 if [ "$ret" != "0" ]; then
1472 diff -u $testroot/stdout.expected $testroot/stdout
1474 test_done "$testroot" "$ret"
1477 function test_stage_patch_removed {
1478 local testroot=`test_init stage_patch_removed`
1479 local commit_id=`git_show_head $testroot/repo`
1481 got checkout $testroot/repo $testroot/wt > /dev/null
1482 ret="$?"
1483 if [ "$ret" != "0" ]; then
1484 test_done "$testroot" "$ret"
1485 return 1
1488 (cd $testroot/wt && got rm beta > /dev/null)
1490 printf "y\n" > $testroot/patchscript
1491 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1492 beta > $testroot/stdout)
1494 echo -n > $testroot/stdout.expected
1496 echo "D beta" > $testroot/stdout.expected
1497 echo "stage deletion? [y/n/q] y" >> $testroot/stdout.expected
1498 cmp -s $testroot/stdout.expected $testroot/stdout
1499 ret="$?"
1500 if [ "$ret" != "0" ]; then
1501 diff -u $testroot/stdout.expected $testroot/stdout
1502 test_done "$testroot" "$ret"
1503 return 1
1506 (cd $testroot/wt && got status > $testroot/stdout)
1507 echo " D beta" > $testroot/stdout.expected
1508 cmp -s $testroot/stdout.expected $testroot/stdout
1509 ret="$?"
1510 if [ "$ret" != "0" ]; then
1511 diff -u $testroot/stdout.expected $testroot/stdout
1512 test_done "$testroot" "$ret"
1513 return 1
1516 (cd $testroot/wt && got diff -s > $testroot/stdout)
1518 echo "diff $commit_id $testroot/wt (staged changes)" \
1519 > $testroot/stdout.expected
1520 echo -n 'blob - ' >> $testroot/stdout.expected
1521 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
1522 >> $testroot/stdout.expected
1523 echo 'blob + /dev/null' >> $testroot/stdout.expected
1524 echo "--- beta" >> $testroot/stdout.expected
1525 echo "+++ /dev/null" >> $testroot/stdout.expected
1526 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
1527 echo "-beta" >> $testroot/stdout.expected
1528 cmp -s $testroot/stdout.expected $testroot/stdout
1529 ret="$?"
1530 if [ "$ret" != "0" ]; then
1531 diff -u $testroot/stdout.expected $testroot/stdout
1533 test_done "$testroot" "$ret"
1536 function test_stage_patch_quit {
1537 local testroot=`test_init stage_patch_quit`
1539 jot 16 > $testroot/repo/numbers
1540 (cd $testroot/repo && git add numbers)
1541 git_commit $testroot/repo -m "added numbers file"
1542 local commit_id=`git_show_head $testroot/repo`
1544 got checkout $testroot/repo $testroot/wt > /dev/null
1545 ret="$?"
1546 if [ "$ret" != "0" ]; then
1547 test_done "$testroot" "$ret"
1548 return 1
1551 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1552 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1553 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1555 # stage first hunk and quit; and don't pass a path argument
1556 printf "y\nq\n" > $testroot/patchscript
1557 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1558 > $testroot/stdout)
1559 ret="$?"
1560 if [ "$ret" != "0" ]; then
1561 echo "got stage command failed unexpectedly" >&2
1562 test_done "$testroot" "1"
1563 return 1
1565 cat > $testroot/stdout.expected <<EOF
1566 -----------------------------------------------
1567 @@ -1,5 +1,5 @@
1574 -----------------------------------------------
1575 M numbers
1576 stage this change? [y/n/q] y
1577 -----------------------------------------------
1578 @@ -4,7 +4,7 @@
1587 -----------------------------------------------
1588 M numbers
1589 stage this change? [y/n/q] q
1590 EOF
1591 cmp -s $testroot/stdout.expected $testroot/stdout
1592 ret="$?"
1593 if [ "$ret" != "0" ]; then
1594 diff -u $testroot/stdout.expected $testroot/stdout
1595 test_done "$testroot" "$ret"
1596 return 1
1599 (cd $testroot/wt && got status > $testroot/stdout)
1600 echo "MM numbers" > $testroot/stdout.expected
1601 cmp -s $testroot/stdout.expected $testroot/stdout
1602 ret="$?"
1603 if [ "$ret" != "0" ]; then
1604 diff -u $testroot/stdout.expected $testroot/stdout
1605 test_done "$testroot" "$ret"
1606 return 1
1609 (cd $testroot/wt && got diff -s > $testroot/stdout)
1611 echo "diff $commit_id $testroot/wt (staged changes)" \
1612 > $testroot/stdout.expected
1613 echo -n 'blob - ' >> $testroot/stdout.expected
1614 got tree -r $testroot/repo -i -c $commit_id \
1615 | grep 'numbers$' | cut -d' ' -f 1 \
1616 >> $testroot/stdout.expected
1617 echo -n 'blob + ' >> $testroot/stdout.expected
1618 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1619 >> $testroot/stdout.expected
1620 echo "--- numbers" >> $testroot/stdout.expected
1621 echo "+++ numbers" >> $testroot/stdout.expected
1622 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
1623 echo " 1" >> $testroot/stdout.expected
1624 echo "-2" >> $testroot/stdout.expected
1625 echo "+a" >> $testroot/stdout.expected
1626 echo " 3" >> $testroot/stdout.expected
1627 echo " 4" >> $testroot/stdout.expected
1628 echo " 5" >> $testroot/stdout.expected
1629 cmp -s $testroot/stdout.expected $testroot/stdout
1630 ret="$?"
1631 if [ "$ret" != "0" ]; then
1632 diff -u $testroot/stdout.expected $testroot/stdout
1634 test_done "$testroot" "$ret"
1638 run_test test_stage_basic
1639 run_test test_stage_no_changes
1640 run_test test_stage_list
1641 run_test test_stage_conflict
1642 run_test test_stage_out_of_date
1643 run_test test_double_stage
1644 run_test test_stage_status
1645 run_test test_stage_add_already_staged_file
1646 run_test test_stage_rm_already_staged_file
1647 run_test test_stage_revert
1648 run_test test_stage_diff
1649 run_test test_stage_histedit
1650 run_test test_stage_rebase
1651 run_test test_stage_update
1652 run_test test_stage_commit_non_staged
1653 run_test test_stage_commit
1654 run_test test_stage_patch
1655 run_test test_stage_patch_added
1656 run_test test_stage_patch_removed
1657 run_test test_stage_patch_quit