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 # disable automatic packing for these tests
20 export GOT_TEST_PACK=""
22 test_stage_basic() {
23 local testroot=`test_init stage_basic`
25 got checkout $testroot/repo $testroot/wt > /dev/null
26 ret=$?
27 if [ $ret -ne 0 ]; then
28 test_done "$testroot" "$ret"
29 return 1
30 fi
32 echo "modified file" > $testroot/wt/alpha
33 (cd $testroot/wt && got rm beta > /dev/null)
34 echo "new file" > $testroot/wt/foo
35 (cd $testroot/wt && got add foo > /dev/null)
37 echo ' M alpha' > $testroot/stdout.expected
38 echo ' D beta' >> $testroot/stdout.expected
39 echo ' A foo' >> $testroot/stdout.expected
40 (cd $testroot/wt && got stage -R > $testroot/stdout)
42 cmp -s $testroot/stdout.expected $testroot/stdout
43 ret=$?
44 if [ $ret -ne 0 ]; then
45 diff -u $testroot/stdout.expected $testroot/stdout
46 fi
47 test_done "$testroot" "$ret"
48 }
50 test_stage_directory() {
51 local testroot=`test_init stage_directory`
53 got checkout $testroot/repo $testroot/wt > /dev/null
54 ret=$?
55 if [ $ret -ne 0 ]; then
56 test_done "$testroot" "$ret"
57 return 1
58 fi
60 (cd $testroot/wt && echo -n > test && got add test > /dev/null)
61 (cd $testroot/wt && got stage . > $testroot/stdout 2> $testroot/stderr)
62 ret=$?
63 echo "got: staging directories requires -R option" \
64 > $testroot/stderr.expected
65 cmp -s $testroot/stderr.expected $testroot/stderr
66 ret=$?
67 if [ $ret -ne 0 ]; then
68 diff -u $testroot/stderr.expected $testroot/stderr
69 test_done "$testroot" "$ret"
70 return 1
71 fi
73 (cd $testroot/wt && got stage -R . > $testroot/stdout)
75 echo ' A test' >> $testroot/stdout.expected
76 cmp -s $testroot/stdout.expected $testroot/stdout
77 ret=$?
78 if [ $ret -ne 0 ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 fi
81 test_done "$testroot" "$ret"
82 }
84 test_stage_no_changes() {
85 local testroot=`test_init stage_no_changes`
87 got checkout $testroot/repo $testroot/wt > /dev/null
88 ret=$?
89 if [ $ret -ne 0 ]; then
90 test_done "$testroot" "$ret"
91 return 1
92 fi
94 (cd $testroot/wt && got stage alpha beta > $testroot/stdout \
95 2> $testroot/stderr)
96 ret=$?
97 if [ $ret -eq 0 ]; then
98 echo "got stage command succeeded unexpectedly" >&2
99 test_done "$testroot" "1"
100 return 1
101 fi
103 echo "got: no changes to stage" > $testroot/stderr.expected
105 cmp -s $testroot/stderr.expected $testroot/stderr
106 ret=$?
107 if [ $ret -ne 0 ]; then
108 diff -u $testroot/stderr.expected $testroot/stderr
109 test_done "$testroot" "$ret"
110 return 1
111 fi
113 echo -n > $testroot/stdout.expected
114 cmp -s $testroot/stdout.expected $testroot/stdout
115 ret=$?
116 if [ $ret -ne 0 ]; then
117 diff -u $testroot/stdout.expected $testroot/stdout
118 fi
119 test_done "$testroot" "$ret"
122 test_stage_unversioned() {
123 local testroot=`test_init stage_unversioned`
125 got checkout $testroot/repo $testroot/wt > /dev/null
126 ret=$?
127 if [ $ret -ne 0 ]; then
128 test_done "$testroot" "$ret"
129 return 1
130 fi
132 echo "modified file" > $testroot/wt/alpha
133 touch $testroot/wt/unversioned-file
135 (cd $testroot/wt && got status > $testroot/stdout)
136 echo "M alpha" > $testroot/stdout.expected
137 echo "? unversioned-file" >> $testroot/stdout.expected
138 cmp -s $testroot/stdout.expected $testroot/stdout
139 ret=$?
140 if [ $ret -ne 0 ]; then
141 diff -u $testroot/stdout.expected $testroot/stdout
142 test_done "$testroot" "$ret"
143 return 1
144 fi
146 (cd $testroot/wt && got stage -R > $testroot/stdout)
147 ret=$?
148 if [ $ret -ne 0 ]; then
149 echo "got stage command failed unexpectedly" >&2
150 test_done "$testroot" "$ret"
151 return 1
152 fi
154 echo " M alpha" > $testroot/stdout.expected
155 cmp -s $testroot/stdout.expected $testroot/stdout
156 ret=$?
157 if [ $ret -ne 0 ]; then
158 diff -u $testroot/stdout.expected $testroot/stdout
159 test_done "$testroot" "$ret"
160 return 1
161 fi
163 echo "modified file again" > $testroot/wt/alpha
165 (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
166 2> $testroot/stderr)
167 ret=$?
168 if [ $ret -eq 0 ]; then
169 echo "got stage command succeed unexpectedly" >&2
170 test_done "$testroot" "1"
171 return 1
172 fi
174 echo "got: no changes to stage" > $testroot/stderr.expected
175 cmp -s $testroot/stderr.expected $testroot/stderr
176 ret=$?
177 if [ $ret -ne 0 ]; then
178 diff -u $testroot/stderr.expected $testroot/stderr
179 fi
180 test_done "$testroot" "$ret"
184 test_stage_nonexistent() {
185 local testroot=`test_init stage_nonexistent`
187 got checkout $testroot/repo $testroot/wt > /dev/null
188 ret=$?
189 if [ $ret -ne 0 ]; then
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 (cd $testroot/wt && got stage nonexistent-file \
195 > $testroot/stdout 2> $testroot/stderr)
196 echo "got: nonexistent-file: No such file or directory" \
197 > $testroot/stderr.expected
198 cmp -s $testroot/stderr.expected $testroot/stderr
199 ret=$?
200 if [ $ret -ne 0 ]; then
201 diff -u $testroot/stderr.expected $testroot/stderr
202 fi
203 test_done "$testroot" "$ret"
206 test_stage_list() {
207 local testroot=`test_init stage_list`
209 got checkout $testroot/repo $testroot/wt > /dev/null
210 ret=$?
211 if [ $ret -ne 0 ]; then
212 test_done "$testroot" "$ret"
213 return 1
214 fi
216 echo "modified file" > $testroot/wt/alpha
217 (cd $testroot/wt && got rm beta > /dev/null)
218 echo "new file" > $testroot/wt/foo
219 (cd $testroot/wt && got add foo > /dev/null)
221 echo ' M alpha' > $testroot/stdout.expected
222 echo ' D beta' >> $testroot/stdout.expected
223 echo ' A foo' >> $testroot/stdout.expected
224 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
226 (cd $testroot/wt && got stage -Rl > $testroot/stdout)
227 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
228 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
229 echo " M alpha" >> $testroot/stdout.expected
230 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
231 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
232 echo " D beta" >> $testroot/stdout.expected
233 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
234 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
235 echo " A foo" >> $testroot/stdout.expected
236 cmp -s $testroot/stdout.expected $testroot/stdout
237 ret=$?
238 if [ $ret -ne 0 ]; then
239 diff -u $testroot/stdout.expected $testroot/stdout
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 (cd $testroot/wt && got stage -l epsilon nonexistent \
245 > $testroot/stdout)
247 echo -n > $testroot/stdout.expected
248 cmp -s $testroot/stdout.expected $testroot/stdout
249 ret=$?
250 if [ $ret -ne 0 ]; then
251 diff -u $testroot/stdout.expected $testroot/stdout
252 test_done "$testroot" "$ret"
253 return 1
254 fi
256 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
258 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
259 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
260 echo " M alpha" >> $testroot/stdout.expected
261 cmp -s $testroot/stdout.expected $testroot/stdout
262 ret=$?
263 if [ $ret -ne 0 ]; then
264 diff -u $testroot/stdout.expected $testroot/stdout
265 fi
266 test_done "$testroot" "$ret"
270 test_stage_conflict() {
271 local testroot=`test_init stage_conflict`
272 local initial_commit=`git_show_head $testroot/repo`
274 got checkout $testroot/repo $testroot/wt > /dev/null
275 ret=$?
276 if [ $ret -ne 0 ]; then
277 test_done "$testroot" "$ret"
278 return 1
279 fi
281 echo "modified alpha" > $testroot/wt/alpha
282 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
284 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
286 echo "modified alpha, too" > $testroot/wt/alpha
288 echo "C alpha" > $testroot/stdout.expected
289 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
290 git_show_head $testroot/repo >> $testroot/stdout.expected
291 echo >> $testroot/stdout.expected
292 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
294 (cd $testroot/wt && got update > $testroot/stdout)
296 cmp -s $testroot/stdout.expected $testroot/stdout
297 ret=$?
298 if [ $ret -ne 0 ]; then
299 diff -u $testroot/stdout.expected $testroot/stdout
300 test_done "$testroot" "$ret"
301 return 1
302 fi
304 (cd $testroot/wt && got stage alpha > $testroot/stdout \
305 2> $testroot/stderr)
306 ret=$?
307 if [ $ret -eq 0 ]; then
308 echo "got stage command succeeded unexpectedly" >&2
309 test_done "$testroot" "1"
310 return 1
311 fi
313 echo -n > $testroot/stdout.expected
314 echo "got: alpha: cannot stage file in conflicted status" \
315 > $testroot/stderr.expected
317 cmp -s $testroot/stdout.expected $testroot/stdout
318 ret=$?
319 if [ $ret -ne 0 ]; then
320 diff -u $testroot/stdout.expected $testroot/stdout
321 test_done "$testroot" "$ret"
322 return 1
323 fi
324 cmp -s $testroot/stderr.expected $testroot/stderr
325 ret=$?
326 if [ $ret -ne 0 ]; then
327 diff -u $testroot/stderr.expected $testroot/stderr
328 fi
329 test_done "$testroot" "$ret"
332 test_stage_out_of_date() {
333 local testroot=`test_init stage_out_of_date`
334 local initial_commit=`git_show_head $testroot/repo`
336 got checkout $testroot/repo $testroot/wt > /dev/null
337 ret=$?
338 if [ $ret -ne 0 ]; then
339 test_done "$testroot" "$ret"
340 return 1
341 fi
343 echo "modified alpha" > $testroot/wt/alpha
344 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
346 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
348 echo "modified alpha again" > $testroot/wt/alpha
349 (cd $testroot/wt && got stage alpha > $testroot/stdout \
350 2> $testroot/stderr)
351 ret=$?
352 if [ $ret -eq 0 ]; then
353 echo "got stage command succeeded unexpectedly" >&2
354 test_done "$testroot" "1"
355 return 1
356 fi
358 echo -n > $testroot/stdout.expected
359 echo "got: work tree must be updated before changes can be staged" \
360 > $testroot/stderr.expected
362 cmp -s $testroot/stdout.expected $testroot/stdout
363 ret=$?
364 if [ $ret -ne 0 ]; then
365 diff -u $testroot/stdout.expected $testroot/stdout
366 test_done "$testroot" "$ret"
367 return 1
368 fi
369 cmp -s $testroot/stderr.expected $testroot/stderr
370 ret=$?
371 if [ $ret -ne 0 ]; then
372 diff -u $testroot/stderr.expected $testroot/stderr
373 fi
374 test_done "$testroot" "$ret"
378 test_double_stage() {
379 local testroot=`test_init double_stage`
381 got checkout $testroot/repo $testroot/wt > /dev/null
382 ret=$?
383 if [ $ret -ne 0 ]; then
384 test_done "$testroot" "$ret"
385 return 1
386 fi
387 echo "modified file" > $testroot/wt/alpha
388 (cd $testroot/wt && got rm beta > /dev/null)
389 echo "new file" > $testroot/wt/foo
390 (cd $testroot/wt && got add foo > /dev/null)
391 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
393 echo "got: no changes to stage" > $testroot/stderr.expected
394 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
395 cmp -s $testroot/stderr.expected $testroot/stderr
396 ret=$?
397 if [ $ret -ne 0 ]; then
398 diff -u $testroot/stderr.expected $testroot/stderr
399 test_done "$testroot" "$ret"
400 return 1
401 fi
403 (cd $testroot/wt && got stage beta \
404 > $testroot/stdout 2> $testroot/stderr)
405 ret=$?
406 if [ $ret -eq 0 ]; then
407 echo "got stage command succeeded unexpectedly" >&2
408 test_done "$testroot" "1"
409 return 1
410 fi
411 echo -n > $testroot/stdout.expected
412 cmp -s $testroot/stdout.expected $testroot/stdout
413 ret=$?
414 if [ $ret -ne 0 ]; then
415 diff -u $testroot/stdout.expected $testroot/stdout
416 test_done "$testroot" "$ret"
417 return 1
418 fi
420 echo "got: no changes to stage" > $testroot/stderr.expected
421 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
422 cmp -s $testroot/stderr.expected $testroot/stderr
423 ret=$?
424 if [ $ret -ne 0 ]; then
425 diff -u $testroot/stderr.expected $testroot/stderr
426 test_done "$testroot" "$ret"
427 return 1
428 fi
430 printf "q\n" > $testroot/patchscript
431 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
432 > $testroot/stdout 2> $testroot/stderr)
433 ret=$?
434 if [ $ret -eq 0 ]; then
435 echo "got stage command succeeded unexpectedly" >&2
436 test_done "$testroot" "1"
437 return 1
438 fi
439 echo -n > $testroot/stdout.expected
440 cmp -s $testroot/stdout.expected $testroot/stdout
441 ret=$?
442 if [ $ret -ne 0 ]; then
443 diff -u $testroot/stdout.expected $testroot/stdout
444 test_done "$testroot" "$ret"
445 return 1
446 fi
448 echo "got: no changes to stage" > $testroot/stderr.expected
449 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
450 cmp -s $testroot/stderr.expected $testroot/stderr
451 ret=$?
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/stderr.expected $testroot/stderr
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 echo "modified file again" > $testroot/wt/alpha
459 echo "modified new file" > $testroot/wt/foo
461 echo ' M alpha' > $testroot/stdout.expected
462 echo ' A foo' >> $testroot/stdout.expected
463 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
464 cmp -s $testroot/stdout.expected $testroot/stdout
465 ret=$?
466 if [ $ret -ne 0 ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 echo ' M alpha' > $testroot/stdout.expected
473 echo ' D beta' >> $testroot/stdout.expected
474 echo ' A foo' >> $testroot/stdout.expected
476 (cd $testroot/wt && got status > $testroot/stdout)
477 cmp -s $testroot/stdout.expected $testroot/stdout
478 ret=$?
479 if [ $ret -ne 0 ]; then
480 diff -u $testroot/stdout.expected $testroot/stdout
481 fi
482 test_done "$testroot" "$ret"
485 test_stage_status() {
486 local testroot=`test_init stage_status`
488 got checkout $testroot/repo $testroot/wt > /dev/null
489 ret=$?
490 if [ $ret -ne 0 ]; then
491 test_done "$testroot" "$ret"
492 return 1
493 fi
495 echo "modified file" > $testroot/wt/alpha
496 (cd $testroot/wt && got rm beta > /dev/null)
497 echo "new file" > $testroot/wt/foo
498 (cd $testroot/wt && got add foo > /dev/null)
499 echo "new file" > $testroot/wt/epsilon/new
500 (cd $testroot/wt && got add epsilon/new > /dev/null)
501 echo "modified file" > $testroot/wt/epsilon/zeta
502 (cd $testroot/wt && got rm gamma/delta > /dev/null)
504 echo ' M alpha' > $testroot/stdout.expected
505 echo ' D beta' >> $testroot/stdout.expected
506 echo 'A epsilon/new' >> $testroot/stdout.expected
507 echo 'M epsilon/zeta' >> $testroot/stdout.expected
508 echo ' A foo' >> $testroot/stdout.expected
509 echo 'D gamma/delta' >> $testroot/stdout.expected
510 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
512 (cd $testroot/wt && got status > $testroot/stdout)
513 cmp -s $testroot/stdout.expected $testroot/stdout
514 ret=$?
515 if [ $ret -ne 0 ]; then
516 diff -u $testroot/stdout.expected $testroot/stdout
517 test_done "$testroot" "$ret"
518 return 1
519 fi
521 echo "modified file again" >> $testroot/wt/alpha
522 echo "modified added file again" >> $testroot/wt/foo
524 echo 'MM alpha' > $testroot/stdout.expected
525 echo ' D beta' >> $testroot/stdout.expected
526 echo 'A epsilon/new' >> $testroot/stdout.expected
527 echo 'M epsilon/zeta' >> $testroot/stdout.expected
528 echo 'MA foo' >> $testroot/stdout.expected
529 echo 'D gamma/delta' >> $testroot/stdout.expected
531 (cd $testroot/wt && got status > $testroot/stdout)
532 cmp -s $testroot/stdout.expected $testroot/stdout
533 ret=$?
534 if [ $ret -ne 0 ]; then
535 diff -u $testroot/stdout.expected $testroot/stdout
536 test_done "$testroot" "$ret"
537 return 1
538 fi
540 # test no-op change of added file with new stat(2) timestamp
541 echo "new file" > $testroot/wt/foo
542 echo ' A foo' > $testroot/stdout.expected
543 (cd $testroot/wt && got status foo > $testroot/stdout)
544 cmp -s $testroot/stdout.expected $testroot/stdout
545 ret=$?
546 if [ $ret -ne 0 ]; then
547 diff -u $testroot/stdout.expected $testroot/stdout
548 test_done "$testroot" "$ret"
549 return 1
550 fi
552 # test staged deleted file which is restored on disk
553 echo "new file" > $testroot/wt/beta
554 echo ' D beta' > $testroot/stdout.expected
555 (cd $testroot/wt && got status beta > $testroot/stdout)
556 cmp -s $testroot/stdout.expected $testroot/stdout
557 ret=$?
558 if [ $ret -ne 0 ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 fi
561 test_done "$testroot" "$ret"
565 test_stage_add_already_staged_file() {
566 local testroot=`test_init stage_add_already_staged_file`
568 got checkout $testroot/repo $testroot/wt > /dev/null
569 ret=$?
570 if [ $ret -ne 0 ]; then
571 test_done "$testroot" "$ret"
572 return 1
573 fi
575 echo "modified file" > $testroot/wt/alpha
576 (cd $testroot/wt && got rm beta > /dev/null)
577 echo "new file" > $testroot/wt/foo
578 (cd $testroot/wt && got add foo > /dev/null)
580 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
582 echo -n > $testroot/stdout.expected
583 for f in alpha beta foo; do
584 (cd $testroot/wt && got add $f \
585 > $testroot/stdout 2> $testroot/stderr)
586 echo "got: $f: file has unexpected status" \
587 > $testroot/stderr.expected
588 cmp -s $testroot/stderr.expected $testroot/stderr
589 ret=$?
590 if [ $ret -ne 0 ]; then
591 diff -u $testroot/stderr.expected $testroot/stderr
592 test_done "$testroot" "$ret"
593 return 1
594 fi
595 cmp -s $testroot/stdout.expected $testroot/stdout
596 ret=$?
597 if [ $ret -ne 0 ]; then
598 diff -u $testroot/stdout.expected $testroot/stdout
599 test_done "$testroot" "$ret"
600 return 1
601 fi
602 done
604 echo ' M alpha' > $testroot/stdout.expected
605 echo ' D beta' >> $testroot/stdout.expected
606 echo ' A foo' >> $testroot/stdout.expected
608 (cd $testroot/wt && got status > $testroot/stdout)
609 cmp -s $testroot/stdout.expected $testroot/stdout
610 ret=$?
611 if [ $ret -ne 0 ]; then
612 diff -u $testroot/stdout.expected $testroot/stdout
613 fi
614 test_done "$testroot" "$ret"
617 test_stage_rm_already_staged_file() {
618 local testroot=`test_init stage_rm_already_staged_file`
620 got checkout $testroot/repo $testroot/wt > /dev/null
621 ret=$?
622 if [ $ret -ne 0 ]; then
623 test_done "$testroot" "$ret"
624 return 1
625 fi
627 echo "modified file" > $testroot/wt/alpha
628 (cd $testroot/wt && got rm beta > /dev/null)
629 echo "new file" > $testroot/wt/foo
630 (cd $testroot/wt && got add foo > /dev/null)
632 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
634 (cd $testroot/wt && got rm beta \
635 > $testroot/stdout 2> $testroot/stderr)
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 echo "got rm command failed unexpectedly" >&2
639 test_done "$testroot" "1"
640 return 1
641 fi
642 echo -n > $testroot/stdout.expected
643 cmp -s $testroot/stdout.expected $testroot/stdout
644 ret=$?
645 if [ $ret -ne 0 ]; then
646 diff -u $testroot/stdout.expected $testroot/stdout
647 test_done "$testroot" "$ret"
648 return 1
649 fi
650 echo -n > $testroot/stderr.expected
651 cmp -s $testroot/stderr.expected $testroot/stderr
652 ret=$?
653 if [ $ret -ne 0 ]; then
654 diff -u $testroot/stderr.expected $testroot/stderr
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 for f in alpha foo; do
660 echo "got: $f: file is staged" > $testroot/stderr.expected
661 (cd $testroot/wt && got rm $f \
662 > $testroot/stdout 2> $testroot/stderr)
663 ret=$?
664 if [ $ret -eq 0 ]; then
665 echo "got rm command succeeded unexpectedly" >&2
666 test_done "$testroot" "1"
667 return 1
668 fi
669 cmp -s $testroot/stderr.expected $testroot/stderr
670 ret=$?
671 if [ $ret -ne 0 ]; then
672 diff -u $testroot/stderr.expected $testroot/stderr
673 test_done "$testroot" "$ret"
674 return 1
675 fi
676 done
678 echo ' M alpha' > $testroot/stdout.expected
679 echo ' D beta' >> $testroot/stdout.expected
680 echo ' A foo' >> $testroot/stdout.expected
682 (cd $testroot/wt && got status > $testroot/stdout)
683 cmp -s $testroot/stdout.expected $testroot/stdout
684 ret=$?
685 if [ $ret -ne 0 ]; then
686 diff -u $testroot/stdout.expected $testroot/stdout
687 fi
688 test_done "$testroot" "$ret"
691 test_stage_revert() {
692 local testroot=`test_init stage_revert`
694 got checkout $testroot/repo $testroot/wt > /dev/null
695 ret=$?
696 if [ $ret -ne 0 ]; then
697 test_done "$testroot" "$ret"
698 return 1
699 fi
701 echo "modified alpha" > $testroot/wt/alpha
702 (cd $testroot/wt && got rm beta > /dev/null)
703 echo "new file" > $testroot/wt/foo
704 (cd $testroot/wt && got add foo > /dev/null)
705 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
707 echo "modified file again" >> $testroot/wt/alpha
708 echo "modified added file again" >> $testroot/wt/foo
710 (cd $testroot/wt && got revert alpha > $testroot/stdout)
711 ret=$?
712 if [ $ret -ne 0 ]; then
713 echo "revert command failed unexpectedly" >&2
714 test_done "$testroot" "$ret"
715 return 1
716 fi
718 echo "R alpha" > $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
720 ret=$?
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
723 test_done "$testroot" "$ret"
724 return 1
725 fi
727 echo "modified alpha" > $testroot/content.expected
728 cat $testroot/wt/alpha > $testroot/content
729 cmp -s $testroot/content.expected $testroot/content
730 ret=$?
731 if [ $ret -ne 0 ]; then
732 diff -u $testroot/content.expected $testroot/content
733 test_done "$testroot" "$ret"
734 return 1
735 fi
737 echo ' M alpha' > $testroot/stdout.expected
738 echo ' D beta' >> $testroot/stdout.expected
739 echo 'MA foo' >> $testroot/stdout.expected
740 (cd $testroot/wt && got status > $testroot/stdout)
741 cmp -s $testroot/stdout.expected $testroot/stdout
742 ret=$?
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/stdout.expected $testroot/stdout
745 test_done "$testroot" "$ret"
746 return 1
747 fi
749 (cd $testroot/wt && got revert alpha > $testroot/stdout)
750 ret=$?
751 if [ $ret -ne 0 ]; then
752 echo "revert command failed unexpectedly" >&2
753 test_done "$testroot" "$ret"
754 return 1
755 fi
757 echo -n > $testroot/stdout.expected
758 cmp -s $testroot/stdout.expected $testroot/stdout
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 diff -u $testroot/stdout.expected $testroot/stdout
762 test_done "$testroot" "$ret"
763 return 1
764 fi
766 echo "modified alpha" > $testroot/content.expected
767 cat $testroot/wt/alpha > $testroot/content
768 cmp -s $testroot/content.expected $testroot/content
769 ret=$?
770 if [ $ret -ne 0 ]; then
771 diff -u $testroot/content.expected $testroot/content
772 test_done "$testroot" "$ret"
773 return 1
774 fi
776 (cd $testroot/wt && got revert beta > $testroot/stdout \
777 2> $testroot/stderr)
778 ret=$?
779 if [ $ret -ne 0 ]; then
780 echo "revert command failed unexpectedly" >&2
781 test_done "$testroot" "$ret"
782 return 1
783 fi
785 echo -n > $testroot/stdout.expected
786 cmp -s $testroot/stdout.expected $testroot/stdout
787 ret=$?
788 if [ $ret -ne 0 ]; then
789 diff -u $testroot/stdout.expected $testroot/stdout
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 echo -n > $testroot/stderr.expected
795 cmp -s $testroot/stderr.expected $testroot/stderr
796 ret=$?
797 if [ $ret -ne 0 ]; then
798 diff -u $testroot/stderr.expected $testroot/stderr
799 test_done "$testroot" "$ret"
800 return 1
801 fi
803 (cd $testroot/wt && got revert foo > $testroot/stdout)
804 ret=$?
805 if [ $ret -ne 0 ]; then
806 echo "revert command failed unexpectedly" >&2
807 test_done "$testroot" "$ret"
808 return 1
809 fi
811 echo "R foo" > $testroot/stdout.expected
812 cmp -s $testroot/stdout.expected $testroot/stdout
813 ret=$?
814 if [ $ret -ne 0 ]; then
815 diff -u $testroot/stdout.expected $testroot/stdout
816 test_done "$testroot" "$ret"
817 return 1
818 fi
820 echo "new file" > $testroot/content.expected
821 cat $testroot/wt/foo > $testroot/content
822 cmp -s $testroot/content.expected $testroot/content
823 ret=$?
824 if [ $ret -ne 0 ]; then
825 diff -u $testroot/content.expected $testroot/content
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 status > $testroot/stdout)
834 cmp -s $testroot/stdout.expected $testroot/stdout
835 ret=$?
836 if [ $ret -ne 0 ]; then
837 diff -u $testroot/stdout.expected $testroot/stdout
838 test_done "$testroot" "$ret"
839 return 1
840 fi
842 (cd $testroot/wt && got revert foo > $testroot/stdout)
843 ret=$?
844 if [ $ret -ne 0 ]; then
845 echo "revert command failed unexpectedly" >&2
846 test_done "$testroot" "$ret"
847 return 1
848 fi
850 echo -n > $testroot/stdout.expected
851 cmp -s $testroot/stdout.expected $testroot/stdout
852 ret=$?
853 if [ $ret -ne 0 ]; then
854 diff -u $testroot/stdout.expected $testroot/stdout
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 echo "new file" > $testroot/content.expected
860 cat $testroot/wt/foo > $testroot/content
861 cmp -s $testroot/content.expected $testroot/content
862 ret=$?
863 if [ $ret -ne 0 ]; then
864 diff -u $testroot/content.expected $testroot/content
865 test_done "$testroot" "$ret"
866 return 1
867 fi
869 echo ' M alpha' > $testroot/stdout.expected
870 echo ' D beta' >> $testroot/stdout.expected
871 echo ' A foo' >> $testroot/stdout.expected
872 (cd $testroot/wt && got status > $testroot/stdout)
873 cmp -s $testroot/stdout.expected $testroot/stdout
874 ret=$?
875 if [ $ret -ne 0 ]; then
876 diff -u $testroot/stdout.expected $testroot/stdout
877 test_done "$testroot" "$ret"
878 return 1
879 fi
881 echo "modified file again" >> $testroot/wt/alpha
882 echo "modified added file again" >> $testroot/wt/foo
884 (cd $testroot/wt && got revert -R . > $testroot/stdout \
885 2> $testroot/stderr)
886 ret=$?
887 if [ $ret -ne 0 ]; then
888 echo "revert command failed unexpectedly" >&2
889 test_done "$testroot" "$ret"
890 return 1
891 fi
893 echo "R alpha" > $testroot/stdout.expected
894 echo "R foo" >> $testroot/stdout.expected
895 cmp -s $testroot/stdout.expected $testroot/stdout
896 ret=$?
897 if [ $ret -ne 0 ]; then
898 diff -u $testroot/stdout.expected $testroot/stdout
899 test_done "$testroot" "$ret"
900 return 1
901 fi
903 echo -n > $testroot/stderr.expected
904 cmp -s $testroot/stderr.expected $testroot/stderr
905 ret=$?
906 if [ $ret -ne 0 ]; then
907 diff -u $testroot/stderr.expected $testroot/stderr
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 status > $testroot/stdout)
916 cmp -s $testroot/stdout.expected $testroot/stdout
917 ret=$?
918 if [ $ret -ne 0 ]; then
919 diff -u $testroot/stdout.expected $testroot/stdout
920 fi
921 test_done "$testroot" "$ret"
924 test_stage_diff() {
925 local testroot=`test_init stage_diff`
926 local head_commit=`git_show_head $testroot/repo`
928 got checkout $testroot/repo $testroot/wt > /dev/null
929 ret=$?
930 if [ $ret -ne 0 ]; then
931 test_done "$testroot" "$ret"
932 return 1
933 fi
935 echo "modified file" > $testroot/wt/alpha
936 (cd $testroot/wt && got rm beta > /dev/null)
937 echo "new file" > $testroot/wt/foo
938 (cd $testroot/wt && got add foo > /dev/null)
940 (cd $testroot/wt && got diff -s > $testroot/stdout)
941 echo -n > $testroot/stdout.expected
942 cmp -s $testroot/stdout.expected $testroot/stdout
943 ret=$?
944 if [ $ret -ne 0 ]; then
945 diff -u $testroot/stdout.expected $testroot/stdout
946 test_done "$testroot" "$ret"
947 return 1
948 fi
950 echo ' M alpha' > $testroot/stdout.expected
951 echo ' D beta' >> $testroot/stdout.expected
952 echo ' A foo' >> $testroot/stdout.expected
953 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
955 (cd $testroot/wt && got diff > $testroot/stdout)
956 echo -n > $testroot/stdout.expected
957 cmp -s $testroot/stdout.expected $testroot/stdout
958 ret=$?
959 if [ $ret -ne 0 ]; then
960 diff -u $testroot/stdout.expected $testroot/stdout
961 test_done "$testroot" "$ret"
962 return 1
963 fi
965 echo "modified file again" > $testroot/wt/alpha
966 echo "new file changed" > $testroot/wt/foo
968 (cd $testroot/wt && got diff > $testroot/stdout)
970 echo "diff $testroot/wt" > $testroot/stdout.expected
971 echo "commit - $head_commit" >> $testroot/stdout.expected
972 echo "path + $testroot/wt" >> $testroot/stdout.expected
973 echo -n 'blob - ' >> $testroot/stdout.expected
974 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
975 >> $testroot/stdout.expected
976 echo ' (staged)' >> $testroot/stdout.expected
977 echo 'file + alpha' >> $testroot/stdout.expected
978 echo '--- alpha' >> $testroot/stdout.expected
979 echo '+++ alpha' >> $testroot/stdout.expected
980 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
981 echo '-modified file' >> $testroot/stdout.expected
982 echo '+modified file again' >> $testroot/stdout.expected
983 echo -n 'blob - ' >> $testroot/stdout.expected
984 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
985 >> $testroot/stdout.expected
986 echo " (staged)" >> $testroot/stdout.expected
987 echo 'file + foo' >> $testroot/stdout.expected
988 echo '--- foo' >> $testroot/stdout.expected
989 echo '+++ foo' >> $testroot/stdout.expected
990 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
991 echo '-new file' >> $testroot/stdout.expected
992 echo '+new file changed' >> $testroot/stdout.expected
994 cmp -s $testroot/stdout.expected $testroot/stdout
995 ret=$?
996 if [ $ret -ne 0 ]; then
997 diff -u $testroot/stdout.expected $testroot/stdout
998 test_done "$testroot" "$ret"
999 return 1
1002 (cd $testroot/wt && got diff -s > $testroot/stdout)
1004 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1005 echo "commit - $head_commit" >> $testroot/stdout.expected
1006 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1007 echo -n 'blob - ' >> $testroot/stdout.expected
1008 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
1009 >> $testroot/stdout.expected
1010 echo -n 'blob + ' >> $testroot/stdout.expected
1011 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1012 >> $testroot/stdout.expected
1013 echo '--- alpha' >> $testroot/stdout.expected
1014 echo '+++ alpha' >> $testroot/stdout.expected
1015 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1016 echo '-alpha' >> $testroot/stdout.expected
1017 echo '+modified file' >> $testroot/stdout.expected
1018 echo -n 'blob - ' >> $testroot/stdout.expected
1019 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1020 >> $testroot/stdout.expected
1021 echo 'blob + /dev/null' >> $testroot/stdout.expected
1022 echo '--- beta' >> $testroot/stdout.expected
1023 echo '+++ /dev/null' >> $testroot/stdout.expected
1024 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1025 echo '-beta' >> $testroot/stdout.expected
1026 echo 'blob - /dev/null' >> $testroot/stdout.expected
1027 echo -n 'blob + ' >> $testroot/stdout.expected
1028 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1029 >> $testroot/stdout.expected
1030 echo '--- /dev/null' >> $testroot/stdout.expected
1031 echo '+++ foo' >> $testroot/stdout.expected
1032 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1033 echo '+new file' >> $testroot/stdout.expected
1035 cmp -s $testroot/stdout.expected $testroot/stdout
1036 ret=$?
1037 if [ $ret -ne 0 ]; then
1038 diff -u $testroot/stdout.expected $testroot/stdout
1040 test_done "$testroot" "$ret"
1044 test_stage_histedit() {
1045 local testroot=`test_init stage_histedit`
1046 local orig_commit=`git_show_head $testroot/repo`
1048 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1049 ret=$?
1050 if [ $ret -ne 0 ]; then
1051 test_done "$testroot" "$ret"
1052 return 1
1055 echo "modified file" > $testroot/wt/alpha
1056 (cd $testroot/wt && got stage alpha > /dev/null)
1058 echo "modified alpha on master" > $testroot/repo/alpha
1059 git -C $testroot/repo rm -q beta
1060 echo "new file on master" > $testroot/repo/epsilon/new
1061 git -C $testroot/repo add epsilon/new
1062 git_commit $testroot/repo -m "committing changes"
1063 local old_commit1=`git_show_head $testroot/repo`
1065 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1066 git_commit $testroot/repo -m "committing to zeta on master"
1067 local old_commit2=`git_show_head $testroot/repo`
1069 echo "pick $old_commit1" > $testroot/histedit-script
1070 echo "pick $old_commit2" >> $testroot/histedit-script
1072 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1073 > $testroot/stdout 2> $testroot/stderr)
1074 ret=$?
1075 if [ $ret -eq 0 ]; then
1076 echo "got histedit command succeeded unexpectedly" >&2
1077 test_done "$testroot" "1"
1078 return 1
1081 echo -n > $testroot/stdout.expected
1082 echo "got: alpha: file is staged" > $testroot/stderr.expected
1084 cmp -s $testroot/stderr.expected $testroot/stderr
1085 ret=$?
1086 if [ $ret -ne 0 ]; then
1087 diff -u $testroot/stderr.expected $testroot/stderr
1088 test_done "$testroot" "$ret"
1089 return 1
1091 cmp -s $testroot/stdout.expected $testroot/stdout
1092 ret=$?
1093 if [ $ret -ne 0 ]; then
1094 diff -u $testroot/stdout.expected $testroot/stdout
1096 test_done "$testroot" "$ret"
1100 test_stage_rebase() {
1101 local testroot=`test_init stage_rebase`
1103 git -C $testroot/repo checkout -q -b newbranch
1104 echo "modified delta on branch" > $testroot/repo/gamma/delta
1105 git_commit $testroot/repo -m "committing to delta on newbranch"
1107 echo "modified alpha on branch" > $testroot/repo/alpha
1108 git -C $testroot/repo rm -q beta
1109 echo "new file on branch" > $testroot/repo/epsilon/new
1110 git -C $testroot/repo add epsilon/new
1111 git_commit $testroot/repo -m "committing more changes on newbranch"
1113 local orig_commit1=`git_show_parent_commit $testroot/repo`
1114 local orig_commit2=`git_show_head $testroot/repo`
1116 git -C $testroot/repo checkout -q master
1117 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1118 git_commit $testroot/repo -m "committing to zeta on master"
1119 local master_commit=`git_show_head $testroot/repo`
1121 got checkout $testroot/repo $testroot/wt > /dev/null
1122 ret=$?
1123 if [ $ret -ne 0 ]; then
1124 test_done "$testroot" "$ret"
1125 return 1
1128 echo "modified file" > $testroot/wt/alpha
1129 (cd $testroot/wt && got stage alpha > /dev/null)
1131 (cd $testroot/wt && got rebase newbranch \
1132 > $testroot/stdout 2> $testroot/stderr)
1133 ret=$?
1134 if [ $ret -eq 0 ]; then
1135 echo "got rebase command succeeded unexpectedly" >&2
1136 test_done "$testroot" "1"
1137 return 1
1140 echo -n > $testroot/stdout.expected
1141 echo "got: alpha: file is staged" > $testroot/stderr.expected
1143 cmp -s $testroot/stderr.expected $testroot/stderr
1144 ret=$?
1145 if [ $ret -ne 0 ]; then
1146 diff -u $testroot/stderr.expected $testroot/stderr
1147 test_done "$testroot" "$ret"
1148 return 1
1150 cmp -s $testroot/stdout.expected $testroot/stdout
1151 ret=$?
1152 if [ $ret -ne 0 ]; then
1153 diff -u $testroot/stdout.expected $testroot/stdout
1155 test_done "$testroot" "$ret"
1158 test_stage_update() {
1159 local testroot=`test_init stage_update`
1161 got checkout $testroot/repo $testroot/wt > /dev/null
1162 ret=$?
1163 if [ $ret -ne 0 ]; then
1164 test_done "$testroot" "$ret"
1165 return 1
1168 echo "modified file" > $testroot/wt/alpha
1169 (cd $testroot/wt && got stage alpha > /dev/null)
1171 echo "modified alpha" > $testroot/repo/alpha
1172 git_commit $testroot/repo -m "modified alpha"
1174 (cd $testroot/wt && got update > $testroot/stdout \
1175 2> $testroot/stderr)
1176 ret=$?
1177 if [ $ret -eq 0 ]; then
1178 echo "got update command succeeded unexpectedly" >&2
1179 test_done "$testroot" "1"
1180 return 1
1183 echo -n > $testroot/stdout.expected
1184 echo "got: alpha: file is staged" > $testroot/stderr.expected
1186 cmp -s $testroot/stderr.expected $testroot/stderr
1187 ret=$?
1188 if [ $ret -ne 0 ]; then
1189 diff -u $testroot/stderr.expected $testroot/stderr
1190 test_done "$testroot" "$ret"
1191 return 1
1193 cmp -s $testroot/stdout.expected $testroot/stdout
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 diff -u $testroot/stdout.expected $testroot/stdout
1198 test_done "$testroot" "$ret"
1201 test_stage_commit_non_staged() {
1202 local testroot=`test_init stage_commit_non_staged`
1204 got checkout $testroot/repo $testroot/wt > /dev/null
1205 ret=$?
1206 if [ $ret -ne 0 ]; then
1207 test_done "$testroot" "$ret"
1208 return 1
1211 echo "modified file" > $testroot/wt/alpha
1212 (cd $testroot/wt && got rm beta > /dev/null)
1213 echo "new file" > $testroot/wt/foo
1214 (cd $testroot/wt && got add foo > /dev/null)
1215 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1217 echo "modified file" > $testroot/wt/gamma/delta
1218 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1219 > $testroot/stdout 2> $testroot/stderr)
1220 ret=$?
1221 if [ $ret -eq 0 ]; then
1222 echo "got commit command succeeded unexpectedly" >&2
1223 test_done "$testroot" "1"
1224 return 1
1227 echo -n > $testroot/stdout.expected
1228 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1230 cmp -s $testroot/stderr.expected $testroot/stderr
1231 ret=$?
1232 if [ $ret -ne 0 ]; then
1233 diff -u $testroot/stderr.expected $testroot/stderr
1234 test_done "$testroot" "$ret"
1235 return 1
1237 cmp -s $testroot/stdout.expected $testroot/stdout
1238 ret=$?
1239 if [ $ret -ne 0 ]; then
1240 diff -u $testroot/stdout.expected $testroot/stdout
1242 test_done "$testroot" "$ret"
1245 test_stage_commit_out_of_date() {
1246 local testroot=`test_init stage_commit_out_of_date`
1248 got checkout $testroot/repo $testroot/wt > /dev/null
1249 ret=$?
1250 if [ $ret -ne 0 ]; then
1251 test_done "$testroot" "$ret"
1252 return 1
1255 echo "modified file" > $testroot/wt/alpha
1256 (cd $testroot/wt && got rm beta > /dev/null)
1257 echo "new file" > $testroot/wt/foo
1258 (cd $testroot/wt && got add foo > /dev/null)
1259 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1261 echo "changed file" > $testroot/repo/alpha
1262 git_commit $testroot/repo -m "changed alpha in repo"
1264 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1265 2> $testroot/stderr)
1266 ret=$?
1267 if [ $ret -eq 0 ]; then
1268 echo "got commit command succeeded unexpectedly" >&2
1269 test_done "$testroot" "1"
1270 return 1
1273 echo -n > $testroot/stdout.expected
1274 echo -n "got: work tree must be updated before these changes " \
1275 > $testroot/stderr.expected
1276 echo "can be committed" >> $testroot/stderr.expected
1278 cmp -s $testroot/stderr.expected $testroot/stderr
1279 ret=$?
1280 if [ $ret -ne 0 ]; then
1281 diff -u $testroot/stderr.expected $testroot/stderr
1282 test_done "$testroot" "$ret"
1283 return 1
1285 cmp -s $testroot/stdout.expected $testroot/stdout
1286 ret=$?
1287 if [ $ret -ne 0 ]; then
1288 diff -u $testroot/stdout.expected $testroot/stdout
1289 test_done "$testroot" "$ret"
1290 return 1
1293 (cd $testroot/wt && got update > $testroot/stdout \
1294 2> $testroot/stderr)
1295 echo -n > $testroot/stdout.expected
1296 echo "got: alpha: file is staged" > $testroot/stderr.expected
1298 cmp -s $testroot/stderr.expected $testroot/stderr
1299 ret=$?
1300 if [ $ret -ne 0 ]; then
1301 diff -u $testroot/stderr.expected $testroot/stderr
1302 test_done "$testroot" "$ret"
1303 return 1
1305 cmp -s $testroot/stdout.expected $testroot/stdout
1306 ret=$?
1307 if [ $ret -ne 0 ]; then
1308 diff -u $testroot/stdout.expected $testroot/stdout
1309 test_done "$testroot" "$ret"
1310 return 1
1313 (cd $testroot/wt && got unstage -R > /dev/null)
1314 (cd $testroot/wt && got update > $testroot/stdout)
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 echo "got update command failed unexpectedly" >&2
1318 test_done "$testroot" "$ret"
1319 return 1
1322 (cd $testroot/wt && got status > $testroot/stdout)
1323 echo "C alpha" > $testroot/stdout.expected
1324 echo "D beta" >> $testroot/stdout.expected
1325 echo "A foo" >> $testroot/stdout.expected
1326 cmp -s $testroot/stdout.expected $testroot/stdout
1327 ret=$?
1328 if [ $ret -ne 0 ]; then
1329 diff -u $testroot/stdout.expected $testroot/stdout
1330 test_done "$testroot" "$ret"
1331 return 1
1334 # resolve conflict
1335 echo "resolved file" > $testroot/wt/alpha
1337 (cd $testroot/wt && got stage -R > /dev/null)
1339 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1340 ret=$?
1341 if [ $ret -ne 0 ]; then
1342 echo "got commit command failed unexpectedly" >&2
1343 test_done "$testroot" "$ret"
1344 return 1
1347 local commit_id=`git_show_head $testroot/repo`
1348 echo "A foo" > $testroot/stdout.expected
1349 echo "M alpha" >> $testroot/stdout.expected
1350 echo "D beta" >> $testroot/stdout.expected
1351 echo "Created commit $commit_id" >> $testroot/stdout.expected
1352 cmp -s $testroot/stdout.expected $testroot/stdout
1353 ret=$?
1354 if [ $ret -ne 0 ]; then
1355 diff -u $testroot/stdout.expected $testroot/stdout
1357 test_done "$testroot" "$ret"
1361 test_stage_commit() {
1362 local testroot=`test_init stage_commit`
1363 local first_commit=`git_show_head $testroot/repo`
1365 got checkout $testroot/repo $testroot/wt > /dev/null
1366 ret=$?
1367 if [ $ret -ne 0 ]; then
1368 test_done "$testroot" "$ret"
1369 return 1
1372 echo "modified file" > $testroot/wt/alpha
1373 (cd $testroot/wt && got rm beta > /dev/null)
1374 echo "new file" > $testroot/wt/foo
1375 (cd $testroot/wt && got add foo > /dev/null)
1376 echo "modified file" > $testroot/wt/alpha
1377 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1379 echo "modified file again" > $testroot/wt/alpha
1380 echo "new file changed" > $testroot/wt/foo
1381 echo "non-staged change" > $testroot/wt/gamma/delta
1382 echo "non-staged new file" > $testroot/wt/epsilon/new
1383 (cd $testroot/wt && got add epsilon/new > /dev/null)
1384 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1386 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1387 > $testroot/blob_id_alpha
1388 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1389 > $testroot/blob_id_foo
1391 (cd $testroot/wt && got commit -m "staged changes" \
1392 > $testroot/stdout)
1393 ret=$?
1394 if [ $ret -ne 0 ]; then
1395 echo "got commit command failed unexpectedly" >&2
1396 test_done "$testroot" "1"
1397 return 1
1400 local head_commit=`git_show_head $testroot/repo`
1401 echo "A foo" > $testroot/stdout.expected
1402 echo "M alpha" >> $testroot/stdout.expected
1403 echo "D beta" >> $testroot/stdout.expected
1404 echo "Created commit $head_commit" >> $testroot/stdout.expected
1406 cmp -s $testroot/stdout.expected $testroot/stdout
1407 ret=$?
1408 if [ $ret -ne 0 ]; then
1409 diff -u $testroot/stdout.expected $testroot/stdout
1410 test_done "$testroot" "$ret"
1411 return 1
1414 got diff -r $testroot/repo $first_commit $head_commit \
1415 > $testroot/stdout
1417 echo "diff $first_commit $head_commit" \
1418 > $testroot/stdout.expected
1419 echo "commit - $first_commit" >> $testroot/stdout.expected
1420 echo "commit + $head_commit" >> $testroot/stdout.expected
1421 echo -n 'blob - ' >> $testroot/stdout.expected
1422 got tree -r $testroot/repo -i -c $first_commit | \
1423 grep 'alpha$' | cut -d' ' -f 1 \
1424 >> $testroot/stdout.expected
1425 echo -n 'blob + ' >> $testroot/stdout.expected
1426 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1427 echo '--- alpha' >> $testroot/stdout.expected
1428 echo '+++ alpha' >> $testroot/stdout.expected
1429 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1430 echo '-alpha' >> $testroot/stdout.expected
1431 echo '+modified file' >> $testroot/stdout.expected
1432 echo -n 'blob - ' >> $testroot/stdout.expected
1433 got tree -r $testroot/repo -i -c $first_commit \
1434 | grep 'beta$' | cut -d' ' -f 1 | tr -d '\n' \
1435 >> $testroot/stdout.expected
1436 echo " (mode 644)" >> $testroot/stdout.expected
1437 echo 'blob + /dev/null' >> $testroot/stdout.expected
1438 echo '--- beta' >> $testroot/stdout.expected
1439 echo '+++ /dev/null' >> $testroot/stdout.expected
1440 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1441 echo '-beta' >> $testroot/stdout.expected
1442 echo 'blob - /dev/null' >> $testroot/stdout.expected
1443 echo -n 'blob + ' >> $testroot/stdout.expected
1444 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1445 echo " (mode 644)" >> $testroot/stdout.expected
1446 echo '--- /dev/null' >> $testroot/stdout.expected
1447 echo '+++ foo' >> $testroot/stdout.expected
1448 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1449 echo '+new file' >> $testroot/stdout.expected
1451 cmp -s $testroot/stdout.expected $testroot/stdout
1452 ret=$?
1453 if [ $ret -ne 0 ]; then
1454 diff -u $testroot/stdout.expected $testroot/stdout
1455 test_done "$testroot" "$ret"
1456 return 1
1459 echo 'M alpha' > $testroot/stdout.expected
1460 echo 'A epsilon/new' >> $testroot/stdout.expected
1461 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1462 echo 'M foo' >> $testroot/stdout.expected
1463 echo 'M gamma/delta' >> $testroot/stdout.expected
1465 (cd $testroot/wt && got status > $testroot/stdout)
1466 cmp -s $testroot/stdout.expected $testroot/stdout
1467 ret=$?
1468 if [ $ret -ne 0 ]; then
1469 diff -u $testroot/stdout.expected $testroot/stdout
1471 test_done "$testroot" "$ret"
1474 test_stage_patch() {
1475 local testroot=`test_init stage_patch`
1477 seq 16 > $testroot/repo/numbers
1478 git -C $testroot/repo add numbers
1479 git_commit $testroot/repo -m "added numbers file"
1480 local commit_id=`git_show_head $testroot/repo`
1482 got checkout $testroot/repo $testroot/wt > /dev/null
1483 ret=$?
1484 if [ $ret -ne 0 ]; then
1485 test_done "$testroot" "$ret"
1486 return 1
1489 ed -s $testroot/wt/numbers <<-\EOF
1490 ,s/^2$/a/
1491 ,s/^7$/b/
1492 ,s/^16$/c/
1494 EOF
1496 # don't stage any hunks
1497 printf "n\nn\nn\n" > $testroot/patchscript
1498 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1499 numbers > $testroot/stdout 2> $testroot/stderr)
1500 ret=$?
1501 if [ $ret -eq 0 ]; then
1502 echo "got stage command succeeded unexpectedly" >&2
1503 test_done "$testroot" "1"
1504 return 1
1506 cat > $testroot/stdout.expected <<EOF
1507 -----------------------------------------------
1508 @@ -1,5 +1,5 @@
1515 -----------------------------------------------
1516 M numbers (change 1 of 3)
1517 stage this change? [y/n/q] n
1518 -----------------------------------------------
1519 @@ -4,7 +4,7 @@
1528 -----------------------------------------------
1529 M numbers (change 2 of 3)
1530 stage this change? [y/n/q] n
1531 -----------------------------------------------
1532 @@ -13,4 +13,4 @@
1536 -16
1538 -----------------------------------------------
1539 M numbers (change 3 of 3)
1540 stage this change? [y/n/q] n
1541 EOF
1542 cmp -s $testroot/stdout.expected $testroot/stdout
1543 ret=$?
1544 if [ $ret -ne 0 ]; then
1545 diff -u $testroot/stdout.expected $testroot/stdout
1546 test_done "$testroot" "$ret"
1547 return 1
1550 echo "got: no changes to stage" > $testroot/stderr.expected
1551 cmp -s $testroot/stderr.expected $testroot/stderr
1552 ret=$?
1553 if [ $ret -ne 0 ]; then
1554 diff -u $testroot/stderr.expected $testroot/stderr
1555 test_done "$testroot" "$ret"
1556 return 1
1560 (cd $testroot/wt && got status > $testroot/stdout)
1561 echo "M numbers" > $testroot/stdout.expected
1562 cmp -s $testroot/stdout.expected $testroot/stdout
1563 ret=$?
1564 if [ $ret -ne 0 ]; then
1565 diff -u $testroot/stdout.expected $testroot/stdout
1566 test_done "$testroot" "$ret"
1567 return 1
1570 # stage middle hunk
1571 printf "n\ny\nn\n" > $testroot/patchscript
1572 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1573 numbers > $testroot/stdout)
1575 cat > $testroot/stdout.expected <<EOF
1576 -----------------------------------------------
1577 @@ -1,5 +1,5 @@
1584 -----------------------------------------------
1585 M numbers (change 1 of 3)
1586 stage this change? [y/n/q] n
1587 -----------------------------------------------
1588 @@ -4,7 +4,7 @@
1597 -----------------------------------------------
1598 M numbers (change 2 of 3)
1599 stage this change? [y/n/q] y
1600 -----------------------------------------------
1601 @@ -13,4 +13,4 @@
1605 -16
1607 -----------------------------------------------
1608 M numbers (change 3 of 3)
1609 stage this change? [y/n/q] n
1610 EOF
1611 cmp -s $testroot/stdout.expected $testroot/stdout
1612 ret=$?
1613 if [ $ret -ne 0 ]; then
1614 diff -u $testroot/stdout.expected $testroot/stdout
1615 test_done "$testroot" "$ret"
1616 return 1
1619 (cd $testroot/wt && got status > $testroot/stdout)
1620 echo "MM numbers" > $testroot/stdout.expected
1621 cmp -s $testroot/stdout.expected $testroot/stdout
1622 ret=$?
1623 if [ $ret -ne 0 ]; then
1624 diff -u $testroot/stdout.expected $testroot/stdout
1625 test_done "$testroot" "$ret"
1626 return 1
1629 (cd $testroot/wt && got diff -s > $testroot/stdout)
1631 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1632 echo "commit - $commit_id" >> $testroot/stdout.expected
1633 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1634 echo -n 'blob - ' >> $testroot/stdout.expected
1635 got tree -r $testroot/repo -i -c $commit_id \
1636 | grep 'numbers$' | cut -d' ' -f 1 \
1637 >> $testroot/stdout.expected
1638 echo -n 'blob + ' >> $testroot/stdout.expected
1639 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1640 >> $testroot/stdout.expected
1641 echo "--- numbers" >> $testroot/stdout.expected
1642 echo "+++ numbers" >> $testroot/stdout.expected
1643 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1644 echo " 4" >> $testroot/stdout.expected
1645 echo " 5" >> $testroot/stdout.expected
1646 echo " 6" >> $testroot/stdout.expected
1647 echo "-7" >> $testroot/stdout.expected
1648 echo "+b" >> $testroot/stdout.expected
1649 echo " 8" >> $testroot/stdout.expected
1650 echo " 9" >> $testroot/stdout.expected
1651 echo " 10" >> $testroot/stdout.expected
1652 cmp -s $testroot/stdout.expected $testroot/stdout
1653 ret=$?
1654 if [ $ret -ne 0 ]; then
1655 diff -u $testroot/stdout.expected $testroot/stdout
1656 test_done "$testroot" "$ret"
1657 return 1
1660 (cd $testroot/wt && got unstage -R >/dev/null)
1661 ret=$?
1662 if [ $ret -ne 0 ]; then
1663 echo "got stage command failed unexpectedly" >&2
1664 test_done "$testroot" "1"
1665 return 1
1667 (cd $testroot/wt && got status > $testroot/stdout)
1668 echo "M numbers" > $testroot/stdout.expected
1669 cmp -s $testroot/stdout.expected $testroot/stdout
1670 ret=$?
1671 if [ $ret -ne 0 ]; then
1672 diff -u $testroot/stdout.expected $testroot/stdout
1673 test_done "$testroot" "$ret"
1674 return 1
1677 # stage last hunk
1678 printf "n\nn\ny\n" > $testroot/patchscript
1679 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1680 numbers > $testroot/stdout)
1682 cat > $testroot/stdout.expected <<EOF
1683 -----------------------------------------------
1684 @@ -1,5 +1,5 @@
1691 -----------------------------------------------
1692 M numbers (change 1 of 3)
1693 stage this change? [y/n/q] n
1694 -----------------------------------------------
1695 @@ -4,7 +4,7 @@
1704 -----------------------------------------------
1705 M numbers (change 2 of 3)
1706 stage this change? [y/n/q] n
1707 -----------------------------------------------
1708 @@ -13,4 +13,4 @@
1712 -16
1714 -----------------------------------------------
1715 M numbers (change 3 of 3)
1716 stage this change? [y/n/q] y
1717 EOF
1718 cmp -s $testroot/stdout.expected $testroot/stdout
1719 ret=$?
1720 if [ $ret -ne 0 ]; then
1721 diff -u $testroot/stdout.expected $testroot/stdout
1722 test_done "$testroot" "$ret"
1723 return 1
1726 (cd $testroot/wt && got status > $testroot/stdout)
1727 echo "MM numbers" > $testroot/stdout.expected
1728 cmp -s $testroot/stdout.expected $testroot/stdout
1729 ret=$?
1730 if [ $ret -ne 0 ]; then
1731 diff -u $testroot/stdout.expected $testroot/stdout
1732 test_done "$testroot" "$ret"
1733 return 1
1736 (cd $testroot/wt && got diff -s > $testroot/stdout)
1738 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1739 echo "commit - $commit_id" >> $testroot/stdout.expected
1740 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1741 echo -n 'blob - ' >> $testroot/stdout.expected
1742 got tree -r $testroot/repo -i -c $commit_id \
1743 | grep 'numbers$' | cut -d' ' -f 1 \
1744 >> $testroot/stdout.expected
1745 echo -n 'blob + ' >> $testroot/stdout.expected
1746 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1747 >> $testroot/stdout.expected
1748 echo "--- numbers" >> $testroot/stdout.expected
1749 echo "+++ numbers" >> $testroot/stdout.expected
1750 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1751 echo " 13" >> $testroot/stdout.expected
1752 echo " 14" >> $testroot/stdout.expected
1753 echo " 15" >> $testroot/stdout.expected
1754 echo "-16" >> $testroot/stdout.expected
1755 echo "+c" >> $testroot/stdout.expected
1756 cmp -s $testroot/stdout.expected $testroot/stdout
1757 ret=$?
1758 if [ $ret -ne 0 ]; then
1759 diff -u $testroot/stdout.expected $testroot/stdout
1761 test_done "$testroot" "$ret"
1764 test_stage_patch_twice() {
1765 local testroot=`test_init stage_patch_twice`
1767 seq 16 > $testroot/repo/numbers
1768 git -C $testroot/repo add numbers
1769 git_commit $testroot/repo -m "added numbers file"
1770 local commit_id=`git_show_head $testroot/repo`
1772 got checkout $testroot/repo $testroot/wt > /dev/null
1773 ret=$?
1774 if [ $ret -ne 0 ]; then
1775 test_done "$testroot" "$ret"
1776 return 1
1779 ed -s $testroot/wt/numbers <<-\EOF
1780 ,s/^2$/a/
1781 ,s/^7$/b/
1782 ,s/^16$/c/
1784 EOF
1786 # stage middle hunk
1787 printf "n\ny\nn\n" > $testroot/patchscript
1788 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1789 numbers > $testroot/stdout)
1791 cat > $testroot/stdout.expected <<EOF
1792 -----------------------------------------------
1793 @@ -1,5 +1,5 @@
1800 -----------------------------------------------
1801 M numbers (change 1 of 3)
1802 stage this change? [y/n/q] n
1803 -----------------------------------------------
1804 @@ -4,7 +4,7 @@
1813 -----------------------------------------------
1814 M numbers (change 2 of 3)
1815 stage this change? [y/n/q] y
1816 -----------------------------------------------
1817 @@ -13,4 +13,4 @@
1821 -16
1823 -----------------------------------------------
1824 M numbers (change 3 of 3)
1825 stage this change? [y/n/q] n
1826 EOF
1827 cmp -s $testroot/stdout.expected $testroot/stdout
1828 ret=$?
1829 if [ $ret -ne 0 ]; then
1830 diff -u $testroot/stdout.expected $testroot/stdout
1831 test_done "$testroot" "$ret"
1832 return 1
1835 (cd $testroot/wt && got status > $testroot/stdout)
1836 echo "MM numbers" > $testroot/stdout.expected
1837 cmp -s $testroot/stdout.expected $testroot/stdout
1838 ret=$?
1839 if [ $ret -ne 0 ]; then
1840 diff -u $testroot/stdout.expected $testroot/stdout
1841 test_done "$testroot" "$ret"
1842 return 1
1845 # stage last hunk
1846 printf "n\ny\n" > $testroot/patchscript
1847 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1848 numbers > $testroot/stdout)
1850 cat > $testroot/stdout.expected <<EOF
1851 -----------------------------------------------
1852 @@ -1,5 +1,5 @@
1859 -----------------------------------------------
1860 M numbers (change 1 of 2)
1861 stage this change? [y/n/q] n
1862 -----------------------------------------------
1863 @@ -13,4 +13,4 @@ b
1867 -16
1869 -----------------------------------------------
1870 M numbers (change 2 of 2)
1871 stage this change? [y/n/q] y
1872 EOF
1873 cmp -s $testroot/stdout.expected $testroot/stdout
1874 ret=$?
1875 if [ $ret -ne 0 ]; then
1876 diff -u $testroot/stdout.expected $testroot/stdout
1877 test_done "$testroot" "$ret"
1878 return 1
1881 (cd $testroot/wt && got status > $testroot/stdout)
1882 echo "MM numbers" > $testroot/stdout.expected
1883 cmp -s $testroot/stdout.expected $testroot/stdout
1884 ret=$?
1885 if [ $ret -ne 0 ]; then
1886 diff -u $testroot/stdout.expected $testroot/stdout
1887 test_done "$testroot" "$ret"
1888 return 1
1891 (cd $testroot/wt && got diff -s > $testroot/stdout)
1893 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1894 echo "commit - $commit_id" >> $testroot/stdout.expected
1895 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1896 echo -n 'blob - ' >> $testroot/stdout.expected
1897 got tree -r $testroot/repo -i -c $commit_id \
1898 | grep 'numbers$' | cut -d' ' -f 1 \
1899 >> $testroot/stdout.expected
1900 echo -n 'blob + ' >> $testroot/stdout.expected
1901 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1902 >> $testroot/stdout.expected
1903 echo "--- numbers" >> $testroot/stdout.expected
1904 echo "+++ numbers" >> $testroot/stdout.expected
1905 cat >> $testroot/stdout.expected <<EOF
1906 @@ -4,7 +4,7 @@
1915 @@ -13,4 +13,4 @@
1919 -16
1921 EOF
1922 cmp -s $testroot/stdout.expected $testroot/stdout
1923 ret=$?
1924 if [ $ret -ne 0 ]; then
1925 diff -u $testroot/stdout.expected $testroot/stdout
1926 test_done "$testroot" "$ret"
1927 return 1
1930 (cd $testroot/wt && got diff > $testroot/stdout)
1932 echo "diff $testroot/wt" > $testroot/stdout.expected
1933 echo "commit - $commit_id" >> $testroot/stdout.expected
1934 echo "path + $testroot/wt" >> $testroot/stdout.expected
1935 echo -n 'blob - ' >> $testroot/stdout.expected
1936 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1937 tr -d '\n' >> $testroot/stdout.expected
1938 echo " (staged)" >> $testroot/stdout.expected
1939 echo 'file + numbers' >> $testroot/stdout.expected
1940 echo "--- numbers" >> $testroot/stdout.expected
1941 echo "+++ numbers" >> $testroot/stdout.expected
1942 cat >> $testroot/stdout.expected <<EOF
1943 @@ -1,5 +1,5 @@
1950 EOF
1951 cmp -s $testroot/stdout.expected $testroot/stdout
1952 ret=$?
1953 if [ $ret -ne 0 ]; then
1954 diff -u $testroot/stdout.expected $testroot/stdout
1956 test_done "$testroot" "$ret"
1959 test_stage_patch_added() {
1960 local testroot=`test_init stage_patch_added`
1961 local commit_id=`git_show_head $testroot/repo`
1963 got checkout $testroot/repo $testroot/wt > /dev/null
1964 ret=$?
1965 if [ $ret -ne 0 ]; then
1966 test_done "$testroot" "$ret"
1967 return 1
1970 echo "new" > $testroot/wt/epsilon/new
1971 (cd $testroot/wt && got add epsilon/new > /dev/null)
1973 printf "y\n" > $testroot/patchscript
1974 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1975 epsilon/new > $testroot/stdout)
1977 echo "A epsilon/new" > $testroot/stdout.expected
1978 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1979 cmp -s $testroot/stdout.expected $testroot/stdout
1980 ret=$?
1981 if [ $ret -ne 0 ]; then
1982 diff -u $testroot/stdout.expected $testroot/stdout
1983 test_done "$testroot" "$ret"
1984 return 1
1987 (cd $testroot/wt && got status > $testroot/stdout)
1988 echo " A epsilon/new" > $testroot/stdout.expected
1989 cmp -s $testroot/stdout.expected $testroot/stdout
1990 ret=$?
1991 if [ $ret -ne 0 ]; then
1992 diff -u $testroot/stdout.expected $testroot/stdout
1993 test_done "$testroot" "$ret"
1994 return 1
1997 (cd $testroot/wt && got diff -s > $testroot/stdout)
1999 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2000 echo "commit - $commit_id" >> $testroot/stdout.expected
2001 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2002 echo 'blob - /dev/null' >> $testroot/stdout.expected
2003 echo -n 'blob + ' >> $testroot/stdout.expected
2004 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
2005 >> $testroot/stdout.expected
2006 echo "--- /dev/null" >> $testroot/stdout.expected
2007 echo "+++ epsilon/new" >> $testroot/stdout.expected
2008 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
2009 echo "+new" >> $testroot/stdout.expected
2010 cmp -s $testroot/stdout.expected $testroot/stdout
2011 ret=$?
2012 if [ $ret -ne 0 ]; then
2013 diff -u $testroot/stdout.expected $testroot/stdout
2015 test_done "$testroot" "$ret"
2018 test_stage_patch_added_twice() {
2019 local testroot=`test_init stage_patch_added_twice`
2020 local commit_id=`git_show_head $testroot/repo`
2022 got checkout $testroot/repo $testroot/wt > /dev/null
2023 ret=$?
2024 if [ $ret -ne 0 ]; then
2025 test_done "$testroot" "$ret"
2026 return 1
2029 echo "new" > $testroot/wt/epsilon/new
2030 (cd $testroot/wt && got add epsilon/new > /dev/null)
2032 printf "y\n" > $testroot/patchscript
2033 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2034 epsilon/new > $testroot/stdout)
2036 echo "A epsilon/new" > $testroot/stdout.expected
2037 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
2038 cmp -s $testroot/stdout.expected $testroot/stdout
2039 ret=$?
2040 if [ $ret -ne 0 ]; then
2041 diff -u $testroot/stdout.expected $testroot/stdout
2042 test_done "$testroot" "$ret"
2043 return 1
2046 (cd $testroot/wt && got status > $testroot/stdout)
2047 echo " A epsilon/new" > $testroot/stdout.expected
2048 cmp -s $testroot/stdout.expected $testroot/stdout
2049 ret=$?
2050 if [ $ret -ne 0 ]; then
2051 diff -u $testroot/stdout.expected $testroot/stdout
2052 test_done "$testroot" "$ret"
2053 return 1
2056 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2057 epsilon/new > $testroot/stdout 2> $testroot/stderr)
2058 ret=$?
2059 if [ $ret -eq 0 ]; then
2060 echo "got stage command succeeded unexpectedly" >&2
2061 test_done "$testroot" "1"
2062 return 1
2065 echo "got: no changes to stage" > $testroot/stderr.expected
2066 cmp -s $testroot/stderr.expected $testroot/stderr
2067 ret=$?
2068 if [ $ret -ne 0 ]; then
2069 diff -u $testroot/stderr.expected $testroot/stderr
2070 test_done "$testroot" "$ret"
2071 return 1
2074 echo -n > $testroot/stdout.expected
2075 cmp -s $testroot/stdout.expected $testroot/stdout
2076 ret=$?
2077 if [ $ret -ne 0 ]; then
2078 diff -u $testroot/stdout.expected $testroot/stdout
2080 test_done "$testroot" "$ret"
2083 test_stage_patch_removed() {
2084 local testroot=`test_init stage_patch_removed`
2085 local commit_id=`git_show_head $testroot/repo`
2087 got checkout $testroot/repo $testroot/wt > /dev/null
2088 ret=$?
2089 if [ $ret -ne 0 ]; then
2090 test_done "$testroot" "$ret"
2091 return 1
2094 (cd $testroot/wt && got rm beta > /dev/null)
2096 printf "y\n" > $testroot/patchscript
2097 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2098 beta > $testroot/stdout)
2100 echo -n > $testroot/stdout.expected
2102 echo "D beta" > $testroot/stdout.expected
2103 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2104 cmp -s $testroot/stdout.expected $testroot/stdout
2105 ret=$?
2106 if [ $ret -ne 0 ]; then
2107 diff -u $testroot/stdout.expected $testroot/stdout
2108 test_done "$testroot" "$ret"
2109 return 1
2112 (cd $testroot/wt && got status > $testroot/stdout)
2113 echo " D beta" > $testroot/stdout.expected
2114 cmp -s $testroot/stdout.expected $testroot/stdout
2115 ret=$?
2116 if [ $ret -ne 0 ]; then
2117 diff -u $testroot/stdout.expected $testroot/stdout
2118 test_done "$testroot" "$ret"
2119 return 1
2122 (cd $testroot/wt && got diff -s > $testroot/stdout)
2124 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2125 echo "commit - $commit_id" >> $testroot/stdout.expected
2126 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2127 echo -n 'blob - ' >> $testroot/stdout.expected
2128 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2129 >> $testroot/stdout.expected
2130 echo 'blob + /dev/null' >> $testroot/stdout.expected
2131 echo "--- beta" >> $testroot/stdout.expected
2132 echo "+++ /dev/null" >> $testroot/stdout.expected
2133 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2134 echo "-beta" >> $testroot/stdout.expected
2135 cmp -s $testroot/stdout.expected $testroot/stdout
2136 ret=$?
2137 if [ $ret -ne 0 ]; then
2138 diff -u $testroot/stdout.expected $testroot/stdout
2140 test_done "$testroot" "$ret"
2143 test_stage_patch_removed_twice() {
2144 local testroot=`test_init stage_patch_removed_twice`
2145 local commit_id=`git_show_head $testroot/repo`
2147 got checkout $testroot/repo $testroot/wt > /dev/null
2148 ret=$?
2149 if [ $ret -ne 0 ]; then
2150 test_done "$testroot" "$ret"
2151 return 1
2154 (cd $testroot/wt && got rm beta > /dev/null)
2156 printf "y\n" > $testroot/patchscript
2157 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2158 beta > $testroot/stdout)
2160 echo -n > $testroot/stdout.expected
2162 echo "D beta" > $testroot/stdout.expected
2163 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2164 cmp -s $testroot/stdout.expected $testroot/stdout
2165 ret=$?
2166 if [ $ret -ne 0 ]; then
2167 diff -u $testroot/stdout.expected $testroot/stdout
2168 test_done "$testroot" "$ret"
2169 return 1
2172 (cd $testroot/wt && got status > $testroot/stdout)
2173 echo " D beta" > $testroot/stdout.expected
2174 cmp -s $testroot/stdout.expected $testroot/stdout
2175 ret=$?
2176 if [ $ret -ne 0 ]; then
2177 diff -u $testroot/stdout.expected $testroot/stdout
2178 test_done "$testroot" "$ret"
2179 return 1
2182 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2183 > $testroot/stdout 2> $testroot/stderr)
2184 ret=$?
2185 if [ $ret -eq 0 ]; then
2186 echo "got stage command succeeded unexpectedly" >&2
2187 test_done "$testroot" "1"
2188 return 1
2191 echo "got: no changes to stage" > $testroot/stderr.expected
2192 cmp -s $testroot/stderr.expected $testroot/stderr
2193 ret=$?
2194 if [ $ret -ne 0 ]; then
2195 diff -u $testroot/stderr.expected $testroot/stderr
2196 test_done "$testroot" "$ret"
2197 return 1
2200 echo -n > $testroot/stdout.expected
2201 cmp -s $testroot/stdout.expected $testroot/stdout
2202 ret=$?
2203 if [ $ret -ne 0 ]; then
2204 diff -u $testroot/stdout.expected $testroot/stdout
2206 test_done "$testroot" "$ret"
2209 test_stage_patch_reversed() {
2210 local testroot=`test_init stage_patch_reversed`
2212 got checkout $testroot/repo $testroot/wt > /dev/null
2213 ret=$?
2214 if [ $ret -ne 0 ]; then
2215 test_done "$testroot" "$ret"
2216 return 1
2219 echo 'ALPHA' > $testroot/wt/alpha
2220 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2221 ret=$?
2222 if [ $ret -ne 0 ]; then
2223 test_done "$testroot" "$ret"
2224 return 1
2227 echo ' M alpha' > $testroot/stdout.expected
2228 cmp -s $testroot/stdout.expected $testroot/stdout
2229 ret=$?
2230 if [ $ret -ne 0 ]; then
2231 diff -u $testroot/stdout.expected $testroot/stdout
2232 test_done "$testroot" "$ret"
2233 return 1
2236 echo 'alpha' > $testroot/wt/alpha
2237 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2238 ret=$?
2239 if [ $ret -ne 0 ]; then
2240 test_done "$testroot" "$ret"
2241 return 1
2244 echo ' M alpha' > $testroot/stdout.expected
2245 cmp -s $testroot/stdout.expected $testroot/stdout
2246 ret=$?
2247 if [ $ret -ne 0 ]; then
2248 diff -u $testroot/stdout.expected $testroot/stdout
2249 test_done "$testroot" "$ret"
2250 return 1
2253 (cd $testroot/wt && got status > $testroot/stdout)
2254 cmp -s /dev/null $testroot/stdout
2255 ret=$?
2256 if [ $ret -ne 0 ]; then
2257 diff -u /dev/null $testroot/stdout
2259 test_done "$testroot" "$ret"
2262 test_stage_patch_quit() {
2263 local testroot=`test_init stage_patch_quit`
2265 seq 16 > $testroot/repo/numbers
2266 echo zzz > $testroot/repo/zzz
2267 git -C $testroot/repo add numbers zzz
2268 git_commit $testroot/repo -m "added files"
2269 local commit_id=`git_show_head $testroot/repo`
2271 got checkout $testroot/repo $testroot/wt > /dev/null
2272 ret=$?
2273 if [ $ret -ne 0 ]; then
2274 test_done "$testroot" "$ret"
2275 return 1
2278 ed -s $testroot/wt/numbers <<-\EOF
2279 ,s/^2$/a/
2280 ,s/^7$/b/
2281 ,s/^16$/c/
2283 EOF
2284 (cd $testroot/wt && got rm zzz > /dev/null)
2286 # stage first hunk and quit; and don't pass a path argument to
2287 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2288 printf "y\nq\nn\n" > $testroot/patchscript
2289 (cd $testroot/wt && got stage -R -F $testroot/patchscript -p \
2290 > $testroot/stdout)
2291 ret=$?
2292 if [ $ret -ne 0 ]; then
2293 echo "got stage command failed unexpectedly" >&2
2294 test_done "$testroot" "1"
2295 return 1
2297 cat > $testroot/stdout.expected <<EOF
2298 -----------------------------------------------
2299 @@ -1,5 +1,5 @@
2306 -----------------------------------------------
2307 M numbers (change 1 of 3)
2308 stage this change? [y/n/q] y
2309 -----------------------------------------------
2310 @@ -4,7 +4,7 @@
2319 -----------------------------------------------
2320 M numbers (change 2 of 3)
2321 stage this change? [y/n/q] q
2322 D zzz
2323 stage this deletion? [y/n] n
2324 EOF
2325 cmp -s $testroot/stdout.expected $testroot/stdout
2326 ret=$?
2327 if [ $ret -ne 0 ]; then
2328 diff -u $testroot/stdout.expected $testroot/stdout
2329 test_done "$testroot" "$ret"
2330 return 1
2333 (cd $testroot/wt && got status > $testroot/stdout)
2334 echo "MM numbers" > $testroot/stdout.expected
2335 echo "D zzz" >> $testroot/stdout.expected
2336 cmp -s $testroot/stdout.expected $testroot/stdout
2337 ret=$?
2338 if [ $ret -ne 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)
2346 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2347 echo "commit - $commit_id" >> $testroot/stdout.expected
2348 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2349 echo -n 'blob - ' >> $testroot/stdout.expected
2350 got tree -r $testroot/repo -i -c $commit_id \
2351 | grep 'numbers$' | cut -d' ' -f 1 \
2352 >> $testroot/stdout.expected
2353 echo -n 'blob + ' >> $testroot/stdout.expected
2354 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2355 >> $testroot/stdout.expected
2356 echo "--- numbers" >> $testroot/stdout.expected
2357 echo "+++ numbers" >> $testroot/stdout.expected
2358 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2359 echo " 1" >> $testroot/stdout.expected
2360 echo "-2" >> $testroot/stdout.expected
2361 echo "+a" >> $testroot/stdout.expected
2362 echo " 3" >> $testroot/stdout.expected
2363 echo " 4" >> $testroot/stdout.expected
2364 echo " 5" >> $testroot/stdout.expected
2365 cmp -s $testroot/stdout.expected $testroot/stdout
2366 ret=$?
2367 if [ $ret -ne 0 ]; then
2368 diff -u $testroot/stdout.expected $testroot/stdout
2370 test_done "$testroot" "$ret"
2374 test_stage_patch_incomplete_script() {
2375 local testroot=`test_init stage_incomplete_script`
2377 seq 16 > $testroot/repo/numbers
2378 echo zzz > $testroot/repo/zzz
2379 git -C $testroot/repo add numbers zzz
2380 git_commit $testroot/repo -m "added files"
2381 local commit_id=`git_show_head $testroot/repo`
2383 got checkout $testroot/repo $testroot/wt > /dev/null
2384 ret=$?
2385 if [ $ret -ne 0 ]; then
2386 test_done "$testroot" "$ret"
2387 return 1
2390 ed -s $testroot/wt/numbers <<-\EOF
2391 ,s/^2$/a/
2392 ,s/^7$/b/
2393 ,s/^16$/c/
2395 EOF
2397 # stage first hunk and then stop responding; got should error out
2398 printf "y\n" > $testroot/patchscript
2399 (cd $testroot/wt && got stage -R -F $testroot/patchscript -p \
2400 > $testroot/stdout 2> $testroot/stderr)
2401 ret=$?
2402 if [ $ret -eq 0 ]; then
2403 echo "got stage command succeeded unexpectedly" >&2
2404 test_done "$testroot" "1"
2405 return 1
2407 cat > $testroot/stdout.expected <<EOF
2408 -----------------------------------------------
2409 @@ -1,5 +1,5 @@
2416 -----------------------------------------------
2417 M numbers (change 1 of 3)
2418 stage this change? [y/n/q] y
2419 -----------------------------------------------
2420 @@ -4,7 +4,7 @@
2429 -----------------------------------------------
2430 M numbers (change 2 of 3)
2431 EOF
2432 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2433 echo "got: invalid patch choice" > $testroot/stderr.expected
2434 cmp -s $testroot/stderr.expected $testroot/stderr
2435 ret=$?
2436 if [ $ret -ne 0 ]; then
2437 diff -u $testroot/stderr.expected $testroot/stderr
2438 test_done "$testroot" "$ret"
2439 return 1
2442 cmp -s $testroot/stdout.expected $testroot/stdout
2443 ret=$?
2444 if [ $ret -ne 0 ]; then
2445 diff -u $testroot/stdout.expected $testroot/stdout
2446 test_done "$testroot" "$ret"
2447 return 1
2450 (cd $testroot/wt && got status > $testroot/stdout)
2451 echo "M numbers" > $testroot/stdout.expected
2452 cmp -s $testroot/stdout.expected $testroot/stdout
2453 ret=$?
2454 if [ $ret -ne 0 ]; then
2455 diff -u $testroot/stdout.expected $testroot/stdout
2456 test_done "$testroot" "$ret"
2457 return 1
2460 (cd $testroot/wt && got diff -s > $testroot/stdout)
2461 echo -n > $testroot/stdout.expected
2462 cmp -s $testroot/stdout.expected $testroot/stdout
2463 ret=$?
2464 if [ $ret -ne 0 ]; then
2465 diff -u $testroot/stdout.expected $testroot/stdout
2467 test_done "$testroot" "$ret"
2471 test_stage_symlink() {
2472 local testroot=`test_init stage_symlink`
2474 (cd $testroot/repo && ln -s alpha alpha.link)
2475 (cd $testroot/repo && ln -s epsilon epsilon.link)
2476 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2477 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2478 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2479 git -C $testroot/repo add .
2480 git_commit $testroot/repo -m "add symlinks"
2481 local head_commit=`git_show_head $testroot/repo`
2483 got checkout $testroot/repo $testroot/wt > /dev/null
2484 ret=$?
2485 if [ $ret -ne 0 ]; then
2486 test_done "$testroot" "$ret"
2487 return 1
2490 (cd $testroot/wt && ln -sf beta alpha.link)
2491 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
2492 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2493 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2494 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2495 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2496 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2497 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2498 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2499 (cd $testroot/wt && got add zeta.link > /dev/null)
2501 (cd $testroot/wt && got stage -R > $testroot/stdout 2> $testroot/stderr)
2502 ret=$?
2503 if [ $ret -eq 0 ]; then
2504 echo "got stage succeeded unexpectedly" >&2
2505 test_done "$testroot" 1
2506 return 1
2508 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
2509 echo "symbolic link points outside of paths under version control" \
2510 >> $testroot/stderr.expected
2511 cmp -s $testroot/stderr.expected $testroot/stderr
2512 ret=$?
2513 if [ $ret -ne 0 ]; then
2514 diff -u $testroot/stderr.expected $testroot/stderr
2515 test_done "$testroot" "$ret"
2516 return 1
2519 (cd $testroot/wt && got stage -RS > $testroot/stdout)
2521 cat > $testroot/stdout.expected <<EOF
2522 M alpha.link
2523 A dotgotbar.link
2524 A dotgotfoo.link
2525 M epsilon/beta.link
2526 M epsilon.link
2527 D nonexistent.link
2528 A zeta.link
2529 EOF
2530 cmp -s $testroot/stdout.expected $testroot/stdout
2531 ret=$?
2532 if [ $ret -ne 0 ]; then
2533 diff -u $testroot/stdout.expected $testroot/stdout
2534 test_done "$testroot" "$ret"
2535 return 1
2538 rm $testroot/wt/alpha.link
2539 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2541 (cd $testroot/wt && got diff -s > $testroot/stdout)
2543 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2544 echo "commit - $head_commit" >> $testroot/stdout.expected
2545 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2546 echo -n 'blob - ' >> $testroot/stdout.expected
2547 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2548 cut -d' ' -f 1 >> $testroot/stdout.expected
2549 echo -n 'blob + ' >> $testroot/stdout.expected
2550 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2551 >> $testroot/stdout.expected
2552 echo '--- alpha.link' >> $testroot/stdout.expected
2553 echo '+++ alpha.link' >> $testroot/stdout.expected
2554 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2555 echo '-alpha' >> $testroot/stdout.expected
2556 echo '\ No newline at end of file' >> $testroot/stdout.expected
2557 echo '+beta' >> $testroot/stdout.expected
2558 echo '\ No newline at end of file' >> $testroot/stdout.expected
2559 echo 'blob - /dev/null' >> $testroot/stdout.expected
2560 echo -n 'blob + ' >> $testroot/stdout.expected
2561 (cd $testroot/wt && got stage -l dotgotbar.link) | cut -d' ' -f 1 \
2562 >> $testroot/stdout.expected
2563 echo '--- /dev/null' >> $testroot/stdout.expected
2564 echo '+++ dotgotbar.link' >> $testroot/stdout.expected
2565 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2566 echo '+.got/bar' >> $testroot/stdout.expected
2567 echo '\ No newline at end of file' >> $testroot/stdout.expected
2568 echo 'blob - /dev/null' >> $testroot/stdout.expected
2569 echo -n 'blob + ' >> $testroot/stdout.expected
2570 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2571 >> $testroot/stdout.expected
2572 echo '--- /dev/null' >> $testroot/stdout.expected
2573 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2574 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2575 echo '+this is regular file foo' >> $testroot/stdout.expected
2576 echo -n 'blob - ' >> $testroot/stdout.expected
2577 got tree -r $testroot/repo -i epsilon | grep 'beta.link@ -> ../beta$' | \
2578 cut -d' ' -f 1 >> $testroot/stdout.expected
2579 echo -n 'blob + ' >> $testroot/stdout.expected
2580 (cd $testroot/wt && got stage -l epsilon/beta.link) | cut -d' ' -f 1 \
2581 >> $testroot/stdout.expected
2582 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
2583 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
2584 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2585 echo '-../beta' >> $testroot/stdout.expected
2586 echo '\ No newline at end of file' >> $testroot/stdout.expected
2587 echo '+../gamma/delta' >> $testroot/stdout.expected
2588 echo '\ No newline at end of file' >> $testroot/stdout.expected
2589 echo -n 'blob - ' >> $testroot/stdout.expected
2590 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2591 cut -d' ' -f 1 >> $testroot/stdout.expected
2592 echo -n 'blob + ' >> $testroot/stdout.expected
2593 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2594 >> $testroot/stdout.expected
2595 echo '--- epsilon.link' >> $testroot/stdout.expected
2596 echo '+++ epsilon.link' >> $testroot/stdout.expected
2597 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2598 echo '-epsilon' >> $testroot/stdout.expected
2599 echo '\ No newline at end of file' >> $testroot/stdout.expected
2600 echo '+gamma' >> $testroot/stdout.expected
2601 echo '\ No newline at end of file' >> $testroot/stdout.expected
2602 echo -n 'blob - ' >> $testroot/stdout.expected
2603 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2604 cut -d' ' -f 1 >> $testroot/stdout.expected
2605 echo 'blob + /dev/null' >> $testroot/stdout.expected
2606 echo '--- nonexistent.link' >> $testroot/stdout.expected
2607 echo '+++ /dev/null' >> $testroot/stdout.expected
2608 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2609 echo '-nonexistent' >> $testroot/stdout.expected
2610 echo '\ No newline at end of file' >> $testroot/stdout.expected
2611 echo 'blob - /dev/null' >> $testroot/stdout.expected
2612 echo -n 'blob + ' >> $testroot/stdout.expected
2613 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2614 >> $testroot/stdout.expected
2615 echo '--- /dev/null' >> $testroot/stdout.expected
2616 echo '+++ zeta.link' >> $testroot/stdout.expected
2617 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2618 echo '+gamma/delta' >> $testroot/stdout.expected
2619 echo '\ No newline at end of file' >> $testroot/stdout.expected
2621 cmp -s $testroot/stdout.expected $testroot/stdout
2622 ret=$?
2623 if [ $ret -ne 0 ]; then
2624 diff -u $testroot/stdout.expected $testroot/stdout
2625 test_done "$testroot" "$ret"
2626 return 1
2629 (cd $testroot/wt && got commit -m "staged symlink" \
2630 > $testroot/stdout)
2631 ret=$?
2632 if [ $ret -ne 0 ]; then
2633 echo "got commit command failed unexpectedly" >&2
2634 test_done "$testroot" "1"
2635 return 1
2638 local commit_id=`git_show_head $testroot/repo`
2639 echo "A dotgotbar.link" > $testroot/stdout.expected
2640 echo "A dotgotfoo.link" >> $testroot/stdout.expected
2641 echo "A zeta.link" >> $testroot/stdout.expected
2642 echo "M alpha.link" >> $testroot/stdout.expected
2643 echo "M epsilon/beta.link" >> $testroot/stdout.expected
2644 echo "M epsilon.link" >> $testroot/stdout.expected
2645 echo "D nonexistent.link" >> $testroot/stdout.expected
2646 echo "Created commit $commit_id" >> $testroot/stdout.expected
2647 cmp -s $testroot/stdout.expected $testroot/stdout
2648 ret=$?
2649 if [ $ret -ne 0 ]; then
2650 diff -u $testroot/stdout.expected $testroot/stdout
2651 test_done "$testroot" "$ret"
2652 return 1
2655 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2656 ret=$?
2657 if [ $ret -ne 0 ]; then
2658 echo "got tree command failed unexpectedly" >&2
2659 test_done "$testroot" "1"
2660 return 1
2663 cat > $testroot/stdout.expected <<EOF
2664 alpha
2665 alpha.link@ -> beta
2666 beta
2667 dotgotbar.link@ -> .got/bar
2668 dotgotfoo.link
2669 epsilon/
2670 epsilon.link@ -> gamma
2671 gamma/
2672 passwd.link@ -> /etc/passwd
2673 zeta.link@ -> gamma/delta
2674 EOF
2675 cmp -s $testroot/stdout.expected $testroot/stdout
2676 ret=$?
2677 if [ $ret -ne 0 ]; then
2678 diff -u $testroot/stdout.expected $testroot/stdout
2679 return 1
2682 if [ -h $testroot/wt/alpha.link ]; then
2683 echo "alpha.link is a symlink"
2684 test_done "$testroot" "1"
2685 return 1
2688 echo 'this is regular file alpha.link' > $testroot/content.expected
2689 cp $testroot/wt/alpha.link $testroot/content
2690 cmp -s $testroot/content.expected $testroot/content
2691 ret=$?
2692 if [ $ret -ne 0 ]; then
2693 diff -u $testroot/content.expected $testroot/content
2694 test_done "$testroot" "$ret"
2695 return 1
2698 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2699 echo "dotgotbar.link is not a symlink"
2700 test_done "$testroot" "1"
2701 return 1
2703 (cd $testroot/wt && got update > /dev/null)
2704 if [ -h $testroot/wt/dotgotbar.link ]; then
2705 echo "dotgotbar.link is a symlink"
2706 test_done "$testroot" "1"
2707 return 1
2709 echo -n ".got/bar" > $testroot/content.expected
2710 cp $testroot/wt/dotgotbar.link $testroot/content
2711 cmp -s $testroot/content.expected $testroot/content
2712 ret=$?
2713 if [ $ret -ne 0 ]; then
2714 diff -u $testroot/content.expected $testroot/content
2715 test_done "$testroot" "$ret"
2716 return 1
2719 if [ -h $testroot/wt/dotgotfoo.link ]; then
2720 echo "dotgotfoo.link is a symlink"
2721 test_done "$testroot" "1"
2722 return 1
2724 echo "this is regular file foo" > $testroot/content.expected
2725 cp $testroot/wt/dotgotfoo.link $testroot/content
2726 cmp -s $testroot/content.expected $testroot/content
2727 ret=$?
2728 if [ $ret -ne 0 ]; then
2729 diff -u $testroot/content.expected $testroot/content
2730 test_done "$testroot" "$ret"
2731 return 1
2734 if ! [ -h $testroot/wt/epsilon.link ]; then
2735 echo "epsilon.link is not a symlink"
2736 test_done "$testroot" "1"
2737 return 1
2740 readlink $testroot/wt/epsilon.link > $testroot/stdout
2741 echo "gamma" > $testroot/stdout.expected
2742 cmp -s $testroot/stdout.expected $testroot/stdout
2743 ret=$?
2744 if [ $ret -ne 0 ]; then
2745 diff -u $testroot/stdout.expected $testroot/stdout
2746 test_done "$testroot" "$ret"
2747 return 1
2750 if [ -h $testroot/wt/passwd.link ]; then
2751 echo "passwd.link is a symlink"
2752 test_done "$testroot" "1"
2753 return 1
2755 echo -n "/etc/passwd" > $testroot/content.expected
2756 cp $testroot/wt/passwd.link $testroot/content
2757 cmp -s $testroot/content.expected $testroot/content
2758 ret=$?
2759 if [ $ret -ne 0 ]; then
2760 diff -u $testroot/content.expected $testroot/content
2761 test_done "$testroot" "$ret"
2762 return 1
2765 if ! [ -h $testroot/wt/zeta.link ]; then
2766 echo "zeta.link is not a symlink"
2767 test_done "$testroot" "1"
2768 return 1
2771 readlink $testroot/wt/zeta.link > $testroot/stdout
2772 echo "gamma/delta" > $testroot/stdout.expected
2773 cmp -s $testroot/stdout.expected $testroot/stdout
2774 ret=$?
2775 if [ $ret -ne 0 ]; then
2776 diff -u $testroot/stdout.expected $testroot/stdout
2777 test_done "$testroot" "$ret"
2778 return 1
2781 test_done "$testroot" "0"
2784 test_stage_patch_symlink() {
2785 local testroot=`test_init stage_patch_symlink`
2787 (cd $testroot/repo && ln -s alpha alpha.link)
2788 (cd $testroot/repo && ln -s epsilon epsilon.link)
2789 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2790 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2791 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2792 git -C $testroot/repo add .
2793 git_commit $testroot/repo -m "add symlinks"
2794 local head_commit=`git_show_head $testroot/repo`
2796 got checkout $testroot/repo $testroot/wt > /dev/null
2797 ret=$?
2798 if [ $ret -ne 0 ]; then
2799 test_done "$testroot" "$ret"
2800 return 1
2803 (cd $testroot/wt && ln -sf beta alpha.link)
2804 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
2805 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2806 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2807 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2808 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2809 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2810 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2811 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2812 (cd $testroot/wt && got add zeta.link > /dev/null)
2814 printf "y\nn\ny\nn\ny\ny\ny" > $testroot/patchscript
2815 (cd $testroot/wt && got stage -R -F $testroot/patchscript -p \
2816 > $testroot/stdout)
2818 cat > $testroot/stdout.expected <<EOF
2819 -----------------------------------------------
2820 @@ -1 +1 @@
2821 -alpha
2822 \ No newline at end of file
2823 +beta
2824 \ No newline at end of file
2825 -----------------------------------------------
2826 M alpha.link (change 1 of 1)
2827 stage this change? [y/n/q] y
2828 A dotgotbar.link
2829 stage this addition? [y/n] n
2830 A dotgotfoo.link
2831 stage this addition? [y/n] y
2832 -----------------------------------------------
2833 @@ -1 +1 @@
2834 -../beta
2835 \ No newline at end of file
2836 +../gamma/delta
2837 \ No newline at end of file
2838 -----------------------------------------------
2839 M epsilon/beta.link (change 1 of 1)
2840 stage this change? [y/n/q] n
2841 -----------------------------------------------
2842 @@ -1 +1 @@
2843 -epsilon
2844 \ No newline at end of file
2845 +gamma
2846 \ No newline at end of file
2847 -----------------------------------------------
2848 M epsilon.link (change 1 of 1)
2849 stage this change? [y/n/q] y
2850 D nonexistent.link
2851 stage this deletion? [y/n] y
2852 A zeta.link
2853 stage this addition? [y/n] y
2854 EOF
2855 cmp -s $testroot/stdout.expected $testroot/stdout
2856 ret=$?
2857 if [ $ret -ne 0 ]; then
2858 diff -u $testroot/stdout.expected $testroot/stdout
2859 test_done "$testroot" "$ret"
2860 return 1
2863 rm $testroot/wt/alpha.link
2864 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2866 (cd $testroot/wt && got diff -s > $testroot/stdout)
2868 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2869 echo "commit - $head_commit" >> $testroot/stdout.expected
2870 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2871 echo -n 'blob - ' >> $testroot/stdout.expected
2872 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2873 cut -d' ' -f 1 >> $testroot/stdout.expected
2874 echo -n 'blob + ' >> $testroot/stdout.expected
2875 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2876 >> $testroot/stdout.expected
2877 echo '--- alpha.link' >> $testroot/stdout.expected
2878 echo '+++ alpha.link' >> $testroot/stdout.expected
2879 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2880 echo '-alpha' >> $testroot/stdout.expected
2881 echo '\ No newline at end of file' >> $testroot/stdout.expected
2882 echo '+beta' >> $testroot/stdout.expected
2883 echo '\ No newline at end of file' >> $testroot/stdout.expected
2884 echo 'blob - /dev/null' >> $testroot/stdout.expected
2885 echo -n 'blob + ' >> $testroot/stdout.expected
2886 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2887 >> $testroot/stdout.expected
2888 echo '--- /dev/null' >> $testroot/stdout.expected
2889 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2890 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2891 echo '+this is regular file foo' >> $testroot/stdout.expected
2892 echo -n 'blob - ' >> $testroot/stdout.expected
2893 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2894 cut -d' ' -f 1 >> $testroot/stdout.expected
2895 echo -n 'blob + ' >> $testroot/stdout.expected
2896 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2897 >> $testroot/stdout.expected
2898 echo '--- epsilon.link' >> $testroot/stdout.expected
2899 echo '+++ epsilon.link' >> $testroot/stdout.expected
2900 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2901 echo '-epsilon' >> $testroot/stdout.expected
2902 echo '\ No newline at end of file' >> $testroot/stdout.expected
2903 echo '+gamma' >> $testroot/stdout.expected
2904 echo '\ No newline at end of file' >> $testroot/stdout.expected
2905 echo -n 'blob - ' >> $testroot/stdout.expected
2906 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2907 cut -d' ' -f 1 >> $testroot/stdout.expected
2908 echo 'blob + /dev/null' >> $testroot/stdout.expected
2909 echo '--- nonexistent.link' >> $testroot/stdout.expected
2910 echo '+++ /dev/null' >> $testroot/stdout.expected
2911 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2912 echo '-nonexistent' >> $testroot/stdout.expected
2913 echo '\ No newline at end of file' >> $testroot/stdout.expected
2914 echo 'blob - /dev/null' >> $testroot/stdout.expected
2915 echo -n 'blob + ' >> $testroot/stdout.expected
2916 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2917 >> $testroot/stdout.expected
2918 echo '--- /dev/null' >> $testroot/stdout.expected
2919 echo '+++ zeta.link' >> $testroot/stdout.expected
2920 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2921 echo '+gamma/delta' >> $testroot/stdout.expected
2922 echo '\ No newline at end of file' >> $testroot/stdout.expected
2924 cmp -s $testroot/stdout.expected $testroot/stdout
2925 ret=$?
2926 if [ $ret -ne 0 ]; then
2927 diff -u $testroot/stdout.expected $testroot/stdout
2928 test_done "$testroot" "$ret"
2929 return 1
2932 (cd $testroot/wt && got commit -m "staged symlink" \
2933 > $testroot/stdout)
2934 ret=$?
2935 if [ $ret -ne 0 ]; then
2936 echo "got commit command failed unexpectedly" >&2
2937 test_done "$testroot" "1"
2938 return 1
2941 local commit_id=`git_show_head $testroot/repo`
2942 echo "A dotgotfoo.link" > $testroot/stdout.expected
2943 echo "A zeta.link" >> $testroot/stdout.expected
2944 echo "M alpha.link" >> $testroot/stdout.expected
2945 echo "M epsilon.link" >> $testroot/stdout.expected
2946 echo "D nonexistent.link" >> $testroot/stdout.expected
2947 echo "Created commit $commit_id" >> $testroot/stdout.expected
2948 cmp -s $testroot/stdout.expected $testroot/stdout
2949 ret=$?
2950 if [ $ret -ne 0 ]; then
2951 diff -u $testroot/stdout.expected $testroot/stdout
2952 test_done "$testroot" "$ret"
2953 return 1
2956 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2957 ret=$?
2958 if [ $ret -ne 0 ]; then
2959 echo "got tree command failed unexpectedly" >&2
2960 test_done "$testroot" "1"
2961 return 1
2964 cat > $testroot/stdout.expected <<EOF
2965 alpha
2966 alpha.link@ -> beta
2967 beta
2968 dotgotfoo.link
2969 epsilon/
2970 epsilon.link@ -> gamma
2971 gamma/
2972 passwd.link@ -> /etc/passwd
2973 zeta.link@ -> gamma/delta
2974 EOF
2975 cmp -s $testroot/stdout.expected $testroot/stdout
2976 ret=$?
2977 if [ $ret -ne 0 ]; then
2978 diff -u $testroot/stdout.expected $testroot/stdout
2979 return 1
2982 if [ -h $testroot/wt/alpha.link ]; then
2983 echo "alpha.link is a symlink"
2984 test_done "$testroot" "1"
2985 return 1
2988 echo 'this is regular file alpha.link' > $testroot/content.expected
2989 cp $testroot/wt/alpha.link $testroot/content
2990 cmp -s $testroot/content.expected $testroot/content
2991 ret=$?
2992 if [ $ret -ne 0 ]; then
2993 diff -u $testroot/content.expected $testroot/content
2994 test_done "$testroot" "$ret"
2995 return 1
2998 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2999 echo "dotgotbar.link is not a symlink"
3000 test_done "$testroot" "1"
3001 return 1
3003 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
3004 echo ".got/bar" > $testroot/stdout.expected
3005 cmp -s $testroot/stdout.expected $testroot/stdout
3006 ret=$?
3007 if [ $ret -ne 0 ]; then
3008 diff -u $testroot/stdout.expected $testroot/stdout
3009 test_done "$testroot" "$ret"
3010 return 1
3013 if [ -h $testroot/wt/dotgotfoo.link ]; then
3014 echo "dotgotfoo.link is a symlink"
3015 test_done "$testroot" "1"
3016 return 1
3018 echo "this is regular file foo" > $testroot/content.expected
3019 cp $testroot/wt/dotgotfoo.link $testroot/content
3020 cmp -s $testroot/content.expected $testroot/content
3021 ret=$?
3022 if [ $ret -ne 0 ]; then
3023 diff -u $testroot/content.expected $testroot/content
3024 test_done "$testroot" "$ret"
3025 return 1
3028 if ! [ -h $testroot/wt/epsilon.link ]; then
3029 echo "epsilon.link is not a symlink"
3030 test_done "$testroot" "1"
3031 return 1
3034 readlink $testroot/wt/epsilon.link > $testroot/stdout
3035 echo "gamma" > $testroot/stdout.expected
3036 cmp -s $testroot/stdout.expected $testroot/stdout
3037 ret=$?
3038 if [ $ret -ne 0 ]; then
3039 diff -u $testroot/stdout.expected $testroot/stdout
3040 test_done "$testroot" "$ret"
3041 return 1
3044 if [ -h $testroot/wt/passwd.link ]; then
3045 echo "passwd.link is a symlink"
3046 test_done "$testroot" "1"
3047 return 1
3049 echo -n "/etc/passwd" > $testroot/content.expected
3050 cp $testroot/wt/passwd.link $testroot/content
3051 cmp -s $testroot/content.expected $testroot/content
3052 ret=$?
3053 if [ $ret -ne 0 ]; then
3054 diff -u $testroot/content.expected $testroot/content
3055 test_done "$testroot" "$ret"
3056 return 1
3059 if ! [ -h $testroot/wt/zeta.link ]; then
3060 echo "zeta.link is not a symlink"
3061 test_done "$testroot" "1"
3062 return 1
3065 readlink $testroot/wt/zeta.link > $testroot/stdout
3066 echo "gamma/delta" > $testroot/stdout.expected
3067 cmp -s $testroot/stdout.expected $testroot/stdout
3068 ret=$?
3069 if [ $ret -ne 0 ]; then
3070 diff -u $testroot/stdout.expected $testroot/stdout
3071 test_done "$testroot" "$ret"
3072 return 1
3075 test_done "$testroot" "0"
3078 test_parseargs "$@"
3079 run_test test_stage_basic
3080 run_test test_stage_directory
3081 run_test test_stage_no_changes
3082 run_test test_stage_unversioned
3083 run_test test_stage_nonexistent
3084 run_test test_stage_list
3085 run_test test_stage_conflict
3086 run_test test_stage_out_of_date
3087 run_test test_double_stage
3088 run_test test_stage_status
3089 run_test test_stage_add_already_staged_file
3090 run_test test_stage_rm_already_staged_file
3091 run_test test_stage_revert
3092 run_test test_stage_diff
3093 run_test test_stage_histedit
3094 run_test test_stage_rebase
3095 run_test test_stage_update
3096 run_test test_stage_commit_non_staged
3097 run_test test_stage_commit_out_of_date
3098 run_test test_stage_commit
3099 run_test test_stage_patch
3100 run_test test_stage_patch_twice
3101 run_test test_stage_patch_added
3102 run_test test_stage_patch_added_twice
3103 run_test test_stage_patch_removed
3104 run_test test_stage_patch_removed_twice
3105 run_test test_stage_patch_reversed
3106 run_test test_stage_patch_quit
3107 run_test test_stage_patch_incomplete_script
3108 run_test test_stage_symlink
3109 run_test test_stage_patch_symlink