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_unstage_basic() {
20 local testroot=`test_init unstage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified file" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta > /dev/null)
31 echo "new file" > $testroot/wt/foo
32 (cd $testroot/wt && got add foo > /dev/null)
34 echo ' M alpha' > $testroot/stdout.expected
35 echo ' D beta' >> $testroot/stdout.expected
36 echo ' A foo' >> $testroot/stdout.expected
37 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
39 (cd $testroot/wt && got unstage -R > $testroot/stdout)
40 ret=$?
41 if [ $ret -ne 0 ]; then
42 echo "got unstage command failed unexpectedly" >&2
43 test_done "$testroot" "1"
44 return 1
45 fi
47 echo 'G alpha' > $testroot/stdout.expected
48 echo 'D beta' >> $testroot/stdout.expected
49 echo 'G foo' >> $testroot/stdout.expected
50 cmp -s $testroot/stdout.expected $testroot/stdout
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 diff -u $testroot/stdout.expected $testroot/stdout
54 test_done "$testroot" "$ret"
55 return 1
56 fi
58 echo 'M alpha' > $testroot/stdout.expected
59 echo 'D beta' >> $testroot/stdout.expected
60 echo 'A foo' >> $testroot/stdout.expected
61 (cd $testroot/wt && got status > $testroot/stdout)
62 cmp -s $testroot/stdout.expected $testroot/stdout
63 ret=$?
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 fi
67 test_done "$testroot" "$ret"
68 }
70 test_unstage_directory() {
71 local testroot=`test_init unstage_directory`
73 got checkout $testroot/repo $testroot/wt > /dev/null
74 ret=$?
75 if [ $ret -ne 0 ]; then
76 test_done "$testroot" "$ret"
77 return 1
78 fi
80 (cd $testroot/wt && echo -n > test && got add test > /dev/null \
81 && got stage test > /dev/null)
83 (cd $testroot/wt && got unstage . > $testroot/stdout 2> $testroot/stderr)
84 ret=$?
85 echo "got: unstaging directories requires -R option" \
86 > $testroot/stderr.expected
87 cmp -s $testroot/stderr.expected $testroot/stderr
88 ret=$?
89 if [ $ret -ne 0 ]; then
90 diff -u $testroot/stderr.expected $testroot/stderr
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 (cd $testroot/wt && got unstage -R . > $testroot/stdout)
97 echo 'G test' >> $testroot/stdout.expected
99 cmp -s $testroot/stdout.expected $testroot/stdout
100 ret=$?
101 if [ $ret -ne 0 ]; then
102 diff -u $testroot/stdout.expected $testroot/stdout
103 fi
104 test_done "$testroot" "$ret"
107 test_unstage_unversioned() {
108 local testroot=`test_init unstage_unversioned`
110 got checkout $testroot/repo $testroot/wt > /dev/null
111 ret=$?
112 if [ $ret -ne 0 ]; then
113 test_done "$testroot" "$ret"
114 return 1
115 fi
117 echo "modified file" > $testroot/wt/alpha
118 (cd $testroot/wt && got rm beta > /dev/null)
119 echo "new file" > $testroot/wt/foo
120 (cd $testroot/wt && got add foo > /dev/null)
122 echo ' M alpha' > $testroot/stdout.expected
123 echo ' D beta' >> $testroot/stdout.expected
124 echo ' A foo' >> $testroot/stdout.expected
125 (cd $testroot/wt && got stage -R > /dev/null)
127 touch $testroot/wt/unversioned-file
129 (cd $testroot/wt && got status > $testroot/stdout)
130 echo ' M alpha' > $testroot/stdout.expected
131 echo ' D beta' >> $testroot/stdout.expected
132 echo ' A foo' >> $testroot/stdout.expected
133 echo "? unversioned-file" >> $testroot/stdout.expected
134 cmp -s $testroot/stdout.expected $testroot/stdout
135 ret=$?
136 if [ $ret -ne 0 ]; then
137 diff -u $testroot/stdout.expected $testroot/stdout
138 test_done "$testroot" "$ret"
139 return 1
140 fi
142 (cd $testroot/wt && got unstage -R > $testroot/stdout)
143 ret=$?
144 if [ $ret -ne 0 ]; then
145 echo "got unstage command failed unexpectedly" >&2
146 test_done "$testroot" "1"
147 return 1
148 fi
150 echo 'G alpha' > $testroot/stdout.expected
151 echo 'D beta' >> $testroot/stdout.expected
152 echo 'G foo' >> $testroot/stdout.expected
153 cmp -s $testroot/stdout.expected $testroot/stdout
154 ret=$?
155 if [ $ret -ne 0 ]; then
156 diff -u $testroot/stdout.expected $testroot/stdout
157 test_done "$testroot" "$ret"
158 return 1
159 fi
161 (cd $testroot/wt && got stage -R > /dev/null)
163 # unstaging an unversioned path is a no-op
164 (cd $testroot/wt && got unstage unversioned > $testroot/stdout)
165 ret=$?
166 if [ $ret -ne 0 ]; then
167 echo "got unstage command failed unexpectedly" >&2
168 test_done "$testroot" "$ret"
169 return 1
170 fi
172 echo ' M alpha' > $testroot/stdout.expected
173 echo ' D beta' >> $testroot/stdout.expected
174 echo ' A foo' >> $testroot/stdout.expected
175 echo "? unversioned-file" >> $testroot/stdout.expected
176 (cd $testroot/wt && got status > $testroot/stdout)
177 cmp -s $testroot/stdout.expected $testroot/stdout
178 ret=$?
179 if [ $ret -ne 0 ]; then
180 diff -u $testroot/stdout.expected $testroot/stdout
181 fi
182 test_done "$testroot" "$ret"
185 test_unstage_nonexistent() {
186 local testroot=`test_init unstage_nonexistent`
188 got checkout $testroot/repo $testroot/wt > /dev/null
189 ret=$?
190 if [ $ret -ne 0 ]; then
191 test_done "$testroot" "$ret"
192 return 1
193 fi
195 echo "modified file" > $testroot/wt/alpha
196 (cd $testroot/wt && got rm beta > /dev/null)
197 echo "new file" > $testroot/wt/foo
198 (cd $testroot/wt && got add foo > /dev/null)
200 echo ' M alpha' > $testroot/stdout.expected
201 echo ' D beta' >> $testroot/stdout.expected
202 echo ' A foo' >> $testroot/stdout.expected
203 (cd $testroot/wt && got stage -R > /dev/null)
205 # unstaging a non-existent file is a no-op
206 (cd $testroot/wt && got unstage nonexistent-file > $testroot/stdout)
207 ret=$?
208 if [ $ret -ne 0 ]; then
209 echo "got unstage command failed unexpectedly" >&2
210 test_done "$testroot" "1"
211 return 1
212 fi
214 echo -n > $testroot/stdout.expected
215 cmp -s $testroot/stdout.expected $testroot/stdout
216 ret=$?
217 if [ $ret -ne 0 ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
219 fi
220 test_done "$testroot" "$ret"
223 test_unstage_patch() {
224 local testroot=`test_init unstage_patch`
226 seq 16 > $testroot/repo/numbers
227 git -C $testroot/repo add numbers
228 git_commit $testroot/repo -m "added numbers file"
229 local commit_id=`git_show_head $testroot/repo`
231 got checkout $testroot/repo $testroot/wt > /dev/null
232 ret=$?
233 if [ $ret -ne 0 ]; then
234 test_done "$testroot" "$ret"
235 return 1
236 fi
238 ed -s $testroot/wt/numbers <<-\EOF
239 ,s/^2$/a/
240 ,s/^7$/b/
241 ,s/^16$/c/
243 EOF
245 (cd $testroot/wt && got stage -R > /dev/null)
246 ret=$?
247 if [ $ret -ne 0 ]; then
248 echo "got stage command failed unexpectedly" >&2
249 test_done "$testroot" "1"
250 return 1
251 fi
253 # don't unstage any hunks
254 printf "n\nn\nn\n" > $testroot/patchscript
255 (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
256 numbers > $testroot/stdout)
257 ret=$?
258 if [ $ret -ne 0 ]; then
259 echo "got unstage command failed unexpectedly" >&2
260 test_done "$testroot" "1"
261 return 1
262 fi
263 cat > $testroot/stdout.expected <<EOF
264 -----------------------------------------------
265 @@ -1,5 +1,5 @@
267 -2
268 +a
272 -----------------------------------------------
273 M numbers (change 1 of 3)
274 unstage this change? [y/n/q] n
275 -----------------------------------------------
276 @@ -4,7 +4,7 @@
280 -7
281 +b
284 10
285 -----------------------------------------------
286 M numbers (change 2 of 3)
287 unstage this change? [y/n/q] n
288 -----------------------------------------------
289 @@ -13,4 +13,4 @@
290 13
291 14
292 15
293 -16
294 +c
295 -----------------------------------------------
296 M numbers (change 3 of 3)
297 unstage this change? [y/n/q] n
298 EOF
299 cmp -s $testroot/stdout.expected $testroot/stdout
300 ret=$?
301 if [ $ret -ne 0 ]; then
302 diff -u $testroot/stdout.expected $testroot/stdout
303 test_done "$testroot" "$ret"
304 return 1
305 fi
307 (cd $testroot/wt && got status > $testroot/stdout)
308 echo " M numbers" > $testroot/stdout.expected
309 cmp -s $testroot/stdout.expected $testroot/stdout
310 ret=$?
311 if [ $ret -ne 0 ]; then
312 diff -u $testroot/stdout.expected $testroot/stdout
313 test_done "$testroot" "$ret"
314 return 1
315 fi
317 # unstage middle hunk
318 printf "n\ny\nn\n" > $testroot/patchscript
319 (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
320 numbers > $testroot/stdout)
322 cat > $testroot/stdout.expected <<EOF
323 -----------------------------------------------
324 @@ -1,5 +1,5 @@
326 -2
327 +a
331 -----------------------------------------------
332 M numbers (change 1 of 3)
333 unstage this change? [y/n/q] n
334 -----------------------------------------------
335 @@ -4,7 +4,7 @@
339 -7
340 +b
343 10
344 -----------------------------------------------
345 M numbers (change 2 of 3)
346 unstage this change? [y/n/q] y
347 -----------------------------------------------
348 @@ -13,4 +13,4 @@
349 13
350 14
351 15
352 -16
353 +c
354 -----------------------------------------------
355 M numbers (change 3 of 3)
356 unstage this change? [y/n/q] n
357 G numbers
358 EOF
359 cmp -s $testroot/stdout.expected $testroot/stdout
360 ret=$?
361 if [ $ret -ne 0 ]; then
362 diff -u $testroot/stdout.expected $testroot/stdout
363 test_done "$testroot" "$ret"
364 return 1
365 fi
367 (cd $testroot/wt && got status > $testroot/stdout)
368 echo "MM numbers" > $testroot/stdout.expected
369 cmp -s $testroot/stdout.expected $testroot/stdout
370 ret=$?
371 if [ $ret -ne 0 ]; then
372 diff -u $testroot/stdout.expected $testroot/stdout
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 (cd $testroot/wt && got diff -s > $testroot/stdout)
379 echo "diff -s $testroot/wt" > $testroot/stdout.expected
380 echo "commit - $commit_id" >> $testroot/stdout.expected
381 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
382 echo -n 'blob - ' >> $testroot/stdout.expected
383 got tree -r $testroot/repo -i -c $commit_id \
384 | grep 'numbers$' | cut -d' ' -f 1 \
385 >> $testroot/stdout.expected
386 echo -n 'blob + ' >> $testroot/stdout.expected
387 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
388 >> $testroot/stdout.expected
389 cat >> $testroot/stdout.expected <<EOF
390 --- numbers
391 +++ numbers
392 @@ -1,5 +1,5 @@
394 -2
395 +a
399 @@ -13,4 +13,4 @@
400 13
401 14
402 15
403 -16
404 +c
405 EOF
406 cmp -s $testroot/stdout.expected $testroot/stdout
407 ret=$?
408 if [ $ret -ne 0 ]; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
411 return 1
412 fi
414 (cd $testroot/wt && got diff > $testroot/stdout)
415 echo "diff $testroot/wt" > $testroot/stdout.expected
416 echo "commit - $commit_id" >> $testroot/stdout.expected
417 echo "path + $testroot/wt" >> $testroot/stdout.expected
418 echo -n 'blob - ' >> $testroot/stdout.expected
419 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
420 tr -d '\n' >> $testroot/stdout.expected
421 echo " (staged)" >> $testroot/stdout.expected
422 echo "file + numbers" >> $testroot/stdout.expected
423 cat >> $testroot/stdout.expected <<EOF
424 --- numbers
425 +++ numbers
426 @@ -4,7 +4,7 @@ a
430 -7
431 +b
434 10
435 EOF
436 cmp -s $testroot/stdout.expected $testroot/stdout
437 ret=$?
438 if [ $ret -ne 0 ]; then
439 diff -u $testroot/stdout.expected $testroot/stdout
440 test_done "$testroot" "$ret"
441 return 1
442 fi
444 (cd $testroot/wt && got stage -R >/dev/null)
445 ret=$?
446 if [ $ret -ne 0 ]; then
447 echo "got stage command failed unexpectedly" >&2
448 test_done "$testroot" "1"
449 return 1
450 fi
452 (cd $testroot/wt && got status > $testroot/stdout)
453 echo " M numbers" > $testroot/stdout.expected
454 cmp -s $testroot/stdout.expected $testroot/stdout
455 ret=$?
456 if [ $ret -ne 0 ]; then
457 diff -u $testroot/stdout.expected $testroot/stdout
458 test_done "$testroot" "$ret"
459 return 1
460 fi
462 # unstage last hunk
463 printf "n\nn\ny\n" > $testroot/patchscript
464 (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
465 numbers > $testroot/stdout)
467 cat > $testroot/stdout.expected <<EOF
468 -----------------------------------------------
469 @@ -1,5 +1,5 @@
471 -2
472 +a
476 -----------------------------------------------
477 M numbers (change 1 of 3)
478 unstage this change? [y/n/q] n
479 -----------------------------------------------
480 @@ -4,7 +4,7 @@
484 -7
485 +b
488 10
489 -----------------------------------------------
490 M numbers (change 2 of 3)
491 unstage this change? [y/n/q] n
492 -----------------------------------------------
493 @@ -13,4 +13,4 @@
494 13
495 14
496 15
497 -16
498 +c
499 -----------------------------------------------
500 M numbers (change 3 of 3)
501 unstage this change? [y/n/q] y
502 G numbers
503 EOF
504 cmp -s $testroot/stdout.expected $testroot/stdout
505 ret=$?
506 if [ $ret -ne 0 ]; then
507 diff -u $testroot/stdout.expected $testroot/stdout
508 test_done "$testroot" "$ret"
509 return 1
510 fi
512 (cd $testroot/wt && got status > $testroot/stdout)
513 echo "MM numbers" > $testroot/stdout.expected
514 cmp -s $testroot/stdout.expected $testroot/stdout
515 ret=$?
516 if [ $ret -ne 0 ]; then
517 diff -u $testroot/stdout.expected $testroot/stdout
518 test_done "$testroot" "$ret"
519 return 1
520 fi
522 (cd $testroot/wt && got diff -s > $testroot/stdout)
524 echo "diff -s $testroot/wt" > $testroot/stdout.expected
525 echo "commit - $commit_id" >> $testroot/stdout.expected
526 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
527 echo -n 'blob - ' >> $testroot/stdout.expected
528 got tree -r $testroot/repo -i -c $commit_id \
529 | grep 'numbers$' | cut -d' ' -f 1 \
530 >> $testroot/stdout.expected
531 echo -n 'blob + ' >> $testroot/stdout.expected
532 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
533 >> $testroot/stdout.expected
534 cat >> $testroot/stdout.expected <<EOF
535 --- numbers
536 +++ numbers
537 @@ -1,10 +1,10 @@
539 -2
540 +a
545 -7
546 +b
549 10
550 EOF
551 cmp -s $testroot/stdout.expected $testroot/stdout
552 ret=$?
553 if [ $ret -ne 0 ]; then
554 diff -u $testroot/stdout.expected $testroot/stdout
555 test_done "$testroot" "$ret"
556 return 1
557 fi
559 (cd $testroot/wt && got diff > $testroot/stdout)
560 echo "diff $testroot/wt" > $testroot/stdout.expected
561 echo "commit - $commit_id" >> $testroot/stdout.expected
562 echo "path + $testroot/wt" >> $testroot/stdout.expected
563 echo -n 'blob - ' >> $testroot/stdout.expected
564 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
565 tr -d '\n' >> $testroot/stdout.expected
566 echo " (staged)" >> $testroot/stdout.expected
567 echo "file + numbers" >> $testroot/stdout.expected
568 cat >> $testroot/stdout.expected <<EOF
569 --- numbers
570 +++ numbers
571 @@ -13,4 +13,4 @@ b
572 13
573 14
574 15
575 -16
576 +c
577 EOF
578 cmp -s $testroot/stdout.expected $testroot/stdout
579 ret=$?
580 if [ $ret -ne 0 ]; then
581 diff -u $testroot/stdout.expected $testroot/stdout
582 test_done "$testroot" "$ret"
583 return 1
584 fi
586 (cd $testroot/wt && got stage -R >/dev/null)
587 ret=$?
588 if [ $ret -ne 0 ]; then
589 echo "got stage command failed unexpectedly" >&2
590 test_done "$testroot" "1"
591 return 1
592 fi
594 (cd $testroot/wt && got status > $testroot/stdout)
595 echo " M numbers" > $testroot/stdout.expected
596 cmp -s $testroot/stdout.expected $testroot/stdout
597 ret=$?
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 test_done "$testroot" "$ret"
601 return 1
602 fi
604 # unstage all hunks
605 printf "y\ny\ny\n" > $testroot/patchscript
606 (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
607 numbers > $testroot/stdout)
609 cat > $testroot/stdout.expected <<EOF
610 -----------------------------------------------
611 @@ -1,5 +1,5 @@
613 -2
614 +a
618 -----------------------------------------------
619 M numbers (change 1 of 3)
620 unstage this change? [y/n/q] y
621 -----------------------------------------------
622 @@ -4,7 +4,7 @@
626 -7
627 +b
630 10
631 -----------------------------------------------
632 M numbers (change 2 of 3)
633 unstage this change? [y/n/q] y
634 -----------------------------------------------
635 @@ -13,4 +13,4 @@
636 13
637 14
638 15
639 -16
640 +c
641 -----------------------------------------------
642 M numbers (change 3 of 3)
643 unstage this change? [y/n/q] y
644 G numbers
645 EOF
646 cmp -s $testroot/stdout.expected $testroot/stdout
647 ret=$?
648 if [ $ret -ne 0 ]; then
649 diff -u $testroot/stdout.expected $testroot/stdout
650 test_done "$testroot" "$ret"
651 return 1
652 fi
654 (cd $testroot/wt && got status > $testroot/stdout)
655 echo "M numbers" > $testroot/stdout.expected
656 cmp -s $testroot/stdout.expected $testroot/stdout
657 ret=$?
658 if [ $ret -ne 0 ]; then
659 diff -u $testroot/stdout.expected $testroot/stdout
660 test_done "$testroot" "$ret"
661 return 1
662 fi
664 (cd $testroot/wt && got diff -s > $testroot/stdout)
665 echo -n > $testroot/stdout.expected
666 cmp -s $testroot/stdout.expected $testroot/stdout
667 ret=$?
668 if [ $ret -ne 0 ]; then
669 diff -u $testroot/stdout.expected $testroot/stdout
670 test_done "$testroot" "$ret"
671 return 1
672 fi
674 (cd $testroot/wt && got diff > $testroot/stdout)
676 echo "diff $testroot/wt" > $testroot/stdout.expected
677 echo "commit - $commit_id" >> $testroot/stdout.expected
678 echo "path + $testroot/wt" >> $testroot/stdout.expected
679 echo -n 'blob - ' >> $testroot/stdout.expected
680 got tree -r $testroot/repo -i -c $commit_id \
681 | grep 'numbers$' | cut -d' ' -f 1 \
682 >> $testroot/stdout.expected
683 echo 'file + numbers' >> $testroot/stdout.expected
684 cat >> $testroot/stdout.expected <<EOF
685 --- numbers
686 +++ numbers
687 @@ -1,10 +1,10 @@
689 -2
690 +a
695 -7
696 +b
699 10
700 @@ -13,4 +13,4 @@
701 13
702 14
703 15
704 -16
705 +c
706 EOF
707 cmp -s $testroot/stdout.expected $testroot/stdout
708 ret=$?
709 if [ $ret -ne 0 ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
711 fi
712 test_done "$testroot" "$ret"
716 test_unstage_patch_added() {
717 local testroot=`test_init unstage_patch_added`
718 local commit_id=`git_show_head $testroot/repo`
720 got checkout $testroot/repo $testroot/wt > /dev/null
721 ret=$?
722 if [ $ret -ne 0 ]; then
723 test_done "$testroot" "$ret"
724 return 1
725 fi
727 echo "new" > $testroot/wt/epsilon/new
728 (cd $testroot/wt && got add epsilon/new > /dev/null)
730 (cd $testroot/wt && got stage -R > /dev/null)
732 printf "y\n" > $testroot/patchscript
733 (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
734 epsilon/new > $testroot/stdout)
736 echo "A epsilon/new" > $testroot/stdout.expected
737 echo "unstage this addition? [y/n] y" >> $testroot/stdout.expected
738 echo "G epsilon/new" >> $testroot/stdout.expected
739 cmp -s $testroot/stdout.expected $testroot/stdout
740 ret=$?
741 if [ $ret -ne 0 ]; then
742 diff -u $testroot/stdout.expected $testroot/stdout
743 test_done "$testroot" "$ret"
744 return 1
745 fi
747 (cd $testroot/wt && got status > $testroot/stdout)
748 echo "A epsilon/new" > $testroot/stdout.expected
749 cmp -s $testroot/stdout.expected $testroot/stdout
750 ret=$?
751 if [ $ret -ne 0 ]; then
752 diff -u $testroot/stdout.expected $testroot/stdout
753 test_done "$testroot" "$ret"
754 return 1
755 fi
757 (cd $testroot/wt && got diff -s > $testroot/stdout)
758 echo -n > $testroot/stdout.expected
759 cmp -s $testroot/stdout.expected $testroot/stdout
760 ret=$?
761 if [ $ret -ne 0 ]; then
762 diff -u $testroot/stdout.expected $testroot/stdout
763 test_done "$testroot" "$ret"
764 return 1
765 fi
767 (cd $testroot/wt && got diff > $testroot/stdout)
769 echo "diff $testroot/wt" > $testroot/stdout.expected
770 echo "commit - $commit_id" >> $testroot/stdout.expected
771 echo "path + $testroot/wt" >> $testroot/stdout.expected
772 echo 'blob - /dev/null' >> $testroot/stdout.expected
773 echo 'file + epsilon/new (mode 644)' >> $testroot/stdout.expected
774 echo "--- /dev/null" >> $testroot/stdout.expected
775 echo "+++ epsilon/new" >> $testroot/stdout.expected
776 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
777 echo "+new" >> $testroot/stdout.expected
778 cmp -s $testroot/stdout.expected $testroot/stdout
779 ret=$?
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
782 fi
783 test_done "$testroot" "$ret"
786 test_unstage_patch_removed() {
787 local testroot=`test_init unstage_patch_removed`
788 local commit_id=`git_show_head $testroot/repo`
790 got checkout $testroot/repo $testroot/wt > /dev/null
791 ret=$?
792 if [ $ret -ne 0 ]; then
793 test_done "$testroot" "$ret"
794 return 1
795 fi
797 (cd $testroot/wt && got rm beta > /dev/null)
798 (cd $testroot/wt && got stage -R > /dev/null)
800 printf "y\n" > $testroot/patchscript
801 (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
802 beta > $testroot/stdout)
804 echo "D beta" > $testroot/stdout.expected
805 echo "unstage this deletion? [y/n] y" >> $testroot/stdout.expected
806 echo "D beta" >> $testroot/stdout.expected
807 cmp -s $testroot/stdout.expected $testroot/stdout
808 ret=$?
809 if [ $ret -ne 0 ]; then
810 diff -u $testroot/stdout.expected $testroot/stdout
811 test_done "$testroot" "$ret"
812 return 1
813 fi
815 (cd $testroot/wt && got status > $testroot/stdout)
816 echo "D beta" > $testroot/stdout.expected
817 cmp -s $testroot/stdout.expected $testroot/stdout
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 (cd $testroot/wt && got diff -s > $testroot/stdout)
826 echo -n > $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
828 ret=$?
829 if [ $ret -ne 0 ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
831 test_done "$testroot" "$ret"
832 return 1
833 fi
835 (cd $testroot/wt && got diff > $testroot/stdout)
837 echo "diff $testroot/wt" > $testroot/stdout.expected
838 echo "commit - $commit_id" >> $testroot/stdout.expected
839 echo "path + $testroot/wt" >> $testroot/stdout.expected
840 echo -n 'blob - ' >> $testroot/stdout.expected
841 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
842 >> $testroot/stdout.expected
843 echo 'file + /dev/null' >> $testroot/stdout.expected
844 echo "--- beta" >> $testroot/stdout.expected
845 echo "+++ /dev/null" >> $testroot/stdout.expected
846 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
847 echo "-beta" >> $testroot/stdout.expected
848 cmp -s $testroot/stdout.expected $testroot/stdout
849 ret=$?
850 if [ $ret -ne 0 ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
852 fi
853 test_done "$testroot" "$ret"
856 test_unstage_patch_quit() {
857 local testroot=`test_init unstage_patch_quit`
859 seq 16 > $testroot/repo/numbers
860 echo zzz > $testroot/repo/zzz
861 git -C $testroot/repo add numbers zzz
862 git_commit $testroot/repo -m "added files"
863 local commit_id=`git_show_head $testroot/repo`
865 got checkout $testroot/repo $testroot/wt > /dev/null
866 ret=$?
867 if [ $ret -ne 0 ]; then
868 test_done "$testroot" "$ret"
869 return 1
870 fi
872 ed -s $testroot/wt/numbers <<-\EOF
873 ,s/^2$/a/
874 ,s/^7$/b/
875 ,s/^16$/c/
877 EOF
878 (cd $testroot/wt && got rm zzz > /dev/null)
879 (cd $testroot/wt && got stage -R > /dev/null)
881 # unstage first hunk and quit; and don't pass a path argument to
882 # ensure that we don't skip asking about the 'zzz' file after 'quit'
883 printf "y\nq\nn\n" > $testroot/patchscript
884 (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
885 > $testroot/stdout)
886 ret=$?
887 if [ $ret -ne 0 ]; then
888 echo "got unstage command failed unexpectedly" >&2
889 test_done "$testroot" "1"
890 return 1
891 fi
892 cat > $testroot/stdout.expected <<EOF
893 -----------------------------------------------
894 @@ -1,5 +1,5 @@
896 -2
897 +a
901 -----------------------------------------------
902 M numbers (change 1 of 3)
903 unstage this change? [y/n/q] y
904 -----------------------------------------------
905 @@ -4,7 +4,7 @@
909 -7
910 +b
913 10
914 -----------------------------------------------
915 M numbers (change 2 of 3)
916 unstage this change? [y/n/q] q
917 G numbers
918 D zzz
919 unstage this deletion? [y/n] n
920 EOF
921 cmp -s $testroot/stdout.expected $testroot/stdout
922 ret=$?
923 if [ $ret -ne 0 ]; then
924 diff -u $testroot/stdout.expected $testroot/stdout
925 test_done "$testroot" "$ret"
926 return 1
927 fi
929 (cd $testroot/wt && got status > $testroot/stdout)
930 echo "MM numbers" > $testroot/stdout.expected
931 echo " D zzz" >> $testroot/stdout.expected
932 cmp -s $testroot/stdout.expected $testroot/stdout
933 ret=$?
934 if [ $ret -ne 0 ]; then
935 diff -u $testroot/stdout.expected $testroot/stdout
936 test_done "$testroot" "$ret"
937 return 1
938 fi
940 (cd $testroot/wt && got diff > $testroot/stdout)
942 echo "diff $testroot/wt" > $testroot/stdout.expected
943 echo "commit - $commit_id" >> $testroot/stdout.expected
944 echo "path + $testroot/wt" >> $testroot/stdout.expected
945 echo -n 'blob - ' >> $testroot/stdout.expected
946 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
947 tr -d '\n' >> $testroot/stdout.expected
948 echo " (staged)" >> $testroot/stdout.expected
949 echo "file + numbers" >> $testroot/stdout.expected
950 echo "--- numbers" >> $testroot/stdout.expected
951 echo "+++ numbers" >> $testroot/stdout.expected
952 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
953 echo " 1" >> $testroot/stdout.expected
954 echo "-2" >> $testroot/stdout.expected
955 echo "+a" >> $testroot/stdout.expected
956 echo " 3" >> $testroot/stdout.expected
957 echo " 4" >> $testroot/stdout.expected
958 echo " 5" >> $testroot/stdout.expected
959 cmp -s $testroot/stdout.expected $testroot/stdout
960 ret=$?
961 if [ $ret -ne 0 ]; then
962 diff -u $testroot/stdout.expected $testroot/stdout
963 test_done "$testroot" "$ret"
964 return 1
965 fi
967 (cd $testroot/wt && got diff -s > $testroot/stdout)
968 echo "diff -s $testroot/wt" > $testroot/stdout.expected
969 echo "commit - $commit_id" >> $testroot/stdout.expected
970 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
971 echo -n 'blob - ' >> $testroot/stdout.expected
972 got tree -r $testroot/repo -i -c $commit_id \
973 | grep 'numbers$' | cut -d' ' -f 1 \
974 >> $testroot/stdout.expected
975 echo -n 'blob + ' >> $testroot/stdout.expected
976 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
977 >> $testroot/stdout.expected
978 cat >> $testroot/stdout.expected <<EOF
979 --- numbers
980 +++ numbers
981 @@ -4,7 +4,7 @@
985 -7
986 +b
989 10
990 @@ -13,4 +13,4 @@
991 13
992 14
993 15
994 -16
995 +c
996 EOF
997 echo -n 'blob - ' >> $testroot/stdout.expected
998 got tree -r $testroot/repo -i | grep 'zzz$' | cut -d' ' -f 1 \
999 >> $testroot/stdout.expected
1000 echo 'blob + /dev/null' >> $testroot/stdout.expected
1001 echo "--- zzz" >> $testroot/stdout.expected
1002 echo "+++ /dev/null" >> $testroot/stdout.expected
1003 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
1004 echo "-zzz" >> $testroot/stdout.expected
1005 cmp -s $testroot/stdout.expected $testroot/stdout
1006 ret=$?
1007 if [ $ret -ne 0 ]; then
1008 diff -u $testroot/stdout.expected $testroot/stdout
1010 test_done "$testroot" "$ret"
1013 test_unstage_symlink() {
1014 local testroot=`test_init unstage_symlink`
1016 (cd $testroot/repo && ln -s alpha alpha.link)
1017 (cd $testroot/repo && ln -s epsilon epsilon.link)
1018 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1019 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1020 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1021 git -C $testroot/repo add .
1022 git_commit $testroot/repo -m "add symlinks"
1023 local head_commit=`git_show_head $testroot/repo`
1025 got checkout $testroot/repo $testroot/wt > /dev/null
1026 ret=$?
1027 if [ $ret -ne 0 ]; then
1028 test_done "$testroot" "$ret"
1029 return 1
1032 (cd $testroot/wt && ln -sf beta alpha.link)
1033 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
1034 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
1035 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
1036 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
1037 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1038 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1039 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1040 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1041 (cd $testroot/wt && got add zeta.link > /dev/null)
1043 (cd $testroot/wt && got stage -RS > /dev/null)
1045 (cd $testroot/wt && got status > $testroot/stdout)
1046 cat > $testroot/stdout.expected <<EOF
1047 M alpha.link
1048 A dotgotbar.link
1049 A dotgotfoo.link
1050 M epsilon/beta.link
1051 M epsilon.link
1052 D nonexistent.link
1053 A zeta.link
1054 EOF
1055 cmp -s $testroot/stdout.expected $testroot/stdout
1056 ret=$?
1057 if [ $ret -ne 0 ]; then
1058 diff -u $testroot/stdout.expected $testroot/stdout
1059 test_done "$testroot" "$ret"
1060 return 1
1063 (cd $testroot/wt && got unstage -R > $testroot/stdout)
1064 ret=$?
1065 if [ $ret -ne 0 ]; then
1066 echo "got unstage command failed unexpectedly" >&2
1067 test_done "$testroot" "1"
1068 return 1
1071 cat > $testroot/stdout.expected <<EOF
1072 G alpha.link
1073 G dotgotbar.link
1074 G dotgotfoo.link
1075 G epsilon/beta.link
1076 G epsilon.link
1077 D nonexistent.link
1078 G zeta.link
1079 EOF
1081 cmp -s $testroot/stdout.expected $testroot/stdout
1082 ret=$?
1083 if [ $ret -ne 0 ]; then
1084 diff -u $testroot/stdout.expected $testroot/stdout
1085 test_done "$testroot" "$ret"
1086 return 1
1089 if [ ! -h $testroot/wt/alpha.link ]; then
1090 echo "alpha.link is not a symlink"
1091 test_done "$testroot" "1"
1092 return 1
1095 readlink $testroot/wt/alpha.link > $testroot/stdout
1096 echo "beta" > $testroot/stdout.expected
1097 cmp -s $testroot/stdout.expected $testroot/stdout
1098 ret=$?
1099 if [ $ret -ne 0 ]; then
1100 diff -u $testroot/stdout.expected $testroot/stdout
1101 test_done "$testroot" "$ret"
1102 return 1
1105 if [ ! -h $testroot/wt/epsilon.link ]; then
1106 echo "epsilon.link is not a symlink"
1107 test_done "$testroot" "1"
1108 return 1
1111 readlink $testroot/wt/epsilon.link > $testroot/stdout
1112 echo "gamma" > $testroot/stdout.expected
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1114 ret=$?
1115 if [ $ret -ne 0 ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1117 test_done "$testroot" "$ret"
1118 return 1
1121 if [ ! -h $testroot/wt/epsilon/beta.link ]; then
1122 echo "epsilon/beta.link is not a symlink"
1123 test_done "$testroot" "1"
1124 return 1
1127 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1128 echo "../gamma/delta" > $testroot/stdout.expected
1129 cmp -s $testroot/stdout.expected $testroot/stdout
1130 ret=$?
1131 if [ $ret -ne 0 ]; then
1132 diff -u $testroot/stdout.expected $testroot/stdout
1133 test_done "$testroot" "$ret"
1134 return 1
1137 if [ ! -f $testroot/wt/dotgotfoo.link ]; then
1138 echo "dotgotfoo.link is a symlink"
1139 test_done "$testroot" "1"
1140 return 1
1143 echo "this is regular file foo" > $testroot/content.expected
1144 cp $testroot/wt/dotgotfoo.link $testroot/content
1145 cmp -s $testroot/content.expected $testroot/content
1146 ret=$?
1147 if [ $ret -ne 0 ]; then
1148 diff -u $testroot/content.expected $testroot/content
1149 test_done "$testroot" "$ret"
1150 return 1
1153 # bad symlinks are allowed as-is for commit and stage/unstage
1154 if [ ! -h $testroot/wt/dotgotbar.link ]; then
1155 echo "dotgotbar.link is not a symlink"
1156 test_done "$testroot" "1"
1157 return 1
1160 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
1161 echo ".got/bar" > $testroot/stdout.expected
1162 cmp -s $testroot/stdout.expected $testroot/stdout
1163 ret=$?
1164 if [ $ret -ne 0 ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1166 test_done "$testroot" "$ret"
1167 return 1
1170 if [ -e $testroot/wt/nonexistent.link ]; then
1171 echo "nonexistent.link exists on disk"
1172 test_done "$testroot" "1"
1173 return 1
1176 if [ ! -h $testroot/wt/zeta.link ]; then
1177 echo "zeta.link is not a symlink"
1178 test_done "$testroot" "1"
1179 return 1
1182 readlink $testroot/wt/zeta.link > $testroot/stdout
1183 echo "gamma/delta" > $testroot/stdout.expected
1184 cmp -s $testroot/stdout.expected $testroot/stdout
1185 ret=$?
1186 if [ $ret -ne 0 ]; then
1187 diff -u $testroot/stdout.expected $testroot/stdout
1188 test_done "$testroot" "$ret"
1189 return 1
1192 test_done "$testroot" "0"
1195 test_unstage_patch_symlink() {
1196 local testroot=`test_init unstage_patch_symlink`
1198 (cd $testroot/repo && ln -s alpha alpha.link)
1199 (cd $testroot/repo && ln -s epsilon epsilon.link)
1200 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1201 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1202 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1203 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1204 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1205 git -C $testroot/repo add .
1206 git_commit $testroot/repo -m "add symlinks"
1207 local commit_id1=`git_show_head $testroot/repo`
1209 got checkout $testroot/repo $testroot/wt > /dev/null
1210 ret=$?
1211 if [ $ret -ne 0 ]; then
1212 test_done "$testroot" "$ret"
1213 return 1
1216 # symlink to file A now points to file B
1217 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1218 # symlink to a directory A now points to file B
1219 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1220 # "bad" symlink now contains a different target path
1221 echo "foo" > $testroot/wt/passwd.link
1222 # relative symlink to directory A now points to relative directory B
1223 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1224 epsilon/beta.link)
1225 # an unversioned symlink
1226 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1227 # symlink to file A now points to non-existent file B
1228 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1229 # removed symlink
1230 (cd $testroot/wt && got rm zeta.link > /dev/null)
1231 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1232 # added symlink
1233 (cd $testroot/wt && ln -sf beta new.link)
1234 (cd $testroot/wt && got add new.link > /dev/null)
1235 (cd $testroot/wt && ln -sf beta zeta3.link)
1236 (cd $testroot/wt && got add zeta3.link > /dev/null)
1238 (cd $testroot/wt && got stage -RS > /dev/null)
1240 (cd $testroot/wt && got status > $testroot/stdout)
1241 cat > $testroot/stdout.expected <<EOF
1242 M alpha.link
1243 ? dotgotfoo.link
1244 M epsilon/beta.link
1245 M epsilon.link
1246 A new.link
1247 M nonexistent.link
1248 M passwd.link
1249 D zeta.link
1250 D zeta2.link
1251 A zeta3.link
1252 EOF
1253 cmp -s $testroot/stdout.expected $testroot/stdout
1254 ret=$?
1255 if [ $ret -ne 0 ]; then
1256 diff -u $testroot/stdout.expected $testroot/stdout
1257 test_done "$testroot" "$ret"
1258 return 1
1261 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1262 (cd $testroot/wt && got unstage -R -F $testroot/patchscript -p \
1263 > $testroot/stdout)
1264 ret=$?
1265 if [ $ret -ne 0 ]; then
1266 echo "got unstage command failed unexpectedly" >&2
1267 test_done "$testroot" "1"
1268 return 1
1271 cat > $testroot/stdout.expected <<EOF
1272 -----------------------------------------------
1273 @@ -1 +1 @@
1274 -alpha
1275 \ No newline at end of file
1276 +gamma/delta
1277 \ No newline at end of file
1278 -----------------------------------------------
1279 M alpha.link (change 1 of 1)
1280 unstage this change? [y/n/q] y
1281 G alpha.link
1282 -----------------------------------------------
1283 @@ -1 +1 @@
1284 -../beta
1285 \ No newline at end of file
1286 +../gamma
1287 \ No newline at end of file
1288 -----------------------------------------------
1289 M epsilon/beta.link (change 1 of 1)
1290 unstage this change? [y/n/q] n
1291 -----------------------------------------------
1292 @@ -1 +1 @@
1293 -epsilon
1294 \ No newline at end of file
1295 +beta
1296 \ No newline at end of file
1297 -----------------------------------------------
1298 M epsilon.link (change 1 of 1)
1299 unstage this change? [y/n/q] y
1300 G epsilon.link
1301 A new.link
1302 unstage this addition? [y/n] n
1303 -----------------------------------------------
1304 @@ -1 +1 @@
1305 -nonexistent
1306 \ No newline at end of file
1307 +nonexistent2
1308 \ No newline at end of file
1309 -----------------------------------------------
1310 M nonexistent.link (change 1 of 1)
1311 unstage this change? [y/n/q] y
1312 G nonexistent.link
1313 -----------------------------------------------
1314 @@ -1 +1 @@
1315 -/etc/passwd
1316 \ No newline at end of file
1317 +foo
1318 -----------------------------------------------
1319 M passwd.link (change 1 of 1)
1320 unstage this change? [y/n/q] y
1321 G passwd.link
1322 D zeta.link
1323 unstage this deletion? [y/n] n
1324 D zeta2.link
1325 unstage this deletion? [y/n] y
1326 D zeta2.link
1327 A zeta3.link
1328 unstage this addition? [y/n] y
1329 G zeta3.link
1330 EOF
1331 cmp -s $testroot/stdout.expected $testroot/stdout
1332 ret=$?
1333 if [ $ret -ne 0 ]; then
1334 diff -u $testroot/stdout.expected $testroot/stdout
1335 test_done "$testroot" "$ret"
1336 return 1
1339 if ! [ -h $testroot/wt/alpha.link ]; then
1340 echo "alpha.link is not a symlink"
1341 test_done "$testroot" "1"
1342 return 1
1345 readlink $testroot/wt/alpha.link > $testroot/stdout
1346 echo "gamma/delta" > $testroot/stdout.expected
1347 cmp -s $testroot/stdout.expected $testroot/stdout
1348 ret=$?
1349 if [ $ret -ne 0 ]; then
1350 diff -u $testroot/stdout.expected $testroot/stdout
1351 test_done "$testroot" "$ret"
1352 return 1
1355 if ! [ -h $testroot/wt/epsilon.link ]; then
1356 echo "epsilon.link is not a symlink"
1357 test_done "$testroot" "1"
1358 return 1
1361 readlink $testroot/wt/epsilon.link > $testroot/stdout
1362 echo "beta" > $testroot/stdout.expected
1363 cmp -s $testroot/stdout.expected $testroot/stdout
1364 ret=$?
1365 if [ $ret -ne 0 ]; then
1366 diff -u $testroot/stdout.expected $testroot/stdout
1367 test_done "$testroot" "$ret"
1368 return 1
1371 if [ -h $testroot/wt/passwd.link ]; then
1372 echo "passwd.link should not be a symlink" >&2
1373 test_done "$testroot" "1"
1374 return 1
1377 echo "foo" > $testroot/content.expected
1378 cp $testroot/wt/passwd.link $testroot/content
1380 cmp -s $testroot/content.expected $testroot/content
1381 ret=$?
1382 if [ $ret -ne 0 ]; then
1383 diff -u $testroot/content.expected $testroot/content
1384 test_done "$testroot" "$ret"
1385 return 1
1388 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1389 echo "../gamma" > $testroot/stdout.expected
1390 cmp -s $testroot/stdout.expected $testroot/stdout
1391 ret=$?
1392 if [ $ret -ne 0 ]; then
1393 diff -u $testroot/stdout.expected $testroot/stdout
1394 test_done "$testroot" "$ret"
1395 return 1
1398 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1399 echo "nonexistent2" > $testroot/stdout.expected
1400 cmp -s $testroot/stdout.expected $testroot/stdout
1401 ret=$?
1402 if [ $ret -ne 0 ]; then
1403 diff -u $testroot/stdout.expected $testroot/stdout
1404 test_done "$testroot" "$ret"
1405 return 1
1408 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1409 echo "dotgotfoo.link is not a symlink " >&2
1410 test_done "$testroot" "1"
1411 return 1
1413 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1414 echo ".got/foo" > $testroot/stdout.expected
1415 cmp -s $testroot/stdout.expected $testroot/stdout
1416 ret=$?
1417 if [ $ret -ne 0 ]; then
1418 diff -u $testroot/stdout.expected $testroot/stdout
1419 test_done "$testroot" "$ret"
1420 return 1
1424 if [ -e $testroot/wt/zeta.link ]; then
1425 echo -n "zeta.link should not exist on disk" >&2
1426 test_done "$testroot" "1"
1427 return 1
1430 if [ -e $testroot/wt/zeta2.link ]; then
1431 echo -n "zeta2.link exists on disk" >&2
1432 test_done "$testroot" "1"
1433 return 1
1436 if [ ! -h $testroot/wt/zeta3.link ]; then
1437 echo -n "zeta3.link is not a symlink" >&2
1438 test_done "$testroot" "1"
1439 return 1
1442 readlink $testroot/wt/zeta3.link > $testroot/stdout
1443 echo "beta" > $testroot/stdout.expected
1444 cmp -s $testroot/stdout.expected $testroot/stdout
1445 ret=$?
1446 if [ $ret -ne 0 ]; then
1447 diff -u $testroot/stdout.expected $testroot/stdout
1448 test_done "$testroot" "$ret"
1449 return 1
1452 if [ ! -h $testroot/wt/new.link ]; then
1453 echo -n "new.link is not a symlink" >&2
1454 test_done "$testroot" "1"
1455 return 1
1458 (cd $testroot/wt && got status > $testroot/stdout)
1459 echo "M alpha.link" > $testroot/stdout.expected
1460 echo "? dotgotfoo.link" >> $testroot/stdout.expected
1461 echo " M epsilon/beta.link" >> $testroot/stdout.expected
1462 echo "M epsilon.link" >> $testroot/stdout.expected
1463 echo " A new.link" >> $testroot/stdout.expected
1464 echo "M nonexistent.link" >> $testroot/stdout.expected
1465 echo "M passwd.link" >> $testroot/stdout.expected
1466 echo " D zeta.link" >> $testroot/stdout.expected
1467 echo "D zeta2.link" >> $testroot/stdout.expected
1468 echo "A zeta3.link" >> $testroot/stdout.expected
1469 cmp -s $testroot/stdout.expected $testroot/stdout
1470 ret=$?
1471 if [ $ret -ne 0 ]; then
1472 diff -u $testroot/stdout.expected $testroot/stdout
1473 return 1
1475 test_done "$testroot" "$ret"
1478 test_parseargs "$@"
1479 run_test test_unstage_basic
1480 run_test test_unstage_directory
1481 run_test test_unstage_unversioned
1482 run_test test_unstage_nonexistent
1483 run_test test_unstage_patch
1484 run_test test_unstage_patch_added
1485 run_test test_unstage_patch_removed
1486 run_test test_unstage_patch_quit
1487 run_test test_unstage_symlink
1488 run_test test_unstage_patch_symlink