Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_stage_basic {
20 local testroot=`test_init stage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified file" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta > /dev/null)
31 echo "new file" > $testroot/wt/foo
32 (cd $testroot/wt && got add foo > /dev/null)
34 echo ' M alpha' > $testroot/stdout.expected
35 echo ' D beta' >> $testroot/stdout.expected
36 echo ' A foo' >> $testroot/stdout.expected
37 (cd $testroot/wt && got stage > $testroot/stdout)
39 cmp -s $testroot/stdout.expected $testroot/stdout
40 ret="$?"
41 if [ "$ret" != "0" ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
43 fi
44 test_done "$testroot" "$ret"
45 }
47 function test_stage_no_changes {
48 local testroot=`test_init stage_no_changes`
50 got checkout $testroot/repo $testroot/wt > /dev/null
51 ret="$?"
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
54 return 1
55 fi
57 (cd $testroot/wt && got stage alpha beta > $testroot/stdout \
58 2> $testroot/stderr)
59 ret="$?"
60 if [ "$ret" == "0" ]; then
61 echo "got stage command succeeded unexpectedly" >&2
62 test_done "$testroot" "1"
63 return 1
64 fi
66 echo "got: no changes to stage" > $testroot/stderr.expected
68 cmp -s $testroot/stderr.expected $testroot/stderr
69 ret="$?"
70 if [ "$ret" != "0" ]; then
71 diff -u $testroot/stderr.expected $testroot/stderr
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 echo -n > $testroot/stdout.expected
77 cmp -s $testroot/stdout.expected $testroot/stdout
78 ret="$?"
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
81 fi
82 test_done "$testroot" "$ret"
83 }
85 function test_stage_unversioned {
86 local testroot=`test_init stage_unversioned`
88 got checkout $testroot/repo $testroot/wt > /dev/null
89 ret="$?"
90 if [ "$ret" != "0" ]; then
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 echo "modified file" > $testroot/wt/alpha
96 touch $testroot/wt/unversioned-file
98 (cd $testroot/wt && got status > $testroot/stdout)
99 echo "M alpha" > $testroot/stdout.expected
100 echo "? unversioned-file" >> $testroot/stdout.expected
101 cmp -s $testroot/stdout.expected $testroot/stdout
102 ret="$?"
103 if [ "$ret" != "0" ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/wt && got stage > $testroot/stdout)
110 ret="$?"
111 if [ "$ret" != "0" ]; then
112 echo "got stage command failed unexpectedly" >&2
113 test_done "$testroot" "$ret"
114 return 1
115 fi
117 echo " M alpha" > $testroot/stdout.expected
118 cmp -s $testroot/stdout.expected $testroot/stdout
119 ret="$?"
120 if [ "$ret" != "0" ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 test_done "$testroot" "$ret"
123 return 1
124 fi
126 echo "modified file again" > $testroot/wt/alpha
128 (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
129 2> $testroot/stderr)
130 ret="$?"
131 if [ "$ret" == "0" ]; then
132 echo "got stage command succeed unexpectedly" >&2
133 test_done "$testroot" "1"
134 return 1
135 fi
137 echo "got: no changes to stage" > $testroot/stderr.expected
138 cmp -s $testroot/stderr.expected $testroot/stderr
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 diff -u $testroot/stderr.expected $testroot/stderr
142 fi
143 test_done "$testroot" "$ret"
147 function test_stage_nonexistent {
148 local testroot=`test_init stage_nonexistent`
150 got checkout $testroot/repo $testroot/wt > /dev/null
151 ret="$?"
152 if [ "$ret" != "0" ]; then
153 test_done "$testroot" "$ret"
154 return 1
155 fi
157 (cd $testroot/wt && got stage nonexistent-file \
158 > $testroot/stdout 2> $testroot/stderr)
159 echo "got: no changes to stage" > $testroot/stderr.expected
160 cmp -s $testroot/stderr.expected $testroot/stderr
161 ret="$?"
162 if [ "$ret" != "0" ]; then
163 diff -u $testroot/stderr.expected $testroot/stderr
164 fi
165 test_done "$testroot" "$ret"
168 function test_stage_list {
169 local testroot=`test_init stage_list`
171 got checkout $testroot/repo $testroot/wt > /dev/null
172 ret="$?"
173 if [ "$ret" != "0" ]; then
174 test_done "$testroot" "$ret"
175 return 1
176 fi
178 echo "modified file" > $testroot/wt/alpha
179 (cd $testroot/wt && got rm beta > /dev/null)
180 echo "new file" > $testroot/wt/foo
181 (cd $testroot/wt && got add foo > /dev/null)
183 echo ' M alpha' > $testroot/stdout.expected
184 echo ' D beta' >> $testroot/stdout.expected
185 echo ' A foo' >> $testroot/stdout.expected
186 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
188 (cd $testroot/wt && got stage -l > $testroot/stdout)
189 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
190 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
191 echo " M alpha" >> $testroot/stdout.expected
192 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
193 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
194 echo " D beta" >> $testroot/stdout.expected
195 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
196 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
197 echo " A foo" >> $testroot/stdout.expected
198 cmp -s $testroot/stdout.expected $testroot/stdout
199 ret="$?"
200 if [ "$ret" != "0" ]; then
201 diff -u $testroot/stdout.expected $testroot/stdout
202 test_done "$testroot" "$ret"
203 return 1
204 fi
206 (cd $testroot/wt && got stage -l epsilon nonexistent \
207 > $testroot/stdout)
209 echo -n > $testroot/stdout.expected
210 cmp -s $testroot/stdout.expected $testroot/stdout
211 ret="$?"
212 if [ "$ret" != "0" ]; then
213 diff -u $testroot/stdout.expected $testroot/stdout
214 test_done "$testroot" "$ret"
215 return 1
216 fi
218 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
220 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
221 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
222 echo " M alpha" >> $testroot/stdout.expected
223 cmp -s $testroot/stdout.expected $testroot/stdout
224 ret="$?"
225 if [ "$ret" != "0" ]; then
226 diff -u $testroot/stdout.expected $testroot/stdout
227 fi
228 test_done "$testroot" "$ret"
232 function test_stage_conflict {
233 local testroot=`test_init stage_conflict`
234 local initial_commit=`git_show_head $testroot/repo`
236 got checkout $testroot/repo $testroot/wt > /dev/null
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 test_done "$testroot" "$ret"
240 return 1
241 fi
243 echo "modified alpha" > $testroot/wt/alpha
244 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
246 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
248 echo "modified alpha, too" > $testroot/wt/alpha
250 echo "C alpha" > $testroot/stdout.expected
251 echo -n "Updated to commit " >> $testroot/stdout.expected
252 git_show_head $testroot/repo >> $testroot/stdout.expected
253 echo >> $testroot/stdout.expected
255 (cd $testroot/wt && got update > $testroot/stdout)
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
265 (cd $testroot/wt && got stage alpha > $testroot/stdout \
266 2> $testroot/stderr)
267 ret="$?"
268 if [ "$ret" == "0" ]; then
269 echo "got stage command succeeded unexpectedly" >&2
270 test_done "$testroot" "1"
271 return 1
272 fi
274 echo -n > $testroot/stdout.expected
275 echo "got: alpha: cannot stage file in conflicted status" \
276 > $testroot/stderr.expected
278 cmp -s $testroot/stdout.expected $testroot/stdout
279 ret="$?"
280 if [ "$ret" != "0" ]; then
281 diff -u $testroot/stdout.expected $testroot/stdout
282 test_done "$testroot" "$ret"
283 return 1
284 fi
285 cmp -s $testroot/stderr.expected $testroot/stderr
286 ret="$?"
287 if [ "$ret" != "0" ]; then
288 diff -u $testroot/stderr.expected $testroot/stderr
289 fi
290 test_done "$testroot" "$ret"
293 function test_stage_out_of_date {
294 local testroot=`test_init stage_out_of_date`
295 local initial_commit=`git_show_head $testroot/repo`
297 got checkout $testroot/repo $testroot/wt > /dev/null
298 ret="$?"
299 if [ "$ret" != "0" ]; then
300 test_done "$testroot" "$ret"
301 return 1
302 fi
304 echo "modified alpha" > $testroot/wt/alpha
305 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
307 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
309 echo "modified alpha again" > $testroot/wt/alpha
310 (cd $testroot/wt && got stage alpha > $testroot/stdout \
311 2> $testroot/stderr)
312 ret="$?"
313 if [ "$ret" == "0" ]; then
314 echo "got stage command succeeded unexpectedly" >&2
315 test_done "$testroot" "1"
316 return 1
317 fi
319 echo -n > $testroot/stdout.expected
320 echo "got: work tree must be updated before changes can be staged" \
321 > $testroot/stderr.expected
323 cmp -s $testroot/stdout.expected $testroot/stdout
324 ret="$?"
325 if [ "$ret" != "0" ]; then
326 diff -u $testroot/stdout.expected $testroot/stdout
327 test_done "$testroot" "$ret"
328 return 1
329 fi
330 cmp -s $testroot/stderr.expected $testroot/stderr
331 ret="$?"
332 if [ "$ret" != "0" ]; then
333 diff -u $testroot/stderr.expected $testroot/stderr
334 fi
335 test_done "$testroot" "$ret"
339 function test_double_stage {
340 local testroot=`test_init double_stage`
342 got checkout $testroot/repo $testroot/wt > /dev/null
343 ret="$?"
344 if [ "$ret" != "0" ]; then
345 test_done "$testroot" "$ret"
346 return 1
347 fi
348 echo "modified file" > $testroot/wt/alpha
349 (cd $testroot/wt && got rm beta > /dev/null)
350 echo "new file" > $testroot/wt/foo
351 (cd $testroot/wt && got add foo > /dev/null)
352 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
354 echo "got: alpha: no changes to stage" > $testroot/stderr.expected
355 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
356 cmp -s $testroot/stderr.expected $testroot/stderr
357 ret="$?"
358 if [ "$ret" != "0" ]; then
359 diff -u $testroot/stderr.expected $testroot/stderr
360 test_done "$testroot" "$ret"
361 return 1
362 fi
364 (cd $testroot/wt && got stage beta > $testroot/stdout)
365 ret="$?"
366 if [ "$ret" != "0" ]; then
367 echo "got stage command failed unexpectedly" >&2
368 test_done "$testroot" "1"
369 return 1
370 fi
371 echo -n > $testroot/stdout.expected
372 cmp -s $testroot/stdout.expected $testroot/stdout
373 ret="$?"
374 if [ "$ret" != "0" ]; then
375 diff -u $testroot/stdout.expected $testroot/stdout
376 test_done "$testroot" "$ret"
377 return 1
378 fi
380 echo "got: foo: no changes to stage" > $testroot/stderr.expected
381 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
382 cmp -s $testroot/stderr.expected $testroot/stderr
383 ret="$?"
384 if [ "$ret" != "0" ]; then
385 diff -u $testroot/stderr.expected $testroot/stderr
386 test_done "$testroot" "$ret"
387 return 1
388 fi
390 echo "modified file again" > $testroot/wt/alpha
391 echo "modified new file" > $testroot/wt/foo
393 echo ' M alpha' > $testroot/stdout.expected
394 echo ' A foo' >> $testroot/stdout.expected
395 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
396 cmp -s $testroot/stdout.expected $testroot/stdout
397 ret="$?"
398 if [ "$ret" != "0" ]; then
399 diff -u $testroot/stdout.expected $testroot/stdout
400 test_done "$testroot" "$ret"
401 return 1
402 fi
404 echo ' M alpha' > $testroot/stdout.expected
405 echo ' D beta' >> $testroot/stdout.expected
406 echo ' A foo' >> $testroot/stdout.expected
408 (cd $testroot/wt && got status > $testroot/stdout)
409 cmp -s $testroot/stdout.expected $testroot/stdout
410 ret="$?"
411 if [ "$ret" != "0" ]; then
412 diff -u $testroot/stdout.expected $testroot/stdout
413 fi
414 test_done "$testroot" "$ret"
417 function test_stage_status {
418 local testroot=`test_init stage_status`
420 got checkout $testroot/repo $testroot/wt > /dev/null
421 ret="$?"
422 if [ "$ret" != "0" ]; then
423 test_done "$testroot" "$ret"
424 return 1
425 fi
427 echo "modified file" > $testroot/wt/alpha
428 (cd $testroot/wt && got rm beta > /dev/null)
429 echo "new file" > $testroot/wt/foo
430 (cd $testroot/wt && got add foo > /dev/null)
431 echo "new file" > $testroot/wt/epsilon/new
432 (cd $testroot/wt && got add epsilon/new > /dev/null)
433 echo "modified file" > $testroot/wt/epsilon/zeta
434 (cd $testroot/wt && got rm gamma/delta > /dev/null)
436 echo ' M alpha' > $testroot/stdout.expected
437 echo ' D beta' >> $testroot/stdout.expected
438 echo 'A epsilon/new' >> $testroot/stdout.expected
439 echo 'M epsilon/zeta' >> $testroot/stdout.expected
440 echo ' A foo' >> $testroot/stdout.expected
441 echo 'D gamma/delta' >> $testroot/stdout.expected
442 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
444 (cd $testroot/wt && got status > $testroot/stdout)
445 cmp -s $testroot/stdout.expected $testroot/stdout
446 ret="$?"
447 if [ "$ret" != "0" ]; then
448 diff -u $testroot/stdout.expected $testroot/stdout
449 test_done "$testroot" "$ret"
450 return 1
451 fi
453 echo "modified file again" >> $testroot/wt/alpha
454 echo "modified added file again" >> $testroot/wt/foo
456 echo 'MM alpha' > $testroot/stdout.expected
457 echo ' D beta' >> $testroot/stdout.expected
458 echo 'A epsilon/new' >> $testroot/stdout.expected
459 echo 'M epsilon/zeta' >> $testroot/stdout.expected
460 echo 'MA foo' >> $testroot/stdout.expected
461 echo 'D gamma/delta' >> $testroot/stdout.expected
463 (cd $testroot/wt && got status > $testroot/stdout)
464 cmp -s $testroot/stdout.expected $testroot/stdout
465 ret="$?"
466 if [ "$ret" != "0" ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 # test no-op change of added file with new stat(2) timestamp
473 echo "new file" > $testroot/wt/foo
474 echo ' A foo' > $testroot/stdout.expected
475 (cd $testroot/wt && got status foo > $testroot/stdout)
476 cmp -s $testroot/stdout.expected $testroot/stdout
477 ret="$?"
478 if [ "$ret" != "0" ]; then
479 diff -u $testroot/stdout.expected $testroot/stdout
480 test_done "$testroot" "$ret"
481 return 1
482 fi
484 # test staged deleted file which is restored on disk
485 echo "new file" > $testroot/wt/beta
486 echo ' D beta' > $testroot/stdout.expected
487 (cd $testroot/wt && got status beta > $testroot/stdout)
488 cmp -s $testroot/stdout.expected $testroot/stdout
489 ret="$?"
490 if [ "$ret" != "0" ]; then
491 diff -u $testroot/stdout.expected $testroot/stdout
492 fi
493 test_done "$testroot" "$ret"
497 function test_stage_add_already_staged_file {
498 local testroot=`test_init stage_add_already_staged_file`
500 got checkout $testroot/repo $testroot/wt > /dev/null
501 ret="$?"
502 if [ "$ret" != "0" ]; then
503 test_done "$testroot" "$ret"
504 return 1
505 fi
507 echo "modified file" > $testroot/wt/alpha
508 (cd $testroot/wt && got rm beta > /dev/null)
509 echo "new file" > $testroot/wt/foo
510 (cd $testroot/wt && got add foo > /dev/null)
512 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
514 echo -n > $testroot/stdout.expected
515 for f in alpha beta foo; do
516 (cd $testroot/wt && got add $f \
517 > $testroot/stdout 2> $testroot/stderr)
518 echo "got: $f: file has unexpected status" \
519 > $testroot/stderr.expected
520 cmp -s $testroot/stderr.expected $testroot/stderr
521 ret="$?"
522 if [ "$ret" != "0" ]; then
523 diff -u $testroot/stderr.expected $testroot/stderr
524 test_done "$testroot" "$ret"
525 return 1
526 fi
527 cmp -s $testroot/stdout.expected $testroot/stdout
528 ret="$?"
529 if [ "$ret" != "0" ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 test_done "$testroot" "$ret"
532 return 1
533 fi
534 done
536 echo ' M alpha' > $testroot/stdout.expected
537 echo ' D beta' >> $testroot/stdout.expected
538 echo ' A foo' >> $testroot/stdout.expected
540 (cd $testroot/wt && got status > $testroot/stdout)
541 cmp -s $testroot/stdout.expected $testroot/stdout
542 ret="$?"
543 if [ "$ret" != "0" ]; then
544 diff -u $testroot/stdout.expected $testroot/stdout
545 fi
546 test_done "$testroot" "$ret"
549 function test_stage_rm_already_staged_file {
550 local testroot=`test_init stage_rm_already_staged_file`
552 got checkout $testroot/repo $testroot/wt > /dev/null
553 ret="$?"
554 if [ "$ret" != "0" ]; then
555 test_done "$testroot" "$ret"
556 return 1
557 fi
559 echo "modified file" > $testroot/wt/alpha
560 (cd $testroot/wt && got rm beta > /dev/null)
561 echo "new file" > $testroot/wt/foo
562 (cd $testroot/wt && got add foo > /dev/null)
564 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
566 (cd $testroot/wt && got rm beta \
567 > $testroot/stdout 2> $testroot/stderr)
568 ret="$?"
569 if [ "$ret" != "0" ]; then
570 echo "got rm command failed unexpectedly" >&2
571 test_done "$testroot" "1"
572 return 1
573 fi
574 echo -n > $testroot/stdout.expected
575 cmp -s $testroot/stdout.expected $testroot/stdout
576 ret="$?"
577 if [ "$ret" != "0" ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 test_done "$testroot" "$ret"
580 return 1
581 fi
582 echo -n > $testroot/stderr.expected
583 cmp -s $testroot/stderr.expected $testroot/stderr
584 ret="$?"
585 if [ "$ret" != "0" ]; then
586 diff -u $testroot/stderr.expected $testroot/stderr
587 test_done "$testroot" "$ret"
588 return 1
589 fi
591 for f in alpha foo; do
592 echo "got: $f: file is staged" > $testroot/stderr.expected
593 (cd $testroot/wt && got rm $f \
594 > $testroot/stdout 2> $testroot/stderr)
595 ret="$?"
596 if [ "$ret" == "0" ]; then
597 echo "got rm command succeeded unexpectedly" >&2
598 test_done "$testroot" "1"
599 return 1
600 fi
601 cmp -s $testroot/stderr.expected $testroot/stderr
602 ret="$?"
603 if [ "$ret" != "0" ]; then
604 diff -u $testroot/stderr.expected $testroot/stderr
605 test_done "$testroot" "$ret"
606 return 1
607 fi
608 done
610 echo ' M alpha' > $testroot/stdout.expected
611 echo ' D beta' >> $testroot/stdout.expected
612 echo ' A foo' >> $testroot/stdout.expected
614 (cd $testroot/wt && got status > $testroot/stdout)
615 cmp -s $testroot/stdout.expected $testroot/stdout
616 ret="$?"
617 if [ "$ret" != "0" ]; then
618 diff -u $testroot/stdout.expected $testroot/stdout
619 fi
620 test_done "$testroot" "$ret"
623 function test_stage_revert {
624 local testroot=`test_init stage_revert`
626 got checkout $testroot/repo $testroot/wt > /dev/null
627 ret="$?"
628 if [ "$ret" != "0" ]; then
629 test_done "$testroot" "$ret"
630 return 1
631 fi
633 echo "modified alpha" > $testroot/wt/alpha
634 (cd $testroot/wt && got rm beta > /dev/null)
635 echo "new file" > $testroot/wt/foo
636 (cd $testroot/wt && got add foo > /dev/null)
637 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
639 echo "modified file again" >> $testroot/wt/alpha
640 echo "modified added file again" >> $testroot/wt/foo
642 (cd $testroot/wt && got revert alpha > $testroot/stdout)
643 ret="$?"
644 if [ "$ret" != "0" ]; then
645 echo "revert command failed unexpectedly" >&2
646 test_done "$testroot" "$ret"
647 return 1
648 fi
650 echo "R alpha" > $testroot/stdout.expected
651 cmp -s $testroot/stdout.expected $testroot/stdout
652 ret="$?"
653 if [ "$ret" != "0" ]; then
654 diff -u $testroot/stdout.expected $testroot/stdout
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 echo "modified alpha" > $testroot/content.expected
660 cat $testroot/wt/alpha > $testroot/content
661 cmp -s $testroot/content.expected $testroot/content
662 ret="$?"
663 if [ "$ret" != "0" ]; then
664 diff -u $testroot/content.expected $testroot/content
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 echo ' M alpha' > $testroot/stdout.expected
670 echo ' D beta' >> $testroot/stdout.expected
671 echo 'MA foo' >> $testroot/stdout.expected
672 (cd $testroot/wt && got status > $testroot/stdout)
673 cmp -s $testroot/stdout.expected $testroot/stdout
674 ret="$?"
675 if [ "$ret" != "0" ]; then
676 diff -u $testroot/stdout.expected $testroot/stdout
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 (cd $testroot/wt && got revert alpha > $testroot/stdout)
682 ret="$?"
683 if [ "$ret" != "0" ]; then
684 echo "revert command failed unexpectedly" >&2
685 test_done "$testroot" "$ret"
686 return 1
687 fi
689 echo -n > $testroot/stdout.expected
690 cmp -s $testroot/stdout.expected $testroot/stdout
691 ret="$?"
692 if [ "$ret" != "0" ]; then
693 diff -u $testroot/stdout.expected $testroot/stdout
694 test_done "$testroot" "$ret"
695 return 1
696 fi
698 echo "modified alpha" > $testroot/content.expected
699 cat $testroot/wt/alpha > $testroot/content
700 cmp -s $testroot/content.expected $testroot/content
701 ret="$?"
702 if [ "$ret" != "0" ]; then
703 diff -u $testroot/content.expected $testroot/content
704 test_done "$testroot" "$ret"
705 return 1
706 fi
708 (cd $testroot/wt && got revert beta > $testroot/stdout \
709 2> $testroot/stderr)
710 ret="$?"
711 if [ "$ret" != "0" ]; then
712 echo "revert command failed unexpectedly" >&2
713 test_done "$testroot" "$ret"
714 return 1
715 fi
717 echo -n > $testroot/stdout.expected
718 cmp -s $testroot/stdout.expected $testroot/stdout
719 ret="$?"
720 if [ "$ret" != "0" ]; then
721 diff -u $testroot/stdout.expected $testroot/stdout
722 test_done "$testroot" "$ret"
723 return 1
724 fi
726 echo -n > $testroot/stderr.expected
727 cmp -s $testroot/stderr.expected $testroot/stderr
728 ret="$?"
729 if [ "$ret" != "0" ]; then
730 diff -u $testroot/stderr.expected $testroot/stderr
731 test_done "$testroot" "$ret"
732 return 1
733 fi
735 (cd $testroot/wt && got revert foo > $testroot/stdout)
736 ret="$?"
737 if [ "$ret" != "0" ]; then
738 echo "revert command failed unexpectedly" >&2
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 echo "R foo" > $testroot/stdout.expected
744 cmp -s $testroot/stdout.expected $testroot/stdout
745 ret="$?"
746 if [ "$ret" != "0" ]; then
747 diff -u $testroot/stdout.expected $testroot/stdout
748 test_done "$testroot" "$ret"
749 return 1
750 fi
752 echo "new file" > $testroot/content.expected
753 cat $testroot/wt/foo > $testroot/content
754 cmp -s $testroot/content.expected $testroot/content
755 ret="$?"
756 if [ "$ret" != "0" ]; then
757 diff -u $testroot/content.expected $testroot/content
758 test_done "$testroot" "$ret"
759 return 1
760 fi
762 echo ' M alpha' > $testroot/stdout.expected
763 echo ' D beta' >> $testroot/stdout.expected
764 echo ' A foo' >> $testroot/stdout.expected
765 (cd $testroot/wt && got status > $testroot/stdout)
766 cmp -s $testroot/stdout.expected $testroot/stdout
767 ret="$?"
768 if [ "$ret" != "0" ]; then
769 diff -u $testroot/stdout.expected $testroot/stdout
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 (cd $testroot/wt && got revert foo > $testroot/stdout)
775 ret="$?"
776 if [ "$ret" != "0" ]; then
777 echo "revert command failed unexpectedly" >&2
778 test_done "$testroot" "$ret"
779 return 1
780 fi
782 echo -n > $testroot/stdout.expected
783 cmp -s $testroot/stdout.expected $testroot/stdout
784 ret="$?"
785 if [ "$ret" != "0" ]; then
786 diff -u $testroot/stdout.expected $testroot/stdout
787 test_done "$testroot" "$ret"
788 return 1
789 fi
791 echo "new file" > $testroot/content.expected
792 cat $testroot/wt/foo > $testroot/content
793 cmp -s $testroot/content.expected $testroot/content
794 ret="$?"
795 if [ "$ret" != "0" ]; then
796 diff -u $testroot/content.expected $testroot/content
797 test_done "$testroot" "$ret"
798 return 1
799 fi
801 echo ' M alpha' > $testroot/stdout.expected
802 echo ' D beta' >> $testroot/stdout.expected
803 echo ' A foo' >> $testroot/stdout.expected
804 (cd $testroot/wt && got status > $testroot/stdout)
805 cmp -s $testroot/stdout.expected $testroot/stdout
806 ret="$?"
807 if [ "$ret" != "0" ]; then
808 diff -u $testroot/stdout.expected $testroot/stdout
809 test_done "$testroot" "$ret"
810 return 1
811 fi
813 echo "modified file again" >> $testroot/wt/alpha
814 echo "modified added file again" >> $testroot/wt/foo
816 (cd $testroot/wt && got revert -R . > $testroot/stdout \
817 2> $testroot/stderr)
818 ret="$?"
819 if [ "$ret" != "0" ]; then
820 echo "revert command failed unexpectedly" >&2
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 echo "R alpha" > $testroot/stdout.expected
826 echo "R foo" >> $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 test_done "$testroot" "$ret"
832 return 1
833 fi
835 echo -n > $testroot/stderr.expected
836 cmp -s $testroot/stderr.expected $testroot/stderr
837 ret="$?"
838 if [ "$ret" != "0" ]; then
839 diff -u $testroot/stderr.expected $testroot/stderr
840 test_done "$testroot" "$ret"
841 return 1
842 fi
844 echo ' M alpha' > $testroot/stdout.expected
845 echo ' D beta' >> $testroot/stdout.expected
846 echo ' A foo' >> $testroot/stdout.expected
847 (cd $testroot/wt && got status > $testroot/stdout)
848 cmp -s $testroot/stdout.expected $testroot/stdout
849 ret="$?"
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
852 fi
853 test_done "$testroot" "$ret"
856 function test_stage_diff {
857 local testroot=`test_init stage_diff`
858 local head_commit=`git_show_head $testroot/repo`
860 got checkout $testroot/repo $testroot/wt > /dev/null
861 ret="$?"
862 if [ "$ret" != "0" ]; then
863 test_done "$testroot" "$ret"
864 return 1
865 fi
867 echo "modified file" > $testroot/wt/alpha
868 (cd $testroot/wt && got rm beta > /dev/null)
869 echo "new file" > $testroot/wt/foo
870 (cd $testroot/wt && got add foo > /dev/null)
872 (cd $testroot/wt && got diff -s > $testroot/stdout)
873 echo -n > $testroot/stdout.expected
874 cmp -s $testroot/stdout.expected $testroot/stdout
875 ret="$?"
876 if [ "$ret" != "0" ]; then
877 diff -u $testroot/stdout.expected $testroot/stdout
878 test_done "$testroot" "$ret"
879 return 1
880 fi
882 echo ' M alpha' > $testroot/stdout.expected
883 echo ' D beta' >> $testroot/stdout.expected
884 echo ' A foo' >> $testroot/stdout.expected
885 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
887 (cd $testroot/wt && got diff > $testroot/stdout)
888 echo -n > $testroot/stdout.expected
889 cmp -s $testroot/stdout.expected $testroot/stdout
890 ret="$?"
891 if [ "$ret" != "0" ]; then
892 diff -u $testroot/stdout.expected $testroot/stdout
893 test_done "$testroot" "$ret"
894 return 1
895 fi
897 echo "modified file again" > $testroot/wt/alpha
898 echo "new file changed" > $testroot/wt/foo
900 (cd $testroot/wt && got diff > $testroot/stdout)
902 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
903 echo -n 'blob - ' >> $testroot/stdout.expected
904 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
905 >> $testroot/stdout.expected
906 echo ' (staged)' >> $testroot/stdout.expected
907 echo 'file + alpha' >> $testroot/stdout.expected
908 echo '--- alpha' >> $testroot/stdout.expected
909 echo '+++ alpha' >> $testroot/stdout.expected
910 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
911 echo '-modified file' >> $testroot/stdout.expected
912 echo '+modified file again' >> $testroot/stdout.expected
913 echo -n 'blob - ' >> $testroot/stdout.expected
914 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
915 >> $testroot/stdout.expected
916 echo " (staged)" >> $testroot/stdout.expected
917 echo 'file + foo' >> $testroot/stdout.expected
918 echo '--- foo' >> $testroot/stdout.expected
919 echo '+++ foo' >> $testroot/stdout.expected
920 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
921 echo '-new file' >> $testroot/stdout.expected
922 echo '+new file changed' >> $testroot/stdout.expected
924 cmp -s $testroot/stdout.expected $testroot/stdout
925 ret="$?"
926 if [ "$ret" != "0" ]; then
927 diff -u $testroot/stdout.expected $testroot/stdout
928 test_done "$testroot" "$ret"
929 return 1
930 fi
932 (cd $testroot/wt && got diff -s > $testroot/stdout)
934 echo "diff $head_commit $testroot/wt (staged changes)" \
935 > $testroot/stdout.expected
936 echo -n 'blob - ' >> $testroot/stdout.expected
937 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
938 >> $testroot/stdout.expected
939 echo -n 'blob + ' >> $testroot/stdout.expected
940 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
941 >> $testroot/stdout.expected
942 echo '--- alpha' >> $testroot/stdout.expected
943 echo '+++ alpha' >> $testroot/stdout.expected
944 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
945 echo '-alpha' >> $testroot/stdout.expected
946 echo '+modified file' >> $testroot/stdout.expected
947 echo -n 'blob - ' >> $testroot/stdout.expected
948 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
949 >> $testroot/stdout.expected
950 echo 'blob + /dev/null' >> $testroot/stdout.expected
951 echo '--- beta' >> $testroot/stdout.expected
952 echo '+++ /dev/null' >> $testroot/stdout.expected
953 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
954 echo '-beta' >> $testroot/stdout.expected
955 echo 'blob - /dev/null' >> $testroot/stdout.expected
956 echo -n 'blob + ' >> $testroot/stdout.expected
957 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
958 >> $testroot/stdout.expected
959 echo '--- /dev/null' >> $testroot/stdout.expected
960 echo '+++ foo' >> $testroot/stdout.expected
961 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
962 echo '+new file' >> $testroot/stdout.expected
964 cmp -s $testroot/stdout.expected $testroot/stdout
965 ret="$?"
966 if [ "$ret" != "0" ]; then
967 diff -u $testroot/stdout.expected $testroot/stdout
968 fi
969 test_done "$testroot" "$ret"
973 function test_stage_histedit {
974 local testroot=`test_init stage_histedit`
975 local orig_commit=`git_show_head $testroot/repo`
977 got checkout -c $orig_commit $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 echo "modified alpha on master" > $testroot/repo/alpha
988 (cd $testroot/repo && git rm -q beta)
989 echo "new file on master" > $testroot/repo/epsilon/new
990 (cd $testroot/repo && git add epsilon/new)
991 git_commit $testroot/repo -m "committing changes"
992 local old_commit1=`git_show_head $testroot/repo`
994 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
995 git_commit $testroot/repo -m "committing to zeta on master"
996 local old_commit2=`git_show_head $testroot/repo`
998 echo "pick $old_commit1" > $testroot/histedit-script
999 echo "pick $old_commit2" >> $testroot/histedit-script
1001 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1002 > $testroot/stdout 2> $testroot/stderr)
1003 ret="$?"
1004 if [ "$ret" == "0" ]; then
1005 echo "got histedit command succeeded unexpectedly" >&2
1006 test_done "$testroot" "1"
1007 return 1
1010 echo -n > $testroot/stdout.expected
1011 echo "got: alpha: file is staged" > $testroot/stderr.expected
1013 cmp -s $testroot/stderr.expected $testroot/stderr
1014 ret="$?"
1015 if [ "$ret" != "0" ]; then
1016 diff -u $testroot/stderr.expected $testroot/stderr
1017 test_done "$testroot" "$ret"
1018 return 1
1020 cmp -s $testroot/stdout.expected $testroot/stdout
1021 ret="$?"
1022 if [ "$ret" != "0" ]; then
1023 diff -u $testroot/stdout.expected $testroot/stdout
1025 test_done "$testroot" "$ret"
1029 function test_stage_rebase {
1030 local testroot=`test_init stage_rebase`
1032 (cd $testroot/repo && git checkout -q -b newbranch)
1033 echo "modified delta on branch" > $testroot/repo/gamma/delta
1034 git_commit $testroot/repo -m "committing to delta on newbranch"
1036 echo "modified alpha on branch" > $testroot/repo/alpha
1037 (cd $testroot/repo && git rm -q beta)
1038 echo "new file on branch" > $testroot/repo/epsilon/new
1039 (cd $testroot/repo && git add epsilon/new)
1040 git_commit $testroot/repo -m "committing more changes on newbranch"
1042 local orig_commit1=`git_show_parent_commit $testroot/repo`
1043 local orig_commit2=`git_show_head $testroot/repo`
1045 (cd $testroot/repo && git checkout -q master)
1046 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1047 git_commit $testroot/repo -m "committing to zeta on master"
1048 local master_commit=`git_show_head $testroot/repo`
1050 got checkout $testroot/repo $testroot/wt > /dev/null
1051 ret="$?"
1052 if [ "$ret" != "0" ]; then
1053 test_done "$testroot" "$ret"
1054 return 1
1057 echo "modified file" > $testroot/wt/alpha
1058 (cd $testroot/wt && got stage alpha > /dev/null)
1060 (cd $testroot/wt && got rebase newbranch \
1061 > $testroot/stdout 2> $testroot/stderr)
1062 ret="$?"
1063 if [ "$ret" == "0" ]; then
1064 echo "got rebase command succeeded unexpectedly" >&2
1065 test_done "$testroot" "1"
1066 return 1
1069 echo -n > $testroot/stdout.expected
1070 echo "got: alpha: file is staged" > $testroot/stderr.expected
1072 cmp -s $testroot/stderr.expected $testroot/stderr
1073 ret="$?"
1074 if [ "$ret" != "0" ]; then
1075 diff -u $testroot/stderr.expected $testroot/stderr
1076 test_done "$testroot" "$ret"
1077 return 1
1079 cmp -s $testroot/stdout.expected $testroot/stdout
1080 ret="$?"
1081 if [ "$ret" != "0" ]; then
1082 diff -u $testroot/stdout.expected $testroot/stdout
1084 test_done "$testroot" "$ret"
1087 function test_stage_update {
1088 local testroot=`test_init stage_update`
1090 got checkout $testroot/repo $testroot/wt > /dev/null
1091 ret="$?"
1092 if [ "$ret" != "0" ]; then
1093 test_done "$testroot" "$ret"
1094 return 1
1097 echo "modified file" > $testroot/wt/alpha
1098 (cd $testroot/wt && got stage alpha > /dev/null)
1100 echo "modified alpha" > $testroot/repo/alpha
1101 git_commit $testroot/repo -m "modified alpha"
1103 (cd $testroot/wt && got update > $testroot/stdout \
1104 2> $testroot/stderr)
1105 ret="$?"
1106 if [ "$ret" == "0" ]; then
1107 echo "got update command succeeded unexpectedly" >&2
1108 test_done "$testroot" "1"
1109 return 1
1112 echo -n > $testroot/stdout.expected
1113 echo "got: alpha: file is staged" > $testroot/stderr.expected
1115 cmp -s $testroot/stderr.expected $testroot/stderr
1116 ret="$?"
1117 if [ "$ret" != "0" ]; then
1118 diff -u $testroot/stderr.expected $testroot/stderr
1119 test_done "$testroot" "$ret"
1120 return 1
1122 cmp -s $testroot/stdout.expected $testroot/stdout
1123 ret="$?"
1124 if [ "$ret" != "0" ]; then
1125 diff -u $testroot/stdout.expected $testroot/stdout
1127 test_done "$testroot" "$ret"
1130 function test_stage_commit_non_staged {
1131 local testroot=`test_init stage_commit_non_staged`
1133 got checkout $testroot/repo $testroot/wt > /dev/null
1134 ret="$?"
1135 if [ "$ret" != "0" ]; then
1136 test_done "$testroot" "$ret"
1137 return 1
1140 echo "modified file" > $testroot/wt/alpha
1141 (cd $testroot/wt && got rm beta > /dev/null)
1142 echo "new file" > $testroot/wt/foo
1143 (cd $testroot/wt && got add foo > /dev/null)
1144 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1146 echo "modified file" > $testroot/wt/gamma/delta
1147 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1148 > $testroot/stdout 2> $testroot/stderr)
1149 ret="$?"
1150 if [ "$ret" == "0" ]; then
1151 echo "got commit command succeeded unexpectedly" >&2
1152 test_done "$testroot" "1"
1153 return 1
1156 echo -n > $testroot/stdout.expected
1157 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1159 cmp -s $testroot/stderr.expected $testroot/stderr
1160 ret="$?"
1161 if [ "$ret" != "0" ]; then
1162 diff -u $testroot/stderr.expected $testroot/stderr
1163 test_done "$testroot" "$ret"
1164 return 1
1166 cmp -s $testroot/stdout.expected $testroot/stdout
1167 ret="$?"
1168 if [ "$ret" != "0" ]; then
1169 diff -u $testroot/stdout.expected $testroot/stdout
1171 test_done "$testroot" "$ret"
1174 function test_stage_commit_out_of_date {
1175 local testroot=`test_init stage_commit_out_of_date`
1177 got checkout $testroot/repo $testroot/wt > /dev/null
1178 ret="$?"
1179 if [ "$ret" != "0" ]; then
1180 test_done "$testroot" "$ret"
1181 return 1
1184 echo "modified file" > $testroot/wt/alpha
1185 (cd $testroot/wt && got rm beta > /dev/null)
1186 echo "new file" > $testroot/wt/foo
1187 (cd $testroot/wt && got add foo > /dev/null)
1188 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1190 echo "changed file" > $testroot/repo/alpha
1191 git_commit $testroot/repo -m "changed alpha in repo"
1193 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1194 2> $testroot/stderr)
1195 ret="$?"
1196 if [ "$ret" == "0" ]; then
1197 echo "got commit command succeeded unexpectedly" >&2
1198 test_done "$testroot" "1"
1199 return 1
1202 echo -n > $testroot/stdout.expected
1203 echo -n "got: work tree must be updated before these changes " \
1204 > $testroot/stderr.expected
1205 echo "can be committed" >> $testroot/stderr.expected
1207 cmp -s $testroot/stderr.expected $testroot/stderr
1208 ret="$?"
1209 if [ "$ret" != "0" ]; then
1210 diff -u $testroot/stderr.expected $testroot/stderr
1211 test_done "$testroot" "$ret"
1212 return 1
1214 cmp -s $testroot/stdout.expected $testroot/stdout
1215 ret="$?"
1216 if [ "$ret" != "0" ]; then
1217 diff -u $testroot/stdout.expected $testroot/stdout
1218 test_done "$testroot" "$ret"
1219 return 1
1222 (cd $testroot/wt && got update > $testroot/stdout \
1223 2> $testroot/stderr)
1224 echo -n > $testroot/stdout.expected
1225 echo "got: alpha: file is staged" > $testroot/stderr.expected
1227 cmp -s $testroot/stderr.expected $testroot/stderr
1228 ret="$?"
1229 if [ "$ret" != "0" ]; then
1230 diff -u $testroot/stderr.expected $testroot/stderr
1231 test_done "$testroot" "$ret"
1232 return 1
1234 cmp -s $testroot/stdout.expected $testroot/stdout
1235 ret="$?"
1236 if [ "$ret" != "0" ]; then
1237 diff -u $testroot/stdout.expected $testroot/stdout
1238 test_done "$testroot" "$ret"
1239 return 1
1242 (cd $testroot/wt && got unstage > /dev/null)
1243 (cd $testroot/wt && got update > $testroot/stdout)
1244 ret="$?"
1245 if [ "$ret" != "0" ]; then
1246 echo "got update command failed unexpectedly" >&2
1247 test_done "$testroot" "$ret"
1248 return 1
1251 (cd $testroot/wt && got status > $testroot/stdout)
1252 echo "C alpha" > $testroot/stdout.expected
1253 echo "D beta" >> $testroot/stdout.expected
1254 echo "A foo" >> $testroot/stdout.expected
1255 cmp -s $testroot/stdout.expected $testroot/stdout
1256 ret="$?"
1257 if [ "$ret" != "0" ]; then
1258 diff -u $testroot/stdout.expected $testroot/stdout
1259 test_done "$testroot" "$ret"
1260 return 1
1263 # resolve conflict
1264 echo "resolved file" > $testroot/wt/alpha
1266 (cd $testroot/wt && got stage > /dev/null)
1268 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1269 ret="$?"
1270 if [ "$ret" != "0" ]; then
1271 echo "got commit command failed unexpectedly" >&2
1272 test_done "$testroot" "$ret"
1273 return 1
1276 local commit_id=`git_show_head $testroot/repo`
1277 echo "A foo" > $testroot/stdout.expected
1278 echo "M alpha" >> $testroot/stdout.expected
1279 echo "D beta" >> $testroot/stdout.expected
1280 echo "Created commit $commit_id" >> $testroot/stdout.expected
1281 cmp -s $testroot/stdout.expected $testroot/stdout
1282 ret="$?"
1283 if [ "$ret" != "0" ]; then
1284 diff -u $testroot/stdout.expected $testroot/stdout
1286 test_done "$testroot" "$ret"
1290 function test_stage_commit {
1291 local testroot=`test_init stage_commit`
1292 local first_commit=`git_show_head $testroot/repo`
1294 got checkout $testroot/repo $testroot/wt > /dev/null
1295 ret="$?"
1296 if [ "$ret" != "0" ]; then
1297 test_done "$testroot" "$ret"
1298 return 1
1301 echo "modified file" > $testroot/wt/alpha
1302 (cd $testroot/wt && got rm beta > /dev/null)
1303 echo "new file" > $testroot/wt/foo
1304 (cd $testroot/wt && got add foo > /dev/null)
1305 echo "modified file" > $testroot/wt/alpha
1306 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1308 echo "modified file again" > $testroot/wt/alpha
1309 echo "new file changed" > $testroot/wt/foo
1310 echo "non-staged change" > $testroot/wt/gamma/delta
1311 echo "non-staged new file" > $testroot/wt/epsilon/new
1312 (cd $testroot/wt && got add epsilon/new > /dev/null)
1313 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1315 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1316 > $testroot/blob_id_alpha
1317 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1318 > $testroot/blob_id_foo
1320 (cd $testroot/wt && got commit -m "staged changes" \
1321 > $testroot/stdout)
1322 ret="$?"
1323 if [ "$ret" != "0" ]; then
1324 echo "got commit command failed unexpectedly" >&2
1325 test_done "$testroot" "1"
1326 return 1
1329 local head_commit=`git_show_head $testroot/repo`
1330 echo "A foo" > $testroot/stdout.expected
1331 echo "M alpha" >> $testroot/stdout.expected
1332 echo "D beta" >> $testroot/stdout.expected
1333 echo "Created commit $head_commit" >> $testroot/stdout.expected
1335 cmp -s $testroot/stdout.expected $testroot/stdout
1336 ret="$?"
1337 if [ "$ret" != "0" ]; then
1338 diff -u $testroot/stdout.expected $testroot/stdout
1339 test_done "$testroot" "$ret"
1340 return 1
1343 got diff -r $testroot/repo $first_commit $head_commit \
1344 > $testroot/stdout
1346 echo "diff $first_commit $head_commit" \
1347 > $testroot/stdout.expected
1348 echo -n 'blob - ' >> $testroot/stdout.expected
1349 got tree -r $testroot/repo -i -c $first_commit | \
1350 grep 'alpha$' | cut -d' ' -f 1 \
1351 >> $testroot/stdout.expected
1352 echo -n 'blob + ' >> $testroot/stdout.expected
1353 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1354 echo '--- alpha' >> $testroot/stdout.expected
1355 echo '+++ alpha' >> $testroot/stdout.expected
1356 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1357 echo '-alpha' >> $testroot/stdout.expected
1358 echo '+modified file' >> $testroot/stdout.expected
1359 echo -n 'blob - ' >> $testroot/stdout.expected
1360 got tree -r $testroot/repo -i -c $first_commit \
1361 | grep 'beta$' | cut -d' ' -f 1 \
1362 >> $testroot/stdout.expected
1363 echo 'blob + /dev/null' >> $testroot/stdout.expected
1364 echo '--- beta' >> $testroot/stdout.expected
1365 echo '+++ /dev/null' >> $testroot/stdout.expected
1366 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1367 echo '-beta' >> $testroot/stdout.expected
1368 echo 'blob - /dev/null' >> $testroot/stdout.expected
1369 echo -n 'blob + ' >> $testroot/stdout.expected
1370 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1371 echo '--- /dev/null' >> $testroot/stdout.expected
1372 echo '+++ foo' >> $testroot/stdout.expected
1373 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1374 echo '+new file' >> $testroot/stdout.expected
1376 cmp -s $testroot/stdout.expected $testroot/stdout
1377 ret="$?"
1378 if [ "$ret" != "0" ]; then
1379 diff -u $testroot/stdout.expected $testroot/stdout
1380 test_done "$testroot" "$ret"
1381 return 1
1384 echo 'A epsilon/new' > $testroot/stdout.expected
1385 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1386 echo 'M gamma/delta' >> $testroot/stdout.expected
1388 (cd $testroot/wt && got status > $testroot/stdout)
1389 cmp -s $testroot/stdout.expected $testroot/stdout
1390 ret="$?"
1391 if [ "$ret" != "0" ]; then
1392 diff -u $testroot/stdout.expected $testroot/stdout
1394 test_done "$testroot" "$ret"
1397 function test_stage_patch {
1398 local testroot=`test_init stage_patch`
1400 jot 16 > $testroot/repo/numbers
1401 (cd $testroot/repo && git add numbers)
1402 git_commit $testroot/repo -m "added numbers file"
1403 local commit_id=`git_show_head $testroot/repo`
1405 got checkout $testroot/repo $testroot/wt > /dev/null
1406 ret="$?"
1407 if [ "$ret" != "0" ]; then
1408 test_done "$testroot" "$ret"
1409 return 1
1412 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1413 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1414 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1416 # don't stage any hunks
1417 printf "n\nn\nn\n" > $testroot/patchscript
1418 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1419 numbers > $testroot/stdout)
1420 ret="$?"
1421 if [ "$ret" != "0" ]; then
1422 echo "got stage command failed unexpectedly" >&2
1423 test_done "$testroot" "1"
1424 return 1
1426 cat > $testroot/stdout.expected <<EOF
1427 -----------------------------------------------
1428 @@ -1,5 +1,5 @@
1435 -----------------------------------------------
1436 M numbers (change 1 of 3)
1437 stage this change? [y/n/q] n
1438 -----------------------------------------------
1439 @@ -4,7 +4,7 @@
1448 -----------------------------------------------
1449 M numbers (change 2 of 3)
1450 stage this change? [y/n/q] n
1451 -----------------------------------------------
1452 @@ -13,4 +13,4 @@
1456 -16
1458 -----------------------------------------------
1459 M numbers (change 3 of 3)
1460 stage this change? [y/n/q] n
1461 EOF
1462 cmp -s $testroot/stdout.expected $testroot/stdout
1463 ret="$?"
1464 if [ "$ret" != "0" ]; then
1465 diff -u $testroot/stdout.expected $testroot/stdout
1466 test_done "$testroot" "$ret"
1467 return 1
1470 (cd $testroot/wt && got status > $testroot/stdout)
1471 echo "M numbers" > $testroot/stdout.expected
1472 cmp -s $testroot/stdout.expected $testroot/stdout
1473 ret="$?"
1474 if [ "$ret" != "0" ]; then
1475 diff -u $testroot/stdout.expected $testroot/stdout
1476 test_done "$testroot" "$ret"
1477 return 1
1480 # stage middle hunk
1481 printf "n\ny\nn\n" > $testroot/patchscript
1482 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1483 numbers > $testroot/stdout)
1485 cat > $testroot/stdout.expected <<EOF
1486 -----------------------------------------------
1487 @@ -1,5 +1,5 @@
1494 -----------------------------------------------
1495 M numbers (change 1 of 3)
1496 stage this change? [y/n/q] n
1497 -----------------------------------------------
1498 @@ -4,7 +4,7 @@
1507 -----------------------------------------------
1508 M numbers (change 2 of 3)
1509 stage this change? [y/n/q] y
1510 -----------------------------------------------
1511 @@ -13,4 +13,4 @@
1515 -16
1517 -----------------------------------------------
1518 M numbers (change 3 of 3)
1519 stage this change? [y/n/q] n
1520 EOF
1521 cmp -s $testroot/stdout.expected $testroot/stdout
1522 ret="$?"
1523 if [ "$ret" != "0" ]; then
1524 diff -u $testroot/stdout.expected $testroot/stdout
1525 test_done "$testroot" "$ret"
1526 return 1
1529 (cd $testroot/wt && got status > $testroot/stdout)
1530 echo "MM numbers" > $testroot/stdout.expected
1531 cmp -s $testroot/stdout.expected $testroot/stdout
1532 ret="$?"
1533 if [ "$ret" != "0" ]; then
1534 diff -u $testroot/stdout.expected $testroot/stdout
1535 test_done "$testroot" "$ret"
1536 return 1
1539 (cd $testroot/wt && got diff -s > $testroot/stdout)
1541 echo "diff $commit_id $testroot/wt (staged changes)" \
1542 > $testroot/stdout.expected
1543 echo -n 'blob - ' >> $testroot/stdout.expected
1544 got tree -r $testroot/repo -i -c $commit_id \
1545 | grep 'numbers$' | cut -d' ' -f 1 \
1546 >> $testroot/stdout.expected
1547 echo -n 'blob + ' >> $testroot/stdout.expected
1548 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1549 >> $testroot/stdout.expected
1550 echo "--- numbers" >> $testroot/stdout.expected
1551 echo "+++ numbers" >> $testroot/stdout.expected
1552 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1553 echo " 4" >> $testroot/stdout.expected
1554 echo " 5" >> $testroot/stdout.expected
1555 echo " 6" >> $testroot/stdout.expected
1556 echo "-7" >> $testroot/stdout.expected
1557 echo "+b" >> $testroot/stdout.expected
1558 echo " 8" >> $testroot/stdout.expected
1559 echo " 9" >> $testroot/stdout.expected
1560 echo " 10" >> $testroot/stdout.expected
1561 cmp -s $testroot/stdout.expected $testroot/stdout
1562 ret="$?"
1563 if [ "$ret" != "0" ]; then
1564 diff -u $testroot/stdout.expected $testroot/stdout
1565 test_done "$testroot" "$ret"
1566 return 1
1569 (cd $testroot/wt && got unstage >/dev/null)
1570 ret="$?"
1571 if [ "$ret" != "0" ]; then
1572 echo "got stage command failed unexpectedly" >&2
1573 test_done "$testroot" "1"
1574 return 1
1576 (cd $testroot/wt && got status > $testroot/stdout)
1577 echo "M numbers" > $testroot/stdout.expected
1578 cmp -s $testroot/stdout.expected $testroot/stdout
1579 ret="$?"
1580 if [ "$ret" != "0" ]; then
1581 diff -u $testroot/stdout.expected $testroot/stdout
1582 test_done "$testroot" "$ret"
1583 return 1
1586 # stage last hunk
1587 printf "n\nn\ny\n" > $testroot/patchscript
1588 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1589 numbers > $testroot/stdout)
1591 cat > $testroot/stdout.expected <<EOF
1592 -----------------------------------------------
1593 @@ -1,5 +1,5 @@
1600 -----------------------------------------------
1601 M numbers (change 1 of 3)
1602 stage this change? [y/n/q] n
1603 -----------------------------------------------
1604 @@ -4,7 +4,7 @@
1613 -----------------------------------------------
1614 M numbers (change 2 of 3)
1615 stage this change? [y/n/q] n
1616 -----------------------------------------------
1617 @@ -13,4 +13,4 @@
1621 -16
1623 -----------------------------------------------
1624 M numbers (change 3 of 3)
1625 stage this change? [y/n/q] y
1626 EOF
1627 cmp -s $testroot/stdout.expected $testroot/stdout
1628 ret="$?"
1629 if [ "$ret" != "0" ]; then
1630 diff -u $testroot/stdout.expected $testroot/stdout
1631 test_done "$testroot" "$ret"
1632 return 1
1635 (cd $testroot/wt && got status > $testroot/stdout)
1636 echo "MM numbers" > $testroot/stdout.expected
1637 cmp -s $testroot/stdout.expected $testroot/stdout
1638 ret="$?"
1639 if [ "$ret" != "0" ]; then
1640 diff -u $testroot/stdout.expected $testroot/stdout
1641 test_done "$testroot" "$ret"
1642 return 1
1645 (cd $testroot/wt && got diff -s > $testroot/stdout)
1647 echo "diff $commit_id $testroot/wt (staged changes)" \
1648 > $testroot/stdout.expected
1649 echo -n 'blob - ' >> $testroot/stdout.expected
1650 got tree -r $testroot/repo -i -c $commit_id \
1651 | grep 'numbers$' | cut -d' ' -f 1 \
1652 >> $testroot/stdout.expected
1653 echo -n 'blob + ' >> $testroot/stdout.expected
1654 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1655 >> $testroot/stdout.expected
1656 echo "--- numbers" >> $testroot/stdout.expected
1657 echo "+++ numbers" >> $testroot/stdout.expected
1658 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1659 echo " 13" >> $testroot/stdout.expected
1660 echo " 14" >> $testroot/stdout.expected
1661 echo " 15" >> $testroot/stdout.expected
1662 echo "-16" >> $testroot/stdout.expected
1663 echo "+c" >> $testroot/stdout.expected
1664 cmp -s $testroot/stdout.expected $testroot/stdout
1665 ret="$?"
1666 if [ "$ret" != "0" ]; then
1667 diff -u $testroot/stdout.expected $testroot/stdout
1669 test_done "$testroot" "$ret"
1672 function test_stage_patch_twice {
1673 local testroot=`test_init stage_patch_twice`
1675 jot 16 > $testroot/repo/numbers
1676 (cd $testroot/repo && git add numbers)
1677 git_commit $testroot/repo -m "added numbers file"
1678 local commit_id=`git_show_head $testroot/repo`
1680 got checkout $testroot/repo $testroot/wt > /dev/null
1681 ret="$?"
1682 if [ "$ret" != "0" ]; then
1683 test_done "$testroot" "$ret"
1684 return 1
1687 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1688 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1689 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1691 # stage middle hunk
1692 printf "n\ny\nn\n" > $testroot/patchscript
1693 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1694 numbers > $testroot/stdout)
1696 cat > $testroot/stdout.expected <<EOF
1697 -----------------------------------------------
1698 @@ -1,5 +1,5 @@
1705 -----------------------------------------------
1706 M numbers (change 1 of 3)
1707 stage this change? [y/n/q] n
1708 -----------------------------------------------
1709 @@ -4,7 +4,7 @@
1718 -----------------------------------------------
1719 M numbers (change 2 of 3)
1720 stage this change? [y/n/q] y
1721 -----------------------------------------------
1722 @@ -13,4 +13,4 @@
1726 -16
1728 -----------------------------------------------
1729 M numbers (change 3 of 3)
1730 stage this change? [y/n/q] n
1731 EOF
1732 cmp -s $testroot/stdout.expected $testroot/stdout
1733 ret="$?"
1734 if [ "$ret" != "0" ]; then
1735 diff -u $testroot/stdout.expected $testroot/stdout
1736 test_done "$testroot" "$ret"
1737 return 1
1740 (cd $testroot/wt && got status > $testroot/stdout)
1741 echo "MM numbers" > $testroot/stdout.expected
1742 cmp -s $testroot/stdout.expected $testroot/stdout
1743 ret="$?"
1744 if [ "$ret" != "0" ]; then
1745 diff -u $testroot/stdout.expected $testroot/stdout
1746 test_done "$testroot" "$ret"
1747 return 1
1750 # stage last hunk
1751 printf "n\ny\n" > $testroot/patchscript
1752 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1753 numbers > $testroot/stdout)
1755 cat > $testroot/stdout.expected <<EOF
1756 -----------------------------------------------
1757 @@ -1,5 +1,5 @@ b
1764 -----------------------------------------------
1765 M numbers (change 1 of 2)
1766 stage this change? [y/n/q] n
1767 -----------------------------------------------
1768 @@ -13,4 +13,4 @@ b
1772 -16
1774 -----------------------------------------------
1775 M numbers (change 2 of 2)
1776 stage this change? [y/n/q] y
1777 EOF
1778 cmp -s $testroot/stdout.expected $testroot/stdout
1779 ret="$?"
1780 if [ "$ret" != "0" ]; then
1781 diff -u $testroot/stdout.expected $testroot/stdout
1782 test_done "$testroot" "$ret"
1783 return 1
1786 (cd $testroot/wt && got status > $testroot/stdout)
1787 echo "MM numbers" > $testroot/stdout.expected
1788 cmp -s $testroot/stdout.expected $testroot/stdout
1789 ret="$?"
1790 if [ "$ret" != "0" ]; then
1791 diff -u $testroot/stdout.expected $testroot/stdout
1792 test_done "$testroot" "$ret"
1793 return 1
1796 (cd $testroot/wt && got diff -s > $testroot/stdout)
1798 echo "diff $commit_id $testroot/wt (staged changes)" \
1799 > $testroot/stdout.expected
1800 echo -n 'blob - ' >> $testroot/stdout.expected
1801 got tree -r $testroot/repo -i -c $commit_id \
1802 | grep 'numbers$' | cut -d' ' -f 1 \
1803 >> $testroot/stdout.expected
1804 echo -n 'blob + ' >> $testroot/stdout.expected
1805 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1806 >> $testroot/stdout.expected
1807 echo "--- numbers" >> $testroot/stdout.expected
1808 echo "+++ numbers" >> $testroot/stdout.expected
1809 cat >> $testroot/stdout.expected <<EOF
1810 @@ -4,7 +4,7 @@
1819 @@ -13,4 +13,4 @@
1823 -16
1825 EOF
1826 cmp -s $testroot/stdout.expected $testroot/stdout
1827 ret="$?"
1828 if [ "$ret" != "0" ]; then
1829 diff -u $testroot/stdout.expected $testroot/stdout
1830 test_done "$testroot" "$ret"
1831 return 1
1834 (cd $testroot/wt && got diff > $testroot/stdout)
1836 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1837 echo -n 'blob - ' >> $testroot/stdout.expected
1838 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1839 tr -d '\n' >> $testroot/stdout.expected
1840 echo " (staged)" >> $testroot/stdout.expected
1841 echo 'file + numbers' >> $testroot/stdout.expected
1842 echo "--- numbers" >> $testroot/stdout.expected
1843 echo "+++ numbers" >> $testroot/stdout.expected
1844 cat >> $testroot/stdout.expected <<EOF
1845 @@ -1,5 +1,5 @@
1852 EOF
1853 cmp -s $testroot/stdout.expected $testroot/stdout
1854 ret="$?"
1855 if [ "$ret" != "0" ]; then
1856 diff -u $testroot/stdout.expected $testroot/stdout
1858 test_done "$testroot" "$ret"
1861 function test_stage_patch_added {
1862 local testroot=`test_init stage_patch_added`
1863 local commit_id=`git_show_head $testroot/repo`
1865 got checkout $testroot/repo $testroot/wt > /dev/null
1866 ret="$?"
1867 if [ "$ret" != "0" ]; then
1868 test_done "$testroot" "$ret"
1869 return 1
1872 echo "new" > $testroot/wt/epsilon/new
1873 (cd $testroot/wt && got add epsilon/new > /dev/null)
1875 printf "y\n" > $testroot/patchscript
1876 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1877 epsilon/new > $testroot/stdout)
1879 echo "A epsilon/new" > $testroot/stdout.expected
1880 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1881 cmp -s $testroot/stdout.expected $testroot/stdout
1882 ret="$?"
1883 if [ "$ret" != "0" ]; then
1884 diff -u $testroot/stdout.expected $testroot/stdout
1885 test_done "$testroot" "$ret"
1886 return 1
1889 (cd $testroot/wt && got status > $testroot/stdout)
1890 echo " A epsilon/new" > $testroot/stdout.expected
1891 cmp -s $testroot/stdout.expected $testroot/stdout
1892 ret="$?"
1893 if [ "$ret" != "0" ]; then
1894 diff -u $testroot/stdout.expected $testroot/stdout
1895 test_done "$testroot" "$ret"
1896 return 1
1899 (cd $testroot/wt && got diff -s > $testroot/stdout)
1901 echo "diff $commit_id $testroot/wt (staged changes)" \
1902 > $testroot/stdout.expected
1903 echo 'blob - /dev/null' >> $testroot/stdout.expected
1904 echo -n 'blob + ' >> $testroot/stdout.expected
1905 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1906 >> $testroot/stdout.expected
1907 echo "--- /dev/null" >> $testroot/stdout.expected
1908 echo "+++ epsilon/new" >> $testroot/stdout.expected
1909 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1910 echo "+new" >> $testroot/stdout.expected
1911 cmp -s $testroot/stdout.expected $testroot/stdout
1912 ret="$?"
1913 if [ "$ret" != "0" ]; then
1914 diff -u $testroot/stdout.expected $testroot/stdout
1916 test_done "$testroot" "$ret"
1919 function test_stage_patch_added_twice {
1920 local testroot=`test_init stage_patch_added_twice`
1921 local commit_id=`git_show_head $testroot/repo`
1923 got checkout $testroot/repo $testroot/wt > /dev/null
1924 ret="$?"
1925 if [ "$ret" != "0" ]; then
1926 test_done "$testroot" "$ret"
1927 return 1
1930 echo "new" > $testroot/wt/epsilon/new
1931 (cd $testroot/wt && got add epsilon/new > /dev/null)
1933 printf "y\n" > $testroot/patchscript
1934 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1935 epsilon/new > $testroot/stdout)
1937 echo "A epsilon/new" > $testroot/stdout.expected
1938 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1939 cmp -s $testroot/stdout.expected $testroot/stdout
1940 ret="$?"
1941 if [ "$ret" != "0" ]; then
1942 diff -u $testroot/stdout.expected $testroot/stdout
1943 test_done "$testroot" "$ret"
1944 return 1
1947 (cd $testroot/wt && got status > $testroot/stdout)
1948 echo " A epsilon/new" > $testroot/stdout.expected
1949 cmp -s $testroot/stdout.expected $testroot/stdout
1950 ret="$?"
1951 if [ "$ret" != "0" ]; then
1952 diff -u $testroot/stdout.expected $testroot/stdout
1953 test_done "$testroot" "$ret"
1954 return 1
1957 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1958 epsilon/new > $testroot/stdout 2> $testroot/stderr)
1959 ret="$?"
1960 if [ "$ret" == "0" ]; then
1961 echo "got stage command succeeded unexpectedly" >&2
1962 test_done "$testroot" "1"
1963 return 1
1966 echo "got: epsilon/new: no changes to stage" > $testroot/stderr.expected
1967 cmp -s $testroot/stderr.expected $testroot/stderr
1968 ret="$?"
1969 if [ "$ret" != "0" ]; then
1970 diff -u $testroot/stderr.expected $testroot/stderr
1971 test_done "$testroot" "$ret"
1972 return 1
1975 echo -n > $testroot/stdout.expected
1976 cmp -s $testroot/stdout.expected $testroot/stdout
1977 ret="$?"
1978 if [ "$ret" != "0" ]; then
1979 diff -u $testroot/stdout.expected $testroot/stdout
1981 test_done "$testroot" "$ret"
1984 function test_stage_patch_removed {
1985 local testroot=`test_init stage_patch_removed`
1986 local commit_id=`git_show_head $testroot/repo`
1988 got checkout $testroot/repo $testroot/wt > /dev/null
1989 ret="$?"
1990 if [ "$ret" != "0" ]; then
1991 test_done "$testroot" "$ret"
1992 return 1
1995 (cd $testroot/wt && got rm beta > /dev/null)
1997 printf "y\n" > $testroot/patchscript
1998 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1999 beta > $testroot/stdout)
2001 echo -n > $testroot/stdout.expected
2003 echo "D beta" > $testroot/stdout.expected
2004 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2005 cmp -s $testroot/stdout.expected $testroot/stdout
2006 ret="$?"
2007 if [ "$ret" != "0" ]; then
2008 diff -u $testroot/stdout.expected $testroot/stdout
2009 test_done "$testroot" "$ret"
2010 return 1
2013 (cd $testroot/wt && got status > $testroot/stdout)
2014 echo " D beta" > $testroot/stdout.expected
2015 cmp -s $testroot/stdout.expected $testroot/stdout
2016 ret="$?"
2017 if [ "$ret" != "0" ]; then
2018 diff -u $testroot/stdout.expected $testroot/stdout
2019 test_done "$testroot" "$ret"
2020 return 1
2023 (cd $testroot/wt && got diff -s > $testroot/stdout)
2025 echo "diff $commit_id $testroot/wt (staged changes)" \
2026 > $testroot/stdout.expected
2027 echo -n 'blob - ' >> $testroot/stdout.expected
2028 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2029 >> $testroot/stdout.expected
2030 echo 'blob + /dev/null' >> $testroot/stdout.expected
2031 echo "--- beta" >> $testroot/stdout.expected
2032 echo "+++ /dev/null" >> $testroot/stdout.expected
2033 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2034 echo "-beta" >> $testroot/stdout.expected
2035 cmp -s $testroot/stdout.expected $testroot/stdout
2036 ret="$?"
2037 if [ "$ret" != "0" ]; then
2038 diff -u $testroot/stdout.expected $testroot/stdout
2040 test_done "$testroot" "$ret"
2043 function test_stage_patch_removed_twice {
2044 local testroot=`test_init stage_patch_removed_twice`
2045 local commit_id=`git_show_head $testroot/repo`
2047 got checkout $testroot/repo $testroot/wt > /dev/null
2048 ret="$?"
2049 if [ "$ret" != "0" ]; then
2050 test_done "$testroot" "$ret"
2051 return 1
2054 (cd $testroot/wt && got rm beta > /dev/null)
2056 printf "y\n" > $testroot/patchscript
2057 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2058 beta > $testroot/stdout)
2060 echo -n > $testroot/stdout.expected
2062 echo "D beta" > $testroot/stdout.expected
2063 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2064 cmp -s $testroot/stdout.expected $testroot/stdout
2065 ret="$?"
2066 if [ "$ret" != "0" ]; then
2067 diff -u $testroot/stdout.expected $testroot/stdout
2068 test_done "$testroot" "$ret"
2069 return 1
2072 (cd $testroot/wt && got status > $testroot/stdout)
2073 echo " D beta" > $testroot/stdout.expected
2074 cmp -s $testroot/stdout.expected $testroot/stdout
2075 ret="$?"
2076 if [ "$ret" != "0" ]; then
2077 diff -u $testroot/stdout.expected $testroot/stdout
2078 test_done "$testroot" "$ret"
2079 return 1
2082 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2083 > $testroot/stdout 2> $testroot/stderr)
2084 ret="$?"
2085 if [ "$ret" != "0" ]; then
2086 echo "got stage command failed unexpectedly" >&2
2087 test_done "$testroot" "$ret"
2088 return 1
2091 echo -n > $testroot/stderr.expected
2092 cmp -s $testroot/stderr.expected $testroot/stderr
2093 ret="$?"
2094 if [ "$ret" != "0" ]; then
2095 diff -u $testroot/stderr.expected $testroot/stderr
2096 test_done "$testroot" "$ret"
2097 return 1
2100 echo -n > $testroot/stdout.expected
2101 cmp -s $testroot/stdout.expected $testroot/stdout
2102 ret="$?"
2103 if [ "$ret" != "0" ]; then
2104 diff -u $testroot/stdout.expected $testroot/stdout
2106 test_done "$testroot" "$ret"
2109 function test_stage_patch_quit {
2110 local testroot=`test_init stage_patch_quit`
2112 jot 16 > $testroot/repo/numbers
2113 echo zzz > $testroot/repo/zzz
2114 (cd $testroot/repo && git add numbers zzz)
2115 git_commit $testroot/repo -m "added files"
2116 local commit_id=`git_show_head $testroot/repo`
2118 got checkout $testroot/repo $testroot/wt > /dev/null
2119 ret="$?"
2120 if [ "$ret" != "0" ]; then
2121 test_done "$testroot" "$ret"
2122 return 1
2125 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2126 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2127 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2128 (cd $testroot/wt && got rm zzz > /dev/null)
2130 # stage first hunk and quit; and don't pass a path argument to
2131 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2132 printf "y\nq\nn\n" > $testroot/patchscript
2133 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2134 > $testroot/stdout)
2135 ret="$?"
2136 if [ "$ret" != "0" ]; then
2137 echo "got stage command failed unexpectedly" >&2
2138 test_done "$testroot" "1"
2139 return 1
2141 cat > $testroot/stdout.expected <<EOF
2142 -----------------------------------------------
2143 @@ -1,5 +1,5 @@
2150 -----------------------------------------------
2151 M numbers (change 1 of 3)
2152 stage this change? [y/n/q] y
2153 -----------------------------------------------
2154 @@ -4,7 +4,7 @@
2163 -----------------------------------------------
2164 M numbers (change 2 of 3)
2165 stage this change? [y/n/q] q
2166 D zzz
2167 stage this deletion? [y/n] n
2168 EOF
2169 cmp -s $testroot/stdout.expected $testroot/stdout
2170 ret="$?"
2171 if [ "$ret" != "0" ]; then
2172 diff -u $testroot/stdout.expected $testroot/stdout
2173 test_done "$testroot" "$ret"
2174 return 1
2177 (cd $testroot/wt && got status > $testroot/stdout)
2178 echo "MM numbers" > $testroot/stdout.expected
2179 echo "D zzz" >> $testroot/stdout.expected
2180 cmp -s $testroot/stdout.expected $testroot/stdout
2181 ret="$?"
2182 if [ "$ret" != "0" ]; then
2183 diff -u $testroot/stdout.expected $testroot/stdout
2184 test_done "$testroot" "$ret"
2185 return 1
2188 (cd $testroot/wt && got diff -s > $testroot/stdout)
2190 echo "diff $commit_id $testroot/wt (staged changes)" \
2191 > $testroot/stdout.expected
2192 echo -n 'blob - ' >> $testroot/stdout.expected
2193 got tree -r $testroot/repo -i -c $commit_id \
2194 | grep 'numbers$' | cut -d' ' -f 1 \
2195 >> $testroot/stdout.expected
2196 echo -n 'blob + ' >> $testroot/stdout.expected
2197 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2198 >> $testroot/stdout.expected
2199 echo "--- numbers" >> $testroot/stdout.expected
2200 echo "+++ numbers" >> $testroot/stdout.expected
2201 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2202 echo " 1" >> $testroot/stdout.expected
2203 echo "-2" >> $testroot/stdout.expected
2204 echo "+a" >> $testroot/stdout.expected
2205 echo " 3" >> $testroot/stdout.expected
2206 echo " 4" >> $testroot/stdout.expected
2207 echo " 5" >> $testroot/stdout.expected
2208 cmp -s $testroot/stdout.expected $testroot/stdout
2209 ret="$?"
2210 if [ "$ret" != "0" ]; then
2211 diff -u $testroot/stdout.expected $testroot/stdout
2213 test_done "$testroot" "$ret"
2217 function test_stage_patch_incomplete_script {
2218 local testroot=`test_init stage_incomplete_script`
2220 jot 16 > $testroot/repo/numbers
2221 echo zzz > $testroot/repo/zzz
2222 (cd $testroot/repo && git add numbers zzz)
2223 git_commit $testroot/repo -m "added files"
2224 local commit_id=`git_show_head $testroot/repo`
2226 got checkout $testroot/repo $testroot/wt > /dev/null
2227 ret="$?"
2228 if [ "$ret" != "0" ]; then
2229 test_done "$testroot" "$ret"
2230 return 1
2233 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2234 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2235 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2237 # stage first hunk and then stop responding; got should error out
2238 printf "y\n" > $testroot/patchscript
2239 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2240 > $testroot/stdout 2> $testroot/stderr)
2241 ret="$?"
2242 if [ "$ret" == "0" ]; then
2243 echo "got stage command succeeded unexpectedly" >&2
2244 test_done "$testroot" "1"
2245 return 1
2247 cat > $testroot/stdout.expected <<EOF
2248 -----------------------------------------------
2249 @@ -1,5 +1,5 @@
2256 -----------------------------------------------
2257 M numbers (change 1 of 3)
2258 stage this change? [y/n/q] y
2259 -----------------------------------------------
2260 @@ -4,7 +4,7 @@
2269 -----------------------------------------------
2270 M numbers (change 2 of 3)
2271 EOF
2272 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2273 echo "got: invalid patch choice" > $testroot/stderr.expected
2274 cmp -s $testroot/stderr.expected $testroot/stderr
2275 ret="$?"
2276 if [ "$ret" != "0" ]; then
2277 diff -u $testroot/stderr.expected $testroot/stderr
2278 test_done "$testroot" "$ret"
2279 return 1
2282 cmp -s $testroot/stdout.expected $testroot/stdout
2283 ret="$?"
2284 if [ "$ret" != "0" ]; then
2285 diff -u $testroot/stdout.expected $testroot/stdout
2286 test_done "$testroot" "$ret"
2287 return 1
2290 (cd $testroot/wt && got status > $testroot/stdout)
2291 echo "M numbers" > $testroot/stdout.expected
2292 cmp -s $testroot/stdout.expected $testroot/stdout
2293 ret="$?"
2294 if [ "$ret" != "0" ]; then
2295 diff -u $testroot/stdout.expected $testroot/stdout
2296 test_done "$testroot" "$ret"
2297 return 1
2300 (cd $testroot/wt && got diff -s > $testroot/stdout)
2301 echo -n > $testroot/stdout.expected
2302 cmp -s $testroot/stdout.expected $testroot/stdout
2303 ret="$?"
2304 if [ "$ret" != "0" ]; then
2305 diff -u $testroot/stdout.expected $testroot/stdout
2307 test_done "$testroot" "$ret"
2311 run_test test_stage_basic
2312 run_test test_stage_no_changes
2313 run_test test_stage_unversioned
2314 run_test test_stage_nonexistent
2315 run_test test_stage_list
2316 run_test test_stage_conflict
2317 run_test test_stage_out_of_date
2318 run_test test_double_stage
2319 run_test test_stage_status
2320 run_test test_stage_add_already_staged_file
2321 run_test test_stage_rm_already_staged_file
2322 run_test test_stage_revert
2323 run_test test_stage_diff
2324 run_test test_stage_histedit
2325 run_test test_stage_rebase
2326 run_test test_stage_update
2327 run_test test_stage_commit_non_staged
2328 run_test test_stage_commit_out_of_date
2329 run_test test_stage_commit
2330 run_test test_stage_patch
2331 run_test test_stage_patch_twice
2332 run_test test_stage_patch_added
2333 run_test test_stage_patch_added_twice
2334 run_test test_stage_patch_removed
2335 run_test test_stage_patch_removed_twice
2336 run_test test_stage_patch_quit
2337 run_test test_stage_patch_incomplete_script