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 $head_commit $testroot/wt" > $testroot/stdout.expected
934 echo -n 'blob - ' >> $testroot/stdout.expected
935 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 | tr -d '\n' \
936 >> $testroot/stdout.expected
937 echo ' (staged)' >> $testroot/stdout.expected
938 echo 'file + alpha' >> $testroot/stdout.expected
939 echo '--- alpha' >> $testroot/stdout.expected
940 echo '+++ alpha' >> $testroot/stdout.expected
941 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
942 echo '-modified file' >> $testroot/stdout.expected
943 echo '+modified file again' >> $testroot/stdout.expected
944 echo -n 'blob - ' >> $testroot/stdout.expected
945 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 | tr -d '\n' \
946 >> $testroot/stdout.expected
947 echo " (staged)" >> $testroot/stdout.expected
948 echo 'file + foo' >> $testroot/stdout.expected
949 echo '--- foo' >> $testroot/stdout.expected
950 echo '+++ foo' >> $testroot/stdout.expected
951 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
952 echo '-new file' >> $testroot/stdout.expected
953 echo '+new file changed' >> $testroot/stdout.expected
955 cmp -s $testroot/stdout.expected $testroot/stdout
956 ret=$?
957 if [ $ret -ne 0 ]; then
958 diff -u $testroot/stdout.expected $testroot/stdout
959 test_done "$testroot" "$ret"
960 return 1
961 fi
963 (cd $testroot/wt && got diff -s > $testroot/stdout)
965 echo "diff $head_commit $testroot/wt (staged changes)" \
966 > $testroot/stdout.expected
967 echo -n 'blob - ' >> $testroot/stdout.expected
968 got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
969 >> $testroot/stdout.expected
970 echo -n 'blob + ' >> $testroot/stdout.expected
971 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
972 >> $testroot/stdout.expected
973 echo '--- alpha' >> $testroot/stdout.expected
974 echo '+++ alpha' >> $testroot/stdout.expected
975 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
976 echo '-alpha' >> $testroot/stdout.expected
977 echo '+modified file' >> $testroot/stdout.expected
978 echo -n 'blob - ' >> $testroot/stdout.expected
979 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
980 >> $testroot/stdout.expected
981 echo 'blob + /dev/null' >> $testroot/stdout.expected
982 echo '--- beta' >> $testroot/stdout.expected
983 echo '+++ /dev/null' >> $testroot/stdout.expected
984 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
985 echo '-beta' >> $testroot/stdout.expected
986 echo 'blob - /dev/null' >> $testroot/stdout.expected
987 echo -n 'blob + ' >> $testroot/stdout.expected
988 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
989 >> $testroot/stdout.expected
990 echo '--- /dev/null' >> $testroot/stdout.expected
991 echo '+++ foo' >> $testroot/stdout.expected
992 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
993 echo '+new file' >> $testroot/stdout.expected
995 cmp -s $testroot/stdout.expected $testroot/stdout
996 ret=$?
997 if [ $ret -ne 0 ]; then
998 diff -u $testroot/stdout.expected $testroot/stdout
999 fi
1000 test_done "$testroot" "$ret"
1004 test_stage_histedit() {
1005 local testroot=`test_init stage_histedit`
1006 local orig_commit=`git_show_head $testroot/repo`
1008 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1009 ret=$?
1010 if [ $ret -ne 0 ]; then
1011 test_done "$testroot" "$ret"
1012 return 1
1015 echo "modified file" > $testroot/wt/alpha
1016 (cd $testroot/wt && got stage alpha > /dev/null)
1018 echo "modified alpha on master" > $testroot/repo/alpha
1019 (cd $testroot/repo && git rm -q beta)
1020 echo "new file on master" > $testroot/repo/epsilon/new
1021 (cd $testroot/repo && git add epsilon/new)
1022 git_commit $testroot/repo -m "committing changes"
1023 local old_commit1=`git_show_head $testroot/repo`
1025 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1026 git_commit $testroot/repo -m "committing to zeta on master"
1027 local old_commit2=`git_show_head $testroot/repo`
1029 echo "pick $old_commit1" > $testroot/histedit-script
1030 echo "pick $old_commit2" >> $testroot/histedit-script
1032 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1033 > $testroot/stdout 2> $testroot/stderr)
1034 ret=$?
1035 if [ $ret -eq 0 ]; then
1036 echo "got histedit command succeeded unexpectedly" >&2
1037 test_done "$testroot" "1"
1038 return 1
1041 echo -n > $testroot/stdout.expected
1042 echo "got: alpha: file is staged" > $testroot/stderr.expected
1044 cmp -s $testroot/stderr.expected $testroot/stderr
1045 ret=$?
1046 if [ $ret -ne 0 ]; then
1047 diff -u $testroot/stderr.expected $testroot/stderr
1048 test_done "$testroot" "$ret"
1049 return 1
1051 cmp -s $testroot/stdout.expected $testroot/stdout
1052 ret=$?
1053 if [ $ret -ne 0 ]; then
1054 diff -u $testroot/stdout.expected $testroot/stdout
1056 test_done "$testroot" "$ret"
1060 test_stage_rebase() {
1061 local testroot=`test_init stage_rebase`
1063 (cd $testroot/repo && git checkout -q -b newbranch)
1064 echo "modified delta on branch" > $testroot/repo/gamma/delta
1065 git_commit $testroot/repo -m "committing to delta on newbranch"
1067 echo "modified alpha on branch" > $testroot/repo/alpha
1068 (cd $testroot/repo && git rm -q beta)
1069 echo "new file on branch" > $testroot/repo/epsilon/new
1070 (cd $testroot/repo && git add epsilon/new)
1071 git_commit $testroot/repo -m "committing more changes on newbranch"
1073 local orig_commit1=`git_show_parent_commit $testroot/repo`
1074 local orig_commit2=`git_show_head $testroot/repo`
1076 (cd $testroot/repo && git checkout -q master)
1077 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1078 git_commit $testroot/repo -m "committing to zeta on master"
1079 local master_commit=`git_show_head $testroot/repo`
1081 got checkout $testroot/repo $testroot/wt > /dev/null
1082 ret=$?
1083 if [ $ret -ne 0 ]; then
1084 test_done "$testroot" "$ret"
1085 return 1
1088 echo "modified file" > $testroot/wt/alpha
1089 (cd $testroot/wt && got stage alpha > /dev/null)
1091 (cd $testroot/wt && got rebase newbranch \
1092 > $testroot/stdout 2> $testroot/stderr)
1093 ret=$?
1094 if [ $ret -eq 0 ]; then
1095 echo "got rebase command succeeded unexpectedly" >&2
1096 test_done "$testroot" "1"
1097 return 1
1100 echo -n > $testroot/stdout.expected
1101 echo "got: alpha: file is staged" > $testroot/stderr.expected
1103 cmp -s $testroot/stderr.expected $testroot/stderr
1104 ret=$?
1105 if [ $ret -ne 0 ]; then
1106 diff -u $testroot/stderr.expected $testroot/stderr
1107 test_done "$testroot" "$ret"
1108 return 1
1110 cmp -s $testroot/stdout.expected $testroot/stdout
1111 ret=$?
1112 if [ $ret -ne 0 ]; then
1113 diff -u $testroot/stdout.expected $testroot/stdout
1115 test_done "$testroot" "$ret"
1118 test_stage_update() {
1119 local testroot=`test_init stage_update`
1121 got checkout $testroot/repo $testroot/wt > /dev/null
1122 ret=$?
1123 if [ $ret -ne 0 ]; then
1124 test_done "$testroot" "$ret"
1125 return 1
1128 echo "modified file" > $testroot/wt/alpha
1129 (cd $testroot/wt && got stage alpha > /dev/null)
1131 echo "modified alpha" > $testroot/repo/alpha
1132 git_commit $testroot/repo -m "modified alpha"
1134 (cd $testroot/wt && got update > $testroot/stdout \
1135 2> $testroot/stderr)
1136 ret=$?
1137 if [ $ret -eq 0 ]; then
1138 echo "got update command succeeded unexpectedly" >&2
1139 test_done "$testroot" "1"
1140 return 1
1143 echo -n > $testroot/stdout.expected
1144 echo "got: alpha: file is staged" > $testroot/stderr.expected
1146 cmp -s $testroot/stderr.expected $testroot/stderr
1147 ret=$?
1148 if [ $ret -ne 0 ]; then
1149 diff -u $testroot/stderr.expected $testroot/stderr
1150 test_done "$testroot" "$ret"
1151 return 1
1153 cmp -s $testroot/stdout.expected $testroot/stdout
1154 ret=$?
1155 if [ $ret -ne 0 ]; then
1156 diff -u $testroot/stdout.expected $testroot/stdout
1158 test_done "$testroot" "$ret"
1161 test_stage_commit_non_staged() {
1162 local testroot=`test_init stage_commit_non_staged`
1164 got checkout $testroot/repo $testroot/wt > /dev/null
1165 ret=$?
1166 if [ $ret -ne 0 ]; then
1167 test_done "$testroot" "$ret"
1168 return 1
1171 echo "modified file" > $testroot/wt/alpha
1172 (cd $testroot/wt && got rm beta > /dev/null)
1173 echo "new file" > $testroot/wt/foo
1174 (cd $testroot/wt && got add foo > /dev/null)
1175 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1177 echo "modified file" > $testroot/wt/gamma/delta
1178 (cd $testroot/wt && got commit -m "change delta" gamma/delta \
1179 > $testroot/stdout 2> $testroot/stderr)
1180 ret=$?
1181 if [ $ret -eq 0 ]; then
1182 echo "got commit command succeeded unexpectedly" >&2
1183 test_done "$testroot" "1"
1184 return 1
1187 echo -n > $testroot/stdout.expected
1188 echo "got: gamma/delta: file is not staged" > $testroot/stderr.expected
1190 cmp -s $testroot/stderr.expected $testroot/stderr
1191 ret=$?
1192 if [ $ret -ne 0 ]; then
1193 diff -u $testroot/stderr.expected $testroot/stderr
1194 test_done "$testroot" "$ret"
1195 return 1
1197 cmp -s $testroot/stdout.expected $testroot/stdout
1198 ret=$?
1199 if [ $ret -ne 0 ]; then
1200 diff -u $testroot/stdout.expected $testroot/stdout
1202 test_done "$testroot" "$ret"
1205 test_stage_commit_out_of_date() {
1206 local testroot=`test_init stage_commit_out_of_date`
1208 got checkout $testroot/repo $testroot/wt > /dev/null
1209 ret=$?
1210 if [ $ret -ne 0 ]; then
1211 test_done "$testroot" "$ret"
1212 return 1
1215 echo "modified file" > $testroot/wt/alpha
1216 (cd $testroot/wt && got rm beta > /dev/null)
1217 echo "new file" > $testroot/wt/foo
1218 (cd $testroot/wt && got add foo > /dev/null)
1219 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1221 echo "changed file" > $testroot/repo/alpha
1222 git_commit $testroot/repo -m "changed alpha in repo"
1224 (cd $testroot/wt && got commit -m "try to commit" > $testroot/stdout \
1225 2> $testroot/stderr)
1226 ret=$?
1227 if [ $ret -eq 0 ]; then
1228 echo "got commit command succeeded unexpectedly" >&2
1229 test_done "$testroot" "1"
1230 return 1
1233 echo -n > $testroot/stdout.expected
1234 echo -n "got: work tree must be updated before these changes " \
1235 > $testroot/stderr.expected
1236 echo "can be committed" >> $testroot/stderr.expected
1238 cmp -s $testroot/stderr.expected $testroot/stderr
1239 ret=$?
1240 if [ $ret -ne 0 ]; then
1241 diff -u $testroot/stderr.expected $testroot/stderr
1242 test_done "$testroot" "$ret"
1243 return 1
1245 cmp -s $testroot/stdout.expected $testroot/stdout
1246 ret=$?
1247 if [ $ret -ne 0 ]; then
1248 diff -u $testroot/stdout.expected $testroot/stdout
1249 test_done "$testroot" "$ret"
1250 return 1
1253 (cd $testroot/wt && got update > $testroot/stdout \
1254 2> $testroot/stderr)
1255 echo -n > $testroot/stdout.expected
1256 echo "got: alpha: file is staged" > $testroot/stderr.expected
1258 cmp -s $testroot/stderr.expected $testroot/stderr
1259 ret=$?
1260 if [ $ret -ne 0 ]; then
1261 diff -u $testroot/stderr.expected $testroot/stderr
1262 test_done "$testroot" "$ret"
1263 return 1
1265 cmp -s $testroot/stdout.expected $testroot/stdout
1266 ret=$?
1267 if [ $ret -ne 0 ]; then
1268 diff -u $testroot/stdout.expected $testroot/stdout
1269 test_done "$testroot" "$ret"
1270 return 1
1273 (cd $testroot/wt && got unstage > /dev/null)
1274 (cd $testroot/wt && got update > $testroot/stdout)
1275 ret=$?
1276 if [ $ret -ne 0 ]; then
1277 echo "got update command failed unexpectedly" >&2
1278 test_done "$testroot" "$ret"
1279 return 1
1282 (cd $testroot/wt && got status > $testroot/stdout)
1283 echo "C alpha" > $testroot/stdout.expected
1284 echo "D beta" >> $testroot/stdout.expected
1285 echo "A foo" >> $testroot/stdout.expected
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1287 ret=$?
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1290 test_done "$testroot" "$ret"
1291 return 1
1294 # resolve conflict
1295 echo "resolved file" > $testroot/wt/alpha
1297 (cd $testroot/wt && got stage > /dev/null)
1299 (cd $testroot/wt && got commit -m "try again" > $testroot/stdout)
1300 ret=$?
1301 if [ $ret -ne 0 ]; then
1302 echo "got commit command failed unexpectedly" >&2
1303 test_done "$testroot" "$ret"
1304 return 1
1307 local commit_id=`git_show_head $testroot/repo`
1308 echo "A foo" > $testroot/stdout.expected
1309 echo "M alpha" >> $testroot/stdout.expected
1310 echo "D beta" >> $testroot/stdout.expected
1311 echo "Created commit $commit_id" >> $testroot/stdout.expected
1312 cmp -s $testroot/stdout.expected $testroot/stdout
1313 ret=$?
1314 if [ $ret -ne 0 ]; then
1315 diff -u $testroot/stdout.expected $testroot/stdout
1317 test_done "$testroot" "$ret"
1321 test_stage_commit() {
1322 local testroot=`test_init stage_commit`
1323 local first_commit=`git_show_head $testroot/repo`
1325 got checkout $testroot/repo $testroot/wt > /dev/null
1326 ret=$?
1327 if [ $ret -ne 0 ]; then
1328 test_done "$testroot" "$ret"
1329 return 1
1332 echo "modified file" > $testroot/wt/alpha
1333 (cd $testroot/wt && got rm beta > /dev/null)
1334 echo "new file" > $testroot/wt/foo
1335 (cd $testroot/wt && got add foo > /dev/null)
1336 echo "modified file" > $testroot/wt/alpha
1337 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
1339 echo "modified file again" > $testroot/wt/alpha
1340 echo "new file changed" > $testroot/wt/foo
1341 echo "non-staged change" > $testroot/wt/gamma/delta
1342 echo "non-staged new file" > $testroot/wt/epsilon/new
1343 (cd $testroot/wt && got add epsilon/new > /dev/null)
1344 (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
1346 (cd $testroot/wt && got stage -l alpha) | cut -d' ' -f 1 \
1347 > $testroot/blob_id_alpha
1348 (cd $testroot/wt && got stage -l foo) | cut -d' ' -f 1 \
1349 > $testroot/blob_id_foo
1351 (cd $testroot/wt && got commit -m "staged changes" \
1352 > $testroot/stdout)
1353 ret=$?
1354 if [ $ret -ne 0 ]; then
1355 echo "got commit command failed unexpectedly" >&2
1356 test_done "$testroot" "1"
1357 return 1
1360 local head_commit=`git_show_head $testroot/repo`
1361 echo "A foo" > $testroot/stdout.expected
1362 echo "M alpha" >> $testroot/stdout.expected
1363 echo "D beta" >> $testroot/stdout.expected
1364 echo "Created commit $head_commit" >> $testroot/stdout.expected
1366 cmp -s $testroot/stdout.expected $testroot/stdout
1367 ret=$?
1368 if [ $ret -ne 0 ]; then
1369 diff -u $testroot/stdout.expected $testroot/stdout
1370 test_done "$testroot" "$ret"
1371 return 1
1374 got diff -r $testroot/repo $first_commit $head_commit \
1375 > $testroot/stdout
1377 echo "diff $first_commit $head_commit" \
1378 > $testroot/stdout.expected
1379 echo -n 'blob - ' >> $testroot/stdout.expected
1380 got tree -r $testroot/repo -i -c $first_commit | \
1381 grep 'alpha$' | cut -d' ' -f 1 \
1382 >> $testroot/stdout.expected
1383 echo -n 'blob + ' >> $testroot/stdout.expected
1384 cat $testroot/blob_id_alpha >> $testroot/stdout.expected
1385 echo '--- alpha' >> $testroot/stdout.expected
1386 echo '+++ alpha' >> $testroot/stdout.expected
1387 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
1388 echo '-alpha' >> $testroot/stdout.expected
1389 echo '+modified file' >> $testroot/stdout.expected
1390 echo -n 'blob - ' >> $testroot/stdout.expected
1391 got tree -r $testroot/repo -i -c $first_commit \
1392 | grep 'beta$' | cut -d' ' -f 1 | tr -d '\n' \
1393 >> $testroot/stdout.expected
1394 echo " (mode 644)" >> $testroot/stdout.expected
1395 echo 'blob + /dev/null' >> $testroot/stdout.expected
1396 echo '--- beta' >> $testroot/stdout.expected
1397 echo '+++ /dev/null' >> $testroot/stdout.expected
1398 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1399 echo '-beta' >> $testroot/stdout.expected
1400 echo 'blob - /dev/null' >> $testroot/stdout.expected
1401 echo -n 'blob + ' >> $testroot/stdout.expected
1402 cat $testroot/blob_id_foo | tr -d '\n' >> $testroot/stdout.expected
1403 echo " (mode 644)" >> $testroot/stdout.expected
1404 echo '--- /dev/null' >> $testroot/stdout.expected
1405 echo '+++ foo' >> $testroot/stdout.expected
1406 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
1407 echo '+new file' >> $testroot/stdout.expected
1409 cmp -s $testroot/stdout.expected $testroot/stdout
1410 ret=$?
1411 if [ $ret -ne 0 ]; then
1412 diff -u $testroot/stdout.expected $testroot/stdout
1413 test_done "$testroot" "$ret"
1414 return 1
1417 echo 'M alpha' > $testroot/stdout.expected
1418 echo 'A epsilon/new' >> $testroot/stdout.expected
1419 echo 'D epsilon/zeta' >> $testroot/stdout.expected
1420 echo 'M foo' >> $testroot/stdout.expected
1421 echo 'M gamma/delta' >> $testroot/stdout.expected
1423 (cd $testroot/wt && got status > $testroot/stdout)
1424 cmp -s $testroot/stdout.expected $testroot/stdout
1425 ret=$?
1426 if [ $ret -ne 0 ]; then
1427 diff -u $testroot/stdout.expected $testroot/stdout
1429 test_done "$testroot" "$ret"
1432 test_stage_patch() {
1433 local testroot=`test_init stage_patch`
1435 jot 16 > $testroot/repo/numbers
1436 (cd $testroot/repo && git add numbers)
1437 git_commit $testroot/repo -m "added numbers file"
1438 local commit_id=`git_show_head $testroot/repo`
1440 got checkout $testroot/repo $testroot/wt > /dev/null
1441 ret=$?
1442 if [ $ret -ne 0 ]; then
1443 test_done "$testroot" "$ret"
1444 return 1
1447 sed -i '' -e 's/^2$/a/' $testroot/wt/numbers
1448 sed -i '' -e 's/^7$/b/' $testroot/wt/numbers
1449 sed -i '' -e 's/^16$/c/' $testroot/wt/numbers
1451 # don't stage any hunks
1452 printf "n\nn\nn\n" > $testroot/patchscript
1453 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1454 numbers > $testroot/stdout 2> $testroot/stderr)
1455 ret=$?
1456 if [ $ret -eq 0 ]; then
1457 echo "got stage command succeeded unexpectedly" >&2
1458 test_done "$testroot" "1"
1459 return 1
1461 cat > $testroot/stdout.expected <<EOF
1462 -----------------------------------------------
1463 @@ -1,5 +1,5 @@
1470 -----------------------------------------------
1471 M numbers (change 1 of 3)
1472 stage this change? [y/n/q] n
1473 -----------------------------------------------
1474 @@ -4,7 +4,7 @@
1483 -----------------------------------------------
1484 M numbers (change 2 of 3)
1485 stage this change? [y/n/q] n
1486 -----------------------------------------------
1487 @@ -13,4 +13,4 @@
1491 -16
1493 -----------------------------------------------
1494 M numbers (change 3 of 3)
1495 stage this change? [y/n/q] n
1496 EOF
1497 cmp -s $testroot/stdout.expected $testroot/stdout
1498 ret=$?
1499 if [ $ret -ne 0 ]; then
1500 diff -u $testroot/stdout.expected $testroot/stdout
1501 test_done "$testroot" "$ret"
1502 return 1
1505 echo "got: no changes to stage" > $testroot/stderr.expected
1506 cmp -s $testroot/stderr.expected $testroot/stderr
1507 ret=$?
1508 if [ $ret -ne 0 ]; then
1509 diff -u $testroot/stderr.expected $testroot/stderr
1510 test_done "$testroot" "$ret"
1511 return 1
1515 (cd $testroot/wt && got status > $testroot/stdout)
1516 echo "M numbers" > $testroot/stdout.expected
1517 cmp -s $testroot/stdout.expected $testroot/stdout
1518 ret=$?
1519 if [ $ret -ne 0 ]; then
1520 diff -u $testroot/stdout.expected $testroot/stdout
1521 test_done "$testroot" "$ret"
1522 return 1
1525 # stage middle hunk
1526 printf "n\ny\nn\n" > $testroot/patchscript
1527 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1528 numbers > $testroot/stdout)
1530 cat > $testroot/stdout.expected <<EOF
1531 -----------------------------------------------
1532 @@ -1,5 +1,5 @@
1539 -----------------------------------------------
1540 M numbers (change 1 of 3)
1541 stage this change? [y/n/q] n
1542 -----------------------------------------------
1543 @@ -4,7 +4,7 @@
1552 -----------------------------------------------
1553 M numbers (change 2 of 3)
1554 stage this change? [y/n/q] y
1555 -----------------------------------------------
1556 @@ -13,4 +13,4 @@
1560 -16
1562 -----------------------------------------------
1563 M numbers (change 3 of 3)
1564 stage this change? [y/n/q] n
1565 EOF
1566 cmp -s $testroot/stdout.expected $testroot/stdout
1567 ret=$?
1568 if [ $ret -ne 0 ]; then
1569 diff -u $testroot/stdout.expected $testroot/stdout
1570 test_done "$testroot" "$ret"
1571 return 1
1574 (cd $testroot/wt && got status > $testroot/stdout)
1575 echo "MM numbers" > $testroot/stdout.expected
1576 cmp -s $testroot/stdout.expected $testroot/stdout
1577 ret=$?
1578 if [ $ret -ne 0 ]; then
1579 diff -u $testroot/stdout.expected $testroot/stdout
1580 test_done "$testroot" "$ret"
1581 return 1
1584 (cd $testroot/wt && got diff -s > $testroot/stdout)
1586 echo "diff $commit_id $testroot/wt (staged changes)" \
1587 > $testroot/stdout.expected
1588 echo -n 'blob - ' >> $testroot/stdout.expected
1589 got tree -r $testroot/repo -i -c $commit_id \
1590 | grep 'numbers$' | cut -d' ' -f 1 \
1591 >> $testroot/stdout.expected
1592 echo -n 'blob + ' >> $testroot/stdout.expected
1593 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1594 >> $testroot/stdout.expected
1595 echo "--- numbers" >> $testroot/stdout.expected
1596 echo "+++ numbers" >> $testroot/stdout.expected
1597 echo "@@ -4,7 +4,7 @@" >> $testroot/stdout.expected
1598 echo " 4" >> $testroot/stdout.expected
1599 echo " 5" >> $testroot/stdout.expected
1600 echo " 6" >> $testroot/stdout.expected
1601 echo "-7" >> $testroot/stdout.expected
1602 echo "+b" >> $testroot/stdout.expected
1603 echo " 8" >> $testroot/stdout.expected
1604 echo " 9" >> $testroot/stdout.expected
1605 echo " 10" >> $testroot/stdout.expected
1606 cmp -s $testroot/stdout.expected $testroot/stdout
1607 ret=$?
1608 if [ $ret -ne 0 ]; then
1609 diff -u $testroot/stdout.expected $testroot/stdout
1610 test_done "$testroot" "$ret"
1611 return 1
1614 (cd $testroot/wt && got unstage >/dev/null)
1615 ret=$?
1616 if [ $ret -ne 0 ]; then
1617 echo "got stage command failed unexpectedly" >&2
1618 test_done "$testroot" "1"
1619 return 1
1621 (cd $testroot/wt && got status > $testroot/stdout)
1622 echo "M numbers" > $testroot/stdout.expected
1623 cmp -s $testroot/stdout.expected $testroot/stdout
1624 ret=$?
1625 if [ $ret -ne 0 ]; then
1626 diff -u $testroot/stdout.expected $testroot/stdout
1627 test_done "$testroot" "$ret"
1628 return 1
1631 # stage last hunk
1632 printf "n\nn\ny\n" > $testroot/patchscript
1633 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1634 numbers > $testroot/stdout)
1636 cat > $testroot/stdout.expected <<EOF
1637 -----------------------------------------------
1638 @@ -1,5 +1,5 @@
1645 -----------------------------------------------
1646 M numbers (change 1 of 3)
1647 stage this change? [y/n/q] n
1648 -----------------------------------------------
1649 @@ -4,7 +4,7 @@
1658 -----------------------------------------------
1659 M numbers (change 2 of 3)
1660 stage this change? [y/n/q] n
1661 -----------------------------------------------
1662 @@ -13,4 +13,4 @@
1666 -16
1668 -----------------------------------------------
1669 M numbers (change 3 of 3)
1670 stage this change? [y/n/q] y
1671 EOF
1672 cmp -s $testroot/stdout.expected $testroot/stdout
1673 ret=$?
1674 if [ $ret -ne 0 ]; then
1675 diff -u $testroot/stdout.expected $testroot/stdout
1676 test_done "$testroot" "$ret"
1677 return 1
1680 (cd $testroot/wt && got status > $testroot/stdout)
1681 echo "MM numbers" > $testroot/stdout.expected
1682 cmp -s $testroot/stdout.expected $testroot/stdout
1683 ret=$?
1684 if [ $ret -ne 0 ]; then
1685 diff -u $testroot/stdout.expected $testroot/stdout
1686 test_done "$testroot" "$ret"
1687 return 1
1690 (cd $testroot/wt && got diff -s > $testroot/stdout)
1692 echo "diff $commit_id $testroot/wt (staged changes)" \
1693 > $testroot/stdout.expected
1694 echo -n 'blob - ' >> $testroot/stdout.expected
1695 got tree -r $testroot/repo -i -c $commit_id \
1696 | grep 'numbers$' | cut -d' ' -f 1 \
1697 >> $testroot/stdout.expected
1698 echo -n 'blob + ' >> $testroot/stdout.expected
1699 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1700 >> $testroot/stdout.expected
1701 echo "--- numbers" >> $testroot/stdout.expected
1702 echo "+++ numbers" >> $testroot/stdout.expected
1703 echo "@@ -13,4 +13,4 @@" >> $testroot/stdout.expected
1704 echo " 13" >> $testroot/stdout.expected
1705 echo " 14" >> $testroot/stdout.expected
1706 echo " 15" >> $testroot/stdout.expected
1707 echo "-16" >> $testroot/stdout.expected
1708 echo "+c" >> $testroot/stdout.expected
1709 cmp -s $testroot/stdout.expected $testroot/stdout
1710 ret=$?
1711 if [ $ret -ne 0 ]; then
1712 diff -u $testroot/stdout.expected $testroot/stdout
1714 test_done "$testroot" "$ret"
1717 test_stage_patch_twice() {
1718 local testroot=`test_init stage_patch_twice`
1720 jot 16 > $testroot/repo/numbers
1721 (cd $testroot/repo && git add numbers)
1722 git_commit $testroot/repo -m "added numbers file"
1723 local commit_id=`git_show_head $testroot/repo`
1725 got checkout $testroot/repo $testroot/wt > /dev/null
1726 ret=$?
1727 if [ $ret -ne 0 ]; then
1728 test_done "$testroot" "$ret"
1729 return 1
1732 sed -i '' -e 's/^2$/a/' $testroot/wt/numbers
1733 sed -i '' -e 's/^7$/b/' $testroot/wt/numbers
1734 sed -i '' -e 's/^16$/c/' $testroot/wt/numbers
1736 # stage middle hunk
1737 printf "n\ny\nn\n" > $testroot/patchscript
1738 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1739 numbers > $testroot/stdout)
1741 cat > $testroot/stdout.expected <<EOF
1742 -----------------------------------------------
1743 @@ -1,5 +1,5 @@
1750 -----------------------------------------------
1751 M numbers (change 1 of 3)
1752 stage this change? [y/n/q] n
1753 -----------------------------------------------
1754 @@ -4,7 +4,7 @@
1763 -----------------------------------------------
1764 M numbers (change 2 of 3)
1765 stage this change? [y/n/q] y
1766 -----------------------------------------------
1767 @@ -13,4 +13,4 @@
1771 -16
1773 -----------------------------------------------
1774 M numbers (change 3 of 3)
1775 stage this change? [y/n/q] n
1776 EOF
1777 cmp -s $testroot/stdout.expected $testroot/stdout
1778 ret=$?
1779 if [ $ret -ne 0 ]; then
1780 diff -u $testroot/stdout.expected $testroot/stdout
1781 test_done "$testroot" "$ret"
1782 return 1
1785 (cd $testroot/wt && got status > $testroot/stdout)
1786 echo "MM numbers" > $testroot/stdout.expected
1787 cmp -s $testroot/stdout.expected $testroot/stdout
1788 ret=$?
1789 if [ $ret -ne 0 ]; then
1790 diff -u $testroot/stdout.expected $testroot/stdout
1791 test_done "$testroot" "$ret"
1792 return 1
1795 # stage last hunk
1796 printf "n\ny\n" > $testroot/patchscript
1797 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1798 numbers > $testroot/stdout)
1800 cat > $testroot/stdout.expected <<EOF
1801 -----------------------------------------------
1802 @@ -1,5 +1,5 @@
1809 -----------------------------------------------
1810 M numbers (change 1 of 2)
1811 stage this change? [y/n/q] n
1812 -----------------------------------------------
1813 @@ -13,4 +13,4 @@ b
1817 -16
1819 -----------------------------------------------
1820 M numbers (change 2 of 2)
1821 stage this change? [y/n/q] y
1822 EOF
1823 cmp -s $testroot/stdout.expected $testroot/stdout
1824 ret=$?
1825 if [ $ret -ne 0 ]; then
1826 diff -u $testroot/stdout.expected $testroot/stdout
1827 test_done "$testroot" "$ret"
1828 return 1
1831 (cd $testroot/wt && got status > $testroot/stdout)
1832 echo "MM numbers" > $testroot/stdout.expected
1833 cmp -s $testroot/stdout.expected $testroot/stdout
1834 ret=$?
1835 if [ $ret -ne 0 ]; then
1836 diff -u $testroot/stdout.expected $testroot/stdout
1837 test_done "$testroot" "$ret"
1838 return 1
1841 (cd $testroot/wt && got diff -s > $testroot/stdout)
1843 echo "diff $commit_id $testroot/wt (staged changes)" \
1844 > $testroot/stdout.expected
1845 echo -n 'blob - ' >> $testroot/stdout.expected
1846 got tree -r $testroot/repo -i -c $commit_id \
1847 | grep 'numbers$' | cut -d' ' -f 1 \
1848 >> $testroot/stdout.expected
1849 echo -n 'blob + ' >> $testroot/stdout.expected
1850 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1851 >> $testroot/stdout.expected
1852 echo "--- numbers" >> $testroot/stdout.expected
1853 echo "+++ numbers" >> $testroot/stdout.expected
1854 cat >> $testroot/stdout.expected <<EOF
1855 @@ -4,7 +4,7 @@
1864 @@ -13,4 +13,4 @@
1868 -16
1870 EOF
1871 cmp -s $testroot/stdout.expected $testroot/stdout
1872 ret=$?
1873 if [ $ret -ne 0 ]; then
1874 diff -u $testroot/stdout.expected $testroot/stdout
1875 test_done "$testroot" "$ret"
1876 return 1
1879 (cd $testroot/wt && got diff > $testroot/stdout)
1881 echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
1882 echo -n 'blob - ' >> $testroot/stdout.expected
1883 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
1884 tr -d '\n' >> $testroot/stdout.expected
1885 echo " (staged)" >> $testroot/stdout.expected
1886 echo 'file + numbers' >> $testroot/stdout.expected
1887 echo "--- numbers" >> $testroot/stdout.expected
1888 echo "+++ numbers" >> $testroot/stdout.expected
1889 cat >> $testroot/stdout.expected <<EOF
1890 @@ -1,5 +1,5 @@
1897 EOF
1898 cmp -s $testroot/stdout.expected $testroot/stdout
1899 ret=$?
1900 if [ $ret -ne 0 ]; then
1901 diff -u $testroot/stdout.expected $testroot/stdout
1903 test_done "$testroot" "$ret"
1906 test_stage_patch_added() {
1907 local testroot=`test_init stage_patch_added`
1908 local commit_id=`git_show_head $testroot/repo`
1910 got checkout $testroot/repo $testroot/wt > /dev/null
1911 ret=$?
1912 if [ $ret -ne 0 ]; then
1913 test_done "$testroot" "$ret"
1914 return 1
1917 echo "new" > $testroot/wt/epsilon/new
1918 (cd $testroot/wt && got add epsilon/new > /dev/null)
1920 printf "y\n" > $testroot/patchscript
1921 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1922 epsilon/new > $testroot/stdout)
1924 echo "A epsilon/new" > $testroot/stdout.expected
1925 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1926 cmp -s $testroot/stdout.expected $testroot/stdout
1927 ret=$?
1928 if [ $ret -ne 0 ]; then
1929 diff -u $testroot/stdout.expected $testroot/stdout
1930 test_done "$testroot" "$ret"
1931 return 1
1934 (cd $testroot/wt && got status > $testroot/stdout)
1935 echo " A epsilon/new" > $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 diff -s > $testroot/stdout)
1946 echo "diff $commit_id $testroot/wt (staged changes)" \
1947 > $testroot/stdout.expected
1948 echo 'blob - /dev/null' >> $testroot/stdout.expected
1949 echo -n 'blob + ' >> $testroot/stdout.expected
1950 (cd $testroot/wt && got stage -l epsilon/new) | cut -d' ' -f 1 \
1951 >> $testroot/stdout.expected
1952 echo "--- /dev/null" >> $testroot/stdout.expected
1953 echo "+++ epsilon/new" >> $testroot/stdout.expected
1954 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
1955 echo "+new" >> $testroot/stdout.expected
1956 cmp -s $testroot/stdout.expected $testroot/stdout
1957 ret=$?
1958 if [ $ret -ne 0 ]; then
1959 diff -u $testroot/stdout.expected $testroot/stdout
1961 test_done "$testroot" "$ret"
1964 test_stage_patch_added_twice() {
1965 local testroot=`test_init stage_patch_added_twice`
1966 local commit_id=`git_show_head $testroot/repo`
1968 got checkout $testroot/repo $testroot/wt > /dev/null
1969 ret=$?
1970 if [ $ret -ne 0 ]; then
1971 test_done "$testroot" "$ret"
1972 return 1
1975 echo "new" > $testroot/wt/epsilon/new
1976 (cd $testroot/wt && got add epsilon/new > /dev/null)
1978 printf "y\n" > $testroot/patchscript
1979 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
1980 epsilon/new > $testroot/stdout)
1982 echo "A epsilon/new" > $testroot/stdout.expected
1983 echo "stage this addition? [y/n] y" >> $testroot/stdout.expected
1984 cmp -s $testroot/stdout.expected $testroot/stdout
1985 ret=$?
1986 if [ $ret -ne 0 ]; then
1987 diff -u $testroot/stdout.expected $testroot/stdout
1988 test_done "$testroot" "$ret"
1989 return 1
1992 (cd $testroot/wt && got status > $testroot/stdout)
1993 echo " A epsilon/new" > $testroot/stdout.expected
1994 cmp -s $testroot/stdout.expected $testroot/stdout
1995 ret=$?
1996 if [ $ret -ne 0 ]; then
1997 diff -u $testroot/stdout.expected $testroot/stdout
1998 test_done "$testroot" "$ret"
1999 return 1
2002 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2003 epsilon/new > $testroot/stdout 2> $testroot/stderr)
2004 ret=$?
2005 if [ $ret -eq 0 ]; then
2006 echo "got stage command succeeded unexpectedly" >&2
2007 test_done "$testroot" "1"
2008 return 1
2011 echo "got: no changes to stage" > $testroot/stderr.expected
2012 cmp -s $testroot/stderr.expected $testroot/stderr
2013 ret=$?
2014 if [ $ret -ne 0 ]; then
2015 diff -u $testroot/stderr.expected $testroot/stderr
2016 test_done "$testroot" "$ret"
2017 return 1
2020 echo -n > $testroot/stdout.expected
2021 cmp -s $testroot/stdout.expected $testroot/stdout
2022 ret=$?
2023 if [ $ret -ne 0 ]; then
2024 diff -u $testroot/stdout.expected $testroot/stdout
2026 test_done "$testroot" "$ret"
2029 test_stage_patch_removed() {
2030 local testroot=`test_init stage_patch_removed`
2031 local commit_id=`git_show_head $testroot/repo`
2033 got checkout $testroot/repo $testroot/wt > /dev/null
2034 ret=$?
2035 if [ $ret -ne 0 ]; then
2036 test_done "$testroot" "$ret"
2037 return 1
2040 (cd $testroot/wt && got rm beta > /dev/null)
2042 printf "y\n" > $testroot/patchscript
2043 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2044 beta > $testroot/stdout)
2046 echo -n > $testroot/stdout.expected
2048 echo "D beta" > $testroot/stdout.expected
2049 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2050 cmp -s $testroot/stdout.expected $testroot/stdout
2051 ret=$?
2052 if [ $ret -ne 0 ]; then
2053 diff -u $testroot/stdout.expected $testroot/stdout
2054 test_done "$testroot" "$ret"
2055 return 1
2058 (cd $testroot/wt && got status > $testroot/stdout)
2059 echo " D beta" > $testroot/stdout.expected
2060 cmp -s $testroot/stdout.expected $testroot/stdout
2061 ret=$?
2062 if [ $ret -ne 0 ]; then
2063 diff -u $testroot/stdout.expected $testroot/stdout
2064 test_done "$testroot" "$ret"
2065 return 1
2068 (cd $testroot/wt && got diff -s > $testroot/stdout)
2070 echo "diff $commit_id $testroot/wt (staged changes)" \
2071 > $testroot/stdout.expected
2072 echo -n 'blob - ' >> $testroot/stdout.expected
2073 (cd $testroot/wt && got stage -l beta) | cut -d' ' -f 1 \
2074 >> $testroot/stdout.expected
2075 echo 'blob + /dev/null' >> $testroot/stdout.expected
2076 echo "--- beta" >> $testroot/stdout.expected
2077 echo "+++ /dev/null" >> $testroot/stdout.expected
2078 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
2079 echo "-beta" >> $testroot/stdout.expected
2080 cmp -s $testroot/stdout.expected $testroot/stdout
2081 ret=$?
2082 if [ $ret -ne 0 ]; then
2083 diff -u $testroot/stdout.expected $testroot/stdout
2085 test_done "$testroot" "$ret"
2088 test_stage_patch_removed_twice() {
2089 local testroot=`test_init stage_patch_removed_twice`
2090 local commit_id=`git_show_head $testroot/repo`
2092 got checkout $testroot/repo $testroot/wt > /dev/null
2093 ret=$?
2094 if [ $ret -ne 0 ]; then
2095 test_done "$testroot" "$ret"
2096 return 1
2099 (cd $testroot/wt && got rm beta > /dev/null)
2101 printf "y\n" > $testroot/patchscript
2102 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2103 beta > $testroot/stdout)
2105 echo -n > $testroot/stdout.expected
2107 echo "D beta" > $testroot/stdout.expected
2108 echo "stage this deletion? [y/n] y" >> $testroot/stdout.expected
2109 cmp -s $testroot/stdout.expected $testroot/stdout
2110 ret=$?
2111 if [ $ret -ne 0 ]; then
2112 diff -u $testroot/stdout.expected $testroot/stdout
2113 test_done "$testroot" "$ret"
2114 return 1
2117 (cd $testroot/wt && got status > $testroot/stdout)
2118 echo " D beta" > $testroot/stdout.expected
2119 cmp -s $testroot/stdout.expected $testroot/stdout
2120 ret=$?
2121 if [ $ret -ne 0 ]; then
2122 diff -u $testroot/stdout.expected $testroot/stdout
2123 test_done "$testroot" "$ret"
2124 return 1
2127 (cd $testroot/wt && got stage -F $testroot/patchscript -p beta \
2128 > $testroot/stdout 2> $testroot/stderr)
2129 ret=$?
2130 if [ $ret -eq 0 ]; then
2131 echo "got stage command succeeded unexpectedly" >&2
2132 test_done "$testroot" "$ret"
2133 return 1
2136 echo "got: no changes to stage" > $testroot/stderr.expected
2137 cmp -s $testroot/stderr.expected $testroot/stderr
2138 ret=$?
2139 if [ $ret -ne 0 ]; then
2140 diff -u $testroot/stderr.expected $testroot/stderr
2141 test_done "$testroot" "$ret"
2142 return 1
2145 echo -n > $testroot/stdout.expected
2146 cmp -s $testroot/stdout.expected $testroot/stdout
2147 ret=$?
2148 if [ $ret -ne 0 ]; then
2149 diff -u $testroot/stdout.expected $testroot/stdout
2151 test_done "$testroot" "$ret"
2154 test_stage_patch_reversed() {
2155 local testroot=`test_init stage_patch_reversed`
2157 got checkout $testroot/repo $testroot/wt > /dev/null
2158 ret=$?
2159 if [ $ret -ne 0 ]; then
2160 test_done "$testroot" "$ret"
2161 return 1
2164 echo 'ALPHA' > $testroot/wt/alpha
2165 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2166 ret=$?
2167 if [ $ret -ne 0 ]; then
2168 test_done "$testroot" "$ret"
2169 return 1
2172 echo ' M alpha' > $testroot/stdout.expected
2173 cmp -s $testroot/stdout.expected $testroot/stdout
2174 ret=$?
2175 if [ $ret -ne 0 ]; then
2176 diff -u $testroot/stdout.expected $testroot/stdout
2177 test_done "$testroot" "$ret"
2178 return 1
2181 echo 'alpha' > $testroot/wt/alpha
2182 (cd $testroot/wt && got stage alpha > $testroot/stdout)
2183 ret=$?
2184 if [ $ret -ne 0 ]; then
2185 test_done "$testroot" "$ret"
2186 return 1
2189 echo ' M alpha' > $testroot/stdout.expected
2190 cmp -s $testroot/stdout.expected $testroot/stdout
2191 ret=$?
2192 if [ $ret -ne 0 ]; then
2193 diff -u $testroot/stdout.expected $testroot/stdout
2194 test_done "$testroot" "$ret"
2195 return 1
2198 (cd $testroot/wt && got status > $testroot/stdout)
2199 cmp -s /dev/null $testroot/stdout
2200 ret=$?
2201 if [ $ret -ne 0 ]; then
2202 diff -u /dev/null $testroot/stdout
2204 test_done "$testroot" "$ret"
2207 test_stage_patch_quit() {
2208 local testroot=`test_init stage_patch_quit`
2210 jot 16 > $testroot/repo/numbers
2211 echo zzz > $testroot/repo/zzz
2212 (cd $testroot/repo && git add numbers zzz)
2213 git_commit $testroot/repo -m "added files"
2214 local commit_id=`git_show_head $testroot/repo`
2216 got checkout $testroot/repo $testroot/wt > /dev/null
2217 ret=$?
2218 if [ $ret -ne 0 ]; then
2219 test_done "$testroot" "$ret"
2220 return 1
2223 sed -i '' -e 's/^2$/a/' $testroot/wt/numbers
2224 sed -i '' -e 's/^7$/b/' $testroot/wt/numbers
2225 sed -i '' -e 's/^16$/c/' $testroot/wt/numbers
2226 (cd $testroot/wt && got rm zzz > /dev/null)
2228 # stage first hunk and quit; and don't pass a path argument to
2229 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2230 printf "y\nq\nn\n" > $testroot/patchscript
2231 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2232 > $testroot/stdout)
2233 ret=$?
2234 if [ $ret -ne 0 ]; then
2235 echo "got stage command failed unexpectedly" >&2
2236 test_done "$testroot" "1"
2237 return 1
2239 cat > $testroot/stdout.expected <<EOF
2240 -----------------------------------------------
2241 @@ -1,5 +1,5 @@
2248 -----------------------------------------------
2249 M numbers (change 1 of 3)
2250 stage this change? [y/n/q] y
2251 -----------------------------------------------
2252 @@ -4,7 +4,7 @@
2261 -----------------------------------------------
2262 M numbers (change 2 of 3)
2263 stage this change? [y/n/q] q
2264 D zzz
2265 stage this deletion? [y/n] n
2266 EOF
2267 cmp -s $testroot/stdout.expected $testroot/stdout
2268 ret=$?
2269 if [ $ret -ne 0 ]; then
2270 diff -u $testroot/stdout.expected $testroot/stdout
2271 test_done "$testroot" "$ret"
2272 return 1
2275 (cd $testroot/wt && got status > $testroot/stdout)
2276 echo "MM numbers" > $testroot/stdout.expected
2277 echo "D zzz" >> $testroot/stdout.expected
2278 cmp -s $testroot/stdout.expected $testroot/stdout
2279 ret=$?
2280 if [ $ret -ne 0 ]; then
2281 diff -u $testroot/stdout.expected $testroot/stdout
2282 test_done "$testroot" "$ret"
2283 return 1
2286 (cd $testroot/wt && got diff -s > $testroot/stdout)
2288 echo "diff $commit_id $testroot/wt (staged changes)" \
2289 > $testroot/stdout.expected
2290 echo -n 'blob - ' >> $testroot/stdout.expected
2291 got tree -r $testroot/repo -i -c $commit_id \
2292 | grep 'numbers$' | cut -d' ' -f 1 \
2293 >> $testroot/stdout.expected
2294 echo -n 'blob + ' >> $testroot/stdout.expected
2295 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2296 >> $testroot/stdout.expected
2297 echo "--- numbers" >> $testroot/stdout.expected
2298 echo "+++ numbers" >> $testroot/stdout.expected
2299 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2300 echo " 1" >> $testroot/stdout.expected
2301 echo "-2" >> $testroot/stdout.expected
2302 echo "+a" >> $testroot/stdout.expected
2303 echo " 3" >> $testroot/stdout.expected
2304 echo " 4" >> $testroot/stdout.expected
2305 echo " 5" >> $testroot/stdout.expected
2306 cmp -s $testroot/stdout.expected $testroot/stdout
2307 ret=$?
2308 if [ $ret -ne 0 ]; then
2309 diff -u $testroot/stdout.expected $testroot/stdout
2311 test_done "$testroot" "$ret"
2315 test_stage_patch_incomplete_script() {
2316 local testroot=`test_init stage_incomplete_script`
2318 jot 16 > $testroot/repo/numbers
2319 echo zzz > $testroot/repo/zzz
2320 (cd $testroot/repo && git add numbers zzz)
2321 git_commit $testroot/repo -m "added files"
2322 local commit_id=`git_show_head $testroot/repo`
2324 got checkout $testroot/repo $testroot/wt > /dev/null
2325 ret=$?
2326 if [ $ret -ne 0 ]; then
2327 test_done "$testroot" "$ret"
2328 return 1
2331 sed -i '' -e 's/^2$/a/' $testroot/wt/numbers
2332 sed -i '' -e 's/^7$/b/' $testroot/wt/numbers
2333 sed -i '' -e 's/^16$/c/' $testroot/wt/numbers
2335 # stage first hunk and then stop responding; got should error out
2336 printf "y\n" > $testroot/patchscript
2337 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2338 > $testroot/stdout 2> $testroot/stderr)
2339 ret=$?
2340 if [ $ret -eq 0 ]; then
2341 echo "got stage command succeeded unexpectedly" >&2
2342 test_done "$testroot" "1"
2343 return 1
2345 cat > $testroot/stdout.expected <<EOF
2346 -----------------------------------------------
2347 @@ -1,5 +1,5 @@
2354 -----------------------------------------------
2355 M numbers (change 1 of 3)
2356 stage this change? [y/n/q] y
2357 -----------------------------------------------
2358 @@ -4,7 +4,7 @@
2367 -----------------------------------------------
2368 M numbers (change 2 of 3)
2369 EOF
2370 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2371 echo "got: invalid patch choice" > $testroot/stderr.expected
2372 cmp -s $testroot/stderr.expected $testroot/stderr
2373 ret=$?
2374 if [ $ret -ne 0 ]; then
2375 diff -u $testroot/stderr.expected $testroot/stderr
2376 test_done "$testroot" "$ret"
2377 return 1
2380 cmp -s $testroot/stdout.expected $testroot/stdout
2381 ret=$?
2382 if [ $ret -ne 0 ]; then
2383 diff -u $testroot/stdout.expected $testroot/stdout
2384 test_done "$testroot" "$ret"
2385 return 1
2388 (cd $testroot/wt && got status > $testroot/stdout)
2389 echo "M numbers" > $testroot/stdout.expected
2390 cmp -s $testroot/stdout.expected $testroot/stdout
2391 ret=$?
2392 if [ $ret -ne 0 ]; then
2393 diff -u $testroot/stdout.expected $testroot/stdout
2394 test_done "$testroot" "$ret"
2395 return 1
2398 (cd $testroot/wt && got diff -s > $testroot/stdout)
2399 echo -n > $testroot/stdout.expected
2400 cmp -s $testroot/stdout.expected $testroot/stdout
2401 ret=$?
2402 if [ $ret -ne 0 ]; then
2403 diff -u $testroot/stdout.expected $testroot/stdout
2405 test_done "$testroot" "$ret"
2409 test_stage_symlink() {
2410 local testroot=`test_init stage_symlink`
2412 (cd $testroot/repo && ln -s alpha alpha.link)
2413 (cd $testroot/repo && ln -s epsilon epsilon.link)
2414 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2415 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2416 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2417 (cd $testroot/repo && git add .)
2418 git_commit $testroot/repo -m "add symlinks"
2419 local head_commit=`git_show_head $testroot/repo`
2421 got checkout $testroot/repo $testroot/wt > /dev/null
2422 ret=$?
2423 if [ $ret -ne 0 ]; then
2424 test_done "$testroot" "$ret"
2425 return 1
2428 (cd $testroot/wt && ln -sf beta alpha.link)
2429 (cd $testroot/wt && ln -sfT gamma epsilon.link)
2430 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2431 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2432 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2433 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2434 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2435 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2436 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2437 (cd $testroot/wt && got add zeta.link > /dev/null)
2439 (cd $testroot/wt && got stage > $testroot/stdout 2> $testroot/stderr)
2440 ret=$?
2441 if [ $ret -eq 0 ]; then
2442 echo "got stage succeeded unexpectedly" >&2
2443 test_done "$testroot" 1
2444 return 1
2446 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
2447 echo "symbolic link points outside of paths under version control" \
2448 >> $testroot/stderr.expected
2449 cmp -s $testroot/stderr.expected $testroot/stderr
2450 ret=$?
2451 if [ $ret -ne 0 ]; then
2452 diff -u $testroot/stderr.expected $testroot/stderr
2453 test_done "$testroot" "$ret"
2454 return 1
2457 (cd $testroot/wt && got stage -S > $testroot/stdout)
2459 cat > $testroot/stdout.expected <<EOF
2460 M alpha.link
2461 A dotgotbar.link
2462 A dotgotfoo.link
2463 M epsilon/beta.link
2464 M epsilon.link
2465 D nonexistent.link
2466 A zeta.link
2467 EOF
2468 cmp -s $testroot/stdout.expected $testroot/stdout
2469 ret=$?
2470 if [ $ret -ne 0 ]; then
2471 diff -u $testroot/stdout.expected $testroot/stdout
2472 test_done "$testroot" "$ret"
2473 return 1
2476 rm $testroot/wt/alpha.link
2477 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2479 (cd $testroot/wt && got diff -s > $testroot/stdout)
2481 echo "diff $head_commit $testroot/wt (staged changes)" \
2482 > $testroot/stdout.expected
2483 echo -n 'blob - ' >> $testroot/stdout.expected
2484 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2485 cut -d' ' -f 1 >> $testroot/stdout.expected
2486 echo -n 'blob + ' >> $testroot/stdout.expected
2487 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2488 >> $testroot/stdout.expected
2489 echo '--- alpha.link' >> $testroot/stdout.expected
2490 echo '+++ alpha.link' >> $testroot/stdout.expected
2491 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2492 echo '-alpha' >> $testroot/stdout.expected
2493 echo '\ No newline at end of file' >> $testroot/stdout.expected
2494 echo '+beta' >> $testroot/stdout.expected
2495 echo '\ No newline at end of file' >> $testroot/stdout.expected
2496 echo 'blob - /dev/null' >> $testroot/stdout.expected
2497 echo -n 'blob + ' >> $testroot/stdout.expected
2498 (cd $testroot/wt && got stage -l dotgotbar.link) | cut -d' ' -f 1 \
2499 >> $testroot/stdout.expected
2500 echo '--- /dev/null' >> $testroot/stdout.expected
2501 echo '+++ dotgotbar.link' >> $testroot/stdout.expected
2502 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2503 echo '+.got/bar' >> $testroot/stdout.expected
2504 echo '\ No newline at end of file' >> $testroot/stdout.expected
2505 echo 'blob - /dev/null' >> $testroot/stdout.expected
2506 echo -n 'blob + ' >> $testroot/stdout.expected
2507 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2508 >> $testroot/stdout.expected
2509 echo '--- /dev/null' >> $testroot/stdout.expected
2510 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2511 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2512 echo '+this is regular file foo' >> $testroot/stdout.expected
2513 echo -n 'blob - ' >> $testroot/stdout.expected
2514 got tree -r $testroot/repo -i epsilon | grep 'beta.link@ -> ../beta$' | \
2515 cut -d' ' -f 1 >> $testroot/stdout.expected
2516 echo -n 'blob + ' >> $testroot/stdout.expected
2517 (cd $testroot/wt && got stage -l epsilon/beta.link) | cut -d' ' -f 1 \
2518 >> $testroot/stdout.expected
2519 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
2520 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
2521 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2522 echo '-../beta' >> $testroot/stdout.expected
2523 echo '\ No newline at end of file' >> $testroot/stdout.expected
2524 echo '+../gamma/delta' >> $testroot/stdout.expected
2525 echo '\ No newline at end of file' >> $testroot/stdout.expected
2526 echo -n 'blob - ' >> $testroot/stdout.expected
2527 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2528 cut -d' ' -f 1 >> $testroot/stdout.expected
2529 echo -n 'blob + ' >> $testroot/stdout.expected
2530 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2531 >> $testroot/stdout.expected
2532 echo '--- epsilon.link' >> $testroot/stdout.expected
2533 echo '+++ epsilon.link' >> $testroot/stdout.expected
2534 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2535 echo '-epsilon' >> $testroot/stdout.expected
2536 echo '\ No newline at end of file' >> $testroot/stdout.expected
2537 echo '+gamma' >> $testroot/stdout.expected
2538 echo '\ No newline at end of file' >> $testroot/stdout.expected
2539 echo -n 'blob - ' >> $testroot/stdout.expected
2540 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2541 cut -d' ' -f 1 >> $testroot/stdout.expected
2542 echo 'blob + /dev/null' >> $testroot/stdout.expected
2543 echo '--- nonexistent.link' >> $testroot/stdout.expected
2544 echo '+++ /dev/null' >> $testroot/stdout.expected
2545 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2546 echo '-nonexistent' >> $testroot/stdout.expected
2547 echo '\ No newline at end of file' >> $testroot/stdout.expected
2548 echo 'blob - /dev/null' >> $testroot/stdout.expected
2549 echo -n 'blob + ' >> $testroot/stdout.expected
2550 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2551 >> $testroot/stdout.expected
2552 echo '--- /dev/null' >> $testroot/stdout.expected
2553 echo '+++ zeta.link' >> $testroot/stdout.expected
2554 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2555 echo '+gamma/delta' >> $testroot/stdout.expected
2556 echo '\ No newline at end of file' >> $testroot/stdout.expected
2558 cmp -s $testroot/stdout.expected $testroot/stdout
2559 ret=$?
2560 if [ $ret -ne 0 ]; then
2561 diff -u $testroot/stdout.expected $testroot/stdout
2562 test_done "$testroot" "$ret"
2563 return 1
2566 (cd $testroot/wt && got commit -m "staged symlink" \
2567 > $testroot/stdout)
2568 ret=$?
2569 if [ $ret -ne 0 ]; then
2570 echo "got commit command failed unexpectedly" >&2
2571 test_done "$testroot" "1"
2572 return 1
2575 local commit_id=`git_show_head $testroot/repo`
2576 echo "A dotgotbar.link" > $testroot/stdout.expected
2577 echo "A dotgotfoo.link" >> $testroot/stdout.expected
2578 echo "A zeta.link" >> $testroot/stdout.expected
2579 echo "M alpha.link" >> $testroot/stdout.expected
2580 echo "M epsilon/beta.link" >> $testroot/stdout.expected
2581 echo "M epsilon.link" >> $testroot/stdout.expected
2582 echo "D nonexistent.link" >> $testroot/stdout.expected
2583 echo "Created commit $commit_id" >> $testroot/stdout.expected
2584 cmp -s $testroot/stdout.expected $testroot/stdout
2585 ret=$?
2586 if [ $ret -ne 0 ]; then
2587 diff -u $testroot/stdout.expected $testroot/stdout
2588 test_done "$testroot" "$ret"
2589 return 1
2592 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2593 ret=$?
2594 if [ $ret -ne 0 ]; then
2595 echo "got tree command failed unexpectedly" >&2
2596 test_done "$testroot" "1"
2597 return 1
2600 cat > $testroot/stdout.expected <<EOF
2601 alpha
2602 alpha.link@ -> beta
2603 beta
2604 dotgotbar.link@ -> .got/bar
2605 dotgotfoo.link
2606 epsilon/
2607 epsilon.link@ -> gamma
2608 gamma/
2609 passwd.link@ -> /etc/passwd
2610 zeta.link@ -> gamma/delta
2611 EOF
2612 cmp -s $testroot/stdout.expected $testroot/stdout
2613 ret=$?
2614 if [ $ret -ne 0 ]; then
2615 diff -u $testroot/stdout.expected $testroot/stdout
2616 return 1
2619 if [ -h $testroot/wt/alpha.link ]; then
2620 echo "alpha.link is a symlink"
2621 test_done "$testroot" "1"
2622 return 1
2625 echo 'this is regular file alpha.link' > $testroot/content.expected
2626 cp $testroot/wt/alpha.link $testroot/content
2627 cmp -s $testroot/content.expected $testroot/content
2628 ret=$?
2629 if [ $ret -ne 0 ]; then
2630 diff -u $testroot/content.expected $testroot/content
2631 test_done "$testroot" "$ret"
2632 return 1
2635 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2636 echo "dotgotbar.link is not a symlink"
2637 test_done "$testroot" "1"
2638 return 1
2640 (cd $testroot/wt && got update > /dev/null)
2641 if [ -h $testroot/wt/dotgotbar.link ]; then
2642 echo "dotgotbar.link is a symlink"
2643 test_done "$testroot" "1"
2644 return 1
2646 echo -n ".got/bar" > $testroot/content.expected
2647 cp $testroot/wt/dotgotbar.link $testroot/content
2648 cmp -s $testroot/content.expected $testroot/content
2649 ret=$?
2650 if [ $ret -ne 0 ]; then
2651 diff -u $testroot/content.expected $testroot/content
2652 test_done "$testroot" "$ret"
2653 return 1
2656 if [ -h $testroot/wt/dotgotfoo.link ]; then
2657 echo "dotgotfoo.link is a symlink"
2658 test_done "$testroot" "1"
2659 return 1
2661 echo "this is regular file foo" > $testroot/content.expected
2662 cp $testroot/wt/dotgotfoo.link $testroot/content
2663 cmp -s $testroot/content.expected $testroot/content
2664 ret=$?
2665 if [ $ret -ne 0 ]; then
2666 diff -u $testroot/content.expected $testroot/content
2667 test_done "$testroot" "$ret"
2668 return 1
2671 if ! [ -h $testroot/wt/epsilon.link ]; then
2672 echo "epsilon.link is not a symlink"
2673 test_done "$testroot" "1"
2674 return 1
2677 readlink $testroot/wt/epsilon.link > $testroot/stdout
2678 echo "gamma" > $testroot/stdout.expected
2679 cmp -s $testroot/stdout.expected $testroot/stdout
2680 ret=$?
2681 if [ $ret -ne 0 ]; then
2682 diff -u $testroot/stdout.expected $testroot/stdout
2683 test_done "$testroot" "$ret"
2684 return 1
2687 if [ -h $testroot/wt/passwd.link ]; then
2688 echo "passwd.link is a symlink"
2689 test_done "$testroot" "1"
2690 return 1
2692 echo -n "/etc/passwd" > $testroot/content.expected
2693 cp $testroot/wt/passwd.link $testroot/content
2694 cmp -s $testroot/content.expected $testroot/content
2695 ret=$?
2696 if [ $ret -ne 0 ]; then
2697 diff -u $testroot/content.expected $testroot/content
2698 test_done "$testroot" "$ret"
2699 return 1
2702 if ! [ -h $testroot/wt/zeta.link ]; then
2703 echo "zeta.link is not a symlink"
2704 test_done "$testroot" "1"
2705 return 1
2708 readlink $testroot/wt/zeta.link > $testroot/stdout
2709 echo "gamma/delta" > $testroot/stdout.expected
2710 cmp -s $testroot/stdout.expected $testroot/stdout
2711 ret=$?
2712 if [ $ret -ne 0 ]; then
2713 diff -u $testroot/stdout.expected $testroot/stdout
2714 test_done "$testroot" "$ret"
2715 return 1
2718 test_done "$testroot" "0"
2721 test_stage_patch_symlink() {
2722 local testroot=`test_init stage_patch_symlink`
2724 (cd $testroot/repo && ln -s alpha alpha.link)
2725 (cd $testroot/repo && ln -s epsilon epsilon.link)
2726 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2727 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2728 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2729 (cd $testroot/repo && git add .)
2730 git_commit $testroot/repo -m "add symlinks"
2731 local head_commit=`git_show_head $testroot/repo`
2733 got checkout $testroot/repo $testroot/wt > /dev/null
2734 ret=$?
2735 if [ $ret -ne 0 ]; then
2736 test_done "$testroot" "$ret"
2737 return 1
2740 (cd $testroot/wt && ln -sf beta alpha.link)
2741 (cd $testroot/wt && ln -sfT gamma epsilon.link)
2742 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2743 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2744 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2745 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2746 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2747 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2748 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2749 (cd $testroot/wt && got add zeta.link > /dev/null)
2751 printf "y\nn\ny\nn\ny\ny\ny" > $testroot/patchscript
2752 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2753 > $testroot/stdout)
2755 cat > $testroot/stdout.expected <<EOF
2756 -----------------------------------------------
2757 @@ -1 +1 @@
2758 -alpha
2759 \ No newline at end of file
2760 +beta
2761 \ No newline at end of file
2762 -----------------------------------------------
2763 M alpha.link (change 1 of 1)
2764 stage this change? [y/n/q] y
2765 A dotgotbar.link
2766 stage this addition? [y/n] n
2767 A dotgotfoo.link
2768 stage this addition? [y/n] y
2769 -----------------------------------------------
2770 @@ -1 +1 @@
2771 -../beta
2772 \ No newline at end of file
2773 +../gamma/delta
2774 \ No newline at end of file
2775 -----------------------------------------------
2776 M epsilon/beta.link (change 1 of 1)
2777 stage this change? [y/n/q] n
2778 -----------------------------------------------
2779 @@ -1 +1 @@
2780 -epsilon
2781 \ No newline at end of file
2782 +gamma
2783 \ No newline at end of file
2784 -----------------------------------------------
2785 M epsilon.link (change 1 of 1)
2786 stage this change? [y/n/q] y
2787 D nonexistent.link
2788 stage this deletion? [y/n] y
2789 A zeta.link
2790 stage this addition? [y/n] y
2791 EOF
2792 cmp -s $testroot/stdout.expected $testroot/stdout
2793 ret=$?
2794 if [ $ret -ne 0 ]; then
2795 diff -u $testroot/stdout.expected $testroot/stdout
2796 test_done "$testroot" "$ret"
2797 return 1
2800 rm $testroot/wt/alpha.link
2801 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2803 (cd $testroot/wt && got diff -s > $testroot/stdout)
2805 echo "diff $head_commit $testroot/wt (staged changes)" \
2806 > $testroot/stdout.expected
2807 echo -n 'blob - ' >> $testroot/stdout.expected
2808 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2809 cut -d' ' -f 1 >> $testroot/stdout.expected
2810 echo -n 'blob + ' >> $testroot/stdout.expected
2811 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2812 >> $testroot/stdout.expected
2813 echo '--- alpha.link' >> $testroot/stdout.expected
2814 echo '+++ alpha.link' >> $testroot/stdout.expected
2815 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2816 echo '-alpha' >> $testroot/stdout.expected
2817 echo '\ No newline at end of file' >> $testroot/stdout.expected
2818 echo '+beta' >> $testroot/stdout.expected
2819 echo '\ No newline at end of file' >> $testroot/stdout.expected
2820 echo 'blob - /dev/null' >> $testroot/stdout.expected
2821 echo -n 'blob + ' >> $testroot/stdout.expected
2822 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2823 >> $testroot/stdout.expected
2824 echo '--- /dev/null' >> $testroot/stdout.expected
2825 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2826 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2827 echo '+this is regular file foo' >> $testroot/stdout.expected
2828 echo -n 'blob - ' >> $testroot/stdout.expected
2829 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2830 cut -d' ' -f 1 >> $testroot/stdout.expected
2831 echo -n 'blob + ' >> $testroot/stdout.expected
2832 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2833 >> $testroot/stdout.expected
2834 echo '--- epsilon.link' >> $testroot/stdout.expected
2835 echo '+++ epsilon.link' >> $testroot/stdout.expected
2836 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2837 echo '-epsilon' >> $testroot/stdout.expected
2838 echo '\ No newline at end of file' >> $testroot/stdout.expected
2839 echo '+gamma' >> $testroot/stdout.expected
2840 echo '\ No newline at end of file' >> $testroot/stdout.expected
2841 echo -n 'blob - ' >> $testroot/stdout.expected
2842 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2843 cut -d' ' -f 1 >> $testroot/stdout.expected
2844 echo 'blob + /dev/null' >> $testroot/stdout.expected
2845 echo '--- nonexistent.link' >> $testroot/stdout.expected
2846 echo '+++ /dev/null' >> $testroot/stdout.expected
2847 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2848 echo '-nonexistent' >> $testroot/stdout.expected
2849 echo '\ No newline at end of file' >> $testroot/stdout.expected
2850 echo 'blob - /dev/null' >> $testroot/stdout.expected
2851 echo -n 'blob + ' >> $testroot/stdout.expected
2852 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2853 >> $testroot/stdout.expected
2854 echo '--- /dev/null' >> $testroot/stdout.expected
2855 echo '+++ zeta.link' >> $testroot/stdout.expected
2856 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2857 echo '+gamma/delta' >> $testroot/stdout.expected
2858 echo '\ No newline at end of file' >> $testroot/stdout.expected
2860 cmp -s $testroot/stdout.expected $testroot/stdout
2861 ret=$?
2862 if [ $ret -ne 0 ]; then
2863 diff -u $testroot/stdout.expected $testroot/stdout
2864 test_done "$testroot" "$ret"
2865 return 1
2868 (cd $testroot/wt && got commit -m "staged symlink" \
2869 > $testroot/stdout)
2870 ret=$?
2871 if [ $ret -ne 0 ]; then
2872 echo "got commit command failed unexpectedly" >&2
2873 test_done "$testroot" "1"
2874 return 1
2877 local commit_id=`git_show_head $testroot/repo`
2878 echo "A dotgotfoo.link" > $testroot/stdout.expected
2879 echo "A zeta.link" >> $testroot/stdout.expected
2880 echo "M alpha.link" >> $testroot/stdout.expected
2881 echo "M epsilon.link" >> $testroot/stdout.expected
2882 echo "D nonexistent.link" >> $testroot/stdout.expected
2883 echo "Created commit $commit_id" >> $testroot/stdout.expected
2884 cmp -s $testroot/stdout.expected $testroot/stdout
2885 ret=$?
2886 if [ $ret -ne 0 ]; then
2887 diff -u $testroot/stdout.expected $testroot/stdout
2888 test_done "$testroot" "$ret"
2889 return 1
2892 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2893 ret=$?
2894 if [ $ret -ne 0 ]; then
2895 echo "got tree command failed unexpectedly" >&2
2896 test_done "$testroot" "1"
2897 return 1
2900 cat > $testroot/stdout.expected <<EOF
2901 alpha
2902 alpha.link@ -> beta
2903 beta
2904 dotgotfoo.link
2905 epsilon/
2906 epsilon.link@ -> gamma
2907 gamma/
2908 passwd.link@ -> /etc/passwd
2909 zeta.link@ -> gamma/delta
2910 EOF
2911 cmp -s $testroot/stdout.expected $testroot/stdout
2912 ret=$?
2913 if [ $ret -ne 0 ]; then
2914 diff -u $testroot/stdout.expected $testroot/stdout
2915 return 1
2918 if [ -h $testroot/wt/alpha.link ]; then
2919 echo "alpha.link is a symlink"
2920 test_done "$testroot" "1"
2921 return 1
2924 echo 'this is regular file alpha.link' > $testroot/content.expected
2925 cp $testroot/wt/alpha.link $testroot/content
2926 cmp -s $testroot/content.expected $testroot/content
2927 ret=$?
2928 if [ $ret -ne 0 ]; then
2929 diff -u $testroot/content.expected $testroot/content
2930 test_done "$testroot" "$ret"
2931 return 1
2934 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2935 echo "dotgotbar.link is not a symlink"
2936 test_done "$testroot" "1"
2937 return 1
2939 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
2940 echo ".got/bar" > $testroot/stdout.expected
2941 cmp -s $testroot/stdout.expected $testroot/stdout
2942 ret=$?
2943 if [ $ret -ne 0 ]; then
2944 diff -u $testroot/stdout.expected $testroot/stdout
2945 test_done "$testroot" "$ret"
2946 return 1
2949 if [ -h $testroot/wt/dotgotfoo.link ]; then
2950 echo "dotgotfoo.link is a symlink"
2951 test_done "$testroot" "1"
2952 return 1
2954 echo "this is regular file foo" > $testroot/content.expected
2955 cp $testroot/wt/dotgotfoo.link $testroot/content
2956 cmp -s $testroot/content.expected $testroot/content
2957 ret=$?
2958 if [ $ret -ne 0 ]; then
2959 diff -u $testroot/content.expected $testroot/content
2960 test_done "$testroot" "$ret"
2961 return 1
2964 if ! [ -h $testroot/wt/epsilon.link ]; then
2965 echo "epsilon.link is not a symlink"
2966 test_done "$testroot" "1"
2967 return 1
2970 readlink $testroot/wt/epsilon.link > $testroot/stdout
2971 echo "gamma" > $testroot/stdout.expected
2972 cmp -s $testroot/stdout.expected $testroot/stdout
2973 ret=$?
2974 if [ $ret -ne 0 ]; then
2975 diff -u $testroot/stdout.expected $testroot/stdout
2976 test_done "$testroot" "$ret"
2977 return 1
2980 if [ -h $testroot/wt/passwd.link ]; then
2981 echo "passwd.link is a symlink"
2982 test_done "$testroot" "1"
2983 return 1
2985 echo -n "/etc/passwd" > $testroot/content.expected
2986 cp $testroot/wt/passwd.link $testroot/content
2987 cmp -s $testroot/content.expected $testroot/content
2988 ret=$?
2989 if [ $ret -ne 0 ]; then
2990 diff -u $testroot/content.expected $testroot/content
2991 test_done "$testroot" "$ret"
2992 return 1
2995 if ! [ -h $testroot/wt/zeta.link ]; then
2996 echo "zeta.link is not a symlink"
2997 test_done "$testroot" "1"
2998 return 1
3001 readlink $testroot/wt/zeta.link > $testroot/stdout
3002 echo "gamma/delta" > $testroot/stdout.expected
3003 cmp -s $testroot/stdout.expected $testroot/stdout
3004 ret=$?
3005 if [ $ret -ne 0 ]; then
3006 diff -u $testroot/stdout.expected $testroot/stdout
3007 test_done "$testroot" "$ret"
3008 return 1
3011 test_done "$testroot" "0"
3014 test_parseargs "$@"
3015 run_test test_stage_basic
3016 run_test test_stage_no_changes
3017 run_test test_stage_unversioned
3018 run_test test_stage_nonexistent
3019 run_test test_stage_list
3020 run_test test_stage_conflict
3021 run_test test_stage_out_of_date
3022 run_test test_double_stage
3023 run_test test_stage_status
3024 run_test test_stage_add_already_staged_file
3025 run_test test_stage_rm_already_staged_file
3026 run_test test_stage_revert
3027 run_test test_stage_diff
3028 run_test test_stage_histedit
3029 run_test test_stage_rebase
3030 run_test test_stage_update
3031 run_test test_stage_commit_non_staged
3032 run_test test_stage_commit_out_of_date
3033 run_test test_stage_commit
3034 run_test test_stage_patch
3035 run_test test_stage_patch_twice
3036 run_test test_stage_patch_added
3037 run_test test_stage_patch_added_twice
3038 run_test test_stage_patch_removed
3039 run_test test_stage_patch_removed_twice
3040 run_test test_stage_patch_reversed
3041 run_test test_stage_patch_quit
3042 run_test test_stage_patch_incomplete_script
3043 run_test test_stage_symlink
3044 run_test test_stage_patch_symlink