Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 # disable automatic packing for these tests
20 export GOT_TEST_PACK=""
22 test_stage_basic() {
23 local testroot=`test_init stage_basic`
25 got checkout $testroot/repo $testroot/wt > /dev/null
26 ret=$?
27 if [ $ret -ne 0 ]; then
28 test_done "$testroot" "$ret"
29 return 1
30 fi
32 echo "modified file" > $testroot/wt/alpha
33 (cd $testroot/wt && got rm beta > /dev/null)
34 echo "new file" > $testroot/wt/foo
35 (cd $testroot/wt && got add foo > /dev/null)
37 echo ' M alpha' > $testroot/stdout.expected
38 echo ' D beta' >> $testroot/stdout.expected
39 echo ' A foo' >> $testroot/stdout.expected
40 (cd $testroot/wt && got stage > $testroot/stdout)
42 cmp -s $testroot/stdout.expected $testroot/stdout
43 ret=$?
44 if [ $ret -ne 0 ]; then
45 diff -u $testroot/stdout.expected $testroot/stdout
46 fi
47 test_done "$testroot" "$ret"
48 }
50 test_stage_no_changes() {
51 local testroot=`test_init stage_no_changes`
53 got checkout $testroot/repo $testroot/wt > /dev/null
54 ret=$?
55 if [ $ret -ne 0 ]; then
56 test_done "$testroot" "$ret"
57 return 1
58 fi
60 (cd $testroot/wt && got stage alpha beta > $testroot/stdout \
61 2> $testroot/stderr)
62 ret=$?
63 if [ $ret -eq 0 ]; then
64 echo "got stage command succeeded unexpectedly" >&2
65 test_done "$testroot" "1"
66 return 1
67 fi
69 echo "got: no changes to stage" > $testroot/stderr.expected
71 cmp -s $testroot/stderr.expected $testroot/stderr
72 ret=$?
73 if [ $ret -ne 0 ]; then
74 diff -u $testroot/stderr.expected $testroot/stderr
75 test_done "$testroot" "$ret"
76 return 1
77 fi
79 echo -n > $testroot/stdout.expected
80 cmp -s $testroot/stdout.expected $testroot/stdout
81 ret=$?
82 if [ $ret -ne 0 ]; then
83 diff -u $testroot/stdout.expected $testroot/stdout
84 fi
85 test_done "$testroot" "$ret"
86 }
88 test_stage_unversioned() {
89 local testroot=`test_init stage_unversioned`
91 got checkout $testroot/repo $testroot/wt > /dev/null
92 ret=$?
93 if [ $ret -ne 0 ]; then
94 test_done "$testroot" "$ret"
95 return 1
96 fi
98 echo "modified file" > $testroot/wt/alpha
99 touch $testroot/wt/unversioned-file
101 (cd $testroot/wt && got status > $testroot/stdout)
102 echo "M alpha" > $testroot/stdout.expected
103 echo "? unversioned-file" >> $testroot/stdout.expected
104 cmp -s $testroot/stdout.expected $testroot/stdout
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 diff -u $testroot/stdout.expected $testroot/stdout
108 test_done "$testroot" "$ret"
109 return 1
110 fi
112 (cd $testroot/wt && got stage > $testroot/stdout)
113 ret=$?
114 if [ $ret -ne 0 ]; then
115 echo "got stage command failed unexpectedly" >&2
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 echo " M alpha" > $testroot/stdout.expected
121 cmp -s $testroot/stdout.expected $testroot/stdout
122 ret=$?
123 if [ $ret -ne 0 ]; then
124 diff -u $testroot/stdout.expected $testroot/stdout
125 test_done "$testroot" "$ret"
126 return 1
127 fi
129 echo "modified file again" > $testroot/wt/alpha
131 (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
132 2> $testroot/stderr)
133 ret=$?
134 if [ $ret -eq 0 ]; then
135 echo "got stage command succeed unexpectedly" >&2
136 test_done "$testroot" "1"
137 return 1
138 fi
140 echo "got: no changes to stage" > $testroot/stderr.expected
141 cmp -s $testroot/stderr.expected $testroot/stderr
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 diff -u $testroot/stderr.expected $testroot/stderr
145 fi
146 test_done "$testroot" "$ret"
150 test_stage_nonexistent() {
151 local testroot=`test_init stage_nonexistent`
153 got checkout $testroot/repo $testroot/wt > /dev/null
154 ret=$?
155 if [ $ret -ne 0 ]; then
156 test_done "$testroot" "$ret"
157 return 1
158 fi
160 (cd $testroot/wt && got stage nonexistent-file \
161 > $testroot/stdout 2> $testroot/stderr)
162 echo "got: nonexistent-file: No such file or directory" \
163 > $testroot/stderr.expected
164 cmp -s $testroot/stderr.expected $testroot/stderr
165 ret=$?
166 if [ $ret -ne 0 ]; then
167 diff -u $testroot/stderr.expected $testroot/stderr
168 fi
169 test_done "$testroot" "$ret"
172 test_stage_list() {
173 local testroot=`test_init stage_list`
175 got checkout $testroot/repo $testroot/wt > /dev/null
176 ret=$?
177 if [ $ret -ne 0 ]; then
178 test_done "$testroot" "$ret"
179 return 1
180 fi
182 echo "modified file" > $testroot/wt/alpha
183 (cd $testroot/wt && got rm beta > /dev/null)
184 echo "new file" > $testroot/wt/foo
185 (cd $testroot/wt && got add foo > /dev/null)
187 echo ' M alpha' > $testroot/stdout.expected
188 echo ' D beta' >> $testroot/stdout.expected
189 echo ' A foo' >> $testroot/stdout.expected
190 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
192 (cd $testroot/wt && got stage -l > $testroot/stdout)
193 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
194 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
195 echo " M alpha" >> $testroot/stdout.expected
196 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
197 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
198 echo " D beta" >> $testroot/stdout.expected
199 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
200 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
201 echo " A foo" >> $testroot/stdout.expected
202 cmp -s $testroot/stdout.expected $testroot/stdout
203 ret=$?
204 if [ $ret -ne 0 ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 test_done "$testroot" "$ret"
207 return 1
208 fi
210 (cd $testroot/wt && got stage -l epsilon nonexistent \
211 > $testroot/stdout)
213 echo -n > $testroot/stdout.expected
214 cmp -s $testroot/stdout.expected $testroot/stdout
215 ret=$?
216 if [ $ret -ne 0 ]; then
217 diff -u $testroot/stdout.expected $testroot/stdout
218 test_done "$testroot" "$ret"
219 return 1
220 fi
222 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
224 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
225 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
226 echo " M alpha" >> $testroot/stdout.expected
227 cmp -s $testroot/stdout.expected $testroot/stdout
228 ret=$?
229 if [ $ret -ne 0 ]; then
230 diff -u $testroot/stdout.expected $testroot/stdout
231 fi
232 test_done "$testroot" "$ret"
236 test_stage_conflict() {
237 local testroot=`test_init stage_conflict`
238 local initial_commit=`git_show_head $testroot/repo`
240 got checkout $testroot/repo $testroot/wt > /dev/null
241 ret=$?
242 if [ $ret -ne 0 ]; then
243 test_done "$testroot" "$ret"
244 return 1
245 fi
247 echo "modified alpha" > $testroot/wt/alpha
248 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
250 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
252 echo "modified alpha, too" > $testroot/wt/alpha
254 echo "C alpha" > $testroot/stdout.expected
255 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
256 git_show_head $testroot/repo >> $testroot/stdout.expected
257 echo >> $testroot/stdout.expected
258 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
260 (cd $testroot/wt && got update > $testroot/stdout)
262 cmp -s $testroot/stdout.expected $testroot/stdout
263 ret=$?
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 (cd $testroot/wt && got stage alpha > $testroot/stdout \
271 2> $testroot/stderr)
272 ret=$?
273 if [ $ret -eq 0 ]; then
274 echo "got stage command succeeded unexpectedly" >&2
275 test_done "$testroot" "1"
276 return 1
277 fi
279 echo -n > $testroot/stdout.expected
280 echo "got: alpha: cannot stage file in conflicted status" \
281 > $testroot/stderr.expected
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret=$?
285 if [ $ret -ne 0 ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
288 return 1
289 fi
290 cmp -s $testroot/stderr.expected $testroot/stderr
291 ret=$?
292 if [ $ret -ne 0 ]; then
293 diff -u $testroot/stderr.expected $testroot/stderr
294 fi
295 test_done "$testroot" "$ret"
298 test_stage_out_of_date() {
299 local testroot=`test_init stage_out_of_date`
300 local initial_commit=`git_show_head $testroot/repo`
302 got checkout $testroot/repo $testroot/wt > /dev/null
303 ret=$?
304 if [ $ret -ne 0 ]; then
305 test_done "$testroot" "$ret"
306 return 1
307 fi
309 echo "modified alpha" > $testroot/wt/alpha
310 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
312 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
314 echo "modified alpha again" > $testroot/wt/alpha
315 (cd $testroot/wt && got stage alpha > $testroot/stdout \
316 2> $testroot/stderr)
317 ret=$?
318 if [ $ret -eq 0 ]; then
319 echo "got stage command succeeded unexpectedly" >&2
320 test_done "$testroot" "1"
321 return 1
322 fi
324 echo -n > $testroot/stdout.expected
325 echo "got: work tree must be updated before changes can be staged" \
326 > $testroot/stderr.expected
328 cmp -s $testroot/stdout.expected $testroot/stdout
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
333 return 1
334 fi
335 cmp -s $testroot/stderr.expected $testroot/stderr
336 ret=$?
337 if [ $ret -ne 0 ]; then
338 diff -u $testroot/stderr.expected $testroot/stderr
339 fi
340 test_done "$testroot" "$ret"
344 test_double_stage() {
345 local testroot=`test_init double_stage`
347 got checkout $testroot/repo $testroot/wt > /dev/null
348 ret=$?
349 if [ $ret -ne 0 ]; then
350 test_done "$testroot" "$ret"
351 return 1
352 fi
353 echo "modified file" > $testroot/wt/alpha
354 (cd $testroot/wt && got rm beta > /dev/null)
355 echo "new file" > $testroot/wt/foo
356 (cd $testroot/wt && got add foo > /dev/null)
357 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
359 echo "got: no changes to stage" > $testroot/stderr.expected
360 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
361 cmp -s $testroot/stderr.expected $testroot/stderr
362 ret=$?
363 if [ $ret -ne 0 ]; then
364 diff -u $testroot/stderr.expected $testroot/stderr
365 test_done "$testroot" "$ret"
366 return 1
367 fi
369 (cd $testroot/wt && got stage beta \
370 > $testroot/stdout 2> $testroot/stderr)
371 ret=$?
372 if [ $ret -eq 0 ]; then
373 echo "got stage command succeeded unexpectedly" >&2
374 test_done "$testroot" "1"
375 return 1
376 fi
377 echo -n > $testroot/stdout.expected
378 cmp -s $testroot/stdout.expected $testroot/stdout
379 ret=$?
380 if [ $ret -ne 0 ]; then
381 diff -u $testroot/stdout.expected $testroot/stdout
382 test_done "$testroot" "$ret"
383 return 1
384 fi
386 echo "got: no changes to stage" > $testroot/stderr.expected
387 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
388 cmp -s $testroot/stderr.expected $testroot/stderr
389 ret=$?
390 if [ $ret -ne 0 ]; then
391 diff -u $testroot/stderr.expected $testroot/stderr
392 test_done "$testroot" "$ret"
393 return 1
394 fi
396 printf "q\n" > $testroot/patchscript
397 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
398 > $testroot/stdout 2> $testroot/stderr)
399 ret=$?
400 if [ $ret -eq 0 ]; then
401 echo "got stage command succeeded unexpectedly" >&2
402 test_done "$testroot" "1"
403 return 1
404 fi
405 echo -n > $testroot/stdout.expected
406 cmp -s $testroot/stdout.expected $testroot/stdout
407 ret=$?
408 if [ $ret -ne 0 ]; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
411 return 1
412 fi
414 echo "got: no changes to stage" > $testroot/stderr.expected
415 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
416 cmp -s $testroot/stderr.expected $testroot/stderr
417 ret=$?
418 if [ $ret -ne 0 ]; then
419 diff -u $testroot/stderr.expected $testroot/stderr
420 test_done "$testroot" "$ret"
421 return 1
422 fi
424 echo "modified file again" > $testroot/wt/alpha
425 echo "modified new file" > $testroot/wt/foo
427 echo ' M alpha' > $testroot/stdout.expected
428 echo ' A foo' >> $testroot/stdout.expected
429 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
430 cmp -s $testroot/stdout.expected $testroot/stdout
431 ret=$?
432 if [ $ret -ne 0 ]; then
433 diff -u $testroot/stdout.expected $testroot/stdout
434 test_done "$testroot" "$ret"
435 return 1
436 fi
438 echo ' M alpha' > $testroot/stdout.expected
439 echo ' D beta' >> $testroot/stdout.expected
440 echo ' A foo' >> $testroot/stdout.expected
442 (cd $testroot/wt && got status > $testroot/stdout)
443 cmp -s $testroot/stdout.expected $testroot/stdout
444 ret=$?
445 if [ $ret -ne 0 ]; then
446 diff -u $testroot/stdout.expected $testroot/stdout
447 fi
448 test_done "$testroot" "$ret"
451 test_stage_status() {
452 local testroot=`test_init stage_status`
454 got checkout $testroot/repo $testroot/wt > /dev/null
455 ret=$?
456 if [ $ret -ne 0 ]; then
457 test_done "$testroot" "$ret"
458 return 1
459 fi
461 echo "modified file" > $testroot/wt/alpha
462 (cd $testroot/wt && got rm beta > /dev/null)
463 echo "new file" > $testroot/wt/foo
464 (cd $testroot/wt && got add foo > /dev/null)
465 echo "new file" > $testroot/wt/epsilon/new
466 (cd $testroot/wt && got add epsilon/new > /dev/null)
467 echo "modified file" > $testroot/wt/epsilon/zeta
468 (cd $testroot/wt && got rm gamma/delta > /dev/null)
470 echo ' M alpha' > $testroot/stdout.expected
471 echo ' D beta' >> $testroot/stdout.expected
472 echo 'A epsilon/new' >> $testroot/stdout.expected
473 echo 'M epsilon/zeta' >> $testroot/stdout.expected
474 echo ' A foo' >> $testroot/stdout.expected
475 echo 'D gamma/delta' >> $testroot/stdout.expected
476 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
478 (cd $testroot/wt && got status > $testroot/stdout)
479 cmp -s $testroot/stdout.expected $testroot/stdout
480 ret=$?
481 if [ $ret -ne 0 ]; then
482 diff -u $testroot/stdout.expected $testroot/stdout
483 test_done "$testroot" "$ret"
484 return 1
485 fi
487 echo "modified file again" >> $testroot/wt/alpha
488 echo "modified added file again" >> $testroot/wt/foo
490 echo 'MM alpha' > $testroot/stdout.expected
491 echo ' D beta' >> $testroot/stdout.expected
492 echo 'A epsilon/new' >> $testroot/stdout.expected
493 echo 'M epsilon/zeta' >> $testroot/stdout.expected
494 echo 'MA foo' >> $testroot/stdout.expected
495 echo 'D gamma/delta' >> $testroot/stdout.expected
497 (cd $testroot/wt && got status > $testroot/stdout)
498 cmp -s $testroot/stdout.expected $testroot/stdout
499 ret=$?
500 if [ $ret -ne 0 ]; then
501 diff -u $testroot/stdout.expected $testroot/stdout
502 test_done "$testroot" "$ret"
503 return 1
504 fi
506 # test no-op change of added file with new stat(2) timestamp
507 echo "new file" > $testroot/wt/foo
508 echo ' A foo' > $testroot/stdout.expected
509 (cd $testroot/wt && got status foo > $testroot/stdout)
510 cmp -s $testroot/stdout.expected $testroot/stdout
511 ret=$?
512 if [ $ret -ne 0 ]; then
513 diff -u $testroot/stdout.expected $testroot/stdout
514 test_done "$testroot" "$ret"
515 return 1
516 fi
518 # test staged deleted file which is restored on disk
519 echo "new file" > $testroot/wt/beta
520 echo ' D beta' > $testroot/stdout.expected
521 (cd $testroot/wt && got status beta > $testroot/stdout)
522 cmp -s $testroot/stdout.expected $testroot/stdout
523 ret=$?
524 if [ $ret -ne 0 ]; then
525 diff -u $testroot/stdout.expected $testroot/stdout
526 fi
527 test_done "$testroot" "$ret"
531 test_stage_add_already_staged_file() {
532 local testroot=`test_init stage_add_already_staged_file`
534 got checkout $testroot/repo $testroot/wt > /dev/null
535 ret=$?
536 if [ $ret -ne 0 ]; then
537 test_done "$testroot" "$ret"
538 return 1
539 fi
541 echo "modified file" > $testroot/wt/alpha
542 (cd $testroot/wt && got rm beta > /dev/null)
543 echo "new file" > $testroot/wt/foo
544 (cd $testroot/wt && got add foo > /dev/null)
546 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
548 echo -n > $testroot/stdout.expected
549 for f in alpha beta foo; do
550 (cd $testroot/wt && got add $f \
551 > $testroot/stdout 2> $testroot/stderr)
552 echo "got: $f: file has unexpected status" \
553 > $testroot/stderr.expected
554 cmp -s $testroot/stderr.expected $testroot/stderr
555 ret=$?
556 if [ $ret -ne 0 ]; then
557 diff -u $testroot/stderr.expected $testroot/stderr
558 test_done "$testroot" "$ret"
559 return 1
560 fi
561 cmp -s $testroot/stdout.expected $testroot/stdout
562 ret=$?
563 if [ $ret -ne 0 ]; then
564 diff -u $testroot/stdout.expected $testroot/stdout
565 test_done "$testroot" "$ret"
566 return 1
567 fi
568 done
570 echo ' M alpha' > $testroot/stdout.expected
571 echo ' D beta' >> $testroot/stdout.expected
572 echo ' A foo' >> $testroot/stdout.expected
574 (cd $testroot/wt && got status > $testroot/stdout)
575 cmp -s $testroot/stdout.expected $testroot/stdout
576 ret=$?
577 if [ $ret -ne 0 ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 fi
580 test_done "$testroot" "$ret"
583 test_stage_rm_already_staged_file() {
584 local testroot=`test_init stage_rm_already_staged_file`
586 got checkout $testroot/repo $testroot/wt > /dev/null
587 ret=$?
588 if [ $ret -ne 0 ]; then
589 test_done "$testroot" "$ret"
590 return 1
591 fi
593 echo "modified file" > $testroot/wt/alpha
594 (cd $testroot/wt && got rm beta > /dev/null)
595 echo "new file" > $testroot/wt/foo
596 (cd $testroot/wt && got add foo > /dev/null)
598 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
600 (cd $testroot/wt && got rm beta \
601 > $testroot/stdout 2> $testroot/stderr)
602 ret=$?
603 if [ $ret -ne 0 ]; then
604 echo "got rm command failed unexpectedly" >&2
605 test_done "$testroot" "1"
606 return 1
607 fi
608 echo -n > $testroot/stdout.expected
609 cmp -s $testroot/stdout.expected $testroot/stdout
610 ret=$?
611 if [ $ret -ne 0 ]; then
612 diff -u $testroot/stdout.expected $testroot/stdout
613 test_done "$testroot" "$ret"
614 return 1
615 fi
616 echo -n > $testroot/stderr.expected
617 cmp -s $testroot/stderr.expected $testroot/stderr
618 ret=$?
619 if [ $ret -ne 0 ]; then
620 diff -u $testroot/stderr.expected $testroot/stderr
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 for f in alpha foo; do
626 echo "got: $f: file is staged" > $testroot/stderr.expected
627 (cd $testroot/wt && got rm $f \
628 > $testroot/stdout 2> $testroot/stderr)
629 ret=$?
630 if [ $ret -eq 0 ]; then
631 echo "got rm command succeeded unexpectedly" >&2
632 test_done "$testroot" "1"
633 return 1
634 fi
635 cmp -s $testroot/stderr.expected $testroot/stderr
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 diff -u $testroot/stderr.expected $testroot/stderr
639 test_done "$testroot" "$ret"
640 return 1
641 fi
642 done
644 echo ' M alpha' > $testroot/stdout.expected
645 echo ' D beta' >> $testroot/stdout.expected
646 echo ' A foo' >> $testroot/stdout.expected
648 (cd $testroot/wt && got status > $testroot/stdout)
649 cmp -s $testroot/stdout.expected $testroot/stdout
650 ret=$?
651 if [ $ret -ne 0 ]; then
652 diff -u $testroot/stdout.expected $testroot/stdout
653 fi
654 test_done "$testroot" "$ret"
657 test_stage_revert() {
658 local testroot=`test_init stage_revert`
660 got checkout $testroot/repo $testroot/wt > /dev/null
661 ret=$?
662 if [ $ret -ne 0 ]; then
663 test_done "$testroot" "$ret"
664 return 1
665 fi
667 echo "modified alpha" > $testroot/wt/alpha
668 (cd $testroot/wt && got rm beta > /dev/null)
669 echo "new file" > $testroot/wt/foo
670 (cd $testroot/wt && got add foo > /dev/null)
671 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
673 echo "modified file again" >> $testroot/wt/alpha
674 echo "modified added file again" >> $testroot/wt/foo
676 (cd $testroot/wt && got revert alpha > $testroot/stdout)
677 ret=$?
678 if [ $ret -ne 0 ]; then
679 echo "revert command failed unexpectedly" >&2
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 echo "R alpha" > $testroot/stdout.expected
685 cmp -s $testroot/stdout.expected $testroot/stdout
686 ret=$?
687 if [ $ret -ne 0 ]; then
688 diff -u $testroot/stdout.expected $testroot/stdout
689 test_done "$testroot" "$ret"
690 return 1
691 fi
693 echo "modified alpha" > $testroot/content.expected
694 cat $testroot/wt/alpha > $testroot/content
695 cmp -s $testroot/content.expected $testroot/content
696 ret=$?
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/content.expected $testroot/content
699 test_done "$testroot" "$ret"
700 return 1
701 fi
703 echo ' M alpha' > $testroot/stdout.expected
704 echo ' D beta' >> $testroot/stdout.expected
705 echo 'MA foo' >> $testroot/stdout.expected
706 (cd $testroot/wt && got status > $testroot/stdout)
707 cmp -s $testroot/stdout.expected $testroot/stdout
708 ret=$?
709 if [ $ret -ne 0 ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 (cd $testroot/wt && got revert alpha > $testroot/stdout)
716 ret=$?
717 if [ $ret -ne 0 ]; then
718 echo "revert command failed unexpectedly" >&2
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 echo -n > $testroot/stdout.expected
724 cmp -s $testroot/stdout.expected $testroot/stdout
725 ret=$?
726 if [ $ret -ne 0 ]; then
727 diff -u $testroot/stdout.expected $testroot/stdout
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 echo "modified alpha" > $testroot/content.expected
733 cat $testroot/wt/alpha > $testroot/content
734 cmp -s $testroot/content.expected $testroot/content
735 ret=$?
736 if [ $ret -ne 0 ]; then
737 diff -u $testroot/content.expected $testroot/content
738 test_done "$testroot" "$ret"
739 return 1
740 fi
742 (cd $testroot/wt && got revert beta > $testroot/stdout \
743 2> $testroot/stderr)
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 echo "revert command failed unexpectedly" >&2
747 test_done "$testroot" "$ret"
748 return 1
749 fi
751 echo -n > $testroot/stdout.expected
752 cmp -s $testroot/stdout.expected $testroot/stdout
753 ret=$?
754 if [ $ret -ne 0 ]; then
755 diff -u $testroot/stdout.expected $testroot/stdout
756 test_done "$testroot" "$ret"
757 return 1
758 fi
760 echo -n > $testroot/stderr.expected
761 cmp -s $testroot/stderr.expected $testroot/stderr
762 ret=$?
763 if [ $ret -ne 0 ]; then
764 diff -u $testroot/stderr.expected $testroot/stderr
765 test_done "$testroot" "$ret"
766 return 1
767 fi
769 (cd $testroot/wt && got revert foo > $testroot/stdout)
770 ret=$?
771 if [ $ret -ne 0 ]; then
772 echo "revert command failed unexpectedly" >&2
773 test_done "$testroot" "$ret"
774 return 1
775 fi
777 echo "R foo" > $testroot/stdout.expected
778 cmp -s $testroot/stdout.expected $testroot/stdout
779 ret=$?
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
782 test_done "$testroot" "$ret"
783 return 1
784 fi
786 echo "new file" > $testroot/content.expected
787 cat $testroot/wt/foo > $testroot/content
788 cmp -s $testroot/content.expected $testroot/content
789 ret=$?
790 if [ $ret -ne 0 ]; then
791 diff -u $testroot/content.expected $testroot/content
792 test_done "$testroot" "$ret"
793 return 1
794 fi
796 echo ' M alpha' > $testroot/stdout.expected
797 echo ' D beta' >> $testroot/stdout.expected
798 echo ' A foo' >> $testroot/stdout.expected
799 (cd $testroot/wt && got status > $testroot/stdout)
800 cmp -s $testroot/stdout.expected $testroot/stdout
801 ret=$?
802 if [ $ret -ne 0 ]; then
803 diff -u $testroot/stdout.expected $testroot/stdout
804 test_done "$testroot" "$ret"
805 return 1
806 fi
808 (cd $testroot/wt && got revert foo > $testroot/stdout)
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 echo "revert command failed unexpectedly" >&2
812 test_done "$testroot" "$ret"
813 return 1
814 fi
816 echo -n > $testroot/stdout.expected
817 cmp -s $testroot/stdout.expected $testroot/stdout
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 echo "new file" > $testroot/content.expected
826 cat $testroot/wt/foo > $testroot/content
827 cmp -s $testroot/content.expected $testroot/content
828 ret=$?
829 if [ $ret -ne 0 ]; then
830 diff -u $testroot/content.expected $testroot/content
831 test_done "$testroot" "$ret"
832 return 1
833 fi
835 echo ' M alpha' > $testroot/stdout.expected
836 echo ' D beta' >> $testroot/stdout.expected
837 echo ' A foo' >> $testroot/stdout.expected
838 (cd $testroot/wt && got status > $testroot/stdout)
839 cmp -s $testroot/stdout.expected $testroot/stdout
840 ret=$?
841 if [ $ret -ne 0 ]; then
842 diff -u $testroot/stdout.expected $testroot/stdout
843 test_done "$testroot" "$ret"
844 return 1
845 fi
847 echo "modified file again" >> $testroot/wt/alpha
848 echo "modified added file again" >> $testroot/wt/foo
850 (cd $testroot/wt && got revert -R . > $testroot/stdout \
851 2> $testroot/stderr)
852 ret=$?
853 if [ $ret -ne 0 ]; then
854 echo "revert command failed unexpectedly" >&2
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 echo "R alpha" > $testroot/stdout.expected
860 echo "R foo" >> $testroot/stdout.expected
861 cmp -s $testroot/stdout.expected $testroot/stdout
862 ret=$?
863 if [ $ret -ne 0 ]; then
864 diff -u $testroot/stdout.expected $testroot/stdout
865 test_done "$testroot" "$ret"
866 return 1
867 fi
869 echo -n > $testroot/stderr.expected
870 cmp -s $testroot/stderr.expected $testroot/stderr
871 ret=$?
872 if [ $ret -ne 0 ]; then
873 diff -u $testroot/stderr.expected $testroot/stderr
874 test_done "$testroot" "$ret"
875 return 1
876 fi
878 echo ' M alpha' > $testroot/stdout.expected
879 echo ' D beta' >> $testroot/stdout.expected
880 echo ' A foo' >> $testroot/stdout.expected
881 (cd $testroot/wt && got status > $testroot/stdout)
882 cmp -s $testroot/stdout.expected $testroot/stdout
883 ret=$?
884 if [ $ret -ne 0 ]; then
885 diff -u $testroot/stdout.expected $testroot/stdout
886 fi
887 test_done "$testroot" "$ret"
890 test_stage_diff() {
891 local testroot=`test_init stage_diff`
892 local head_commit=`git_show_head $testroot/repo`
894 got checkout $testroot/repo $testroot/wt > /dev/null
895 ret=$?
896 if [ $ret -ne 0 ]; then
897 test_done "$testroot" "$ret"
898 return 1
899 fi
901 echo "modified file" > $testroot/wt/alpha
902 (cd $testroot/wt && got rm beta > /dev/null)
903 echo "new file" > $testroot/wt/foo
904 (cd $testroot/wt && got add foo > /dev/null)
906 (cd $testroot/wt && got diff -s > $testroot/stdout)
907 echo -n > $testroot/stdout.expected
908 cmp -s $testroot/stdout.expected $testroot/stdout
909 ret=$?
910 if [ $ret -ne 0 ]; then
911 diff -u $testroot/stdout.expected $testroot/stdout
912 test_done "$testroot" "$ret"
913 return 1
914 fi
916 echo ' M alpha' > $testroot/stdout.expected
917 echo ' D beta' >> $testroot/stdout.expected
918 echo ' A foo' >> $testroot/stdout.expected
919 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
921 (cd $testroot/wt && got diff > $testroot/stdout)
922 echo -n > $testroot/stdout.expected
923 cmp -s $testroot/stdout.expected $testroot/stdout
924 ret=$?
925 if [ $ret -ne 0 ]; then
926 diff -u $testroot/stdout.expected $testroot/stdout
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 echo "modified file again" > $testroot/wt/alpha
932 echo "new file changed" > $testroot/wt/foo
934 (cd $testroot/wt && got diff > $testroot/stdout)
936 echo "diff $testroot/wt" > $testroot/stdout.expected
937 echo "commit - $head_commit" >> $testroot/stdout.expected
938 echo "path + $testroot/wt" >> $testroot/stdout.expected
939 echo -n 'blob - ' >> $testroot/stdout.expected
940 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
941 >> $testroot/stdout.expected
942 echo ' (staged)' >> $testroot/stdout.expected
943 echo 'file + alpha' >> $testroot/stdout.expected
944 echo '--- alpha' >> $testroot/stdout.expected
945 echo '+++ alpha' >> $testroot/stdout.expected
946 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
947 echo '-modified file' >> $testroot/stdout.expected
948 echo '+modified file again' >> $testroot/stdout.expected
949 echo -n 'blob - ' >> $testroot/stdout.expected
950 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
951 >> $testroot/stdout.expected
952 echo " (staged)" >> $testroot/stdout.expected
953 echo 'file + foo' >> $testroot/stdout.expected
954 echo '--- foo' >> $testroot/stdout.expected
955 echo '+++ foo' >> $testroot/stdout.expected
956 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
957 echo '-new file' >> $testroot/stdout.expected
958 echo '+new file changed' >> $testroot/stdout.expected
960 cmp -s $testroot/stdout.expected $testroot/stdout
961 ret=$?
962 if [ $ret -ne 0 ]; then
963 diff -u $testroot/stdout.expected $testroot/stdout
964 test_done "$testroot" "$ret"
965 return 1
966 fi
968 (cd $testroot/wt && got diff -s > $testroot/stdout)
970 echo "diff -s $testroot/wt" > $testroot/stdout.expected
971 echo "commit - $head_commit" >> $testroot/stdout.expected
972 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
973 echo -n 'blob - ' >> $testroot/stdout.expected
974 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
975 >> $testroot/stdout.expected
976 echo -n 'blob + ' >> $testroot/stdout.expected
977 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
978 >> $testroot/stdout.expected
979 echo '--- alpha' >> $testroot/stdout.expected
980 echo '+++ alpha' >> $testroot/stdout.expected
981 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
982 echo '-alpha' >> $testroot/stdout.expected
983 echo '+modified file' >> $testroot/stdout.expected
984 echo -n 'blob - ' >> $testroot/stdout.expected
985 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
986 >> $testroot/stdout.expected
987 echo 'blob + /dev/null' >> $testroot/stdout.expected
988 echo '--- beta' >> $testroot/stdout.expected
989 echo '+++ /dev/null' >> $testroot/stdout.expected
990 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
991 echo '-beta' >> $testroot/stdout.expected
992 echo 'blob - /dev/null' >> $testroot/stdout.expected
993 echo -n 'blob + ' >> $testroot/stdout.expected
994 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
995 >> $testroot/stdout.expected
996 echo '--- /dev/null' >> $testroot/stdout.expected
997 echo '+++ foo' >> $testroot/stdout.expected
998 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
999 echo '+new file' >> $testroot/stdout.expected
1001 cmp -s $testroot/stdout.expected $testroot/stdout
1002 ret=$?
1003 if [ $ret -ne 0 ]; then
1004 diff -u $testroot/stdout.expected $testroot/stdout
1006 test_done "$testroot" "$ret"
1010 test_stage_histedit() {
1011 local testroot=`test_init stage_histedit`
1012 local orig_commit=`git_show_head $testroot/repo`
1014 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1015 ret=$?
1016 if [ $ret -ne 0 ]; then
1017 test_done "$testroot" "$ret"
1018 return 1
1021 echo "modified file" > $testroot/wt/alpha
1022 (cd $testroot/wt && got stage alpha > /dev/null)
1024 echo "modified alpha on master" > $testroot/repo/alpha
1025 (cd $testroot/repo && git rm -q beta)
1026 echo "new file on master" > $testroot/repo/epsilon/new
1027 (cd $testroot/repo && git add epsilon/new)
1028 git_commit $testroot/repo -m "committing changes"
1029 local old_commit1=`git_show_head $testroot/repo`
1031 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1032 git_commit $testroot/repo -m "committing to zeta on master"
1033 local old_commit2=`git_show_head $testroot/repo`
1035 echo "pick $old_commit1" > $testroot/histedit-script
1036 echo "pick $old_commit2" >> $testroot/histedit-script
1038 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1039 > $testroot/stdout 2> $testroot/stderr)
1040 ret=$?
1041 if [ $ret -eq 0 ]; then
1042 echo "got histedit command succeeded unexpectedly" >&2
1043 test_done "$testroot" "1"
1044 return 1
1047 echo -n > $testroot/stdout.expected
1048 echo "got: alpha: file is staged" > $testroot/stderr.expected
1050 cmp -s $testroot/stderr.expected $testroot/stderr
1051 ret=$?
1052 if [ $ret -ne 0 ]; then
1053 diff -u $testroot/stderr.expected $testroot/stderr
1054 test_done "$testroot" "$ret"
1055 return 1
1057 cmp -s $testroot/stdout.expected $testroot/stdout
1058 ret=$?
1059 if [ $ret -ne 0 ]; then
1060 diff -u $testroot/stdout.expected $testroot/stdout
1062 test_done "$testroot" "$ret"
1066 test_stage_rebase() {
1067 local testroot=`test_init stage_rebase`
1069 (cd $testroot/repo && git checkout -q -b newbranch)
1070 echo "modified delta on branch" > $testroot/repo/gamma/delta
1071 git_commit $testroot/repo -m "committing to delta on newbranch"
1073 echo "modified alpha on branch" > $testroot/repo/alpha
1074 (cd $testroot/repo && git rm -q beta)
1075 echo "new file on branch" > $testroot/repo/epsilon/new
1076 (cd $testroot/repo && git add epsilon/new)
1077 git_commit $testroot/repo -m "committing more changes on newbranch"
1079 local orig_commit1=`git_show_parent_commit $testroot/repo`
1080 local orig_commit2=`git_show_head $testroot/repo`
1082 (cd $testroot/repo && git checkout -q master)
1083 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1084 git_commit $testroot/repo -m "committing to zeta on master"
1085 local master_commit=`git_show_head $testroot/repo`
1087 got checkout $testroot/repo $testroot/wt > /dev/null
1088 ret=$?
1089 if [ $ret -ne 0 ]; then
1090 test_done "$testroot" "$ret"
1091 return 1
1094 echo "modified file" > $testroot/wt/alpha
1095 (cd $testroot/wt && got stage alpha > /dev/null)
1097 (cd $testroot/wt && got rebase newbranch \
1098 > $testroot/stdout 2> $testroot/stderr)
1099 ret=$?
1100 if [ $ret -eq 0 ]; then
1101 echo "got rebase command succeeded unexpectedly" >&2
1102 test_done "$testroot" "1"
1103 return 1
1106 echo -n > $testroot/stdout.expected
1107 echo "got: alpha: file is staged" > $testroot/stderr.expected
1109 cmp -s $testroot/stderr.expected $testroot/stderr
1110 ret=$?
1111 if [ $ret -ne 0 ]; then
1112 diff -u $testroot/stderr.expected $testroot/stderr
1113 test_done "$testroot" "$ret"
1114 return 1
1116 cmp -s $testroot/stdout.expected $testroot/stdout
1117 ret=$?
1118 if [ $ret -ne 0 ]; then
1119 diff -u $testroot/stdout.expected $testroot/stdout
1121 test_done "$testroot" "$ret"
1124 test_stage_update() {
1125 local testroot=`test_init stage_update`
1127 got checkout $testroot/repo $testroot/wt > /dev/null
1128 ret=$?
1129 if [ $ret -ne 0 ]; then
1130 test_done "$testroot" "$ret"
1131 return 1
1134 echo "modified file" > $testroot/wt/alpha
1135 (cd $testroot/wt && got stage alpha > /dev/null)
1137 echo "modified alpha" > $testroot/repo/alpha
1138 git_commit $testroot/repo -m "modified alpha"
1140 (cd $testroot/wt && got update > $testroot/stdout \
1141 2> $testroot/stderr)
1142 ret=$?
1143 if [ $ret -eq 0 ]; then
1144 echo "got update command succeeded unexpectedly" >&2
1145 test_done "$testroot" "1"
1146 return 1
1149 echo -n > $testroot/stdout.expected
1150 echo "got: alpha: file is staged" > $testroot/stderr.expected
1152 cmp -s $testroot/stderr.expected $testroot/stderr
1153 ret=$?
1154 if [ $ret -ne 0 ]; then
1155 diff -u $testroot/stderr.expected $testroot/stderr
1156 test_done "$testroot" "$ret"
1157 return 1
1159 cmp -s $testroot/stdout.expected $testroot/stdout
1160 ret=$?
1161 if [ $ret -ne 0 ]; then
1162 diff -u $testroot/stdout.expected $testroot/stdout
1164 test_done "$testroot" "$ret"
1167 test_stage_commit_non_staged() {
1168 local testroot=`test_init stage_commit_non_staged`
1170 got checkout $testroot/repo $testroot/wt > /dev/null
1171 ret=$?
1172 if [ $ret -ne 0 ]; then
1173 test_done "$testroot" "$ret"
1174 return 1
1177 echo "modified file" > $testroot/wt/alpha
1178 (cd $testroot/wt && got rm beta > /dev/null)
1179 echo "new file" > $testroot/wt/foo
1180 (cd $testroot/wt && got add foo > /dev/null)
1181 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1183 echo "modified file" > $testroot/wt/gamma/delta
1184 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1185 > $testroot/stdout 2> $testroot/stderr)
1186 ret=$?
1187 if [ $ret -eq 0 ]; then
1188 echo "got commit command succeeded unexpectedly" >&2
1189 test_done "$testroot" "1"
1190 return 1
1193 echo -n > $testroot/stdout.expected
1194 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1196 cmp -s $testroot/stderr.expected $testroot/stderr
1197 ret=$?
1198 if [ $ret -ne 0 ]; then
1199 diff -u $testroot/stderr.expected $testroot/stderr
1200 test_done "$testroot" "$ret"
1201 return 1
1203 cmp -s $testroot/stdout.expected $testroot/stdout
1204 ret=$?
1205 if [ $ret -ne 0 ]; then
1206 diff -u $testroot/stdout.expected $testroot/stdout
1208 test_done "$testroot" "$ret"
1211 test_stage_commit_out_of_date() {
1212 local testroot=`test_init stage_commit_out_of_date`
1214 got checkout $testroot/repo $testroot/wt > /dev/null
1215 ret=$?
1216 if [ $ret -ne 0 ]; then
1217 test_done "$testroot" "$ret"
1218 return 1
1221 echo "modified file" > $testroot/wt/alpha
1222 (cd $testroot/wt && got rm beta > /dev/null)
1223 echo "new file" > $testroot/wt/foo
1224 (cd $testroot/wt && got add foo > /dev/null)
1225 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1227 echo "changed file" > $testroot/repo/alpha
1228 git_commit $testroot/repo -m "changed alpha in repo"
1230 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1231 2> $testroot/stderr)
1232 ret=$?
1233 if [ $ret -eq 0 ]; then
1234 echo "got commit command succeeded unexpectedly" >&2
1235 test_done "$testroot" "1"
1236 return 1
1239 echo -n > $testroot/stdout.expected
1240 echo -n "got: work tree must be updated before these changes " \
1241 > $testroot/stderr.expected
1242 echo "can be committed" >> $testroot/stderr.expected
1244 cmp -s $testroot/stderr.expected $testroot/stderr
1245 ret=$?
1246 if [ $ret -ne 0 ]; then
1247 diff -u $testroot/stderr.expected $testroot/stderr
1248 test_done "$testroot" "$ret"
1249 return 1
1251 cmp -s $testroot/stdout.expected $testroot/stdout
1252 ret=$?
1253 if [ $ret -ne 0 ]; then
1254 diff -u $testroot/stdout.expected $testroot/stdout
1255 test_done "$testroot" "$ret"
1256 return 1
1259 (cd $testroot/wt && got update > $testroot/stdout \
1260 2> $testroot/stderr)
1261 echo -n > $testroot/stdout.expected
1262 echo "got: alpha: file is staged" > $testroot/stderr.expected
1264 cmp -s $testroot/stderr.expected $testroot/stderr
1265 ret=$?
1266 if [ $ret -ne 0 ]; then
1267 diff -u $testroot/stderr.expected $testroot/stderr
1268 test_done "$testroot" "$ret"
1269 return 1
1271 cmp -s $testroot/stdout.expected $testroot/stdout
1272 ret=$?
1273 if [ $ret -ne 0 ]; then
1274 diff -u $testroot/stdout.expected $testroot/stdout
1275 test_done "$testroot" "$ret"
1276 return 1
1279 (cd $testroot/wt && got unstage > /dev/null)
1280 (cd $testroot/wt && got update > $testroot/stdout)
1281 ret=$?
1282 if [ $ret -ne 0 ]; then
1283 echo "got update command failed unexpectedly" >&2
1284 test_done "$testroot" "$ret"
1285 return 1
1288 (cd $testroot/wt && got status > $testroot/stdout)
1289 echo "C alpha" > $testroot/stdout.expected
1290 echo "D beta" >> $testroot/stdout.expected
1291 echo "A foo" >> $testroot/stdout.expected
1292 cmp -s $testroot/stdout.expected $testroot/stdout
1293 ret=$?
1294 if [ $ret -ne 0 ]; then
1295 diff -u $testroot/stdout.expected $testroot/stdout
1296 test_done "$testroot" "$ret"
1297 return 1
1300 # resolve conflict
1301 echo "resolved file" > $testroot/wt/alpha
1303 (cd $testroot/wt && got stage > /dev/null)
1305 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1306 ret=$?
1307 if [ $ret -ne 0 ]; then
1308 echo "got commit command failed unexpectedly" >&2
1309 test_done "$testroot" "$ret"
1310 return 1
1313 local commit_id=`git_show_head $testroot/repo`
1314 echo "A foo" > $testroot/stdout.expected
1315 echo "M alpha" >> $testroot/stdout.expected
1316 echo "D beta" >> $testroot/stdout.expected
1317 echo "Created commit $commit_id" >> $testroot/stdout.expected
1318 cmp -s $testroot/stdout.expected $testroot/stdout
1319 ret=$?
1320 if [ $ret -ne 0 ]; then
1321 diff -u $testroot/stdout.expected $testroot/stdout
1323 test_done "$testroot" "$ret"
1327 test_stage_commit() {
1328 local testroot=`test_init stage_commit`
1329 local first_commit=`git_show_head $testroot/repo`
1331 got checkout $testroot/repo $testroot/wt > /dev/null
1332 ret=$?
1333 if [ $ret -ne 0 ]; then
1334 test_done "$testroot" "$ret"
1335 return 1
1338 echo "modified file" > $testroot/wt/alpha
1339 (cd $testroot/wt && got rm beta > /dev/null)
1340 echo "new file" > $testroot/wt/foo
1341 (cd $testroot/wt && got add foo > /dev/null)
1342 echo "modified file" > $testroot/wt/alpha
1343 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1345 echo "modified file again" > $testroot/wt/alpha
1346 echo "new file changed" > $testroot/wt/foo
1347 echo "non-staged change" > $testroot/wt/gamma/delta
1348 echo "non-staged new file" > $testroot/wt/epsilon/new
1349 (cd $testroot/wt && got add epsilon/new > /dev/null)
1350 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1352 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1353 > $testroot/blob_id_alpha
1354 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1355 > $testroot/blob_id_foo
1357 (cd $testroot/wt && got commit -m "staged changes" \
1358 > $testroot/stdout)
1359 ret=$?
1360 if [ $ret -ne 0 ]; then
1361 echo "got commit command failed unexpectedly" >&2
1362 test_done "$testroot" "1"
1363 return 1
1366 local head_commit=`git_show_head $testroot/repo`
1367 echo "A foo" > $testroot/stdout.expected
1368 echo "M alpha" >> $testroot/stdout.expected
1369 echo "D beta" >> $testroot/stdout.expected
1370 echo "Created commit $head_commit" >> $testroot/stdout.expected
1372 cmp -s $testroot/stdout.expected $testroot/stdout
1373 ret=$?
1374 if [ $ret -ne 0 ]; then
1375 diff -u $testroot/stdout.expected $testroot/stdout
1376 test_done "$testroot" "$ret"
1377 return 1
1380 got diff -r $testroot/repo $first_commit $head_commit \
1381 > $testroot/stdout
1383 echo "diff $first_commit $head_commit" \
1384 > $testroot/stdout.expected
1385 echo "commit - $first_commit" >> $testroot/stdout.expected
1386 echo "commit + $head_commit" >> $testroot/stdout.expected
1387 echo -n 'blob - ' >> $testroot/stdout.expected
1388 got tree -r $testroot/repo -i -c $first_commit | \
1389 grep 'alpha$' | cut -d' ' -f 1 \
1390 >> $testroot/stdout.expected
1391 echo -n 'blob + ' >> $testroot/stdout.expected
1392 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1393 echo '--- alpha' >> $testroot/stdout.expected
1394 echo '+++ alpha' >> $testroot/stdout.expected
1395 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1396 echo '-alpha' >> $testroot/stdout.expected
1397 echo '+modified file' >> $testroot/stdout.expected
1398 echo -n 'blob - ' >> $testroot/stdout.expected
1399 got tree -r $testroot/repo -i -c $first_commit \
1400 | grep 'beta$' | cut -d' ' -f 1 | tr -d '\n' \
1401 >> $testroot/stdout.expected
1402 echo " (mode 644)" >> $testroot/stdout.expected
1403 echo 'blob + /dev/null' >> $testroot/stdout.expected
1404 echo '--- beta' >> $testroot/stdout.expected
1405 echo '+++ /dev/null' >> $testroot/stdout.expected
1406 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1407 echo '-beta' >> $testroot/stdout.expected
1408 echo 'blob - /dev/null' >> $testroot/stdout.expected
1409 echo -n 'blob + ' >> $testroot/stdout.expected
1410 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1411 echo " (mode 644)" >> $testroot/stdout.expected
1412 echo '--- /dev/null' >> $testroot/stdout.expected
1413 echo '+++ foo' >> $testroot/stdout.expected
1414 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1415 echo '+new file' >> $testroot/stdout.expected
1417 cmp -s $testroot/stdout.expected $testroot/stdout
1418 ret=$?
1419 if [ $ret -ne 0 ]; then
1420 diff -u $testroot/stdout.expected $testroot/stdout
1421 test_done "$testroot" "$ret"
1422 return 1
1425 echo 'M alpha' > $testroot/stdout.expected
1426 echo 'A epsilon/new' >> $testroot/stdout.expected
1427 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1428 echo 'M foo' >> $testroot/stdout.expected
1429 echo 'M gamma/delta' >> $testroot/stdout.expected
1431 (cd $testroot/wt && got status > $testroot/stdout)
1432 cmp -s $testroot/stdout.expected $testroot/stdout
1433 ret=$?
1434 if [ $ret -ne 0 ]; then
1435 diff -u $testroot/stdout.expected $testroot/stdout
1437 test_done "$testroot" "$ret"
1440 test_stage_patch() {
1441 local testroot=`test_init stage_patch`
1443 jot 16 > $testroot/repo/numbers
1444 (cd $testroot/repo && git add numbers)
1445 git_commit $testroot/repo -m "added numbers file"
1446 local commit_id=`git_show_head $testroot/repo`
1448 got checkout $testroot/repo $testroot/wt > /dev/null
1449 ret=$?
1450 if [ $ret -ne 0 ]; then
1451 test_done "$testroot" "$ret"
1452 return 1
1455 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1456 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1457 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1459 # don't stage any hunks
1460 printf "n\nn\nn\n" > $testroot/patchscript
1461 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1462 numbers > $testroot/stdout 2> $testroot/stderr)
1463 ret=$?
1464 if [ $ret -eq 0 ]; then
1465 echo "got stage command succeeded unexpectedly" >&2
1466 test_done "$testroot" "1"
1467 return 1
1469 cat > $testroot/stdout.expected <<EOF
1470 -----------------------------------------------
1471 @@ -1,5 +1,5 @@
1478 -----------------------------------------------
1479 M numbers (change 1 of 3)
1480 stage this change? [y/n/q] n
1481 -----------------------------------------------
1482 @@ -4,7 +4,7 @@
1491 -----------------------------------------------
1492 M numbers (change 2 of 3)
1493 stage this change? [y/n/q] n
1494 -----------------------------------------------
1495 @@ -13,4 +13,4 @@
1499 -16
1501 -----------------------------------------------
1502 M numbers (change 3 of 3)
1503 stage this change? [y/n/q] n
1504 EOF
1505 cmp -s $testroot/stdout.expected $testroot/stdout
1506 ret=$?
1507 if [ $ret -ne 0 ]; then
1508 diff -u $testroot/stdout.expected $testroot/stdout
1509 test_done "$testroot" "$ret"
1510 return 1
1513 echo "got: no changes to stage" > $testroot/stderr.expected
1514 cmp -s $testroot/stderr.expected $testroot/stderr
1515 ret=$?
1516 if [ $ret -ne 0 ]; then
1517 diff -u $testroot/stderr.expected $testroot/stderr
1518 test_done "$testroot" "$ret"
1519 return 1
1523 (cd $testroot/wt && got status > $testroot/stdout)
1524 echo "M numbers" > $testroot/stdout.expected
1525 cmp -s $testroot/stdout.expected $testroot/stdout
1526 ret=$?
1527 if [ $ret -ne 0 ]; then
1528 diff -u $testroot/stdout.expected $testroot/stdout
1529 test_done "$testroot" "$ret"
1530 return 1
1533 # stage middle hunk
1534 printf "n\ny\nn\n" > $testroot/patchscript
1535 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1536 numbers > $testroot/stdout)
1538 cat > $testroot/stdout.expected <<EOF
1539 -----------------------------------------------
1540 @@ -1,5 +1,5 @@
1547 -----------------------------------------------
1548 M numbers (change 1 of 3)
1549 stage this change? [y/n/q] n
1550 -----------------------------------------------
1551 @@ -4,7 +4,7 @@
1560 -----------------------------------------------
1561 M numbers (change 2 of 3)
1562 stage this change? [y/n/q] y
1563 -----------------------------------------------
1564 @@ -13,4 +13,4 @@
1568 -16
1570 -----------------------------------------------
1571 M numbers (change 3 of 3)
1572 stage this change? [y/n/q] n
1573 EOF
1574 cmp -s $testroot/stdout.expected $testroot/stdout
1575 ret=$?
1576 if [ $ret -ne 0 ]; then
1577 diff -u $testroot/stdout.expected $testroot/stdout
1578 test_done "$testroot" "$ret"
1579 return 1
1582 (cd $testroot/wt && got status > $testroot/stdout)
1583 echo "MM numbers" > $testroot/stdout.expected
1584 cmp -s $testroot/stdout.expected $testroot/stdout
1585 ret=$?
1586 if [ $ret -ne 0 ]; then
1587 diff -u $testroot/stdout.expected $testroot/stdout
1588 test_done "$testroot" "$ret"
1589 return 1
1592 (cd $testroot/wt && got diff -s > $testroot/stdout)
1594 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1595 echo "commit - $commit_id" >> $testroot/stdout.expected
1596 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1597 echo -n 'blob - ' >> $testroot/stdout.expected
1598 got tree -r $testroot/repo -i -c $commit_id \
1599 | grep 'numbers$' | cut -d' ' -f 1 \
1600 >> $testroot/stdout.expected
1601 echo -n 'blob + ' >> $testroot/stdout.expected
1602 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1603 >> $testroot/stdout.expected
1604 echo "--- numbers" >> $testroot/stdout.expected
1605 echo "+++ numbers" >> $testroot/stdout.expected
1606 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1607 echo " 4" >> $testroot/stdout.expected
1608 echo " 5" >> $testroot/stdout.expected
1609 echo " 6" >> $testroot/stdout.expected
1610 echo "-7" >> $testroot/stdout.expected
1611 echo "+b" >> $testroot/stdout.expected
1612 echo " 8" >> $testroot/stdout.expected
1613 echo " 9" >> $testroot/stdout.expected
1614 echo " 10" >> $testroot/stdout.expected
1615 cmp -s $testroot/stdout.expected $testroot/stdout
1616 ret=$?
1617 if [ $ret -ne 0 ]; then
1618 diff -u $testroot/stdout.expected $testroot/stdout
1619 test_done "$testroot" "$ret"
1620 return 1
1623 (cd $testroot/wt && got unstage >/dev/null)
1624 ret=$?
1625 if [ $ret -ne 0 ]; then
1626 echo "got stage command failed unexpectedly" >&2
1627 test_done "$testroot" "1"
1628 return 1
1630 (cd $testroot/wt && got status > $testroot/stdout)
1631 echo "M numbers" > $testroot/stdout.expected
1632 cmp -s $testroot/stdout.expected $testroot/stdout
1633 ret=$?
1634 if [ $ret -ne 0 ]; then
1635 diff -u $testroot/stdout.expected $testroot/stdout
1636 test_done "$testroot" "$ret"
1637 return 1
1640 # stage last hunk
1641 printf "n\nn\ny\n" > $testroot/patchscript
1642 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1643 numbers > $testroot/stdout)
1645 cat > $testroot/stdout.expected <<EOF
1646 -----------------------------------------------
1647 @@ -1,5 +1,5 @@
1654 -----------------------------------------------
1655 M numbers (change 1 of 3)
1656 stage this change? [y/n/q] n
1657 -----------------------------------------------
1658 @@ -4,7 +4,7 @@
1667 -----------------------------------------------
1668 M numbers (change 2 of 3)
1669 stage this change? [y/n/q] n
1670 -----------------------------------------------
1671 @@ -13,4 +13,4 @@
1675 -16
1677 -----------------------------------------------
1678 M numbers (change 3 of 3)
1679 stage this change? [y/n/q] y
1680 EOF
1681 cmp -s $testroot/stdout.expected $testroot/stdout
1682 ret=$?
1683 if [ $ret -ne 0 ]; then
1684 diff -u $testroot/stdout.expected $testroot/stdout
1685 test_done "$testroot" "$ret"
1686 return 1
1689 (cd $testroot/wt && got status > $testroot/stdout)
1690 echo "MM numbers" > $testroot/stdout.expected
1691 cmp -s $testroot/stdout.expected $testroot/stdout
1692 ret=$?
1693 if [ $ret -ne 0 ]; then
1694 diff -u $testroot/stdout.expected $testroot/stdout
1695 test_done "$testroot" "$ret"
1696 return 1
1699 (cd $testroot/wt && got diff -s > $testroot/stdout)
1701 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1702 echo "commit - $commit_id" >> $testroot/stdout.expected
1703 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1704 echo -n 'blob - ' >> $testroot/stdout.expected
1705 got tree -r $testroot/repo -i -c $commit_id \
1706 | grep 'numbers$' | cut -d' ' -f 1 \
1707 >> $testroot/stdout.expected
1708 echo -n 'blob + ' >> $testroot/stdout.expected
1709 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1710 >> $testroot/stdout.expected
1711 echo "--- numbers" >> $testroot/stdout.expected
1712 echo "+++ numbers" >> $testroot/stdout.expected
1713 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1714 echo " 13" >> $testroot/stdout.expected
1715 echo " 14" >> $testroot/stdout.expected
1716 echo " 15" >> $testroot/stdout.expected
1717 echo "-16" >> $testroot/stdout.expected
1718 echo "+c" >> $testroot/stdout.expected
1719 cmp -s $testroot/stdout.expected $testroot/stdout
1720 ret=$?
1721 if [ $ret -ne 0 ]; then
1722 diff -u $testroot/stdout.expected $testroot/stdout
1724 test_done "$testroot" "$ret"
1727 test_stage_patch_twice() {
1728 local testroot=`test_init stage_patch_twice`
1730 jot 16 > $testroot/repo/numbers
1731 (cd $testroot/repo && git add numbers)
1732 git_commit $testroot/repo -m "added numbers file"
1733 local commit_id=`git_show_head $testroot/repo`
1735 got checkout $testroot/repo $testroot/wt > /dev/null
1736 ret=$?
1737 if [ $ret -ne 0 ]; then
1738 test_done "$testroot" "$ret"
1739 return 1
1742 sed -i -e 's/^2$/a/' $testroot/wt/numbers
1743 sed -i -e 's/^7$/b/' $testroot/wt/numbers
1744 sed -i -e 's/^16$/c/' $testroot/wt/numbers
1746 # stage middle hunk
1747 printf "n\ny\nn\n" > $testroot/patchscript
1748 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1749 numbers > $testroot/stdout)
1751 cat > $testroot/stdout.expected <<EOF
1752 -----------------------------------------------
1753 @@ -1,5 +1,5 @@
1760 -----------------------------------------------
1761 M numbers (change 1 of 3)
1762 stage this change? [y/n/q] n
1763 -----------------------------------------------
1764 @@ -4,7 +4,7 @@
1773 -----------------------------------------------
1774 M numbers (change 2 of 3)
1775 stage this change? [y/n/q] y
1776 -----------------------------------------------
1777 @@ -13,4 +13,4 @@
1781 -16
1783 -----------------------------------------------
1784 M numbers (change 3 of 3)
1785 stage this change? [y/n/q] n
1786 EOF
1787 cmp -s $testroot/stdout.expected $testroot/stdout
1788 ret=$?
1789 if [ $ret -ne 0 ]; then
1790 diff -u $testroot/stdout.expected $testroot/stdout
1791 test_done "$testroot" "$ret"
1792 return 1
1795 (cd $testroot/wt && got status > $testroot/stdout)
1796 echo "MM numbers" > $testroot/stdout.expected
1797 cmp -s $testroot/stdout.expected $testroot/stdout
1798 ret=$?
1799 if [ $ret -ne 0 ]; then
1800 diff -u $testroot/stdout.expected $testroot/stdout
1801 test_done "$testroot" "$ret"
1802 return 1
1805 # stage last hunk
1806 printf "n\ny\n" > $testroot/patchscript
1807 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1808 numbers > $testroot/stdout)
1810 cat > $testroot/stdout.expected <<EOF
1811 -----------------------------------------------
1812 @@ -1,5 +1,5 @@
1819 -----------------------------------------------
1820 M numbers (change 1 of 2)
1821 stage this change? [y/n/q] n
1822 -----------------------------------------------
1823 @@ -13,4 +13,4 @@ b
1827 -16
1829 -----------------------------------------------
1830 M numbers (change 2 of 2)
1831 stage this change? [y/n/q] y
1832 EOF
1833 cmp -s $testroot/stdout.expected $testroot/stdout
1834 ret=$?
1835 if [ $ret -ne 0 ]; then
1836 diff -u $testroot/stdout.expected $testroot/stdout
1837 test_done "$testroot" "$ret"
1838 return 1
1841 (cd $testroot/wt && got status > $testroot/stdout)
1842 echo "MM numbers" > $testroot/stdout.expected
1843 cmp -s $testroot/stdout.expected $testroot/stdout
1844 ret=$?
1845 if [ $ret -ne 0 ]; then
1846 diff -u $testroot/stdout.expected $testroot/stdout
1847 test_done "$testroot" "$ret"
1848 return 1
1851 (cd $testroot/wt && got diff -s > $testroot/stdout)
1853 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1854 echo "commit - $commit_id" >> $testroot/stdout.expected
1855 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1856 echo -n 'blob - ' >> $testroot/stdout.expected
1857 got tree -r $testroot/repo -i -c $commit_id \
1858 | grep 'numbers$' | cut -d' ' -f 1 \
1859 >> $testroot/stdout.expected
1860 echo -n 'blob + ' >> $testroot/stdout.expected
1861 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1862 >> $testroot/stdout.expected
1863 echo "--- numbers" >> $testroot/stdout.expected
1864 echo "+++ numbers" >> $testroot/stdout.expected
1865 cat >> $testroot/stdout.expected <<EOF
1866 @@ -4,7 +4,7 @@
1875 @@ -13,4 +13,4 @@
1879 -16
1881 EOF
1882 cmp -s $testroot/stdout.expected $testroot/stdout
1883 ret=$?
1884 if [ $ret -ne 0 ]; then
1885 diff -u $testroot/stdout.expected $testroot/stdout
1886 test_done "$testroot" "$ret"
1887 return 1
1890 (cd $testroot/wt && got diff > $testroot/stdout)
1892 echo "diff $testroot/wt" > $testroot/stdout.expected
1893 echo "commit - $commit_id" >> $testroot/stdout.expected
1894 echo "path + $testroot/wt" >> $testroot/stdout.expected
1895 echo -n 'blob - ' >> $testroot/stdout.expected
1896 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1897 tr -d '\n' >> $testroot/stdout.expected
1898 echo " (staged)" >> $testroot/stdout.expected
1899 echo 'file + numbers' >> $testroot/stdout.expected
1900 echo "--- numbers" >> $testroot/stdout.expected
1901 echo "+++ numbers" >> $testroot/stdout.expected
1902 cat >> $testroot/stdout.expected <<EOF
1903 @@ -1,5 +1,5 @@
1910 EOF
1911 cmp -s $testroot/stdout.expected $testroot/stdout
1912 ret=$?
1913 if [ $ret -ne 0 ]; then
1914 diff -u $testroot/stdout.expected $testroot/stdout
1916 test_done "$testroot" "$ret"
1919 test_stage_patch_added() {
1920 local testroot=`test_init stage_patch_added`
1921 local commit_id=`git_show_head $testroot/repo`
1923 got checkout $testroot/repo $testroot/wt > /dev/null
1924 ret=$?
1925 if [ $ret -ne 0 ]; then
1926 test_done "$testroot" "$ret"
1927 return 1
1930 echo "new" > $testroot/wt/epsilon/new
1931 (cd $testroot/wt && got add epsilon/new > /dev/null)
1933 printf "y\n" > $testroot/patchscript
1934 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1935 epsilon/new > $testroot/stdout)
1937 echo "A epsilon/new" > $testroot/stdout.expected
1938 echo "stage this addition? [y/n] y" >> $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 status > $testroot/stdout)
1948 echo " A epsilon/new" > $testroot/stdout.expected
1949 cmp -s $testroot/stdout.expected $testroot/stdout
1950 ret=$?
1951 if [ $ret -ne 0 ]; then
1952 diff -u $testroot/stdout.expected $testroot/stdout
1953 test_done "$testroot" "$ret"
1954 return 1
1957 (cd $testroot/wt && got diff -s > $testroot/stdout)
1959 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1960 echo "commit - $commit_id" >> $testroot/stdout.expected
1961 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1962 echo 'blob - /dev/null' >> $testroot/stdout.expected
1963 echo -n 'blob + ' >> $testroot/stdout.expected
1964 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1965 >> $testroot/stdout.expected
1966 echo "--- /dev/null" >> $testroot/stdout.expected
1967 echo "+++ epsilon/new" >> $testroot/stdout.expected
1968 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1969 echo "+new" >> $testroot/stdout.expected
1970 cmp -s $testroot/stdout.expected $testroot/stdout
1971 ret=$?
1972 if [ $ret -ne 0 ]; then
1973 diff -u $testroot/stdout.expected $testroot/stdout
1975 test_done "$testroot" "$ret"
1978 test_stage_patch_added_twice() {
1979 local testroot=`test_init stage_patch_added_twice`
1980 local commit_id=`git_show_head $testroot/repo`
1982 got checkout $testroot/repo $testroot/wt > /dev/null
1983 ret=$?
1984 if [ $ret -ne 0 ]; then
1985 test_done "$testroot" "$ret"
1986 return 1
1989 echo "new" > $testroot/wt/epsilon/new
1990 (cd $testroot/wt && got add epsilon/new > /dev/null)
1992 printf "y\n" > $testroot/patchscript
1993 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1994 epsilon/new > $testroot/stdout)
1996 echo "A epsilon/new" > $testroot/stdout.expected
1997 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1998 cmp -s $testroot/stdout.expected $testroot/stdout
1999 ret=$?
2000 if [ $ret -ne 0 ]; then
2001 diff -u $testroot/stdout.expected $testroot/stdout
2002 test_done "$testroot" "$ret"
2003 return 1
2006 (cd $testroot/wt && got status > $testroot/stdout)
2007 echo " A epsilon/new" > $testroot/stdout.expected
2008 cmp -s $testroot/stdout.expected $testroot/stdout
2009 ret=$?
2010 if [ $ret -ne 0 ]; then
2011 diff -u $testroot/stdout.expected $testroot/stdout
2012 test_done "$testroot" "$ret"
2013 return 1
2016 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2017 epsilon/new > $testroot/stdout 2> $testroot/stderr)
2018 ret=$?
2019 if [ $ret -eq 0 ]; then
2020 echo "got stage command succeeded unexpectedly" >&2
2021 test_done "$testroot" "1"
2022 return 1
2025 echo "got: no changes to stage" > $testroot/stderr.expected
2026 cmp -s $testroot/stderr.expected $testroot/stderr
2027 ret=$?
2028 if [ $ret -ne 0 ]; then
2029 diff -u $testroot/stderr.expected $testroot/stderr
2030 test_done "$testroot" "$ret"
2031 return 1
2034 echo -n > $testroot/stdout.expected
2035 cmp -s $testroot/stdout.expected $testroot/stdout
2036 ret=$?
2037 if [ $ret -ne 0 ]; then
2038 diff -u $testroot/stdout.expected $testroot/stdout
2040 test_done "$testroot" "$ret"
2043 test_stage_patch_removed() {
2044 local testroot=`test_init stage_patch_removed`
2045 local commit_id=`git_show_head $testroot/repo`
2047 got checkout $testroot/repo $testroot/wt > /dev/null
2048 ret=$?
2049 if [ $ret -ne 0 ]; then
2050 test_done "$testroot" "$ret"
2051 return 1
2054 (cd $testroot/wt && got rm beta > /dev/null)
2056 printf "y\n" > $testroot/patchscript
2057 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2058 beta > $testroot/stdout)
2060 echo -n > $testroot/stdout.expected
2062 echo "D beta" > $testroot/stdout.expected
2063 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2064 cmp -s $testroot/stdout.expected $testroot/stdout
2065 ret=$?
2066 if [ $ret -ne 0 ]; then
2067 diff -u $testroot/stdout.expected $testroot/stdout
2068 test_done "$testroot" "$ret"
2069 return 1
2072 (cd $testroot/wt && got status > $testroot/stdout)
2073 echo " D beta" > $testroot/stdout.expected
2074 cmp -s $testroot/stdout.expected $testroot/stdout
2075 ret=$?
2076 if [ $ret -ne 0 ]; then
2077 diff -u $testroot/stdout.expected $testroot/stdout
2078 test_done "$testroot" "$ret"
2079 return 1
2082 (cd $testroot/wt && got diff -s > $testroot/stdout)
2084 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2085 echo "commit - $commit_id" >> $testroot/stdout.expected
2086 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2087 echo -n 'blob - ' >> $testroot/stdout.expected
2088 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2089 >> $testroot/stdout.expected
2090 echo 'blob + /dev/null' >> $testroot/stdout.expected
2091 echo "--- beta" >> $testroot/stdout.expected
2092 echo "+++ /dev/null" >> $testroot/stdout.expected
2093 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2094 echo "-beta" >> $testroot/stdout.expected
2095 cmp -s $testroot/stdout.expected $testroot/stdout
2096 ret=$?
2097 if [ $ret -ne 0 ]; then
2098 diff -u $testroot/stdout.expected $testroot/stdout
2100 test_done "$testroot" "$ret"
2103 test_stage_patch_removed_twice() {
2104 local testroot=`test_init stage_patch_removed_twice`
2105 local commit_id=`git_show_head $testroot/repo`
2107 got checkout $testroot/repo $testroot/wt > /dev/null
2108 ret=$?
2109 if [ $ret -ne 0 ]; then
2110 test_done "$testroot" "$ret"
2111 return 1
2114 (cd $testroot/wt && got rm beta > /dev/null)
2116 printf "y\n" > $testroot/patchscript
2117 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2118 beta > $testroot/stdout)
2120 echo -n > $testroot/stdout.expected
2122 echo "D beta" > $testroot/stdout.expected
2123 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2124 cmp -s $testroot/stdout.expected $testroot/stdout
2125 ret=$?
2126 if [ $ret -ne 0 ]; then
2127 diff -u $testroot/stdout.expected $testroot/stdout
2128 test_done "$testroot" "$ret"
2129 return 1
2132 (cd $testroot/wt && got status > $testroot/stdout)
2133 echo " D beta" > $testroot/stdout.expected
2134 cmp -s $testroot/stdout.expected $testroot/stdout
2135 ret=$?
2136 if [ $ret -ne 0 ]; then
2137 diff -u $testroot/stdout.expected $testroot/stdout
2138 test_done "$testroot" "$ret"
2139 return 1
2142 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2143 > $testroot/stdout 2> $testroot/stderr)
2144 ret=$?
2145 if [ $ret -eq 0 ]; then
2146 echo "got stage command succeeded unexpectedly" >&2
2147 test_done "$testroot" "$ret"
2148 return 1
2151 echo "got: no changes to stage" > $testroot/stderr.expected
2152 cmp -s $testroot/stderr.expected $testroot/stderr
2153 ret=$?
2154 if [ $ret -ne 0 ]; then
2155 diff -u $testroot/stderr.expected $testroot/stderr
2156 test_done "$testroot" "$ret"
2157 return 1
2160 echo -n > $testroot/stdout.expected
2161 cmp -s $testroot/stdout.expected $testroot/stdout
2162 ret=$?
2163 if [ $ret -ne 0 ]; then
2164 diff -u $testroot/stdout.expected $testroot/stdout
2166 test_done "$testroot" "$ret"
2169 test_stage_patch_reversed() {
2170 local testroot=`test_init stage_patch_reversed`
2172 got checkout $testroot/repo $testroot/wt > /dev/null
2173 ret=$?
2174 if [ $ret -ne 0 ]; then
2175 test_done "$testroot" "$ret"
2176 return 1
2179 echo 'ALPHA' > $testroot/wt/alpha
2180 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2181 ret=$?
2182 if [ $ret -ne 0 ]; then
2183 test_done "$testroot" "$ret"
2184 return 1
2187 echo ' M alpha' > $testroot/stdout.expected
2188 cmp -s $testroot/stdout.expected $testroot/stdout
2189 ret=$?
2190 if [ $ret -ne 0 ]; then
2191 diff -u $testroot/stdout.expected $testroot/stdout
2192 test_done "$testroot" "$ret"
2193 return 1
2196 echo 'alpha' > $testroot/wt/alpha
2197 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2198 ret=$?
2199 if [ $ret -ne 0 ]; then
2200 test_done "$testroot" "$ret"
2201 return 1
2204 echo ' M alpha' > $testroot/stdout.expected
2205 cmp -s $testroot/stdout.expected $testroot/stdout
2206 ret=$?
2207 if [ $ret -ne 0 ]; then
2208 diff -u $testroot/stdout.expected $testroot/stdout
2209 test_done "$testroot" "$ret"
2210 return 1
2213 (cd $testroot/wt && got status > $testroot/stdout)
2214 cmp -s /dev/null $testroot/stdout
2215 ret=$?
2216 if [ $ret -ne 0 ]; then
2217 diff -u /dev/null $testroot/stdout
2219 test_done "$testroot" "$ret"
2222 test_stage_patch_quit() {
2223 local testroot=`test_init stage_patch_quit`
2225 jot 16 > $testroot/repo/numbers
2226 echo zzz > $testroot/repo/zzz
2227 (cd $testroot/repo && git add numbers zzz)
2228 git_commit $testroot/repo -m "added files"
2229 local commit_id=`git_show_head $testroot/repo`
2231 got checkout $testroot/repo $testroot/wt > /dev/null
2232 ret=$?
2233 if [ $ret -ne 0 ]; then
2234 test_done "$testroot" "$ret"
2235 return 1
2238 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2239 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2240 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2241 (cd $testroot/wt && got rm zzz > /dev/null)
2243 # stage first hunk and quit; and don't pass a path argument to
2244 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2245 printf "y\nq\nn\n" > $testroot/patchscript
2246 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2247 > $testroot/stdout)
2248 ret=$?
2249 if [ $ret -ne 0 ]; then
2250 echo "got stage command failed unexpectedly" >&2
2251 test_done "$testroot" "1"
2252 return 1
2254 cat > $testroot/stdout.expected <<EOF
2255 -----------------------------------------------
2256 @@ -1,5 +1,5 @@
2263 -----------------------------------------------
2264 M numbers (change 1 of 3)
2265 stage this change? [y/n/q] y
2266 -----------------------------------------------
2267 @@ -4,7 +4,7 @@
2276 -----------------------------------------------
2277 M numbers (change 2 of 3)
2278 stage this change? [y/n/q] q
2279 D zzz
2280 stage this deletion? [y/n] n
2281 EOF
2282 cmp -s $testroot/stdout.expected $testroot/stdout
2283 ret=$?
2284 if [ $ret -ne 0 ]; then
2285 diff -u $testroot/stdout.expected $testroot/stdout
2286 test_done "$testroot" "$ret"
2287 return 1
2290 (cd $testroot/wt && got status > $testroot/stdout)
2291 echo "MM numbers" > $testroot/stdout.expected
2292 echo "D zzz" >> $testroot/stdout.expected
2293 cmp -s $testroot/stdout.expected $testroot/stdout
2294 ret=$?
2295 if [ $ret -ne 0 ]; then
2296 diff -u $testroot/stdout.expected $testroot/stdout
2297 test_done "$testroot" "$ret"
2298 return 1
2301 (cd $testroot/wt && got diff -s > $testroot/stdout)
2303 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2304 echo "commit - $commit_id" >> $testroot/stdout.expected
2305 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2306 echo -n 'blob - ' >> $testroot/stdout.expected
2307 got tree -r $testroot/repo -i -c $commit_id \
2308 | grep 'numbers$' | cut -d' ' -f 1 \
2309 >> $testroot/stdout.expected
2310 echo -n 'blob + ' >> $testroot/stdout.expected
2311 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2312 >> $testroot/stdout.expected
2313 echo "--- numbers" >> $testroot/stdout.expected
2314 echo "+++ numbers" >> $testroot/stdout.expected
2315 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2316 echo " 1" >> $testroot/stdout.expected
2317 echo "-2" >> $testroot/stdout.expected
2318 echo "+a" >> $testroot/stdout.expected
2319 echo " 3" >> $testroot/stdout.expected
2320 echo " 4" >> $testroot/stdout.expected
2321 echo " 5" >> $testroot/stdout.expected
2322 cmp -s $testroot/stdout.expected $testroot/stdout
2323 ret=$?
2324 if [ $ret -ne 0 ]; then
2325 diff -u $testroot/stdout.expected $testroot/stdout
2327 test_done "$testroot" "$ret"
2331 test_stage_patch_incomplete_script() {
2332 local testroot=`test_init stage_incomplete_script`
2334 jot 16 > $testroot/repo/numbers
2335 echo zzz > $testroot/repo/zzz
2336 (cd $testroot/repo && git add numbers zzz)
2337 git_commit $testroot/repo -m "added files"
2338 local commit_id=`git_show_head $testroot/repo`
2340 got checkout $testroot/repo $testroot/wt > /dev/null
2341 ret=$?
2342 if [ $ret -ne 0 ]; then
2343 test_done "$testroot" "$ret"
2344 return 1
2347 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2348 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2349 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2351 # stage first hunk and then stop responding; got should error out
2352 printf "y\n" > $testroot/patchscript
2353 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2354 > $testroot/stdout 2> $testroot/stderr)
2355 ret=$?
2356 if [ $ret -eq 0 ]; then
2357 echo "got stage command succeeded unexpectedly" >&2
2358 test_done "$testroot" "1"
2359 return 1
2361 cat > $testroot/stdout.expected <<EOF
2362 -----------------------------------------------
2363 @@ -1,5 +1,5 @@
2370 -----------------------------------------------
2371 M numbers (change 1 of 3)
2372 stage this change? [y/n/q] y
2373 -----------------------------------------------
2374 @@ -4,7 +4,7 @@
2383 -----------------------------------------------
2384 M numbers (change 2 of 3)
2385 EOF
2386 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2387 echo "got: invalid patch choice" > $testroot/stderr.expected
2388 cmp -s $testroot/stderr.expected $testroot/stderr
2389 ret=$?
2390 if [ $ret -ne 0 ]; then
2391 diff -u $testroot/stderr.expected $testroot/stderr
2392 test_done "$testroot" "$ret"
2393 return 1
2396 cmp -s $testroot/stdout.expected $testroot/stdout
2397 ret=$?
2398 if [ $ret -ne 0 ]; then
2399 diff -u $testroot/stdout.expected $testroot/stdout
2400 test_done "$testroot" "$ret"
2401 return 1
2404 (cd $testroot/wt && got status > $testroot/stdout)
2405 echo "M numbers" > $testroot/stdout.expected
2406 cmp -s $testroot/stdout.expected $testroot/stdout
2407 ret=$?
2408 if [ $ret -ne 0 ]; then
2409 diff -u $testroot/stdout.expected $testroot/stdout
2410 test_done "$testroot" "$ret"
2411 return 1
2414 (cd $testroot/wt && got diff -s > $testroot/stdout)
2415 echo -n > $testroot/stdout.expected
2416 cmp -s $testroot/stdout.expected $testroot/stdout
2417 ret=$?
2418 if [ $ret -ne 0 ]; then
2419 diff -u $testroot/stdout.expected $testroot/stdout
2421 test_done "$testroot" "$ret"
2425 test_stage_symlink() {
2426 local testroot=`test_init stage_symlink`
2428 (cd $testroot/repo && ln -s alpha alpha.link)
2429 (cd $testroot/repo && ln -s epsilon epsilon.link)
2430 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2431 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2432 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2433 (cd $testroot/repo && git add .)
2434 git_commit $testroot/repo -m "add symlinks"
2435 local head_commit=`git_show_head $testroot/repo`
2437 got checkout $testroot/repo $testroot/wt > /dev/null
2438 ret=$?
2439 if [ $ret -ne 0 ]; then
2440 test_done "$testroot" "$ret"
2441 return 1
2444 (cd $testroot/wt && ln -sf beta alpha.link)
2445 (cd $testroot/wt && ln -sfh gamma epsilon.link)
2446 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2447 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2448 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2449 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2450 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2451 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2452 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2453 (cd $testroot/wt && got add zeta.link > /dev/null)
2455 (cd $testroot/wt && got stage > $testroot/stdout 2> $testroot/stderr)
2456 ret=$?
2457 if [ $ret -eq 0 ]; then
2458 echo "got stage succeeded unexpectedly" >&2
2459 test_done "$testroot" 1
2460 return 1
2462 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
2463 echo "symbolic link points outside of paths under version control" \
2464 >> $testroot/stderr.expected
2465 cmp -s $testroot/stderr.expected $testroot/stderr
2466 ret=$?
2467 if [ $ret -ne 0 ]; then
2468 diff -u $testroot/stderr.expected $testroot/stderr
2469 test_done "$testroot" "$ret"
2470 return 1
2473 (cd $testroot/wt && got stage -S > $testroot/stdout)
2475 cat > $testroot/stdout.expected <<EOF
2476 M alpha.link
2477 A dotgotbar.link
2478 A dotgotfoo.link
2479 M epsilon/beta.link
2480 M epsilon.link
2481 D nonexistent.link
2482 A zeta.link
2483 EOF
2484 cmp -s $testroot/stdout.expected $testroot/stdout
2485 ret=$?
2486 if [ $ret -ne 0 ]; then
2487 diff -u $testroot/stdout.expected $testroot/stdout
2488 test_done "$testroot" "$ret"
2489 return 1
2492 rm $testroot/wt/alpha.link
2493 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2495 (cd $testroot/wt && got diff -s > $testroot/stdout)
2497 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2498 echo "commit - $head_commit" >> $testroot/stdout.expected
2499 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2500 echo -n 'blob - ' >> $testroot/stdout.expected
2501 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2502 cut -d' ' -f 1 >> $testroot/stdout.expected
2503 echo -n 'blob + ' >> $testroot/stdout.expected
2504 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2505 >> $testroot/stdout.expected
2506 echo '--- alpha.link' >> $testroot/stdout.expected
2507 echo '+++ alpha.link' >> $testroot/stdout.expected
2508 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2509 echo '-alpha' >> $testroot/stdout.expected
2510 echo '\ No newline at end of file' >> $testroot/stdout.expected
2511 echo '+beta' >> $testroot/stdout.expected
2512 echo '\ No newline at end of file' >> $testroot/stdout.expected
2513 echo 'blob - /dev/null' >> $testroot/stdout.expected
2514 echo -n 'blob + ' >> $testroot/stdout.expected
2515 (cd $testroot/wt && got stage -l dotgotbar.link) | cut -d' ' -f 1 \
2516 >> $testroot/stdout.expected
2517 echo '--- /dev/null' >> $testroot/stdout.expected
2518 echo '+++ dotgotbar.link' >> $testroot/stdout.expected
2519 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2520 echo '+.got/bar' >> $testroot/stdout.expected
2521 echo '\ No newline at end of file' >> $testroot/stdout.expected
2522 echo 'blob - /dev/null' >> $testroot/stdout.expected
2523 echo -n 'blob + ' >> $testroot/stdout.expected
2524 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2525 >> $testroot/stdout.expected
2526 echo '--- /dev/null' >> $testroot/stdout.expected
2527 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2528 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2529 echo '+this is regular file foo' >> $testroot/stdout.expected
2530 echo -n 'blob - ' >> $testroot/stdout.expected
2531 got tree -r $testroot/repo -i epsilon | grep 'beta.link@ -> ../beta$' | \
2532 cut -d' ' -f 1 >> $testroot/stdout.expected
2533 echo -n 'blob + ' >> $testroot/stdout.expected
2534 (cd $testroot/wt && got stage -l epsilon/beta.link) | cut -d' ' -f 1 \
2535 >> $testroot/stdout.expected
2536 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
2537 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
2538 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2539 echo '-../beta' >> $testroot/stdout.expected
2540 echo '\ No newline at end of file' >> $testroot/stdout.expected
2541 echo '+../gamma/delta' >> $testroot/stdout.expected
2542 echo '\ No newline at end of file' >> $testroot/stdout.expected
2543 echo -n 'blob - ' >> $testroot/stdout.expected
2544 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2545 cut -d' ' -f 1 >> $testroot/stdout.expected
2546 echo -n 'blob + ' >> $testroot/stdout.expected
2547 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2548 >> $testroot/stdout.expected
2549 echo '--- epsilon.link' >> $testroot/stdout.expected
2550 echo '+++ epsilon.link' >> $testroot/stdout.expected
2551 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2552 echo '-epsilon' >> $testroot/stdout.expected
2553 echo '\ No newline at end of file' >> $testroot/stdout.expected
2554 echo '+gamma' >> $testroot/stdout.expected
2555 echo '\ No newline at end of file' >> $testroot/stdout.expected
2556 echo -n 'blob - ' >> $testroot/stdout.expected
2557 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2558 cut -d' ' -f 1 >> $testroot/stdout.expected
2559 echo 'blob + /dev/null' >> $testroot/stdout.expected
2560 echo '--- nonexistent.link' >> $testroot/stdout.expected
2561 echo '+++ /dev/null' >> $testroot/stdout.expected
2562 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2563 echo '-nonexistent' >> $testroot/stdout.expected
2564 echo '\ No newline at end of file' >> $testroot/stdout.expected
2565 echo 'blob - /dev/null' >> $testroot/stdout.expected
2566 echo -n 'blob + ' >> $testroot/stdout.expected
2567 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2568 >> $testroot/stdout.expected
2569 echo '--- /dev/null' >> $testroot/stdout.expected
2570 echo '+++ zeta.link' >> $testroot/stdout.expected
2571 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2572 echo '+gamma/delta' >> $testroot/stdout.expected
2573 echo '\ No newline at end of file' >> $testroot/stdout.expected
2575 cmp -s $testroot/stdout.expected $testroot/stdout
2576 ret=$?
2577 if [ $ret -ne 0 ]; then
2578 diff -u $testroot/stdout.expected $testroot/stdout
2579 test_done "$testroot" "$ret"
2580 return 1
2583 (cd $testroot/wt && got commit -m "staged symlink" \
2584 > $testroot/stdout)
2585 ret=$?
2586 if [ $ret -ne 0 ]; then
2587 echo "got commit command failed unexpectedly" >&2
2588 test_done "$testroot" "1"
2589 return 1
2592 local commit_id=`git_show_head $testroot/repo`
2593 echo "A dotgotbar.link" > $testroot/stdout.expected
2594 echo "A dotgotfoo.link" >> $testroot/stdout.expected
2595 echo "A zeta.link" >> $testroot/stdout.expected
2596 echo "M alpha.link" >> $testroot/stdout.expected
2597 echo "M epsilon/beta.link" >> $testroot/stdout.expected
2598 echo "M epsilon.link" >> $testroot/stdout.expected
2599 echo "D nonexistent.link" >> $testroot/stdout.expected
2600 echo "Created commit $commit_id" >> $testroot/stdout.expected
2601 cmp -s $testroot/stdout.expected $testroot/stdout
2602 ret=$?
2603 if [ $ret -ne 0 ]; then
2604 diff -u $testroot/stdout.expected $testroot/stdout
2605 test_done "$testroot" "$ret"
2606 return 1
2609 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2610 ret=$?
2611 if [ $ret -ne 0 ]; then
2612 echo "got tree command failed unexpectedly" >&2
2613 test_done "$testroot" "1"
2614 return 1
2617 cat > $testroot/stdout.expected <<EOF
2618 alpha
2619 alpha.link@ -> beta
2620 beta
2621 dotgotbar.link@ -> .got/bar
2622 dotgotfoo.link
2623 epsilon/
2624 epsilon.link@ -> gamma
2625 gamma/
2626 passwd.link@ -> /etc/passwd
2627 zeta.link@ -> gamma/delta
2628 EOF
2629 cmp -s $testroot/stdout.expected $testroot/stdout
2630 ret=$?
2631 if [ $ret -ne 0 ]; then
2632 diff -u $testroot/stdout.expected $testroot/stdout
2633 return 1
2636 if [ -h $testroot/wt/alpha.link ]; then
2637 echo "alpha.link is a symlink"
2638 test_done "$testroot" "1"
2639 return 1
2642 echo 'this is regular file alpha.link' > $testroot/content.expected
2643 cp $testroot/wt/alpha.link $testroot/content
2644 cmp -s $testroot/content.expected $testroot/content
2645 ret=$?
2646 if [ $ret -ne 0 ]; then
2647 diff -u $testroot/content.expected $testroot/content
2648 test_done "$testroot" "$ret"
2649 return 1
2652 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2653 echo "dotgotbar.link is not a symlink"
2654 test_done "$testroot" "1"
2655 return 1
2657 (cd $testroot/wt && got update > /dev/null)
2658 if [ -h $testroot/wt/dotgotbar.link ]; then
2659 echo "dotgotbar.link is a symlink"
2660 test_done "$testroot" "1"
2661 return 1
2663 echo -n ".got/bar" > $testroot/content.expected
2664 cp $testroot/wt/dotgotbar.link $testroot/content
2665 cmp -s $testroot/content.expected $testroot/content
2666 ret=$?
2667 if [ $ret -ne 0 ]; then
2668 diff -u $testroot/content.expected $testroot/content
2669 test_done "$testroot" "$ret"
2670 return 1
2673 if [ -h $testroot/wt/dotgotfoo.link ]; then
2674 echo "dotgotfoo.link is a symlink"
2675 test_done "$testroot" "1"
2676 return 1
2678 echo "this is regular file foo" > $testroot/content.expected
2679 cp $testroot/wt/dotgotfoo.link $testroot/content
2680 cmp -s $testroot/content.expected $testroot/content
2681 ret=$?
2682 if [ $ret -ne 0 ]; then
2683 diff -u $testroot/content.expected $testroot/content
2684 test_done "$testroot" "$ret"
2685 return 1
2688 if ! [ -h $testroot/wt/epsilon.link ]; then
2689 echo "epsilon.link is not a symlink"
2690 test_done "$testroot" "1"
2691 return 1
2694 readlink $testroot/wt/epsilon.link > $testroot/stdout
2695 echo "gamma" > $testroot/stdout.expected
2696 cmp -s $testroot/stdout.expected $testroot/stdout
2697 ret=$?
2698 if [ $ret -ne 0 ]; then
2699 diff -u $testroot/stdout.expected $testroot/stdout
2700 test_done "$testroot" "$ret"
2701 return 1
2704 if [ -h $testroot/wt/passwd.link ]; then
2705 echo "passwd.link is a symlink"
2706 test_done "$testroot" "1"
2707 return 1
2709 echo -n "/etc/passwd" > $testroot/content.expected
2710 cp $testroot/wt/passwd.link $testroot/content
2711 cmp -s $testroot/content.expected $testroot/content
2712 ret=$?
2713 if [ $ret -ne 0 ]; then
2714 diff -u $testroot/content.expected $testroot/content
2715 test_done "$testroot" "$ret"
2716 return 1
2719 if ! [ -h $testroot/wt/zeta.link ]; then
2720 echo "zeta.link is not a symlink"
2721 test_done "$testroot" "1"
2722 return 1
2725 readlink $testroot/wt/zeta.link > $testroot/stdout
2726 echo "gamma/delta" > $testroot/stdout.expected
2727 cmp -s $testroot/stdout.expected $testroot/stdout
2728 ret=$?
2729 if [ $ret -ne 0 ]; then
2730 diff -u $testroot/stdout.expected $testroot/stdout
2731 test_done "$testroot" "$ret"
2732 return 1
2735 test_done "$testroot" "0"
2738 test_stage_patch_symlink() {
2739 local testroot=`test_init stage_patch_symlink`
2741 (cd $testroot/repo && ln -s alpha alpha.link)
2742 (cd $testroot/repo && ln -s epsilon epsilon.link)
2743 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2744 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2745 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2746 (cd $testroot/repo && git add .)
2747 git_commit $testroot/repo -m "add symlinks"
2748 local head_commit=`git_show_head $testroot/repo`
2750 got checkout $testroot/repo $testroot/wt > /dev/null
2751 ret=$?
2752 if [ $ret -ne 0 ]; then
2753 test_done "$testroot" "$ret"
2754 return 1
2757 (cd $testroot/wt && ln -sf beta alpha.link)
2758 (cd $testroot/wt && ln -sfh gamma epsilon.link)
2759 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2760 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2761 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2762 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2763 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2764 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2765 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2766 (cd $testroot/wt && got add zeta.link > /dev/null)
2768 printf "y\nn\ny\nn\ny\ny\ny" > $testroot/patchscript
2769 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2770 > $testroot/stdout)
2772 cat > $testroot/stdout.expected <<EOF
2773 -----------------------------------------------
2774 @@ -1 +1 @@
2775 -alpha
2776 \ No newline at end of file
2777 +beta
2778 \ No newline at end of file
2779 -----------------------------------------------
2780 M alpha.link (change 1 of 1)
2781 stage this change? [y/n/q] y
2782 A dotgotbar.link
2783 stage this addition? [y/n] n
2784 A dotgotfoo.link
2785 stage this addition? [y/n] y
2786 -----------------------------------------------
2787 @@ -1 +1 @@
2788 -../beta
2789 \ No newline at end of file
2790 +../gamma/delta
2791 \ No newline at end of file
2792 -----------------------------------------------
2793 M epsilon/beta.link (change 1 of 1)
2794 stage this change? [y/n/q] n
2795 -----------------------------------------------
2796 @@ -1 +1 @@
2797 -epsilon
2798 \ No newline at end of file
2799 +gamma
2800 \ No newline at end of file
2801 -----------------------------------------------
2802 M epsilon.link (change 1 of 1)
2803 stage this change? [y/n/q] y
2804 D nonexistent.link
2805 stage this deletion? [y/n] y
2806 A zeta.link
2807 stage this addition? [y/n] y
2808 EOF
2809 cmp -s $testroot/stdout.expected $testroot/stdout
2810 ret=$?
2811 if [ $ret -ne 0 ]; then
2812 diff -u $testroot/stdout.expected $testroot/stdout
2813 test_done "$testroot" "$ret"
2814 return 1
2817 rm $testroot/wt/alpha.link
2818 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2820 (cd $testroot/wt && got diff -s > $testroot/stdout)
2822 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2823 echo "commit - $head_commit" >> $testroot/stdout.expected
2824 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2825 echo -n 'blob - ' >> $testroot/stdout.expected
2826 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2827 cut -d' ' -f 1 >> $testroot/stdout.expected
2828 echo -n 'blob + ' >> $testroot/stdout.expected
2829 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2830 >> $testroot/stdout.expected
2831 echo '--- alpha.link' >> $testroot/stdout.expected
2832 echo '+++ alpha.link' >> $testroot/stdout.expected
2833 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2834 echo '-alpha' >> $testroot/stdout.expected
2835 echo '\ No newline at end of file' >> $testroot/stdout.expected
2836 echo '+beta' >> $testroot/stdout.expected
2837 echo '\ No newline at end of file' >> $testroot/stdout.expected
2838 echo 'blob - /dev/null' >> $testroot/stdout.expected
2839 echo -n 'blob + ' >> $testroot/stdout.expected
2840 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2841 >> $testroot/stdout.expected
2842 echo '--- /dev/null' >> $testroot/stdout.expected
2843 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2844 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2845 echo '+this is regular file foo' >> $testroot/stdout.expected
2846 echo -n 'blob - ' >> $testroot/stdout.expected
2847 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2848 cut -d' ' -f 1 >> $testroot/stdout.expected
2849 echo -n 'blob + ' >> $testroot/stdout.expected
2850 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2851 >> $testroot/stdout.expected
2852 echo '--- epsilon.link' >> $testroot/stdout.expected
2853 echo '+++ epsilon.link' >> $testroot/stdout.expected
2854 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2855 echo '-epsilon' >> $testroot/stdout.expected
2856 echo '\ No newline at end of file' >> $testroot/stdout.expected
2857 echo '+gamma' >> $testroot/stdout.expected
2858 echo '\ No newline at end of file' >> $testroot/stdout.expected
2859 echo -n 'blob - ' >> $testroot/stdout.expected
2860 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2861 cut -d' ' -f 1 >> $testroot/stdout.expected
2862 echo 'blob + /dev/null' >> $testroot/stdout.expected
2863 echo '--- nonexistent.link' >> $testroot/stdout.expected
2864 echo '+++ /dev/null' >> $testroot/stdout.expected
2865 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2866 echo '-nonexistent' >> $testroot/stdout.expected
2867 echo '\ No newline at end of file' >> $testroot/stdout.expected
2868 echo 'blob - /dev/null' >> $testroot/stdout.expected
2869 echo -n 'blob + ' >> $testroot/stdout.expected
2870 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2871 >> $testroot/stdout.expected
2872 echo '--- /dev/null' >> $testroot/stdout.expected
2873 echo '+++ zeta.link' >> $testroot/stdout.expected
2874 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2875 echo '+gamma/delta' >> $testroot/stdout.expected
2876 echo '\ No newline at end of file' >> $testroot/stdout.expected
2878 cmp -s $testroot/stdout.expected $testroot/stdout
2879 ret=$?
2880 if [ $ret -ne 0 ]; then
2881 diff -u $testroot/stdout.expected $testroot/stdout
2882 test_done "$testroot" "$ret"
2883 return 1
2886 (cd $testroot/wt && got commit -m "staged symlink" \
2887 > $testroot/stdout)
2888 ret=$?
2889 if [ $ret -ne 0 ]; then
2890 echo "got commit command failed unexpectedly" >&2
2891 test_done "$testroot" "1"
2892 return 1
2895 local commit_id=`git_show_head $testroot/repo`
2896 echo "A dotgotfoo.link" > $testroot/stdout.expected
2897 echo "A zeta.link" >> $testroot/stdout.expected
2898 echo "M alpha.link" >> $testroot/stdout.expected
2899 echo "M epsilon.link" >> $testroot/stdout.expected
2900 echo "D nonexistent.link" >> $testroot/stdout.expected
2901 echo "Created commit $commit_id" >> $testroot/stdout.expected
2902 cmp -s $testroot/stdout.expected $testroot/stdout
2903 ret=$?
2904 if [ $ret -ne 0 ]; then
2905 diff -u $testroot/stdout.expected $testroot/stdout
2906 test_done "$testroot" "$ret"
2907 return 1
2910 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2911 ret=$?
2912 if [ $ret -ne 0 ]; then
2913 echo "got tree command failed unexpectedly" >&2
2914 test_done "$testroot" "1"
2915 return 1
2918 cat > $testroot/stdout.expected <<EOF
2919 alpha
2920 alpha.link@ -> beta
2921 beta
2922 dotgotfoo.link
2923 epsilon/
2924 epsilon.link@ -> gamma
2925 gamma/
2926 passwd.link@ -> /etc/passwd
2927 zeta.link@ -> gamma/delta
2928 EOF
2929 cmp -s $testroot/stdout.expected $testroot/stdout
2930 ret=$?
2931 if [ $ret -ne 0 ]; then
2932 diff -u $testroot/stdout.expected $testroot/stdout
2933 return 1
2936 if [ -h $testroot/wt/alpha.link ]; then
2937 echo "alpha.link is a symlink"
2938 test_done "$testroot" "1"
2939 return 1
2942 echo 'this is regular file alpha.link' > $testroot/content.expected
2943 cp $testroot/wt/alpha.link $testroot/content
2944 cmp -s $testroot/content.expected $testroot/content
2945 ret=$?
2946 if [ $ret -ne 0 ]; then
2947 diff -u $testroot/content.expected $testroot/content
2948 test_done "$testroot" "$ret"
2949 return 1
2952 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2953 echo "dotgotbar.link is not a symlink"
2954 test_done "$testroot" "1"
2955 return 1
2957 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
2958 echo ".got/bar" > $testroot/stdout.expected
2959 cmp -s $testroot/stdout.expected $testroot/stdout
2960 ret=$?
2961 if [ $ret -ne 0 ]; then
2962 diff -u $testroot/stdout.expected $testroot/stdout
2963 test_done "$testroot" "$ret"
2964 return 1
2967 if [ -h $testroot/wt/dotgotfoo.link ]; then
2968 echo "dotgotfoo.link is a symlink"
2969 test_done "$testroot" "1"
2970 return 1
2972 echo "this is regular file foo" > $testroot/content.expected
2973 cp $testroot/wt/dotgotfoo.link $testroot/content
2974 cmp -s $testroot/content.expected $testroot/content
2975 ret=$?
2976 if [ $ret -ne 0 ]; then
2977 diff -u $testroot/content.expected $testroot/content
2978 test_done "$testroot" "$ret"
2979 return 1
2982 if ! [ -h $testroot/wt/epsilon.link ]; then
2983 echo "epsilon.link is not a symlink"
2984 test_done "$testroot" "1"
2985 return 1
2988 readlink $testroot/wt/epsilon.link > $testroot/stdout
2989 echo "gamma" > $testroot/stdout.expected
2990 cmp -s $testroot/stdout.expected $testroot/stdout
2991 ret=$?
2992 if [ $ret -ne 0 ]; then
2993 diff -u $testroot/stdout.expected $testroot/stdout
2994 test_done "$testroot" "$ret"
2995 return 1
2998 if [ -h $testroot/wt/passwd.link ]; then
2999 echo "passwd.link is a symlink"
3000 test_done "$testroot" "1"
3001 return 1
3003 echo -n "/etc/passwd" > $testroot/content.expected
3004 cp $testroot/wt/passwd.link $testroot/content
3005 cmp -s $testroot/content.expected $testroot/content
3006 ret=$?
3007 if [ $ret -ne 0 ]; then
3008 diff -u $testroot/content.expected $testroot/content
3009 test_done "$testroot" "$ret"
3010 return 1
3013 if ! [ -h $testroot/wt/zeta.link ]; then
3014 echo "zeta.link is not a symlink"
3015 test_done "$testroot" "1"
3016 return 1
3019 readlink $testroot/wt/zeta.link > $testroot/stdout
3020 echo "gamma/delta" > $testroot/stdout.expected
3021 cmp -s $testroot/stdout.expected $testroot/stdout
3022 ret=$?
3023 if [ $ret -ne 0 ]; then
3024 diff -u $testroot/stdout.expected $testroot/stdout
3025 test_done "$testroot" "$ret"
3026 return 1
3029 test_done "$testroot" "0"
3032 test_parseargs "$@"
3033 run_test test_stage_basic
3034 run_test test_stage_no_changes
3035 run_test test_stage_unversioned
3036 run_test test_stage_nonexistent
3037 run_test test_stage_list
3038 run_test test_stage_conflict
3039 run_test test_stage_out_of_date
3040 run_test test_double_stage
3041 run_test test_stage_status
3042 run_test test_stage_add_already_staged_file
3043 run_test test_stage_rm_already_staged_file
3044 run_test test_stage_revert
3045 run_test test_stage_diff
3046 run_test test_stage_histedit
3047 run_test test_stage_rebase
3048 run_test test_stage_update
3049 run_test test_stage_commit_non_staged
3050 run_test test_stage_commit_out_of_date
3051 run_test test_stage_commit
3052 run_test test_stage_patch
3053 run_test test_stage_patch_twice
3054 run_test test_stage_patch_added
3055 run_test test_stage_patch_added_twice
3056 run_test test_stage_patch_removed
3057 run_test test_stage_patch_removed_twice
3058 run_test test_stage_patch_reversed
3059 run_test test_stage_patch_quit
3060 run_test test_stage_patch_incomplete_script
3061 run_test test_stage_symlink
3062 run_test test_stage_patch_symlink