Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_stage_basic {
20 local testroot=`test_init stage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified file" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta > /dev/null)
31 echo "new file" > $testroot/wt/foo
32 (cd $testroot/wt && got add foo > /dev/null)
34 echo ' M alpha' > $testroot/stdout.expected
35 echo ' D beta' >> $testroot/stdout.expected
36 echo ' A foo' >> $testroot/stdout.expected
37 (cd $testroot/wt && got stage > $testroot/stdout)
39 cmp -s $testroot/stdout.expected $testroot/stdout
40 ret="$?"
41 if [ "$ret" != "0" ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
43 fi
44 test_done "$testroot" "$ret"
45 }
47 function test_stage_no_changes {
48 local testroot=`test_init stage_no_changes`
50 got checkout $testroot/repo $testroot/wt > /dev/null
51 ret="$?"
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
54 return 1
55 fi
57 (cd $testroot/wt && got stage alpha beta > $testroot/stdout \
58 2> $testroot/stderr)
59 ret="$?"
60 if [ "$ret" == "0" ]; then
61 echo "got stage command succeeded unexpectedly" >&2
62 test_done "$testroot" "1"
63 return 1
64 fi
66 echo "got: no changes to stage" > $testroot/stderr.expected
68 cmp -s $testroot/stderr.expected $testroot/stderr
69 ret="$?"
70 if [ "$ret" != "0" ]; then
71 diff -u $testroot/stderr.expected $testroot/stderr
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 echo -n > $testroot/stdout.expected
77 cmp -s $testroot/stdout.expected $testroot/stdout
78 ret="$?"
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
81 fi
82 test_done "$testroot" "$ret"
83 }
85 function test_stage_unversioned {
86 local testroot=`test_init stage_unversioned`
88 got checkout $testroot/repo $testroot/wt > /dev/null
89 ret="$?"
90 if [ "$ret" != "0" ]; then
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 echo "modified file" > $testroot/wt/alpha
96 touch $testroot/wt/unversioned-file
98 (cd $testroot/wt && got status > $testroot/stdout)
99 echo "M alpha" > $testroot/stdout.expected
100 echo "? unversioned-file" >> $testroot/stdout.expected
101 cmp -s $testroot/stdout.expected $testroot/stdout
102 ret="$?"
103 if [ "$ret" != "0" ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/wt && got stage > $testroot/stdout)
110 ret="$?"
111 if [ "$ret" != "0" ]; then
112 echo "got stage command failed unexpectedly" >&2
113 test_done "$testroot" "$ret"
114 return 1
115 fi
117 echo " M alpha" > $testroot/stdout.expected
118 cmp -s $testroot/stdout.expected $testroot/stdout
119 ret="$?"
120 if [ "$ret" != "0" ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 test_done "$testroot" "$ret"
123 return 1
124 fi
126 echo "modified file again" > $testroot/wt/alpha
128 (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
129 2> $testroot/stderr)
130 ret="$?"
131 if [ "$ret" == "0" ]; then
132 echo "got stage command succeed unexpectedly" >&2
133 test_done "$testroot" "1"
134 return 1
135 fi
137 echo "got: no changes to stage" > $testroot/stderr.expected
138 cmp -s $testroot/stderr.expected $testroot/stderr
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 diff -u $testroot/stderr.expected $testroot/stderr
142 fi
143 test_done "$testroot" "$ret"
147 function test_stage_nonexistent {
148 local testroot=`test_init stage_nonexistent`
150 got checkout $testroot/repo $testroot/wt > /dev/null
151 ret="$?"
152 if [ "$ret" != "0" ]; then
153 test_done "$testroot" "$ret"
154 return 1
155 fi
157 (cd $testroot/wt && got stage nonexistent-file \
158 > $testroot/stdout 2> $testroot/stderr)
159 echo "got: nonexistent-file: No such file or directory" \
160 > $testroot/stderr.expected
161 cmp -s $testroot/stderr.expected $testroot/stderr
162 ret="$?"
163 if [ "$ret" != "0" ]; then
164 diff -u $testroot/stderr.expected $testroot/stderr
165 fi
166 test_done "$testroot" "$ret"
169 function test_stage_list {
170 local testroot=`test_init stage_list`
172 got checkout $testroot/repo $testroot/wt > /dev/null
173 ret="$?"
174 if [ "$ret" != "0" ]; then
175 test_done "$testroot" "$ret"
176 return 1
177 fi
179 echo "modified file" > $testroot/wt/alpha
180 (cd $testroot/wt && got rm beta > /dev/null)
181 echo "new file" > $testroot/wt/foo
182 (cd $testroot/wt && got add foo > /dev/null)
184 echo ' M alpha' > $testroot/stdout.expected
185 echo ' D beta' >> $testroot/stdout.expected
186 echo ' A foo' >> $testroot/stdout.expected
187 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
189 (cd $testroot/wt && got stage -l > $testroot/stdout)
190 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
191 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
192 echo " M alpha" >> $testroot/stdout.expected
193 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
194 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
195 echo " D beta" >> $testroot/stdout.expected
196 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
197 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
198 echo " A foo" >> $testroot/stdout.expected
199 cmp -s $testroot/stdout.expected $testroot/stdout
200 ret="$?"
201 if [ "$ret" != "0" ]; then
202 diff -u $testroot/stdout.expected $testroot/stdout
203 test_done "$testroot" "$ret"
204 return 1
205 fi
207 (cd $testroot/wt && got stage -l epsilon nonexistent \
208 > $testroot/stdout)
210 echo -n > $testroot/stdout.expected
211 cmp -s $testroot/stdout.expected $testroot/stdout
212 ret="$?"
213 if [ "$ret" != "0" ]; then
214 diff -u $testroot/stdout.expected $testroot/stdout
215 test_done "$testroot" "$ret"
216 return 1
217 fi
219 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
221 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
222 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
223 echo " M alpha" >> $testroot/stdout.expected
224 cmp -s $testroot/stdout.expected $testroot/stdout
225 ret="$?"
226 if [ "$ret" != "0" ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
228 fi
229 test_done "$testroot" "$ret"
233 function test_stage_conflict {
234 local testroot=`test_init stage_conflict`
235 local initial_commit=`git_show_head $testroot/repo`
237 got checkout $testroot/repo $testroot/wt > /dev/null
238 ret="$?"
239 if [ "$ret" != "0" ]; then
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 echo "modified alpha" > $testroot/wt/alpha
245 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
247 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
249 echo "modified alpha, too" > $testroot/wt/alpha
251 echo "C alpha" > $testroot/stdout.expected
252 echo -n "Updated to commit " >> $testroot/stdout.expected
253 git_show_head $testroot/repo >> $testroot/stdout.expected
254 echo >> $testroot/stdout.expected
256 (cd $testroot/wt && got update > $testroot/stdout)
258 cmp -s $testroot/stdout.expected $testroot/stdout
259 ret="$?"
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 test_done "$testroot" "$ret"
263 return 1
264 fi
266 (cd $testroot/wt && got stage alpha > $testroot/stdout \
267 2> $testroot/stderr)
268 ret="$?"
269 if [ "$ret" == "0" ]; then
270 echo "got stage command succeeded unexpectedly" >&2
271 test_done "$testroot" "1"
272 return 1
273 fi
275 echo -n > $testroot/stdout.expected
276 echo "got: alpha: cannot stage file in conflicted status" \
277 > $testroot/stderr.expected
279 cmp -s $testroot/stdout.expected $testroot/stdout
280 ret="$?"
281 if [ "$ret" != "0" ]; then
282 diff -u $testroot/stdout.expected $testroot/stdout
283 test_done "$testroot" "$ret"
284 return 1
285 fi
286 cmp -s $testroot/stderr.expected $testroot/stderr
287 ret="$?"
288 if [ "$ret" != "0" ]; then
289 diff -u $testroot/stderr.expected $testroot/stderr
290 fi
291 test_done "$testroot" "$ret"
294 function test_stage_out_of_date {
295 local testroot=`test_init stage_out_of_date`
296 local initial_commit=`git_show_head $testroot/repo`
298 got checkout $testroot/repo $testroot/wt > /dev/null
299 ret="$?"
300 if [ "$ret" != "0" ]; then
301 test_done "$testroot" "$ret"
302 return 1
303 fi
305 echo "modified alpha" > $testroot/wt/alpha
306 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
308 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
310 echo "modified alpha again" > $testroot/wt/alpha
311 (cd $testroot/wt && got stage alpha > $testroot/stdout \
312 2> $testroot/stderr)
313 ret="$?"
314 if [ "$ret" == "0" ]; then
315 echo "got stage command succeeded unexpectedly" >&2
316 test_done "$testroot" "1"
317 return 1
318 fi
320 echo -n > $testroot/stdout.expected
321 echo "got: work tree must be updated before changes can be staged" \
322 > $testroot/stderr.expected
324 cmp -s $testroot/stdout.expected $testroot/stdout
325 ret="$?"
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
329 return 1
330 fi
331 cmp -s $testroot/stderr.expected $testroot/stderr
332 ret="$?"
333 if [ "$ret" != "0" ]; then
334 diff -u $testroot/stderr.expected $testroot/stderr
335 fi
336 test_done "$testroot" "$ret"
340 function test_double_stage {
341 local testroot=`test_init double_stage`
343 got checkout $testroot/repo $testroot/wt > /dev/null
344 ret="$?"
345 if [ "$ret" != "0" ]; then
346 test_done "$testroot" "$ret"
347 return 1
348 fi
349 echo "modified file" > $testroot/wt/alpha
350 (cd $testroot/wt && got rm beta > /dev/null)
351 echo "new file" > $testroot/wt/foo
352 (cd $testroot/wt && got add foo > /dev/null)
353 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
355 echo "got: no changes to stage" > $testroot/stderr.expected
356 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
357 cmp -s $testroot/stderr.expected $testroot/stderr
358 ret="$?"
359 if [ "$ret" != "0" ]; then
360 diff -u $testroot/stderr.expected $testroot/stderr
361 test_done "$testroot" "$ret"
362 return 1
363 fi
365 (cd $testroot/wt && got stage beta \
366 > $testroot/stdout 2> $testroot/stderr)
367 ret="$?"
368 if [ "$ret" == "0" ]; then
369 echo "got stage command succeeded unexpectedly" >&2
370 test_done "$testroot" "1"
371 return 1
372 fi
373 echo -n > $testroot/stdout.expected
374 cmp -s $testroot/stdout.expected $testroot/stdout
375 ret="$?"
376 if [ "$ret" != "0" ]; then
377 diff -u $testroot/stdout.expected $testroot/stdout
378 test_done "$testroot" "$ret"
379 return 1
380 fi
382 echo "got: no changes to stage" > $testroot/stderr.expected
383 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
384 cmp -s $testroot/stderr.expected $testroot/stderr
385 ret="$?"
386 if [ "$ret" != "0" ]; then
387 diff -u $testroot/stderr.expected $testroot/stderr
388 test_done "$testroot" "$ret"
389 return 1
390 fi
392 printf "q\n" > $testroot/patchscript
393 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
394 > $testroot/stdout 2> $testroot/stderr)
395 ret="$?"
396 if [ "$ret" == "0" ]; then
397 echo "got stage command succeeded unexpectedly" >&2
398 test_done "$testroot" "1"
399 return 1
400 fi
401 echo -n > $testroot/stdout.expected
402 cmp -s $testroot/stdout.expected $testroot/stdout
403 ret="$?"
404 if [ "$ret" != "0" ]; then
405 diff -u $testroot/stdout.expected $testroot/stdout
406 test_done "$testroot" "$ret"
407 return 1
408 fi
410 echo "got: no changes to stage" > $testroot/stderr.expected
411 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
412 cmp -s $testroot/stderr.expected $testroot/stderr
413 ret="$?"
414 if [ "$ret" != "0" ]; then
415 diff -u $testroot/stderr.expected $testroot/stderr
416 test_done "$testroot" "$ret"
417 return 1
418 fi
420 echo "modified file again" > $testroot/wt/alpha
421 echo "modified new file" > $testroot/wt/foo
423 echo ' M alpha' > $testroot/stdout.expected
424 echo ' A foo' >> $testroot/stdout.expected
425 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
426 cmp -s $testroot/stdout.expected $testroot/stdout
427 ret="$?"
428 if [ "$ret" != "0" ]; then
429 diff -u $testroot/stdout.expected $testroot/stdout
430 test_done "$testroot" "$ret"
431 return 1
432 fi
434 echo ' M alpha' > $testroot/stdout.expected
435 echo ' D beta' >> $testroot/stdout.expected
436 echo ' A foo' >> $testroot/stdout.expected
438 (cd $testroot/wt && got status > $testroot/stdout)
439 cmp -s $testroot/stdout.expected $testroot/stdout
440 ret="$?"
441 if [ "$ret" != "0" ]; then
442 diff -u $testroot/stdout.expected $testroot/stdout
443 fi
444 test_done "$testroot" "$ret"
447 function test_stage_status {
448 local testroot=`test_init stage_status`
450 got checkout $testroot/repo $testroot/wt > /dev/null
451 ret="$?"
452 if [ "$ret" != "0" ]; then
453 test_done "$testroot" "$ret"
454 return 1
455 fi
457 echo "modified file" > $testroot/wt/alpha
458 (cd $testroot/wt && got rm beta > /dev/null)
459 echo "new file" > $testroot/wt/foo
460 (cd $testroot/wt && got add foo > /dev/null)
461 echo "new file" > $testroot/wt/epsilon/new
462 (cd $testroot/wt && got add epsilon/new > /dev/null)
463 echo "modified file" > $testroot/wt/epsilon/zeta
464 (cd $testroot/wt && got rm gamma/delta > /dev/null)
466 echo ' M alpha' > $testroot/stdout.expected
467 echo ' D beta' >> $testroot/stdout.expected
468 echo 'A epsilon/new' >> $testroot/stdout.expected
469 echo 'M epsilon/zeta' >> $testroot/stdout.expected
470 echo ' A foo' >> $testroot/stdout.expected
471 echo 'D gamma/delta' >> $testroot/stdout.expected
472 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
474 (cd $testroot/wt && got status > $testroot/stdout)
475 cmp -s $testroot/stdout.expected $testroot/stdout
476 ret="$?"
477 if [ "$ret" != "0" ]; then
478 diff -u $testroot/stdout.expected $testroot/stdout
479 test_done "$testroot" "$ret"
480 return 1
481 fi
483 echo "modified file again" >> $testroot/wt/alpha
484 echo "modified added file again" >> $testroot/wt/foo
486 echo 'MM alpha' > $testroot/stdout.expected
487 echo ' D beta' >> $testroot/stdout.expected
488 echo 'A epsilon/new' >> $testroot/stdout.expected
489 echo 'M epsilon/zeta' >> $testroot/stdout.expected
490 echo 'MA foo' >> $testroot/stdout.expected
491 echo 'D gamma/delta' >> $testroot/stdout.expected
493 (cd $testroot/wt && got status > $testroot/stdout)
494 cmp -s $testroot/stdout.expected $testroot/stdout
495 ret="$?"
496 if [ "$ret" != "0" ]; then
497 diff -u $testroot/stdout.expected $testroot/stdout
498 test_done "$testroot" "$ret"
499 return 1
500 fi
502 # test no-op change of added file with new stat(2) timestamp
503 echo "new file" > $testroot/wt/foo
504 echo ' A foo' > $testroot/stdout.expected
505 (cd $testroot/wt && got status foo > $testroot/stdout)
506 cmp -s $testroot/stdout.expected $testroot/stdout
507 ret="$?"
508 if [ "$ret" != "0" ]; then
509 diff -u $testroot/stdout.expected $testroot/stdout
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 # test staged deleted file which is restored on disk
515 echo "new file" > $testroot/wt/beta
516 echo ' D beta' > $testroot/stdout.expected
517 (cd $testroot/wt && got status beta > $testroot/stdout)
518 cmp -s $testroot/stdout.expected $testroot/stdout
519 ret="$?"
520 if [ "$ret" != "0" ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 fi
523 test_done "$testroot" "$ret"
527 function test_stage_add_already_staged_file {
528 local testroot=`test_init stage_add_already_staged_file`
530 got checkout $testroot/repo $testroot/wt > /dev/null
531 ret="$?"
532 if [ "$ret" != "0" ]; then
533 test_done "$testroot" "$ret"
534 return 1
535 fi
537 echo "modified file" > $testroot/wt/alpha
538 (cd $testroot/wt && got rm beta > /dev/null)
539 echo "new file" > $testroot/wt/foo
540 (cd $testroot/wt && got add foo > /dev/null)
542 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
544 echo -n > $testroot/stdout.expected
545 for f in alpha beta foo; do
546 (cd $testroot/wt && got add $f \
547 > $testroot/stdout 2> $testroot/stderr)
548 echo "got: $f: file has unexpected status" \
549 > $testroot/stderr.expected
550 cmp -s $testroot/stderr.expected $testroot/stderr
551 ret="$?"
552 if [ "$ret" != "0" ]; then
553 diff -u $testroot/stderr.expected $testroot/stderr
554 test_done "$testroot" "$ret"
555 return 1
556 fi
557 cmp -s $testroot/stdout.expected $testroot/stdout
558 ret="$?"
559 if [ "$ret" != "0" ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
562 return 1
563 fi
564 done
566 echo ' M alpha' > $testroot/stdout.expected
567 echo ' D beta' >> $testroot/stdout.expected
568 echo ' A foo' >> $testroot/stdout.expected
570 (cd $testroot/wt && got status > $testroot/stdout)
571 cmp -s $testroot/stdout.expected $testroot/stdout
572 ret="$?"
573 if [ "$ret" != "0" ]; then
574 diff -u $testroot/stdout.expected $testroot/stdout
575 fi
576 test_done "$testroot" "$ret"
579 function test_stage_rm_already_staged_file {
580 local testroot=`test_init stage_rm_already_staged_file`
582 got checkout $testroot/repo $testroot/wt > /dev/null
583 ret="$?"
584 if [ "$ret" != "0" ]; then
585 test_done "$testroot" "$ret"
586 return 1
587 fi
589 echo "modified file" > $testroot/wt/alpha
590 (cd $testroot/wt && got rm beta > /dev/null)
591 echo "new file" > $testroot/wt/foo
592 (cd $testroot/wt && got add foo > /dev/null)
594 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
596 (cd $testroot/wt && got rm beta \
597 > $testroot/stdout 2> $testroot/stderr)
598 ret="$?"
599 if [ "$ret" != "0" ]; then
600 echo "got rm command failed unexpectedly" >&2
601 test_done "$testroot" "1"
602 return 1
603 fi
604 echo -n > $testroot/stdout.expected
605 cmp -s $testroot/stdout.expected $testroot/stdout
606 ret="$?"
607 if [ "$ret" != "0" ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 test_done "$testroot" "$ret"
610 return 1
611 fi
612 echo -n > $testroot/stderr.expected
613 cmp -s $testroot/stderr.expected $testroot/stderr
614 ret="$?"
615 if [ "$ret" != "0" ]; then
616 diff -u $testroot/stderr.expected $testroot/stderr
617 test_done "$testroot" "$ret"
618 return 1
619 fi
621 for f in alpha foo; do
622 echo "got: $f: file is staged" > $testroot/stderr.expected
623 (cd $testroot/wt && got rm $f \
624 > $testroot/stdout 2> $testroot/stderr)
625 ret="$?"
626 if [ "$ret" == "0" ]; then
627 echo "got rm command succeeded unexpectedly" >&2
628 test_done "$testroot" "1"
629 return 1
630 fi
631 cmp -s $testroot/stderr.expected $testroot/stderr
632 ret="$?"
633 if [ "$ret" != "0" ]; then
634 diff -u $testroot/stderr.expected $testroot/stderr
635 test_done "$testroot" "$ret"
636 return 1
637 fi
638 done
640 echo ' M alpha' > $testroot/stdout.expected
641 echo ' D beta' >> $testroot/stdout.expected
642 echo ' A foo' >> $testroot/stdout.expected
644 (cd $testroot/wt && got status > $testroot/stdout)
645 cmp -s $testroot/stdout.expected $testroot/stdout
646 ret="$?"
647 if [ "$ret" != "0" ]; then
648 diff -u $testroot/stdout.expected $testroot/stdout
649 fi
650 test_done "$testroot" "$ret"
653 function test_stage_revert {
654 local testroot=`test_init stage_revert`
656 got checkout $testroot/repo $testroot/wt > /dev/null
657 ret="$?"
658 if [ "$ret" != "0" ]; then
659 test_done "$testroot" "$ret"
660 return 1
661 fi
663 echo "modified alpha" > $testroot/wt/alpha
664 (cd $testroot/wt && got rm beta > /dev/null)
665 echo "new file" > $testroot/wt/foo
666 (cd $testroot/wt && got add foo > /dev/null)
667 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
669 echo "modified file again" >> $testroot/wt/alpha
670 echo "modified added file again" >> $testroot/wt/foo
672 (cd $testroot/wt && got revert alpha > $testroot/stdout)
673 ret="$?"
674 if [ "$ret" != "0" ]; then
675 echo "revert command failed unexpectedly" >&2
676 test_done "$testroot" "$ret"
677 return 1
678 fi
680 echo "R alpha" > $testroot/stdout.expected
681 cmp -s $testroot/stdout.expected $testroot/stdout
682 ret="$?"
683 if [ "$ret" != "0" ]; then
684 diff -u $testroot/stdout.expected $testroot/stdout
685 test_done "$testroot" "$ret"
686 return 1
687 fi
689 echo "modified alpha" > $testroot/content.expected
690 cat $testroot/wt/alpha > $testroot/content
691 cmp -s $testroot/content.expected $testroot/content
692 ret="$?"
693 if [ "$ret" != "0" ]; then
694 diff -u $testroot/content.expected $testroot/content
695 test_done "$testroot" "$ret"
696 return 1
697 fi
699 echo ' M alpha' > $testroot/stdout.expected
700 echo ' D beta' >> $testroot/stdout.expected
701 echo 'MA foo' >> $testroot/stdout.expected
702 (cd $testroot/wt && got status > $testroot/stdout)
703 cmp -s $testroot/stdout.expected $testroot/stdout
704 ret="$?"
705 if [ "$ret" != "0" ]; then
706 diff -u $testroot/stdout.expected $testroot/stdout
707 test_done "$testroot" "$ret"
708 return 1
709 fi
711 (cd $testroot/wt && got revert alpha > $testroot/stdout)
712 ret="$?"
713 if [ "$ret" != "0" ]; then
714 echo "revert command failed unexpectedly" >&2
715 test_done "$testroot" "$ret"
716 return 1
717 fi
719 echo -n > $testroot/stdout.expected
720 cmp -s $testroot/stdout.expected $testroot/stdout
721 ret="$?"
722 if [ "$ret" != "0" ]; then
723 diff -u $testroot/stdout.expected $testroot/stdout
724 test_done "$testroot" "$ret"
725 return 1
726 fi
728 echo "modified alpha" > $testroot/content.expected
729 cat $testroot/wt/alpha > $testroot/content
730 cmp -s $testroot/content.expected $testroot/content
731 ret="$?"
732 if [ "$ret" != "0" ]; then
733 diff -u $testroot/content.expected $testroot/content
734 test_done "$testroot" "$ret"
735 return 1
736 fi
738 (cd $testroot/wt && got revert beta > $testroot/stdout \
739 2> $testroot/stderr)
740 ret="$?"
741 if [ "$ret" != "0" ]; then
742 echo "revert command failed unexpectedly" >&2
743 test_done "$testroot" "$ret"
744 return 1
745 fi
747 echo -n > $testroot/stdout.expected
748 cmp -s $testroot/stdout.expected $testroot/stdout
749 ret="$?"
750 if [ "$ret" != "0" ]; then
751 diff -u $testroot/stdout.expected $testroot/stdout
752 test_done "$testroot" "$ret"
753 return 1
754 fi
756 echo -n > $testroot/stderr.expected
757 cmp -s $testroot/stderr.expected $testroot/stderr
758 ret="$?"
759 if [ "$ret" != "0" ]; then
760 diff -u $testroot/stderr.expected $testroot/stderr
761 test_done "$testroot" "$ret"
762 return 1
763 fi
765 (cd $testroot/wt && got revert foo > $testroot/stdout)
766 ret="$?"
767 if [ "$ret" != "0" ]; then
768 echo "revert command failed unexpectedly" >&2
769 test_done "$testroot" "$ret"
770 return 1
771 fi
773 echo "R foo" > $testroot/stdout.expected
774 cmp -s $testroot/stdout.expected $testroot/stdout
775 ret="$?"
776 if [ "$ret" != "0" ]; then
777 diff -u $testroot/stdout.expected $testroot/stdout
778 test_done "$testroot" "$ret"
779 return 1
780 fi
782 echo "new file" > $testroot/content.expected
783 cat $testroot/wt/foo > $testroot/content
784 cmp -s $testroot/content.expected $testroot/content
785 ret="$?"
786 if [ "$ret" != "0" ]; then
787 diff -u $testroot/content.expected $testroot/content
788 test_done "$testroot" "$ret"
789 return 1
790 fi
792 echo ' M alpha' > $testroot/stdout.expected
793 echo ' D beta' >> $testroot/stdout.expected
794 echo ' A foo' >> $testroot/stdout.expected
795 (cd $testroot/wt && got status > $testroot/stdout)
796 cmp -s $testroot/stdout.expected $testroot/stdout
797 ret="$?"
798 if [ "$ret" != "0" ]; then
799 diff -u $testroot/stdout.expected $testroot/stdout
800 test_done "$testroot" "$ret"
801 return 1
802 fi
804 (cd $testroot/wt && got revert foo > $testroot/stdout)
805 ret="$?"
806 if [ "$ret" != "0" ]; then
807 echo "revert command failed unexpectedly" >&2
808 test_done "$testroot" "$ret"
809 return 1
810 fi
812 echo -n > $testroot/stdout.expected
813 cmp -s $testroot/stdout.expected $testroot/stdout
814 ret="$?"
815 if [ "$ret" != "0" ]; then
816 diff -u $testroot/stdout.expected $testroot/stdout
817 test_done "$testroot" "$ret"
818 return 1
819 fi
821 echo "new file" > $testroot/content.expected
822 cat $testroot/wt/foo > $testroot/content
823 cmp -s $testroot/content.expected $testroot/content
824 ret="$?"
825 if [ "$ret" != "0" ]; then
826 diff -u $testroot/content.expected $testroot/content
827 test_done "$testroot" "$ret"
828 return 1
829 fi
831 echo ' M alpha' > $testroot/stdout.expected
832 echo ' D beta' >> $testroot/stdout.expected
833 echo ' A foo' >> $testroot/stdout.expected
834 (cd $testroot/wt && got status > $testroot/stdout)
835 cmp -s $testroot/stdout.expected $testroot/stdout
836 ret="$?"
837 if [ "$ret" != "0" ]; then
838 diff -u $testroot/stdout.expected $testroot/stdout
839 test_done "$testroot" "$ret"
840 return 1
841 fi
843 echo "modified file again" >> $testroot/wt/alpha
844 echo "modified added file again" >> $testroot/wt/foo
846 (cd $testroot/wt && got revert -R . > $testroot/stdout \
847 2> $testroot/stderr)
848 ret="$?"
849 if [ "$ret" != "0" ]; then
850 echo "revert command failed unexpectedly" >&2
851 test_done "$testroot" "$ret"
852 return 1
853 fi
855 echo "R alpha" > $testroot/stdout.expected
856 echo "R foo" >> $testroot/stdout.expected
857 cmp -s $testroot/stdout.expected $testroot/stdout
858 ret="$?"
859 if [ "$ret" != "0" ]; then
860 diff -u $testroot/stdout.expected $testroot/stdout
861 test_done "$testroot" "$ret"
862 return 1
863 fi
865 echo -n > $testroot/stderr.expected
866 cmp -s $testroot/stderr.expected $testroot/stderr
867 ret="$?"
868 if [ "$ret" != "0" ]; then
869 diff -u $testroot/stderr.expected $testroot/stderr
870 test_done "$testroot" "$ret"
871 return 1
872 fi
874 echo ' M alpha' > $testroot/stdout.expected
875 echo ' D beta' >> $testroot/stdout.expected
876 echo ' A foo' >> $testroot/stdout.expected
877 (cd $testroot/wt && got status > $testroot/stdout)
878 cmp -s $testroot/stdout.expected $testroot/stdout
879 ret="$?"
880 if [ "$ret" != "0" ]; then
881 diff -u $testroot/stdout.expected $testroot/stdout
882 fi
883 test_done "$testroot" "$ret"
886 function test_stage_diff {
887 local testroot=`test_init stage_diff`
888 local head_commit=`git_show_head $testroot/repo`
890 got checkout $testroot/repo $testroot/wt > /dev/null
891 ret="$?"
892 if [ "$ret" != "0" ]; then
893 test_done "$testroot" "$ret"
894 return 1
895 fi
897 echo "modified file" > $testroot/wt/alpha
898 (cd $testroot/wt && got rm beta > /dev/null)
899 echo "new file" > $testroot/wt/foo
900 (cd $testroot/wt && got add foo > /dev/null)
902 (cd $testroot/wt && got diff -s > $testroot/stdout)
903 echo -n > $testroot/stdout.expected
904 cmp -s $testroot/stdout.expected $testroot/stdout
905 ret="$?"
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 test_done "$testroot" "$ret"
909 return 1
910 fi
912 echo ' M alpha' > $testroot/stdout.expected
913 echo ' D beta' >> $testroot/stdout.expected
914 echo ' A foo' >> $testroot/stdout.expected
915 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
917 (cd $testroot/wt && got diff > $testroot/stdout)
918 echo -n > $testroot/stdout.expected
919 cmp -s $testroot/stdout.expected $testroot/stdout
920 ret="$?"
921 if [ "$ret" != "0" ]; then
922 diff -u $testroot/stdout.expected $testroot/stdout
923 test_done "$testroot" "$ret"
924 return 1
925 fi
927 echo "modified file again" > $testroot/wt/alpha
928 echo "new file changed" > $testroot/wt/foo
930 (cd $testroot/wt && got diff > $testroot/stdout)
932 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
933 echo -n 'blob - ' >> $testroot/stdout.expected
934 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
935 >> $testroot/stdout.expected
936 echo ' (staged)' >> $testroot/stdout.expected
937 echo 'file + alpha' >> $testroot/stdout.expected
938 echo '--- alpha' >> $testroot/stdout.expected
939 echo '+++ alpha' >> $testroot/stdout.expected
940 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
941 echo '-modified file' >> $testroot/stdout.expected
942 echo '+modified file again' >> $testroot/stdout.expected
943 echo -n 'blob - ' >> $testroot/stdout.expected
944 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
945 >> $testroot/stdout.expected
946 echo " (staged)" >> $testroot/stdout.expected
947 echo 'file + foo' >> $testroot/stdout.expected
948 echo '--- foo' >> $testroot/stdout.expected
949 echo '+++ foo' >> $testroot/stdout.expected
950 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
951 echo '-new file' >> $testroot/stdout.expected
952 echo '+new file changed' >> $testroot/stdout.expected
954 cmp -s $testroot/stdout.expected $testroot/stdout
955 ret="$?"
956 if [ "$ret" != "0" ]; then
957 diff -u $testroot/stdout.expected $testroot/stdout
958 test_done "$testroot" "$ret"
959 return 1
960 fi
962 (cd $testroot/wt && got diff -s > $testroot/stdout)
964 echo "diff $head_commit $testroot/wt (staged changes)" \
965 > $testroot/stdout.expected
966 echo -n 'blob - ' >> $testroot/stdout.expected
967 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
968 >> $testroot/stdout.expected
969 echo -n 'blob + ' >> $testroot/stdout.expected
970 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
971 >> $testroot/stdout.expected
972 echo '--- alpha' >> $testroot/stdout.expected
973 echo '+++ alpha' >> $testroot/stdout.expected
974 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
975 echo '-alpha' >> $testroot/stdout.expected
976 echo '+modified file' >> $testroot/stdout.expected
977 echo -n 'blob - ' >> $testroot/stdout.expected
978 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
979 >> $testroot/stdout.expected
980 echo 'blob + /dev/null' >> $testroot/stdout.expected
981 echo '--- beta' >> $testroot/stdout.expected
982 echo '+++ /dev/null' >> $testroot/stdout.expected
983 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
984 echo '-beta' >> $testroot/stdout.expected
985 echo 'blob - /dev/null' >> $testroot/stdout.expected
986 echo -n 'blob + ' >> $testroot/stdout.expected
987 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
988 >> $testroot/stdout.expected
989 echo '--- /dev/null' >> $testroot/stdout.expected
990 echo '+++ foo' >> $testroot/stdout.expected
991 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
992 echo '+new file' >> $testroot/stdout.expected
994 cmp -s $testroot/stdout.expected $testroot/stdout
995 ret="$?"
996 if [ "$ret" != "0" ]; then
997 diff -u $testroot/stdout.expected $testroot/stdout
998 fi
999 test_done "$testroot" "$ret"
1003 function test_stage_histedit {
1004 local testroot=`test_init stage_histedit`
1005 local orig_commit=`git_show_head $testroot/repo`
1007 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1008 ret="$?"
1009 if [ "$ret" != "0" ]; then
1010 test_done "$testroot" "$ret"
1011 return 1
1014 echo "modified file" > $testroot/wt/alpha
1015 (cd $testroot/wt && got stage alpha > /dev/null)
1017 echo "modified alpha on master" > $testroot/repo/alpha
1018 (cd $testroot/repo && git rm -q beta)
1019 echo "new file on master" > $testroot/repo/epsilon/new
1020 (cd $testroot/repo && git add epsilon/new)
1021 git_commit $testroot/repo -m "committing changes"
1022 local old_commit1=`git_show_head $testroot/repo`
1024 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1025 git_commit $testroot/repo -m "committing to zeta on master"
1026 local old_commit2=`git_show_head $testroot/repo`
1028 echo "pick $old_commit1" > $testroot/histedit-script
1029 echo "pick $old_commit2" >> $testroot/histedit-script
1031 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1032 > $testroot/stdout 2> $testroot/stderr)
1033 ret="$?"
1034 if [ "$ret" == "0" ]; then
1035 echo "got histedit command succeeded unexpectedly" >&2
1036 test_done "$testroot" "1"
1037 return 1
1040 echo -n > $testroot/stdout.expected
1041 echo "got: alpha: file is staged" > $testroot/stderr.expected
1043 cmp -s $testroot/stderr.expected $testroot/stderr
1044 ret="$?"
1045 if [ "$ret" != "0" ]; then
1046 diff -u $testroot/stderr.expected $testroot/stderr
1047 test_done "$testroot" "$ret"
1048 return 1
1050 cmp -s $testroot/stdout.expected $testroot/stdout
1051 ret="$?"
1052 if [ "$ret" != "0" ]; then
1053 diff -u $testroot/stdout.expected $testroot/stdout
1055 test_done "$testroot" "$ret"
1059 function test_stage_rebase {
1060 local testroot=`test_init stage_rebase`
1062 (cd $testroot/repo && git checkout -q -b newbranch)
1063 echo "modified delta on branch" > $testroot/repo/gamma/delta
1064 git_commit $testroot/repo -m "committing to delta on newbranch"
1066 echo "modified alpha on branch" > $testroot/repo/alpha
1067 (cd $testroot/repo && git rm -q beta)
1068 echo "new file on branch" > $testroot/repo/epsilon/new
1069 (cd $testroot/repo && git add epsilon/new)
1070 git_commit $testroot/repo -m "committing more changes on newbranch"
1072 local orig_commit1=`git_show_parent_commit $testroot/repo`
1073 local orig_commit2=`git_show_head $testroot/repo`
1075 (cd $testroot/repo && git checkout -q master)
1076 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1077 git_commit $testroot/repo -m "committing to zeta on master"
1078 local master_commit=`git_show_head $testroot/repo`
1080 got checkout $testroot/repo $testroot/wt > /dev/null
1081 ret="$?"
1082 if [ "$ret" != "0" ]; then
1083 test_done "$testroot" "$ret"
1084 return 1
1087 echo "modified file" > $testroot/wt/alpha
1088 (cd $testroot/wt && got stage alpha > /dev/null)
1090 (cd $testroot/wt && got rebase newbranch \
1091 > $testroot/stdout 2> $testroot/stderr)
1092 ret="$?"
1093 if [ "$ret" == "0" ]; then
1094 echo "got rebase command succeeded unexpectedly" >&2
1095 test_done "$testroot" "1"
1096 return 1
1099 echo -n > $testroot/stdout.expected
1100 echo "got: alpha: file is staged" > $testroot/stderr.expected
1102 cmp -s $testroot/stderr.expected $testroot/stderr
1103 ret="$?"
1104 if [ "$ret" != "0" ]; then
1105 diff -u $testroot/stderr.expected $testroot/stderr
1106 test_done "$testroot" "$ret"
1107 return 1
1109 cmp -s $testroot/stdout.expected $testroot/stdout
1110 ret="$?"
1111 if [ "$ret" != "0" ]; then
1112 diff -u $testroot/stdout.expected $testroot/stdout
1114 test_done "$testroot" "$ret"
1117 function test_stage_update {
1118 local testroot=`test_init stage_update`
1120 got checkout $testroot/repo $testroot/wt > /dev/null
1121 ret="$?"
1122 if [ "$ret" != "0" ]; then
1123 test_done "$testroot" "$ret"
1124 return 1
1127 echo "modified file" > $testroot/wt/alpha
1128 (cd $testroot/wt && got stage alpha > /dev/null)
1130 echo "modified alpha" > $testroot/repo/alpha
1131 git_commit $testroot/repo -m "modified alpha"
1133 (cd $testroot/wt && got update > $testroot/stdout \
1134 2> $testroot/stderr)
1135 ret="$?"
1136 if [ "$ret" == "0" ]; then
1137 echo "got update command succeeded unexpectedly" >&2
1138 test_done "$testroot" "1"
1139 return 1
1142 echo -n > $testroot/stdout.expected
1143 echo "got: alpha: file is staged" > $testroot/stderr.expected
1145 cmp -s $testroot/stderr.expected $testroot/stderr
1146 ret="$?"
1147 if [ "$ret" != "0" ]; then
1148 diff -u $testroot/stderr.expected $testroot/stderr
1149 test_done "$testroot" "$ret"
1150 return 1
1152 cmp -s $testroot/stdout.expected $testroot/stdout
1153 ret="$?"
1154 if [ "$ret" != "0" ]; then
1155 diff -u $testroot/stdout.expected $testroot/stdout
1157 test_done "$testroot" "$ret"
1160 function test_stage_commit_non_staged {
1161 local testroot=`test_init stage_commit_non_staged`
1163 got checkout $testroot/repo $testroot/wt > /dev/null
1164 ret="$?"
1165 if [ "$ret" != "0" ]; then
1166 test_done "$testroot" "$ret"
1167 return 1
1170 echo "modified file" > $testroot/wt/alpha
1171 (cd $testroot/wt && got rm beta > /dev/null)
1172 echo "new file" > $testroot/wt/foo
1173 (cd $testroot/wt && got add foo > /dev/null)
1174 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1176 echo "modified file" > $testroot/wt/gamma/delta
1177 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1178 > $testroot/stdout 2> $testroot/stderr)
1179 ret="$?"
1180 if [ "$ret" == "0" ]; then
1181 echo "got commit command succeeded unexpectedly" >&2
1182 test_done "$testroot" "1"
1183 return 1
1186 echo -n > $testroot/stdout.expected
1187 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1189 cmp -s $testroot/stderr.expected $testroot/stderr
1190 ret="$?"
1191 if [ "$ret" != "0" ]; then
1192 diff -u $testroot/stderr.expected $testroot/stderr
1193 test_done "$testroot" "$ret"
1194 return 1
1196 cmp -s $testroot/stdout.expected $testroot/stdout
1197 ret="$?"
1198 if [ "$ret" != "0" ]; then
1199 diff -u $testroot/stdout.expected $testroot/stdout
1201 test_done "$testroot" "$ret"
1204 function test_stage_commit_out_of_date {
1205 local testroot=`test_init stage_commit_out_of_date`
1207 got checkout $testroot/repo $testroot/wt > /dev/null
1208 ret="$?"
1209 if [ "$ret" != "0" ]; then
1210 test_done "$testroot" "$ret"
1211 return 1
1214 echo "modified file" > $testroot/wt/alpha
1215 (cd $testroot/wt && got rm beta > /dev/null)
1216 echo "new file" > $testroot/wt/foo
1217 (cd $testroot/wt && got add foo > /dev/null)
1218 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1220 echo "changed file" > $testroot/repo/alpha
1221 git_commit $testroot/repo -m "changed alpha in repo"
1223 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1224 2> $testroot/stderr)
1225 ret="$?"
1226 if [ "$ret" == "0" ]; then
1227 echo "got commit command succeeded unexpectedly" >&2
1228 test_done "$testroot" "1"
1229 return 1
1232 echo -n > $testroot/stdout.expected
1233 echo -n "got: work tree must be updated before these changes " \
1234 > $testroot/stderr.expected
1235 echo "can be committed" >> $testroot/stderr.expected
1237 cmp -s $testroot/stderr.expected $testroot/stderr
1238 ret="$?"
1239 if [ "$ret" != "0" ]; then
1240 diff -u $testroot/stderr.expected $testroot/stderr
1241 test_done "$testroot" "$ret"
1242 return 1
1244 cmp -s $testroot/stdout.expected $testroot/stdout
1245 ret="$?"
1246 if [ "$ret" != "0" ]; then
1247 diff -u $testroot/stdout.expected $testroot/stdout
1248 test_done "$testroot" "$ret"
1249 return 1
1252 (cd $testroot/wt && got update > $testroot/stdout \
1253 2> $testroot/stderr)
1254 echo -n > $testroot/stdout.expected
1255 echo "got: alpha: file is staged" > $testroot/stderr.expected
1257 cmp -s $testroot/stderr.expected $testroot/stderr
1258 ret="$?"
1259 if [ "$ret" != "0" ]; then
1260 diff -u $testroot/stderr.expected $testroot/stderr
1261 test_done "$testroot" "$ret"
1262 return 1
1264 cmp -s $testroot/stdout.expected $testroot/stdout
1265 ret="$?"
1266 if [ "$ret" != "0" ]; then
1267 diff -u $testroot/stdout.expected $testroot/stdout
1268 test_done "$testroot" "$ret"
1269 return 1
1272 (cd $testroot/wt && got unstage > /dev/null)
1273 (cd $testroot/wt && got update > $testroot/stdout)
1274 ret="$?"
1275 if [ "$ret" != "0" ]; then
1276 echo "got update command failed unexpectedly" >&2
1277 test_done "$testroot" "$ret"
1278 return 1
1281 (cd $testroot/wt && got status > $testroot/stdout)
1282 echo "C alpha" > $testroot/stdout.expected
1283 echo "D beta" >> $testroot/stdout.expected
1284 echo "A foo" >> $testroot/stdout.expected
1285 cmp -s $testroot/stdout.expected $testroot/stdout
1286 ret="$?"
1287 if [ "$ret" != "0" ]; then
1288 diff -u $testroot/stdout.expected $testroot/stdout
1289 test_done "$testroot" "$ret"
1290 return 1
1293 # resolve conflict
1294 echo "resolved file" > $testroot/wt/alpha
1296 (cd $testroot/wt && got stage > /dev/null)
1298 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1299 ret="$?"
1300 if [ "$ret" != "0" ]; then
1301 echo "got commit command failed unexpectedly" >&2
1302 test_done "$testroot" "$ret"
1303 return 1
1306 local commit_id=`git_show_head $testroot/repo`
1307 echo "A foo" > $testroot/stdout.expected
1308 echo "M alpha" >> $testroot/stdout.expected
1309 echo "D beta" >> $testroot/stdout.expected
1310 echo "Created commit $commit_id" >> $testroot/stdout.expected
1311 cmp -s $testroot/stdout.expected $testroot/stdout
1312 ret="$?"
1313 if [ "$ret" != "0" ]; then
1314 diff -u $testroot/stdout.expected $testroot/stdout
1316 test_done "$testroot" "$ret"
1320 function test_stage_commit {
1321 local testroot=`test_init stage_commit`
1322 local first_commit=`git_show_head $testroot/repo`
1324 got checkout $testroot/repo $testroot/wt > /dev/null
1325 ret="$?"
1326 if [ "$ret" != "0" ]; then
1327 test_done "$testroot" "$ret"
1328 return 1
1331 echo "modified file" > $testroot/wt/alpha
1332 (cd $testroot/wt && got rm beta > /dev/null)
1333 echo "new file" > $testroot/wt/foo
1334 (cd $testroot/wt && got add foo > /dev/null)
1335 echo "modified file" > $testroot/wt/alpha
1336 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1338 echo "modified file again" > $testroot/wt/alpha
1339 echo "new file changed" > $testroot/wt/foo
1340 echo "non-staged change" > $testroot/wt/gamma/delta
1341 echo "non-staged new file" > $testroot/wt/epsilon/new
1342 (cd $testroot/wt && got add epsilon/new > /dev/null)
1343 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1345 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1346 > $testroot/blob_id_alpha
1347 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1348 > $testroot/blob_id_foo
1350 (cd $testroot/wt && got commit -m "staged changes" \
1351 > $testroot/stdout)
1352 ret="$?"
1353 if [ "$ret" != "0" ]; then
1354 echo "got commit command failed unexpectedly" >&2
1355 test_done "$testroot" "1"
1356 return 1
1359 local head_commit=`git_show_head $testroot/repo`
1360 echo "A foo" > $testroot/stdout.expected
1361 echo "M alpha" >> $testroot/stdout.expected
1362 echo "D beta" >> $testroot/stdout.expected
1363 echo "Created commit $head_commit" >> $testroot/stdout.expected
1365 cmp -s $testroot/stdout.expected $testroot/stdout
1366 ret="$?"
1367 if [ "$ret" != "0" ]; then
1368 diff -u $testroot/stdout.expected $testroot/stdout
1369 test_done "$testroot" "$ret"
1370 return 1
1373 got diff -r $testroot/repo $first_commit $head_commit \
1374 > $testroot/stdout
1376 echo "diff $first_commit $head_commit" \
1377 > $testroot/stdout.expected
1378 echo -n 'blob - ' >> $testroot/stdout.expected
1379 got tree -r $testroot/repo -i -c $first_commit | \
1380 grep 'alpha$' | cut -d' ' -f 1 \
1381 >> $testroot/stdout.expected
1382 echo -n 'blob + ' >> $testroot/stdout.expected
1383 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1384 echo '--- alpha' >> $testroot/stdout.expected
1385 echo '+++ alpha' >> $testroot/stdout.expected
1386 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1387 echo '-alpha' >> $testroot/stdout.expected
1388 echo '+modified file' >> $testroot/stdout.expected
1389 echo -n 'blob - ' >> $testroot/stdout.expected
1390 got tree -r $testroot/repo -i -c $first_commit \
1391 | grep 'beta$' | cut -d' ' -f 1 | tr -d '\n' \
1392 >> $testroot/stdout.expected
1393 echo " (mode 644)" >> $testroot/stdout.expected
1394 echo 'blob + /dev/null' >> $testroot/stdout.expected
1395 echo '--- beta' >> $testroot/stdout.expected
1396 echo '+++ /dev/null' >> $testroot/stdout.expected
1397 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1398 echo '-beta' >> $testroot/stdout.expected
1399 echo 'blob - /dev/null' >> $testroot/stdout.expected
1400 echo -n 'blob + ' >> $testroot/stdout.expected
1401 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1402 echo " (mode 644)" >> $testroot/stdout.expected
1403 echo '--- /dev/null' >> $testroot/stdout.expected
1404 echo '+++ foo' >> $testroot/stdout.expected
1405 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1406 echo '+new file' >> $testroot/stdout.expected
1408 cmp -s $testroot/stdout.expected $testroot/stdout
1409 ret="$?"
1410 if [ "$ret" != "0" ]; then
1411 diff -u $testroot/stdout.expected $testroot/stdout
1412 test_done "$testroot" "$ret"
1413 return 1
1416 echo 'M alpha' > $testroot/stdout.expected
1417 echo 'A epsilon/new' >> $testroot/stdout.expected
1418 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1419 echo 'M foo' >> $testroot/stdout.expected
1420 echo 'M gamma/delta' >> $testroot/stdout.expected
1422 (cd $testroot/wt && got status > $testroot/stdout)
1423 cmp -s $testroot/stdout.expected $testroot/stdout
1424 ret="$?"
1425 if [ "$ret" != "0" ]; then
1426 diff -u $testroot/stdout.expected $testroot/stdout
1428 test_done "$testroot" "$ret"
1431 function test_stage_patch {
1432 local testroot=`test_init stage_patch`
1434 jot 16 > $testroot/repo/numbers
1435 (cd $testroot/repo && git add numbers)
1436 git_commit $testroot/repo -m "added numbers file"
1437 local commit_id=`git_show_head $testroot/repo`
1439 got checkout $testroot/repo $testroot/wt > /dev/null
1440 ret="$?"
1441 if [ "$ret" != "0" ]; then
1442 test_done "$testroot" "$ret"
1443 return 1
1446 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1447 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1448 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1450 # don't stage any hunks
1451 printf "n\nn\nn\n" > $testroot/patchscript
1452 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1453 numbers > $testroot/stdout 2> $testroot/stderr)
1454 ret="$?"
1455 if [ "$ret" == "0" ]; then
1456 echo "got stage command succeeded unexpectedly" >&2
1457 test_done "$testroot" "1"
1458 return 1
1460 cat > $testroot/stdout.expected <<EOF
1461 -----------------------------------------------
1462 @@ -1,5 +1,5 @@
1469 -----------------------------------------------
1470 M numbers (change 1 of 3)
1471 stage this change? [y/n/q] n
1472 -----------------------------------------------
1473 @@ -4,7 +4,7 @@
1482 -----------------------------------------------
1483 M numbers (change 2 of 3)
1484 stage this change? [y/n/q] n
1485 -----------------------------------------------
1486 @@ -13,4 +13,4 @@
1490 -16
1492 -----------------------------------------------
1493 M numbers (change 3 of 3)
1494 stage this change? [y/n/q] n
1495 EOF
1496 cmp -s $testroot/stdout.expected $testroot/stdout
1497 ret="$?"
1498 if [ "$ret" != "0" ]; then
1499 diff -u $testroot/stdout.expected $testroot/stdout
1500 test_done "$testroot" "$ret"
1501 return 1
1504 echo "got: no changes to stage" > $testroot/stderr.expected
1505 cmp -s $testroot/stderr.expected $testroot/stderr
1506 ret="$?"
1507 if [ "$ret" != "0" ]; then
1508 diff -u $testroot/stderr.expected $testroot/stderr
1509 test_done "$testroot" "$ret"
1510 return 1
1514 (cd $testroot/wt && got status > $testroot/stdout)
1515 echo "M numbers" > $testroot/stdout.expected
1516 cmp -s $testroot/stdout.expected $testroot/stdout
1517 ret="$?"
1518 if [ "$ret" != "0" ]; then
1519 diff -u $testroot/stdout.expected $testroot/stdout
1520 test_done "$testroot" "$ret"
1521 return 1
1524 # stage middle hunk
1525 printf "n\ny\nn\n" > $testroot/patchscript
1526 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1527 numbers > $testroot/stdout)
1529 cat > $testroot/stdout.expected <<EOF
1530 -----------------------------------------------
1531 @@ -1,5 +1,5 @@
1538 -----------------------------------------------
1539 M numbers (change 1 of 3)
1540 stage this change? [y/n/q] n
1541 -----------------------------------------------
1542 @@ -4,7 +4,7 @@
1551 -----------------------------------------------
1552 M numbers (change 2 of 3)
1553 stage this change? [y/n/q] y
1554 -----------------------------------------------
1555 @@ -13,4 +13,4 @@
1559 -16
1561 -----------------------------------------------
1562 M numbers (change 3 of 3)
1563 stage this change? [y/n/q] n
1564 EOF
1565 cmp -s $testroot/stdout.expected $testroot/stdout
1566 ret="$?"
1567 if [ "$ret" != "0" ]; then
1568 diff -u $testroot/stdout.expected $testroot/stdout
1569 test_done "$testroot" "$ret"
1570 return 1
1573 (cd $testroot/wt && got status > $testroot/stdout)
1574 echo "MM numbers" > $testroot/stdout.expected
1575 cmp -s $testroot/stdout.expected $testroot/stdout
1576 ret="$?"
1577 if [ "$ret" != "0" ]; then
1578 diff -u $testroot/stdout.expected $testroot/stdout
1579 test_done "$testroot" "$ret"
1580 return 1
1583 (cd $testroot/wt && got diff -s > $testroot/stdout)
1585 echo "diff $commit_id $testroot/wt (staged changes)" \
1586 > $testroot/stdout.expected
1587 echo -n 'blob - ' >> $testroot/stdout.expected
1588 got tree -r $testroot/repo -i -c $commit_id \
1589 | grep 'numbers$' | cut -d' ' -f 1 \
1590 >> $testroot/stdout.expected
1591 echo -n 'blob + ' >> $testroot/stdout.expected
1592 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1593 >> $testroot/stdout.expected
1594 echo "--- numbers" >> $testroot/stdout.expected
1595 echo "+++ numbers" >> $testroot/stdout.expected
1596 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1597 echo " 4" >> $testroot/stdout.expected
1598 echo " 5" >> $testroot/stdout.expected
1599 echo " 6" >> $testroot/stdout.expected
1600 echo "-7" >> $testroot/stdout.expected
1601 echo "+b" >> $testroot/stdout.expected
1602 echo " 8" >> $testroot/stdout.expected
1603 echo " 9" >> $testroot/stdout.expected
1604 echo " 10" >> $testroot/stdout.expected
1605 cmp -s $testroot/stdout.expected $testroot/stdout
1606 ret="$?"
1607 if [ "$ret" != "0" ]; then
1608 diff -u $testroot/stdout.expected $testroot/stdout
1609 test_done "$testroot" "$ret"
1610 return 1
1613 (cd $testroot/wt && got unstage >/dev/null)
1614 ret="$?"
1615 if [ "$ret" != "0" ]; then
1616 echo "got stage command failed unexpectedly" >&2
1617 test_done "$testroot" "1"
1618 return 1
1620 (cd $testroot/wt && got status > $testroot/stdout)
1621 echo "M numbers" > $testroot/stdout.expected
1622 cmp -s $testroot/stdout.expected $testroot/stdout
1623 ret="$?"
1624 if [ "$ret" != "0" ]; then
1625 diff -u $testroot/stdout.expected $testroot/stdout
1626 test_done "$testroot" "$ret"
1627 return 1
1630 # stage last hunk
1631 printf "n\nn\ny\n" > $testroot/patchscript
1632 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1633 numbers > $testroot/stdout)
1635 cat > $testroot/stdout.expected <<EOF
1636 -----------------------------------------------
1637 @@ -1,5 +1,5 @@
1644 -----------------------------------------------
1645 M numbers (change 1 of 3)
1646 stage this change? [y/n/q] n
1647 -----------------------------------------------
1648 @@ -4,7 +4,7 @@
1657 -----------------------------------------------
1658 M numbers (change 2 of 3)
1659 stage this change? [y/n/q] n
1660 -----------------------------------------------
1661 @@ -13,4 +13,4 @@
1665 -16
1667 -----------------------------------------------
1668 M numbers (change 3 of 3)
1669 stage this change? [y/n/q] y
1670 EOF
1671 cmp -s $testroot/stdout.expected $testroot/stdout
1672 ret="$?"
1673 if [ "$ret" != "0" ]; then
1674 diff -u $testroot/stdout.expected $testroot/stdout
1675 test_done "$testroot" "$ret"
1676 return 1
1679 (cd $testroot/wt && got status > $testroot/stdout)
1680 echo "MM numbers" > $testroot/stdout.expected
1681 cmp -s $testroot/stdout.expected $testroot/stdout
1682 ret="$?"
1683 if [ "$ret" != "0" ]; then
1684 diff -u $testroot/stdout.expected $testroot/stdout
1685 test_done "$testroot" "$ret"
1686 return 1
1689 (cd $testroot/wt && got diff -s > $testroot/stdout)
1691 echo "diff $commit_id $testroot/wt (staged changes)" \
1692 > $testroot/stdout.expected
1693 echo -n 'blob - ' >> $testroot/stdout.expected
1694 got tree -r $testroot/repo -i -c $commit_id \
1695 | grep 'numbers$' | cut -d' ' -f 1 \
1696 >> $testroot/stdout.expected
1697 echo -n 'blob + ' >> $testroot/stdout.expected
1698 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1699 >> $testroot/stdout.expected
1700 echo "--- numbers" >> $testroot/stdout.expected
1701 echo "+++ numbers" >> $testroot/stdout.expected
1702 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1703 echo " 13" >> $testroot/stdout.expected
1704 echo " 14" >> $testroot/stdout.expected
1705 echo " 15" >> $testroot/stdout.expected
1706 echo "-16" >> $testroot/stdout.expected
1707 echo "+c" >> $testroot/stdout.expected
1708 cmp -s $testroot/stdout.expected $testroot/stdout
1709 ret="$?"
1710 if [ "$ret" != "0" ]; then
1711 diff -u $testroot/stdout.expected $testroot/stdout
1713 test_done "$testroot" "$ret"
1716 function test_stage_patch_twice {
1717 local testroot=`test_init stage_patch_twice`
1719 jot 16 > $testroot/repo/numbers
1720 (cd $testroot/repo && git add numbers)
1721 git_commit $testroot/repo -m "added numbers file"
1722 local commit_id=`git_show_head $testroot/repo`
1724 got checkout $testroot/repo $testroot/wt > /dev/null
1725 ret="$?"
1726 if [ "$ret" != "0" ]; then
1727 test_done "$testroot" "$ret"
1728 return 1
1731 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1732 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1733 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1735 # stage middle hunk
1736 printf "n\ny\nn\n" > $testroot/patchscript
1737 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1738 numbers > $testroot/stdout)
1740 cat > $testroot/stdout.expected <<EOF
1741 -----------------------------------------------
1742 @@ -1,5 +1,5 @@
1749 -----------------------------------------------
1750 M numbers (change 1 of 3)
1751 stage this change? [y/n/q] n
1752 -----------------------------------------------
1753 @@ -4,7 +4,7 @@
1762 -----------------------------------------------
1763 M numbers (change 2 of 3)
1764 stage this change? [y/n/q] y
1765 -----------------------------------------------
1766 @@ -13,4 +13,4 @@
1770 -16
1772 -----------------------------------------------
1773 M numbers (change 3 of 3)
1774 stage this change? [y/n/q] n
1775 EOF
1776 cmp -s $testroot/stdout.expected $testroot/stdout
1777 ret="$?"
1778 if [ "$ret" != "0" ]; then
1779 diff -u $testroot/stdout.expected $testroot/stdout
1780 test_done "$testroot" "$ret"
1781 return 1
1784 (cd $testroot/wt && got status > $testroot/stdout)
1785 echo "MM numbers" > $testroot/stdout.expected
1786 cmp -s $testroot/stdout.expected $testroot/stdout
1787 ret="$?"
1788 if [ "$ret" != "0" ]; then
1789 diff -u $testroot/stdout.expected $testroot/stdout
1790 test_done "$testroot" "$ret"
1791 return 1
1794 # stage last hunk
1795 printf "n\ny\n" > $testroot/patchscript
1796 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1797 numbers > $testroot/stdout)
1799 cat > $testroot/stdout.expected <<EOF
1800 -----------------------------------------------
1801 @@ -1,5 +1,5 @@ b
1808 -----------------------------------------------
1809 M numbers (change 1 of 2)
1810 stage this change? [y/n/q] n
1811 -----------------------------------------------
1812 @@ -13,4 +13,4 @@ b
1816 -16
1818 -----------------------------------------------
1819 M numbers (change 2 of 2)
1820 stage this change? [y/n/q] y
1821 EOF
1822 cmp -s $testroot/stdout.expected $testroot/stdout
1823 ret="$?"
1824 if [ "$ret" != "0" ]; then
1825 diff -u $testroot/stdout.expected $testroot/stdout
1826 test_done "$testroot" "$ret"
1827 return 1
1830 (cd $testroot/wt && got status > $testroot/stdout)
1831 echo "MM numbers" > $testroot/stdout.expected
1832 cmp -s $testroot/stdout.expected $testroot/stdout
1833 ret="$?"
1834 if [ "$ret" != "0" ]; then
1835 diff -u $testroot/stdout.expected $testroot/stdout
1836 test_done "$testroot" "$ret"
1837 return 1
1840 (cd $testroot/wt && got diff -s > $testroot/stdout)
1842 echo "diff $commit_id $testroot/wt (staged changes)" \
1843 > $testroot/stdout.expected
1844 echo -n 'blob - ' >> $testroot/stdout.expected
1845 got tree -r $testroot/repo -i -c $commit_id \
1846 | grep 'numbers$' | cut -d' ' -f 1 \
1847 >> $testroot/stdout.expected
1848 echo -n 'blob + ' >> $testroot/stdout.expected
1849 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1850 >> $testroot/stdout.expected
1851 echo "--- numbers" >> $testroot/stdout.expected
1852 echo "+++ numbers" >> $testroot/stdout.expected
1853 cat >> $testroot/stdout.expected <<EOF
1854 @@ -4,7 +4,7 @@
1863 @@ -13,4 +13,4 @@
1867 -16
1869 EOF
1870 cmp -s $testroot/stdout.expected $testroot/stdout
1871 ret="$?"
1872 if [ "$ret" != "0" ]; then
1873 diff -u $testroot/stdout.expected $testroot/stdout
1874 test_done "$testroot" "$ret"
1875 return 1
1878 (cd $testroot/wt && got diff > $testroot/stdout)
1880 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1881 echo -n 'blob - ' >> $testroot/stdout.expected
1882 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1883 tr -d '\n' >> $testroot/stdout.expected
1884 echo " (staged)" >> $testroot/stdout.expected
1885 echo 'file + numbers' >> $testroot/stdout.expected
1886 echo "--- numbers" >> $testroot/stdout.expected
1887 echo "+++ numbers" >> $testroot/stdout.expected
1888 cat >> $testroot/stdout.expected <<EOF
1889 @@ -1,5 +1,5 @@
1896 EOF
1897 cmp -s $testroot/stdout.expected $testroot/stdout
1898 ret="$?"
1899 if [ "$ret" != "0" ]; then
1900 diff -u $testroot/stdout.expected $testroot/stdout
1902 test_done "$testroot" "$ret"
1905 function test_stage_patch_added {
1906 local testroot=`test_init stage_patch_added`
1907 local commit_id=`git_show_head $testroot/repo`
1909 got checkout $testroot/repo $testroot/wt > /dev/null
1910 ret="$?"
1911 if [ "$ret" != "0" ]; then
1912 test_done "$testroot" "$ret"
1913 return 1
1916 echo "new" > $testroot/wt/epsilon/new
1917 (cd $testroot/wt && got add epsilon/new > /dev/null)
1919 printf "y\n" > $testroot/patchscript
1920 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1921 epsilon/new > $testroot/stdout)
1923 echo "A epsilon/new" > $testroot/stdout.expected
1924 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1925 cmp -s $testroot/stdout.expected $testroot/stdout
1926 ret="$?"
1927 if [ "$ret" != "0" ]; then
1928 diff -u $testroot/stdout.expected $testroot/stdout
1929 test_done "$testroot" "$ret"
1930 return 1
1933 (cd $testroot/wt && got status > $testroot/stdout)
1934 echo " A epsilon/new" > $testroot/stdout.expected
1935 cmp -s $testroot/stdout.expected $testroot/stdout
1936 ret="$?"
1937 if [ "$ret" != "0" ]; then
1938 diff -u $testroot/stdout.expected $testroot/stdout
1939 test_done "$testroot" "$ret"
1940 return 1
1943 (cd $testroot/wt && got diff -s > $testroot/stdout)
1945 echo "diff $commit_id $testroot/wt (staged changes)" \
1946 > $testroot/stdout.expected
1947 echo 'blob - /dev/null' >> $testroot/stdout.expected
1948 echo -n 'blob + ' >> $testroot/stdout.expected
1949 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1950 >> $testroot/stdout.expected
1951 echo "--- /dev/null" >> $testroot/stdout.expected
1952 echo "+++ epsilon/new" >> $testroot/stdout.expected
1953 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1954 echo "+new" >> $testroot/stdout.expected
1955 cmp -s $testroot/stdout.expected $testroot/stdout
1956 ret="$?"
1957 if [ "$ret" != "0" ]; then
1958 diff -u $testroot/stdout.expected $testroot/stdout
1960 test_done "$testroot" "$ret"
1963 function test_stage_patch_added_twice {
1964 local testroot=`test_init stage_patch_added_twice`
1965 local commit_id=`git_show_head $testroot/repo`
1967 got checkout $testroot/repo $testroot/wt > /dev/null
1968 ret="$?"
1969 if [ "$ret" != "0" ]; then
1970 test_done "$testroot" "$ret"
1971 return 1
1974 echo "new" > $testroot/wt/epsilon/new
1975 (cd $testroot/wt && got add epsilon/new > /dev/null)
1977 printf "y\n" > $testroot/patchscript
1978 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1979 epsilon/new > $testroot/stdout)
1981 echo "A epsilon/new" > $testroot/stdout.expected
1982 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1983 cmp -s $testroot/stdout.expected $testroot/stdout
1984 ret="$?"
1985 if [ "$ret" != "0" ]; then
1986 diff -u $testroot/stdout.expected $testroot/stdout
1987 test_done "$testroot" "$ret"
1988 return 1
1991 (cd $testroot/wt && got status > $testroot/stdout)
1992 echo " A epsilon/new" > $testroot/stdout.expected
1993 cmp -s $testroot/stdout.expected $testroot/stdout
1994 ret="$?"
1995 if [ "$ret" != "0" ]; then
1996 diff -u $testroot/stdout.expected $testroot/stdout
1997 test_done "$testroot" "$ret"
1998 return 1
2001 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2002 epsilon/new > $testroot/stdout 2> $testroot/stderr)
2003 ret="$?"
2004 if [ "$ret" == "0" ]; then
2005 echo "got stage command succeeded unexpectedly" >&2
2006 test_done "$testroot" "1"
2007 return 1
2010 echo "got: no changes to stage" > $testroot/stderr.expected
2011 cmp -s $testroot/stderr.expected $testroot/stderr
2012 ret="$?"
2013 if [ "$ret" != "0" ]; then
2014 diff -u $testroot/stderr.expected $testroot/stderr
2015 test_done "$testroot" "$ret"
2016 return 1
2019 echo -n > $testroot/stdout.expected
2020 cmp -s $testroot/stdout.expected $testroot/stdout
2021 ret="$?"
2022 if [ "$ret" != "0" ]; then
2023 diff -u $testroot/stdout.expected $testroot/stdout
2025 test_done "$testroot" "$ret"
2028 function test_stage_patch_removed {
2029 local testroot=`test_init stage_patch_removed`
2030 local commit_id=`git_show_head $testroot/repo`
2032 got checkout $testroot/repo $testroot/wt > /dev/null
2033 ret="$?"
2034 if [ "$ret" != "0" ]; then
2035 test_done "$testroot" "$ret"
2036 return 1
2039 (cd $testroot/wt && got rm beta > /dev/null)
2041 printf "y\n" > $testroot/patchscript
2042 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2043 beta > $testroot/stdout)
2045 echo -n > $testroot/stdout.expected
2047 echo "D beta" > $testroot/stdout.expected
2048 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2049 cmp -s $testroot/stdout.expected $testroot/stdout
2050 ret="$?"
2051 if [ "$ret" != "0" ]; then
2052 diff -u $testroot/stdout.expected $testroot/stdout
2053 test_done "$testroot" "$ret"
2054 return 1
2057 (cd $testroot/wt && got status > $testroot/stdout)
2058 echo " D beta" > $testroot/stdout.expected
2059 cmp -s $testroot/stdout.expected $testroot/stdout
2060 ret="$?"
2061 if [ "$ret" != "0" ]; then
2062 diff -u $testroot/stdout.expected $testroot/stdout
2063 test_done "$testroot" "$ret"
2064 return 1
2067 (cd $testroot/wt && got diff -s > $testroot/stdout)
2069 echo "diff $commit_id $testroot/wt (staged changes)" \
2070 > $testroot/stdout.expected
2071 echo -n 'blob - ' >> $testroot/stdout.expected
2072 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2073 >> $testroot/stdout.expected
2074 echo 'blob + /dev/null' >> $testroot/stdout.expected
2075 echo "--- beta" >> $testroot/stdout.expected
2076 echo "+++ /dev/null" >> $testroot/stdout.expected
2077 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2078 echo "-beta" >> $testroot/stdout.expected
2079 cmp -s $testroot/stdout.expected $testroot/stdout
2080 ret="$?"
2081 if [ "$ret" != "0" ]; then
2082 diff -u $testroot/stdout.expected $testroot/stdout
2084 test_done "$testroot" "$ret"
2087 function test_stage_patch_removed_twice {
2088 local testroot=`test_init stage_patch_removed_twice`
2089 local commit_id=`git_show_head $testroot/repo`
2091 got checkout $testroot/repo $testroot/wt > /dev/null
2092 ret="$?"
2093 if [ "$ret" != "0" ]; then
2094 test_done "$testroot" "$ret"
2095 return 1
2098 (cd $testroot/wt && got rm beta > /dev/null)
2100 printf "y\n" > $testroot/patchscript
2101 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2102 beta > $testroot/stdout)
2104 echo -n > $testroot/stdout.expected
2106 echo "D beta" > $testroot/stdout.expected
2107 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2108 cmp -s $testroot/stdout.expected $testroot/stdout
2109 ret="$?"
2110 if [ "$ret" != "0" ]; then
2111 diff -u $testroot/stdout.expected $testroot/stdout
2112 test_done "$testroot" "$ret"
2113 return 1
2116 (cd $testroot/wt && got status > $testroot/stdout)
2117 echo " D beta" > $testroot/stdout.expected
2118 cmp -s $testroot/stdout.expected $testroot/stdout
2119 ret="$?"
2120 if [ "$ret" != "0" ]; then
2121 diff -u $testroot/stdout.expected $testroot/stdout
2122 test_done "$testroot" "$ret"
2123 return 1
2126 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2127 > $testroot/stdout 2> $testroot/stderr)
2128 ret="$?"
2129 if [ "$ret" == "0" ]; then
2130 echo "got stage command succeeded unexpectedly" >&2
2131 test_done "$testroot" "$ret"
2132 return 1
2135 echo "got: no changes to stage" > $testroot/stderr.expected
2136 cmp -s $testroot/stderr.expected $testroot/stderr
2137 ret="$?"
2138 if [ "$ret" != "0" ]; then
2139 diff -u $testroot/stderr.expected $testroot/stderr
2140 test_done "$testroot" "$ret"
2141 return 1
2144 echo -n > $testroot/stdout.expected
2145 cmp -s $testroot/stdout.expected $testroot/stdout
2146 ret="$?"
2147 if [ "$ret" != "0" ]; then
2148 diff -u $testroot/stdout.expected $testroot/stdout
2150 test_done "$testroot" "$ret"
2153 function test_stage_patch_quit {
2154 local testroot=`test_init stage_patch_quit`
2156 jot 16 > $testroot/repo/numbers
2157 echo zzz > $testroot/repo/zzz
2158 (cd $testroot/repo && git add numbers zzz)
2159 git_commit $testroot/repo -m "added files"
2160 local commit_id=`git_show_head $testroot/repo`
2162 got checkout $testroot/repo $testroot/wt > /dev/null
2163 ret="$?"
2164 if [ "$ret" != "0" ]; then
2165 test_done "$testroot" "$ret"
2166 return 1
2169 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2170 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2171 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2172 (cd $testroot/wt && got rm zzz > /dev/null)
2174 # stage first hunk and quit; and don't pass a path argument to
2175 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2176 printf "y\nq\nn\n" > $testroot/patchscript
2177 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2178 > $testroot/stdout)
2179 ret="$?"
2180 if [ "$ret" != "0" ]; then
2181 echo "got stage command failed unexpectedly" >&2
2182 test_done "$testroot" "1"
2183 return 1
2185 cat > $testroot/stdout.expected <<EOF
2186 -----------------------------------------------
2187 @@ -1,5 +1,5 @@
2194 -----------------------------------------------
2195 M numbers (change 1 of 3)
2196 stage this change? [y/n/q] y
2197 -----------------------------------------------
2198 @@ -4,7 +4,7 @@
2207 -----------------------------------------------
2208 M numbers (change 2 of 3)
2209 stage this change? [y/n/q] q
2210 D zzz
2211 stage this deletion? [y/n] n
2212 EOF
2213 cmp -s $testroot/stdout.expected $testroot/stdout
2214 ret="$?"
2215 if [ "$ret" != "0" ]; then
2216 diff -u $testroot/stdout.expected $testroot/stdout
2217 test_done "$testroot" "$ret"
2218 return 1
2221 (cd $testroot/wt && got status > $testroot/stdout)
2222 echo "MM numbers" > $testroot/stdout.expected
2223 echo "D zzz" >> $testroot/stdout.expected
2224 cmp -s $testroot/stdout.expected $testroot/stdout
2225 ret="$?"
2226 if [ "$ret" != "0" ]; then
2227 diff -u $testroot/stdout.expected $testroot/stdout
2228 test_done "$testroot" "$ret"
2229 return 1
2232 (cd $testroot/wt && got diff -s > $testroot/stdout)
2234 echo "diff $commit_id $testroot/wt (staged changes)" \
2235 > $testroot/stdout.expected
2236 echo -n 'blob - ' >> $testroot/stdout.expected
2237 got tree -r $testroot/repo -i -c $commit_id \
2238 | grep 'numbers$' | cut -d' ' -f 1 \
2239 >> $testroot/stdout.expected
2240 echo -n 'blob + ' >> $testroot/stdout.expected
2241 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2242 >> $testroot/stdout.expected
2243 echo "--- numbers" >> $testroot/stdout.expected
2244 echo "+++ numbers" >> $testroot/stdout.expected
2245 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2246 echo " 1" >> $testroot/stdout.expected
2247 echo "-2" >> $testroot/stdout.expected
2248 echo "+a" >> $testroot/stdout.expected
2249 echo " 3" >> $testroot/stdout.expected
2250 echo " 4" >> $testroot/stdout.expected
2251 echo " 5" >> $testroot/stdout.expected
2252 cmp -s $testroot/stdout.expected $testroot/stdout
2253 ret="$?"
2254 if [ "$ret" != "0" ]; then
2255 diff -u $testroot/stdout.expected $testroot/stdout
2257 test_done "$testroot" "$ret"
2261 function test_stage_patch_incomplete_script {
2262 local testroot=`test_init stage_incomplete_script`
2264 jot 16 > $testroot/repo/numbers
2265 echo zzz > $testroot/repo/zzz
2266 (cd $testroot/repo && git add numbers zzz)
2267 git_commit $testroot/repo -m "added files"
2268 local commit_id=`git_show_head $testroot/repo`
2270 got checkout $testroot/repo $testroot/wt > /dev/null
2271 ret="$?"
2272 if [ "$ret" != "0" ]; then
2273 test_done "$testroot" "$ret"
2274 return 1
2277 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2278 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2279 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2281 # stage first hunk and then stop responding; got should error out
2282 printf "y\n" > $testroot/patchscript
2283 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2284 > $testroot/stdout 2> $testroot/stderr)
2285 ret="$?"
2286 if [ "$ret" == "0" ]; then
2287 echo "got stage command succeeded unexpectedly" >&2
2288 test_done "$testroot" "1"
2289 return 1
2291 cat > $testroot/stdout.expected <<EOF
2292 -----------------------------------------------
2293 @@ -1,5 +1,5 @@
2300 -----------------------------------------------
2301 M numbers (change 1 of 3)
2302 stage this change? [y/n/q] y
2303 -----------------------------------------------
2304 @@ -4,7 +4,7 @@
2313 -----------------------------------------------
2314 M numbers (change 2 of 3)
2315 EOF
2316 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2317 echo "got: invalid patch choice" > $testroot/stderr.expected
2318 cmp -s $testroot/stderr.expected $testroot/stderr
2319 ret="$?"
2320 if [ "$ret" != "0" ]; then
2321 diff -u $testroot/stderr.expected $testroot/stderr
2322 test_done "$testroot" "$ret"
2323 return 1
2326 cmp -s $testroot/stdout.expected $testroot/stdout
2327 ret="$?"
2328 if [ "$ret" != "0" ]; then
2329 diff -u $testroot/stdout.expected $testroot/stdout
2330 test_done "$testroot" "$ret"
2331 return 1
2334 (cd $testroot/wt && got status > $testroot/stdout)
2335 echo "M numbers" > $testroot/stdout.expected
2336 cmp -s $testroot/stdout.expected $testroot/stdout
2337 ret="$?"
2338 if [ "$ret" != "0" ]; then
2339 diff -u $testroot/stdout.expected $testroot/stdout
2340 test_done "$testroot" "$ret"
2341 return 1
2344 (cd $testroot/wt && got diff -s > $testroot/stdout)
2345 echo -n > $testroot/stdout.expected
2346 cmp -s $testroot/stdout.expected $testroot/stdout
2347 ret="$?"
2348 if [ "$ret" != "0" ]; then
2349 diff -u $testroot/stdout.expected $testroot/stdout
2351 test_done "$testroot" "$ret"
2355 run_test test_stage_basic
2356 run_test test_stage_no_changes
2357 run_test test_stage_unversioned
2358 run_test test_stage_nonexistent
2359 run_test test_stage_list
2360 run_test test_stage_conflict
2361 run_test test_stage_out_of_date
2362 run_test test_double_stage
2363 run_test test_stage_status
2364 run_test test_stage_add_already_staged_file
2365 run_test test_stage_rm_already_staged_file
2366 run_test test_stage_revert
2367 run_test test_stage_diff
2368 run_test test_stage_histedit
2369 run_test test_stage_rebase
2370 run_test test_stage_update
2371 run_test test_stage_commit_non_staged
2372 run_test test_stage_commit_out_of_date
2373 run_test test_stage_commit
2374 run_test test_stage_patch
2375 run_test test_stage_patch_twice
2376 run_test test_stage_patch_added
2377 run_test test_stage_patch_added_twice
2378 run_test test_stage_patch_removed
2379 run_test test_stage_patch_removed_twice
2380 run_test test_stage_patch_quit
2381 run_test test_stage_patch_incomplete_script