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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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 commit " >> $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" != "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" = "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" = "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" = "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" = "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" != "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" != "0" ]; then
2149 diff -u $testroot/stdout.expected $testroot/stdout
2151 test_done "$testroot" "$ret"
2154 test_stage_patch_quit() {
2155 local testroot=`test_init stage_patch_quit`
2157 jot 16 > $testroot/repo/numbers
2158 echo zzz > $testroot/repo/zzz
2159 (cd $testroot/repo && git add numbers zzz)
2160 git_commit $testroot/repo -m "added files"
2161 local commit_id=`git_show_head $testroot/repo`
2163 got checkout $testroot/repo $testroot/wt > /dev/null
2164 ret="$?"
2165 if [ "$ret" != "0" ]; then
2166 test_done "$testroot" "$ret"
2167 return 1
2170 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2171 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2172 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2173 (cd $testroot/wt && got rm zzz > /dev/null)
2175 # stage first hunk and quit; and don't pass a path argument to
2176 # ensure that we don't skip asking about the 'zzz' file after 'quit'
2177 printf "y\nq\nn\n" > $testroot/patchscript
2178 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2179 > $testroot/stdout)
2180 ret="$?"
2181 if [ "$ret" != "0" ]; then
2182 echo "got stage command failed unexpectedly" >&2
2183 test_done "$testroot" "1"
2184 return 1
2186 cat > $testroot/stdout.expected <<EOF
2187 -----------------------------------------------
2188 @@ -1,5 +1,5 @@
2195 -----------------------------------------------
2196 M numbers (change 1 of 3)
2197 stage this change? [y/n/q] y
2198 -----------------------------------------------
2199 @@ -4,7 +4,7 @@
2208 -----------------------------------------------
2209 M numbers (change 2 of 3)
2210 stage this change? [y/n/q] q
2211 D zzz
2212 stage this deletion? [y/n] n
2213 EOF
2214 cmp -s $testroot/stdout.expected $testroot/stdout
2215 ret="$?"
2216 if [ "$ret" != "0" ]; then
2217 diff -u $testroot/stdout.expected $testroot/stdout
2218 test_done "$testroot" "$ret"
2219 return 1
2222 (cd $testroot/wt && got status > $testroot/stdout)
2223 echo "MM numbers" > $testroot/stdout.expected
2224 echo "D zzz" >> $testroot/stdout.expected
2225 cmp -s $testroot/stdout.expected $testroot/stdout
2226 ret="$?"
2227 if [ "$ret" != "0" ]; then
2228 diff -u $testroot/stdout.expected $testroot/stdout
2229 test_done "$testroot" "$ret"
2230 return 1
2233 (cd $testroot/wt && got diff -s > $testroot/stdout)
2235 echo "diff $commit_id $testroot/wt (staged changes)" \
2236 > $testroot/stdout.expected
2237 echo -n 'blob - ' >> $testroot/stdout.expected
2238 got tree -r $testroot/repo -i -c $commit_id \
2239 | grep 'numbers$' | cut -d' ' -f 1 \
2240 >> $testroot/stdout.expected
2241 echo -n 'blob + ' >> $testroot/stdout.expected
2242 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
2243 >> $testroot/stdout.expected
2244 echo "--- numbers" >> $testroot/stdout.expected
2245 echo "+++ numbers" >> $testroot/stdout.expected
2246 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
2247 echo " 1" >> $testroot/stdout.expected
2248 echo "-2" >> $testroot/stdout.expected
2249 echo "+a" >> $testroot/stdout.expected
2250 echo " 3" >> $testroot/stdout.expected
2251 echo " 4" >> $testroot/stdout.expected
2252 echo " 5" >> $testroot/stdout.expected
2253 cmp -s $testroot/stdout.expected $testroot/stdout
2254 ret="$?"
2255 if [ "$ret" != "0" ]; then
2256 diff -u $testroot/stdout.expected $testroot/stdout
2258 test_done "$testroot" "$ret"
2262 test_stage_patch_incomplete_script() {
2263 local testroot=`test_init stage_incomplete_script`
2265 jot 16 > $testroot/repo/numbers
2266 echo zzz > $testroot/repo/zzz
2267 (cd $testroot/repo && git add numbers zzz)
2268 git_commit $testroot/repo -m "added files"
2269 local commit_id=`git_show_head $testroot/repo`
2271 got checkout $testroot/repo $testroot/wt > /dev/null
2272 ret="$?"
2273 if [ "$ret" != "0" ]; then
2274 test_done "$testroot" "$ret"
2275 return 1
2278 sed -i -e 's/^2$/a/' $testroot/wt/numbers
2279 sed -i -e 's/^7$/b/' $testroot/wt/numbers
2280 sed -i -e 's/^16$/c/' $testroot/wt/numbers
2282 # stage first hunk and then stop responding; got should error out
2283 printf "y\n" > $testroot/patchscript
2284 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2285 > $testroot/stdout 2> $testroot/stderr)
2286 ret="$?"
2287 if [ "$ret" = "0" ]; then
2288 echo "got stage command succeeded unexpectedly" >&2
2289 test_done "$testroot" "1"
2290 return 1
2292 cat > $testroot/stdout.expected <<EOF
2293 -----------------------------------------------
2294 @@ -1,5 +1,5 @@
2301 -----------------------------------------------
2302 M numbers (change 1 of 3)
2303 stage this change? [y/n/q] y
2304 -----------------------------------------------
2305 @@ -4,7 +4,7 @@
2314 -----------------------------------------------
2315 M numbers (change 2 of 3)
2316 EOF
2317 echo -n "stage this change? [y/n/q] " >> $testroot/stdout.expected
2318 echo "got: invalid patch choice" > $testroot/stderr.expected
2319 cmp -s $testroot/stderr.expected $testroot/stderr
2320 ret="$?"
2321 if [ "$ret" != "0" ]; then
2322 diff -u $testroot/stderr.expected $testroot/stderr
2323 test_done "$testroot" "$ret"
2324 return 1
2327 cmp -s $testroot/stdout.expected $testroot/stdout
2328 ret="$?"
2329 if [ "$ret" != "0" ]; then
2330 diff -u $testroot/stdout.expected $testroot/stdout
2331 test_done "$testroot" "$ret"
2332 return 1
2335 (cd $testroot/wt && got status > $testroot/stdout)
2336 echo "M numbers" > $testroot/stdout.expected
2337 cmp -s $testroot/stdout.expected $testroot/stdout
2338 ret="$?"
2339 if [ "$ret" != "0" ]; then
2340 diff -u $testroot/stdout.expected $testroot/stdout
2341 test_done "$testroot" "$ret"
2342 return 1
2345 (cd $testroot/wt && got diff -s > $testroot/stdout)
2346 echo -n > $testroot/stdout.expected
2347 cmp -s $testroot/stdout.expected $testroot/stdout
2348 ret="$?"
2349 if [ "$ret" != "0" ]; then
2350 diff -u $testroot/stdout.expected $testroot/stdout
2352 test_done "$testroot" "$ret"
2356 test_stage_symlink() {
2357 local testroot=`test_init stage_symlink`
2359 (cd $testroot/repo && ln -s alpha alpha.link)
2360 (cd $testroot/repo && ln -s epsilon epsilon.link)
2361 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2362 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2363 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2364 (cd $testroot/repo && git add .)
2365 git_commit $testroot/repo -m "add symlinks"
2366 local head_commit=`git_show_head $testroot/repo`
2368 got checkout $testroot/repo $testroot/wt > /dev/null
2369 ret="$?"
2370 if [ "$ret" != "0" ]; then
2371 test_done "$testroot" "$ret"
2372 return 1
2375 (cd $testroot/wt && ln -sf beta alpha.link)
2376 (cd $testroot/wt && ln -sfh gamma epsilon.link)
2377 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2378 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2379 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2380 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2381 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2382 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2383 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2384 (cd $testroot/wt && got add zeta.link > /dev/null)
2386 (cd $testroot/wt && got stage > $testroot/stdout 2> $testroot/stderr)
2387 ret="$?"
2388 if [ "$ret" = "0" ]; then
2389 echo "got stage succeeded unexpectedly" >&2
2390 test_done "$testroot" "$ret"
2391 return 1
2393 echo -n "got: $testroot/wt/dotgotbar.link: " > $testroot/stderr.expected
2394 echo "symbolic link points outside of paths under version control" \
2395 >> $testroot/stderr.expected
2396 cmp -s $testroot/stderr.expected $testroot/stderr
2397 ret="$?"
2398 if [ "$ret" != "0" ]; then
2399 diff -u $testroot/stderr.expected $testroot/stderr
2400 test_done "$testroot" "$ret"
2401 return 1
2404 (cd $testroot/wt && got stage -S > $testroot/stdout)
2406 cat > $testroot/stdout.expected <<EOF
2407 M alpha.link
2408 A dotgotbar.link
2409 A dotgotfoo.link
2410 M epsilon/beta.link
2411 M epsilon.link
2412 D nonexistent.link
2413 A zeta.link
2414 EOF
2415 cmp -s $testroot/stdout.expected $testroot/stdout
2416 ret="$?"
2417 if [ "$ret" != "0" ]; then
2418 diff -u $testroot/stdout.expected $testroot/stdout
2419 test_done "$testroot" "$ret"
2420 return 1
2423 rm $testroot/wt/alpha.link
2424 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2426 (cd $testroot/wt && got diff -s > $testroot/stdout)
2428 echo "diff $head_commit $testroot/wt (staged changes)" \
2429 > $testroot/stdout.expected
2430 echo -n 'blob - ' >> $testroot/stdout.expected
2431 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2432 cut -d' ' -f 1 >> $testroot/stdout.expected
2433 echo -n 'blob + ' >> $testroot/stdout.expected
2434 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2435 >> $testroot/stdout.expected
2436 echo '--- alpha.link' >> $testroot/stdout.expected
2437 echo '+++ alpha.link' >> $testroot/stdout.expected
2438 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2439 echo '-alpha' >> $testroot/stdout.expected
2440 echo '\ No newline at end of file' >> $testroot/stdout.expected
2441 echo '+beta' >> $testroot/stdout.expected
2442 echo '\ No newline at end of file' >> $testroot/stdout.expected
2443 echo 'blob - /dev/null' >> $testroot/stdout.expected
2444 echo -n 'blob + ' >> $testroot/stdout.expected
2445 (cd $testroot/wt && got stage -l dotgotbar.link) | cut -d' ' -f 1 \
2446 >> $testroot/stdout.expected
2447 echo '--- /dev/null' >> $testroot/stdout.expected
2448 echo '+++ dotgotbar.link' >> $testroot/stdout.expected
2449 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2450 echo '+.got/bar' >> $testroot/stdout.expected
2451 echo '\ No newline at end of file' >> $testroot/stdout.expected
2452 echo 'blob - /dev/null' >> $testroot/stdout.expected
2453 echo -n 'blob + ' >> $testroot/stdout.expected
2454 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2455 >> $testroot/stdout.expected
2456 echo '--- /dev/null' >> $testroot/stdout.expected
2457 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2458 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2459 echo '+this is regular file foo' >> $testroot/stdout.expected
2460 echo -n 'blob - ' >> $testroot/stdout.expected
2461 got tree -r $testroot/repo -i epsilon | grep 'beta.link@ -> ../beta$' | \
2462 cut -d' ' -f 1 >> $testroot/stdout.expected
2463 echo -n 'blob + ' >> $testroot/stdout.expected
2464 (cd $testroot/wt && got stage -l epsilon/beta.link) | cut -d' ' -f 1 \
2465 >> $testroot/stdout.expected
2466 echo '--- epsilon/beta.link' >> $testroot/stdout.expected
2467 echo '+++ epsilon/beta.link' >> $testroot/stdout.expected
2468 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2469 echo '-../beta' >> $testroot/stdout.expected
2470 echo '\ No newline at end of file' >> $testroot/stdout.expected
2471 echo '+../gamma/delta' >> $testroot/stdout.expected
2472 echo '\ No newline at end of file' >> $testroot/stdout.expected
2473 echo -n 'blob - ' >> $testroot/stdout.expected
2474 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2475 cut -d' ' -f 1 >> $testroot/stdout.expected
2476 echo -n 'blob + ' >> $testroot/stdout.expected
2477 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2478 >> $testroot/stdout.expected
2479 echo '--- epsilon.link' >> $testroot/stdout.expected
2480 echo '+++ epsilon.link' >> $testroot/stdout.expected
2481 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2482 echo '-epsilon' >> $testroot/stdout.expected
2483 echo '\ No newline at end of file' >> $testroot/stdout.expected
2484 echo '+gamma' >> $testroot/stdout.expected
2485 echo '\ No newline at end of file' >> $testroot/stdout.expected
2486 echo -n 'blob - ' >> $testroot/stdout.expected
2487 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2488 cut -d' ' -f 1 >> $testroot/stdout.expected
2489 echo 'blob + /dev/null' >> $testroot/stdout.expected
2490 echo '--- nonexistent.link' >> $testroot/stdout.expected
2491 echo '+++ /dev/null' >> $testroot/stdout.expected
2492 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2493 echo '-nonexistent' >> $testroot/stdout.expected
2494 echo '\ No newline at end of file' >> $testroot/stdout.expected
2495 echo 'blob - /dev/null' >> $testroot/stdout.expected
2496 echo -n 'blob + ' >> $testroot/stdout.expected
2497 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2498 >> $testroot/stdout.expected
2499 echo '--- /dev/null' >> $testroot/stdout.expected
2500 echo '+++ zeta.link' >> $testroot/stdout.expected
2501 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2502 echo '+gamma/delta' >> $testroot/stdout.expected
2503 echo '\ No newline at end of file' >> $testroot/stdout.expected
2505 cmp -s $testroot/stdout.expected $testroot/stdout
2506 ret="$?"
2507 if [ "$ret" != "0" ]; then
2508 diff -u $testroot/stdout.expected $testroot/stdout
2509 test_done "$testroot" "$ret"
2510 return 1
2513 (cd $testroot/wt && got commit -m "staged symlink" \
2514 > $testroot/stdout)
2515 ret="$?"
2516 if [ "$ret" != "0" ]; then
2517 echo "got commit command failed unexpectedly" >&2
2518 test_done "$testroot" "1"
2519 return 1
2522 local commit_id=`git_show_head $testroot/repo`
2523 echo "A dotgotbar.link" > $testroot/stdout.expected
2524 echo "A dotgotfoo.link" >> $testroot/stdout.expected
2525 echo "A zeta.link" >> $testroot/stdout.expected
2526 echo "M alpha.link" >> $testroot/stdout.expected
2527 echo "M epsilon/beta.link" >> $testroot/stdout.expected
2528 echo "M epsilon.link" >> $testroot/stdout.expected
2529 echo "D nonexistent.link" >> $testroot/stdout.expected
2530 echo "Created commit $commit_id" >> $testroot/stdout.expected
2531 cmp -s $testroot/stdout.expected $testroot/stdout
2532 ret="$?"
2533 if [ "$ret" != "0" ]; then
2534 diff -u $testroot/stdout.expected $testroot/stdout
2535 test_done "$testroot" "$ret"
2536 return 1
2539 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2540 ret="$?"
2541 if [ "$ret" != "0" ]; then
2542 echo "got tree command failed unexpectedly" >&2
2543 test_done "$testroot" "1"
2544 return 1
2547 cat > $testroot/stdout.expected <<EOF
2548 alpha
2549 alpha.link@ -> beta
2550 beta
2551 dotgotbar.link@ -> .got/bar
2552 dotgotfoo.link
2553 epsilon/
2554 epsilon.link@ -> gamma
2555 gamma/
2556 passwd.link@ -> /etc/passwd
2557 zeta.link@ -> gamma/delta
2558 EOF
2559 cmp -s $testroot/stdout.expected $testroot/stdout
2560 ret="$?"
2561 if [ "$ret" != "0" ]; then
2562 diff -u $testroot/stdout.expected $testroot/stdout
2563 return 1
2566 if [ -h $testroot/wt/alpha.link ]; then
2567 echo "alpha.link is a symlink"
2568 test_done "$testroot" "1"
2569 return 1
2572 echo 'this is regular file alpha.link' > $testroot/content.expected
2573 cp $testroot/wt/alpha.link $testroot/content
2574 cmp -s $testroot/content.expected $testroot/content
2575 ret="$?"
2576 if [ "$ret" != "0" ]; then
2577 diff -u $testroot/content.expected $testroot/content
2578 test_done "$testroot" "$ret"
2579 return 1
2582 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2583 echo "dotgotbar.link is not a symlink"
2584 test_done "$testroot" "1"
2585 return 1
2587 (cd $testroot/wt && got update > /dev/null)
2588 if [ -h $testroot/wt/dotgotbar.link ]; then
2589 echo "dotgotbar.link is a symlink"
2590 test_done "$testroot" "1"
2591 return 1
2593 echo -n ".got/bar" > $testroot/content.expected
2594 cp $testroot/wt/dotgotbar.link $testroot/content
2595 cmp -s $testroot/content.expected $testroot/content
2596 ret="$?"
2597 if [ "$ret" != "0" ]; then
2598 diff -u $testroot/content.expected $testroot/content
2599 test_done "$testroot" "$ret"
2600 return 1
2603 if [ -h $testroot/wt/dotgotfoo.link ]; then
2604 echo "dotgotfoo.link is a symlink"
2605 test_done "$testroot" "1"
2606 return 1
2608 echo "this is regular file foo" > $testroot/content.expected
2609 cp $testroot/wt/dotgotfoo.link $testroot/content
2610 cmp -s $testroot/content.expected $testroot/content
2611 ret="$?"
2612 if [ "$ret" != "0" ]; then
2613 diff -u $testroot/content.expected $testroot/content
2614 test_done "$testroot" "$ret"
2615 return 1
2618 if ! [ -h $testroot/wt/epsilon.link ]; then
2619 echo "epsilon.link is not a symlink"
2620 test_done "$testroot" "1"
2621 return 1
2624 readlink $testroot/wt/epsilon.link > $testroot/stdout
2625 echo "gamma" > $testroot/stdout.expected
2626 cmp -s $testroot/stdout.expected $testroot/stdout
2627 ret="$?"
2628 if [ "$ret" != "0" ]; then
2629 diff -u $testroot/stdout.expected $testroot/stdout
2630 test_done "$testroot" "$ret"
2631 return 1
2634 if [ -h $testroot/wt/passwd.link ]; then
2635 echo "passwd.link is a symlink"
2636 test_done "$testroot" "1"
2637 return 1
2639 echo -n "/etc/passwd" > $testroot/content.expected
2640 cp $testroot/wt/passwd.link $testroot/content
2641 cmp -s $testroot/content.expected $testroot/content
2642 ret="$?"
2643 if [ "$ret" != "0" ]; then
2644 diff -u $testroot/content.expected $testroot/content
2645 test_done "$testroot" "$ret"
2646 return 1
2649 if ! [ -h $testroot/wt/zeta.link ]; then
2650 echo "zeta.link is not a symlink"
2651 test_done "$testroot" "1"
2652 return 1
2655 readlink $testroot/wt/zeta.link > $testroot/stdout
2656 echo "gamma/delta" > $testroot/stdout.expected
2657 cmp -s $testroot/stdout.expected $testroot/stdout
2658 ret="$?"
2659 if [ "$ret" != "0" ]; then
2660 diff -u $testroot/stdout.expected $testroot/stdout
2661 test_done "$testroot" "$ret"
2662 return 1
2665 test_done "$testroot" "0"
2668 test_stage_patch_symlink() {
2669 local testroot=`test_init stage_patch_symlink`
2671 (cd $testroot/repo && ln -s alpha alpha.link)
2672 (cd $testroot/repo && ln -s epsilon epsilon.link)
2673 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2674 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2675 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2676 (cd $testroot/repo && git add .)
2677 git_commit $testroot/repo -m "add symlinks"
2678 local head_commit=`git_show_head $testroot/repo`
2680 got checkout $testroot/repo $testroot/wt > /dev/null
2681 ret="$?"
2682 if [ "$ret" != "0" ]; then
2683 test_done "$testroot" "$ret"
2684 return 1
2687 (cd $testroot/wt && ln -sf beta alpha.link)
2688 (cd $testroot/wt && ln -sfh gamma epsilon.link)
2689 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
2690 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
2691 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2692 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
2693 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2694 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
2695 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
2696 (cd $testroot/wt && got add zeta.link > /dev/null)
2698 printf "y\nn\ny\nn\ny\ny\ny" > $testroot/patchscript
2699 (cd $testroot/wt && got stage -F $testroot/patchscript -p \
2700 > $testroot/stdout)
2702 cat > $testroot/stdout.expected <<EOF
2703 -----------------------------------------------
2704 @@ -1 +1 @@
2705 -alpha
2706 \ No newline at end of file
2707 +beta
2708 \ No newline at end of file
2709 -----------------------------------------------
2710 M alpha.link (change 1 of 1)
2711 stage this change? [y/n/q] y
2712 A dotgotbar.link
2713 stage this addition? [y/n] n
2714 A dotgotfoo.link
2715 stage this addition? [y/n] y
2716 -----------------------------------------------
2717 @@ -1 +1 @@
2718 -../beta
2719 \ No newline at end of file
2720 +../gamma/delta
2721 \ No newline at end of file
2722 -----------------------------------------------
2723 M epsilon/beta.link (change 1 of 1)
2724 stage this change? [y/n/q] n
2725 -----------------------------------------------
2726 @@ -1 +1 @@
2727 -epsilon
2728 \ No newline at end of file
2729 +gamma
2730 \ No newline at end of file
2731 -----------------------------------------------
2732 M epsilon.link (change 1 of 1)
2733 stage this change? [y/n/q] y
2734 D nonexistent.link
2735 stage this deletion? [y/n] y
2736 A zeta.link
2737 stage this addition? [y/n] y
2738 EOF
2739 cmp -s $testroot/stdout.expected $testroot/stdout
2740 ret="$?"
2741 if [ "$ret" != "0" ]; then
2742 diff -u $testroot/stdout.expected $testroot/stdout
2743 test_done "$testroot" "$ret"
2744 return 1
2747 rm $testroot/wt/alpha.link
2748 echo 'this is regular file alpha.link' > $testroot/wt/alpha.link
2750 (cd $testroot/wt && got diff -s > $testroot/stdout)
2752 echo "diff $head_commit $testroot/wt (staged changes)" \
2753 > $testroot/stdout.expected
2754 echo -n 'blob - ' >> $testroot/stdout.expected
2755 got tree -r $testroot/repo -i | grep 'alpha.link@ -> alpha$' | \
2756 cut -d' ' -f 1 >> $testroot/stdout.expected
2757 echo -n 'blob + ' >> $testroot/stdout.expected
2758 (cd $testroot/wt && got stage -l alpha.link) | cut -d' ' -f 1 \
2759 >> $testroot/stdout.expected
2760 echo '--- alpha.link' >> $testroot/stdout.expected
2761 echo '+++ alpha.link' >> $testroot/stdout.expected
2762 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2763 echo '-alpha' >> $testroot/stdout.expected
2764 echo '\ No newline at end of file' >> $testroot/stdout.expected
2765 echo '+beta' >> $testroot/stdout.expected
2766 echo '\ No newline at end of file' >> $testroot/stdout.expected
2767 echo 'blob - /dev/null' >> $testroot/stdout.expected
2768 echo -n 'blob + ' >> $testroot/stdout.expected
2769 (cd $testroot/wt && got stage -l dotgotfoo.link) | cut -d' ' -f 1 \
2770 >> $testroot/stdout.expected
2771 echo '--- /dev/null' >> $testroot/stdout.expected
2772 echo '+++ dotgotfoo.link' >> $testroot/stdout.expected
2773 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2774 echo '+this is regular file foo' >> $testroot/stdout.expected
2775 echo -n 'blob - ' >> $testroot/stdout.expected
2776 got tree -r $testroot/repo -i | grep 'epsilon.link@ -> epsilon$' | \
2777 cut -d' ' -f 1 >> $testroot/stdout.expected
2778 echo -n 'blob + ' >> $testroot/stdout.expected
2779 (cd $testroot/wt && got stage -l epsilon.link) | cut -d' ' -f 1 \
2780 >> $testroot/stdout.expected
2781 echo '--- epsilon.link' >> $testroot/stdout.expected
2782 echo '+++ epsilon.link' >> $testroot/stdout.expected
2783 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
2784 echo '-epsilon' >> $testroot/stdout.expected
2785 echo '\ No newline at end of file' >> $testroot/stdout.expected
2786 echo '+gamma' >> $testroot/stdout.expected
2787 echo '\ No newline at end of file' >> $testroot/stdout.expected
2788 echo -n 'blob - ' >> $testroot/stdout.expected
2789 got tree -r $testroot/repo -i | grep 'nonexistent.link@ -> nonexistent$' | \
2790 cut -d' ' -f 1 >> $testroot/stdout.expected
2791 echo 'blob + /dev/null' >> $testroot/stdout.expected
2792 echo '--- nonexistent.link' >> $testroot/stdout.expected
2793 echo '+++ /dev/null' >> $testroot/stdout.expected
2794 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
2795 echo '-nonexistent' >> $testroot/stdout.expected
2796 echo '\ No newline at end of file' >> $testroot/stdout.expected
2797 echo 'blob - /dev/null' >> $testroot/stdout.expected
2798 echo -n 'blob + ' >> $testroot/stdout.expected
2799 (cd $testroot/wt && got stage -l zeta.link) | cut -d' ' -f 1 \
2800 >> $testroot/stdout.expected
2801 echo '--- /dev/null' >> $testroot/stdout.expected
2802 echo '+++ zeta.link' >> $testroot/stdout.expected
2803 echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
2804 echo '+gamma/delta' >> $testroot/stdout.expected
2805 echo '\ No newline at end of file' >> $testroot/stdout.expected
2807 cmp -s $testroot/stdout.expected $testroot/stdout
2808 ret="$?"
2809 if [ "$ret" != "0" ]; then
2810 diff -u $testroot/stdout.expected $testroot/stdout
2811 test_done "$testroot" "$ret"
2812 return 1
2815 (cd $testroot/wt && got commit -m "staged symlink" \
2816 > $testroot/stdout)
2817 ret="$?"
2818 if [ "$ret" != "0" ]; then
2819 echo "got commit command failed unexpectedly" >&2
2820 test_done "$testroot" "1"
2821 return 1
2824 local commit_id=`git_show_head $testroot/repo`
2825 echo "A dotgotfoo.link" > $testroot/stdout.expected
2826 echo "A zeta.link" >> $testroot/stdout.expected
2827 echo "M alpha.link" >> $testroot/stdout.expected
2828 echo "M epsilon.link" >> $testroot/stdout.expected
2829 echo "D nonexistent.link" >> $testroot/stdout.expected
2830 echo "Created commit $commit_id" >> $testroot/stdout.expected
2831 cmp -s $testroot/stdout.expected $testroot/stdout
2832 ret="$?"
2833 if [ "$ret" != "0" ]; then
2834 diff -u $testroot/stdout.expected $testroot/stdout
2835 test_done "$testroot" "$ret"
2836 return 1
2839 got tree -r $testroot/repo -c $commit_id > $testroot/stdout
2840 ret="$?"
2841 if [ "$ret" != "0" ]; then
2842 echo "got tree command failed unexpectedly" >&2
2843 test_done "$testroot" "1"
2844 return 1
2847 cat > $testroot/stdout.expected <<EOF
2848 alpha
2849 alpha.link@ -> beta
2850 beta
2851 dotgotfoo.link
2852 epsilon/
2853 epsilon.link@ -> gamma
2854 gamma/
2855 passwd.link@ -> /etc/passwd
2856 zeta.link@ -> gamma/delta
2857 EOF
2858 cmp -s $testroot/stdout.expected $testroot/stdout
2859 ret="$?"
2860 if [ "$ret" != "0" ]; then
2861 diff -u $testroot/stdout.expected $testroot/stdout
2862 return 1
2865 if [ -h $testroot/wt/alpha.link ]; then
2866 echo "alpha.link is a symlink"
2867 test_done "$testroot" "1"
2868 return 1
2871 echo 'this is regular file alpha.link' > $testroot/content.expected
2872 cp $testroot/wt/alpha.link $testroot/content
2873 cmp -s $testroot/content.expected $testroot/content
2874 ret="$?"
2875 if [ "$ret" != "0" ]; then
2876 diff -u $testroot/content.expected $testroot/content
2877 test_done "$testroot" "$ret"
2878 return 1
2881 if [ ! -h $testroot/wt/dotgotbar.link ]; then
2882 echo "dotgotbar.link is not a symlink"
2883 test_done "$testroot" "1"
2884 return 1
2886 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
2887 echo ".got/bar" > $testroot/stdout.expected
2888 cmp -s $testroot/stdout.expected $testroot/stdout
2889 ret="$?"
2890 if [ "$ret" != "0" ]; then
2891 diff -u $testroot/stdout.expected $testroot/stdout
2892 test_done "$testroot" "$ret"
2893 return 1
2896 if [ -h $testroot/wt/dotgotfoo.link ]; then
2897 echo "dotgotfoo.link is a symlink"
2898 test_done "$testroot" "1"
2899 return 1
2901 echo "this is regular file foo" > $testroot/content.expected
2902 cp $testroot/wt/dotgotfoo.link $testroot/content
2903 cmp -s $testroot/content.expected $testroot/content
2904 ret="$?"
2905 if [ "$ret" != "0" ]; then
2906 diff -u $testroot/content.expected $testroot/content
2907 test_done "$testroot" "$ret"
2908 return 1
2911 if ! [ -h $testroot/wt/epsilon.link ]; then
2912 echo "epsilon.link is not a symlink"
2913 test_done "$testroot" "1"
2914 return 1
2917 readlink $testroot/wt/epsilon.link > $testroot/stdout
2918 echo "gamma" > $testroot/stdout.expected
2919 cmp -s $testroot/stdout.expected $testroot/stdout
2920 ret="$?"
2921 if [ "$ret" != "0" ]; then
2922 diff -u $testroot/stdout.expected $testroot/stdout
2923 test_done "$testroot" "$ret"
2924 return 1
2927 if [ -h $testroot/wt/passwd.link ]; then
2928 echo "passwd.link is a symlink"
2929 test_done "$testroot" "1"
2930 return 1
2932 echo -n "/etc/passwd" > $testroot/content.expected
2933 cp $testroot/wt/passwd.link $testroot/content
2934 cmp -s $testroot/content.expected $testroot/content
2935 ret="$?"
2936 if [ "$ret" != "0" ]; then
2937 diff -u $testroot/content.expected $testroot/content
2938 test_done "$testroot" "$ret"
2939 return 1
2942 if ! [ -h $testroot/wt/zeta.link ]; then
2943 echo "zeta.link is not a symlink"
2944 test_done "$testroot" "1"
2945 return 1
2948 readlink $testroot/wt/zeta.link > $testroot/stdout
2949 echo "gamma/delta" > $testroot/stdout.expected
2950 cmp -s $testroot/stdout.expected $testroot/stdout
2951 ret="$?"
2952 if [ "$ret" != "0" ]; then
2953 diff -u $testroot/stdout.expected $testroot/stdout
2954 test_done "$testroot" "$ret"
2955 return 1
2958 test_done "$testroot" "0"
2961 test_parseargs "$@"
2962 run_test test_stage_basic
2963 run_test test_stage_no_changes
2964 run_test test_stage_unversioned
2965 run_test test_stage_nonexistent
2966 run_test test_stage_list
2967 run_test test_stage_conflict
2968 run_test test_stage_out_of_date
2969 run_test test_double_stage
2970 run_test test_stage_status
2971 run_test test_stage_add_already_staged_file
2972 run_test test_stage_rm_already_staged_file
2973 run_test test_stage_revert
2974 run_test test_stage_diff
2975 run_test test_stage_histedit
2976 run_test test_stage_rebase
2977 run_test test_stage_update
2978 run_test test_stage_commit_non_staged
2979 run_test test_stage_commit_out_of_date
2980 run_test test_stage_commit
2981 run_test test_stage_patch
2982 run_test test_stage_patch_twice
2983 run_test test_stage_patch_added
2984 run_test test_stage_patch_added_twice
2985 run_test test_stage_patch_removed
2986 run_test test_stage_patch_removed_twice
2987 run_test test_stage_patch_quit
2988 run_test test_stage_patch_incomplete_script
2989 run_test test_stage_symlink
2990 run_test test_stage_patch_symlink