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 test_stage_basic() {
20 local testroot=`test_init stage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified file" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta > /dev/null)
31 echo "new file" > $testroot/wt/foo
32 (cd $testroot/wt && got add foo > /dev/null)
34 echo ' M alpha' > $testroot/stdout.expected
35 echo ' D beta' >> $testroot/stdout.expected
36 echo ' A foo' >> $testroot/stdout.expected
37 (cd $testroot/wt && got stage > $testroot/stdout)
39 cmp -s $testroot/stdout.expected $testroot/stdout
40 ret=$?
41 if [ $ret -ne 0 ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
43 fi
44 test_done "$testroot" "$ret"
45 }
47 test_stage_no_changes() {
48 local testroot=`test_init stage_no_changes`
50 got checkout $testroot/repo $testroot/wt > /dev/null
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 test_done "$testroot" "$ret"
54 return 1
55 fi
57 (cd $testroot/wt && got stage alpha beta > $testroot/stdout \
58 2> $testroot/stderr)
59 ret=$?
60 if [ $ret -eq 0 ]; then
61 echo "got stage command succeeded unexpectedly" >&2
62 test_done "$testroot" "1"
63 return 1
64 fi
66 echo "got: no changes to stage" > $testroot/stderr.expected
68 cmp -s $testroot/stderr.expected $testroot/stderr
69 ret=$?
70 if [ $ret -ne 0 ]; then
71 diff -u $testroot/stderr.expected $testroot/stderr
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 echo -n > $testroot/stdout.expected
77 cmp -s $testroot/stdout.expected $testroot/stdout
78 ret=$?
79 if [ $ret -ne 0 ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
81 fi
82 test_done "$testroot" "$ret"
83 }
85 test_stage_unversioned() {
86 local testroot=`test_init stage_unversioned`
88 got checkout $testroot/repo $testroot/wt > /dev/null
89 ret=$?
90 if [ $ret -ne 0 ]; then
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 echo "modified file" > $testroot/wt/alpha
96 touch $testroot/wt/unversioned-file
98 (cd $testroot/wt && got status > $testroot/stdout)
99 echo "M alpha" > $testroot/stdout.expected
100 echo "? unversioned-file" >> $testroot/stdout.expected
101 cmp -s $testroot/stdout.expected $testroot/stdout
102 ret=$?
103 if [ $ret -ne 0 ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/wt && got stage > $testroot/stdout)
110 ret=$?
111 if [ $ret -ne 0 ]; then
112 echo "got stage command failed unexpectedly" >&2
113 test_done "$testroot" "$ret"
114 return 1
115 fi
117 echo " M alpha" > $testroot/stdout.expected
118 cmp -s $testroot/stdout.expected $testroot/stdout
119 ret=$?
120 if [ $ret -ne 0 ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 test_done "$testroot" "$ret"
123 return 1
124 fi
126 echo "modified file again" > $testroot/wt/alpha
128 (cd $testroot/wt && got stage unversioned-file > $testroot/stdout \
129 2> $testroot/stderr)
130 ret=$?
131 if [ $ret -eq 0 ]; then
132 echo "got stage command succeed unexpectedly" >&2
133 test_done "$testroot" "1"
134 return 1
135 fi
137 echo "got: no changes to stage" > $testroot/stderr.expected
138 cmp -s $testroot/stderr.expected $testroot/stderr
139 ret=$?
140 if [ $ret -ne 0 ]; then
141 diff -u $testroot/stderr.expected $testroot/stderr
142 fi
143 test_done "$testroot" "$ret"
147 test_stage_nonexistent() {
148 local testroot=`test_init stage_nonexistent`
150 got checkout $testroot/repo $testroot/wt > /dev/null
151 ret=$?
152 if [ $ret -ne 0 ]; then
153 test_done "$testroot" "$ret"
154 return 1
155 fi
157 (cd $testroot/wt && got stage nonexistent-file \
158 > $testroot/stdout 2> $testroot/stderr)
159 echo "got: nonexistent-file: No such file or directory" \
160 > $testroot/stderr.expected
161 cmp -s $testroot/stderr.expected $testroot/stderr
162 ret=$?
163 if [ $ret -ne 0 ]; then
164 diff -u $testroot/stderr.expected $testroot/stderr
165 fi
166 test_done "$testroot" "$ret"
169 test_stage_list() {
170 local testroot=`test_init stage_list`
172 got checkout $testroot/repo $testroot/wt > /dev/null
173 ret=$?
174 if [ $ret -ne 0 ]; then
175 test_done "$testroot" "$ret"
176 return 1
177 fi
179 echo "modified file" > $testroot/wt/alpha
180 (cd $testroot/wt && got rm beta > /dev/null)
181 echo "new file" > $testroot/wt/foo
182 (cd $testroot/wt && got add foo > /dev/null)
184 echo ' M alpha' > $testroot/stdout.expected
185 echo ' D beta' >> $testroot/stdout.expected
186 echo ' A foo' >> $testroot/stdout.expected
187 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
189 (cd $testroot/wt && got stage -l > $testroot/stdout)
190 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
191 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
192 echo " M alpha" >> $testroot/stdout.expected
193 (cd $testroot/wt && got diff -s beta | grep '^blob -' | \
194 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
195 echo " D beta" >> $testroot/stdout.expected
196 (cd $testroot/wt && got diff -s foo | grep '^blob +' | \
197 cut -d' ' -f3 | tr -d '\n' >> $testroot/stdout.expected)
198 echo " A foo" >> $testroot/stdout.expected
199 cmp -s $testroot/stdout.expected $testroot/stdout
200 ret=$?
201 if [ $ret -ne 0 ]; then
202 diff -u $testroot/stdout.expected $testroot/stdout
203 test_done "$testroot" "$ret"
204 return 1
205 fi
207 (cd $testroot/wt && got stage -l epsilon nonexistent \
208 > $testroot/stdout)
210 echo -n > $testroot/stdout.expected
211 cmp -s $testroot/stdout.expected $testroot/stdout
212 ret=$?
213 if [ $ret -ne 0 ]; then
214 diff -u $testroot/stdout.expected $testroot/stdout
215 test_done "$testroot" "$ret"
216 return 1
217 fi
219 (cd $testroot/wt && got stage -l alpha > $testroot/stdout)
221 (cd $testroot/wt && got diff -s alpha | grep '^blob +' | \
222 cut -d' ' -f3 | tr -d '\n' > $testroot/stdout.expected)
223 echo " M alpha" >> $testroot/stdout.expected
224 cmp -s $testroot/stdout.expected $testroot/stdout
225 ret=$?
226 if [ $ret -ne 0 ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
228 fi
229 test_done "$testroot" "$ret"
233 test_stage_conflict() {
234 local testroot=`test_init stage_conflict`
235 local initial_commit=`git_show_head $testroot/repo`
237 got checkout $testroot/repo $testroot/wt > /dev/null
238 ret=$?
239 if [ $ret -ne 0 ]; then
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 echo "modified alpha" > $testroot/wt/alpha
245 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
247 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
249 echo "modified alpha, too" > $testroot/wt/alpha
251 echo "C alpha" > $testroot/stdout.expected
252 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
253 git_show_head $testroot/repo >> $testroot/stdout.expected
254 echo >> $testroot/stdout.expected
255 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
257 (cd $testroot/wt && got update > $testroot/stdout)
259 cmp -s $testroot/stdout.expected $testroot/stdout
260 ret=$?
261 if [ $ret -ne 0 ]; then
262 diff -u $testroot/stdout.expected $testroot/stdout
263 test_done "$testroot" "$ret"
264 return 1
265 fi
267 (cd $testroot/wt && got stage alpha > $testroot/stdout \
268 2> $testroot/stderr)
269 ret=$?
270 if [ $ret -eq 0 ]; then
271 echo "got stage command succeeded unexpectedly" >&2
272 test_done "$testroot" "1"
273 return 1
274 fi
276 echo -n > $testroot/stdout.expected
277 echo "got: alpha: cannot stage file in conflicted status" \
278 > $testroot/stderr.expected
280 cmp -s $testroot/stdout.expected $testroot/stdout
281 ret=$?
282 if [ $ret -ne 0 ]; then
283 diff -u $testroot/stdout.expected $testroot/stdout
284 test_done "$testroot" "$ret"
285 return 1
286 fi
287 cmp -s $testroot/stderr.expected $testroot/stderr
288 ret=$?
289 if [ $ret -ne 0 ]; then
290 diff -u $testroot/stderr.expected $testroot/stderr
291 fi
292 test_done "$testroot" "$ret"
295 test_stage_out_of_date() {
296 local testroot=`test_init stage_out_of_date`
297 local initial_commit=`git_show_head $testroot/repo`
299 got checkout $testroot/repo $testroot/wt > /dev/null
300 ret=$?
301 if [ $ret -ne 0 ]; then
302 test_done "$testroot" "$ret"
303 return 1
304 fi
306 echo "modified alpha" > $testroot/wt/alpha
307 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
309 (cd $testroot/wt && got update -c $initial_commit > /dev/null)
311 echo "modified alpha again" > $testroot/wt/alpha
312 (cd $testroot/wt && got stage alpha > $testroot/stdout \
313 2> $testroot/stderr)
314 ret=$?
315 if [ $ret -eq 0 ]; then
316 echo "got stage command succeeded unexpectedly" >&2
317 test_done "$testroot" "1"
318 return 1
319 fi
321 echo -n > $testroot/stdout.expected
322 echo "got: work tree must be updated before changes can be staged" \
323 > $testroot/stderr.expected
325 cmp -s $testroot/stdout.expected $testroot/stdout
326 ret=$?
327 if [ $ret -ne 0 ]; then
328 diff -u $testroot/stdout.expected $testroot/stdout
329 test_done "$testroot" "$ret"
330 return 1
331 fi
332 cmp -s $testroot/stderr.expected $testroot/stderr
333 ret=$?
334 if [ $ret -ne 0 ]; then
335 diff -u $testroot/stderr.expected $testroot/stderr
336 fi
337 test_done "$testroot" "$ret"
341 test_double_stage() {
342 local testroot=`test_init double_stage`
344 got checkout $testroot/repo $testroot/wt > /dev/null
345 ret=$?
346 if [ $ret -ne 0 ]; then
347 test_done "$testroot" "$ret"
348 return 1
349 fi
350 echo "modified file" > $testroot/wt/alpha
351 (cd $testroot/wt && got rm beta > /dev/null)
352 echo "new file" > $testroot/wt/foo
353 (cd $testroot/wt && got add foo > /dev/null)
354 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
356 echo "got: no changes to stage" > $testroot/stderr.expected
357 (cd $testroot/wt && got stage alpha 2> $testroot/stderr)
358 cmp -s $testroot/stderr.expected $testroot/stderr
359 ret=$?
360 if [ $ret -ne 0 ]; then
361 diff -u $testroot/stderr.expected $testroot/stderr
362 test_done "$testroot" "$ret"
363 return 1
364 fi
366 (cd $testroot/wt && got stage beta \
367 > $testroot/stdout 2> $testroot/stderr)
368 ret=$?
369 if [ $ret -eq 0 ]; then
370 echo "got stage command succeeded unexpectedly" >&2
371 test_done "$testroot" "1"
372 return 1
373 fi
374 echo -n > $testroot/stdout.expected
375 cmp -s $testroot/stdout.expected $testroot/stdout
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 test_done "$testroot" "$ret"
380 return 1
381 fi
383 echo "got: no changes to stage" > $testroot/stderr.expected
384 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
385 cmp -s $testroot/stderr.expected $testroot/stderr
386 ret=$?
387 if [ $ret -ne 0 ]; then
388 diff -u $testroot/stderr.expected $testroot/stderr
389 test_done "$testroot" "$ret"
390 return 1
391 fi
393 printf "q\n" > $testroot/patchscript
394 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
395 > $testroot/stdout 2> $testroot/stderr)
396 ret=$?
397 if [ $ret -eq 0 ]; then
398 echo "got stage command succeeded unexpectedly" >&2
399 test_done "$testroot" "1"
400 return 1
401 fi
402 echo -n > $testroot/stdout.expected
403 cmp -s $testroot/stdout.expected $testroot/stdout
404 ret=$?
405 if [ $ret -ne 0 ]; then
406 diff -u $testroot/stdout.expected $testroot/stdout
407 test_done "$testroot" "$ret"
408 return 1
409 fi
411 echo "got: no changes to stage" > $testroot/stderr.expected
412 (cd $testroot/wt && got stage foo 2> $testroot/stderr)
413 cmp -s $testroot/stderr.expected $testroot/stderr
414 ret=$?
415 if [ $ret -ne 0 ]; then
416 diff -u $testroot/stderr.expected $testroot/stderr
417 test_done "$testroot" "$ret"
418 return 1
419 fi
421 echo "modified file again" > $testroot/wt/alpha
422 echo "modified new file" > $testroot/wt/foo
424 echo ' M alpha' > $testroot/stdout.expected
425 echo ' A foo' >> $testroot/stdout.expected
426 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
427 cmp -s $testroot/stdout.expected $testroot/stdout
428 ret=$?
429 if [ $ret -ne 0 ]; then
430 diff -u $testroot/stdout.expected $testroot/stdout
431 test_done "$testroot" "$ret"
432 return 1
433 fi
435 echo ' M alpha' > $testroot/stdout.expected
436 echo ' D beta' >> $testroot/stdout.expected
437 echo ' A foo' >> $testroot/stdout.expected
439 (cd $testroot/wt && got status > $testroot/stdout)
440 cmp -s $testroot/stdout.expected $testroot/stdout
441 ret=$?
442 if [ $ret -ne 0 ]; then
443 diff -u $testroot/stdout.expected $testroot/stdout
444 fi
445 test_done "$testroot" "$ret"
448 test_stage_status() {
449 local testroot=`test_init stage_status`
451 got checkout $testroot/repo $testroot/wt > /dev/null
452 ret=$?
453 if [ $ret -ne 0 ]; then
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 echo "modified file" > $testroot/wt/alpha
459 (cd $testroot/wt && got rm beta > /dev/null)
460 echo "new file" > $testroot/wt/foo
461 (cd $testroot/wt && got add foo > /dev/null)
462 echo "new file" > $testroot/wt/epsilon/new
463 (cd $testroot/wt && got add epsilon/new > /dev/null)
464 echo "modified file" > $testroot/wt/epsilon/zeta
465 (cd $testroot/wt && got rm gamma/delta > /dev/null)
467 echo ' M alpha' > $testroot/stdout.expected
468 echo ' D beta' >> $testroot/stdout.expected
469 echo 'A epsilon/new' >> $testroot/stdout.expected
470 echo 'M epsilon/zeta' >> $testroot/stdout.expected
471 echo ' A foo' >> $testroot/stdout.expected
472 echo 'D gamma/delta' >> $testroot/stdout.expected
473 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
475 (cd $testroot/wt && got status > $testroot/stdout)
476 cmp -s $testroot/stdout.expected $testroot/stdout
477 ret=$?
478 if [ $ret -ne 0 ]; then
479 diff -u $testroot/stdout.expected $testroot/stdout
480 test_done "$testroot" "$ret"
481 return 1
482 fi
484 echo "modified file again" >> $testroot/wt/alpha
485 echo "modified added file again" >> $testroot/wt/foo
487 echo 'MM alpha' > $testroot/stdout.expected
488 echo ' D beta' >> $testroot/stdout.expected
489 echo 'A epsilon/new' >> $testroot/stdout.expected
490 echo 'M epsilon/zeta' >> $testroot/stdout.expected
491 echo 'MA foo' >> $testroot/stdout.expected
492 echo 'D gamma/delta' >> $testroot/stdout.expected
494 (cd $testroot/wt && got status > $testroot/stdout)
495 cmp -s $testroot/stdout.expected $testroot/stdout
496 ret=$?
497 if [ $ret -ne 0 ]; then
498 diff -u $testroot/stdout.expected $testroot/stdout
499 test_done "$testroot" "$ret"
500 return 1
501 fi
503 # test no-op change of added file with new stat(2) timestamp
504 echo "new file" > $testroot/wt/foo
505 echo ' A foo' > $testroot/stdout.expected
506 (cd $testroot/wt && got status foo > $testroot/stdout)
507 cmp -s $testroot/stdout.expected $testroot/stdout
508 ret=$?
509 if [ $ret -ne 0 ]; then
510 diff -u $testroot/stdout.expected $testroot/stdout
511 test_done "$testroot" "$ret"
512 return 1
513 fi
515 # test staged deleted file which is restored on disk
516 echo "new file" > $testroot/wt/beta
517 echo ' D beta' > $testroot/stdout.expected
518 (cd $testroot/wt && got status beta > $testroot/stdout)
519 cmp -s $testroot/stdout.expected $testroot/stdout
520 ret=$?
521 if [ $ret -ne 0 ]; then
522 diff -u $testroot/stdout.expected $testroot/stdout
523 fi
524 test_done "$testroot" "$ret"
528 test_stage_add_already_staged_file() {
529 local testroot=`test_init stage_add_already_staged_file`
531 got checkout $testroot/repo $testroot/wt > /dev/null
532 ret=$?
533 if [ $ret -ne 0 ]; then
534 test_done "$testroot" "$ret"
535 return 1
536 fi
538 echo "modified file" > $testroot/wt/alpha
539 (cd $testroot/wt && got rm beta > /dev/null)
540 echo "new file" > $testroot/wt/foo
541 (cd $testroot/wt && got add foo > /dev/null)
543 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
545 echo -n > $testroot/stdout.expected
546 for f in alpha beta foo; do
547 (cd $testroot/wt && got add $f \
548 > $testroot/stdout 2> $testroot/stderr)
549 echo "got: $f: file has unexpected status" \
550 > $testroot/stderr.expected
551 cmp -s $testroot/stderr.expected $testroot/stderr
552 ret=$?
553 if [ $ret -ne 0 ]; then
554 diff -u $testroot/stderr.expected $testroot/stderr
555 test_done "$testroot" "$ret"
556 return 1
557 fi
558 cmp -s $testroot/stdout.expected $testroot/stdout
559 ret=$?
560 if [ $ret -ne 0 ]; then
561 diff -u $testroot/stdout.expected $testroot/stdout
562 test_done "$testroot" "$ret"
563 return 1
564 fi
565 done
567 echo ' M alpha' > $testroot/stdout.expected
568 echo ' D beta' >> $testroot/stdout.expected
569 echo ' A foo' >> $testroot/stdout.expected
571 (cd $testroot/wt && got status > $testroot/stdout)
572 cmp -s $testroot/stdout.expected $testroot/stdout
573 ret=$?
574 if [ $ret -ne 0 ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 fi
577 test_done "$testroot" "$ret"
580 test_stage_rm_already_staged_file() {
581 local testroot=`test_init stage_rm_already_staged_file`
583 got checkout $testroot/repo $testroot/wt > /dev/null
584 ret=$?
585 if [ $ret -ne 0 ]; then
586 test_done "$testroot" "$ret"
587 return 1
588 fi
590 echo "modified file" > $testroot/wt/alpha
591 (cd $testroot/wt && got rm beta > /dev/null)
592 echo "new file" > $testroot/wt/foo
593 (cd $testroot/wt && got add foo > /dev/null)
595 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
597 (cd $testroot/wt && got rm beta \
598 > $testroot/stdout 2> $testroot/stderr)
599 ret=$?
600 if [ $ret -ne 0 ]; then
601 echo "got rm command failed unexpectedly" >&2
602 test_done "$testroot" "1"
603 return 1
604 fi
605 echo -n > $testroot/stdout.expected
606 cmp -s $testroot/stdout.expected $testroot/stdout
607 ret=$?
608 if [ $ret -ne 0 ]; then
609 diff -u $testroot/stdout.expected $testroot/stdout
610 test_done "$testroot" "$ret"
611 return 1
612 fi
613 echo -n > $testroot/stderr.expected
614 cmp -s $testroot/stderr.expected $testroot/stderr
615 ret=$?
616 if [ $ret -ne 0 ]; then
617 diff -u $testroot/stderr.expected $testroot/stderr
618 test_done "$testroot" "$ret"
619 return 1
620 fi
622 for f in alpha foo; do
623 echo "got: $f: file is staged" > $testroot/stderr.expected
624 (cd $testroot/wt && got rm $f \
625 > $testroot/stdout 2> $testroot/stderr)
626 ret=$?
627 if [ $ret -eq 0 ]; then
628 echo "got rm command succeeded unexpectedly" >&2
629 test_done "$testroot" "1"
630 return 1
631 fi
632 cmp -s $testroot/stderr.expected $testroot/stderr
633 ret=$?
634 if [ $ret -ne 0 ]; then
635 diff -u $testroot/stderr.expected $testroot/stderr
636 test_done "$testroot" "$ret"
637 return 1
638 fi
639 done
641 echo ' M alpha' > $testroot/stdout.expected
642 echo ' D beta' >> $testroot/stdout.expected
643 echo ' A foo' >> $testroot/stdout.expected
645 (cd $testroot/wt && got status > $testroot/stdout)
646 cmp -s $testroot/stdout.expected $testroot/stdout
647 ret=$?
648 if [ $ret -ne 0 ]; then
649 diff -u $testroot/stdout.expected $testroot/stdout
650 fi
651 test_done "$testroot" "$ret"
654 test_stage_revert() {
655 local testroot=`test_init stage_revert`
657 got checkout $testroot/repo $testroot/wt > /dev/null
658 ret=$?
659 if [ $ret -ne 0 ]; then
660 test_done "$testroot" "$ret"
661 return 1
662 fi
664 echo "modified alpha" > $testroot/wt/alpha
665 (cd $testroot/wt && got rm beta > /dev/null)
666 echo "new file" > $testroot/wt/foo
667 (cd $testroot/wt && got add foo > /dev/null)
668 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
670 echo "modified file again" >> $testroot/wt/alpha
671 echo "modified added file again" >> $testroot/wt/foo
673 (cd $testroot/wt && got revert alpha > $testroot/stdout)
674 ret=$?
675 if [ $ret -ne 0 ]; then
676 echo "revert command failed unexpectedly" >&2
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 echo "R alpha" > $testroot/stdout.expected
682 cmp -s $testroot/stdout.expected $testroot/stdout
683 ret=$?
684 if [ $ret -ne 0 ]; then
685 diff -u $testroot/stdout.expected $testroot/stdout
686 test_done "$testroot" "$ret"
687 return 1
688 fi
690 echo "modified alpha" > $testroot/content.expected
691 cat $testroot/wt/alpha > $testroot/content
692 cmp -s $testroot/content.expected $testroot/content
693 ret=$?
694 if [ $ret -ne 0 ]; then
695 diff -u $testroot/content.expected $testroot/content
696 test_done "$testroot" "$ret"
697 return 1
698 fi
700 echo ' M alpha' > $testroot/stdout.expected
701 echo ' D beta' >> $testroot/stdout.expected
702 echo 'MA foo' >> $testroot/stdout.expected
703 (cd $testroot/wt && got status > $testroot/stdout)
704 cmp -s $testroot/stdout.expected $testroot/stdout
705 ret=$?
706 if [ $ret -ne 0 ]; then
707 diff -u $testroot/stdout.expected $testroot/stdout
708 test_done "$testroot" "$ret"
709 return 1
710 fi
712 (cd $testroot/wt && got revert alpha > $testroot/stdout)
713 ret=$?
714 if [ $ret -ne 0 ]; then
715 echo "revert command failed unexpectedly" >&2
716 test_done "$testroot" "$ret"
717 return 1
718 fi
720 echo -n > $testroot/stdout.expected
721 cmp -s $testroot/stdout.expected $testroot/stdout
722 ret=$?
723 if [ $ret -ne 0 ]; then
724 diff -u $testroot/stdout.expected $testroot/stdout
725 test_done "$testroot" "$ret"
726 return 1
727 fi
729 echo "modified alpha" > $testroot/content.expected
730 cat $testroot/wt/alpha > $testroot/content
731 cmp -s $testroot/content.expected $testroot/content
732 ret=$?
733 if [ $ret -ne 0 ]; then
734 diff -u $testroot/content.expected $testroot/content
735 test_done "$testroot" "$ret"
736 return 1
737 fi
739 (cd $testroot/wt && got revert beta > $testroot/stdout \
740 2> $testroot/stderr)
741 ret=$?
742 if [ $ret -ne 0 ]; then
743 echo "revert command failed unexpectedly" >&2
744 test_done "$testroot" "$ret"
745 return 1
746 fi
748 echo -n > $testroot/stdout.expected
749 cmp -s $testroot/stdout.expected $testroot/stdout
750 ret=$?
751 if [ $ret -ne 0 ]; then
752 diff -u $testroot/stdout.expected $testroot/stdout
753 test_done "$testroot" "$ret"
754 return 1
755 fi
757 echo -n > $testroot/stderr.expected
758 cmp -s $testroot/stderr.expected $testroot/stderr
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 diff -u $testroot/stderr.expected $testroot/stderr
762 test_done "$testroot" "$ret"
763 return 1
764 fi
766 (cd $testroot/wt && got revert foo > $testroot/stdout)
767 ret=$?
768 if [ $ret -ne 0 ]; then
769 echo "revert command failed unexpectedly" >&2
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 echo "R foo" > $testroot/stdout.expected
775 cmp -s $testroot/stdout.expected $testroot/stdout
776 ret=$?
777 if [ $ret -ne 0 ]; then
778 diff -u $testroot/stdout.expected $testroot/stdout
779 test_done "$testroot" "$ret"
780 return 1
781 fi
783 echo "new file" > $testroot/content.expected
784 cat $testroot/wt/foo > $testroot/content
785 cmp -s $testroot/content.expected $testroot/content
786 ret=$?
787 if [ $ret -ne 0 ]; then
788 diff -u $testroot/content.expected $testroot/content
789 test_done "$testroot" "$ret"
790 return 1
791 fi
793 echo ' M alpha' > $testroot/stdout.expected
794 echo ' D beta' >> $testroot/stdout.expected
795 echo ' A foo' >> $testroot/stdout.expected
796 (cd $testroot/wt && got status > $testroot/stdout)
797 cmp -s $testroot/stdout.expected $testroot/stdout
798 ret=$?
799 if [ $ret -ne 0 ]; then
800 diff -u $testroot/stdout.expected $testroot/stdout
801 test_done "$testroot" "$ret"
802 return 1
803 fi
805 (cd $testroot/wt && got revert foo > $testroot/stdout)
806 ret=$?
807 if [ $ret -ne 0 ]; then
808 echo "revert command failed unexpectedly" >&2
809 test_done "$testroot" "$ret"
810 return 1
811 fi
813 echo -n > $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected $testroot/stdout
815 ret=$?
816 if [ $ret -ne 0 ]; then
817 diff -u $testroot/stdout.expected $testroot/stdout
818 test_done "$testroot" "$ret"
819 return 1
820 fi
822 echo "new file" > $testroot/content.expected
823 cat $testroot/wt/foo > $testroot/content
824 cmp -s $testroot/content.expected $testroot/content
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 diff -u $testroot/content.expected $testroot/content
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 echo ' M alpha' > $testroot/stdout.expected
833 echo ' D beta' >> $testroot/stdout.expected
834 echo ' A foo' >> $testroot/stdout.expected
835 (cd $testroot/wt && got status > $testroot/stdout)
836 cmp -s $testroot/stdout.expected $testroot/stdout
837 ret=$?
838 if [ $ret -ne 0 ]; then
839 diff -u $testroot/stdout.expected $testroot/stdout
840 test_done "$testroot" "$ret"
841 return 1
842 fi
844 echo "modified file again" >> $testroot/wt/alpha
845 echo "modified added file again" >> $testroot/wt/foo
847 (cd $testroot/wt && got revert -R . > $testroot/stdout \
848 2> $testroot/stderr)
849 ret=$?
850 if [ $ret -ne 0 ]; then
851 echo "revert command failed unexpectedly" >&2
852 test_done "$testroot" "$ret"
853 return 1
854 fi
856 echo "R alpha" > $testroot/stdout.expected
857 echo "R foo" >> $testroot/stdout.expected
858 cmp -s $testroot/stdout.expected $testroot/stdout
859 ret=$?
860 if [ $ret -ne 0 ]; then
861 diff -u $testroot/stdout.expected $testroot/stdout
862 test_done "$testroot" "$ret"
863 return 1
864 fi
866 echo -n > $testroot/stderr.expected
867 cmp -s $testroot/stderr.expected $testroot/stderr
868 ret=$?
869 if [ $ret -ne 0 ]; then
870 diff -u $testroot/stderr.expected $testroot/stderr
871 test_done "$testroot" "$ret"
872 return 1
873 fi
875 echo ' M alpha' > $testroot/stdout.expected
876 echo ' D beta' >> $testroot/stdout.expected
877 echo ' A foo' >> $testroot/stdout.expected
878 (cd $testroot/wt && got status > $testroot/stdout)
879 cmp -s $testroot/stdout.expected $testroot/stdout
880 ret=$?
881 if [ $ret -ne 0 ]; then
882 diff -u $testroot/stdout.expected $testroot/stdout
883 fi
884 test_done "$testroot" "$ret"
887 test_stage_diff() {
888 local testroot=`test_init stage_diff`
889 local head_commit=`git_show_head $testroot/repo`
891 got checkout $testroot/repo $testroot/wt > /dev/null
892 ret=$?
893 if [ $ret -ne 0 ]; then
894 test_done "$testroot" "$ret"
895 return 1
896 fi
898 echo "modified file" > $testroot/wt/alpha
899 (cd $testroot/wt && got rm beta > /dev/null)
900 echo "new file" > $testroot/wt/foo
901 (cd $testroot/wt && got add foo > /dev/null)
903 (cd $testroot/wt && got diff -s > $testroot/stdout)
904 echo -n > $testroot/stdout.expected
905 cmp -s $testroot/stdout.expected $testroot/stdout
906 ret=$?
907 if [ $ret -ne 0 ]; then
908 diff -u $testroot/stdout.expected $testroot/stdout
909 test_done "$testroot" "$ret"
910 return 1
911 fi
913 echo ' M alpha' > $testroot/stdout.expected
914 echo ' D beta' >> $testroot/stdout.expected
915 echo ' A foo' >> $testroot/stdout.expected
916 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
918 (cd $testroot/wt && got diff > $testroot/stdout)
919 echo -n > $testroot/stdout.expected
920 cmp -s $testroot/stdout.expected $testroot/stdout
921 ret=$?
922 if [ $ret -ne 0 ]; then
923 diff -u $testroot/stdout.expected $testroot/stdout
924 test_done "$testroot" "$ret"
925 return 1
926 fi
928 echo "modified file again" > $testroot/wt/alpha
929 echo "new file changed" > $testroot/wt/foo
931 (cd $testroot/wt && got diff > $testroot/stdout)
933 echo "diff $testroot/wt" > $testroot/stdout.expected
934 echo "commit - $head_commit" >> $testroot/stdout.expected
935 echo "path + $testroot/wt" >> $testroot/stdout.expected
936 echo -n 'blob - ' >> $testroot/stdout.expected
937 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
938 >> $testroot/stdout.expected
939 echo ' (staged)' >> $testroot/stdout.expected
940 echo 'file + alpha' >> $testroot/stdout.expected
941 echo '--- alpha' >> $testroot/stdout.expected
942 echo '+++ alpha' >> $testroot/stdout.expected
943 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
944 echo '-modified file' >> $testroot/stdout.expected
945 echo '+modified file again' >> $testroot/stdout.expected
946 echo -n 'blob - ' >> $testroot/stdout.expected
947 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
948 >> $testroot/stdout.expected
949 echo " (staged)" >> $testroot/stdout.expected
950 echo 'file + foo' >> $testroot/stdout.expected
951 echo '--- foo' >> $testroot/stdout.expected
952 echo '+++ foo' >> $testroot/stdout.expected
953 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
954 echo '-new file' >> $testroot/stdout.expected
955 echo '+new file changed' >> $testroot/stdout.expected
957 cmp -s $testroot/stdout.expected $testroot/stdout
958 ret=$?
959 if [ $ret -ne 0 ]; then
960 diff -u $testroot/stdout.expected $testroot/stdout
961 test_done "$testroot" "$ret"
962 return 1
963 fi
965 (cd $testroot/wt && got diff -s > $testroot/stdout)
967 echo "diff -s $testroot/wt" > $testroot/stdout.expected
968 echo "commit - $head_commit" >> $testroot/stdout.expected
969 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
970 echo -n 'blob - ' >> $testroot/stdout.expected
971 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
972 >> $testroot/stdout.expected
973 echo -n 'blob + ' >> $testroot/stdout.expected
974 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
975 >> $testroot/stdout.expected
976 echo '--- alpha' >> $testroot/stdout.expected
977 echo '+++ alpha' >> $testroot/stdout.expected
978 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
979 echo '-alpha' >> $testroot/stdout.expected
980 echo '+modified file' >> $testroot/stdout.expected
981 echo -n 'blob - ' >> $testroot/stdout.expected
982 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
983 >> $testroot/stdout.expected
984 echo 'blob + /dev/null' >> $testroot/stdout.expected
985 echo '--- beta' >> $testroot/stdout.expected
986 echo '+++ /dev/null' >> $testroot/stdout.expected
987 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
988 echo '-beta' >> $testroot/stdout.expected
989 echo 'blob - /dev/null' >> $testroot/stdout.expected
990 echo -n 'blob + ' >> $testroot/stdout.expected
991 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
992 >> $testroot/stdout.expected
993 echo '--- /dev/null' >> $testroot/stdout.expected
994 echo '+++ foo' >> $testroot/stdout.expected
995 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
996 echo '+new file' >> $testroot/stdout.expected
998 cmp -s $testroot/stdout.expected $testroot/stdout
999 ret=$?
1000 if [ $ret -ne 0 ]; then
1001 diff -u $testroot/stdout.expected $testroot/stdout
1003 test_done "$testroot" "$ret"
1007 test_stage_histedit() {
1008 local testroot=`test_init stage_histedit`
1009 local orig_commit=`git_show_head $testroot/repo`
1011 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1012 ret=$?
1013 if [ $ret -ne 0 ]; then
1014 test_done "$testroot" "$ret"
1015 return 1
1018 echo "modified file" > $testroot/wt/alpha
1019 (cd $testroot/wt && got stage alpha > /dev/null)
1021 echo "modified alpha on master" > $testroot/repo/alpha
1022 (cd $testroot/repo && git rm -q beta)
1023 echo "new file on master" > $testroot/repo/epsilon/new
1024 (cd $testroot/repo && git add epsilon/new)
1025 git_commit $testroot/repo -m "committing changes"
1026 local old_commit1=`git_show_head $testroot/repo`
1028 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1029 git_commit $testroot/repo -m "committing to zeta on master"
1030 local old_commit2=`git_show_head $testroot/repo`
1032 echo "pick $old_commit1" > $testroot/histedit-script
1033 echo "pick $old_commit2" >> $testroot/histedit-script
1035 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1036 > $testroot/stdout 2> $testroot/stderr)
1037 ret=$?
1038 if [ $ret -eq 0 ]; then
1039 echo "got histedit command succeeded unexpectedly" >&2
1040 test_done "$testroot" "1"
1041 return 1
1044 echo -n > $testroot/stdout.expected
1045 echo "got: alpha: file is staged" > $testroot/stderr.expected
1047 cmp -s $testroot/stderr.expected $testroot/stderr
1048 ret=$?
1049 if [ $ret -ne 0 ]; then
1050 diff -u $testroot/stderr.expected $testroot/stderr
1051 test_done "$testroot" "$ret"
1052 return 1
1054 cmp -s $testroot/stdout.expected $testroot/stdout
1055 ret=$?
1056 if [ $ret -ne 0 ]; then
1057 diff -u $testroot/stdout.expected $testroot/stdout
1059 test_done "$testroot" "$ret"
1063 test_stage_rebase() {
1064 local testroot=`test_init stage_rebase`
1066 (cd $testroot/repo && git checkout -q -b newbranch)
1067 echo "modified delta on branch" > $testroot/repo/gamma/delta
1068 git_commit $testroot/repo -m "committing to delta on newbranch"
1070 echo "modified alpha on branch" > $testroot/repo/alpha
1071 (cd $testroot/repo && git rm -q beta)
1072 echo "new file on branch" > $testroot/repo/epsilon/new
1073 (cd $testroot/repo && git add epsilon/new)
1074 git_commit $testroot/repo -m "committing more changes on newbranch"
1076 local orig_commit1=`git_show_parent_commit $testroot/repo`
1077 local orig_commit2=`git_show_head $testroot/repo`
1079 (cd $testroot/repo && git checkout -q master)
1080 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1081 git_commit $testroot/repo -m "committing to zeta on master"
1082 local master_commit=`git_show_head $testroot/repo`
1084 got checkout $testroot/repo $testroot/wt > /dev/null
1085 ret=$?
1086 if [ $ret -ne 0 ]; then
1087 test_done "$testroot" "$ret"
1088 return 1
1091 echo "modified file" > $testroot/wt/alpha
1092 (cd $testroot/wt && got stage alpha > /dev/null)
1094 (cd $testroot/wt && got rebase newbranch \
1095 > $testroot/stdout 2> $testroot/stderr)
1096 ret=$?
1097 if [ $ret -eq 0 ]; then
1098 echo "got rebase command succeeded unexpectedly" >&2
1099 test_done "$testroot" "1"
1100 return 1
1103 echo -n > $testroot/stdout.expected
1104 echo "got: alpha: file is staged" > $testroot/stderr.expected
1106 cmp -s $testroot/stderr.expected $testroot/stderr
1107 ret=$?
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/stderr.expected $testroot/stderr
1110 test_done "$testroot" "$ret"
1111 return 1
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1114 ret=$?
1115 if [ $ret -ne 0 ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1118 test_done "$testroot" "$ret"
1121 test_stage_update() {
1122 local testroot=`test_init stage_update`
1124 got checkout $testroot/repo $testroot/wt > /dev/null
1125 ret=$?
1126 if [ $ret -ne 0 ]; then
1127 test_done "$testroot" "$ret"
1128 return 1
1131 echo "modified file" > $testroot/wt/alpha
1132 (cd $testroot/wt && got stage alpha > /dev/null)
1134 echo "modified alpha" > $testroot/repo/alpha
1135 git_commit $testroot/repo -m "modified alpha"
1137 (cd $testroot/wt && got update > $testroot/stdout \
1138 2> $testroot/stderr)
1139 ret=$?
1140 if [ $ret -eq 0 ]; then
1141 echo "got update command succeeded unexpectedly" >&2
1142 test_done "$testroot" "1"
1143 return 1
1146 echo -n > $testroot/stdout.expected
1147 echo "got: alpha: file is staged" > $testroot/stderr.expected
1149 cmp -s $testroot/stderr.expected $testroot/stderr
1150 ret=$?
1151 if [ $ret -ne 0 ]; then
1152 diff -u $testroot/stderr.expected $testroot/stderr
1153 test_done "$testroot" "$ret"
1154 return 1
1156 cmp -s $testroot/stdout.expected $testroot/stdout
1157 ret=$?
1158 if [ $ret -ne 0 ]; then
1159 diff -u $testroot/stdout.expected $testroot/stdout
1161 test_done "$testroot" "$ret"
1164 test_stage_commit_non_staged() {
1165 local testroot=`test_init stage_commit_non_staged`
1167 got checkout $testroot/repo $testroot/wt > /dev/null
1168 ret=$?
1169 if [ $ret -ne 0 ]; then
1170 test_done "$testroot" "$ret"
1171 return 1
1174 echo "modified file" > $testroot/wt/alpha
1175 (cd $testroot/wt && got rm beta > /dev/null)
1176 echo "new file" > $testroot/wt/foo
1177 (cd $testroot/wt && got add foo > /dev/null)
1178 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1180 echo "modified file" > $testroot/wt/gamma/delta
1181 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1182 > $testroot/stdout 2> $testroot/stderr)
1183 ret=$?
1184 if [ $ret -eq 0 ]; then
1185 echo "got commit command succeeded unexpectedly" >&2
1186 test_done "$testroot" "1"
1187 return 1
1190 echo -n > $testroot/stdout.expected
1191 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1193 cmp -s $testroot/stderr.expected $testroot/stderr
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 diff -u $testroot/stderr.expected $testroot/stderr
1197 test_done "$testroot" "$ret"
1198 return 1
1200 cmp -s $testroot/stdout.expected $testroot/stdout
1201 ret=$?
1202 if [ $ret -ne 0 ]; then
1203 diff -u $testroot/stdout.expected $testroot/stdout
1205 test_done "$testroot" "$ret"
1208 test_stage_commit_out_of_date() {
1209 local testroot=`test_init stage_commit_out_of_date`
1211 got checkout $testroot/repo $testroot/wt > /dev/null
1212 ret=$?
1213 if [ $ret -ne 0 ]; then
1214 test_done "$testroot" "$ret"
1215 return 1
1218 echo "modified file" > $testroot/wt/alpha
1219 (cd $testroot/wt && got rm beta > /dev/null)
1220 echo "new file" > $testroot/wt/foo
1221 (cd $testroot/wt && got add foo > /dev/null)
1222 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1224 echo "changed file" > $testroot/repo/alpha
1225 git_commit $testroot/repo -m "changed alpha in repo"
1227 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1228 2> $testroot/stderr)
1229 ret=$?
1230 if [ $ret -eq 0 ]; then
1231 echo "got commit command succeeded unexpectedly" >&2
1232 test_done "$testroot" "1"
1233 return 1
1236 echo -n > $testroot/stdout.expected
1237 echo -n "got: work tree must be updated before these changes " \
1238 > $testroot/stderr.expected
1239 echo "can be committed" >> $testroot/stderr.expected
1241 cmp -s $testroot/stderr.expected $testroot/stderr
1242 ret=$?
1243 if [ $ret -ne 0 ]; then
1244 diff -u $testroot/stderr.expected $testroot/stderr
1245 test_done "$testroot" "$ret"
1246 return 1
1248 cmp -s $testroot/stdout.expected $testroot/stdout
1249 ret=$?
1250 if [ $ret -ne 0 ]; then
1251 diff -u $testroot/stdout.expected $testroot/stdout
1252 test_done "$testroot" "$ret"
1253 return 1
1256 (cd $testroot/wt && got update > $testroot/stdout \
1257 2> $testroot/stderr)
1258 echo -n > $testroot/stdout.expected
1259 echo "got: alpha: file is staged" > $testroot/stderr.expected
1261 cmp -s $testroot/stderr.expected $testroot/stderr
1262 ret=$?
1263 if [ $ret -ne 0 ]; then
1264 diff -u $testroot/stderr.expected $testroot/stderr
1265 test_done "$testroot" "$ret"
1266 return 1
1268 cmp -s $testroot/stdout.expected $testroot/stdout
1269 ret=$?
1270 if [ $ret -ne 0 ]; then
1271 diff -u $testroot/stdout.expected $testroot/stdout
1272 test_done "$testroot" "$ret"
1273 return 1
1276 (cd $testroot/wt && got unstage > /dev/null)
1277 (cd $testroot/wt && got update > $testroot/stdout)
1278 ret=$?
1279 if [ $ret -ne 0 ]; then
1280 echo "got update command failed unexpectedly" >&2
1281 test_done "$testroot" "$ret"
1282 return 1
1285 (cd $testroot/wt && got status > $testroot/stdout)
1286 echo "C alpha" > $testroot/stdout.expected
1287 echo "D beta" >> $testroot/stdout.expected
1288 echo "A foo" >> $testroot/stdout.expected
1289 cmp -s $testroot/stdout.expected $testroot/stdout
1290 ret=$?
1291 if [ $ret -ne 0 ]; then
1292 diff -u $testroot/stdout.expected $testroot/stdout
1293 test_done "$testroot" "$ret"
1294 return 1
1297 # resolve conflict
1298 echo "resolved file" > $testroot/wt/alpha
1300 (cd $testroot/wt && got stage > /dev/null)
1302 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1303 ret=$?
1304 if [ $ret -ne 0 ]; then
1305 echo "got commit command failed unexpectedly" >&2
1306 test_done "$testroot" "$ret"
1307 return 1
1310 local commit_id=`git_show_head $testroot/repo`
1311 echo "A foo" > $testroot/stdout.expected
1312 echo "M alpha" >> $testroot/stdout.expected
1313 echo "D beta" >> $testroot/stdout.expected
1314 echo "Created commit $commit_id" >> $testroot/stdout.expected
1315 cmp -s $testroot/stdout.expected $testroot/stdout
1316 ret=$?
1317 if [ $ret -ne 0 ]; then
1318 diff -u $testroot/stdout.expected $testroot/stdout
1320 test_done "$testroot" "$ret"
1324 test_stage_commit() {
1325 local testroot=`test_init stage_commit`
1326 local first_commit=`git_show_head $testroot/repo`
1328 got checkout $testroot/repo $testroot/wt > /dev/null
1329 ret=$?
1330 if [ $ret -ne 0 ]; then
1331 test_done "$testroot" "$ret"
1332 return 1
1335 echo "modified file" > $testroot/wt/alpha
1336 (cd $testroot/wt && got rm beta > /dev/null)
1337 echo "new file" > $testroot/wt/foo
1338 (cd $testroot/wt && got add foo > /dev/null)
1339 echo "modified file" > $testroot/wt/alpha
1340 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1342 echo "modified file again" > $testroot/wt/alpha
1343 echo "new file changed" > $testroot/wt/foo
1344 echo "non-staged change" > $testroot/wt/gamma/delta
1345 echo "non-staged new file" > $testroot/wt/epsilon/new
1346 (cd $testroot/wt && got add epsilon/new > /dev/null)
1347 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1349 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1350 > $testroot/blob_id_alpha
1351 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1352 > $testroot/blob_id_foo
1354 (cd $testroot/wt && got commit -m "staged changes" \
1355 > $testroot/stdout)
1356 ret=$?
1357 if [ $ret -ne 0 ]; then
1358 echo "got commit command failed unexpectedly" >&2
1359 test_done "$testroot" "1"
1360 return 1
1363 local head_commit=`git_show_head $testroot/repo`
1364 echo "A foo" > $testroot/stdout.expected
1365 echo "M alpha" >> $testroot/stdout.expected
1366 echo "D beta" >> $testroot/stdout.expected
1367 echo "Created commit $head_commit" >> $testroot/stdout.expected
1369 cmp -s $testroot/stdout.expected $testroot/stdout
1370 ret=$?
1371 if [ $ret -ne 0 ]; then
1372 diff -u $testroot/stdout.expected $testroot/stdout
1373 test_done "$testroot" "$ret"
1374 return 1
1377 got diff -r $testroot/repo $first_commit $head_commit \
1378 > $testroot/stdout
1380 echo "diff $first_commit $head_commit" \
1381 > $testroot/stdout.expected
1382 echo "commit - $first_commit" >> $testroot/stdout.expected
1383 echo "commit + $head_commit" >> $testroot/stdout.expected
1384 echo -n 'blob - ' >> $testroot/stdout.expected
1385 got tree -r $testroot/repo -i -c $first_commit | \
1386 grep 'alpha$' | cut -d' ' -f 1 \
1387 >> $testroot/stdout.expected
1388 echo -n 'blob + ' >> $testroot/stdout.expected
1389 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1390 echo '--- alpha' >> $testroot/stdout.expected
1391 echo '+++ alpha' >> $testroot/stdout.expected
1392 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1393 echo '-alpha' >> $testroot/stdout.expected
1394 echo '+modified file' >> $testroot/stdout.expected
1395 echo -n 'blob - ' >> $testroot/stdout.expected
1396 got tree -r $testroot/repo -i -c $first_commit \
1397 | grep 'beta$' | cut -d' ' -f 1 | tr -d '\n' \
1398 >> $testroot/stdout.expected
1399 echo " (mode 644)" >> $testroot/stdout.expected
1400 echo 'blob + /dev/null' >> $testroot/stdout.expected
1401 echo '--- beta' >> $testroot/stdout.expected
1402 echo '+++ /dev/null' >> $testroot/stdout.expected
1403 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1404 echo '-beta' >> $testroot/stdout.expected
1405 echo 'blob - /dev/null' >> $testroot/stdout.expected
1406 echo -n 'blob + ' >> $testroot/stdout.expected
1407 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1408 echo " (mode 644)" >> $testroot/stdout.expected
1409 echo '--- /dev/null' >> $testroot/stdout.expected
1410 echo '+++ foo' >> $testroot/stdout.expected
1411 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1412 echo '+new file' >> $testroot/stdout.expected
1414 cmp -s $testroot/stdout.expected $testroot/stdout
1415 ret=$?
1416 if [ $ret -ne 0 ]; then
1417 diff -u $testroot/stdout.expected $testroot/stdout
1418 test_done "$testroot" "$ret"
1419 return 1
1422 echo 'M alpha' > $testroot/stdout.expected
1423 echo 'A epsilon/new' >> $testroot/stdout.expected
1424 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1425 echo 'M foo' >> $testroot/stdout.expected
1426 echo 'M gamma/delta' >> $testroot/stdout.expected
1428 (cd $testroot/wt && got status > $testroot/stdout)
1429 cmp -s $testroot/stdout.expected $testroot/stdout
1430 ret=$?
1431 if [ $ret -ne 0 ]; then
1432 diff -u $testroot/stdout.expected $testroot/stdout
1434 test_done "$testroot" "$ret"
1437 test_stage_patch() {
1438 local testroot=`test_init stage_patch`
1440 jot 16 > $testroot/repo/numbers
1441 (cd $testroot/repo && git add numbers)
1442 git_commit $testroot/repo -m "added numbers file"
1443 local commit_id=`git_show_head $testroot/repo`
1445 got checkout $testroot/repo $testroot/wt > /dev/null
1446 ret=$?
1447 if [ $ret -ne 0 ]; then
1448 test_done "$testroot" "$ret"
1449 return 1
1452 sed -i '' -e 's/^2$/a/' $testroot/wt/numbers
1453 sed -i '' -e 's/^7$/b/' $testroot/wt/numbers
1454 sed -i '' -e 's/^16$/c/' $testroot/wt/numbers
1456 # don't stage any hunks
1457 printf "n\nn\nn\n" > $testroot/patchscript
1458 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1459 numbers > $testroot/stdout 2> $testroot/stderr)
1460 ret=$?
1461 if [ $ret -eq 0 ]; then
1462 echo "got stage command succeeded unexpectedly" >&2
1463 test_done "$testroot" "1"
1464 return 1
1466 cat > $testroot/stdout.expected <<EOF
1467 -----------------------------------------------
1468 @@ -1,5 +1,5 @@
1475 -----------------------------------------------
1476 M numbers (change 1 of 3)
1477 stage this change? [y/n/q] n
1478 -----------------------------------------------
1479 @@ -4,7 +4,7 @@
1488 -----------------------------------------------
1489 M numbers (change 2 of 3)
1490 stage this change? [y/n/q] n
1491 -----------------------------------------------
1492 @@ -13,4 +13,4 @@
1496 -16
1498 -----------------------------------------------
1499 M numbers (change 3 of 3)
1500 stage this change? [y/n/q] n
1501 EOF
1502 cmp -s $testroot/stdout.expected $testroot/stdout
1503 ret=$?
1504 if [ $ret -ne 0 ]; then
1505 diff -u $testroot/stdout.expected $testroot/stdout
1506 test_done "$testroot" "$ret"
1507 return 1
1510 echo "got: no changes to stage" > $testroot/stderr.expected
1511 cmp -s $testroot/stderr.expected $testroot/stderr
1512 ret=$?
1513 if [ $ret -ne 0 ]; then
1514 diff -u $testroot/stderr.expected $testroot/stderr
1515 test_done "$testroot" "$ret"
1516 return 1
1520 (cd $testroot/wt && got status > $testroot/stdout)
1521 echo "M numbers" > $testroot/stdout.expected
1522 cmp -s $testroot/stdout.expected $testroot/stdout
1523 ret=$?
1524 if [ $ret -ne 0 ]; then
1525 diff -u $testroot/stdout.expected $testroot/stdout
1526 test_done "$testroot" "$ret"
1527 return 1
1530 # stage middle hunk
1531 printf "n\ny\nn\n" > $testroot/patchscript
1532 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1533 numbers > $testroot/stdout)
1535 cat > $testroot/stdout.expected <<EOF
1536 -----------------------------------------------
1537 @@ -1,5 +1,5 @@
1544 -----------------------------------------------
1545 M numbers (change 1 of 3)
1546 stage this change? [y/n/q] n
1547 -----------------------------------------------
1548 @@ -4,7 +4,7 @@
1557 -----------------------------------------------
1558 M numbers (change 2 of 3)
1559 stage this change? [y/n/q] y
1560 -----------------------------------------------
1561 @@ -13,4 +13,4 @@
1565 -16
1567 -----------------------------------------------
1568 M numbers (change 3 of 3)
1569 stage this change? [y/n/q] n
1570 EOF
1571 cmp -s $testroot/stdout.expected $testroot/stdout
1572 ret=$?
1573 if [ $ret -ne 0 ]; then
1574 diff -u $testroot/stdout.expected $testroot/stdout
1575 test_done "$testroot" "$ret"
1576 return 1
1579 (cd $testroot/wt && got status > $testroot/stdout)
1580 echo "MM numbers" > $testroot/stdout.expected
1581 cmp -s $testroot/stdout.expected $testroot/stdout
1582 ret=$?
1583 if [ $ret -ne 0 ]; then
1584 diff -u $testroot/stdout.expected $testroot/stdout
1585 test_done "$testroot" "$ret"
1586 return 1
1589 (cd $testroot/wt && got diff -s > $testroot/stdout)
1591 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1592 echo "commit - $commit_id" >> $testroot/stdout.expected
1593 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1594 echo -n 'blob - ' >> $testroot/stdout.expected
1595 got tree -r $testroot/repo -i -c $commit_id \
1596 | grep 'numbers$' | cut -d' ' -f 1 \
1597 >> $testroot/stdout.expected
1598 echo -n 'blob + ' >> $testroot/stdout.expected
1599 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1600 >> $testroot/stdout.expected
1601 echo "--- numbers" >> $testroot/stdout.expected
1602 echo "+++ numbers" >> $testroot/stdout.expected
1603 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1604 echo " 4" >> $testroot/stdout.expected
1605 echo " 5" >> $testroot/stdout.expected
1606 echo " 6" >> $testroot/stdout.expected
1607 echo "-7" >> $testroot/stdout.expected
1608 echo "+b" >> $testroot/stdout.expected
1609 echo " 8" >> $testroot/stdout.expected
1610 echo " 9" >> $testroot/stdout.expected
1611 echo " 10" >> $testroot/stdout.expected
1612 cmp -s $testroot/stdout.expected $testroot/stdout
1613 ret=$?
1614 if [ $ret -ne 0 ]; then
1615 diff -u $testroot/stdout.expected $testroot/stdout
1616 test_done "$testroot" "$ret"
1617 return 1
1620 (cd $testroot/wt && got unstage >/dev/null)
1621 ret=$?
1622 if [ $ret -ne 0 ]; then
1623 echo "got stage command failed unexpectedly" >&2
1624 test_done "$testroot" "1"
1625 return 1
1627 (cd $testroot/wt && got status > $testroot/stdout)
1628 echo "M numbers" > $testroot/stdout.expected
1629 cmp -s $testroot/stdout.expected $testroot/stdout
1630 ret=$?
1631 if [ $ret -ne 0 ]; then
1632 diff -u $testroot/stdout.expected $testroot/stdout
1633 test_done "$testroot" "$ret"
1634 return 1
1637 # stage last hunk
1638 printf "n\nn\ny\n" > $testroot/patchscript
1639 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1640 numbers > $testroot/stdout)
1642 cat > $testroot/stdout.expected <<EOF
1643 -----------------------------------------------
1644 @@ -1,5 +1,5 @@
1651 -----------------------------------------------
1652 M numbers (change 1 of 3)
1653 stage this change? [y/n/q] n
1654 -----------------------------------------------
1655 @@ -4,7 +4,7 @@
1664 -----------------------------------------------
1665 M numbers (change 2 of 3)
1666 stage this change? [y/n/q] n
1667 -----------------------------------------------
1668 @@ -13,4 +13,4 @@
1672 -16
1674 -----------------------------------------------
1675 M numbers (change 3 of 3)
1676 stage this change? [y/n/q] y
1677 EOF
1678 cmp -s $testroot/stdout.expected $testroot/stdout
1679 ret=$?
1680 if [ $ret -ne 0 ]; then
1681 diff -u $testroot/stdout.expected $testroot/stdout
1682 test_done "$testroot" "$ret"
1683 return 1
1686 (cd $testroot/wt && got status > $testroot/stdout)
1687 echo "MM numbers" > $testroot/stdout.expected
1688 cmp -s $testroot/stdout.expected $testroot/stdout
1689 ret=$?
1690 if [ $ret -ne 0 ]; then
1691 diff -u $testroot/stdout.expected $testroot/stdout
1692 test_done "$testroot" "$ret"
1693 return 1
1696 (cd $testroot/wt && got diff -s > $testroot/stdout)
1698 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1699 echo "commit - $commit_id" >> $testroot/stdout.expected
1700 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1701 echo -n 'blob - ' >> $testroot/stdout.expected
1702 got tree -r $testroot/repo -i -c $commit_id \
1703 | grep 'numbers$' | cut -d' ' -f 1 \
1704 >> $testroot/stdout.expected
1705 echo -n 'blob + ' >> $testroot/stdout.expected
1706 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1707 >> $testroot/stdout.expected
1708 echo "--- numbers" >> $testroot/stdout.expected
1709 echo "+++ numbers" >> $testroot/stdout.expected
1710 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1711 echo " 13" >> $testroot/stdout.expected
1712 echo " 14" >> $testroot/stdout.expected
1713 echo " 15" >> $testroot/stdout.expected
1714 echo "-16" >> $testroot/stdout.expected
1715 echo "+c" >> $testroot/stdout.expected
1716 cmp -s $testroot/stdout.expected $testroot/stdout
1717 ret=$?
1718 if [ $ret -ne 0 ]; then
1719 diff -u $testroot/stdout.expected $testroot/stdout
1721 test_done "$testroot" "$ret"
1724 test_stage_patch_twice() {
1725 local testroot=`test_init stage_patch_twice`
1727 jot 16 > $testroot/repo/numbers
1728 (cd $testroot/repo && git add numbers)
1729 git_commit $testroot/repo -m "added numbers file"
1730 local commit_id=`git_show_head $testroot/repo`
1732 got checkout $testroot/repo $testroot/wt > /dev/null
1733 ret=$?
1734 if [ $ret -ne 0 ]; then
1735 test_done "$testroot" "$ret"
1736 return 1
1739 sed -i '' -e 's/^2$/a/' $testroot/wt/numbers
1740 sed -i '' -e 's/^7$/b/' $testroot/wt/numbers
1741 sed -i '' -e 's/^16$/c/' $testroot/wt/numbers
1743 # stage middle hunk
1744 printf "n\ny\nn\n" > $testroot/patchscript
1745 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1746 numbers > $testroot/stdout)
1748 cat > $testroot/stdout.expected <<EOF
1749 -----------------------------------------------
1750 @@ -1,5 +1,5 @@
1757 -----------------------------------------------
1758 M numbers (change 1 of 3)
1759 stage this change? [y/n/q] n
1760 -----------------------------------------------
1761 @@ -4,7 +4,7 @@
1770 -----------------------------------------------
1771 M numbers (change 2 of 3)
1772 stage this change? [y/n/q] y
1773 -----------------------------------------------
1774 @@ -13,4 +13,4 @@
1778 -16
1780 -----------------------------------------------
1781 M numbers (change 3 of 3)
1782 stage this change? [y/n/q] n
1783 EOF
1784 cmp -s $testroot/stdout.expected $testroot/stdout
1785 ret=$?
1786 if [ $ret -ne 0 ]; then
1787 diff -u $testroot/stdout.expected $testroot/stdout
1788 test_done "$testroot" "$ret"
1789 return 1
1792 (cd $testroot/wt && got status > $testroot/stdout)
1793 echo "MM numbers" > $testroot/stdout.expected
1794 cmp -s $testroot/stdout.expected $testroot/stdout
1795 ret=$?
1796 if [ $ret -ne 0 ]; then
1797 diff -u $testroot/stdout.expected $testroot/stdout
1798 test_done "$testroot" "$ret"
1799 return 1
1802 # stage last hunk
1803 printf "n\ny\n" > $testroot/patchscript
1804 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1805 numbers > $testroot/stdout)
1807 cat > $testroot/stdout.expected <<EOF
1808 -----------------------------------------------
1809 @@ -1,5 +1,5 @@
1816 -----------------------------------------------
1817 M numbers (change 1 of 2)
1818 stage this change? [y/n/q] n
1819 -----------------------------------------------
1820 @@ -13,4 +13,4 @@ b
1824 -16
1826 -----------------------------------------------
1827 M numbers (change 2 of 2)
1828 stage this change? [y/n/q] y
1829 EOF
1830 cmp -s $testroot/stdout.expected $testroot/stdout
1831 ret=$?
1832 if [ $ret -ne 0 ]; then
1833 diff -u $testroot/stdout.expected $testroot/stdout
1834 test_done "$testroot" "$ret"
1835 return 1
1838 (cd $testroot/wt && got status > $testroot/stdout)
1839 echo "MM numbers" > $testroot/stdout.expected
1840 cmp -s $testroot/stdout.expected $testroot/stdout
1841 ret=$?
1842 if [ $ret -ne 0 ]; then
1843 diff -u $testroot/stdout.expected $testroot/stdout
1844 test_done "$testroot" "$ret"
1845 return 1
1848 (cd $testroot/wt && got diff -s > $testroot/stdout)
1850 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1851 echo "commit - $commit_id" >> $testroot/stdout.expected
1852 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1853 echo -n 'blob - ' >> $testroot/stdout.expected
1854 got tree -r $testroot/repo -i -c $commit_id \
1855 | grep 'numbers$' | cut -d' ' -f 1 \
1856 >> $testroot/stdout.expected
1857 echo -n 'blob + ' >> $testroot/stdout.expected
1858 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1859 >> $testroot/stdout.expected
1860 echo "--- numbers" >> $testroot/stdout.expected
1861 echo "+++ numbers" >> $testroot/stdout.expected
1862 cat >> $testroot/stdout.expected <<EOF
1863 @@ -4,7 +4,7 @@
1872 @@ -13,4 +13,4 @@
1876 -16
1878 EOF
1879 cmp -s $testroot/stdout.expected $testroot/stdout
1880 ret=$?
1881 if [ $ret -ne 0 ]; then
1882 diff -u $testroot/stdout.expected $testroot/stdout
1883 test_done "$testroot" "$ret"
1884 return 1
1887 (cd $testroot/wt && got diff > $testroot/stdout)
1889 echo "diff $testroot/wt" > $testroot/stdout.expected
1890 echo "commit - $commit_id" >> $testroot/stdout.expected
1891 echo "path + $testroot/wt" >> $testroot/stdout.expected
1892 echo -n 'blob - ' >> $testroot/stdout.expected
1893 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1894 tr -d '\n' >> $testroot/stdout.expected
1895 echo " (staged)" >> $testroot/stdout.expected
1896 echo 'file + numbers' >> $testroot/stdout.expected
1897 echo "--- numbers" >> $testroot/stdout.expected
1898 echo "+++ numbers" >> $testroot/stdout.expected
1899 cat >> $testroot/stdout.expected <<EOF
1900 @@ -1,5 +1,5 @@
1907 EOF
1908 cmp -s $testroot/stdout.expected $testroot/stdout
1909 ret=$?
1910 if [ $ret -ne 0 ]; then
1911 diff -u $testroot/stdout.expected $testroot/stdout
1913 test_done "$testroot" "$ret"
1916 test_stage_patch_added() {
1917 local testroot=`test_init stage_patch_added`
1918 local commit_id=`git_show_head $testroot/repo`
1920 got checkout $testroot/repo $testroot/wt > /dev/null
1921 ret=$?
1922 if [ $ret -ne 0 ]; then
1923 test_done "$testroot" "$ret"
1924 return 1
1927 echo "new" > $testroot/wt/epsilon/new
1928 (cd $testroot/wt && got add epsilon/new > /dev/null)
1930 printf "y\n" > $testroot/patchscript
1931 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1932 epsilon/new > $testroot/stdout)
1934 echo "A epsilon/new" > $testroot/stdout.expected
1935 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1936 cmp -s $testroot/stdout.expected $testroot/stdout
1937 ret=$?
1938 if [ $ret -ne 0 ]; then
1939 diff -u $testroot/stdout.expected $testroot/stdout
1940 test_done "$testroot" "$ret"
1941 return 1
1944 (cd $testroot/wt && got status > $testroot/stdout)
1945 echo " A epsilon/new" > $testroot/stdout.expected
1946 cmp -s $testroot/stdout.expected $testroot/stdout
1947 ret=$?
1948 if [ $ret -ne 0 ]; then
1949 diff -u $testroot/stdout.expected $testroot/stdout
1950 test_done "$testroot" "$ret"
1951 return 1
1954 (cd $testroot/wt && got diff -s > $testroot/stdout)
1956 echo "diff -s $testroot/wt" > $testroot/stdout.expected
1957 echo "commit - $commit_id" >> $testroot/stdout.expected
1958 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
1959 echo 'blob - /dev/null' >> $testroot/stdout.expected
1960 echo -n 'blob + ' >> $testroot/stdout.expected
1961 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1962 >> $testroot/stdout.expected
1963 echo "--- /dev/null" >> $testroot/stdout.expected
1964 echo "+++ epsilon/new" >> $testroot/stdout.expected
1965 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1966 echo "+new" >> $testroot/stdout.expected
1967 cmp -s $testroot/stdout.expected $testroot/stdout
1968 ret=$?
1969 if [ $ret -ne 0 ]; then
1970 diff -u $testroot/stdout.expected $testroot/stdout
1972 test_done "$testroot" "$ret"
1975 test_stage_patch_added_twice() {
1976 local testroot=`test_init stage_patch_added_twice`
1977 local commit_id=`git_show_head $testroot/repo`
1979 got checkout $testroot/repo $testroot/wt > /dev/null
1980 ret=$?
1981 if [ $ret -ne 0 ]; then
1982 test_done "$testroot" "$ret"
1983 return 1
1986 echo "new" > $testroot/wt/epsilon/new
1987 (cd $testroot/wt && got add epsilon/new > /dev/null)
1989 printf "y\n" > $testroot/patchscript
1990 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1991 epsilon/new > $testroot/stdout)
1993 echo "A epsilon/new" > $testroot/stdout.expected
1994 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1995 cmp -s $testroot/stdout.expected $testroot/stdout
1996 ret=$?
1997 if [ $ret -ne 0 ]; then
1998 diff -u $testroot/stdout.expected $testroot/stdout
1999 test_done "$testroot" "$ret"
2000 return 1
2003 (cd $testroot/wt && got status > $testroot/stdout)
2004 echo " A epsilon/new" > $testroot/stdout.expected
2005 cmp -s $testroot/stdout.expected $testroot/stdout
2006 ret=$?
2007 if [ $ret -ne 0 ]; then
2008 diff -u $testroot/stdout.expected $testroot/stdout
2009 test_done "$testroot" "$ret"
2010 return 1
2013 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2014 epsilon/new > $testroot/stdout 2> $testroot/stderr)
2015 ret=$?
2016 if [ $ret -eq 0 ]; then
2017 echo "got stage command succeeded unexpectedly" >&2
2018 test_done "$testroot" "1"
2019 return 1
2022 echo "got: no changes to stage" > $testroot/stderr.expected
2023 cmp -s $testroot/stderr.expected $testroot/stderr
2024 ret=$?
2025 if [ $ret -ne 0 ]; then
2026 diff -u $testroot/stderr.expected $testroot/stderr
2027 test_done "$testroot" "$ret"
2028 return 1
2031 echo -n > $testroot/stdout.expected
2032 cmp -s $testroot/stdout.expected $testroot/stdout
2033 ret=$?
2034 if [ $ret -ne 0 ]; then
2035 diff -u $testroot/stdout.expected $testroot/stdout
2037 test_done "$testroot" "$ret"
2040 test_stage_patch_removed() {
2041 local testroot=`test_init stage_patch_removed`
2042 local commit_id=`git_show_head $testroot/repo`
2044 got checkout $testroot/repo $testroot/wt > /dev/null
2045 ret=$?
2046 if [ $ret -ne 0 ]; then
2047 test_done "$testroot" "$ret"
2048 return 1
2051 (cd $testroot/wt && got rm beta > /dev/null)
2053 printf "y\n" > $testroot/patchscript
2054 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2055 beta > $testroot/stdout)
2057 echo -n > $testroot/stdout.expected
2059 echo "D beta" > $testroot/stdout.expected
2060 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2061 cmp -s $testroot/stdout.expected $testroot/stdout
2062 ret=$?
2063 if [ $ret -ne 0 ]; then
2064 diff -u $testroot/stdout.expected $testroot/stdout
2065 test_done "$testroot" "$ret"
2066 return 1
2069 (cd $testroot/wt && got status > $testroot/stdout)
2070 echo " D beta" > $testroot/stdout.expected
2071 cmp -s $testroot/stdout.expected $testroot/stdout
2072 ret=$?
2073 if [ $ret -ne 0 ]; then
2074 diff -u $testroot/stdout.expected $testroot/stdout
2075 test_done "$testroot" "$ret"
2076 return 1
2079 (cd $testroot/wt && got diff -s > $testroot/stdout)
2081 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2082 echo "commit - $commit_id" >> $testroot/stdout.expected
2083 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2084 echo -n 'blob - ' >> $testroot/stdout.expected
2085 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2086 >> $testroot/stdout.expected
2087 echo 'blob + /dev/null' >> $testroot/stdout.expected
2088 echo "--- beta" >> $testroot/stdout.expected
2089 echo "+++ /dev/null" >> $testroot/stdout.expected
2090 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2091 echo "-beta" >> $testroot/stdout.expected
2092 cmp -s $testroot/stdout.expected $testroot/stdout
2093 ret=$?
2094 if [ $ret -ne 0 ]; then
2095 diff -u $testroot/stdout.expected $testroot/stdout
2097 test_done "$testroot" "$ret"
2100 test_stage_patch_removed_twice() {
2101 local testroot=`test_init stage_patch_removed_twice`
2102 local commit_id=`git_show_head $testroot/repo`
2104 got checkout $testroot/repo $testroot/wt > /dev/null
2105 ret=$?
2106 if [ $ret -ne 0 ]; then
2107 test_done "$testroot" "$ret"
2108 return 1
2111 (cd $testroot/wt && got rm beta > /dev/null)
2113 printf "y\n" > $testroot/patchscript
2114 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2115 beta > $testroot/stdout)
2117 echo -n > $testroot/stdout.expected
2119 echo "D beta" > $testroot/stdout.expected
2120 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2121 cmp -s $testroot/stdout.expected $testroot/stdout
2122 ret=$?
2123 if [ $ret -ne 0 ]; then
2124 diff -u $testroot/stdout.expected $testroot/stdout
2125 test_done "$testroot" "$ret"
2126 return 1
2129 (cd $testroot/wt && got status > $testroot/stdout)
2130 echo " D beta" > $testroot/stdout.expected
2131 cmp -s $testroot/stdout.expected $testroot/stdout
2132 ret=$?
2133 if [ $ret -ne 0 ]; then
2134 diff -u $testroot/stdout.expected $testroot/stdout
2135 test_done "$testroot" "$ret"
2136 return 1
2139 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2140 > $testroot/stdout 2> $testroot/stderr)
2141 ret=$?
2142 if [ $ret -eq 0 ]; then
2143 echo "got stage command succeeded unexpectedly" >&2
2144 test_done "$testroot" "$ret"
2145 return 1
2148 echo "got: no changes to stage" > $testroot/stderr.expected
2149 cmp -s $testroot/stderr.expected $testroot/stderr
2150 ret=$?
2151 if [ $ret -ne 0 ]; then
2152 diff -u $testroot/stderr.expected $testroot/stderr
2153 test_done "$testroot" "$ret"
2154 return 1
2157 echo -n > $testroot/stdout.expected
2158 cmp -s $testroot/stdout.expected $testroot/stdout
2159 ret=$?
2160 if [ $ret -ne 0 ]; then
2161 diff -u $testroot/stdout.expected $testroot/stdout
2163 test_done "$testroot" "$ret"
2166 test_stage_patch_reversed() {
2167 local testroot=`test_init stage_patch_reversed`
2169 got checkout $testroot/repo $testroot/wt > /dev/null
2170 ret=$?
2171 if [ $ret -ne 0 ]; then
2172 test_done "$testroot" "$ret"
2173 return 1
2176 echo 'ALPHA' > $testroot/wt/alpha
2177 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2178 ret=$?
2179 if [ $ret -ne 0 ]; then
2180 test_done "$testroot" "$ret"
2181 return 1
2184 echo ' M alpha' > $testroot/stdout.expected
2185 cmp -s $testroot/stdout.expected $testroot/stdout
2186 ret=$?
2187 if [ $ret -ne 0 ]; then
2188 diff -u $testroot/stdout.expected $testroot/stdout
2189 test_done "$testroot" "$ret"
2190 return 1
2193 echo 'alpha' > $testroot/wt/alpha
2194 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2195 ret=$?
2196 if [ $ret -ne 0 ]; then
2197 test_done "$testroot" "$ret"
2198 return 1
2201 echo ' M alpha' > $testroot/stdout.expected
2202 cmp -s $testroot/stdout.expected $testroot/stdout
2203 ret=$?
2204 if [ $ret -ne 0 ]; then
2205 diff -u $testroot/stdout.expected $testroot/stdout
2206 test_done "$testroot" "$ret"
2207 return 1
2210 (cd $testroot/wt && got status > $testroot/stdout)
2211 cmp -s /dev/null $testroot/stdout
2212 ret=$?
2213 if [ $ret -ne 0 ]; then
2214 diff -u /dev/null $testroot/stdout
2216 test_done "$testroot" "$ret"
2219 test_stage_patch_quit() {
2220 local testroot=`test_init stage_patch_quit`
2222 jot 16 > $testroot/repo/numbers
2223 echo zzz > $testroot/repo/zzz
2224 (cd $testroot/repo && git add numbers zzz)
2225 git_commit $testroot/repo -m "added files"
2226 local commit_id=`git_show_head $testroot/repo`
2228 got checkout $testroot/repo $testroot/wt > /dev/null
2229 ret=$?
2230 if [ $ret -ne 0 ]; then
2231 test_done "$testroot" "$ret"
2232 return 1
2235 sed -i '' -e 's/^2$/a/' $testroot/wt/numbers
2236 sed -i '' -e 's/^7$/b/' $testroot/wt/numbers
2237 sed -i '' -e 's/^16$/c/' $testroot/wt/numbers
2238 (cd $testroot/wt && got rm zzz > /dev/null)
2240 # stage first hunk and quit; and don't pass a path argument to
2241 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2242 printf "y\nq\nn\n" > $testroot/patchscript
2243 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2244 > $testroot/stdout)
2245 ret=$?
2246 if [ $ret -ne 0 ]; then
2247 echo "got stage command failed unexpectedly" >&2
2248 test_done "$testroot" "1"
2249 return 1
2251 cat > $testroot/stdout.expected <<EOF
2252 -----------------------------------------------
2253 @@ -1,5 +1,5 @@
2260 -----------------------------------------------
2261 M numbers (change 1 of 3)
2262 stage this change? [y/n/q] y
2263 -----------------------------------------------
2264 @@ -4,7 +4,7 @@
2273 -----------------------------------------------
2274 M numbers (change 2 of 3)
2275 stage this change? [y/n/q] q
2276 D zzz
2277 stage this deletion? [y/n] n
2278 EOF
2279 cmp -s $testroot/stdout.expected $testroot/stdout
2280 ret=$?
2281 if [ $ret -ne 0 ]; then
2282 diff -u $testroot/stdout.expected $testroot/stdout
2283 test_done "$testroot" "$ret"
2284 return 1
2287 (cd $testroot/wt && got status > $testroot/stdout)
2288 echo "MM numbers" > $testroot/stdout.expected
2289 echo "D zzz" >> $testroot/stdout.expected
2290 cmp -s $testroot/stdout.expected $testroot/stdout
2291 ret=$?
2292 if [ $ret -ne 0 ]; then
2293 diff -u $testroot/stdout.expected $testroot/stdout
2294 test_done "$testroot" "$ret"
2295 return 1
2298 (cd $testroot/wt && got diff -s > $testroot/stdout)
2300 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2301 echo "commit - $commit_id" >> $testroot/stdout.expected
2302 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2303 echo -n 'blob - ' >> $testroot/stdout.expected
2304 got tree -r $testroot/repo -i -c $commit_id \
2305 | grep 'numbers$' | cut -d' ' -f 1 \
2306 >> $testroot/stdout.expected
2307 echo -n 'blob + ' >> $testroot/stdout.expected
2308 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2309 >> $testroot/stdout.expected
2310 echo "--- numbers" >> $testroot/stdout.expected
2311 echo "+++ numbers" >> $testroot/stdout.expected
2312 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2313 echo " 1" >> $testroot/stdout.expected
2314 echo "-2" >> $testroot/stdout.expected
2315 echo "+a" >> $testroot/stdout.expected
2316 echo " 3" >> $testroot/stdout.expected
2317 echo " 4" >> $testroot/stdout.expected
2318 echo " 5" >> $testroot/stdout.expected
2319 cmp -s $testroot/stdout.expected $testroot/stdout
2320 ret=$?
2321 if [ $ret -ne 0 ]; then
2322 diff -u $testroot/stdout.expected $testroot/stdout
2324 test_done "$testroot" "$ret"
2328 test_stage_patch_incomplete_script() {
2329 local testroot=`test_init stage_incomplete_script`
2331 jot 16 > $testroot/repo/numbers
2332 echo zzz > $testroot/repo/zzz
2333 (cd $testroot/repo && git add numbers zzz)
2334 git_commit $testroot/repo -m "added files"
2335 local commit_id=`git_show_head $testroot/repo`
2337 got checkout $testroot/repo $testroot/wt > /dev/null
2338 ret=$?
2339 if [ $ret -ne 0 ]; then
2340 test_done "$testroot" "$ret"
2341 return 1
2344 sed -i '' -e 's/^2$/a/' $testroot/wt/numbers
2345 sed -i '' -e 's/^7$/b/' $testroot/wt/numbers
2346 sed -i '' -e 's/^16$/c/' $testroot/wt/numbers
2348 # stage first hunk and then stop responding; got should error out
2349 printf "y\n" > $testroot/patchscript
2350 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2351 > $testroot/stdout 2> $testroot/stderr)
2352 ret=$?
2353 if [ $ret -eq 0 ]; then
2354 echo "got stage command succeeded unexpectedly" >&2
2355 test_done "$testroot" "1"
2356 return 1
2358 cat > $testroot/stdout.expected <<EOF
2359 -----------------------------------------------
2360 @@ -1,5 +1,5 @@
2367 -----------------------------------------------
2368 M numbers (change 1 of 3)
2369 stage this change? [y/n/q] y
2370 -----------------------------------------------
2371 @@ -4,7 +4,7 @@
2380 -----------------------------------------------
2381 M numbers (change 2 of 3)
2382 EOF
2383 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2384 echo "got: invalid patch choice" > $testroot/stderr.expected
2385 cmp -s $testroot/stderr.expected $testroot/stderr
2386 ret=$?
2387 if [ $ret -ne 0 ]; then
2388 diff -u $testroot/stderr.expected $testroot/stderr
2389 test_done "$testroot" "$ret"
2390 return 1
2393 cmp -s $testroot/stdout.expected $testroot/stdout
2394 ret=$?
2395 if [ $ret -ne 0 ]; then
2396 diff -u $testroot/stdout.expected $testroot/stdout
2397 test_done "$testroot" "$ret"
2398 return 1
2401 (cd $testroot/wt && got status > $testroot/stdout)
2402 echo "M numbers" > $testroot/stdout.expected
2403 cmp -s $testroot/stdout.expected $testroot/stdout
2404 ret=$?
2405 if [ $ret -ne 0 ]; then
2406 diff -u $testroot/stdout.expected $testroot/stdout
2407 test_done "$testroot" "$ret"
2408 return 1
2411 (cd $testroot/wt && got diff -s > $testroot/stdout)
2412 echo -n > $testroot/stdout.expected
2413 cmp -s $testroot/stdout.expected $testroot/stdout
2414 ret=$?
2415 if [ $ret -ne 0 ]; then
2416 diff -u $testroot/stdout.expected $testroot/stdout
2418 test_done "$testroot" "$ret"
2422 test_stage_symlink() {
2423 local testroot=`test_init stage_symlink`
2425 (cd $testroot/repo && ln -s alpha alpha.link)
2426 (cd $testroot/repo && ln -s epsilon epsilon.link)
2427 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2428 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2429 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2430 (cd $testroot/repo && git add .)
2431 git_commit $testroot/repo -m "add symlinks"
2432 local head_commit=`git_show_head $testroot/repo`
2434 got checkout $testroot/repo $testroot/wt > /dev/null
2435 ret=$?
2436 if [ $ret -ne 0 ]; then
2437 test_done "$testroot" "$ret"
2438 return 1
2441 (cd $testroot/wt && ln -sf beta alpha.link)
2442 (cd $testroot/wt && ln -sfT gamma epsilon.link)
2443 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2444 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2445 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2446 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2447 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2448 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2449 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2450 (cd $testroot/wt && got add zeta.link > /dev/null)
2452 (cd $testroot/wt && got stage > $testroot/stdout 2> $testroot/stderr)
2453 ret=$?
2454 if [ $ret -eq 0 ]; then
2455 echo "got stage succeeded unexpectedly" >&2
2456 test_done "$testroot" 1
2457 return 1
2459 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
2460 echo "symbolic link points outside of paths under version control" \
2461 >> $testroot/stderr.expected
2462 cmp -s $testroot/stderr.expected $testroot/stderr
2463 ret=$?
2464 if [ $ret -ne 0 ]; then
2465 diff -u $testroot/stderr.expected $testroot/stderr
2466 test_done "$testroot" "$ret"
2467 return 1
2470 (cd $testroot/wt && got stage -S > $testroot/stdout)
2472 cat > $testroot/stdout.expected <<EOF
2473 M alpha.link
2474 A dotgotbar.link
2475 A dotgotfoo.link
2476 M epsilon/beta.link
2477 M epsilon.link
2478 D nonexistent.link
2479 A zeta.link
2480 EOF
2481 cmp -s $testroot/stdout.expected $testroot/stdout
2482 ret=$?
2483 if [ $ret -ne 0 ]; then
2484 diff -u $testroot/stdout.expected $testroot/stdout
2485 test_done "$testroot" "$ret"
2486 return 1
2489 rm $testroot/wt/alpha.link
2490 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2492 (cd $testroot/wt && got diff -s > $testroot/stdout)
2494 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2495 echo "commit - $head_commit" >> $testroot/stdout.expected
2496 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2497 echo -n 'blob - ' >> $testroot/stdout.expected
2498 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2499 cut -d' ' -f 1 >> $testroot/stdout.expected
2500 echo -n 'blob + ' >> $testroot/stdout.expected
2501 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2502 >> $testroot/stdout.expected
2503 echo '--- alpha.link' >> $testroot/stdout.expected
2504 echo '+++ alpha.link' >> $testroot/stdout.expected
2505 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2506 echo '-alpha' >> $testroot/stdout.expected
2507 echo '\ No newline at end of file' >> $testroot/stdout.expected
2508 echo '+beta' >> $testroot/stdout.expected
2509 echo '\ No newline at end of file' >> $testroot/stdout.expected
2510 echo 'blob - /dev/null' >> $testroot/stdout.expected
2511 echo -n 'blob + ' >> $testroot/stdout.expected
2512 (cd $testroot/wt && got stage -l dotgotbar.link) | cut -d' ' -f 1 \
2513 >> $testroot/stdout.expected
2514 echo '--- /dev/null' >> $testroot/stdout.expected
2515 echo '+++ dotgotbar.link' >> $testroot/stdout.expected
2516 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2517 echo '+.got/bar' >> $testroot/stdout.expected
2518 echo '\ No newline at end of file' >> $testroot/stdout.expected
2519 echo 'blob - /dev/null' >> $testroot/stdout.expected
2520 echo -n 'blob + ' >> $testroot/stdout.expected
2521 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2522 >> $testroot/stdout.expected
2523 echo '--- /dev/null' >> $testroot/stdout.expected
2524 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2525 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2526 echo '+this is regular file foo' >> $testroot/stdout.expected
2527 echo -n 'blob - ' >> $testroot/stdout.expected
2528 got tree -r $testroot/repo -i epsilon | grep 'beta.link@ -> ../beta$' | \
2529 cut -d' ' -f 1 >> $testroot/stdout.expected
2530 echo -n 'blob + ' >> $testroot/stdout.expected
2531 (cd $testroot/wt && got stage -l epsilon/beta.link) | cut -d' ' -f 1 \
2532 >> $testroot/stdout.expected
2533 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
2534 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
2535 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2536 echo '-../beta' >> $testroot/stdout.expected
2537 echo '\ No newline at end of file' >> $testroot/stdout.expected
2538 echo '+../gamma/delta' >> $testroot/stdout.expected
2539 echo '\ No newline at end of file' >> $testroot/stdout.expected
2540 echo -n 'blob - ' >> $testroot/stdout.expected
2541 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2542 cut -d' ' -f 1 >> $testroot/stdout.expected
2543 echo -n 'blob + ' >> $testroot/stdout.expected
2544 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2545 >> $testroot/stdout.expected
2546 echo '--- epsilon.link' >> $testroot/stdout.expected
2547 echo '+++ epsilon.link' >> $testroot/stdout.expected
2548 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2549 echo '-epsilon' >> $testroot/stdout.expected
2550 echo '\ No newline at end of file' >> $testroot/stdout.expected
2551 echo '+gamma' >> $testroot/stdout.expected
2552 echo '\ No newline at end of file' >> $testroot/stdout.expected
2553 echo -n 'blob - ' >> $testroot/stdout.expected
2554 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2555 cut -d' ' -f 1 >> $testroot/stdout.expected
2556 echo 'blob + /dev/null' >> $testroot/stdout.expected
2557 echo '--- nonexistent.link' >> $testroot/stdout.expected
2558 echo '+++ /dev/null' >> $testroot/stdout.expected
2559 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2560 echo '-nonexistent' >> $testroot/stdout.expected
2561 echo '\ No newline at end of file' >> $testroot/stdout.expected
2562 echo 'blob - /dev/null' >> $testroot/stdout.expected
2563 echo -n 'blob + ' >> $testroot/stdout.expected
2564 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2565 >> $testroot/stdout.expected
2566 echo '--- /dev/null' >> $testroot/stdout.expected
2567 echo '+++ zeta.link' >> $testroot/stdout.expected
2568 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2569 echo '+gamma/delta' >> $testroot/stdout.expected
2570 echo '\ No newline at end of file' >> $testroot/stdout.expected
2572 cmp -s $testroot/stdout.expected $testroot/stdout
2573 ret=$?
2574 if [ $ret -ne 0 ]; then
2575 diff -u $testroot/stdout.expected $testroot/stdout
2576 test_done "$testroot" "$ret"
2577 return 1
2580 (cd $testroot/wt && got commit -m "staged symlink" \
2581 > $testroot/stdout)
2582 ret=$?
2583 if [ $ret -ne 0 ]; then
2584 echo "got commit command failed unexpectedly" >&2
2585 test_done "$testroot" "1"
2586 return 1
2589 local commit_id=`git_show_head $testroot/repo`
2590 echo "A dotgotbar.link" > $testroot/stdout.expected
2591 echo "A dotgotfoo.link" >> $testroot/stdout.expected
2592 echo "A zeta.link" >> $testroot/stdout.expected
2593 echo "M alpha.link" >> $testroot/stdout.expected
2594 echo "M epsilon/beta.link" >> $testroot/stdout.expected
2595 echo "M epsilon.link" >> $testroot/stdout.expected
2596 echo "D nonexistent.link" >> $testroot/stdout.expected
2597 echo "Created commit $commit_id" >> $testroot/stdout.expected
2598 cmp -s $testroot/stdout.expected $testroot/stdout
2599 ret=$?
2600 if [ $ret -ne 0 ]; then
2601 diff -u $testroot/stdout.expected $testroot/stdout
2602 test_done "$testroot" "$ret"
2603 return 1
2606 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2607 ret=$?
2608 if [ $ret -ne 0 ]; then
2609 echo "got tree command failed unexpectedly" >&2
2610 test_done "$testroot" "1"
2611 return 1
2614 cat > $testroot/stdout.expected <<EOF
2615 alpha
2616 alpha.link@ -> beta
2617 beta
2618 dotgotbar.link@ -> .got/bar
2619 dotgotfoo.link
2620 epsilon/
2621 epsilon.link@ -> gamma
2622 gamma/
2623 passwd.link@ -> /etc/passwd
2624 zeta.link@ -> gamma/delta
2625 EOF
2626 cmp -s $testroot/stdout.expected $testroot/stdout
2627 ret=$?
2628 if [ $ret -ne 0 ]; then
2629 diff -u $testroot/stdout.expected $testroot/stdout
2630 return 1
2633 if [ -h $testroot/wt/alpha.link ]; then
2634 echo "alpha.link is a symlink"
2635 test_done "$testroot" "1"
2636 return 1
2639 echo 'this is regular file alpha.link' > $testroot/content.expected
2640 cp $testroot/wt/alpha.link $testroot/content
2641 cmp -s $testroot/content.expected $testroot/content
2642 ret=$?
2643 if [ $ret -ne 0 ]; then
2644 diff -u $testroot/content.expected $testroot/content
2645 test_done "$testroot" "$ret"
2646 return 1
2649 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2650 echo "dotgotbar.link is not a symlink"
2651 test_done "$testroot" "1"
2652 return 1
2654 (cd $testroot/wt && got update > /dev/null)
2655 if [ -h $testroot/wt/dotgotbar.link ]; then
2656 echo "dotgotbar.link is a symlink"
2657 test_done "$testroot" "1"
2658 return 1
2660 echo -n ".got/bar" > $testroot/content.expected
2661 cp $testroot/wt/dotgotbar.link $testroot/content
2662 cmp -s $testroot/content.expected $testroot/content
2663 ret=$?
2664 if [ $ret -ne 0 ]; then
2665 diff -u $testroot/content.expected $testroot/content
2666 test_done "$testroot" "$ret"
2667 return 1
2670 if [ -h $testroot/wt/dotgotfoo.link ]; then
2671 echo "dotgotfoo.link is a symlink"
2672 test_done "$testroot" "1"
2673 return 1
2675 echo "this is regular file foo" > $testroot/content.expected
2676 cp $testroot/wt/dotgotfoo.link $testroot/content
2677 cmp -s $testroot/content.expected $testroot/content
2678 ret=$?
2679 if [ $ret -ne 0 ]; then
2680 diff -u $testroot/content.expected $testroot/content
2681 test_done "$testroot" "$ret"
2682 return 1
2685 if ! [ -h $testroot/wt/epsilon.link ]; then
2686 echo "epsilon.link is not a symlink"
2687 test_done "$testroot" "1"
2688 return 1
2691 readlink $testroot/wt/epsilon.link > $testroot/stdout
2692 echo "gamma" > $testroot/stdout.expected
2693 cmp -s $testroot/stdout.expected $testroot/stdout
2694 ret=$?
2695 if [ $ret -ne 0 ]; then
2696 diff -u $testroot/stdout.expected $testroot/stdout
2697 test_done "$testroot" "$ret"
2698 return 1
2701 if [ -h $testroot/wt/passwd.link ]; then
2702 echo "passwd.link is a symlink"
2703 test_done "$testroot" "1"
2704 return 1
2706 echo -n "/etc/passwd" > $testroot/content.expected
2707 cp $testroot/wt/passwd.link $testroot/content
2708 cmp -s $testroot/content.expected $testroot/content
2709 ret=$?
2710 if [ $ret -ne 0 ]; then
2711 diff -u $testroot/content.expected $testroot/content
2712 test_done "$testroot" "$ret"
2713 return 1
2716 if ! [ -h $testroot/wt/zeta.link ]; then
2717 echo "zeta.link is not a symlink"
2718 test_done "$testroot" "1"
2719 return 1
2722 readlink $testroot/wt/zeta.link > $testroot/stdout
2723 echo "gamma/delta" > $testroot/stdout.expected
2724 cmp -s $testroot/stdout.expected $testroot/stdout
2725 ret=$?
2726 if [ $ret -ne 0 ]; then
2727 diff -u $testroot/stdout.expected $testroot/stdout
2728 test_done "$testroot" "$ret"
2729 return 1
2732 test_done "$testroot" "0"
2735 test_stage_patch_symlink() {
2736 local testroot=`test_init stage_patch_symlink`
2738 (cd $testroot/repo && ln -s alpha alpha.link)
2739 (cd $testroot/repo && ln -s epsilon epsilon.link)
2740 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2741 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2742 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2743 (cd $testroot/repo && git add .)
2744 git_commit $testroot/repo -m "add symlinks"
2745 local head_commit=`git_show_head $testroot/repo`
2747 got checkout $testroot/repo $testroot/wt > /dev/null
2748 ret=$?
2749 if [ $ret -ne 0 ]; then
2750 test_done "$testroot" "$ret"
2751 return 1
2754 (cd $testroot/wt && ln -sf beta alpha.link)
2755 (cd $testroot/wt && ln -sfT gamma epsilon.link)
2756 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2757 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2758 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2759 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2760 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2761 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2762 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2763 (cd $testroot/wt && got add zeta.link > /dev/null)
2765 printf "y\nn\ny\nn\ny\ny\ny" > $testroot/patchscript
2766 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2767 > $testroot/stdout)
2769 cat > $testroot/stdout.expected <<EOF
2770 -----------------------------------------------
2771 @@ -1 +1 @@
2772 -alpha
2773 \ No newline at end of file
2774 +beta
2775 \ No newline at end of file
2776 -----------------------------------------------
2777 M alpha.link (change 1 of 1)
2778 stage this change? [y/n/q] y
2779 A dotgotbar.link
2780 stage this addition? [y/n] n
2781 A dotgotfoo.link
2782 stage this addition? [y/n] y
2783 -----------------------------------------------
2784 @@ -1 +1 @@
2785 -../beta
2786 \ No newline at end of file
2787 +../gamma/delta
2788 \ No newline at end of file
2789 -----------------------------------------------
2790 M epsilon/beta.link (change 1 of 1)
2791 stage this change? [y/n/q] n
2792 -----------------------------------------------
2793 @@ -1 +1 @@
2794 -epsilon
2795 \ No newline at end of file
2796 +gamma
2797 \ No newline at end of file
2798 -----------------------------------------------
2799 M epsilon.link (change 1 of 1)
2800 stage this change? [y/n/q] y
2801 D nonexistent.link
2802 stage this deletion? [y/n] y
2803 A zeta.link
2804 stage this addition? [y/n] y
2805 EOF
2806 cmp -s $testroot/stdout.expected $testroot/stdout
2807 ret=$?
2808 if [ $ret -ne 0 ]; then
2809 diff -u $testroot/stdout.expected $testroot/stdout
2810 test_done "$testroot" "$ret"
2811 return 1
2814 rm $testroot/wt/alpha.link
2815 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2817 (cd $testroot/wt && got diff -s > $testroot/stdout)
2819 echo "diff -s $testroot/wt" > $testroot/stdout.expected
2820 echo "commit - $head_commit" >> $testroot/stdout.expected
2821 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
2822 echo -n 'blob - ' >> $testroot/stdout.expected
2823 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2824 cut -d' ' -f 1 >> $testroot/stdout.expected
2825 echo -n 'blob + ' >> $testroot/stdout.expected
2826 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2827 >> $testroot/stdout.expected
2828 echo '--- alpha.link' >> $testroot/stdout.expected
2829 echo '+++ alpha.link' >> $testroot/stdout.expected
2830 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2831 echo '-alpha' >> $testroot/stdout.expected
2832 echo '\ No newline at end of file' >> $testroot/stdout.expected
2833 echo '+beta' >> $testroot/stdout.expected
2834 echo '\ No newline at end of file' >> $testroot/stdout.expected
2835 echo 'blob - /dev/null' >> $testroot/stdout.expected
2836 echo -n 'blob + ' >> $testroot/stdout.expected
2837 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2838 >> $testroot/stdout.expected
2839 echo '--- /dev/null' >> $testroot/stdout.expected
2840 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2841 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2842 echo '+this is regular file foo' >> $testroot/stdout.expected
2843 echo -n 'blob - ' >> $testroot/stdout.expected
2844 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2845 cut -d' ' -f 1 >> $testroot/stdout.expected
2846 echo -n 'blob + ' >> $testroot/stdout.expected
2847 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2848 >> $testroot/stdout.expected
2849 echo '--- epsilon.link' >> $testroot/stdout.expected
2850 echo '+++ epsilon.link' >> $testroot/stdout.expected
2851 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2852 echo '-epsilon' >> $testroot/stdout.expected
2853 echo '\ No newline at end of file' >> $testroot/stdout.expected
2854 echo '+gamma' >> $testroot/stdout.expected
2855 echo '\ No newline at end of file' >> $testroot/stdout.expected
2856 echo -n 'blob - ' >> $testroot/stdout.expected
2857 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2858 cut -d' ' -f 1 >> $testroot/stdout.expected
2859 echo 'blob + /dev/null' >> $testroot/stdout.expected
2860 echo '--- nonexistent.link' >> $testroot/stdout.expected
2861 echo '+++ /dev/null' >> $testroot/stdout.expected
2862 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2863 echo '-nonexistent' >> $testroot/stdout.expected
2864 echo '\ No newline at end of file' >> $testroot/stdout.expected
2865 echo 'blob - /dev/null' >> $testroot/stdout.expected
2866 echo -n 'blob + ' >> $testroot/stdout.expected
2867 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2868 >> $testroot/stdout.expected
2869 echo '--- /dev/null' >> $testroot/stdout.expected
2870 echo '+++ zeta.link' >> $testroot/stdout.expected
2871 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2872 echo '+gamma/delta' >> $testroot/stdout.expected
2873 echo '\ No newline at end of file' >> $testroot/stdout.expected
2875 cmp -s $testroot/stdout.expected $testroot/stdout
2876 ret=$?
2877 if [ $ret -ne 0 ]; then
2878 diff -u $testroot/stdout.expected $testroot/stdout
2879 test_done "$testroot" "$ret"
2880 return 1
2883 (cd $testroot/wt && got commit -m "staged symlink" \
2884 > $testroot/stdout)
2885 ret=$?
2886 if [ $ret -ne 0 ]; then
2887 echo "got commit command failed unexpectedly" >&2
2888 test_done "$testroot" "1"
2889 return 1
2892 local commit_id=`git_show_head $testroot/repo`
2893 echo "A dotgotfoo.link" > $testroot/stdout.expected
2894 echo "A zeta.link" >> $testroot/stdout.expected
2895 echo "M alpha.link" >> $testroot/stdout.expected
2896 echo "M epsilon.link" >> $testroot/stdout.expected
2897 echo "D nonexistent.link" >> $testroot/stdout.expected
2898 echo "Created commit $commit_id" >> $testroot/stdout.expected
2899 cmp -s $testroot/stdout.expected $testroot/stdout
2900 ret=$?
2901 if [ $ret -ne 0 ]; then
2902 diff -u $testroot/stdout.expected $testroot/stdout
2903 test_done "$testroot" "$ret"
2904 return 1
2907 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2908 ret=$?
2909 if [ $ret -ne 0 ]; then
2910 echo "got tree command failed unexpectedly" >&2
2911 test_done "$testroot" "1"
2912 return 1
2915 cat > $testroot/stdout.expected <<EOF
2916 alpha
2917 alpha.link@ -> beta
2918 beta
2919 dotgotfoo.link
2920 epsilon/
2921 epsilon.link@ -> gamma
2922 gamma/
2923 passwd.link@ -> /etc/passwd
2924 zeta.link@ -> gamma/delta
2925 EOF
2926 cmp -s $testroot/stdout.expected $testroot/stdout
2927 ret=$?
2928 if [ $ret -ne 0 ]; then
2929 diff -u $testroot/stdout.expected $testroot/stdout
2930 return 1
2933 if [ -h $testroot/wt/alpha.link ]; then
2934 echo "alpha.link is a symlink"
2935 test_done "$testroot" "1"
2936 return 1
2939 echo 'this is regular file alpha.link' > $testroot/content.expected
2940 cp $testroot/wt/alpha.link $testroot/content
2941 cmp -s $testroot/content.expected $testroot/content
2942 ret=$?
2943 if [ $ret -ne 0 ]; then
2944 diff -u $testroot/content.expected $testroot/content
2945 test_done "$testroot" "$ret"
2946 return 1
2949 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2950 echo "dotgotbar.link is not a symlink"
2951 test_done "$testroot" "1"
2952 return 1
2954 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
2955 echo ".got/bar" > $testroot/stdout.expected
2956 cmp -s $testroot/stdout.expected $testroot/stdout
2957 ret=$?
2958 if [ $ret -ne 0 ]; then
2959 diff -u $testroot/stdout.expected $testroot/stdout
2960 test_done "$testroot" "$ret"
2961 return 1
2964 if [ -h $testroot/wt/dotgotfoo.link ]; then
2965 echo "dotgotfoo.link is a symlink"
2966 test_done "$testroot" "1"
2967 return 1
2969 echo "this is regular file foo" > $testroot/content.expected
2970 cp $testroot/wt/dotgotfoo.link $testroot/content
2971 cmp -s $testroot/content.expected $testroot/content
2972 ret=$?
2973 if [ $ret -ne 0 ]; then
2974 diff -u $testroot/content.expected $testroot/content
2975 test_done "$testroot" "$ret"
2976 return 1
2979 if ! [ -h $testroot/wt/epsilon.link ]; then
2980 echo "epsilon.link is not a symlink"
2981 test_done "$testroot" "1"
2982 return 1
2985 readlink $testroot/wt/epsilon.link > $testroot/stdout
2986 echo "gamma" > $testroot/stdout.expected
2987 cmp -s $testroot/stdout.expected $testroot/stdout
2988 ret=$?
2989 if [ $ret -ne 0 ]; then
2990 diff -u $testroot/stdout.expected $testroot/stdout
2991 test_done "$testroot" "$ret"
2992 return 1
2995 if [ -h $testroot/wt/passwd.link ]; then
2996 echo "passwd.link is a symlink"
2997 test_done "$testroot" "1"
2998 return 1
3000 echo -n "/etc/passwd" > $testroot/content.expected
3001 cp $testroot/wt/passwd.link $testroot/content
3002 cmp -s $testroot/content.expected $testroot/content
3003 ret=$?
3004 if [ $ret -ne 0 ]; then
3005 diff -u $testroot/content.expected $testroot/content
3006 test_done "$testroot" "$ret"
3007 return 1
3010 if ! [ -h $testroot/wt/zeta.link ]; then
3011 echo "zeta.link is not a symlink"
3012 test_done "$testroot" "1"
3013 return 1
3016 readlink $testroot/wt/zeta.link > $testroot/stdout
3017 echo "gamma/delta" > $testroot/stdout.expected
3018 cmp -s $testroot/stdout.expected $testroot/stdout
3019 ret=$?
3020 if [ $ret -ne 0 ]; then
3021 diff -u $testroot/stdout.expected $testroot/stdout
3022 test_done "$testroot" "$ret"
3023 return 1
3026 test_done "$testroot" "0"
3029 test_parseargs "$@"
3030 run_test test_stage_basic
3031 run_test test_stage_no_changes
3032 run_test test_stage_unversioned
3033 run_test test_stage_nonexistent
3034 run_test test_stage_list
3035 run_test test_stage_conflict
3036 run_test test_stage_out_of_date
3037 run_test test_double_stage
3038 run_test test_stage_status
3039 run_test test_stage_add_already_staged_file
3040 run_test test_stage_rm_already_staged_file
3041 run_test test_stage_revert
3042 run_test test_stage_diff
3043 run_test test_stage_histedit
3044 run_test test_stage_rebase
3045 run_test test_stage_update
3046 run_test test_stage_commit_non_staged
3047 run_test test_stage_commit_out_of_date
3048 run_test test_stage_commit
3049 run_test test_stage_patch
3050 run_test test_stage_patch_twice
3051 run_test test_stage_patch_added
3052 run_test test_stage_patch_added_twice
3053 run_test test_stage_patch_removed
3054 run_test test_stage_patch_removed_twice
3055 run_test test_stage_patch_reversed
3056 run_test test_stage_patch_quit
3057 run_test test_stage_patch_incomplete_script
3058 run_test test_stage_symlink
3059 run_test test_stage_patch_symlink