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 succeeded unexpectedly" >&2
713 test_done "$testroot" "1"
714 return 1
715 fi
717 echo "got: beta: file is staged" > $testroot/stderr.expected
718 cmp -s $testroot/stderr.expected $testroot/stderr
719 ret="$?"
720 if [ "$ret" != "0" ]; then
721 diff -u $testroot/stderr.expected $testroot/stderr
722 test_done "$testroot" "$ret"
723 return 1
724 fi
726 (cd $testroot/wt && got revert foo > $testroot/stdout)
727 ret="$?"
728 if [ "$ret" != "0" ]; then
729 echo "revert command failed unexpectedly" >&2
730 test_done "$testroot" "$ret"
731 return 1
732 fi
734 echo "R foo" > $testroot/stdout.expected
735 cmp -s $testroot/stdout.expected $testroot/stdout
736 ret="$?"
737 if [ "$ret" != "0" ]; then
738 diff -u $testroot/stdout.expected $testroot/stdout
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 echo "new file" > $testroot/content.expected
744 cat $testroot/wt/foo > $testroot/content
745 cmp -s $testroot/content.expected $testroot/content
746 ret="$?"
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/content.expected $testroot/content
749 test_done "$testroot" "$ret"
750 return 1
751 fi
753 echo ' M alpha' > $testroot/stdout.expected
754 echo ' D beta' >> $testroot/stdout.expected
755 echo ' A foo' >> $testroot/stdout.expected
756 (cd $testroot/wt && got status > $testroot/stdout)
757 cmp -s $testroot/stdout.expected $testroot/stdout
758 ret="$?"
759 if [ "$ret" != "0" ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
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 -n > $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 fi
801 test_done "$testroot" "$ret"
804 function test_stage_diff {
805 local testroot=`test_init stage_diff`
806 local head_commit=`git_show_head $testroot/repo`
808 got checkout $testroot/repo $testroot/wt > /dev/null
809 ret="$?"
810 if [ "$ret" != "0" ]; then
811 test_done "$testroot" "$ret"
812 return 1
813 fi
815 echo "modified file" > $testroot/wt/alpha
816 (cd $testroot/wt && got rm beta > /dev/null)
817 echo "new file" > $testroot/wt/foo
818 (cd $testroot/wt && got add foo > /dev/null)
820 (cd $testroot/wt && got diff -s > $testroot/stdout)
821 echo -n > $testroot/stdout.expected
822 cmp -s $testroot/stdout.expected $testroot/stdout
823 ret="$?"
824 if [ "$ret" != "0" ]; then
825 diff -u $testroot/stdout.expected $testroot/stdout
826 test_done "$testroot" "$ret"
827 return 1
828 fi
830 echo ' M alpha' > $testroot/stdout.expected
831 echo ' D beta' >> $testroot/stdout.expected
832 echo ' A foo' >> $testroot/stdout.expected
833 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
835 (cd $testroot/wt && got diff > $testroot/stdout)
836 echo -n > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
838 ret="$?"
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
841 test_done "$testroot" "$ret"
842 return 1
843 fi
845 echo "modified file again" > $testroot/wt/alpha
846 echo "new file changed" > $testroot/wt/foo
848 (cd $testroot/wt && got diff > $testroot/stdout)
850 echo "diff $head_commit $testroot/wt" > $testroot/stdout.expected
851 echo -n 'blob - ' >> $testroot/stdout.expected
852 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
853 >> $testroot/stdout.expected
854 echo ' (staged)' >> $testroot/stdout.expected
855 echo 'file + alpha' >> $testroot/stdout.expected
856 echo '--- alpha' >> $testroot/stdout.expected
857 echo '+++ alpha' >> $testroot/stdout.expected
858 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
859 echo '-modified file' >> $testroot/stdout.expected
860 echo '+modified file again' >> $testroot/stdout.expected
861 echo -n 'blob - ' >> $testroot/stdout.expected
862 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
863 >> $testroot/stdout.expected
864 echo " (staged)" >> $testroot/stdout.expected
865 echo 'file + foo' >> $testroot/stdout.expected
866 echo '--- foo' >> $testroot/stdout.expected
867 echo '+++ foo' >> $testroot/stdout.expected
868 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
869 echo '-new file' >> $testroot/stdout.expected
870 echo '+new file changed' >> $testroot/stdout.expected
872 cmp -s $testroot/stdout.expected $testroot/stdout
873 ret="$?"
874 if [ "$ret" != "0" ]; then
875 diff -u $testroot/stdout.expected $testroot/stdout
876 test_done "$testroot" "$ret"
877 return 1
878 fi
880 (cd $testroot/wt && got diff -s > $testroot/stdout)
882 echo "diff $head_commit $testroot/wt (staged changes)" \
883 > $testroot/stdout.expected
884 echo -n 'blob - ' >> $testroot/stdout.expected
885 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
886 >> $testroot/stdout.expected
887 echo -n 'blob + ' >> $testroot/stdout.expected
888 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
889 >> $testroot/stdout.expected
890 echo '--- alpha' >> $testroot/stdout.expected
891 echo '+++ alpha' >> $testroot/stdout.expected
892 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
893 echo '-alpha' >> $testroot/stdout.expected
894 echo '+modified file' >> $testroot/stdout.expected
895 echo -n 'blob - ' >> $testroot/stdout.expected
896 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
897 >> $testroot/stdout.expected
898 echo 'blob + /dev/null' >> $testroot/stdout.expected
899 echo '--- beta' >> $testroot/stdout.expected
900 echo '+++ /dev/null' >> $testroot/stdout.expected
901 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
902 echo '-beta' >> $testroot/stdout.expected
903 echo 'blob - /dev/null' >> $testroot/stdout.expected
904 echo -n 'blob + ' >> $testroot/stdout.expected
905 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
906 >> $testroot/stdout.expected
907 echo '--- /dev/null' >> $testroot/stdout.expected
908 echo '+++ foo' >> $testroot/stdout.expected
909 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
910 echo '+new file' >> $testroot/stdout.expected
912 cmp -s $testroot/stdout.expected $testroot/stdout
913 ret="$?"
914 if [ "$ret" != "0" ]; then
915 diff -u $testroot/stdout.expected $testroot/stdout
916 fi
917 test_done "$testroot" "$ret"
921 function test_stage_histedit {
922 local testroot=`test_init stage_histedit`
923 local orig_commit=`git_show_head $testroot/repo`
925 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
926 ret="$?"
927 if [ "$ret" != "0" ]; then
928 test_done "$testroot" "$ret"
929 return 1
930 fi
932 echo "modified file" > $testroot/wt/alpha
933 (cd $testroot/wt && got stage alpha > /dev/null)
935 echo "modified alpha on master" > $testroot/repo/alpha
936 (cd $testroot/repo && git rm -q beta)
937 echo "new file on master" > $testroot/repo/epsilon/new
938 (cd $testroot/repo && git add epsilon/new)
939 git_commit $testroot/repo -m "committing changes"
940 local old_commit1=`git_show_head $testroot/repo`
942 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
943 git_commit $testroot/repo -m "committing to zeta on master"
944 local old_commit2=`git_show_head $testroot/repo`
946 echo "pick $old_commit1" > $testroot/histedit-script
947 echo "pick $old_commit2" >> $testroot/histedit-script
949 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
950 > $testroot/stdout 2> $testroot/stderr)
951 ret="$?"
952 if [ "$ret" == "0" ]; then
953 echo "got histedit command succeeded unexpectedly" >&2
954 test_done "$testroot" "1"
955 return 1
956 fi
958 echo -n > $testroot/stdout.expected
959 echo "got: alpha: file is staged" > $testroot/stderr.expected
961 cmp -s $testroot/stderr.expected $testroot/stderr
962 ret="$?"
963 if [ "$ret" != "0" ]; then
964 diff -u $testroot/stderr.expected $testroot/stderr
965 test_done "$testroot" "$ret"
966 return 1
967 fi
968 cmp -s $testroot/stdout.expected $testroot/stdout
969 ret="$?"
970 if [ "$ret" != "0" ]; then
971 diff -u $testroot/stdout.expected $testroot/stdout
972 fi
973 test_done "$testroot" "$ret"
977 function test_stage_rebase {
978 local testroot=`test_init stage_rebase`
980 (cd $testroot/repo && git checkout -q -b newbranch)
981 echo "modified delta on branch" > $testroot/repo/gamma/delta
982 git_commit $testroot/repo -m "committing to delta on newbranch"
984 echo "modified alpha on branch" > $testroot/repo/alpha
985 (cd $testroot/repo && git rm -q beta)
986 echo "new file on branch" > $testroot/repo/epsilon/new
987 (cd $testroot/repo && git add epsilon/new)
988 git_commit $testroot/repo -m "committing more changes on newbranch"
990 local orig_commit1=`git_show_parent_commit $testroot/repo`
991 local orig_commit2=`git_show_head $testroot/repo`
993 (cd $testroot/repo && git checkout -q master)
994 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
995 git_commit $testroot/repo -m "committing to zeta on master"
996 local master_commit=`git_show_head $testroot/repo`
998 got checkout $testroot/repo $testroot/wt > /dev/null
999 ret="$?"
1000 if [ "$ret" != "0" ]; then
1001 test_done "$testroot" "$ret"
1002 return 1
1005 echo "modified file" > $testroot/wt/alpha
1006 (cd $testroot/wt && got stage alpha > /dev/null)
1008 (cd $testroot/wt && got rebase newbranch \
1009 > $testroot/stdout 2> $testroot/stderr)
1010 ret="$?"
1011 if [ "$ret" == "0" ]; then
1012 echo "got rebase command succeeded unexpectedly" >&2
1013 test_done "$testroot" "1"
1014 return 1
1017 echo -n > $testroot/stdout.expected
1018 echo "got: alpha: file is staged" > $testroot/stderr.expected
1020 cmp -s $testroot/stderr.expected $testroot/stderr
1021 ret="$?"
1022 if [ "$ret" != "0" ]; then
1023 diff -u $testroot/stderr.expected $testroot/stderr
1024 test_done "$testroot" "$ret"
1025 return 1
1027 cmp -s $testroot/stdout.expected $testroot/stdout
1028 ret="$?"
1029 if [ "$ret" != "0" ]; then
1030 diff -u $testroot/stdout.expected $testroot/stdout
1032 test_done "$testroot" "$ret"
1035 function test_stage_update {
1036 local testroot=`test_init stage_update`
1038 got checkout $testroot/repo $testroot/wt > /dev/null
1039 ret="$?"
1040 if [ "$ret" != "0" ]; then
1041 test_done "$testroot" "$ret"
1042 return 1
1045 echo "modified file" > $testroot/wt/alpha
1046 (cd $testroot/wt && got stage alpha > /dev/null)
1048 echo "modified alpha" > $testroot/repo/alpha
1049 git_commit $testroot/repo -m "modified alpha"
1051 (cd $testroot/wt && got update > $testroot/stdout \
1052 2> $testroot/stderr)
1053 ret="$?"
1054 if [ "$ret" == "0" ]; then
1055 echo "got update command succeeded unexpectedly" >&2
1056 test_done "$testroot" "1"
1057 return 1
1060 echo -n > $testroot/stdout.expected
1061 echo "got: alpha: file is staged" > $testroot/stderr.expected
1063 cmp -s $testroot/stderr.expected $testroot/stderr
1064 ret="$?"
1065 if [ "$ret" != "0" ]; then
1066 diff -u $testroot/stderr.expected $testroot/stderr
1067 test_done "$testroot" "$ret"
1068 return 1
1070 cmp -s $testroot/stdout.expected $testroot/stdout
1071 ret="$?"
1072 if [ "$ret" != "0" ]; then
1073 diff -u $testroot/stdout.expected $testroot/stdout
1075 test_done "$testroot" "$ret"
1078 function test_stage_commit_non_staged {
1079 local testroot=`test_init stage_commit_non_staged`
1081 got checkout $testroot/repo $testroot/wt > /dev/null
1082 ret="$?"
1083 if [ "$ret" != "0" ]; then
1084 test_done "$testroot" "$ret"
1085 return 1
1088 echo "modified file" > $testroot/wt/alpha
1089 (cd $testroot/wt && got rm beta > /dev/null)
1090 echo "new file" > $testroot/wt/foo
1091 (cd $testroot/wt && got add foo > /dev/null)
1092 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1094 echo "modified file" > $testroot/wt/gamma/delta
1095 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1096 > $testroot/stdout 2> $testroot/stderr)
1097 ret="$?"
1098 if [ "$ret" == "0" ]; then
1099 echo "got commit command succeeded unexpectedly" >&2
1100 test_done "$testroot" "1"
1101 return 1
1104 echo -n > $testroot/stdout.expected
1105 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1107 cmp -s $testroot/stderr.expected $testroot/stderr
1108 ret="$?"
1109 if [ "$ret" != "0" ]; then
1110 diff -u $testroot/stderr.expected $testroot/stderr
1111 test_done "$testroot" "$ret"
1112 return 1
1114 cmp -s $testroot/stdout.expected $testroot/stdout
1115 ret="$?"
1116 if [ "$ret" != "0" ]; then
1117 diff -u $testroot/stdout.expected $testroot/stdout
1119 test_done "$testroot" "$ret"
1122 function test_stage_commit {
1123 local testroot=`test_init stage_commit`
1124 local first_commit=`git_show_head $testroot/repo`
1126 got checkout $testroot/repo $testroot/wt > /dev/null
1127 ret="$?"
1128 if [ "$ret" != "0" ]; then
1129 test_done "$testroot" "$ret"
1130 return 1
1133 echo "modified file" > $testroot/wt/alpha
1134 (cd $testroot/wt && got rm beta > /dev/null)
1135 echo "new file" > $testroot/wt/foo
1136 (cd $testroot/wt && got add foo > /dev/null)
1137 echo "modified file" > $testroot/wt/alpha
1138 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1140 echo "modified file again" > $testroot/wt/alpha
1141 echo "new file changed" > $testroot/wt/foo
1142 echo "non-staged change" > $testroot/wt/gamma/delta
1143 echo "non-staged new file" > $testroot/wt/epsilon/new
1144 (cd $testroot/wt && got add epsilon/new > /dev/null)
1145 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1147 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1148 > $testroot/blob_id_alpha
1149 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1150 > $testroot/blob_id_foo
1152 (cd $testroot/wt && got commit -m "staged changes" \
1153 > $testroot/stdout)
1154 ret="$?"
1155 if [ "$ret" != "0" ]; then
1156 echo "got commit command failed unexpectedly" >&2
1157 test_done "$testroot" "1"
1158 return 1
1161 local head_commit=`git_show_head $testroot/repo`
1162 echo "A foo" > $testroot/stdout.expected
1163 echo "M alpha" >> $testroot/stdout.expected
1164 echo "D beta" >> $testroot/stdout.expected
1165 echo "Created commit $head_commit" >> $testroot/stdout.expected
1167 cmp -s $testroot/stdout.expected $testroot/stdout
1168 ret="$?"
1169 if [ "$ret" != "0" ]; then
1170 diff -u $testroot/stdout.expected $testroot/stdout
1171 test_done "$testroot" "$ret"
1172 return 1
1175 got diff -r $testroot/repo $first_commit $head_commit \
1176 > $testroot/stdout
1178 echo "diff $first_commit $head_commit" \
1179 > $testroot/stdout.expected
1180 echo -n 'blob - ' >> $testroot/stdout.expected
1181 got tree -r $testroot/repo -i -c $first_commit | \
1182 grep 'alpha$' | cut -d' ' -f 1 \
1183 >> $testroot/stdout.expected
1184 echo -n 'blob + ' >> $testroot/stdout.expected
1185 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1186 echo '--- alpha' >> $testroot/stdout.expected
1187 echo '+++ alpha' >> $testroot/stdout.expected
1188 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1189 echo '-alpha' >> $testroot/stdout.expected
1190 echo '+modified file' >> $testroot/stdout.expected
1191 echo -n 'blob - ' >> $testroot/stdout.expected
1192 got tree -r $testroot/repo -i -c $first_commit \
1193 | grep 'beta$' | cut -d' ' -f 1 \
1194 >> $testroot/stdout.expected
1195 echo 'blob + /dev/null' >> $testroot/stdout.expected
1196 echo '--- beta' >> $testroot/stdout.expected
1197 echo '+++ /dev/null' >> $testroot/stdout.expected
1198 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1199 echo '-beta' >> $testroot/stdout.expected
1200 echo 'blob - /dev/null' >> $testroot/stdout.expected
1201 echo -n 'blob + ' >> $testroot/stdout.expected
1202 cat $testroot/blob_id_foo >> $testroot/stdout.expected
1203 echo '--- /dev/null' >> $testroot/stdout.expected
1204 echo '+++ foo' >> $testroot/stdout.expected
1205 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1206 echo '+new file' >> $testroot/stdout.expected
1208 cmp -s $testroot/stdout.expected $testroot/stdout
1209 ret="$?"
1210 if [ "$ret" != "0" ]; then
1211 diff -u $testroot/stdout.expected $testroot/stdout
1212 test_done "$testroot" "$ret"
1213 return 1
1216 echo 'A epsilon/new' > $testroot/stdout.expected
1217 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1218 echo 'M gamma/delta' >> $testroot/stdout.expected
1220 (cd $testroot/wt && got status > $testroot/stdout)
1221 cmp -s $testroot/stdout.expected $testroot/stdout
1222 ret="$?"
1223 if [ "$ret" != "0" ]; then
1224 diff -u $testroot/stdout.expected $testroot/stdout
1226 test_done "$testroot" "$ret"
1229 function test_stage_patch {
1230 local testroot=`test_init stage_patch`
1232 jot 16 > $testroot/repo/numbers
1233 (cd $testroot/repo && git add numbers)
1234 git_commit $testroot/repo -m "added numbers file"
1235 local commit_id=`git_show_head $testroot/repo`
1237 got checkout $testroot/repo $testroot/wt > /dev/null
1238 ret="$?"
1239 if [ "$ret" != "0" ]; then
1240 test_done "$testroot" "$ret"
1241 return 1
1244 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1245 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1246 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1248 # don't stage any hunks
1249 printf "n\nn\nn\n" > $testroot/patchscript
1250 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1251 numbers > $testroot/stdout)
1252 ret="$?"
1253 if [ "$ret" != "0" ]; then
1254 echo "got stage command failed unexpectedly" >&2
1255 test_done "$testroot" "1"
1256 return 1
1258 cat > $testroot/stdout.expected <<EOF
1259 -----------------------------------------------
1260 @@ -1,5 +1,5 @@
1267 -----------------------------------------------
1268 M numbers (change 1 of 3)
1269 stage this change? [y/n/q] n
1270 -----------------------------------------------
1271 @@ -4,7 +4,7 @@
1280 -----------------------------------------------
1281 M numbers (change 2 of 3)
1282 stage this change? [y/n/q] n
1283 -----------------------------------------------
1284 @@ -13,4 +13,4 @@
1288 -16
1290 -----------------------------------------------
1291 M numbers (change 3 of 3)
1292 stage this change? [y/n/q] n
1293 EOF
1294 cmp -s $testroot/stdout.expected $testroot/stdout
1295 ret="$?"
1296 if [ "$ret" != "0" ]; then
1297 diff -u $testroot/stdout.expected $testroot/stdout
1298 test_done "$testroot" "$ret"
1299 return 1
1302 (cd $testroot/wt && got status > $testroot/stdout)
1303 echo "M numbers" > $testroot/stdout.expected
1304 cmp -s $testroot/stdout.expected $testroot/stdout
1305 ret="$?"
1306 if [ "$ret" != "0" ]; then
1307 diff -u $testroot/stdout.expected $testroot/stdout
1308 test_done "$testroot" "$ret"
1309 return 1
1312 # stage middle hunk
1313 printf "n\ny\nn\n" > $testroot/patchscript
1314 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1315 numbers > $testroot/stdout)
1317 cat > $testroot/stdout.expected <<EOF
1318 -----------------------------------------------
1319 @@ -1,5 +1,5 @@
1326 -----------------------------------------------
1327 M numbers (change 1 of 3)
1328 stage this change? [y/n/q] n
1329 -----------------------------------------------
1330 @@ -4,7 +4,7 @@
1339 -----------------------------------------------
1340 M numbers (change 2 of 3)
1341 stage this change? [y/n/q] y
1342 -----------------------------------------------
1343 @@ -13,4 +13,4 @@
1347 -16
1349 -----------------------------------------------
1350 M numbers (change 3 of 3)
1351 stage this change? [y/n/q] n
1352 EOF
1353 cmp -s $testroot/stdout.expected $testroot/stdout
1354 ret="$?"
1355 if [ "$ret" != "0" ]; then
1356 diff -u $testroot/stdout.expected $testroot/stdout
1357 test_done "$testroot" "$ret"
1358 return 1
1361 (cd $testroot/wt && got status > $testroot/stdout)
1362 echo "MM numbers" > $testroot/stdout.expected
1363 cmp -s $testroot/stdout.expected $testroot/stdout
1364 ret="$?"
1365 if [ "$ret" != "0" ]; then
1366 diff -u $testroot/stdout.expected $testroot/stdout
1367 test_done "$testroot" "$ret"
1368 return 1
1371 (cd $testroot/wt && got diff -s > $testroot/stdout)
1373 echo "diff $commit_id $testroot/wt (staged changes)" \
1374 > $testroot/stdout.expected
1375 echo -n 'blob - ' >> $testroot/stdout.expected
1376 got tree -r $testroot/repo -i -c $commit_id \
1377 | grep 'numbers$' | cut -d' ' -f 1 \
1378 >> $testroot/stdout.expected
1379 echo -n 'blob + ' >> $testroot/stdout.expected
1380 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1381 >> $testroot/stdout.expected
1382 echo "--- numbers" >> $testroot/stdout.expected
1383 echo "+++ numbers" >> $testroot/stdout.expected
1384 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1385 echo " 4" >> $testroot/stdout.expected
1386 echo " 5" >> $testroot/stdout.expected
1387 echo " 6" >> $testroot/stdout.expected
1388 echo "-7" >> $testroot/stdout.expected
1389 echo "+b" >> $testroot/stdout.expected
1390 echo " 8" >> $testroot/stdout.expected
1391 echo " 9" >> $testroot/stdout.expected
1392 echo " 10" >> $testroot/stdout.expected
1393 cmp -s $testroot/stdout.expected $testroot/stdout
1394 ret="$?"
1395 if [ "$ret" != "0" ]; then
1396 diff -u $testroot/stdout.expected $testroot/stdout
1397 test_done "$testroot" "$ret"
1398 return 1
1401 (cd $testroot/wt && got unstage >/dev/null)
1402 ret="$?"
1403 if [ "$ret" != "0" ]; then
1404 echo "got stage command failed unexpectedly" >&2
1405 test_done "$testroot" "1"
1406 return 1
1408 (cd $testroot/wt && got status > $testroot/stdout)
1409 echo "M numbers" > $testroot/stdout.expected
1410 cmp -s $testroot/stdout.expected $testroot/stdout
1411 ret="$?"
1412 if [ "$ret" != "0" ]; then
1413 diff -u $testroot/stdout.expected $testroot/stdout
1414 test_done "$testroot" "$ret"
1415 return 1
1418 # stage last hunk
1419 printf "n\nn\ny\n" > $testroot/patchscript
1420 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1421 numbers > $testroot/stdout)
1423 cat > $testroot/stdout.expected <<EOF
1424 -----------------------------------------------
1425 @@ -1,5 +1,5 @@
1432 -----------------------------------------------
1433 M numbers (change 1 of 3)
1434 stage this change? [y/n/q] n
1435 -----------------------------------------------
1436 @@ -4,7 +4,7 @@
1445 -----------------------------------------------
1446 M numbers (change 2 of 3)
1447 stage this change? [y/n/q] n
1448 -----------------------------------------------
1449 @@ -13,4 +13,4 @@
1453 -16
1455 -----------------------------------------------
1456 M numbers (change 3 of 3)
1457 stage this change? [y/n/q] y
1458 EOF
1459 cmp -s $testroot/stdout.expected $testroot/stdout
1460 ret="$?"
1461 if [ "$ret" != "0" ]; then
1462 diff -u $testroot/stdout.expected $testroot/stdout
1463 test_done "$testroot" "$ret"
1464 return 1
1467 (cd $testroot/wt && got status > $testroot/stdout)
1468 echo "MM numbers" > $testroot/stdout.expected
1469 cmp -s $testroot/stdout.expected $testroot/stdout
1470 ret="$?"
1471 if [ "$ret" != "0" ]; then
1472 diff -u $testroot/stdout.expected $testroot/stdout
1473 test_done "$testroot" "$ret"
1474 return 1
1477 (cd $testroot/wt && got diff -s > $testroot/stdout)
1479 echo "diff $commit_id $testroot/wt (staged changes)" \
1480 > $testroot/stdout.expected
1481 echo -n 'blob - ' >> $testroot/stdout.expected
1482 got tree -r $testroot/repo -i -c $commit_id \
1483 | grep 'numbers$' | cut -d' ' -f 1 \
1484 >> $testroot/stdout.expected
1485 echo -n 'blob + ' >> $testroot/stdout.expected
1486 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1487 >> $testroot/stdout.expected
1488 echo "--- numbers" >> $testroot/stdout.expected
1489 echo "+++ numbers" >> $testroot/stdout.expected
1490 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1491 echo " 13" >> $testroot/stdout.expected
1492 echo " 14" >> $testroot/stdout.expected
1493 echo " 15" >> $testroot/stdout.expected
1494 echo "-16" >> $testroot/stdout.expected
1495 echo "+c" >> $testroot/stdout.expected
1496 cmp -s $testroot/stdout.expected $testroot/stdout
1497 ret="$?"
1498 if [ "$ret" != "0" ]; then
1499 diff -u $testroot/stdout.expected $testroot/stdout
1501 test_done "$testroot" "$ret"
1504 function test_stage_patch_added {
1505 local testroot=`test_init stage_patch_added`
1506 local commit_id=`git_show_head $testroot/repo`
1508 got checkout $testroot/repo $testroot/wt > /dev/null
1509 ret="$?"
1510 if [ "$ret" != "0" ]; then
1511 test_done "$testroot" "$ret"
1512 return 1
1515 echo "new" > $testroot/wt/epsilon/new
1516 (cd $testroot/wt && got add epsilon/new > /dev/null)
1518 printf "y\n" > $testroot/patchscript
1519 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1520 epsilon/new > $testroot/stdout)
1522 echo "A epsilon/new" > $testroot/stdout.expected
1523 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1524 cmp -s $testroot/stdout.expected $testroot/stdout
1525 ret="$?"
1526 if [ "$ret" != "0" ]; then
1527 diff -u $testroot/stdout.expected $testroot/stdout
1528 test_done "$testroot" "$ret"
1529 return 1
1532 (cd $testroot/wt && got status > $testroot/stdout)
1533 echo " A epsilon/new" > $testroot/stdout.expected
1534 cmp -s $testroot/stdout.expected $testroot/stdout
1535 ret="$?"
1536 if [ "$ret" != "0" ]; then
1537 diff -u $testroot/stdout.expected $testroot/stdout
1538 test_done "$testroot" "$ret"
1539 return 1
1542 (cd $testroot/wt && got diff -s > $testroot/stdout)
1544 echo "diff $commit_id $testroot/wt (staged changes)" \
1545 > $testroot/stdout.expected
1546 echo 'blob - /dev/null' >> $testroot/stdout.expected
1547 echo -n 'blob + ' >> $testroot/stdout.expected
1548 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1549 >> $testroot/stdout.expected
1550 echo "--- /dev/null" >> $testroot/stdout.expected
1551 echo "+++ epsilon/new" >> $testroot/stdout.expected
1552 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1553 echo "+new" >> $testroot/stdout.expected
1554 cmp -s $testroot/stdout.expected $testroot/stdout
1555 ret="$?"
1556 if [ "$ret" != "0" ]; then
1557 diff -u $testroot/stdout.expected $testroot/stdout
1559 test_done "$testroot" "$ret"
1562 function test_stage_patch_removed {
1563 local testroot=`test_init stage_patch_removed`
1564 local commit_id=`git_show_head $testroot/repo`
1566 got checkout $testroot/repo $testroot/wt > /dev/null
1567 ret="$?"
1568 if [ "$ret" != "0" ]; then
1569 test_done "$testroot" "$ret"
1570 return 1
1573 (cd $testroot/wt && got rm beta > /dev/null)
1575 printf "y\n" > $testroot/patchscript
1576 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1577 beta > $testroot/stdout)
1579 echo -n > $testroot/stdout.expected
1581 echo "D beta" > $testroot/stdout.expected
1582 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
1583 cmp -s $testroot/stdout.expected $testroot/stdout
1584 ret="$?"
1585 if [ "$ret" != "0" ]; then
1586 diff -u $testroot/stdout.expected $testroot/stdout
1587 test_done "$testroot" "$ret"
1588 return 1
1591 (cd $testroot/wt && got status > $testroot/stdout)
1592 echo " D beta" > $testroot/stdout.expected
1593 cmp -s $testroot/stdout.expected $testroot/stdout
1594 ret="$?"
1595 if [ "$ret" != "0" ]; then
1596 diff -u $testroot/stdout.expected $testroot/stdout
1597 test_done "$testroot" "$ret"
1598 return 1
1601 (cd $testroot/wt && got diff -s > $testroot/stdout)
1603 echo "diff $commit_id $testroot/wt (staged changes)" \
1604 > $testroot/stdout.expected
1605 echo -n 'blob - ' >> $testroot/stdout.expected
1606 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
1607 >> $testroot/stdout.expected
1608 echo 'blob + /dev/null' >> $testroot/stdout.expected
1609 echo "--- beta" >> $testroot/stdout.expected
1610 echo "+++ /dev/null" >> $testroot/stdout.expected
1611 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
1612 echo "-beta" >> $testroot/stdout.expected
1613 cmp -s $testroot/stdout.expected $testroot/stdout
1614 ret="$?"
1615 if [ "$ret" != "0" ]; then
1616 diff -u $testroot/stdout.expected $testroot/stdout
1618 test_done "$testroot" "$ret"
1621 function test_stage_patch_quit {
1622 local testroot=`test_init stage_patch_quit`
1624 jot 16 > $testroot/repo/numbers
1625 echo zzz > $testroot/repo/zzz
1626 (cd $testroot/repo && git add numbers zzz)
1627 git_commit $testroot/repo -m "added files"
1628 local commit_id=`git_show_head $testroot/repo`
1630 got checkout $testroot/repo $testroot/wt > /dev/null
1631 ret="$?"
1632 if [ "$ret" != "0" ]; then
1633 test_done "$testroot" "$ret"
1634 return 1
1637 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1638 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1639 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1640 (cd $testroot/wt && got rm zzz > /dev/null)
1642 # stage first hunk and quit; and don't pass a path argument to
1643 # ensure that we don't skip asking about the 'zzz' file after 'quit'
1644 printf "y\nq\nn\n" > $testroot/patchscript
1645 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1646 > $testroot/stdout)
1647 ret="$?"
1648 if [ "$ret" != "0" ]; then
1649 echo "got stage command failed unexpectedly" >&2
1650 test_done "$testroot" "1"
1651 return 1
1653 cat > $testroot/stdout.expected <<EOF
1654 -----------------------------------------------
1655 @@ -1,5 +1,5 @@
1662 -----------------------------------------------
1663 M numbers (change 1 of 3)
1664 stage this change? [y/n/q] y
1665 -----------------------------------------------
1666 @@ -4,7 +4,7 @@
1675 -----------------------------------------------
1676 M numbers (change 2 of 3)
1677 stage this change? [y/n/q] q
1678 D zzz
1679 stage this deletion? [y/n] n
1680 EOF
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 status > $testroot/stdout)
1690 echo "MM numbers" > $testroot/stdout.expected
1691 echo "D zzz" >> $testroot/stdout.expected
1692 cmp -s $testroot/stdout.expected $testroot/stdout
1693 ret="$?"
1694 if [ "$ret" != "0" ]; then
1695 diff -u $testroot/stdout.expected $testroot/stdout
1696 test_done "$testroot" "$ret"
1697 return 1
1700 (cd $testroot/wt && got diff -s > $testroot/stdout)
1702 echo "diff $commit_id $testroot/wt (staged changes)" \
1703 > $testroot/stdout.expected
1704 echo -n 'blob - ' >> $testroot/stdout.expected
1705 got tree -r $testroot/repo -i -c $commit_id \
1706 | grep 'numbers$' | cut -d' ' -f 1 \
1707 >> $testroot/stdout.expected
1708 echo -n 'blob + ' >> $testroot/stdout.expected
1709 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1710 >> $testroot/stdout.expected
1711 echo "--- numbers" >> $testroot/stdout.expected
1712 echo "+++ numbers" >> $testroot/stdout.expected
1713 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
1714 echo " 1" >> $testroot/stdout.expected
1715 echo "-2" >> $testroot/stdout.expected
1716 echo "+a" >> $testroot/stdout.expected
1717 echo " 3" >> $testroot/stdout.expected
1718 echo " 4" >> $testroot/stdout.expected
1719 echo " 5" >> $testroot/stdout.expected
1720 cmp -s $testroot/stdout.expected $testroot/stdout
1721 ret="$?"
1722 if [ "$ret" != "0" ]; then
1723 diff -u $testroot/stdout.expected $testroot/stdout
1725 test_done "$testroot" "$ret"
1729 function test_stage_patch_incomplete_script {
1730 local testroot=`test_init stage_incomplete_script`
1732 jot 16 > $testroot/repo/numbers
1733 echo zzz > $testroot/repo/zzz
1734 (cd $testroot/repo && git add numbers zzz)
1735 git_commit $testroot/repo -m "added files"
1736 local commit_id=`git_show_head $testroot/repo`
1738 got checkout $testroot/repo $testroot/wt > /dev/null
1739 ret="$?"
1740 if [ "$ret" != "0" ]; then
1741 test_done "$testroot" "$ret"
1742 return 1
1745 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1746 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1747 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1749 # stage first hunk and then stop responding; got should error out
1750 printf "y\n" > $testroot/patchscript
1751 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1752 > $testroot/stdout 2> $testroot/stderr)
1753 ret="$?"
1754 if [ "$ret" == "0" ]; then
1755 echo "got stage command succeeded unexpectedly" >&2
1756 test_done "$testroot" "1"
1757 return 1
1759 cat > $testroot/stdout.expected <<EOF
1760 -----------------------------------------------
1761 @@ -1,5 +1,5 @@
1768 -----------------------------------------------
1769 M numbers (change 1 of 3)
1770 stage this change? [y/n/q] y
1771 -----------------------------------------------
1772 @@ -4,7 +4,7 @@
1781 -----------------------------------------------
1782 M numbers (change 2 of 3)
1783 EOF
1784 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
1785 echo "got: invalid patch choice" > $testroot/stderr.expected
1786 cmp -s $testroot/stderr.expected $testroot/stderr
1787 ret="$?"
1788 if [ "$ret" != "0" ]; then
1789 diff -u $testroot/stderr.expected $testroot/stderr
1790 test_done "$testroot" "$ret"
1791 return 1
1794 cmp -s $testroot/stdout.expected $testroot/stdout
1795 ret="$?"
1796 if [ "$ret" != "0" ]; then
1797 diff -u $testroot/stdout.expected $testroot/stdout
1798 test_done "$testroot" "$ret"
1799 return 1
1802 (cd $testroot/wt && got status > $testroot/stdout)
1803 echo "M numbers" > $testroot/stdout.expected
1804 cmp -s $testroot/stdout.expected $testroot/stdout
1805 ret="$?"
1806 if [ "$ret" != "0" ]; then
1807 diff -u $testroot/stdout.expected $testroot/stdout
1808 test_done "$testroot" "$ret"
1809 return 1
1812 (cd $testroot/wt && got diff -s > $testroot/stdout)
1813 echo -n > $testroot/stdout.expected
1814 cmp -s $testroot/stdout.expected $testroot/stdout
1815 ret="$?"
1816 if [ "$ret" != "0" ]; then
1817 diff -u $testroot/stdout.expected $testroot/stdout
1819 test_done "$testroot" "$ret"
1823 run_test test_stage_basic
1824 run_test test_stage_no_changes
1825 run_test test_stage_unversioned
1826 run_test test_stage_nonexistent
1827 run_test test_stage_list
1828 run_test test_stage_conflict
1829 run_test test_stage_out_of_date
1830 run_test test_double_stage
1831 run_test test_stage_status
1832 run_test test_stage_add_already_staged_file
1833 run_test test_stage_rm_already_staged_file
1834 run_test test_stage_revert
1835 run_test test_stage_diff
1836 run_test test_stage_histedit
1837 run_test test_stage_rebase
1838 run_test test_stage_update
1839 run_test test_stage_commit_non_staged
1840 run_test test_stage_commit
1841 run_test test_stage_patch
1842 run_test test_stage_patch_added
1843 run_test test_stage_patch_removed
1844 run_test test_stage_patch_quit
1845 run_test test_stage_patch_incomplete_script