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 $head_commit $testroot/wt" > $testroot/stdout.expected
937 echo -n 'blob - ' >> $testroot/stdout.expected
938 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
939 >> $testroot/stdout.expected
940 echo ' (staged)' >> $testroot/stdout.expected
941 echo 'file + alpha' >> $testroot/stdout.expected
942 echo '--- alpha' >> $testroot/stdout.expected
943 echo '+++ alpha' >> $testroot/stdout.expected
944 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
945 echo '-modified file' >> $testroot/stdout.expected
946 echo '+modified file again' >> $testroot/stdout.expected
947 echo -n 'blob - ' >> $testroot/stdout.expected
948 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
949 >> $testroot/stdout.expected
950 echo " (staged)" >> $testroot/stdout.expected
951 echo 'file + foo' >> $testroot/stdout.expected
952 echo '--- foo' >> $testroot/stdout.expected
953 echo '+++ foo' >> $testroot/stdout.expected
954 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
955 echo '-new file' >> $testroot/stdout.expected
956 echo '+new file changed' >> $testroot/stdout.expected
958 cmp -s $testroot/stdout.expected $testroot/stdout
959 ret=$?
960 if [ $ret -ne 0 ]; then
961 diff -u $testroot/stdout.expected $testroot/stdout
962 test_done "$testroot" "$ret"
963 return 1
964 fi
966 (cd $testroot/wt && got diff -s > $testroot/stdout)
968 echo "diff $head_commit $testroot/wt (staged changes)" \
969 > $testroot/stdout.expected
970 echo -n 'blob - ' >> $testroot/stdout.expected
971 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
972 >> $testroot/stdout.expected
973 echo -n 'blob + ' >> $testroot/stdout.expected
974 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
975 >> $testroot/stdout.expected
976 echo '--- alpha' >> $testroot/stdout.expected
977 echo '+++ alpha' >> $testroot/stdout.expected
978 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
979 echo '-alpha' >> $testroot/stdout.expected
980 echo '+modified file' >> $testroot/stdout.expected
981 echo -n 'blob - ' >> $testroot/stdout.expected
982 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
983 >> $testroot/stdout.expected
984 echo 'blob + /dev/null' >> $testroot/stdout.expected
985 echo '--- beta' >> $testroot/stdout.expected
986 echo '+++ /dev/null' >> $testroot/stdout.expected
987 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
988 echo '-beta' >> $testroot/stdout.expected
989 echo 'blob - /dev/null' >> $testroot/stdout.expected
990 echo -n 'blob + ' >> $testroot/stdout.expected
991 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
992 >> $testroot/stdout.expected
993 echo '--- /dev/null' >> $testroot/stdout.expected
994 echo '+++ foo' >> $testroot/stdout.expected
995 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
996 echo '+new file' >> $testroot/stdout.expected
998 cmp -s $testroot/stdout.expected $testroot/stdout
999 ret=$?
1000 if [ $ret -ne 0 ]; then
1001 diff -u $testroot/stdout.expected $testroot/stdout
1003 test_done "$testroot" "$ret"
1007 test_stage_histedit() {
1008 local testroot=`test_init stage_histedit`
1009 local orig_commit=`git_show_head $testroot/repo`
1011 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1012 ret=$?
1013 if [ $ret -ne 0 ]; then
1014 test_done "$testroot" "$ret"
1015 return 1
1018 echo "modified file" > $testroot/wt/alpha
1019 (cd $testroot/wt && got stage alpha > /dev/null)
1021 echo "modified alpha on master" > $testroot/repo/alpha
1022 (cd $testroot/repo && git rm -q beta)
1023 echo "new file on master" > $testroot/repo/epsilon/new
1024 (cd $testroot/repo && git add epsilon/new)
1025 git_commit $testroot/repo -m "committing changes"
1026 local old_commit1=`git_show_head $testroot/repo`
1028 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1029 git_commit $testroot/repo -m "committing to zeta on master"
1030 local old_commit2=`git_show_head $testroot/repo`
1032 echo "pick $old_commit1" > $testroot/histedit-script
1033 echo "pick $old_commit2" >> $testroot/histedit-script
1035 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1036 > $testroot/stdout 2> $testroot/stderr)
1037 ret=$?
1038 if [ $ret -eq 0 ]; then
1039 echo "got histedit command succeeded unexpectedly" >&2
1040 test_done "$testroot" "1"
1041 return 1
1044 echo -n > $testroot/stdout.expected
1045 echo "got: alpha: file is staged" > $testroot/stderr.expected
1047 cmp -s $testroot/stderr.expected $testroot/stderr
1048 ret=$?
1049 if [ $ret -ne 0 ]; then
1050 diff -u $testroot/stderr.expected $testroot/stderr
1051 test_done "$testroot" "$ret"
1052 return 1
1054 cmp -s $testroot/stdout.expected $testroot/stdout
1055 ret=$?
1056 if [ $ret -ne 0 ]; then
1057 diff -u $testroot/stdout.expected $testroot/stdout
1059 test_done "$testroot" "$ret"
1063 test_stage_rebase() {
1064 local testroot=`test_init stage_rebase`
1066 (cd $testroot/repo && git checkout -q -b newbranch)
1067 echo "modified delta on branch" > $testroot/repo/gamma/delta
1068 git_commit $testroot/repo -m "committing to delta on newbranch"
1070 echo "modified alpha on branch" > $testroot/repo/alpha
1071 (cd $testroot/repo && git rm -q beta)
1072 echo "new file on branch" > $testroot/repo/epsilon/new
1073 (cd $testroot/repo && git add epsilon/new)
1074 git_commit $testroot/repo -m "committing more changes on newbranch"
1076 local orig_commit1=`git_show_parent_commit $testroot/repo`
1077 local orig_commit2=`git_show_head $testroot/repo`
1079 (cd $testroot/repo && git checkout -q master)
1080 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1081 git_commit $testroot/repo -m "committing to zeta on master"
1082 local master_commit=`git_show_head $testroot/repo`
1084 got checkout $testroot/repo $testroot/wt > /dev/null
1085 ret=$?
1086 if [ $ret -ne 0 ]; then
1087 test_done "$testroot" "$ret"
1088 return 1
1091 echo "modified file" > $testroot/wt/alpha
1092 (cd $testroot/wt && got stage alpha > /dev/null)
1094 (cd $testroot/wt && got rebase newbranch \
1095 > $testroot/stdout 2> $testroot/stderr)
1096 ret=$?
1097 if [ $ret -eq 0 ]; then
1098 echo "got rebase command succeeded unexpectedly" >&2
1099 test_done "$testroot" "1"
1100 return 1
1103 echo -n > $testroot/stdout.expected
1104 echo "got: alpha: file is staged" > $testroot/stderr.expected
1106 cmp -s $testroot/stderr.expected $testroot/stderr
1107 ret=$?
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/stderr.expected $testroot/stderr
1110 test_done "$testroot" "$ret"
1111 return 1
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1114 ret=$?
1115 if [ $ret -ne 0 ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1118 test_done "$testroot" "$ret"
1121 test_stage_update() {
1122 local testroot=`test_init stage_update`
1124 got checkout $testroot/repo $testroot/wt > /dev/null
1125 ret=$?
1126 if [ $ret -ne 0 ]; then
1127 test_done "$testroot" "$ret"
1128 return 1
1131 echo "modified file" > $testroot/wt/alpha
1132 (cd $testroot/wt && got stage alpha > /dev/null)
1134 echo "modified alpha" > $testroot/repo/alpha
1135 git_commit $testroot/repo -m "modified alpha"
1137 (cd $testroot/wt && got update > $testroot/stdout \
1138 2> $testroot/stderr)
1139 ret=$?
1140 if [ $ret -eq 0 ]; then
1141 echo "got update command succeeded unexpectedly" >&2
1142 test_done "$testroot" "1"
1143 return 1
1146 echo -n > $testroot/stdout.expected
1147 echo "got: alpha: file is staged" > $testroot/stderr.expected
1149 cmp -s $testroot/stderr.expected $testroot/stderr
1150 ret=$?
1151 if [ $ret -ne 0 ]; then
1152 diff -u $testroot/stderr.expected $testroot/stderr
1153 test_done "$testroot" "$ret"
1154 return 1
1156 cmp -s $testroot/stdout.expected $testroot/stdout
1157 ret=$?
1158 if [ $ret -ne 0 ]; then
1159 diff -u $testroot/stdout.expected $testroot/stdout
1161 test_done "$testroot" "$ret"
1164 test_stage_commit_non_staged() {
1165 local testroot=`test_init stage_commit_non_staged`
1167 got checkout $testroot/repo $testroot/wt > /dev/null
1168 ret=$?
1169 if [ $ret -ne 0 ]; then
1170 test_done "$testroot" "$ret"
1171 return 1
1174 echo "modified file" > $testroot/wt/alpha
1175 (cd $testroot/wt && got rm beta > /dev/null)
1176 echo "new file" > $testroot/wt/foo
1177 (cd $testroot/wt && got add foo > /dev/null)
1178 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1180 echo "modified file" > $testroot/wt/gamma/delta
1181 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1182 > $testroot/stdout 2> $testroot/stderr)
1183 ret=$?
1184 if [ $ret -eq 0 ]; then
1185 echo "got commit command succeeded unexpectedly" >&2
1186 test_done "$testroot" "1"
1187 return 1
1190 echo -n > $testroot/stdout.expected
1191 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1193 cmp -s $testroot/stderr.expected $testroot/stderr
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 diff -u $testroot/stderr.expected $testroot/stderr
1197 test_done "$testroot" "$ret"
1198 return 1
1200 cmp -s $testroot/stdout.expected $testroot/stdout
1201 ret=$?
1202 if [ $ret -ne 0 ]; then
1203 diff -u $testroot/stdout.expected $testroot/stdout
1205 test_done "$testroot" "$ret"
1208 test_stage_commit_out_of_date() {
1209 local testroot=`test_init stage_commit_out_of_date`
1211 got checkout $testroot/repo $testroot/wt > /dev/null
1212 ret=$?
1213 if [ $ret -ne 0 ]; then
1214 test_done "$testroot" "$ret"
1215 return 1
1218 echo "modified file" > $testroot/wt/alpha
1219 (cd $testroot/wt && got rm beta > /dev/null)
1220 echo "new file" > $testroot/wt/foo
1221 (cd $testroot/wt && got add foo > /dev/null)
1222 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1224 echo "changed file" > $testroot/repo/alpha
1225 git_commit $testroot/repo -m "changed alpha in repo"
1227 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1228 2> $testroot/stderr)
1229 ret=$?
1230 if [ $ret -eq 0 ]; then
1231 echo "got commit command succeeded unexpectedly" >&2
1232 test_done "$testroot" "1"
1233 return 1
1236 echo -n > $testroot/stdout.expected
1237 echo -n "got: work tree must be updated before these changes " \
1238 > $testroot/stderr.expected
1239 echo "can be committed" >> $testroot/stderr.expected
1241 cmp -s $testroot/stderr.expected $testroot/stderr
1242 ret=$?
1243 if [ $ret -ne 0 ]; then
1244 diff -u $testroot/stderr.expected $testroot/stderr
1245 test_done "$testroot" "$ret"
1246 return 1
1248 cmp -s $testroot/stdout.expected $testroot/stdout
1249 ret=$?
1250 if [ $ret -ne 0 ]; then
1251 diff -u $testroot/stdout.expected $testroot/stdout
1252 test_done "$testroot" "$ret"
1253 return 1
1256 (cd $testroot/wt && got update > $testroot/stdout \
1257 2> $testroot/stderr)
1258 echo -n > $testroot/stdout.expected
1259 echo "got: alpha: file is staged" > $testroot/stderr.expected
1261 cmp -s $testroot/stderr.expected $testroot/stderr
1262 ret=$?
1263 if [ $ret -ne 0 ]; then
1264 diff -u $testroot/stderr.expected $testroot/stderr
1265 test_done "$testroot" "$ret"
1266 return 1
1268 cmp -s $testroot/stdout.expected $testroot/stdout
1269 ret=$?
1270 if [ $ret -ne 0 ]; then
1271 diff -u $testroot/stdout.expected $testroot/stdout
1272 test_done "$testroot" "$ret"
1273 return 1
1276 (cd $testroot/wt && got unstage > /dev/null)
1277 (cd $testroot/wt && got update > $testroot/stdout)
1278 ret=$?
1279 if [ $ret -ne 0 ]; then
1280 echo "got update command failed unexpectedly" >&2
1281 test_done "$testroot" "$ret"
1282 return 1
1285 (cd $testroot/wt && got status > $testroot/stdout)
1286 echo "C alpha" > $testroot/stdout.expected
1287 echo "D beta" >> $testroot/stdout.expected
1288 echo "A foo" >> $testroot/stdout.expected
1289 cmp -s $testroot/stdout.expected $testroot/stdout
1290 ret=$?
1291 if [ $ret -ne 0 ]; then
1292 diff -u $testroot/stdout.expected $testroot/stdout
1293 test_done "$testroot" "$ret"
1294 return 1
1297 # resolve conflict
1298 echo "resolved file" > $testroot/wt/alpha
1300 (cd $testroot/wt && got stage > /dev/null)
1302 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1303 ret=$?
1304 if [ $ret -ne 0 ]; then
1305 echo "got commit command failed unexpectedly" >&2
1306 test_done "$testroot" "$ret"
1307 return 1
1310 local commit_id=`git_show_head $testroot/repo`
1311 echo "A foo" > $testroot/stdout.expected
1312 echo "M alpha" >> $testroot/stdout.expected
1313 echo "D beta" >> $testroot/stdout.expected
1314 echo "Created commit $commit_id" >> $testroot/stdout.expected
1315 cmp -s $testroot/stdout.expected $testroot/stdout
1316 ret=$?
1317 if [ $ret -ne 0 ]; then
1318 diff -u $testroot/stdout.expected $testroot/stdout
1320 test_done "$testroot" "$ret"
1324 test_stage_commit() {
1325 local testroot=`test_init stage_commit`
1326 local first_commit=`git_show_head $testroot/repo`
1328 got checkout $testroot/repo $testroot/wt > /dev/null
1329 ret=$?
1330 if [ $ret -ne 0 ]; then
1331 test_done "$testroot" "$ret"
1332 return 1
1335 echo "modified file" > $testroot/wt/alpha
1336 (cd $testroot/wt && got rm beta > /dev/null)
1337 echo "new file" > $testroot/wt/foo
1338 (cd $testroot/wt && got add foo > /dev/null)
1339 echo "modified file" > $testroot/wt/alpha
1340 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1342 echo "modified file again" > $testroot/wt/alpha
1343 echo "new file changed" > $testroot/wt/foo
1344 echo "non-staged change" > $testroot/wt/gamma/delta
1345 echo "non-staged new file" > $testroot/wt/epsilon/new
1346 (cd $testroot/wt && got add epsilon/new > /dev/null)
1347 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1349 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1350 > $testroot/blob_id_alpha
1351 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1352 > $testroot/blob_id_foo
1354 (cd $testroot/wt && got commit -m "staged changes" \
1355 > $testroot/stdout)
1356 ret=$?
1357 if [ $ret -ne 0 ]; then
1358 echo "got commit command failed unexpectedly" >&2
1359 test_done "$testroot" "1"
1360 return 1
1363 local head_commit=`git_show_head $testroot/repo`
1364 echo "A foo" > $testroot/stdout.expected
1365 echo "M alpha" >> $testroot/stdout.expected
1366 echo "D beta" >> $testroot/stdout.expected
1367 echo "Created commit $head_commit" >> $testroot/stdout.expected
1369 cmp -s $testroot/stdout.expected $testroot/stdout
1370 ret=$?
1371 if [ $ret -ne 0 ]; then
1372 diff -u $testroot/stdout.expected $testroot/stdout
1373 test_done "$testroot" "$ret"
1374 return 1
1377 got diff -r $testroot/repo $first_commit $head_commit \
1378 > $testroot/stdout
1380 echo "diff $first_commit $head_commit" \
1381 > $testroot/stdout.expected
1382 echo -n 'blob - ' >> $testroot/stdout.expected
1383 got tree -r $testroot/repo -i -c $first_commit | \
1384 grep 'alpha$' | cut -d' ' -f 1 \
1385 >> $testroot/stdout.expected
1386 echo -n 'blob + ' >> $testroot/stdout.expected
1387 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1388 echo '--- alpha' >> $testroot/stdout.expected
1389 echo '+++ alpha' >> $testroot/stdout.expected
1390 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1391 echo '-alpha' >> $testroot/stdout.expected
1392 echo '+modified file' >> $testroot/stdout.expected
1393 echo -n 'blob - ' >> $testroot/stdout.expected
1394 got tree -r $testroot/repo -i -c $first_commit \
1395 | grep 'beta$' | cut -d' ' -f 1 | tr -d '\n' \
1396 >> $testroot/stdout.expected
1397 echo " (mode 644)" >> $testroot/stdout.expected
1398 echo 'blob + /dev/null' >> $testroot/stdout.expected
1399 echo '--- beta' >> $testroot/stdout.expected
1400 echo '+++ /dev/null' >> $testroot/stdout.expected
1401 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1402 echo '-beta' >> $testroot/stdout.expected
1403 echo 'blob - /dev/null' >> $testroot/stdout.expected
1404 echo -n 'blob + ' >> $testroot/stdout.expected
1405 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1406 echo " (mode 644)" >> $testroot/stdout.expected
1407 echo '--- /dev/null' >> $testroot/stdout.expected
1408 echo '+++ foo' >> $testroot/stdout.expected
1409 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1410 echo '+new file' >> $testroot/stdout.expected
1412 cmp -s $testroot/stdout.expected $testroot/stdout
1413 ret=$?
1414 if [ $ret -ne 0 ]; then
1415 diff -u $testroot/stdout.expected $testroot/stdout
1416 test_done "$testroot" "$ret"
1417 return 1
1420 echo 'M alpha' > $testroot/stdout.expected
1421 echo 'A epsilon/new' >> $testroot/stdout.expected
1422 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1423 echo 'M foo' >> $testroot/stdout.expected
1424 echo 'M gamma/delta' >> $testroot/stdout.expected
1426 (cd $testroot/wt && got status > $testroot/stdout)
1427 cmp -s $testroot/stdout.expected $testroot/stdout
1428 ret=$?
1429 if [ $ret -ne 0 ]; then
1430 diff -u $testroot/stdout.expected $testroot/stdout
1432 test_done "$testroot" "$ret"
1435 test_stage_patch() {
1436 local testroot=`test_init stage_patch`
1438 jot 16 > $testroot/repo/numbers
1439 (cd $testroot/repo && git add numbers)
1440 git_commit $testroot/repo -m "added numbers file"
1441 local commit_id=`git_show_head $testroot/repo`
1443 got checkout $testroot/repo $testroot/wt > /dev/null
1444 ret=$?
1445 if [ $ret -ne 0 ]; then
1446 test_done "$testroot" "$ret"
1447 return 1
1450 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1451 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1452 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1454 # don't stage any hunks
1455 printf "n\nn\nn\n" > $testroot/patchscript
1456 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1457 numbers > $testroot/stdout 2> $testroot/stderr)
1458 ret=$?
1459 if [ $ret -eq 0 ]; then
1460 echo "got stage command succeeded unexpectedly" >&2
1461 test_done "$testroot" "1"
1462 return 1
1464 cat > $testroot/stdout.expected <<EOF
1465 -----------------------------------------------
1466 @@ -1,5 +1,5 @@
1473 -----------------------------------------------
1474 M numbers (change 1 of 3)
1475 stage this change? [y/n/q] n
1476 -----------------------------------------------
1477 @@ -4,7 +4,7 @@
1486 -----------------------------------------------
1487 M numbers (change 2 of 3)
1488 stage this change? [y/n/q] n
1489 -----------------------------------------------
1490 @@ -13,4 +13,4 @@
1494 -16
1496 -----------------------------------------------
1497 M numbers (change 3 of 3)
1498 stage this change? [y/n/q] n
1499 EOF
1500 cmp -s $testroot/stdout.expected $testroot/stdout
1501 ret=$?
1502 if [ $ret -ne 0 ]; then
1503 diff -u $testroot/stdout.expected $testroot/stdout
1504 test_done "$testroot" "$ret"
1505 return 1
1508 echo "got: no changes to stage" > $testroot/stderr.expected
1509 cmp -s $testroot/stderr.expected $testroot/stderr
1510 ret=$?
1511 if [ $ret -ne 0 ]; then
1512 diff -u $testroot/stderr.expected $testroot/stderr
1513 test_done "$testroot" "$ret"
1514 return 1
1518 (cd $testroot/wt && got status > $testroot/stdout)
1519 echo "M numbers" > $testroot/stdout.expected
1520 cmp -s $testroot/stdout.expected $testroot/stdout
1521 ret=$?
1522 if [ $ret -ne 0 ]; then
1523 diff -u $testroot/stdout.expected $testroot/stdout
1524 test_done "$testroot" "$ret"
1525 return 1
1528 # stage middle hunk
1529 printf "n\ny\nn\n" > $testroot/patchscript
1530 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1531 numbers > $testroot/stdout)
1533 cat > $testroot/stdout.expected <<EOF
1534 -----------------------------------------------
1535 @@ -1,5 +1,5 @@
1542 -----------------------------------------------
1543 M numbers (change 1 of 3)
1544 stage this change? [y/n/q] n
1545 -----------------------------------------------
1546 @@ -4,7 +4,7 @@
1555 -----------------------------------------------
1556 M numbers (change 2 of 3)
1557 stage this change? [y/n/q] y
1558 -----------------------------------------------
1559 @@ -13,4 +13,4 @@
1563 -16
1565 -----------------------------------------------
1566 M numbers (change 3 of 3)
1567 stage this change? [y/n/q] n
1568 EOF
1569 cmp -s $testroot/stdout.expected $testroot/stdout
1570 ret=$?
1571 if [ $ret -ne 0 ]; then
1572 diff -u $testroot/stdout.expected $testroot/stdout
1573 test_done "$testroot" "$ret"
1574 return 1
1577 (cd $testroot/wt && got status > $testroot/stdout)
1578 echo "MM numbers" > $testroot/stdout.expected
1579 cmp -s $testroot/stdout.expected $testroot/stdout
1580 ret=$?
1581 if [ $ret -ne 0 ]; then
1582 diff -u $testroot/stdout.expected $testroot/stdout
1583 test_done "$testroot" "$ret"
1584 return 1
1587 (cd $testroot/wt && got diff -s > $testroot/stdout)
1589 echo "diff $commit_id $testroot/wt (staged changes)" \
1590 > $testroot/stdout.expected
1591 echo -n 'blob - ' >> $testroot/stdout.expected
1592 got tree -r $testroot/repo -i -c $commit_id \
1593 | grep 'numbers$' | cut -d' ' -f 1 \
1594 >> $testroot/stdout.expected
1595 echo -n 'blob + ' >> $testroot/stdout.expected
1596 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1597 >> $testroot/stdout.expected
1598 echo "--- numbers" >> $testroot/stdout.expected
1599 echo "+++ numbers" >> $testroot/stdout.expected
1600 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1601 echo " 4" >> $testroot/stdout.expected
1602 echo " 5" >> $testroot/stdout.expected
1603 echo " 6" >> $testroot/stdout.expected
1604 echo "-7" >> $testroot/stdout.expected
1605 echo "+b" >> $testroot/stdout.expected
1606 echo " 8" >> $testroot/stdout.expected
1607 echo " 9" >> $testroot/stdout.expected
1608 echo " 10" >> $testroot/stdout.expected
1609 cmp -s $testroot/stdout.expected $testroot/stdout
1610 ret=$?
1611 if [ $ret -ne 0 ]; then
1612 diff -u $testroot/stdout.expected $testroot/stdout
1613 test_done "$testroot" "$ret"
1614 return 1
1617 (cd $testroot/wt && got unstage >/dev/null)
1618 ret=$?
1619 if [ $ret -ne 0 ]; then
1620 echo "got stage command failed unexpectedly" >&2
1621 test_done "$testroot" "1"
1622 return 1
1624 (cd $testroot/wt && got status > $testroot/stdout)
1625 echo "M numbers" > $testroot/stdout.expected
1626 cmp -s $testroot/stdout.expected $testroot/stdout
1627 ret=$?
1628 if [ $ret -ne 0 ]; then
1629 diff -u $testroot/stdout.expected $testroot/stdout
1630 test_done "$testroot" "$ret"
1631 return 1
1634 # stage last hunk
1635 printf "n\nn\ny\n" > $testroot/patchscript
1636 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1637 numbers > $testroot/stdout)
1639 cat > $testroot/stdout.expected <<EOF
1640 -----------------------------------------------
1641 @@ -1,5 +1,5 @@
1648 -----------------------------------------------
1649 M numbers (change 1 of 3)
1650 stage this change? [y/n/q] n
1651 -----------------------------------------------
1652 @@ -4,7 +4,7 @@
1661 -----------------------------------------------
1662 M numbers (change 2 of 3)
1663 stage this change? [y/n/q] n
1664 -----------------------------------------------
1665 @@ -13,4 +13,4 @@
1669 -16
1671 -----------------------------------------------
1672 M numbers (change 3 of 3)
1673 stage this change? [y/n/q] y
1674 EOF
1675 cmp -s $testroot/stdout.expected $testroot/stdout
1676 ret=$?
1677 if [ $ret -ne 0 ]; then
1678 diff -u $testroot/stdout.expected $testroot/stdout
1679 test_done "$testroot" "$ret"
1680 return 1
1683 (cd $testroot/wt && got status > $testroot/stdout)
1684 echo "MM numbers" > $testroot/stdout.expected
1685 cmp -s $testroot/stdout.expected $testroot/stdout
1686 ret=$?
1687 if [ $ret -ne 0 ]; then
1688 diff -u $testroot/stdout.expected $testroot/stdout
1689 test_done "$testroot" "$ret"
1690 return 1
1693 (cd $testroot/wt && got diff -s > $testroot/stdout)
1695 echo "diff $commit_id $testroot/wt (staged changes)" \
1696 > $testroot/stdout.expected
1697 echo -n 'blob - ' >> $testroot/stdout.expected
1698 got tree -r $testroot/repo -i -c $commit_id \
1699 | grep 'numbers$' | cut -d' ' -f 1 \
1700 >> $testroot/stdout.expected
1701 echo -n 'blob + ' >> $testroot/stdout.expected
1702 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1703 >> $testroot/stdout.expected
1704 echo "--- numbers" >> $testroot/stdout.expected
1705 echo "+++ numbers" >> $testroot/stdout.expected
1706 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1707 echo " 13" >> $testroot/stdout.expected
1708 echo " 14" >> $testroot/stdout.expected
1709 echo " 15" >> $testroot/stdout.expected
1710 echo "-16" >> $testroot/stdout.expected
1711 echo "+c" >> $testroot/stdout.expected
1712 cmp -s $testroot/stdout.expected $testroot/stdout
1713 ret=$?
1714 if [ $ret -ne 0 ]; then
1715 diff -u $testroot/stdout.expected $testroot/stdout
1717 test_done "$testroot" "$ret"
1720 test_stage_patch_twice() {
1721 local testroot=`test_init stage_patch_twice`
1723 jot 16 > $testroot/repo/numbers
1724 (cd $testroot/repo && git add numbers)
1725 git_commit $testroot/repo -m "added numbers file"
1726 local commit_id=`git_show_head $testroot/repo`
1728 got checkout $testroot/repo $testroot/wt > /dev/null
1729 ret=$?
1730 if [ $ret -ne 0 ]; then
1731 test_done "$testroot" "$ret"
1732 return 1
1735 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1736 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1737 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1739 # stage middle hunk
1740 printf "n\ny\nn\n" > $testroot/patchscript
1741 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1742 numbers > $testroot/stdout)
1744 cat > $testroot/stdout.expected <<EOF
1745 -----------------------------------------------
1746 @@ -1,5 +1,5 @@
1753 -----------------------------------------------
1754 M numbers (change 1 of 3)
1755 stage this change? [y/n/q] n
1756 -----------------------------------------------
1757 @@ -4,7 +4,7 @@
1766 -----------------------------------------------
1767 M numbers (change 2 of 3)
1768 stage this change? [y/n/q] y
1769 -----------------------------------------------
1770 @@ -13,4 +13,4 @@
1774 -16
1776 -----------------------------------------------
1777 M numbers (change 3 of 3)
1778 stage this change? [y/n/q] n
1779 EOF
1780 cmp -s $testroot/stdout.expected $testroot/stdout
1781 ret=$?
1782 if [ $ret -ne 0 ]; then
1783 diff -u $testroot/stdout.expected $testroot/stdout
1784 test_done "$testroot" "$ret"
1785 return 1
1788 (cd $testroot/wt && got status > $testroot/stdout)
1789 echo "MM numbers" > $testroot/stdout.expected
1790 cmp -s $testroot/stdout.expected $testroot/stdout
1791 ret=$?
1792 if [ $ret -ne 0 ]; then
1793 diff -u $testroot/stdout.expected $testroot/stdout
1794 test_done "$testroot" "$ret"
1795 return 1
1798 # stage last hunk
1799 printf "n\ny\n" > $testroot/patchscript
1800 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1801 numbers > $testroot/stdout)
1803 cat > $testroot/stdout.expected <<EOF
1804 -----------------------------------------------
1805 @@ -1,5 +1,5 @@
1812 -----------------------------------------------
1813 M numbers (change 1 of 2)
1814 stage this change? [y/n/q] n
1815 -----------------------------------------------
1816 @@ -13,4 +13,4 @@ b
1820 -16
1822 -----------------------------------------------
1823 M numbers (change 2 of 2)
1824 stage this change? [y/n/q] y
1825 EOF
1826 cmp -s $testroot/stdout.expected $testroot/stdout
1827 ret=$?
1828 if [ $ret -ne 0 ]; then
1829 diff -u $testroot/stdout.expected $testroot/stdout
1830 test_done "$testroot" "$ret"
1831 return 1
1834 (cd $testroot/wt && got status > $testroot/stdout)
1835 echo "MM numbers" > $testroot/stdout.expected
1836 cmp -s $testroot/stdout.expected $testroot/stdout
1837 ret=$?
1838 if [ $ret -ne 0 ]; then
1839 diff -u $testroot/stdout.expected $testroot/stdout
1840 test_done "$testroot" "$ret"
1841 return 1
1844 (cd $testroot/wt && got diff -s > $testroot/stdout)
1846 echo "diff $commit_id $testroot/wt (staged changes)" \
1847 > $testroot/stdout.expected
1848 echo -n 'blob - ' >> $testroot/stdout.expected
1849 got tree -r $testroot/repo -i -c $commit_id \
1850 | grep 'numbers$' | cut -d' ' -f 1 \
1851 >> $testroot/stdout.expected
1852 echo -n 'blob + ' >> $testroot/stdout.expected
1853 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1854 >> $testroot/stdout.expected
1855 echo "--- numbers" >> $testroot/stdout.expected
1856 echo "+++ numbers" >> $testroot/stdout.expected
1857 cat >> $testroot/stdout.expected <<EOF
1858 @@ -4,7 +4,7 @@
1867 @@ -13,4 +13,4 @@
1871 -16
1873 EOF
1874 cmp -s $testroot/stdout.expected $testroot/stdout
1875 ret=$?
1876 if [ $ret -ne 0 ]; then
1877 diff -u $testroot/stdout.expected $testroot/stdout
1878 test_done "$testroot" "$ret"
1879 return 1
1882 (cd $testroot/wt && got diff > $testroot/stdout)
1884 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1885 echo -n 'blob - ' >> $testroot/stdout.expected
1886 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1887 tr -d '\n' >> $testroot/stdout.expected
1888 echo " (staged)" >> $testroot/stdout.expected
1889 echo 'file + numbers' >> $testroot/stdout.expected
1890 echo "--- numbers" >> $testroot/stdout.expected
1891 echo "+++ numbers" >> $testroot/stdout.expected
1892 cat >> $testroot/stdout.expected <<EOF
1893 @@ -1,5 +1,5 @@
1900 EOF
1901 cmp -s $testroot/stdout.expected $testroot/stdout
1902 ret=$?
1903 if [ $ret -ne 0 ]; then
1904 diff -u $testroot/stdout.expected $testroot/stdout
1906 test_done "$testroot" "$ret"
1909 test_stage_patch_added() {
1910 local testroot=`test_init stage_patch_added`
1911 local commit_id=`git_show_head $testroot/repo`
1913 got checkout $testroot/repo $testroot/wt > /dev/null
1914 ret=$?
1915 if [ $ret -ne 0 ]; then
1916 test_done "$testroot" "$ret"
1917 return 1
1920 echo "new" > $testroot/wt/epsilon/new
1921 (cd $testroot/wt && got add epsilon/new > /dev/null)
1923 printf "y\n" > $testroot/patchscript
1924 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1925 epsilon/new > $testroot/stdout)
1927 echo "A epsilon/new" > $testroot/stdout.expected
1928 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1929 cmp -s $testroot/stdout.expected $testroot/stdout
1930 ret=$?
1931 if [ $ret -ne 0 ]; then
1932 diff -u $testroot/stdout.expected $testroot/stdout
1933 test_done "$testroot" "$ret"
1934 return 1
1937 (cd $testroot/wt && got status > $testroot/stdout)
1938 echo " A epsilon/new" > $testroot/stdout.expected
1939 cmp -s $testroot/stdout.expected $testroot/stdout
1940 ret=$?
1941 if [ $ret -ne 0 ]; then
1942 diff -u $testroot/stdout.expected $testroot/stdout
1943 test_done "$testroot" "$ret"
1944 return 1
1947 (cd $testroot/wt && got diff -s > $testroot/stdout)
1949 echo "diff $commit_id $testroot/wt (staged changes)" \
1950 > $testroot/stdout.expected
1951 echo 'blob - /dev/null' >> $testroot/stdout.expected
1952 echo -n 'blob + ' >> $testroot/stdout.expected
1953 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1954 >> $testroot/stdout.expected
1955 echo "--- /dev/null" >> $testroot/stdout.expected
1956 echo "+++ epsilon/new" >> $testroot/stdout.expected
1957 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1958 echo "+new" >> $testroot/stdout.expected
1959 cmp -s $testroot/stdout.expected $testroot/stdout
1960 ret=$?
1961 if [ $ret -ne 0 ]; then
1962 diff -u $testroot/stdout.expected $testroot/stdout
1964 test_done "$testroot" "$ret"
1967 test_stage_patch_added_twice() {
1968 local testroot=`test_init stage_patch_added_twice`
1969 local commit_id=`git_show_head $testroot/repo`
1971 got checkout $testroot/repo $testroot/wt > /dev/null
1972 ret=$?
1973 if [ $ret -ne 0 ]; then
1974 test_done "$testroot" "$ret"
1975 return 1
1978 echo "new" > $testroot/wt/epsilon/new
1979 (cd $testroot/wt && got add epsilon/new > /dev/null)
1981 printf "y\n" > $testroot/patchscript
1982 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1983 epsilon/new > $testroot/stdout)
1985 echo "A epsilon/new" > $testroot/stdout.expected
1986 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1987 cmp -s $testroot/stdout.expected $testroot/stdout
1988 ret=$?
1989 if [ $ret -ne 0 ]; then
1990 diff -u $testroot/stdout.expected $testroot/stdout
1991 test_done "$testroot" "$ret"
1992 return 1
1995 (cd $testroot/wt && got status > $testroot/stdout)
1996 echo " A epsilon/new" > $testroot/stdout.expected
1997 cmp -s $testroot/stdout.expected $testroot/stdout
1998 ret=$?
1999 if [ $ret -ne 0 ]; then
2000 diff -u $testroot/stdout.expected $testroot/stdout
2001 test_done "$testroot" "$ret"
2002 return 1
2005 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2006 epsilon/new > $testroot/stdout 2> $testroot/stderr)
2007 ret=$?
2008 if [ $ret -eq 0 ]; then
2009 echo "got stage command succeeded unexpectedly" >&2
2010 test_done "$testroot" "1"
2011 return 1
2014 echo "got: no changes to stage" > $testroot/stderr.expected
2015 cmp -s $testroot/stderr.expected $testroot/stderr
2016 ret=$?
2017 if [ $ret -ne 0 ]; then
2018 diff -u $testroot/stderr.expected $testroot/stderr
2019 test_done "$testroot" "$ret"
2020 return 1
2023 echo -n > $testroot/stdout.expected
2024 cmp -s $testroot/stdout.expected $testroot/stdout
2025 ret=$?
2026 if [ $ret -ne 0 ]; then
2027 diff -u $testroot/stdout.expected $testroot/stdout
2029 test_done "$testroot" "$ret"
2032 test_stage_patch_removed() {
2033 local testroot=`test_init stage_patch_removed`
2034 local commit_id=`git_show_head $testroot/repo`
2036 got checkout $testroot/repo $testroot/wt > /dev/null
2037 ret=$?
2038 if [ $ret -ne 0 ]; then
2039 test_done "$testroot" "$ret"
2040 return 1
2043 (cd $testroot/wt && got rm beta > /dev/null)
2045 printf "y\n" > $testroot/patchscript
2046 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2047 beta > $testroot/stdout)
2049 echo -n > $testroot/stdout.expected
2051 echo "D beta" > $testroot/stdout.expected
2052 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2053 cmp -s $testroot/stdout.expected $testroot/stdout
2054 ret=$?
2055 if [ $ret -ne 0 ]; then
2056 diff -u $testroot/stdout.expected $testroot/stdout
2057 test_done "$testroot" "$ret"
2058 return 1
2061 (cd $testroot/wt && got status > $testroot/stdout)
2062 echo " D beta" > $testroot/stdout.expected
2063 cmp -s $testroot/stdout.expected $testroot/stdout
2064 ret=$?
2065 if [ $ret -ne 0 ]; then
2066 diff -u $testroot/stdout.expected $testroot/stdout
2067 test_done "$testroot" "$ret"
2068 return 1
2071 (cd $testroot/wt && got diff -s > $testroot/stdout)
2073 echo "diff $commit_id $testroot/wt (staged changes)" \
2074 > $testroot/stdout.expected
2075 echo -n 'blob - ' >> $testroot/stdout.expected
2076 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2077 >> $testroot/stdout.expected
2078 echo 'blob + /dev/null' >> $testroot/stdout.expected
2079 echo "--- beta" >> $testroot/stdout.expected
2080 echo "+++ /dev/null" >> $testroot/stdout.expected
2081 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2082 echo "-beta" >> $testroot/stdout.expected
2083 cmp -s $testroot/stdout.expected $testroot/stdout
2084 ret=$?
2085 if [ $ret -ne 0 ]; then
2086 diff -u $testroot/stdout.expected $testroot/stdout
2088 test_done "$testroot" "$ret"
2091 test_stage_patch_removed_twice() {
2092 local testroot=`test_init stage_patch_removed_twice`
2093 local commit_id=`git_show_head $testroot/repo`
2095 got checkout $testroot/repo $testroot/wt > /dev/null
2096 ret=$?
2097 if [ $ret -ne 0 ]; then
2098 test_done "$testroot" "$ret"
2099 return 1
2102 (cd $testroot/wt && got rm beta > /dev/null)
2104 printf "y\n" > $testroot/patchscript
2105 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2106 beta > $testroot/stdout)
2108 echo -n > $testroot/stdout.expected
2110 echo "D beta" > $testroot/stdout.expected
2111 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2112 cmp -s $testroot/stdout.expected $testroot/stdout
2113 ret=$?
2114 if [ $ret -ne 0 ]; then
2115 diff -u $testroot/stdout.expected $testroot/stdout
2116 test_done "$testroot" "$ret"
2117 return 1
2120 (cd $testroot/wt && got status > $testroot/stdout)
2121 echo " D beta" > $testroot/stdout.expected
2122 cmp -s $testroot/stdout.expected $testroot/stdout
2123 ret=$?
2124 if [ $ret -ne 0 ]; then
2125 diff -u $testroot/stdout.expected $testroot/stdout
2126 test_done "$testroot" "$ret"
2127 return 1
2130 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2131 > $testroot/stdout 2> $testroot/stderr)
2132 ret=$?
2133 if [ $ret -eq 0 ]; then
2134 echo "got stage command succeeded unexpectedly" >&2
2135 test_done "$testroot" "$ret"
2136 return 1
2139 echo "got: no changes to stage" > $testroot/stderr.expected
2140 cmp -s $testroot/stderr.expected $testroot/stderr
2141 ret=$?
2142 if [ $ret -ne 0 ]; then
2143 diff -u $testroot/stderr.expected $testroot/stderr
2144 test_done "$testroot" "$ret"
2145 return 1
2148 echo -n > $testroot/stdout.expected
2149 cmp -s $testroot/stdout.expected $testroot/stdout
2150 ret=$?
2151 if [ $ret -ne 0 ]; then
2152 diff -u $testroot/stdout.expected $testroot/stdout
2154 test_done "$testroot" "$ret"
2157 test_stage_patch_reversed() {
2158 local testroot=`test_init stage_patch_reversed`
2160 got checkout $testroot/repo $testroot/wt > /dev/null
2161 ret=$?
2162 if [ $ret -ne 0 ]; then
2163 test_done "$testroot" "$ret"
2164 return 1
2167 echo 'ALPHA' > $testroot/wt/alpha
2168 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2169 ret=$?
2170 if [ $ret -ne 0 ]; then
2171 test_done "$testroot" "$ret"
2172 return 1
2175 echo ' M alpha' > $testroot/stdout.expected
2176 cmp -s $testroot/stdout.expected $testroot/stdout
2177 ret=$?
2178 if [ $ret -ne 0 ]; then
2179 diff -u $testroot/stdout.expected $testroot/stdout
2180 test_done "$testroot" "$ret"
2181 return 1
2184 echo 'alpha' > $testroot/wt/alpha
2185 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2186 ret=$?
2187 if [ $ret -ne 0 ]; then
2188 test_done "$testroot" "$ret"
2189 return 1
2192 echo ' M alpha' > $testroot/stdout.expected
2193 cmp -s $testroot/stdout.expected $testroot/stdout
2194 ret=$?
2195 if [ $ret -ne 0 ]; then
2196 diff -u $testroot/stdout.expected $testroot/stdout
2197 test_done "$testroot" "$ret"
2198 return 1
2201 (cd $testroot/wt && got status > $testroot/stdout)
2202 cmp -s /dev/null $testroot/stdout
2203 ret=$?
2204 if [ $ret -ne 0 ]; then
2205 diff -u /dev/null $testroot/stdout
2207 test_done "$testroot" "$ret"
2210 test_stage_patch_quit() {
2211 local testroot=`test_init stage_patch_quit`
2213 jot 16 > $testroot/repo/numbers
2214 echo zzz > $testroot/repo/zzz
2215 (cd $testroot/repo && git add numbers zzz)
2216 git_commit $testroot/repo -m "added files"
2217 local commit_id=`git_show_head $testroot/repo`
2219 got checkout $testroot/repo $testroot/wt > /dev/null
2220 ret=$?
2221 if [ $ret -ne 0 ]; then
2222 test_done "$testroot" "$ret"
2223 return 1
2226 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2227 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2228 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2229 (cd $testroot/wt && got rm zzz > /dev/null)
2231 # stage first hunk and quit; and don't pass a path argument to
2232 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2233 printf "y\nq\nn\n" > $testroot/patchscript
2234 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2235 > $testroot/stdout)
2236 ret=$?
2237 if [ $ret -ne 0 ]; then
2238 echo "got stage command failed unexpectedly" >&2
2239 test_done "$testroot" "1"
2240 return 1
2242 cat > $testroot/stdout.expected <<EOF
2243 -----------------------------------------------
2244 @@ -1,5 +1,5 @@
2251 -----------------------------------------------
2252 M numbers (change 1 of 3)
2253 stage this change? [y/n/q] y
2254 -----------------------------------------------
2255 @@ -4,7 +4,7 @@
2264 -----------------------------------------------
2265 M numbers (change 2 of 3)
2266 stage this change? [y/n/q] q
2267 D zzz
2268 stage this deletion? [y/n] n
2269 EOF
2270 cmp -s $testroot/stdout.expected $testroot/stdout
2271 ret=$?
2272 if [ $ret -ne 0 ]; then
2273 diff -u $testroot/stdout.expected $testroot/stdout
2274 test_done "$testroot" "$ret"
2275 return 1
2278 (cd $testroot/wt && got status > $testroot/stdout)
2279 echo "MM numbers" > $testroot/stdout.expected
2280 echo "D zzz" >> $testroot/stdout.expected
2281 cmp -s $testroot/stdout.expected $testroot/stdout
2282 ret=$?
2283 if [ $ret -ne 0 ]; then
2284 diff -u $testroot/stdout.expected $testroot/stdout
2285 test_done "$testroot" "$ret"
2286 return 1
2289 (cd $testroot/wt && got diff -s > $testroot/stdout)
2291 echo "diff $commit_id $testroot/wt (staged changes)" \
2292 > $testroot/stdout.expected
2293 echo -n 'blob - ' >> $testroot/stdout.expected
2294 got tree -r $testroot/repo -i -c $commit_id \
2295 | grep 'numbers$' | cut -d' ' -f 1 \
2296 >> $testroot/stdout.expected
2297 echo -n 'blob + ' >> $testroot/stdout.expected
2298 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2299 >> $testroot/stdout.expected
2300 echo "--- numbers" >> $testroot/stdout.expected
2301 echo "+++ numbers" >> $testroot/stdout.expected
2302 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2303 echo " 1" >> $testroot/stdout.expected
2304 echo "-2" >> $testroot/stdout.expected
2305 echo "+a" >> $testroot/stdout.expected
2306 echo " 3" >> $testroot/stdout.expected
2307 echo " 4" >> $testroot/stdout.expected
2308 echo " 5" >> $testroot/stdout.expected
2309 cmp -s $testroot/stdout.expected $testroot/stdout
2310 ret=$?
2311 if [ $ret -ne 0 ]; then
2312 diff -u $testroot/stdout.expected $testroot/stdout
2314 test_done "$testroot" "$ret"
2318 test_stage_patch_incomplete_script() {
2319 local testroot=`test_init stage_incomplete_script`
2321 jot 16 > $testroot/repo/numbers
2322 echo zzz > $testroot/repo/zzz
2323 (cd $testroot/repo && git add numbers zzz)
2324 git_commit $testroot/repo -m "added files"
2325 local commit_id=`git_show_head $testroot/repo`
2327 got checkout $testroot/repo $testroot/wt > /dev/null
2328 ret=$?
2329 if [ $ret -ne 0 ]; then
2330 test_done "$testroot" "$ret"
2331 return 1
2334 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2335 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2336 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2338 # stage first hunk and then stop responding; got should error out
2339 printf "y\n" > $testroot/patchscript
2340 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2341 > $testroot/stdout 2> $testroot/stderr)
2342 ret=$?
2343 if [ $ret -eq 0 ]; then
2344 echo "got stage command succeeded unexpectedly" >&2
2345 test_done "$testroot" "1"
2346 return 1
2348 cat > $testroot/stdout.expected <<EOF
2349 -----------------------------------------------
2350 @@ -1,5 +1,5 @@
2357 -----------------------------------------------
2358 M numbers (change 1 of 3)
2359 stage this change? [y/n/q] y
2360 -----------------------------------------------
2361 @@ -4,7 +4,7 @@
2370 -----------------------------------------------
2371 M numbers (change 2 of 3)
2372 EOF
2373 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2374 echo "got: invalid patch choice" > $testroot/stderr.expected
2375 cmp -s $testroot/stderr.expected $testroot/stderr
2376 ret=$?
2377 if [ $ret -ne 0 ]; then
2378 diff -u $testroot/stderr.expected $testroot/stderr
2379 test_done "$testroot" "$ret"
2380 return 1
2383 cmp -s $testroot/stdout.expected $testroot/stdout
2384 ret=$?
2385 if [ $ret -ne 0 ]; then
2386 diff -u $testroot/stdout.expected $testroot/stdout
2387 test_done "$testroot" "$ret"
2388 return 1
2391 (cd $testroot/wt && got status > $testroot/stdout)
2392 echo "M numbers" > $testroot/stdout.expected
2393 cmp -s $testroot/stdout.expected $testroot/stdout
2394 ret=$?
2395 if [ $ret -ne 0 ]; then
2396 diff -u $testroot/stdout.expected $testroot/stdout
2397 test_done "$testroot" "$ret"
2398 return 1
2401 (cd $testroot/wt && got diff -s > $testroot/stdout)
2402 echo -n > $testroot/stdout.expected
2403 cmp -s $testroot/stdout.expected $testroot/stdout
2404 ret=$?
2405 if [ $ret -ne 0 ]; then
2406 diff -u $testroot/stdout.expected $testroot/stdout
2408 test_done "$testroot" "$ret"
2412 test_stage_symlink() {
2413 local testroot=`test_init stage_symlink`
2415 (cd $testroot/repo && ln -s alpha alpha.link)
2416 (cd $testroot/repo && ln -s epsilon epsilon.link)
2417 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2418 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2419 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2420 (cd $testroot/repo && git add .)
2421 git_commit $testroot/repo -m "add symlinks"
2422 local head_commit=`git_show_head $testroot/repo`
2424 got checkout $testroot/repo $testroot/wt > /dev/null
2425 ret=$?
2426 if [ $ret -ne 0 ]; then
2427 test_done "$testroot" "$ret"
2428 return 1
2431 (cd $testroot/wt && ln -sf beta alpha.link)
2432 (cd $testroot/wt && ln -sfh gamma epsilon.link)
2433 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2434 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2435 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2436 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2437 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2438 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2439 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2440 (cd $testroot/wt && got add zeta.link > /dev/null)
2442 (cd $testroot/wt && got stage > $testroot/stdout 2> $testroot/stderr)
2443 ret=$?
2444 if [ $ret -eq 0 ]; then
2445 echo "got stage succeeded unexpectedly" >&2
2446 test_done "$testroot" 1
2447 return 1
2449 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
2450 echo "symbolic link points outside of paths under version control" \
2451 >> $testroot/stderr.expected
2452 cmp -s $testroot/stderr.expected $testroot/stderr
2453 ret=$?
2454 if [ $ret -ne 0 ]; then
2455 diff -u $testroot/stderr.expected $testroot/stderr
2456 test_done "$testroot" "$ret"
2457 return 1
2460 (cd $testroot/wt && got stage -S > $testroot/stdout)
2462 cat > $testroot/stdout.expected <<EOF
2463 M alpha.link
2464 A dotgotbar.link
2465 A dotgotfoo.link
2466 M epsilon/beta.link
2467 M epsilon.link
2468 D nonexistent.link
2469 A zeta.link
2470 EOF
2471 cmp -s $testroot/stdout.expected $testroot/stdout
2472 ret=$?
2473 if [ $ret -ne 0 ]; then
2474 diff -u $testroot/stdout.expected $testroot/stdout
2475 test_done "$testroot" "$ret"
2476 return 1
2479 rm $testroot/wt/alpha.link
2480 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2482 (cd $testroot/wt && got diff -s > $testroot/stdout)
2484 echo "diff $head_commit $testroot/wt (staged changes)" \
2485 > $testroot/stdout.expected
2486 echo -n 'blob - ' >> $testroot/stdout.expected
2487 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2488 cut -d' ' -f 1 >> $testroot/stdout.expected
2489 echo -n 'blob + ' >> $testroot/stdout.expected
2490 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2491 >> $testroot/stdout.expected
2492 echo '--- alpha.link' >> $testroot/stdout.expected
2493 echo '+++ alpha.link' >> $testroot/stdout.expected
2494 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2495 echo '-alpha' >> $testroot/stdout.expected
2496 echo '\ No newline at end of file' >> $testroot/stdout.expected
2497 echo '+beta' >> $testroot/stdout.expected
2498 echo '\ No newline at end of file' >> $testroot/stdout.expected
2499 echo 'blob - /dev/null' >> $testroot/stdout.expected
2500 echo -n 'blob + ' >> $testroot/stdout.expected
2501 (cd $testroot/wt && got stage -l dotgotbar.link) | cut -d' ' -f 1 \
2502 >> $testroot/stdout.expected
2503 echo '--- /dev/null' >> $testroot/stdout.expected
2504 echo '+++ dotgotbar.link' >> $testroot/stdout.expected
2505 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2506 echo '+.got/bar' >> $testroot/stdout.expected
2507 echo '\ No newline at end of file' >> $testroot/stdout.expected
2508 echo 'blob - /dev/null' >> $testroot/stdout.expected
2509 echo -n 'blob + ' >> $testroot/stdout.expected
2510 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2511 >> $testroot/stdout.expected
2512 echo '--- /dev/null' >> $testroot/stdout.expected
2513 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2514 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2515 echo '+this is regular file foo' >> $testroot/stdout.expected
2516 echo -n 'blob - ' >> $testroot/stdout.expected
2517 got tree -r $testroot/repo -i epsilon | grep 'beta.link@ -> ../beta$' | \
2518 cut -d' ' -f 1 >> $testroot/stdout.expected
2519 echo -n 'blob + ' >> $testroot/stdout.expected
2520 (cd $testroot/wt && got stage -l epsilon/beta.link) | cut -d' ' -f 1 \
2521 >> $testroot/stdout.expected
2522 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
2523 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
2524 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2525 echo '-../beta' >> $testroot/stdout.expected
2526 echo '\ No newline at end of file' >> $testroot/stdout.expected
2527 echo '+../gamma/delta' >> $testroot/stdout.expected
2528 echo '\ No newline at end of file' >> $testroot/stdout.expected
2529 echo -n 'blob - ' >> $testroot/stdout.expected
2530 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2531 cut -d' ' -f 1 >> $testroot/stdout.expected
2532 echo -n 'blob + ' >> $testroot/stdout.expected
2533 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2534 >> $testroot/stdout.expected
2535 echo '--- epsilon.link' >> $testroot/stdout.expected
2536 echo '+++ epsilon.link' >> $testroot/stdout.expected
2537 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2538 echo '-epsilon' >> $testroot/stdout.expected
2539 echo '\ No newline at end of file' >> $testroot/stdout.expected
2540 echo '+gamma' >> $testroot/stdout.expected
2541 echo '\ No newline at end of file' >> $testroot/stdout.expected
2542 echo -n 'blob - ' >> $testroot/stdout.expected
2543 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2544 cut -d' ' -f 1 >> $testroot/stdout.expected
2545 echo 'blob + /dev/null' >> $testroot/stdout.expected
2546 echo '--- nonexistent.link' >> $testroot/stdout.expected
2547 echo '+++ /dev/null' >> $testroot/stdout.expected
2548 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2549 echo '-nonexistent' >> $testroot/stdout.expected
2550 echo '\ No newline at end of file' >> $testroot/stdout.expected
2551 echo 'blob - /dev/null' >> $testroot/stdout.expected
2552 echo -n 'blob + ' >> $testroot/stdout.expected
2553 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2554 >> $testroot/stdout.expected
2555 echo '--- /dev/null' >> $testroot/stdout.expected
2556 echo '+++ zeta.link' >> $testroot/stdout.expected
2557 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2558 echo '+gamma/delta' >> $testroot/stdout.expected
2559 echo '\ No newline at end of file' >> $testroot/stdout.expected
2561 cmp -s $testroot/stdout.expected $testroot/stdout
2562 ret=$?
2563 if [ $ret -ne 0 ]; then
2564 diff -u $testroot/stdout.expected $testroot/stdout
2565 test_done "$testroot" "$ret"
2566 return 1
2569 (cd $testroot/wt && got commit -m "staged symlink" \
2570 > $testroot/stdout)
2571 ret=$?
2572 if [ $ret -ne 0 ]; then
2573 echo "got commit command failed unexpectedly" >&2
2574 test_done "$testroot" "1"
2575 return 1
2578 local commit_id=`git_show_head $testroot/repo`
2579 echo "A dotgotbar.link" > $testroot/stdout.expected
2580 echo "A dotgotfoo.link" >> $testroot/stdout.expected
2581 echo "A zeta.link" >> $testroot/stdout.expected
2582 echo "M alpha.link" >> $testroot/stdout.expected
2583 echo "M epsilon/beta.link" >> $testroot/stdout.expected
2584 echo "M epsilon.link" >> $testroot/stdout.expected
2585 echo "D nonexistent.link" >> $testroot/stdout.expected
2586 echo "Created commit $commit_id" >> $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 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2596 ret=$?
2597 if [ $ret -ne 0 ]; then
2598 echo "got tree command failed unexpectedly" >&2
2599 test_done "$testroot" "1"
2600 return 1
2603 cat > $testroot/stdout.expected <<EOF
2604 alpha
2605 alpha.link@ -> beta
2606 beta
2607 dotgotbar.link@ -> .got/bar
2608 dotgotfoo.link
2609 epsilon/
2610 epsilon.link@ -> gamma
2611 gamma/
2612 passwd.link@ -> /etc/passwd
2613 zeta.link@ -> gamma/delta
2614 EOF
2615 cmp -s $testroot/stdout.expected $testroot/stdout
2616 ret=$?
2617 if [ $ret -ne 0 ]; then
2618 diff -u $testroot/stdout.expected $testroot/stdout
2619 return 1
2622 if [ -h $testroot/wt/alpha.link ]; then
2623 echo "alpha.link is a symlink"
2624 test_done "$testroot" "1"
2625 return 1
2628 echo 'this is regular file alpha.link' > $testroot/content.expected
2629 cp $testroot/wt/alpha.link $testroot/content
2630 cmp -s $testroot/content.expected $testroot/content
2631 ret=$?
2632 if [ $ret -ne 0 ]; then
2633 diff -u $testroot/content.expected $testroot/content
2634 test_done "$testroot" "$ret"
2635 return 1
2638 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2639 echo "dotgotbar.link is not a symlink"
2640 test_done "$testroot" "1"
2641 return 1
2643 (cd $testroot/wt && got update > /dev/null)
2644 if [ -h $testroot/wt/dotgotbar.link ]; then
2645 echo "dotgotbar.link is a symlink"
2646 test_done "$testroot" "1"
2647 return 1
2649 echo -n ".got/bar" > $testroot/content.expected
2650 cp $testroot/wt/dotgotbar.link $testroot/content
2651 cmp -s $testroot/content.expected $testroot/content
2652 ret=$?
2653 if [ $ret -ne 0 ]; then
2654 diff -u $testroot/content.expected $testroot/content
2655 test_done "$testroot" "$ret"
2656 return 1
2659 if [ -h $testroot/wt/dotgotfoo.link ]; then
2660 echo "dotgotfoo.link is a symlink"
2661 test_done "$testroot" "1"
2662 return 1
2664 echo "this is regular file foo" > $testroot/content.expected
2665 cp $testroot/wt/dotgotfoo.link $testroot/content
2666 cmp -s $testroot/content.expected $testroot/content
2667 ret=$?
2668 if [ $ret -ne 0 ]; then
2669 diff -u $testroot/content.expected $testroot/content
2670 test_done "$testroot" "$ret"
2671 return 1
2674 if ! [ -h $testroot/wt/epsilon.link ]; then
2675 echo "epsilon.link is not a symlink"
2676 test_done "$testroot" "1"
2677 return 1
2680 readlink $testroot/wt/epsilon.link > $testroot/stdout
2681 echo "gamma" > $testroot/stdout.expected
2682 cmp -s $testroot/stdout.expected $testroot/stdout
2683 ret=$?
2684 if [ $ret -ne 0 ]; then
2685 diff -u $testroot/stdout.expected $testroot/stdout
2686 test_done "$testroot" "$ret"
2687 return 1
2690 if [ -h $testroot/wt/passwd.link ]; then
2691 echo "passwd.link is a symlink"
2692 test_done "$testroot" "1"
2693 return 1
2695 echo -n "/etc/passwd" > $testroot/content.expected
2696 cp $testroot/wt/passwd.link $testroot/content
2697 cmp -s $testroot/content.expected $testroot/content
2698 ret=$?
2699 if [ $ret -ne 0 ]; then
2700 diff -u $testroot/content.expected $testroot/content
2701 test_done "$testroot" "$ret"
2702 return 1
2705 if ! [ -h $testroot/wt/zeta.link ]; then
2706 echo "zeta.link is not a symlink"
2707 test_done "$testroot" "1"
2708 return 1
2711 readlink $testroot/wt/zeta.link > $testroot/stdout
2712 echo "gamma/delta" > $testroot/stdout.expected
2713 cmp -s $testroot/stdout.expected $testroot/stdout
2714 ret=$?
2715 if [ $ret -ne 0 ]; then
2716 diff -u $testroot/stdout.expected $testroot/stdout
2717 test_done "$testroot" "$ret"
2718 return 1
2721 test_done "$testroot" "0"
2724 test_stage_patch_symlink() {
2725 local testroot=`test_init stage_patch_symlink`
2727 (cd $testroot/repo && ln -s alpha alpha.link)
2728 (cd $testroot/repo && ln -s epsilon epsilon.link)
2729 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2730 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2731 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2732 (cd $testroot/repo && git add .)
2733 git_commit $testroot/repo -m "add symlinks"
2734 local head_commit=`git_show_head $testroot/repo`
2736 got checkout $testroot/repo $testroot/wt > /dev/null
2737 ret=$?
2738 if [ $ret -ne 0 ]; then
2739 test_done "$testroot" "$ret"
2740 return 1
2743 (cd $testroot/wt && ln -sf beta alpha.link)
2744 (cd $testroot/wt && ln -sfh gamma epsilon.link)
2745 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2746 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2747 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2748 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2749 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2750 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2751 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2752 (cd $testroot/wt && got add zeta.link > /dev/null)
2754 printf "y\nn\ny\nn\ny\ny\ny" > $testroot/patchscript
2755 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2756 > $testroot/stdout)
2758 cat > $testroot/stdout.expected <<EOF
2759 -----------------------------------------------
2760 @@ -1 +1 @@
2761 -alpha
2762 \ No newline at end of file
2763 +beta
2764 \ No newline at end of file
2765 -----------------------------------------------
2766 M alpha.link (change 1 of 1)
2767 stage this change? [y/n/q] y
2768 A dotgotbar.link
2769 stage this addition? [y/n] n
2770 A dotgotfoo.link
2771 stage this addition? [y/n] y
2772 -----------------------------------------------
2773 @@ -1 +1 @@
2774 -../beta
2775 \ No newline at end of file
2776 +../gamma/delta
2777 \ No newline at end of file
2778 -----------------------------------------------
2779 M epsilon/beta.link (change 1 of 1)
2780 stage this change? [y/n/q] n
2781 -----------------------------------------------
2782 @@ -1 +1 @@
2783 -epsilon
2784 \ No newline at end of file
2785 +gamma
2786 \ No newline at end of file
2787 -----------------------------------------------
2788 M epsilon.link (change 1 of 1)
2789 stage this change? [y/n/q] y
2790 D nonexistent.link
2791 stage this deletion? [y/n] y
2792 A zeta.link
2793 stage this addition? [y/n] y
2794 EOF
2795 cmp -s $testroot/stdout.expected $testroot/stdout
2796 ret=$?
2797 if [ $ret -ne 0 ]; then
2798 diff -u $testroot/stdout.expected $testroot/stdout
2799 test_done "$testroot" "$ret"
2800 return 1
2803 rm $testroot/wt/alpha.link
2804 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2806 (cd $testroot/wt && got diff -s > $testroot/stdout)
2808 echo "diff $head_commit $testroot/wt (staged changes)" \
2809 > $testroot/stdout.expected
2810 echo -n 'blob - ' >> $testroot/stdout.expected
2811 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2812 cut -d' ' -f 1 >> $testroot/stdout.expected
2813 echo -n 'blob + ' >> $testroot/stdout.expected
2814 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2815 >> $testroot/stdout.expected
2816 echo '--- alpha.link' >> $testroot/stdout.expected
2817 echo '+++ alpha.link' >> $testroot/stdout.expected
2818 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2819 echo '-alpha' >> $testroot/stdout.expected
2820 echo '\ No newline at end of file' >> $testroot/stdout.expected
2821 echo '+beta' >> $testroot/stdout.expected
2822 echo '\ No newline at end of file' >> $testroot/stdout.expected
2823 echo 'blob - /dev/null' >> $testroot/stdout.expected
2824 echo -n 'blob + ' >> $testroot/stdout.expected
2825 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2826 >> $testroot/stdout.expected
2827 echo '--- /dev/null' >> $testroot/stdout.expected
2828 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2829 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2830 echo '+this is regular file foo' >> $testroot/stdout.expected
2831 echo -n 'blob - ' >> $testroot/stdout.expected
2832 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2833 cut -d' ' -f 1 >> $testroot/stdout.expected
2834 echo -n 'blob + ' >> $testroot/stdout.expected
2835 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2836 >> $testroot/stdout.expected
2837 echo '--- epsilon.link' >> $testroot/stdout.expected
2838 echo '+++ epsilon.link' >> $testroot/stdout.expected
2839 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2840 echo '-epsilon' >> $testroot/stdout.expected
2841 echo '\ No newline at end of file' >> $testroot/stdout.expected
2842 echo '+gamma' >> $testroot/stdout.expected
2843 echo '\ No newline at end of file' >> $testroot/stdout.expected
2844 echo -n 'blob - ' >> $testroot/stdout.expected
2845 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2846 cut -d' ' -f 1 >> $testroot/stdout.expected
2847 echo 'blob + /dev/null' >> $testroot/stdout.expected
2848 echo '--- nonexistent.link' >> $testroot/stdout.expected
2849 echo '+++ /dev/null' >> $testroot/stdout.expected
2850 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2851 echo '-nonexistent' >> $testroot/stdout.expected
2852 echo '\ No newline at end of file' >> $testroot/stdout.expected
2853 echo 'blob - /dev/null' >> $testroot/stdout.expected
2854 echo -n 'blob + ' >> $testroot/stdout.expected
2855 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2856 >> $testroot/stdout.expected
2857 echo '--- /dev/null' >> $testroot/stdout.expected
2858 echo '+++ zeta.link' >> $testroot/stdout.expected
2859 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2860 echo '+gamma/delta' >> $testroot/stdout.expected
2861 echo '\ No newline at end of file' >> $testroot/stdout.expected
2863 cmp -s $testroot/stdout.expected $testroot/stdout
2864 ret=$?
2865 if [ $ret -ne 0 ]; then
2866 diff -u $testroot/stdout.expected $testroot/stdout
2867 test_done "$testroot" "$ret"
2868 return 1
2871 (cd $testroot/wt && got commit -m "staged symlink" \
2872 > $testroot/stdout)
2873 ret=$?
2874 if [ $ret -ne 0 ]; then
2875 echo "got commit command failed unexpectedly" >&2
2876 test_done "$testroot" "1"
2877 return 1
2880 local commit_id=`git_show_head $testroot/repo`
2881 echo "A dotgotfoo.link" > $testroot/stdout.expected
2882 echo "A zeta.link" >> $testroot/stdout.expected
2883 echo "M alpha.link" >> $testroot/stdout.expected
2884 echo "M epsilon.link" >> $testroot/stdout.expected
2885 echo "D nonexistent.link" >> $testroot/stdout.expected
2886 echo "Created commit $commit_id" >> $testroot/stdout.expected
2887 cmp -s $testroot/stdout.expected $testroot/stdout
2888 ret=$?
2889 if [ $ret -ne 0 ]; then
2890 diff -u $testroot/stdout.expected $testroot/stdout
2891 test_done "$testroot" "$ret"
2892 return 1
2895 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2896 ret=$?
2897 if [ $ret -ne 0 ]; then
2898 echo "got tree command failed unexpectedly" >&2
2899 test_done "$testroot" "1"
2900 return 1
2903 cat > $testroot/stdout.expected <<EOF
2904 alpha
2905 alpha.link@ -> beta
2906 beta
2907 dotgotfoo.link
2908 epsilon/
2909 epsilon.link@ -> gamma
2910 gamma/
2911 passwd.link@ -> /etc/passwd
2912 zeta.link@ -> gamma/delta
2913 EOF
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 return 1
2921 if [ -h $testroot/wt/alpha.link ]; then
2922 echo "alpha.link is a symlink"
2923 test_done "$testroot" "1"
2924 return 1
2927 echo 'this is regular file alpha.link' > $testroot/content.expected
2928 cp $testroot/wt/alpha.link $testroot/content
2929 cmp -s $testroot/content.expected $testroot/content
2930 ret=$?
2931 if [ $ret -ne 0 ]; then
2932 diff -u $testroot/content.expected $testroot/content
2933 test_done "$testroot" "$ret"
2934 return 1
2937 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2938 echo "dotgotbar.link is not a symlink"
2939 test_done "$testroot" "1"
2940 return 1
2942 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
2943 echo ".got/bar" > $testroot/stdout.expected
2944 cmp -s $testroot/stdout.expected $testroot/stdout
2945 ret=$?
2946 if [ $ret -ne 0 ]; then
2947 diff -u $testroot/stdout.expected $testroot/stdout
2948 test_done "$testroot" "$ret"
2949 return 1
2952 if [ -h $testroot/wt/dotgotfoo.link ]; then
2953 echo "dotgotfoo.link is a symlink"
2954 test_done "$testroot" "1"
2955 return 1
2957 echo "this is regular file foo" > $testroot/content.expected
2958 cp $testroot/wt/dotgotfoo.link $testroot/content
2959 cmp -s $testroot/content.expected $testroot/content
2960 ret=$?
2961 if [ $ret -ne 0 ]; then
2962 diff -u $testroot/content.expected $testroot/content
2963 test_done "$testroot" "$ret"
2964 return 1
2967 if ! [ -h $testroot/wt/epsilon.link ]; then
2968 echo "epsilon.link is not a symlink"
2969 test_done "$testroot" "1"
2970 return 1
2973 readlink $testroot/wt/epsilon.link > $testroot/stdout
2974 echo "gamma" > $testroot/stdout.expected
2975 cmp -s $testroot/stdout.expected $testroot/stdout
2976 ret=$?
2977 if [ $ret -ne 0 ]; then
2978 diff -u $testroot/stdout.expected $testroot/stdout
2979 test_done "$testroot" "$ret"
2980 return 1
2983 if [ -h $testroot/wt/passwd.link ]; then
2984 echo "passwd.link is a symlink"
2985 test_done "$testroot" "1"
2986 return 1
2988 echo -n "/etc/passwd" > $testroot/content.expected
2989 cp $testroot/wt/passwd.link $testroot/content
2990 cmp -s $testroot/content.expected $testroot/content
2991 ret=$?
2992 if [ $ret -ne 0 ]; then
2993 diff -u $testroot/content.expected $testroot/content
2994 test_done "$testroot" "$ret"
2995 return 1
2998 if ! [ -h $testroot/wt/zeta.link ]; then
2999 echo "zeta.link is not a symlink"
3000 test_done "$testroot" "1"
3001 return 1
3004 readlink $testroot/wt/zeta.link > $testroot/stdout
3005 echo "gamma/delta" > $testroot/stdout.expected
3006 cmp -s $testroot/stdout.expected $testroot/stdout
3007 ret=$?
3008 if [ $ret -ne 0 ]; then
3009 diff -u $testroot/stdout.expected $testroot/stdout
3010 test_done "$testroot" "$ret"
3011 return 1
3014 test_done "$testroot" "0"
3017 test_parseargs "$@"
3018 run_test test_stage_basic
3019 run_test test_stage_no_changes
3020 run_test test_stage_unversioned
3021 run_test test_stage_nonexistent
3022 run_test test_stage_list
3023 run_test test_stage_conflict
3024 run_test test_stage_out_of_date
3025 run_test test_double_stage
3026 run_test test_stage_status
3027 run_test test_stage_add_already_staged_file
3028 run_test test_stage_rm_already_staged_file
3029 run_test test_stage_revert
3030 run_test test_stage_diff
3031 run_test test_stage_histedit
3032 run_test test_stage_rebase
3033 run_test test_stage_update
3034 run_test test_stage_commit_non_staged
3035 run_test test_stage_commit_out_of_date
3036 run_test test_stage_commit
3037 run_test test_stage_patch
3038 run_test test_stage_patch_twice
3039 run_test test_stage_patch_added
3040 run_test test_stage_patch_added_twice
3041 run_test test_stage_patch_removed
3042 run_test test_stage_patch_removed_twice
3043 run_test test_stage_patch_reversed
3044 run_test test_stage_patch_quit
3045 run_test test_stage_patch_incomplete_script
3046 run_test test_stage_symlink
3047 run_test test_stage_patch_symlink