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 > $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_no_changes() {
51 local testroot=`test_init stage_no_changes`
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 && got stage alpha beta > $testroot/stdout \
61 2> $testroot/stderr)
62 ret=$?
63 if [ $ret -eq 0 ]; then
64 echo "got stage command succeeded unexpectedly" >&2
65 test_done "$testroot" "1"
66 return 1
67 fi
69 echo "got: no changes to stage" > $testroot/stderr.expected
71 cmp -s $testroot/stderr.expected $testroot/stderr
72 ret=$?
73 if [ $ret -ne 0 ]; then
74 diff -u $testroot/stderr.expected $testroot/stderr
75 test_done "$testroot" "$ret"
76 return 1
77 fi
79 echo -n > $testroot/stdout.expected
80 cmp -s $testroot/stdout.expected $testroot/stdout
81 ret=$?
82 if [ $ret -ne 0 ]; then
83 diff -u $testroot/stdout.expected $testroot/stdout
84 fi
85 test_done "$testroot" "$ret"
86 }
88 test_stage_unversioned() {
89 local testroot=`test_init stage_unversioned`
91 got checkout $testroot/repo $testroot/wt > /dev/null
92 ret=$?
93 if [ $ret -ne 0 ]; then
94 test_done "$testroot" "$ret"
95 return 1
96 fi
98 echo "modified file" > $testroot/wt/alpha
99 touch $testroot/wt/unversioned-file
101 (cd $testroot/wt && got status > $testroot/stdout)
102 echo "M alpha" > $testroot/stdout.expected
103 echo "? unversioned-file" >> $testroot/stdout.expected
104 cmp -s $testroot/stdout.expected $testroot/stdout
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 diff -u $testroot/stdout.expected $testroot/stdout
108 test_done "$testroot" "$ret"
109 return 1
110 fi
112 (cd $testroot/wt && got stage > $testroot/stdout)
113 ret=$?
114 if [ $ret -ne 0 ]; then
115 echo "got stage command failed unexpectedly" >&2
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 echo " M alpha" > $testroot/stdout.expected
121 cmp -s $testroot/stdout.expected $testroot/stdout
122 ret=$?
123 if [ $ret -ne 0 ]; then
124 diff -u $testroot/stdout.expected $testroot/stdout
125 test_done "$testroot" "$ret"
126 return 1
127 fi
129 echo "modified file again" > $testroot/wt/alpha
131 (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
132 2> $testroot/stderr)
133 ret=$?
134 if [ $ret -eq 0 ]; then
135 echo "got stage command succeed unexpectedly" >&2
136 test_done "$testroot" "1"
137 return 1
138 fi
140 echo "got: no changes to stage" > $testroot/stderr.expected
141 cmp -s $testroot/stderr.expected $testroot/stderr
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 diff -u $testroot/stderr.expected $testroot/stderr
145 fi
146 test_done "$testroot" "$ret"
150 test_stage_nonexistent() {
151 local testroot=`test_init stage_nonexistent`
153 got checkout $testroot/repo $testroot/wt > /dev/null
154 ret=$?
155 if [ $ret -ne 0 ]; then
156 test_done "$testroot" "$ret"
157 return 1
158 fi
160 (cd $testroot/wt && got stage nonexistent-file \
161 > $testroot/stdout 2> $testroot/stderr)
162 echo "got: nonexistent-file: No such file or directory" \
163 > $testroot/stderr.expected
164 cmp -s $testroot/stderr.expected $testroot/stderr
165 ret=$?
166 if [ $ret -ne 0 ]; then
167 diff -u $testroot/stderr.expected $testroot/stderr
168 fi
169 test_done "$testroot" "$ret"
172 test_stage_list() {
173 local testroot=`test_init stage_list`
175 got checkout $testroot/repo $testroot/wt > /dev/null
176 ret=$?
177 if [ $ret -ne 0 ]; then
178 test_done "$testroot" "$ret"
179 return 1
180 fi
182 echo "modified file" > $testroot/wt/alpha
183 (cd $testroot/wt && got rm beta > /dev/null)
184 echo "new file" > $testroot/wt/foo
185 (cd $testroot/wt && got add foo > /dev/null)
187 echo ' M alpha' > $testroot/stdout.expected
188 echo ' D beta' >> $testroot/stdout.expected
189 echo ' A foo' >> $testroot/stdout.expected
190 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
192 (cd $testroot/wt && got stage -l > $testroot/stdout)
193 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
194 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
195 echo " M alpha" >> $testroot/stdout.expected
196 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
197 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
198 echo " D beta" >> $testroot/stdout.expected
199 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
200 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
201 echo " A foo" >> $testroot/stdout.expected
202 cmp -s $testroot/stdout.expected $testroot/stdout
203 ret=$?
204 if [ $ret -ne 0 ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 test_done "$testroot" "$ret"
207 return 1
208 fi
210 (cd $testroot/wt && got stage -l epsilon nonexistent \
211 > $testroot/stdout)
213 echo -n > $testroot/stdout.expected
214 cmp -s $testroot/stdout.expected $testroot/stdout
215 ret=$?
216 if [ $ret -ne 0 ]; then
217 diff -u $testroot/stdout.expected $testroot/stdout
218 test_done "$testroot" "$ret"
219 return 1
220 fi
222 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
224 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
225 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
226 echo " M alpha" >> $testroot/stdout.expected
227 cmp -s $testroot/stdout.expected $testroot/stdout
228 ret=$?
229 if [ $ret -ne 0 ]; then
230 diff -u $testroot/stdout.expected $testroot/stdout
231 fi
232 test_done "$testroot" "$ret"
236 test_stage_conflict() {
237 local testroot=`test_init stage_conflict`
238 local initial_commit=`git_show_head $testroot/repo`
240 got checkout $testroot/repo $testroot/wt > /dev/null
241 ret=$?
242 if [ $ret -ne 0 ]; then
243 test_done "$testroot" "$ret"
244 return 1
245 fi
247 echo "modified alpha" > $testroot/wt/alpha
248 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
250 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
252 echo "modified alpha, too" > $testroot/wt/alpha
254 echo "C alpha" > $testroot/stdout.expected
255 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
256 git_show_head $testroot/repo >> $testroot/stdout.expected
257 echo >> $testroot/stdout.expected
258 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
260 (cd $testroot/wt && got update > $testroot/stdout)
262 cmp -s $testroot/stdout.expected $testroot/stdout
263 ret=$?
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 (cd $testroot/wt && got stage alpha > $testroot/stdout \
271 2> $testroot/stderr)
272 ret=$?
273 if [ $ret -eq 0 ]; then
274 echo "got stage command succeeded unexpectedly" >&2
275 test_done "$testroot" "1"
276 return 1
277 fi
279 echo -n > $testroot/stdout.expected
280 echo "got: alpha: cannot stage file in conflicted status" \
281 > $testroot/stderr.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret=$?
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
288 return 1
289 fi
290 cmp -s $testroot/stderr.expected $testroot/stderr
291 ret=$?
292 if [ $ret -ne 0 ]; then
293 diff -u $testroot/stderr.expected $testroot/stderr
294 fi
295 test_done "$testroot" "$ret"
298 test_stage_out_of_date() {
299 local testroot=`test_init stage_out_of_date`
300 local initial_commit=`git_show_head $testroot/repo`
302 got checkout $testroot/repo $testroot/wt > /dev/null
303 ret=$?
304 if [ $ret -ne 0 ]; then
305 test_done "$testroot" "$ret"
306 return 1
307 fi
309 echo "modified alpha" > $testroot/wt/alpha
310 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
312 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
314 echo "modified alpha again" > $testroot/wt/alpha
315 (cd $testroot/wt && got stage alpha > $testroot/stdout \
316 2> $testroot/stderr)
317 ret=$?
318 if [ $ret -eq 0 ]; then
319 echo "got stage command succeeded unexpectedly" >&2
320 test_done "$testroot" "1"
321 return 1
322 fi
324 echo -n > $testroot/stdout.expected
325 echo "got: work tree must be updated before changes can be staged" \
326 > $testroot/stderr.expected
328 cmp -s $testroot/stdout.expected $testroot/stdout
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
333 return 1
334 fi
335 cmp -s $testroot/stderr.expected $testroot/stderr
336 ret=$?
337 if [ $ret -ne 0 ]; then
338 diff -u $testroot/stderr.expected $testroot/stderr
339 fi
340 test_done "$testroot" "$ret"
344 test_double_stage() {
345 local testroot=`test_init double_stage`
347 got checkout $testroot/repo $testroot/wt > /dev/null
348 ret=$?
349 if [ $ret -ne 0 ]; then
350 test_done "$testroot" "$ret"
351 return 1
352 fi
353 echo "modified file" > $testroot/wt/alpha
354 (cd $testroot/wt && got rm beta > /dev/null)
355 echo "new file" > $testroot/wt/foo
356 (cd $testroot/wt && got add foo > /dev/null)
357 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
359 echo "got: no changes to stage" > $testroot/stderr.expected
360 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
361 cmp -s $testroot/stderr.expected $testroot/stderr
362 ret=$?
363 if [ $ret -ne 0 ]; then
364 diff -u $testroot/stderr.expected $testroot/stderr
365 test_done "$testroot" "$ret"
366 return 1
367 fi
369 (cd $testroot/wt && got stage beta \
370 > $testroot/stdout 2> $testroot/stderr)
371 ret=$?
372 if [ $ret -eq 0 ]; then
373 echo "got stage command succeeded unexpectedly" >&2
374 test_done "$testroot" "1"
375 return 1
376 fi
377 echo -n > $testroot/stdout.expected
378 cmp -s $testroot/stdout.expected $testroot/stdout
379 ret=$?
380 if [ $ret -ne 0 ]; then
381 diff -u $testroot/stdout.expected $testroot/stdout
382 test_done "$testroot" "$ret"
383 return 1
384 fi
386 echo "got: no changes to stage" > $testroot/stderr.expected
387 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
388 cmp -s $testroot/stderr.expected $testroot/stderr
389 ret=$?
390 if [ $ret -ne 0 ]; then
391 diff -u $testroot/stderr.expected $testroot/stderr
392 test_done "$testroot" "$ret"
393 return 1
394 fi
396 printf "q\n" > $testroot/patchscript
397 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
398 > $testroot/stdout 2> $testroot/stderr)
399 ret=$?
400 if [ $ret -eq 0 ]; then
401 echo "got stage command succeeded unexpectedly" >&2
402 test_done "$testroot" "1"
403 return 1
404 fi
405 echo -n > $testroot/stdout.expected
406 cmp -s $testroot/stdout.expected $testroot/stdout
407 ret=$?
408 if [ $ret -ne 0 ]; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
411 return 1
412 fi
414 echo "got: no changes to stage" > $testroot/stderr.expected
415 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
416 cmp -s $testroot/stderr.expected $testroot/stderr
417 ret=$?
418 if [ $ret -ne 0 ]; then
419 diff -u $testroot/stderr.expected $testroot/stderr
420 test_done "$testroot" "$ret"
421 return 1
422 fi
424 echo "modified file again" > $testroot/wt/alpha
425 echo "modified new file" > $testroot/wt/foo
427 echo ' M alpha' > $testroot/stdout.expected
428 echo ' A foo' >> $testroot/stdout.expected
429 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
430 cmp -s $testroot/stdout.expected $testroot/stdout
431 ret=$?
432 if [ $ret -ne 0 ]; then
433 diff -u $testroot/stdout.expected $testroot/stdout
434 test_done "$testroot" "$ret"
435 return 1
436 fi
438 echo ' M alpha' > $testroot/stdout.expected
439 echo ' D beta' >> $testroot/stdout.expected
440 echo ' A foo' >> $testroot/stdout.expected
442 (cd $testroot/wt && got status > $testroot/stdout)
443 cmp -s $testroot/stdout.expected $testroot/stdout
444 ret=$?
445 if [ $ret -ne 0 ]; then
446 diff -u $testroot/stdout.expected $testroot/stdout
447 fi
448 test_done "$testroot" "$ret"
451 test_stage_status() {
452 local testroot=`test_init stage_status`
454 got checkout $testroot/repo $testroot/wt > /dev/null
455 ret=$?
456 if [ $ret -ne 0 ]; then
457 test_done "$testroot" "$ret"
458 return 1
459 fi
461 echo "modified file" > $testroot/wt/alpha
462 (cd $testroot/wt && got rm beta > /dev/null)
463 echo "new file" > $testroot/wt/foo
464 (cd $testroot/wt && got add foo > /dev/null)
465 echo "new file" > $testroot/wt/epsilon/new
466 (cd $testroot/wt && got add epsilon/new > /dev/null)
467 echo "modified file" > $testroot/wt/epsilon/zeta
468 (cd $testroot/wt && got rm gamma/delta > /dev/null)
470 echo ' M alpha' > $testroot/stdout.expected
471 echo ' D beta' >> $testroot/stdout.expected
472 echo 'A epsilon/new' >> $testroot/stdout.expected
473 echo 'M epsilon/zeta' >> $testroot/stdout.expected
474 echo ' A foo' >> $testroot/stdout.expected
475 echo 'D gamma/delta' >> $testroot/stdout.expected
476 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
478 (cd $testroot/wt && got status > $testroot/stdout)
479 cmp -s $testroot/stdout.expected $testroot/stdout
480 ret=$?
481 if [ $ret -ne 0 ]; then
482 diff -u $testroot/stdout.expected $testroot/stdout
483 test_done "$testroot" "$ret"
484 return 1
485 fi
487 echo "modified file again" >> $testroot/wt/alpha
488 echo "modified added file again" >> $testroot/wt/foo
490 echo 'MM alpha' > $testroot/stdout.expected
491 echo ' D beta' >> $testroot/stdout.expected
492 echo 'A epsilon/new' >> $testroot/stdout.expected
493 echo 'M epsilon/zeta' >> $testroot/stdout.expected
494 echo 'MA foo' >> $testroot/stdout.expected
495 echo 'D gamma/delta' >> $testroot/stdout.expected
497 (cd $testroot/wt && got status > $testroot/stdout)
498 cmp -s $testroot/stdout.expected $testroot/stdout
499 ret=$?
500 if [ $ret -ne 0 ]; then
501 diff -u $testroot/stdout.expected $testroot/stdout
502 test_done "$testroot" "$ret"
503 return 1
504 fi
506 # test no-op change of added file with new stat(2) timestamp
507 echo "new file" > $testroot/wt/foo
508 echo ' A foo' > $testroot/stdout.expected
509 (cd $testroot/wt && got status foo > $testroot/stdout)
510 cmp -s $testroot/stdout.expected $testroot/stdout
511 ret=$?
512 if [ $ret -ne 0 ]; then
513 diff -u $testroot/stdout.expected $testroot/stdout
514 test_done "$testroot" "$ret"
515 return 1
516 fi
518 # test staged deleted file which is restored on disk
519 echo "new file" > $testroot/wt/beta
520 echo ' D beta' > $testroot/stdout.expected
521 (cd $testroot/wt && got status beta > $testroot/stdout)
522 cmp -s $testroot/stdout.expected $testroot/stdout
523 ret=$?
524 if [ $ret -ne 0 ]; then
525 diff -u $testroot/stdout.expected $testroot/stdout
526 fi
527 test_done "$testroot" "$ret"
531 test_stage_add_already_staged_file() {
532 local testroot=`test_init stage_add_already_staged_file`
534 got checkout $testroot/repo $testroot/wt > /dev/null
535 ret=$?
536 if [ $ret -ne 0 ]; then
537 test_done "$testroot" "$ret"
538 return 1
539 fi
541 echo "modified file" > $testroot/wt/alpha
542 (cd $testroot/wt && got rm beta > /dev/null)
543 echo "new file" > $testroot/wt/foo
544 (cd $testroot/wt && got add foo > /dev/null)
546 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
548 echo -n > $testroot/stdout.expected
549 for f in alpha beta foo; do
550 (cd $testroot/wt && got add $f \
551 > $testroot/stdout 2> $testroot/stderr)
552 echo "got: $f: file has unexpected status" \
553 > $testroot/stderr.expected
554 cmp -s $testroot/stderr.expected $testroot/stderr
555 ret=$?
556 if [ $ret -ne 0 ]; then
557 diff -u $testroot/stderr.expected $testroot/stderr
558 test_done "$testroot" "$ret"
559 return 1
560 fi
561 cmp -s $testroot/stdout.expected $testroot/stdout
562 ret=$?
563 if [ $ret -ne 0 ]; then
564 diff -u $testroot/stdout.expected $testroot/stdout
565 test_done "$testroot" "$ret"
566 return 1
567 fi
568 done
570 echo ' M alpha' > $testroot/stdout.expected
571 echo ' D beta' >> $testroot/stdout.expected
572 echo ' A foo' >> $testroot/stdout.expected
574 (cd $testroot/wt && got status > $testroot/stdout)
575 cmp -s $testroot/stdout.expected $testroot/stdout
576 ret=$?
577 if [ $ret -ne 0 ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 fi
580 test_done "$testroot" "$ret"
583 test_stage_rm_already_staged_file() {
584 local testroot=`test_init stage_rm_already_staged_file`
586 got checkout $testroot/repo $testroot/wt > /dev/null
587 ret=$?
588 if [ $ret -ne 0 ]; then
589 test_done "$testroot" "$ret"
590 return 1
591 fi
593 echo "modified file" > $testroot/wt/alpha
594 (cd $testroot/wt && got rm beta > /dev/null)
595 echo "new file" > $testroot/wt/foo
596 (cd $testroot/wt && got add foo > /dev/null)
598 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
600 (cd $testroot/wt && got rm beta \
601 > $testroot/stdout 2> $testroot/stderr)
602 ret=$?
603 if [ $ret -ne 0 ]; then
604 echo "got rm command failed unexpectedly" >&2
605 test_done "$testroot" "1"
606 return 1
607 fi
608 echo -n > $testroot/stdout.expected
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 test_done "$testroot" "$ret"
614 return 1
615 fi
616 echo -n > $testroot/stderr.expected
617 cmp -s $testroot/stderr.expected $testroot/stderr
618 ret=$?
619 if [ $ret -ne 0 ]; then
620 diff -u $testroot/stderr.expected $testroot/stderr
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 for f in alpha foo; do
626 echo "got: $f: file is staged" > $testroot/stderr.expected
627 (cd $testroot/wt && got rm $f \
628 > $testroot/stdout 2> $testroot/stderr)
629 ret=$?
630 if [ $ret -eq 0 ]; then
631 echo "got rm command succeeded unexpectedly" >&2
632 test_done "$testroot" "1"
633 return 1
634 fi
635 cmp -s $testroot/stderr.expected $testroot/stderr
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 diff -u $testroot/stderr.expected $testroot/stderr
639 test_done "$testroot" "$ret"
640 return 1
641 fi
642 done
644 echo ' M alpha' > $testroot/stdout.expected
645 echo ' D beta' >> $testroot/stdout.expected
646 echo ' A foo' >> $testroot/stdout.expected
648 (cd $testroot/wt && got status > $testroot/stdout)
649 cmp -s $testroot/stdout.expected $testroot/stdout
650 ret=$?
651 if [ $ret -ne 0 ]; then
652 diff -u $testroot/stdout.expected $testroot/stdout
653 fi
654 test_done "$testroot" "$ret"
657 test_stage_revert() {
658 local testroot=`test_init stage_revert`
660 got checkout $testroot/repo $testroot/wt > /dev/null
661 ret=$?
662 if [ $ret -ne 0 ]; then
663 test_done "$testroot" "$ret"
664 return 1
665 fi
667 echo "modified alpha" > $testroot/wt/alpha
668 (cd $testroot/wt && got rm beta > /dev/null)
669 echo "new file" > $testroot/wt/foo
670 (cd $testroot/wt && got add foo > /dev/null)
671 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
673 echo "modified file again" >> $testroot/wt/alpha
674 echo "modified added file again" >> $testroot/wt/foo
676 (cd $testroot/wt && got revert alpha > $testroot/stdout)
677 ret=$?
678 if [ $ret -ne 0 ]; then
679 echo "revert command failed unexpectedly" >&2
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 echo "R alpha" > $testroot/stdout.expected
685 cmp -s $testroot/stdout.expected $testroot/stdout
686 ret=$?
687 if [ $ret -ne 0 ]; then
688 diff -u $testroot/stdout.expected $testroot/stdout
689 test_done "$testroot" "$ret"
690 return 1
691 fi
693 echo "modified alpha" > $testroot/content.expected
694 cat $testroot/wt/alpha > $testroot/content
695 cmp -s $testroot/content.expected $testroot/content
696 ret=$?
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/content.expected $testroot/content
699 test_done "$testroot" "$ret"
700 return 1
701 fi
703 echo ' M alpha' > $testroot/stdout.expected
704 echo ' D beta' >> $testroot/stdout.expected
705 echo 'MA foo' >> $testroot/stdout.expected
706 (cd $testroot/wt && got status > $testroot/stdout)
707 cmp -s $testroot/stdout.expected $testroot/stdout
708 ret=$?
709 if [ $ret -ne 0 ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 (cd $testroot/wt && got revert alpha > $testroot/stdout)
716 ret=$?
717 if [ $ret -ne 0 ]; then
718 echo "revert command failed unexpectedly" >&2
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 echo -n > $testroot/stdout.expected
724 cmp -s $testroot/stdout.expected $testroot/stdout
725 ret=$?
726 if [ $ret -ne 0 ]; then
727 diff -u $testroot/stdout.expected $testroot/stdout
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 echo "modified alpha" > $testroot/content.expected
733 cat $testroot/wt/alpha > $testroot/content
734 cmp -s $testroot/content.expected $testroot/content
735 ret=$?
736 if [ $ret -ne 0 ]; then
737 diff -u $testroot/content.expected $testroot/content
738 test_done "$testroot" "$ret"
739 return 1
740 fi
742 (cd $testroot/wt && got revert beta > $testroot/stdout \
743 2> $testroot/stderr)
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 echo "revert command failed unexpectedly" >&2
747 test_done "$testroot" "$ret"
748 return 1
749 fi
751 echo -n > $testroot/stdout.expected
752 cmp -s $testroot/stdout.expected $testroot/stdout
753 ret=$?
754 if [ $ret -ne 0 ]; then
755 diff -u $testroot/stdout.expected $testroot/stdout
756 test_done "$testroot" "$ret"
757 return 1
758 fi
760 echo -n > $testroot/stderr.expected
761 cmp -s $testroot/stderr.expected $testroot/stderr
762 ret=$?
763 if [ $ret -ne 0 ]; then
764 diff -u $testroot/stderr.expected $testroot/stderr
765 test_done "$testroot" "$ret"
766 return 1
767 fi
769 (cd $testroot/wt && got revert foo > $testroot/stdout)
770 ret=$?
771 if [ $ret -ne 0 ]; then
772 echo "revert command failed unexpectedly" >&2
773 test_done "$testroot" "$ret"
774 return 1
775 fi
777 echo "R foo" > $testroot/stdout.expected
778 cmp -s $testroot/stdout.expected $testroot/stdout
779 ret=$?
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
782 test_done "$testroot" "$ret"
783 return 1
784 fi
786 echo "new file" > $testroot/content.expected
787 cat $testroot/wt/foo > $testroot/content
788 cmp -s $testroot/content.expected $testroot/content
789 ret=$?
790 if [ $ret -ne 0 ]; then
791 diff -u $testroot/content.expected $testroot/content
792 test_done "$testroot" "$ret"
793 return 1
794 fi
796 echo ' M alpha' > $testroot/stdout.expected
797 echo ' D beta' >> $testroot/stdout.expected
798 echo ' A foo' >> $testroot/stdout.expected
799 (cd $testroot/wt && got status > $testroot/stdout)
800 cmp -s $testroot/stdout.expected $testroot/stdout
801 ret=$?
802 if [ $ret -ne 0 ]; then
803 diff -u $testroot/stdout.expected $testroot/stdout
804 test_done "$testroot" "$ret"
805 return 1
806 fi
808 (cd $testroot/wt && got revert foo > $testroot/stdout)
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 echo "revert command failed unexpectedly" >&2
812 test_done "$testroot" "$ret"
813 return 1
814 fi
816 echo -n > $testroot/stdout.expected
817 cmp -s $testroot/stdout.expected $testroot/stdout
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 echo "new file" > $testroot/content.expected
826 cat $testroot/wt/foo > $testroot/content
827 cmp -s $testroot/content.expected $testroot/content
828 ret=$?
829 if [ $ret -ne 0 ]; then
830 diff -u $testroot/content.expected $testroot/content
831 test_done "$testroot" "$ret"
832 return 1
833 fi
835 echo ' M alpha' > $testroot/stdout.expected
836 echo ' D beta' >> $testroot/stdout.expected
837 echo ' A foo' >> $testroot/stdout.expected
838 (cd $testroot/wt && got status > $testroot/stdout)
839 cmp -s $testroot/stdout.expected $testroot/stdout
840 ret=$?
841 if [ $ret -ne 0 ]; then
842 diff -u $testroot/stdout.expected $testroot/stdout
843 test_done "$testroot" "$ret"
844 return 1
845 fi
847 echo "modified file again" >> $testroot/wt/alpha
848 echo "modified added file again" >> $testroot/wt/foo
850 (cd $testroot/wt && got revert -R . > $testroot/stdout \
851 2> $testroot/stderr)
852 ret=$?
853 if [ $ret -ne 0 ]; then
854 echo "revert command failed unexpectedly" >&2
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 echo "R alpha" > $testroot/stdout.expected
860 echo "R foo" >> $testroot/stdout.expected
861 cmp -s $testroot/stdout.expected $testroot/stdout
862 ret=$?
863 if [ $ret -ne 0 ]; then
864 diff -u $testroot/stdout.expected $testroot/stdout
865 test_done "$testroot" "$ret"
866 return 1
867 fi
869 echo -n > $testroot/stderr.expected
870 cmp -s $testroot/stderr.expected $testroot/stderr
871 ret=$?
872 if [ $ret -ne 0 ]; then
873 diff -u $testroot/stderr.expected $testroot/stderr
874 test_done "$testroot" "$ret"
875 return 1
876 fi
878 echo ' M alpha' > $testroot/stdout.expected
879 echo ' D beta' >> $testroot/stdout.expected
880 echo ' A foo' >> $testroot/stdout.expected
881 (cd $testroot/wt && got status > $testroot/stdout)
882 cmp -s $testroot/stdout.expected $testroot/stdout
883 ret=$?
884 if [ $ret -ne 0 ]; then
885 diff -u $testroot/stdout.expected $testroot/stdout
886 fi
887 test_done "$testroot" "$ret"
890 test_stage_diff() {
891 local testroot=`test_init stage_diff`
892 local head_commit=`git_show_head $testroot/repo`
894 got checkout $testroot/repo $testroot/wt > /dev/null
895 ret=$?
896 if [ $ret -ne 0 ]; then
897 test_done "$testroot" "$ret"
898 return 1
899 fi
901 echo "modified file" > $testroot/wt/alpha
902 (cd $testroot/wt && got rm beta > /dev/null)
903 echo "new file" > $testroot/wt/foo
904 (cd $testroot/wt && got add foo > /dev/null)
906 (cd $testroot/wt && got diff -s > $testroot/stdout)
907 echo -n > $testroot/stdout.expected
908 cmp -s $testroot/stdout.expected $testroot/stdout
909 ret=$?
910 if [ $ret -ne 0 ]; then
911 diff -u $testroot/stdout.expected $testroot/stdout
912 test_done "$testroot" "$ret"
913 return 1
914 fi
916 echo ' M alpha' > $testroot/stdout.expected
917 echo ' D beta' >> $testroot/stdout.expected
918 echo ' A foo' >> $testroot/stdout.expected
919 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
921 (cd $testroot/wt && got diff > $testroot/stdout)
922 echo -n > $testroot/stdout.expected
923 cmp -s $testroot/stdout.expected $testroot/stdout
924 ret=$?
925 if [ $ret -ne 0 ]; then
926 diff -u $testroot/stdout.expected $testroot/stdout
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 echo "modified file again" > $testroot/wt/alpha
932 echo "new file changed" > $testroot/wt/foo
934 (cd $testroot/wt && got diff > $testroot/stdout)
936 echo "diff $testroot/wt" > $testroot/stdout.expected
937 echo "commit - $head_commit" >> $testroot/stdout.expected
938 echo "path + $testroot/wt" >> $testroot/stdout.expected
939 echo -n 'blob - ' >> $testroot/stdout.expected
940 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
941 >> $testroot/stdout.expected
942 echo ' (staged)' >> $testroot/stdout.expected
943 echo 'file + alpha' >> $testroot/stdout.expected
944 echo '--- alpha' >> $testroot/stdout.expected
945 echo '+++ alpha' >> $testroot/stdout.expected
946 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
947 echo '-modified file' >> $testroot/stdout.expected
948 echo '+modified file again' >> $testroot/stdout.expected
949 echo -n 'blob - ' >> $testroot/stdout.expected
950 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
951 >> $testroot/stdout.expected
952 echo " (staged)" >> $testroot/stdout.expected
953 echo 'file + foo' >> $testroot/stdout.expected
954 echo '--- foo' >> $testroot/stdout.expected
955 echo '+++ foo' >> $testroot/stdout.expected
956 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
957 echo '-new file' >> $testroot/stdout.expected
958 echo '+new file changed' >> $testroot/stdout.expected
960 cmp -s $testroot/stdout.expected $testroot/stdout
961 ret=$?
962 if [ $ret -ne 0 ]; then
963 diff -u $testroot/stdout.expected $testroot/stdout
964 test_done "$testroot" "$ret"
965 return 1
966 fi
968 (cd $testroot/wt && got diff -s > $testroot/stdout)
970 echo "diff -s $testroot/wt" > $testroot/stdout.expected
971 echo "commit - $head_commit" >> $testroot/stdout.expected
972 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
973 echo -n 'blob - ' >> $testroot/stdout.expected
974 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
975 >> $testroot/stdout.expected
976 echo -n 'blob + ' >> $testroot/stdout.expected
977 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
978 >> $testroot/stdout.expected
979 echo '--- alpha' >> $testroot/stdout.expected
980 echo '+++ alpha' >> $testroot/stdout.expected
981 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
982 echo '-alpha' >> $testroot/stdout.expected
983 echo '+modified file' >> $testroot/stdout.expected
984 echo -n 'blob - ' >> $testroot/stdout.expected
985 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
986 >> $testroot/stdout.expected
987 echo 'blob + /dev/null' >> $testroot/stdout.expected
988 echo '--- beta' >> $testroot/stdout.expected
989 echo '+++ /dev/null' >> $testroot/stdout.expected
990 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
991 echo '-beta' >> $testroot/stdout.expected
992 echo 'blob - /dev/null' >> $testroot/stdout.expected
993 echo -n 'blob + ' >> $testroot/stdout.expected
994 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
995 >> $testroot/stdout.expected
996 echo '--- /dev/null' >> $testroot/stdout.expected
997 echo '+++ foo' >> $testroot/stdout.expected
998 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
999 echo '+new file' >> $testroot/stdout.expected
1001 cmp -s $testroot/stdout.expected $testroot/stdout
1002 ret=$?
1003 if [ $ret -ne 0 ]; then
1004 diff -u $testroot/stdout.expected $testroot/stdout
1006 test_done "$testroot" "$ret"
1010 test_stage_histedit() {
1011 local testroot=`test_init stage_histedit`
1012 local orig_commit=`git_show_head $testroot/repo`
1014 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1015 ret=$?
1016 if [ $ret -ne 0 ]; then
1017 test_done "$testroot" "$ret"
1018 return 1
1021 echo "modified file" > $testroot/wt/alpha
1022 (cd $testroot/wt && got stage alpha > /dev/null)
1024 echo "modified alpha on master" > $testroot/repo/alpha
1025 (cd $testroot/repo && git rm -q beta)
1026 echo "new file on master" > $testroot/repo/epsilon/new
1027 (cd $testroot/repo && git add epsilon/new)
1028 git_commit $testroot/repo -m "committing changes"
1029 local old_commit1=`git_show_head $testroot/repo`
1031 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1032 git_commit $testroot/repo -m "committing to zeta on master"
1033 local old_commit2=`git_show_head $testroot/repo`
1035 echo "pick $old_commit1" > $testroot/histedit-script
1036 echo "pick $old_commit2" >> $testroot/histedit-script
1038 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1039 > $testroot/stdout 2> $testroot/stderr)
1040 ret=$?
1041 if [ $ret -eq 0 ]; then
1042 echo "got histedit command succeeded unexpectedly" >&2
1043 test_done "$testroot" "1"
1044 return 1
1047 echo -n > $testroot/stdout.expected
1048 echo "got: alpha: file is staged" > $testroot/stderr.expected
1050 cmp -s $testroot/stderr.expected $testroot/stderr
1051 ret=$?
1052 if [ $ret -ne 0 ]; then
1053 diff -u $testroot/stderr.expected $testroot/stderr
1054 test_done "$testroot" "$ret"
1055 return 1
1057 cmp -s $testroot/stdout.expected $testroot/stdout
1058 ret=$?
1059 if [ $ret -ne 0 ]; then
1060 diff -u $testroot/stdout.expected $testroot/stdout
1062 test_done "$testroot" "$ret"
1066 test_stage_rebase() {
1067 local testroot=`test_init stage_rebase`
1069 (cd $testroot/repo && git checkout -q -b newbranch)
1070 echo "modified delta on branch" > $testroot/repo/gamma/delta
1071 git_commit $testroot/repo -m "committing to delta on newbranch"
1073 echo "modified alpha on branch" > $testroot/repo/alpha
1074 (cd $testroot/repo && git rm -q beta)
1075 echo "new file on branch" > $testroot/repo/epsilon/new
1076 (cd $testroot/repo && git add epsilon/new)
1077 git_commit $testroot/repo -m "committing more changes on newbranch"
1079 local orig_commit1=`git_show_parent_commit $testroot/repo`
1080 local orig_commit2=`git_show_head $testroot/repo`
1082 (cd $testroot/repo && git checkout -q master)
1083 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1084 git_commit $testroot/repo -m "committing to zeta on master"
1085 local master_commit=`git_show_head $testroot/repo`
1087 got checkout $testroot/repo $testroot/wt > /dev/null
1088 ret=$?
1089 if [ $ret -ne 0 ]; then
1090 test_done "$testroot" "$ret"
1091 return 1
1094 echo "modified file" > $testroot/wt/alpha
1095 (cd $testroot/wt && got stage alpha > /dev/null)
1097 (cd $testroot/wt && got rebase newbranch \
1098 > $testroot/stdout 2> $testroot/stderr)
1099 ret=$?
1100 if [ $ret -eq 0 ]; then
1101 echo "got rebase command succeeded unexpectedly" >&2
1102 test_done "$testroot" "1"
1103 return 1
1106 echo -n > $testroot/stdout.expected
1107 echo "got: alpha: file is staged" > $testroot/stderr.expected
1109 cmp -s $testroot/stderr.expected $testroot/stderr
1110 ret=$?
1111 if [ $ret -ne 0 ]; then
1112 diff -u $testroot/stderr.expected $testroot/stderr
1113 test_done "$testroot" "$ret"
1114 return 1
1116 cmp -s $testroot/stdout.expected $testroot/stdout
1117 ret=$?
1118 if [ $ret -ne 0 ]; then
1119 diff -u $testroot/stdout.expected $testroot/stdout
1121 test_done "$testroot" "$ret"
1124 test_stage_update() {
1125 local testroot=`test_init stage_update`
1127 got checkout $testroot/repo $testroot/wt > /dev/null
1128 ret=$?
1129 if [ $ret -ne 0 ]; then
1130 test_done "$testroot" "$ret"
1131 return 1
1134 echo "modified file" > $testroot/wt/alpha
1135 (cd $testroot/wt && got stage alpha > /dev/null)
1137 echo "modified alpha" > $testroot/repo/alpha
1138 git_commit $testroot/repo -m "modified alpha"
1140 (cd $testroot/wt && got update > $testroot/stdout \
1141 2> $testroot/stderr)
1142 ret=$?
1143 if [ $ret -eq 0 ]; then
1144 echo "got update command succeeded unexpectedly" >&2
1145 test_done "$testroot" "1"
1146 return 1
1149 echo -n > $testroot/stdout.expected
1150 echo "got: alpha: file is staged" > $testroot/stderr.expected
1152 cmp -s $testroot/stderr.expected $testroot/stderr
1153 ret=$?
1154 if [ $ret -ne 0 ]; then
1155 diff -u $testroot/stderr.expected $testroot/stderr
1156 test_done "$testroot" "$ret"
1157 return 1
1159 cmp -s $testroot/stdout.expected $testroot/stdout
1160 ret=$?
1161 if [ $ret -ne 0 ]; then
1162 diff -u $testroot/stdout.expected $testroot/stdout
1164 test_done "$testroot" "$ret"
1167 test_stage_commit_non_staged() {
1168 local testroot=`test_init stage_commit_non_staged`
1170 got checkout $testroot/repo $testroot/wt > /dev/null
1171 ret=$?
1172 if [ $ret -ne 0 ]; then
1173 test_done "$testroot" "$ret"
1174 return 1
1177 echo "modified file" > $testroot/wt/alpha
1178 (cd $testroot/wt && got rm beta > /dev/null)
1179 echo "new file" > $testroot/wt/foo
1180 (cd $testroot/wt && got add foo > /dev/null)
1181 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1183 echo "modified file" > $testroot/wt/gamma/delta
1184 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1185 > $testroot/stdout 2> $testroot/stderr)
1186 ret=$?
1187 if [ $ret -eq 0 ]; then
1188 echo "got commit command succeeded unexpectedly" >&2
1189 test_done "$testroot" "1"
1190 return 1
1193 echo -n > $testroot/stdout.expected
1194 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1196 cmp -s $testroot/stderr.expected $testroot/stderr
1197 ret=$?
1198 if [ $ret -ne 0 ]; then
1199 diff -u $testroot/stderr.expected $testroot/stderr
1200 test_done "$testroot" "$ret"
1201 return 1
1203 cmp -s $testroot/stdout.expected $testroot/stdout
1204 ret=$?
1205 if [ $ret -ne 0 ]; then
1206 diff -u $testroot/stdout.expected $testroot/stdout
1208 test_done "$testroot" "$ret"
1211 test_stage_commit_out_of_date() {
1212 local testroot=`test_init stage_commit_out_of_date`
1214 got checkout $testroot/repo $testroot/wt > /dev/null
1215 ret=$?
1216 if [ $ret -ne 0 ]; then
1217 test_done "$testroot" "$ret"
1218 return 1
1221 echo "modified file" > $testroot/wt/alpha
1222 (cd $testroot/wt && got rm beta > /dev/null)
1223 echo "new file" > $testroot/wt/foo
1224 (cd $testroot/wt && got add foo > /dev/null)
1225 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1227 echo "changed file" > $testroot/repo/alpha
1228 git_commit $testroot/repo -m "changed alpha in repo"
1230 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1231 2> $testroot/stderr)
1232 ret=$?
1233 if [ $ret -eq 0 ]; then
1234 echo "got commit command succeeded unexpectedly" >&2
1235 test_done "$testroot" "1"
1236 return 1
1239 echo -n > $testroot/stdout.expected
1240 echo -n "got: work tree must be updated before these changes " \
1241 > $testroot/stderr.expected
1242 echo "can be committed" >> $testroot/stderr.expected
1244 cmp -s $testroot/stderr.expected $testroot/stderr
1245 ret=$?
1246 if [ $ret -ne 0 ]; then
1247 diff -u $testroot/stderr.expected $testroot/stderr
1248 test_done "$testroot" "$ret"
1249 return 1
1251 cmp -s $testroot/stdout.expected $testroot/stdout
1252 ret=$?
1253 if [ $ret -ne 0 ]; then
1254 diff -u $testroot/stdout.expected $testroot/stdout
1255 test_done "$testroot" "$ret"
1256 return 1
1259 (cd $testroot/wt && got update > $testroot/stdout \
1260 2> $testroot/stderr)
1261 echo -n > $testroot/stdout.expected
1262 echo "got: alpha: file is staged" > $testroot/stderr.expected
1264 cmp -s $testroot/stderr.expected $testroot/stderr
1265 ret=$?
1266 if [ $ret -ne 0 ]; then
1267 diff -u $testroot/stderr.expected $testroot/stderr
1268 test_done "$testroot" "$ret"
1269 return 1
1271 cmp -s $testroot/stdout.expected $testroot/stdout
1272 ret=$?
1273 if [ $ret -ne 0 ]; then
1274 diff -u $testroot/stdout.expected $testroot/stdout
1275 test_done "$testroot" "$ret"
1276 return 1
1279 (cd $testroot/wt && got unstage > /dev/null)
1280 (cd $testroot/wt && got update > $testroot/stdout)
1281 ret=$?
1282 if [ $ret -ne 0 ]; then
1283 echo "got update command failed unexpectedly" >&2
1284 test_done "$testroot" "$ret"
1285 return 1
1288 (cd $testroot/wt && got status > $testroot/stdout)
1289 echo "C alpha" > $testroot/stdout.expected
1290 echo "D beta" >> $testroot/stdout.expected
1291 echo "A foo" >> $testroot/stdout.expected
1292 cmp -s $testroot/stdout.expected $testroot/stdout
1293 ret=$?
1294 if [ $ret -ne 0 ]; then
1295 diff -u $testroot/stdout.expected $testroot/stdout
1296 test_done "$testroot" "$ret"
1297 return 1
1300 # resolve conflict
1301 echo "resolved file" > $testroot/wt/alpha
1303 (cd $testroot/wt && got stage > /dev/null)
1305 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1306 ret=$?
1307 if [ $ret -ne 0 ]; then
1308 echo "got commit command failed unexpectedly" >&2
1309 test_done "$testroot" "$ret"
1310 return 1
1313 local commit_id=`git_show_head $testroot/repo`
1314 echo "A foo" > $testroot/stdout.expected
1315 echo "M alpha" >> $testroot/stdout.expected
1316 echo "D beta" >> $testroot/stdout.expected
1317 echo "Created commit $commit_id" >> $testroot/stdout.expected
1318 cmp -s $testroot/stdout.expected $testroot/stdout
1319 ret=$?
1320 if [ $ret -ne 0 ]; then
1321 diff -u $testroot/stdout.expected $testroot/stdout
1323 test_done "$testroot" "$ret"
1327 test_stage_commit() {
1328 local testroot=`test_init stage_commit`
1329 local first_commit=`git_show_head $testroot/repo`
1331 got checkout $testroot/repo $testroot/wt > /dev/null
1332 ret=$?
1333 if [ $ret -ne 0 ]; then
1334 test_done "$testroot" "$ret"
1335 return 1
1338 echo "modified file" > $testroot/wt/alpha
1339 (cd $testroot/wt && got rm beta > /dev/null)
1340 echo "new file" > $testroot/wt/foo
1341 (cd $testroot/wt && got add foo > /dev/null)
1342 echo "modified file" > $testroot/wt/alpha
1343 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1345 echo "modified file again" > $testroot/wt/alpha
1346 echo "new file changed" > $testroot/wt/foo
1347 echo "non-staged change" > $testroot/wt/gamma/delta
1348 echo "non-staged new file" > $testroot/wt/epsilon/new
1349 (cd $testroot/wt && got add epsilon/new > /dev/null)
1350 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1352 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1353 > $testroot/blob_id_alpha
1354 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1355 > $testroot/blob_id_foo
1357 (cd $testroot/wt && got commit -m "staged changes" \
1358 > $testroot/stdout)
1359 ret=$?
1360 if [ $ret -ne 0 ]; then
1361 echo "got commit command failed unexpectedly" >&2
1362 test_done "$testroot" "1"
1363 return 1
1366 local head_commit=`git_show_head $testroot/repo`
1367 echo "A foo" > $testroot/stdout.expected
1368 echo "M alpha" >> $testroot/stdout.expected
1369 echo "D beta" >> $testroot/stdout.expected
1370 echo "Created commit $head_commit" >> $testroot/stdout.expected
1372 cmp -s $testroot/stdout.expected $testroot/stdout
1373 ret=$?
1374 if [ $ret -ne 0 ]; then
1375 diff -u $testroot/stdout.expected $testroot/stdout
1376 test_done "$testroot" "$ret"
1377 return 1
1380 got diff -r $testroot/repo $first_commit $head_commit \
1381 > $testroot/stdout
1383 echo "diff $first_commit $head_commit" \
1384 > $testroot/stdout.expected
1385 echo "commit - $first_commit" >> $testroot/stdout.expected
1386 echo "commit + $head_commit" >> $testroot/stdout.expected
1387 echo -n 'blob - ' >> $testroot/stdout.expected
1388 got tree -r $testroot/repo -i -c $first_commit | \
1389 grep 'alpha$' | cut -d' ' -f 1 \
1390 >> $testroot/stdout.expected
1391 echo -n 'blob + ' >> $testroot/stdout.expected
1392 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1393 echo '--- alpha' >> $testroot/stdout.expected
1394 echo '+++ alpha' >> $testroot/stdout.expected
1395 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1396 echo '-alpha' >> $testroot/stdout.expected
1397 echo '+modified file' >> $testroot/stdout.expected
1398 echo -n 'blob - ' >> $testroot/stdout.expected
1399 got tree -r $testroot/repo -i -c $first_commit \
1400 | grep 'beta$' | cut -d' ' -f 1 | tr -d '\n' \
1401 >> $testroot/stdout.expected
1402 echo " (mode 644)" >> $testroot/stdout.expected
1403 echo 'blob + /dev/null' >> $testroot/stdout.expected
1404 echo '--- beta' >> $testroot/stdout.expected
1405 echo '+++ /dev/null' >> $testroot/stdout.expected
1406 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1407 echo '-beta' >> $testroot/stdout.expected
1408 echo 'blob - /dev/null' >> $testroot/stdout.expected
1409 echo -n 'blob + ' >> $testroot/stdout.expected
1410 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1411 echo " (mode 644)" >> $testroot/stdout.expected
1412 echo '--- /dev/null' >> $testroot/stdout.expected
1413 echo '+++ foo' >> $testroot/stdout.expected
1414 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1415 echo '+new file' >> $testroot/stdout.expected
1417 cmp -s $testroot/stdout.expected $testroot/stdout
1418 ret=$?
1419 if [ $ret -ne 0 ]; then
1420 diff -u $testroot/stdout.expected $testroot/stdout
1421 test_done "$testroot" "$ret"
1422 return 1
1425 echo 'M alpha' > $testroot/stdout.expected
1426 echo 'A epsilon/new' >> $testroot/stdout.expected
1427 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1428 echo 'M foo' >> $testroot/stdout.expected
1429 echo 'M gamma/delta' >> $testroot/stdout.expected
1431 (cd $testroot/wt && got status > $testroot/stdout)
1432 cmp -s $testroot/stdout.expected $testroot/stdout
1433 ret=$?
1434 if [ $ret -ne 0 ]; then
1435 diff -u $testroot/stdout.expected $testroot/stdout
1437 test_done "$testroot" "$ret"
1440 test_stage_patch() {
1441 local testroot=`test_init stage_patch`
1443 jot 16 > $testroot/repo/numbers
1444 (cd $testroot/repo && git add numbers)
1445 git_commit $testroot/repo -m "added numbers file"
1446 local commit_id=`git_show_head $testroot/repo`
1448 got checkout $testroot/repo $testroot/wt > /dev/null
1449 ret=$?
1450 if [ $ret -ne 0 ]; then
1451 test_done "$testroot" "$ret"
1452 return 1
1455 ed -s $testroot/wt/numbers <<-\EOF
1456 ,s/^2$/a/
1457 ,s/^7$/b/
1458 ,s/^16$/c/
1460 EOF
1462 # don't stage any hunks
1463 printf "n\nn\nn\n" > $testroot/patchscript
1464 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1465 numbers > $testroot/stdout 2> $testroot/stderr)
1466 ret=$?
1467 if [ $ret -eq 0 ]; then
1468 echo "got stage command succeeded unexpectedly" >&2
1469 test_done "$testroot" "1"
1470 return 1
1472 cat > $testroot/stdout.expected <<EOF
1473 -----------------------------------------------
1474 @@ -1,5 +1,5 @@
1481 -----------------------------------------------
1482 M numbers (change 1 of 3)
1483 stage this change? [y/n/q] n
1484 -----------------------------------------------
1485 @@ -4,7 +4,7 @@
1494 -----------------------------------------------
1495 M numbers (change 2 of 3)
1496 stage this change? [y/n/q] n
1497 -----------------------------------------------
1498 @@ -13,4 +13,4 @@
1502 -16
1504 -----------------------------------------------
1505 M numbers (change 3 of 3)
1506 stage this change? [y/n/q] n
1507 EOF
1508 cmp -s $testroot/stdout.expected $testroot/stdout
1509 ret=$?
1510 if [ $ret -ne 0 ]; then
1511 diff -u $testroot/stdout.expected $testroot/stdout
1512 test_done "$testroot" "$ret"
1513 return 1
1516 echo "got: no changes to stage" > $testroot/stderr.expected
1517 cmp -s $testroot/stderr.expected $testroot/stderr
1518 ret=$?
1519 if [ $ret -ne 0 ]; then
1520 diff -u $testroot/stderr.expected $testroot/stderr
1521 test_done "$testroot" "$ret"
1522 return 1
1526 (cd $testroot/wt && got status > $testroot/stdout)
1527 echo "M numbers" > $testroot/stdout.expected
1528 cmp -s $testroot/stdout.expected $testroot/stdout
1529 ret=$?
1530 if [ $ret -ne 0 ]; then
1531 diff -u $testroot/stdout.expected $testroot/stdout
1532 test_done "$testroot" "$ret"
1533 return 1
1536 # stage middle hunk
1537 printf "n\ny\nn\n" > $testroot/patchscript
1538 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1539 numbers > $testroot/stdout)
1541 cat > $testroot/stdout.expected <<EOF
1542 -----------------------------------------------
1543 @@ -1,5 +1,5 @@
1550 -----------------------------------------------
1551 M numbers (change 1 of 3)
1552 stage this change? [y/n/q] n
1553 -----------------------------------------------
1554 @@ -4,7 +4,7 @@
1563 -----------------------------------------------
1564 M numbers (change 2 of 3)
1565 stage this change? [y/n/q] y
1566 -----------------------------------------------
1567 @@ -13,4 +13,4 @@
1571 -16
1573 -----------------------------------------------
1574 M numbers (change 3 of 3)
1575 stage this change? [y/n/q] n
1576 EOF
1577 cmp -s $testroot/stdout.expected $testroot/stdout
1578 ret=$?
1579 if [ $ret -ne 0 ]; then
1580 diff -u $testroot/stdout.expected $testroot/stdout
1581 test_done "$testroot" "$ret"
1582 return 1
1585 (cd $testroot/wt && got status > $testroot/stdout)
1586 echo "MM numbers" > $testroot/stdout.expected
1587 cmp -s $testroot/stdout.expected $testroot/stdout
1588 ret=$?
1589 if [ $ret -ne 0 ]; then
1590 diff -u $testroot/stdout.expected $testroot/stdout
1591 test_done "$testroot" "$ret"
1592 return 1
1595 (cd $testroot/wt && got diff -s > $testroot/stdout)
1597 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1598 echo "commit - $commit_id" >> $testroot/stdout.expected
1599 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1600 echo -n 'blob - ' >> $testroot/stdout.expected
1601 got tree -r $testroot/repo -i -c $commit_id \
1602 | grep 'numbers$' | cut -d' ' -f 1 \
1603 >> $testroot/stdout.expected
1604 echo -n 'blob + ' >> $testroot/stdout.expected
1605 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1606 >> $testroot/stdout.expected
1607 echo "--- numbers" >> $testroot/stdout.expected
1608 echo "+++ numbers" >> $testroot/stdout.expected
1609 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1610 echo " 4" >> $testroot/stdout.expected
1611 echo " 5" >> $testroot/stdout.expected
1612 echo " 6" >> $testroot/stdout.expected
1613 echo "-7" >> $testroot/stdout.expected
1614 echo "+b" >> $testroot/stdout.expected
1615 echo " 8" >> $testroot/stdout.expected
1616 echo " 9" >> $testroot/stdout.expected
1617 echo " 10" >> $testroot/stdout.expected
1618 cmp -s $testroot/stdout.expected $testroot/stdout
1619 ret=$?
1620 if [ $ret -ne 0 ]; then
1621 diff -u $testroot/stdout.expected $testroot/stdout
1622 test_done "$testroot" "$ret"
1623 return 1
1626 (cd $testroot/wt && got unstage >/dev/null)
1627 ret=$?
1628 if [ $ret -ne 0 ]; then
1629 echo "got stage command failed unexpectedly" >&2
1630 test_done "$testroot" "1"
1631 return 1
1633 (cd $testroot/wt && got status > $testroot/stdout)
1634 echo "M numbers" > $testroot/stdout.expected
1635 cmp -s $testroot/stdout.expected $testroot/stdout
1636 ret=$?
1637 if [ $ret -ne 0 ]; then
1638 diff -u $testroot/stdout.expected $testroot/stdout
1639 test_done "$testroot" "$ret"
1640 return 1
1643 # stage last hunk
1644 printf "n\nn\ny\n" > $testroot/patchscript
1645 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1646 numbers > $testroot/stdout)
1648 cat > $testroot/stdout.expected <<EOF
1649 -----------------------------------------------
1650 @@ -1,5 +1,5 @@
1657 -----------------------------------------------
1658 M numbers (change 1 of 3)
1659 stage this change? [y/n/q] n
1660 -----------------------------------------------
1661 @@ -4,7 +4,7 @@
1670 -----------------------------------------------
1671 M numbers (change 2 of 3)
1672 stage this change? [y/n/q] n
1673 -----------------------------------------------
1674 @@ -13,4 +13,4 @@
1678 -16
1680 -----------------------------------------------
1681 M numbers (change 3 of 3)
1682 stage this change? [y/n/q] y
1683 EOF
1684 cmp -s $testroot/stdout.expected $testroot/stdout
1685 ret=$?
1686 if [ $ret -ne 0 ]; then
1687 diff -u $testroot/stdout.expected $testroot/stdout
1688 test_done "$testroot" "$ret"
1689 return 1
1692 (cd $testroot/wt && got status > $testroot/stdout)
1693 echo "MM numbers" > $testroot/stdout.expected
1694 cmp -s $testroot/stdout.expected $testroot/stdout
1695 ret=$?
1696 if [ $ret -ne 0 ]; then
1697 diff -u $testroot/stdout.expected $testroot/stdout
1698 test_done "$testroot" "$ret"
1699 return 1
1702 (cd $testroot/wt && got diff -s > $testroot/stdout)
1704 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1705 echo "commit - $commit_id" >> $testroot/stdout.expected
1706 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1707 echo -n 'blob - ' >> $testroot/stdout.expected
1708 got tree -r $testroot/repo -i -c $commit_id \
1709 | grep 'numbers$' | cut -d' ' -f 1 \
1710 >> $testroot/stdout.expected
1711 echo -n 'blob + ' >> $testroot/stdout.expected
1712 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1713 >> $testroot/stdout.expected
1714 echo "--- numbers" >> $testroot/stdout.expected
1715 echo "+++ numbers" >> $testroot/stdout.expected
1716 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1717 echo " 13" >> $testroot/stdout.expected
1718 echo " 14" >> $testroot/stdout.expected
1719 echo " 15" >> $testroot/stdout.expected
1720 echo "-16" >> $testroot/stdout.expected
1721 echo "+c" >> $testroot/stdout.expected
1722 cmp -s $testroot/stdout.expected $testroot/stdout
1723 ret=$?
1724 if [ $ret -ne 0 ]; then
1725 diff -u $testroot/stdout.expected $testroot/stdout
1727 test_done "$testroot" "$ret"
1730 test_stage_patch_twice() {
1731 local testroot=`test_init stage_patch_twice`
1733 jot 16 > $testroot/repo/numbers
1734 (cd $testroot/repo && git add numbers)
1735 git_commit $testroot/repo -m "added numbers file"
1736 local commit_id=`git_show_head $testroot/repo`
1738 got checkout $testroot/repo $testroot/wt > /dev/null
1739 ret=$?
1740 if [ $ret -ne 0 ]; then
1741 test_done "$testroot" "$ret"
1742 return 1
1745 ed -s $testroot/wt/numbers <<-\EOF
1746 ,s/^2$/a/
1747 ,s/^7$/b/
1748 ,s/^16$/c/
1750 EOF
1752 # stage middle hunk
1753 printf "n\ny\nn\n" > $testroot/patchscript
1754 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1755 numbers > $testroot/stdout)
1757 cat > $testroot/stdout.expected <<EOF
1758 -----------------------------------------------
1759 @@ -1,5 +1,5 @@
1766 -----------------------------------------------
1767 M numbers (change 1 of 3)
1768 stage this change? [y/n/q] n
1769 -----------------------------------------------
1770 @@ -4,7 +4,7 @@
1779 -----------------------------------------------
1780 M numbers (change 2 of 3)
1781 stage this change? [y/n/q] y
1782 -----------------------------------------------
1783 @@ -13,4 +13,4 @@
1787 -16
1789 -----------------------------------------------
1790 M numbers (change 3 of 3)
1791 stage this change? [y/n/q] n
1792 EOF
1793 cmp -s $testroot/stdout.expected $testroot/stdout
1794 ret=$?
1795 if [ $ret -ne 0 ]; then
1796 diff -u $testroot/stdout.expected $testroot/stdout
1797 test_done "$testroot" "$ret"
1798 return 1
1801 (cd $testroot/wt && got status > $testroot/stdout)
1802 echo "MM numbers" > $testroot/stdout.expected
1803 cmp -s $testroot/stdout.expected $testroot/stdout
1804 ret=$?
1805 if [ $ret -ne 0 ]; then
1806 diff -u $testroot/stdout.expected $testroot/stdout
1807 test_done "$testroot" "$ret"
1808 return 1
1811 # stage last hunk
1812 printf "n\ny\n" > $testroot/patchscript
1813 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1814 numbers > $testroot/stdout)
1816 cat > $testroot/stdout.expected <<EOF
1817 -----------------------------------------------
1818 @@ -1,5 +1,5 @@
1825 -----------------------------------------------
1826 M numbers (change 1 of 2)
1827 stage this change? [y/n/q] n
1828 -----------------------------------------------
1829 @@ -13,4 +13,4 @@ b
1833 -16
1835 -----------------------------------------------
1836 M numbers (change 2 of 2)
1837 stage this change? [y/n/q] y
1838 EOF
1839 cmp -s $testroot/stdout.expected $testroot/stdout
1840 ret=$?
1841 if [ $ret -ne 0 ]; then
1842 diff -u $testroot/stdout.expected $testroot/stdout
1843 test_done "$testroot" "$ret"
1844 return 1
1847 (cd $testroot/wt && got status > $testroot/stdout)
1848 echo "MM numbers" > $testroot/stdout.expected
1849 cmp -s $testroot/stdout.expected $testroot/stdout
1850 ret=$?
1851 if [ $ret -ne 0 ]; then
1852 diff -u $testroot/stdout.expected $testroot/stdout
1853 test_done "$testroot" "$ret"
1854 return 1
1857 (cd $testroot/wt && got diff -s > $testroot/stdout)
1859 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1860 echo "commit - $commit_id" >> $testroot/stdout.expected
1861 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1862 echo -n 'blob - ' >> $testroot/stdout.expected
1863 got tree -r $testroot/repo -i -c $commit_id \
1864 | grep 'numbers$' | cut -d' ' -f 1 \
1865 >> $testroot/stdout.expected
1866 echo -n 'blob + ' >> $testroot/stdout.expected
1867 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1868 >> $testroot/stdout.expected
1869 echo "--- numbers" >> $testroot/stdout.expected
1870 echo "+++ numbers" >> $testroot/stdout.expected
1871 cat >> $testroot/stdout.expected <<EOF
1872 @@ -4,7 +4,7 @@
1881 @@ -13,4 +13,4 @@
1885 -16
1887 EOF
1888 cmp -s $testroot/stdout.expected $testroot/stdout
1889 ret=$?
1890 if [ $ret -ne 0 ]; then
1891 diff -u $testroot/stdout.expected $testroot/stdout
1892 test_done "$testroot" "$ret"
1893 return 1
1896 (cd $testroot/wt && got diff > $testroot/stdout)
1898 echo "diff $testroot/wt" > $testroot/stdout.expected
1899 echo "commit - $commit_id" >> $testroot/stdout.expected
1900 echo "path + $testroot/wt" >> $testroot/stdout.expected
1901 echo -n 'blob - ' >> $testroot/stdout.expected
1902 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1903 tr -d '\n' >> $testroot/stdout.expected
1904 echo " (staged)" >> $testroot/stdout.expected
1905 echo 'file + numbers' >> $testroot/stdout.expected
1906 echo "--- numbers" >> $testroot/stdout.expected
1907 echo "+++ numbers" >> $testroot/stdout.expected
1908 cat >> $testroot/stdout.expected <<EOF
1909 @@ -1,5 +1,5 @@
1916 EOF
1917 cmp -s $testroot/stdout.expected $testroot/stdout
1918 ret=$?
1919 if [ $ret -ne 0 ]; then
1920 diff -u $testroot/stdout.expected $testroot/stdout
1922 test_done "$testroot" "$ret"
1925 test_stage_patch_added() {
1926 local testroot=`test_init stage_patch_added`
1927 local commit_id=`git_show_head $testroot/repo`
1929 got checkout $testroot/repo $testroot/wt > /dev/null
1930 ret=$?
1931 if [ $ret -ne 0 ]; then
1932 test_done "$testroot" "$ret"
1933 return 1
1936 echo "new" > $testroot/wt/epsilon/new
1937 (cd $testroot/wt && got add epsilon/new > /dev/null)
1939 printf "y\n" > $testroot/patchscript
1940 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1941 epsilon/new > $testroot/stdout)
1943 echo "A epsilon/new" > $testroot/stdout.expected
1944 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1945 cmp -s $testroot/stdout.expected $testroot/stdout
1946 ret=$?
1947 if [ $ret -ne 0 ]; then
1948 diff -u $testroot/stdout.expected $testroot/stdout
1949 test_done "$testroot" "$ret"
1950 return 1
1953 (cd $testroot/wt && got status > $testroot/stdout)
1954 echo " A epsilon/new" > $testroot/stdout.expected
1955 cmp -s $testroot/stdout.expected $testroot/stdout
1956 ret=$?
1957 if [ $ret -ne 0 ]; then
1958 diff -u $testroot/stdout.expected $testroot/stdout
1959 test_done "$testroot" "$ret"
1960 return 1
1963 (cd $testroot/wt && got diff -s > $testroot/stdout)
1965 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1966 echo "commit - $commit_id" >> $testroot/stdout.expected
1967 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1968 echo 'blob - /dev/null' >> $testroot/stdout.expected
1969 echo -n 'blob + ' >> $testroot/stdout.expected
1970 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1971 >> $testroot/stdout.expected
1972 echo "--- /dev/null" >> $testroot/stdout.expected
1973 echo "+++ epsilon/new" >> $testroot/stdout.expected
1974 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1975 echo "+new" >> $testroot/stdout.expected
1976 cmp -s $testroot/stdout.expected $testroot/stdout
1977 ret=$?
1978 if [ $ret -ne 0 ]; then
1979 diff -u $testroot/stdout.expected $testroot/stdout
1981 test_done "$testroot" "$ret"
1984 test_stage_patch_added_twice() {
1985 local testroot=`test_init stage_patch_added_twice`
1986 local commit_id=`git_show_head $testroot/repo`
1988 got checkout $testroot/repo $testroot/wt > /dev/null
1989 ret=$?
1990 if [ $ret -ne 0 ]; then
1991 test_done "$testroot" "$ret"
1992 return 1
1995 echo "new" > $testroot/wt/epsilon/new
1996 (cd $testroot/wt && got add epsilon/new > /dev/null)
1998 printf "y\n" > $testroot/patchscript
1999 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2000 epsilon/new > $testroot/stdout)
2002 echo "A epsilon/new" > $testroot/stdout.expected
2003 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
2004 cmp -s $testroot/stdout.expected $testroot/stdout
2005 ret=$?
2006 if [ $ret -ne 0 ]; then
2007 diff -u $testroot/stdout.expected $testroot/stdout
2008 test_done "$testroot" "$ret"
2009 return 1
2012 (cd $testroot/wt && got status > $testroot/stdout)
2013 echo " A epsilon/new" > $testroot/stdout.expected
2014 cmp -s $testroot/stdout.expected $testroot/stdout
2015 ret=$?
2016 if [ $ret -ne 0 ]; then
2017 diff -u $testroot/stdout.expected $testroot/stdout
2018 test_done "$testroot" "$ret"
2019 return 1
2022 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2023 epsilon/new > $testroot/stdout 2> $testroot/stderr)
2024 ret=$?
2025 if [ $ret -eq 0 ]; then
2026 echo "got stage command succeeded unexpectedly" >&2
2027 test_done "$testroot" "1"
2028 return 1
2031 echo "got: no changes to stage" > $testroot/stderr.expected
2032 cmp -s $testroot/stderr.expected $testroot/stderr
2033 ret=$?
2034 if [ $ret -ne 0 ]; then
2035 diff -u $testroot/stderr.expected $testroot/stderr
2036 test_done "$testroot" "$ret"
2037 return 1
2040 echo -n > $testroot/stdout.expected
2041 cmp -s $testroot/stdout.expected $testroot/stdout
2042 ret=$?
2043 if [ $ret -ne 0 ]; then
2044 diff -u $testroot/stdout.expected $testroot/stdout
2046 test_done "$testroot" "$ret"
2049 test_stage_patch_removed() {
2050 local testroot=`test_init stage_patch_removed`
2051 local commit_id=`git_show_head $testroot/repo`
2053 got checkout $testroot/repo $testroot/wt > /dev/null
2054 ret=$?
2055 if [ $ret -ne 0 ]; then
2056 test_done "$testroot" "$ret"
2057 return 1
2060 (cd $testroot/wt && got rm beta > /dev/null)
2062 printf "y\n" > $testroot/patchscript
2063 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2064 beta > $testroot/stdout)
2066 echo -n > $testroot/stdout.expected
2068 echo "D beta" > $testroot/stdout.expected
2069 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2070 cmp -s $testroot/stdout.expected $testroot/stdout
2071 ret=$?
2072 if [ $ret -ne 0 ]; then
2073 diff -u $testroot/stdout.expected $testroot/stdout
2074 test_done "$testroot" "$ret"
2075 return 1
2078 (cd $testroot/wt && got status > $testroot/stdout)
2079 echo " D beta" > $testroot/stdout.expected
2080 cmp -s $testroot/stdout.expected $testroot/stdout
2081 ret=$?
2082 if [ $ret -ne 0 ]; then
2083 diff -u $testroot/stdout.expected $testroot/stdout
2084 test_done "$testroot" "$ret"
2085 return 1
2088 (cd $testroot/wt && got diff -s > $testroot/stdout)
2090 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2091 echo "commit - $commit_id" >> $testroot/stdout.expected
2092 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2093 echo -n 'blob - ' >> $testroot/stdout.expected
2094 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2095 >> $testroot/stdout.expected
2096 echo 'blob + /dev/null' >> $testroot/stdout.expected
2097 echo "--- beta" >> $testroot/stdout.expected
2098 echo "+++ /dev/null" >> $testroot/stdout.expected
2099 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2100 echo "-beta" >> $testroot/stdout.expected
2101 cmp -s $testroot/stdout.expected $testroot/stdout
2102 ret=$?
2103 if [ $ret -ne 0 ]; then
2104 diff -u $testroot/stdout.expected $testroot/stdout
2106 test_done "$testroot" "$ret"
2109 test_stage_patch_removed_twice() {
2110 local testroot=`test_init stage_patch_removed_twice`
2111 local commit_id=`git_show_head $testroot/repo`
2113 got checkout $testroot/repo $testroot/wt > /dev/null
2114 ret=$?
2115 if [ $ret -ne 0 ]; then
2116 test_done "$testroot" "$ret"
2117 return 1
2120 (cd $testroot/wt && got rm beta > /dev/null)
2122 printf "y\n" > $testroot/patchscript
2123 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2124 beta > $testroot/stdout)
2126 echo -n > $testroot/stdout.expected
2128 echo "D beta" > $testroot/stdout.expected
2129 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2130 cmp -s $testroot/stdout.expected $testroot/stdout
2131 ret=$?
2132 if [ $ret -ne 0 ]; then
2133 diff -u $testroot/stdout.expected $testroot/stdout
2134 test_done "$testroot" "$ret"
2135 return 1
2138 (cd $testroot/wt && got status > $testroot/stdout)
2139 echo " D beta" > $testroot/stdout.expected
2140 cmp -s $testroot/stdout.expected $testroot/stdout
2141 ret=$?
2142 if [ $ret -ne 0 ]; then
2143 diff -u $testroot/stdout.expected $testroot/stdout
2144 test_done "$testroot" "$ret"
2145 return 1
2148 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2149 > $testroot/stdout 2> $testroot/stderr)
2150 ret=$?
2151 if [ $ret -eq 0 ]; then
2152 echo "got stage command succeeded unexpectedly" >&2
2153 test_done "$testroot" "$ret"
2154 return 1
2157 echo "got: no changes to stage" > $testroot/stderr.expected
2158 cmp -s $testroot/stderr.expected $testroot/stderr
2159 ret=$?
2160 if [ $ret -ne 0 ]; then
2161 diff -u $testroot/stderr.expected $testroot/stderr
2162 test_done "$testroot" "$ret"
2163 return 1
2166 echo -n > $testroot/stdout.expected
2167 cmp -s $testroot/stdout.expected $testroot/stdout
2168 ret=$?
2169 if [ $ret -ne 0 ]; then
2170 diff -u $testroot/stdout.expected $testroot/stdout
2172 test_done "$testroot" "$ret"
2175 test_stage_patch_reversed() {
2176 local testroot=`test_init stage_patch_reversed`
2178 got checkout $testroot/repo $testroot/wt > /dev/null
2179 ret=$?
2180 if [ $ret -ne 0 ]; then
2181 test_done "$testroot" "$ret"
2182 return 1
2185 echo 'ALPHA' > $testroot/wt/alpha
2186 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2187 ret=$?
2188 if [ $ret -ne 0 ]; then
2189 test_done "$testroot" "$ret"
2190 return 1
2193 echo ' M alpha' > $testroot/stdout.expected
2194 cmp -s $testroot/stdout.expected $testroot/stdout
2195 ret=$?
2196 if [ $ret -ne 0 ]; then
2197 diff -u $testroot/stdout.expected $testroot/stdout
2198 test_done "$testroot" "$ret"
2199 return 1
2202 echo 'alpha' > $testroot/wt/alpha
2203 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2204 ret=$?
2205 if [ $ret -ne 0 ]; then
2206 test_done "$testroot" "$ret"
2207 return 1
2210 echo ' M alpha' > $testroot/stdout.expected
2211 cmp -s $testroot/stdout.expected $testroot/stdout
2212 ret=$?
2213 if [ $ret -ne 0 ]; then
2214 diff -u $testroot/stdout.expected $testroot/stdout
2215 test_done "$testroot" "$ret"
2216 return 1
2219 (cd $testroot/wt && got status > $testroot/stdout)
2220 cmp -s /dev/null $testroot/stdout
2221 ret=$?
2222 if [ $ret -ne 0 ]; then
2223 diff -u /dev/null $testroot/stdout
2225 test_done "$testroot" "$ret"
2228 test_stage_patch_quit() {
2229 local testroot=`test_init stage_patch_quit`
2231 jot 16 > $testroot/repo/numbers
2232 echo zzz > $testroot/repo/zzz
2233 (cd $testroot/repo && git add numbers zzz)
2234 git_commit $testroot/repo -m "added files"
2235 local commit_id=`git_show_head $testroot/repo`
2237 got checkout $testroot/repo $testroot/wt > /dev/null
2238 ret=$?
2239 if [ $ret -ne 0 ]; then
2240 test_done "$testroot" "$ret"
2241 return 1
2244 ed -s $testroot/wt/numbers <<-\EOF
2245 ,s/^2$/a/
2246 ,s/^7$/b/
2247 ,s/^16$/c/
2249 EOF
2250 (cd $testroot/wt && got rm zzz > /dev/null)
2252 # stage first hunk and quit; and don't pass a path argument to
2253 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2254 printf "y\nq\nn\n" > $testroot/patchscript
2255 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2256 > $testroot/stdout)
2257 ret=$?
2258 if [ $ret -ne 0 ]; then
2259 echo "got stage command failed unexpectedly" >&2
2260 test_done "$testroot" "1"
2261 return 1
2263 cat > $testroot/stdout.expected <<EOF
2264 -----------------------------------------------
2265 @@ -1,5 +1,5 @@
2272 -----------------------------------------------
2273 M numbers (change 1 of 3)
2274 stage this change? [y/n/q] y
2275 -----------------------------------------------
2276 @@ -4,7 +4,7 @@
2285 -----------------------------------------------
2286 M numbers (change 2 of 3)
2287 stage this change? [y/n/q] q
2288 D zzz
2289 stage this deletion? [y/n] n
2290 EOF
2291 cmp -s $testroot/stdout.expected $testroot/stdout
2292 ret=$?
2293 if [ $ret -ne 0 ]; then
2294 diff -u $testroot/stdout.expected $testroot/stdout
2295 test_done "$testroot" "$ret"
2296 return 1
2299 (cd $testroot/wt && got status > $testroot/stdout)
2300 echo "MM numbers" > $testroot/stdout.expected
2301 echo "D zzz" >> $testroot/stdout.expected
2302 cmp -s $testroot/stdout.expected $testroot/stdout
2303 ret=$?
2304 if [ $ret -ne 0 ]; then
2305 diff -u $testroot/stdout.expected $testroot/stdout
2306 test_done "$testroot" "$ret"
2307 return 1
2310 (cd $testroot/wt && got diff -s > $testroot/stdout)
2312 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2313 echo "commit - $commit_id" >> $testroot/stdout.expected
2314 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2315 echo -n 'blob - ' >> $testroot/stdout.expected
2316 got tree -r $testroot/repo -i -c $commit_id \
2317 | grep 'numbers$' | cut -d' ' -f 1 \
2318 >> $testroot/stdout.expected
2319 echo -n 'blob + ' >> $testroot/stdout.expected
2320 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2321 >> $testroot/stdout.expected
2322 echo "--- numbers" >> $testroot/stdout.expected
2323 echo "+++ numbers" >> $testroot/stdout.expected
2324 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2325 echo " 1" >> $testroot/stdout.expected
2326 echo "-2" >> $testroot/stdout.expected
2327 echo "+a" >> $testroot/stdout.expected
2328 echo " 3" >> $testroot/stdout.expected
2329 echo " 4" >> $testroot/stdout.expected
2330 echo " 5" >> $testroot/stdout.expected
2331 cmp -s $testroot/stdout.expected $testroot/stdout
2332 ret=$?
2333 if [ $ret -ne 0 ]; then
2334 diff -u $testroot/stdout.expected $testroot/stdout
2336 test_done "$testroot" "$ret"
2340 test_stage_patch_incomplete_script() {
2341 local testroot=`test_init stage_incomplete_script`
2343 jot 16 > $testroot/repo/numbers
2344 echo zzz > $testroot/repo/zzz
2345 (cd $testroot/repo && git add numbers zzz)
2346 git_commit $testroot/repo -m "added files"
2347 local commit_id=`git_show_head $testroot/repo`
2349 got checkout $testroot/repo $testroot/wt > /dev/null
2350 ret=$?
2351 if [ $ret -ne 0 ]; then
2352 test_done "$testroot" "$ret"
2353 return 1
2356 ed -s $testroot/wt/numbers <<-\EOF
2357 ,s/^2$/a/
2358 ,s/^7$/b/
2359 ,s/^16$/c/
2361 EOF
2363 # stage first hunk and then stop responding; got should error out
2364 printf "y\n" > $testroot/patchscript
2365 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2366 > $testroot/stdout 2> $testroot/stderr)
2367 ret=$?
2368 if [ $ret -eq 0 ]; then
2369 echo "got stage command succeeded unexpectedly" >&2
2370 test_done "$testroot" "1"
2371 return 1
2373 cat > $testroot/stdout.expected <<EOF
2374 -----------------------------------------------
2375 @@ -1,5 +1,5 @@
2382 -----------------------------------------------
2383 M numbers (change 1 of 3)
2384 stage this change? [y/n/q] y
2385 -----------------------------------------------
2386 @@ -4,7 +4,7 @@
2395 -----------------------------------------------
2396 M numbers (change 2 of 3)
2397 EOF
2398 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2399 echo "got: invalid patch choice" > $testroot/stderr.expected
2400 cmp -s $testroot/stderr.expected $testroot/stderr
2401 ret=$?
2402 if [ $ret -ne 0 ]; then
2403 diff -u $testroot/stderr.expected $testroot/stderr
2404 test_done "$testroot" "$ret"
2405 return 1
2408 cmp -s $testroot/stdout.expected $testroot/stdout
2409 ret=$?
2410 if [ $ret -ne 0 ]; then
2411 diff -u $testroot/stdout.expected $testroot/stdout
2412 test_done "$testroot" "$ret"
2413 return 1
2416 (cd $testroot/wt && got status > $testroot/stdout)
2417 echo "M numbers" > $testroot/stdout.expected
2418 cmp -s $testroot/stdout.expected $testroot/stdout
2419 ret=$?
2420 if [ $ret -ne 0 ]; then
2421 diff -u $testroot/stdout.expected $testroot/stdout
2422 test_done "$testroot" "$ret"
2423 return 1
2426 (cd $testroot/wt && got diff -s > $testroot/stdout)
2427 echo -n > $testroot/stdout.expected
2428 cmp -s $testroot/stdout.expected $testroot/stdout
2429 ret=$?
2430 if [ $ret -ne 0 ]; then
2431 diff -u $testroot/stdout.expected $testroot/stdout
2433 test_done "$testroot" "$ret"
2437 test_stage_symlink() {
2438 local testroot=`test_init stage_symlink`
2440 (cd $testroot/repo && ln -s alpha alpha.link)
2441 (cd $testroot/repo && ln -s epsilon epsilon.link)
2442 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2443 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2444 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2445 (cd $testroot/repo && git add .)
2446 git_commit $testroot/repo -m "add symlinks"
2447 local head_commit=`git_show_head $testroot/repo`
2449 got checkout $testroot/repo $testroot/wt > /dev/null
2450 ret=$?
2451 if [ $ret -ne 0 ]; then
2452 test_done "$testroot" "$ret"
2453 return 1
2456 (cd $testroot/wt && ln -sf beta alpha.link)
2457 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
2458 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2459 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2460 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2461 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2462 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2463 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2464 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2465 (cd $testroot/wt && got add zeta.link > /dev/null)
2467 (cd $testroot/wt && got stage > $testroot/stdout 2> $testroot/stderr)
2468 ret=$?
2469 if [ $ret -eq 0 ]; then
2470 echo "got stage succeeded unexpectedly" >&2
2471 test_done "$testroot" 1
2472 return 1
2474 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
2475 echo "symbolic link points outside of paths under version control" \
2476 >> $testroot/stderr.expected
2477 cmp -s $testroot/stderr.expected $testroot/stderr
2478 ret=$?
2479 if [ $ret -ne 0 ]; then
2480 diff -u $testroot/stderr.expected $testroot/stderr
2481 test_done "$testroot" "$ret"
2482 return 1
2485 (cd $testroot/wt && got stage -S > $testroot/stdout)
2487 cat > $testroot/stdout.expected <<EOF
2488 M alpha.link
2489 A dotgotbar.link
2490 A dotgotfoo.link
2491 M epsilon/beta.link
2492 M epsilon.link
2493 D nonexistent.link
2494 A zeta.link
2495 EOF
2496 cmp -s $testroot/stdout.expected $testroot/stdout
2497 ret=$?
2498 if [ $ret -ne 0 ]; then
2499 diff -u $testroot/stdout.expected $testroot/stdout
2500 test_done "$testroot" "$ret"
2501 return 1
2504 rm $testroot/wt/alpha.link
2505 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2507 (cd $testroot/wt && got diff -s > $testroot/stdout)
2509 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2510 echo "commit - $head_commit" >> $testroot/stdout.expected
2511 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2512 echo -n 'blob - ' >> $testroot/stdout.expected
2513 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2514 cut -d' ' -f 1 >> $testroot/stdout.expected
2515 echo -n 'blob + ' >> $testroot/stdout.expected
2516 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2517 >> $testroot/stdout.expected
2518 echo '--- alpha.link' >> $testroot/stdout.expected
2519 echo '+++ alpha.link' >> $testroot/stdout.expected
2520 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2521 echo '-alpha' >> $testroot/stdout.expected
2522 echo '\ No newline at end of file' >> $testroot/stdout.expected
2523 echo '+beta' >> $testroot/stdout.expected
2524 echo '\ No newline at end of file' >> $testroot/stdout.expected
2525 echo 'blob - /dev/null' >> $testroot/stdout.expected
2526 echo -n 'blob + ' >> $testroot/stdout.expected
2527 (cd $testroot/wt && got stage -l dotgotbar.link) | cut -d' ' -f 1 \
2528 >> $testroot/stdout.expected
2529 echo '--- /dev/null' >> $testroot/stdout.expected
2530 echo '+++ dotgotbar.link' >> $testroot/stdout.expected
2531 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2532 echo '+.got/bar' >> $testroot/stdout.expected
2533 echo '\ No newline at end of file' >> $testroot/stdout.expected
2534 echo 'blob - /dev/null' >> $testroot/stdout.expected
2535 echo -n 'blob + ' >> $testroot/stdout.expected
2536 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2537 >> $testroot/stdout.expected
2538 echo '--- /dev/null' >> $testroot/stdout.expected
2539 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2540 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2541 echo '+this is regular file foo' >> $testroot/stdout.expected
2542 echo -n 'blob - ' >> $testroot/stdout.expected
2543 got tree -r $testroot/repo -i epsilon | grep 'beta.link@ -> ../beta$' | \
2544 cut -d' ' -f 1 >> $testroot/stdout.expected
2545 echo -n 'blob + ' >> $testroot/stdout.expected
2546 (cd $testroot/wt && got stage -l epsilon/beta.link) | cut -d' ' -f 1 \
2547 >> $testroot/stdout.expected
2548 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
2549 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
2550 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2551 echo '-../beta' >> $testroot/stdout.expected
2552 echo '\ No newline at end of file' >> $testroot/stdout.expected
2553 echo '+../gamma/delta' >> $testroot/stdout.expected
2554 echo '\ No newline at end of file' >> $testroot/stdout.expected
2555 echo -n 'blob - ' >> $testroot/stdout.expected
2556 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2557 cut -d' ' -f 1 >> $testroot/stdout.expected
2558 echo -n 'blob + ' >> $testroot/stdout.expected
2559 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2560 >> $testroot/stdout.expected
2561 echo '--- epsilon.link' >> $testroot/stdout.expected
2562 echo '+++ epsilon.link' >> $testroot/stdout.expected
2563 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2564 echo '-epsilon' >> $testroot/stdout.expected
2565 echo '\ No newline at end of file' >> $testroot/stdout.expected
2566 echo '+gamma' >> $testroot/stdout.expected
2567 echo '\ No newline at end of file' >> $testroot/stdout.expected
2568 echo -n 'blob - ' >> $testroot/stdout.expected
2569 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2570 cut -d' ' -f 1 >> $testroot/stdout.expected
2571 echo 'blob + /dev/null' >> $testroot/stdout.expected
2572 echo '--- nonexistent.link' >> $testroot/stdout.expected
2573 echo '+++ /dev/null' >> $testroot/stdout.expected
2574 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2575 echo '-nonexistent' >> $testroot/stdout.expected
2576 echo '\ No newline at end of file' >> $testroot/stdout.expected
2577 echo 'blob - /dev/null' >> $testroot/stdout.expected
2578 echo -n 'blob + ' >> $testroot/stdout.expected
2579 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2580 >> $testroot/stdout.expected
2581 echo '--- /dev/null' >> $testroot/stdout.expected
2582 echo '+++ zeta.link' >> $testroot/stdout.expected
2583 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2584 echo '+gamma/delta' >> $testroot/stdout.expected
2585 echo '\ No newline at end of file' >> $testroot/stdout.expected
2587 cmp -s $testroot/stdout.expected $testroot/stdout
2588 ret=$?
2589 if [ $ret -ne 0 ]; then
2590 diff -u $testroot/stdout.expected $testroot/stdout
2591 test_done "$testroot" "$ret"
2592 return 1
2595 (cd $testroot/wt && got commit -m "staged symlink" \
2596 > $testroot/stdout)
2597 ret=$?
2598 if [ $ret -ne 0 ]; then
2599 echo "got commit command failed unexpectedly" >&2
2600 test_done "$testroot" "1"
2601 return 1
2604 local commit_id=`git_show_head $testroot/repo`
2605 echo "A dotgotbar.link" > $testroot/stdout.expected
2606 echo "A dotgotfoo.link" >> $testroot/stdout.expected
2607 echo "A zeta.link" >> $testroot/stdout.expected
2608 echo "M alpha.link" >> $testroot/stdout.expected
2609 echo "M epsilon/beta.link" >> $testroot/stdout.expected
2610 echo "M epsilon.link" >> $testroot/stdout.expected
2611 echo "D nonexistent.link" >> $testroot/stdout.expected
2612 echo "Created commit $commit_id" >> $testroot/stdout.expected
2613 cmp -s $testroot/stdout.expected $testroot/stdout
2614 ret=$?
2615 if [ $ret -ne 0 ]; then
2616 diff -u $testroot/stdout.expected $testroot/stdout
2617 test_done "$testroot" "$ret"
2618 return 1
2621 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2622 ret=$?
2623 if [ $ret -ne 0 ]; then
2624 echo "got tree command failed unexpectedly" >&2
2625 test_done "$testroot" "1"
2626 return 1
2629 cat > $testroot/stdout.expected <<EOF
2630 alpha
2631 alpha.link@ -> beta
2632 beta
2633 dotgotbar.link@ -> .got/bar
2634 dotgotfoo.link
2635 epsilon/
2636 epsilon.link@ -> gamma
2637 gamma/
2638 passwd.link@ -> /etc/passwd
2639 zeta.link@ -> gamma/delta
2640 EOF
2641 cmp -s $testroot/stdout.expected $testroot/stdout
2642 ret=$?
2643 if [ $ret -ne 0 ]; then
2644 diff -u $testroot/stdout.expected $testroot/stdout
2645 return 1
2648 if [ -h $testroot/wt/alpha.link ]; then
2649 echo "alpha.link is a symlink"
2650 test_done "$testroot" "1"
2651 return 1
2654 echo 'this is regular file alpha.link' > $testroot/content.expected
2655 cp $testroot/wt/alpha.link $testroot/content
2656 cmp -s $testroot/content.expected $testroot/content
2657 ret=$?
2658 if [ $ret -ne 0 ]; then
2659 diff -u $testroot/content.expected $testroot/content
2660 test_done "$testroot" "$ret"
2661 return 1
2664 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2665 echo "dotgotbar.link is not a symlink"
2666 test_done "$testroot" "1"
2667 return 1
2669 (cd $testroot/wt && got update > /dev/null)
2670 if [ -h $testroot/wt/dotgotbar.link ]; then
2671 echo "dotgotbar.link is a symlink"
2672 test_done "$testroot" "1"
2673 return 1
2675 echo -n ".got/bar" > $testroot/content.expected
2676 cp $testroot/wt/dotgotbar.link $testroot/content
2677 cmp -s $testroot/content.expected $testroot/content
2678 ret=$?
2679 if [ $ret -ne 0 ]; then
2680 diff -u $testroot/content.expected $testroot/content
2681 test_done "$testroot" "$ret"
2682 return 1
2685 if [ -h $testroot/wt/dotgotfoo.link ]; then
2686 echo "dotgotfoo.link is a symlink"
2687 test_done "$testroot" "1"
2688 return 1
2690 echo "this is regular file foo" > $testroot/content.expected
2691 cp $testroot/wt/dotgotfoo.link $testroot/content
2692 cmp -s $testroot/content.expected $testroot/content
2693 ret=$?
2694 if [ $ret -ne 0 ]; then
2695 diff -u $testroot/content.expected $testroot/content
2696 test_done "$testroot" "$ret"
2697 return 1
2700 if ! [ -h $testroot/wt/epsilon.link ]; then
2701 echo "epsilon.link is not a symlink"
2702 test_done "$testroot" "1"
2703 return 1
2706 readlink $testroot/wt/epsilon.link > $testroot/stdout
2707 echo "gamma" > $testroot/stdout.expected
2708 cmp -s $testroot/stdout.expected $testroot/stdout
2709 ret=$?
2710 if [ $ret -ne 0 ]; then
2711 diff -u $testroot/stdout.expected $testroot/stdout
2712 test_done "$testroot" "$ret"
2713 return 1
2716 if [ -h $testroot/wt/passwd.link ]; then
2717 echo "passwd.link is a symlink"
2718 test_done "$testroot" "1"
2719 return 1
2721 echo -n "/etc/passwd" > $testroot/content.expected
2722 cp $testroot/wt/passwd.link $testroot/content
2723 cmp -s $testroot/content.expected $testroot/content
2724 ret=$?
2725 if [ $ret -ne 0 ]; then
2726 diff -u $testroot/content.expected $testroot/content
2727 test_done "$testroot" "$ret"
2728 return 1
2731 if ! [ -h $testroot/wt/zeta.link ]; then
2732 echo "zeta.link is not a symlink"
2733 test_done "$testroot" "1"
2734 return 1
2737 readlink $testroot/wt/zeta.link > $testroot/stdout
2738 echo "gamma/delta" > $testroot/stdout.expected
2739 cmp -s $testroot/stdout.expected $testroot/stdout
2740 ret=$?
2741 if [ $ret -ne 0 ]; then
2742 diff -u $testroot/stdout.expected $testroot/stdout
2743 test_done "$testroot" "$ret"
2744 return 1
2747 test_done "$testroot" "0"
2750 test_stage_patch_symlink() {
2751 local testroot=`test_init stage_patch_symlink`
2753 (cd $testroot/repo && ln -s alpha alpha.link)
2754 (cd $testroot/repo && ln -s epsilon epsilon.link)
2755 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2756 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2757 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2758 (cd $testroot/repo && git add .)
2759 git_commit $testroot/repo -m "add symlinks"
2760 local head_commit=`git_show_head $testroot/repo`
2762 got checkout $testroot/repo $testroot/wt > /dev/null
2763 ret=$?
2764 if [ $ret -ne 0 ]; then
2765 test_done "$testroot" "$ret"
2766 return 1
2769 (cd $testroot/wt && ln -sf beta alpha.link)
2770 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
2771 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2772 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2773 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2774 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2775 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2776 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2777 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2778 (cd $testroot/wt && got add zeta.link > /dev/null)
2780 printf "y\nn\ny\nn\ny\ny\ny" > $testroot/patchscript
2781 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2782 > $testroot/stdout)
2784 cat > $testroot/stdout.expected <<EOF
2785 -----------------------------------------------
2786 @@ -1 +1 @@
2787 -alpha
2788 \ No newline at end of file
2789 +beta
2790 \ No newline at end of file
2791 -----------------------------------------------
2792 M alpha.link (change 1 of 1)
2793 stage this change? [y/n/q] y
2794 A dotgotbar.link
2795 stage this addition? [y/n] n
2796 A dotgotfoo.link
2797 stage this addition? [y/n] y
2798 -----------------------------------------------
2799 @@ -1 +1 @@
2800 -../beta
2801 \ No newline at end of file
2802 +../gamma/delta
2803 \ No newline at end of file
2804 -----------------------------------------------
2805 M epsilon/beta.link (change 1 of 1)
2806 stage this change? [y/n/q] n
2807 -----------------------------------------------
2808 @@ -1 +1 @@
2809 -epsilon
2810 \ No newline at end of file
2811 +gamma
2812 \ No newline at end of file
2813 -----------------------------------------------
2814 M epsilon.link (change 1 of 1)
2815 stage this change? [y/n/q] y
2816 D nonexistent.link
2817 stage this deletion? [y/n] y
2818 A zeta.link
2819 stage this addition? [y/n] y
2820 EOF
2821 cmp -s $testroot/stdout.expected $testroot/stdout
2822 ret=$?
2823 if [ $ret -ne 0 ]; then
2824 diff -u $testroot/stdout.expected $testroot/stdout
2825 test_done "$testroot" "$ret"
2826 return 1
2829 rm $testroot/wt/alpha.link
2830 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2832 (cd $testroot/wt && got diff -s > $testroot/stdout)
2834 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2835 echo "commit - $head_commit" >> $testroot/stdout.expected
2836 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2837 echo -n 'blob - ' >> $testroot/stdout.expected
2838 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2839 cut -d' ' -f 1 >> $testroot/stdout.expected
2840 echo -n 'blob + ' >> $testroot/stdout.expected
2841 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2842 >> $testroot/stdout.expected
2843 echo '--- alpha.link' >> $testroot/stdout.expected
2844 echo '+++ alpha.link' >> $testroot/stdout.expected
2845 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2846 echo '-alpha' >> $testroot/stdout.expected
2847 echo '\ No newline at end of file' >> $testroot/stdout.expected
2848 echo '+beta' >> $testroot/stdout.expected
2849 echo '\ No newline at end of file' >> $testroot/stdout.expected
2850 echo 'blob - /dev/null' >> $testroot/stdout.expected
2851 echo -n 'blob + ' >> $testroot/stdout.expected
2852 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2853 >> $testroot/stdout.expected
2854 echo '--- /dev/null' >> $testroot/stdout.expected
2855 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2856 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2857 echo '+this is regular file foo' >> $testroot/stdout.expected
2858 echo -n 'blob - ' >> $testroot/stdout.expected
2859 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2860 cut -d' ' -f 1 >> $testroot/stdout.expected
2861 echo -n 'blob + ' >> $testroot/stdout.expected
2862 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2863 >> $testroot/stdout.expected
2864 echo '--- epsilon.link' >> $testroot/stdout.expected
2865 echo '+++ epsilon.link' >> $testroot/stdout.expected
2866 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2867 echo '-epsilon' >> $testroot/stdout.expected
2868 echo '\ No newline at end of file' >> $testroot/stdout.expected
2869 echo '+gamma' >> $testroot/stdout.expected
2870 echo '\ No newline at end of file' >> $testroot/stdout.expected
2871 echo -n 'blob - ' >> $testroot/stdout.expected
2872 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2873 cut -d' ' -f 1 >> $testroot/stdout.expected
2874 echo 'blob + /dev/null' >> $testroot/stdout.expected
2875 echo '--- nonexistent.link' >> $testroot/stdout.expected
2876 echo '+++ /dev/null' >> $testroot/stdout.expected
2877 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2878 echo '-nonexistent' >> $testroot/stdout.expected
2879 echo '\ No newline at end of file' >> $testroot/stdout.expected
2880 echo 'blob - /dev/null' >> $testroot/stdout.expected
2881 echo -n 'blob + ' >> $testroot/stdout.expected
2882 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2883 >> $testroot/stdout.expected
2884 echo '--- /dev/null' >> $testroot/stdout.expected
2885 echo '+++ zeta.link' >> $testroot/stdout.expected
2886 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2887 echo '+gamma/delta' >> $testroot/stdout.expected
2888 echo '\ No newline at end of file' >> $testroot/stdout.expected
2890 cmp -s $testroot/stdout.expected $testroot/stdout
2891 ret=$?
2892 if [ $ret -ne 0 ]; then
2893 diff -u $testroot/stdout.expected $testroot/stdout
2894 test_done "$testroot" "$ret"
2895 return 1
2898 (cd $testroot/wt && got commit -m "staged symlink" \
2899 > $testroot/stdout)
2900 ret=$?
2901 if [ $ret -ne 0 ]; then
2902 echo "got commit command failed unexpectedly" >&2
2903 test_done "$testroot" "1"
2904 return 1
2907 local commit_id=`git_show_head $testroot/repo`
2908 echo "A dotgotfoo.link" > $testroot/stdout.expected
2909 echo "A zeta.link" >> $testroot/stdout.expected
2910 echo "M alpha.link" >> $testroot/stdout.expected
2911 echo "M epsilon.link" >> $testroot/stdout.expected
2912 echo "D nonexistent.link" >> $testroot/stdout.expected
2913 echo "Created commit $commit_id" >> $testroot/stdout.expected
2914 cmp -s $testroot/stdout.expected $testroot/stdout
2915 ret=$?
2916 if [ $ret -ne 0 ]; then
2917 diff -u $testroot/stdout.expected $testroot/stdout
2918 test_done "$testroot" "$ret"
2919 return 1
2922 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2923 ret=$?
2924 if [ $ret -ne 0 ]; then
2925 echo "got tree command failed unexpectedly" >&2
2926 test_done "$testroot" "1"
2927 return 1
2930 cat > $testroot/stdout.expected <<EOF
2931 alpha
2932 alpha.link@ -> beta
2933 beta
2934 dotgotfoo.link
2935 epsilon/
2936 epsilon.link@ -> gamma
2937 gamma/
2938 passwd.link@ -> /etc/passwd
2939 zeta.link@ -> gamma/delta
2940 EOF
2941 cmp -s $testroot/stdout.expected $testroot/stdout
2942 ret=$?
2943 if [ $ret -ne 0 ]; then
2944 diff -u $testroot/stdout.expected $testroot/stdout
2945 return 1
2948 if [ -h $testroot/wt/alpha.link ]; then
2949 echo "alpha.link is a symlink"
2950 test_done "$testroot" "1"
2951 return 1
2954 echo 'this is regular file alpha.link' > $testroot/content.expected
2955 cp $testroot/wt/alpha.link $testroot/content
2956 cmp -s $testroot/content.expected $testroot/content
2957 ret=$?
2958 if [ $ret -ne 0 ]; then
2959 diff -u $testroot/content.expected $testroot/content
2960 test_done "$testroot" "$ret"
2961 return 1
2964 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2965 echo "dotgotbar.link is not a symlink"
2966 test_done "$testroot" "1"
2967 return 1
2969 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
2970 echo ".got/bar" > $testroot/stdout.expected
2971 cmp -s $testroot/stdout.expected $testroot/stdout
2972 ret=$?
2973 if [ $ret -ne 0 ]; then
2974 diff -u $testroot/stdout.expected $testroot/stdout
2975 test_done "$testroot" "$ret"
2976 return 1
2979 if [ -h $testroot/wt/dotgotfoo.link ]; then
2980 echo "dotgotfoo.link is a symlink"
2981 test_done "$testroot" "1"
2982 return 1
2984 echo "this is regular file foo" > $testroot/content.expected
2985 cp $testroot/wt/dotgotfoo.link $testroot/content
2986 cmp -s $testroot/content.expected $testroot/content
2987 ret=$?
2988 if [ $ret -ne 0 ]; then
2989 diff -u $testroot/content.expected $testroot/content
2990 test_done "$testroot" "$ret"
2991 return 1
2994 if ! [ -h $testroot/wt/epsilon.link ]; then
2995 echo "epsilon.link is not a symlink"
2996 test_done "$testroot" "1"
2997 return 1
3000 readlink $testroot/wt/epsilon.link > $testroot/stdout
3001 echo "gamma" > $testroot/stdout.expected
3002 cmp -s $testroot/stdout.expected $testroot/stdout
3003 ret=$?
3004 if [ $ret -ne 0 ]; then
3005 diff -u $testroot/stdout.expected $testroot/stdout
3006 test_done "$testroot" "$ret"
3007 return 1
3010 if [ -h $testroot/wt/passwd.link ]; then
3011 echo "passwd.link is a symlink"
3012 test_done "$testroot" "1"
3013 return 1
3015 echo -n "/etc/passwd" > $testroot/content.expected
3016 cp $testroot/wt/passwd.link $testroot/content
3017 cmp -s $testroot/content.expected $testroot/content
3018 ret=$?
3019 if [ $ret -ne 0 ]; then
3020 diff -u $testroot/content.expected $testroot/content
3021 test_done "$testroot" "$ret"
3022 return 1
3025 if ! [ -h $testroot/wt/zeta.link ]; then
3026 echo "zeta.link is not a symlink"
3027 test_done "$testroot" "1"
3028 return 1
3031 readlink $testroot/wt/zeta.link > $testroot/stdout
3032 echo "gamma/delta" > $testroot/stdout.expected
3033 cmp -s $testroot/stdout.expected $testroot/stdout
3034 ret=$?
3035 if [ $ret -ne 0 ]; then
3036 diff -u $testroot/stdout.expected $testroot/stdout
3037 test_done "$testroot" "$ret"
3038 return 1
3041 test_done "$testroot" "0"
3044 test_parseargs "$@"
3045 run_test test_stage_basic
3046 run_test test_stage_no_changes
3047 run_test test_stage_unversioned
3048 run_test test_stage_nonexistent
3049 run_test test_stage_list
3050 run_test test_stage_conflict
3051 run_test test_stage_out_of_date
3052 run_test test_double_stage
3053 run_test test_stage_status
3054 run_test test_stage_add_already_staged_file
3055 run_test test_stage_rm_already_staged_file
3056 run_test test_stage_revert
3057 run_test test_stage_diff
3058 run_test test_stage_histedit
3059 run_test test_stage_rebase
3060 run_test test_stage_update
3061 run_test test_stage_commit_non_staged
3062 run_test test_stage_commit_out_of_date
3063 run_test test_stage_commit
3064 run_test test_stage_patch
3065 run_test test_stage_patch_twice
3066 run_test test_stage_patch_added
3067 run_test test_stage_patch_added_twice
3068 run_test test_stage_patch_removed
3069 run_test test_stage_patch_removed_twice
3070 run_test test_stage_patch_reversed
3071 run_test test_stage_patch_quit
3072 run_test test_stage_patch_incomplete_script
3073 run_test test_stage_symlink
3074 run_test test_stage_patch_symlink