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