3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
19 test_unstage_basic() {
20 local testroot=`test_init unstage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
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 > $testroot/stdout)
41 if [ $ret -ne 0 ]; then
42 echo "got unstage command failed unexpectedly" >&2
43 test_done "$testroot" "1"
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
52 if [ $ret -ne 0 ]; then
53 diff -u $testroot/stdout.expected $testroot/stdout
54 test_done "$testroot" "$ret"
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
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
67 test_done "$testroot" "$ret"
70 test_unstage_unversioned() {
71 local testroot=`test_init unstage_unversioned`
73 got checkout $testroot/repo $testroot/wt > /dev/null
75 if [ $ret -ne 0 ]; then
76 test_done "$testroot" "$ret"
80 echo "modified file" > $testroot/wt/alpha
81 (cd $testroot/wt && got rm beta > /dev/null)
82 echo "new file" > $testroot/wt/foo
83 (cd $testroot/wt && got add foo > /dev/null)
85 echo ' M alpha' > $testroot/stdout.expected
86 echo ' D beta' >> $testroot/stdout.expected
87 echo ' A foo' >> $testroot/stdout.expected
88 (cd $testroot/wt && got stage > /dev/null)
90 touch $testroot/wt/unversioned-file
92 (cd $testroot/wt && got status > $testroot/stdout)
93 echo ' M alpha' > $testroot/stdout.expected
94 echo ' D beta' >> $testroot/stdout.expected
95 echo ' A foo' >> $testroot/stdout.expected
96 echo "? unversioned-file" >> $testroot/stdout.expected
97 cmp -s $testroot/stdout.expected $testroot/stdout
99 if [ $ret -ne 0 ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 test_done "$testroot" "$ret"
105 (cd $testroot/wt && got unstage > $testroot/stdout)
107 if [ $ret -ne 0 ]; then
108 echo "got unstage command failed unexpectedly" >&2
109 test_done "$testroot" "1"
113 echo 'G alpha' > $testroot/stdout.expected
114 echo 'D beta' >> $testroot/stdout.expected
115 echo 'G foo' >> $testroot/stdout.expected
116 cmp -s $testroot/stdout.expected $testroot/stdout
118 if [ $ret -ne 0 ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
124 (cd $testroot/wt && got stage > /dev/null)
126 # unstaging an unversioned path is a no-op
127 (cd $testroot/wt && got unstage unversioned > $testroot/stdout)
129 if [ $ret -ne 0 ]; then
130 echo "got unstage command failed unexpectedly" >&2
131 test_done "$testroot" "$ret"
135 echo ' M alpha' > $testroot/stdout.expected
136 echo ' D beta' >> $testroot/stdout.expected
137 echo ' A foo' >> $testroot/stdout.expected
138 echo "? unversioned-file" >> $testroot/stdout.expected
139 (cd $testroot/wt && got status > $testroot/stdout)
140 cmp -s $testroot/stdout.expected $testroot/stdout
142 if [ $ret -ne 0 ]; then
143 diff -u $testroot/stdout.expected $testroot/stdout
145 test_done "$testroot" "$ret"
148 test_unstage_nonexistent() {
149 local testroot=`test_init unstage_nonexistent`
151 got checkout $testroot/repo $testroot/wt > /dev/null
153 if [ $ret -ne 0 ]; then
154 test_done "$testroot" "$ret"
158 echo "modified file" > $testroot/wt/alpha
159 (cd $testroot/wt && got rm beta > /dev/null)
160 echo "new file" > $testroot/wt/foo
161 (cd $testroot/wt && got add foo > /dev/null)
163 echo ' M alpha' > $testroot/stdout.expected
164 echo ' D beta' >> $testroot/stdout.expected
165 echo ' A foo' >> $testroot/stdout.expected
166 (cd $testroot/wt && got stage > /dev/null)
168 # unstaging a non-existent file is a no-op
169 (cd $testroot/wt && got unstage nonexistent-file > $testroot/stdout)
171 if [ $ret -ne 0 ]; then
172 echo "got unstage command failed unexpectedly" >&2
173 test_done "$testroot" "1"
177 echo -n > $testroot/stdout.expected
178 cmp -s $testroot/stdout.expected $testroot/stdout
180 if [ $ret -ne 0 ]; then
181 diff -u $testroot/stdout.expected $testroot/stdout
183 test_done "$testroot" "$ret"
186 test_unstage_patch() {
187 local testroot=`test_init unstage_patch`
189 jot 16 > $testroot/repo/numbers
190 git -C $testroot/repo add numbers
191 git_commit $testroot/repo -m "added numbers file"
192 local commit_id=`git_show_head $testroot/repo`
194 got checkout $testroot/repo $testroot/wt > /dev/null
196 if [ $ret -ne 0 ]; then
197 test_done "$testroot" "$ret"
201 ed -s $testroot/wt/numbers <<-\EOF
208 (cd $testroot/wt && got stage > /dev/null)
210 if [ $ret -ne 0 ]; then
211 echo "got stage command failed unexpectedly" >&2
212 test_done "$testroot" "1"
216 # don't unstage any hunks
217 printf "n\nn\nn\n" > $testroot/patchscript
218 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
219 numbers > $testroot/stdout)
221 if [ $ret -ne 0 ]; then
222 echo "got unstage command failed unexpectedly" >&2
223 test_done "$testroot" "1"
226 cat > $testroot/stdout.expected <<EOF
227 -----------------------------------------------
235 -----------------------------------------------
236 M numbers (change 1 of 3)
237 unstage this change? [y/n/q] n
238 -----------------------------------------------
248 -----------------------------------------------
249 M numbers (change 2 of 3)
250 unstage this change? [y/n/q] n
251 -----------------------------------------------
258 -----------------------------------------------
259 M numbers (change 3 of 3)
260 unstage this change? [y/n/q] n
262 cmp -s $testroot/stdout.expected $testroot/stdout
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
270 (cd $testroot/wt && got status > $testroot/stdout)
271 echo " M numbers" > $testroot/stdout.expected
272 cmp -s $testroot/stdout.expected $testroot/stdout
274 if [ $ret -ne 0 ]; then
275 diff -u $testroot/stdout.expected $testroot/stdout
276 test_done "$testroot" "$ret"
280 # unstage middle hunk
281 printf "n\ny\nn\n" > $testroot/patchscript
282 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
283 numbers > $testroot/stdout)
285 cat > $testroot/stdout.expected <<EOF
286 -----------------------------------------------
294 -----------------------------------------------
295 M numbers (change 1 of 3)
296 unstage this change? [y/n/q] n
297 -----------------------------------------------
307 -----------------------------------------------
308 M numbers (change 2 of 3)
309 unstage this change? [y/n/q] y
310 -----------------------------------------------
317 -----------------------------------------------
318 M numbers (change 3 of 3)
319 unstage this change? [y/n/q] n
322 cmp -s $testroot/stdout.expected $testroot/stdout
324 if [ $ret -ne 0 ]; then
325 diff -u $testroot/stdout.expected $testroot/stdout
326 test_done "$testroot" "$ret"
330 (cd $testroot/wt && got status > $testroot/stdout)
331 echo "MM numbers" > $testroot/stdout.expected
332 cmp -s $testroot/stdout.expected $testroot/stdout
334 if [ $ret -ne 0 ]; then
335 diff -u $testroot/stdout.expected $testroot/stdout
336 test_done "$testroot" "$ret"
340 (cd $testroot/wt && got diff -s > $testroot/stdout)
342 echo "diff -s $testroot/wt" > $testroot/stdout.expected
343 echo "commit - $commit_id" >> $testroot/stdout.expected
344 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
345 echo -n 'blob - ' >> $testroot/stdout.expected
346 got tree -r $testroot/repo -i -c $commit_id \
347 | grep 'numbers$' | cut -d' ' -f 1 \
348 >> $testroot/stdout.expected
349 echo -n 'blob + ' >> $testroot/stdout.expected
350 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
351 >> $testroot/stdout.expected
352 cat >> $testroot/stdout.expected <<EOF
369 cmp -s $testroot/stdout.expected $testroot/stdout
371 if [ $ret -ne 0 ]; then
372 diff -u $testroot/stdout.expected $testroot/stdout
373 test_done "$testroot" "$ret"
377 (cd $testroot/wt && got diff > $testroot/stdout)
378 echo "diff $testroot/wt" > $testroot/stdout.expected
379 echo "commit - $commit_id" >> $testroot/stdout.expected
380 echo "path + $testroot/wt" >> $testroot/stdout.expected
381 echo -n 'blob - ' >> $testroot/stdout.expected
382 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
383 tr -d '\n' >> $testroot/stdout.expected
384 echo " (staged)" >> $testroot/stdout.expected
385 echo "file + numbers" >> $testroot/stdout.expected
386 cat >> $testroot/stdout.expected <<EOF
399 cmp -s $testroot/stdout.expected $testroot/stdout
401 if [ $ret -ne 0 ]; then
402 diff -u $testroot/stdout.expected $testroot/stdout
403 test_done "$testroot" "$ret"
407 (cd $testroot/wt && got stage >/dev/null)
409 if [ $ret -ne 0 ]; then
410 echo "got stage command failed unexpectedly" >&2
411 test_done "$testroot" "1"
415 (cd $testroot/wt && got status > $testroot/stdout)
416 echo " M numbers" > $testroot/stdout.expected
417 cmp -s $testroot/stdout.expected $testroot/stdout
419 if [ $ret -ne 0 ]; then
420 diff -u $testroot/stdout.expected $testroot/stdout
421 test_done "$testroot" "$ret"
426 printf "n\nn\ny\n" > $testroot/patchscript
427 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
428 numbers > $testroot/stdout)
430 cat > $testroot/stdout.expected <<EOF
431 -----------------------------------------------
439 -----------------------------------------------
440 M numbers (change 1 of 3)
441 unstage this change? [y/n/q] n
442 -----------------------------------------------
452 -----------------------------------------------
453 M numbers (change 2 of 3)
454 unstage this change? [y/n/q] n
455 -----------------------------------------------
462 -----------------------------------------------
463 M numbers (change 3 of 3)
464 unstage this change? [y/n/q] y
467 cmp -s $testroot/stdout.expected $testroot/stdout
469 if [ $ret -ne 0 ]; then
470 diff -u $testroot/stdout.expected $testroot/stdout
471 test_done "$testroot" "$ret"
475 (cd $testroot/wt && got status > $testroot/stdout)
476 echo "MM numbers" > $testroot/stdout.expected
477 cmp -s $testroot/stdout.expected $testroot/stdout
479 if [ $ret -ne 0 ]; then
480 diff -u $testroot/stdout.expected $testroot/stdout
481 test_done "$testroot" "$ret"
485 (cd $testroot/wt && got diff -s > $testroot/stdout)
487 echo "diff -s $testroot/wt" > $testroot/stdout.expected
488 echo "commit - $commit_id" >> $testroot/stdout.expected
489 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
490 echo -n 'blob - ' >> $testroot/stdout.expected
491 got tree -r $testroot/repo -i -c $commit_id \
492 | grep 'numbers$' | cut -d' ' -f 1 \
493 >> $testroot/stdout.expected
494 echo -n 'blob + ' >> $testroot/stdout.expected
495 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
496 >> $testroot/stdout.expected
497 cat >> $testroot/stdout.expected <<EOF
514 cmp -s $testroot/stdout.expected $testroot/stdout
516 if [ $ret -ne 0 ]; then
517 diff -u $testroot/stdout.expected $testroot/stdout
518 test_done "$testroot" "$ret"
522 (cd $testroot/wt && got diff > $testroot/stdout)
523 echo "diff $testroot/wt" > $testroot/stdout.expected
524 echo "commit - $commit_id" >> $testroot/stdout.expected
525 echo "path + $testroot/wt" >> $testroot/stdout.expected
526 echo -n 'blob - ' >> $testroot/stdout.expected
527 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
528 tr -d '\n' >> $testroot/stdout.expected
529 echo " (staged)" >> $testroot/stdout.expected
530 echo "file + numbers" >> $testroot/stdout.expected
531 cat >> $testroot/stdout.expected <<EOF
541 cmp -s $testroot/stdout.expected $testroot/stdout
543 if [ $ret -ne 0 ]; then
544 diff -u $testroot/stdout.expected $testroot/stdout
545 test_done "$testroot" "$ret"
549 (cd $testroot/wt && got stage >/dev/null)
551 if [ $ret -ne 0 ]; then
552 echo "got stage command failed unexpectedly" >&2
553 test_done "$testroot" "1"
557 (cd $testroot/wt && got status > $testroot/stdout)
558 echo " M numbers" > $testroot/stdout.expected
559 cmp -s $testroot/stdout.expected $testroot/stdout
561 if [ $ret -ne 0 ]; then
562 diff -u $testroot/stdout.expected $testroot/stdout
563 test_done "$testroot" "$ret"
568 printf "y\ny\ny\n" > $testroot/patchscript
569 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
570 numbers > $testroot/stdout)
572 cat > $testroot/stdout.expected <<EOF
573 -----------------------------------------------
581 -----------------------------------------------
582 M numbers (change 1 of 3)
583 unstage this change? [y/n/q] y
584 -----------------------------------------------
594 -----------------------------------------------
595 M numbers (change 2 of 3)
596 unstage this change? [y/n/q] y
597 -----------------------------------------------
604 -----------------------------------------------
605 M numbers (change 3 of 3)
606 unstage this change? [y/n/q] y
609 cmp -s $testroot/stdout.expected $testroot/stdout
611 if [ $ret -ne 0 ]; then
612 diff -u $testroot/stdout.expected $testroot/stdout
613 test_done "$testroot" "$ret"
617 (cd $testroot/wt && got status > $testroot/stdout)
618 echo "M numbers" > $testroot/stdout.expected
619 cmp -s $testroot/stdout.expected $testroot/stdout
621 if [ $ret -ne 0 ]; then
622 diff -u $testroot/stdout.expected $testroot/stdout
623 test_done "$testroot" "$ret"
627 (cd $testroot/wt && got diff -s > $testroot/stdout)
628 echo -n > $testroot/stdout.expected
629 cmp -s $testroot/stdout.expected $testroot/stdout
631 if [ $ret -ne 0 ]; then
632 diff -u $testroot/stdout.expected $testroot/stdout
633 test_done "$testroot" "$ret"
637 (cd $testroot/wt && got diff > $testroot/stdout)
639 echo "diff $testroot/wt" > $testroot/stdout.expected
640 echo "commit - $commit_id" >> $testroot/stdout.expected
641 echo "path + $testroot/wt" >> $testroot/stdout.expected
642 echo -n 'blob - ' >> $testroot/stdout.expected
643 got tree -r $testroot/repo -i -c $commit_id \
644 | grep 'numbers$' | cut -d' ' -f 1 \
645 >> $testroot/stdout.expected
646 echo 'file + numbers' >> $testroot/stdout.expected
647 cat >> $testroot/stdout.expected <<EOF
670 cmp -s $testroot/stdout.expected $testroot/stdout
672 if [ $ret -ne 0 ]; then
673 diff -u $testroot/stdout.expected $testroot/stdout
675 test_done "$testroot" "$ret"
679 test_unstage_patch_added() {
680 local testroot=`test_init unstage_patch_added`
681 local commit_id=`git_show_head $testroot/repo`
683 got checkout $testroot/repo $testroot/wt > /dev/null
685 if [ $ret -ne 0 ]; then
686 test_done "$testroot" "$ret"
690 echo "new" > $testroot/wt/epsilon/new
691 (cd $testroot/wt && got add epsilon/new > /dev/null)
693 (cd $testroot/wt && got stage > /dev/null)
695 printf "y\n" > $testroot/patchscript
696 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
697 epsilon/new > $testroot/stdout)
699 echo "A epsilon/new" > $testroot/stdout.expected
700 echo "unstage this addition? [y/n] y" >> $testroot/stdout.expected
701 echo "G epsilon/new" >> $testroot/stdout.expected
702 cmp -s $testroot/stdout.expected $testroot/stdout
704 if [ $ret -ne 0 ]; then
705 diff -u $testroot/stdout.expected $testroot/stdout
706 test_done "$testroot" "$ret"
710 (cd $testroot/wt && got status > $testroot/stdout)
711 echo "A epsilon/new" > $testroot/stdout.expected
712 cmp -s $testroot/stdout.expected $testroot/stdout
714 if [ $ret -ne 0 ]; then
715 diff -u $testroot/stdout.expected $testroot/stdout
716 test_done "$testroot" "$ret"
720 (cd $testroot/wt && got diff -s > $testroot/stdout)
721 echo -n > $testroot/stdout.expected
722 cmp -s $testroot/stdout.expected $testroot/stdout
724 if [ $ret -ne 0 ]; then
725 diff -u $testroot/stdout.expected $testroot/stdout
726 test_done "$testroot" "$ret"
730 (cd $testroot/wt && got diff > $testroot/stdout)
732 echo "diff $testroot/wt" > $testroot/stdout.expected
733 echo "commit - $commit_id" >> $testroot/stdout.expected
734 echo "path + $testroot/wt" >> $testroot/stdout.expected
735 echo 'blob - /dev/null' >> $testroot/stdout.expected
736 echo 'file + epsilon/new (mode 644)' >> $testroot/stdout.expected
737 echo "--- /dev/null" >> $testroot/stdout.expected
738 echo "+++ epsilon/new" >> $testroot/stdout.expected
739 echo "@@ -0,0 +1 @@" >> $testroot/stdout.expected
740 echo "+new" >> $testroot/stdout.expected
741 cmp -s $testroot/stdout.expected $testroot/stdout
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/stdout.expected $testroot/stdout
746 test_done "$testroot" "$ret"
749 test_unstage_patch_removed() {
750 local testroot=`test_init unstage_patch_removed`
751 local commit_id=`git_show_head $testroot/repo`
753 got checkout $testroot/repo $testroot/wt > /dev/null
755 if [ $ret -ne 0 ]; then
756 test_done "$testroot" "$ret"
760 (cd $testroot/wt && got rm beta > /dev/null)
761 (cd $testroot/wt && got stage > /dev/null)
763 printf "y\n" > $testroot/patchscript
764 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
765 beta > $testroot/stdout)
767 echo "D beta" > $testroot/stdout.expected
768 echo "unstage this deletion? [y/n] y" >> $testroot/stdout.expected
769 echo "D beta" >> $testroot/stdout.expected
770 cmp -s $testroot/stdout.expected $testroot/stdout
772 if [ $ret -ne 0 ]; then
773 diff -u $testroot/stdout.expected $testroot/stdout
774 test_done "$testroot" "$ret"
778 (cd $testroot/wt && got status > $testroot/stdout)
779 echo "D beta" > $testroot/stdout.expected
780 cmp -s $testroot/stdout.expected $testroot/stdout
782 if [ $ret -ne 0 ]; then
783 diff -u $testroot/stdout.expected $testroot/stdout
784 test_done "$testroot" "$ret"
788 (cd $testroot/wt && got diff -s > $testroot/stdout)
789 echo -n > $testroot/stdout.expected
790 cmp -s $testroot/stdout.expected $testroot/stdout
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/stdout.expected $testroot/stdout
794 test_done "$testroot" "$ret"
798 (cd $testroot/wt && got diff > $testroot/stdout)
800 echo "diff $testroot/wt" > $testroot/stdout.expected
801 echo "commit - $commit_id" >> $testroot/stdout.expected
802 echo "path + $testroot/wt" >> $testroot/stdout.expected
803 echo -n 'blob - ' >> $testroot/stdout.expected
804 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
805 >> $testroot/stdout.expected
806 echo 'file + /dev/null' >> $testroot/stdout.expected
807 echo "--- beta" >> $testroot/stdout.expected
808 echo "+++ /dev/null" >> $testroot/stdout.expected
809 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
810 echo "-beta" >> $testroot/stdout.expected
811 cmp -s $testroot/stdout.expected $testroot/stdout
813 if [ $ret -ne 0 ]; then
814 diff -u $testroot/stdout.expected $testroot/stdout
816 test_done "$testroot" "$ret"
819 test_unstage_patch_quit() {
820 local testroot=`test_init unstage_patch_quit`
822 jot 16 > $testroot/repo/numbers
823 echo zzz > $testroot/repo/zzz
824 git -C $testroot/repo add numbers zzz
825 git_commit $testroot/repo -m "added files"
826 local commit_id=`git_show_head $testroot/repo`
828 got checkout $testroot/repo $testroot/wt > /dev/null
830 if [ $ret -ne 0 ]; then
831 test_done "$testroot" "$ret"
835 ed -s $testroot/wt/numbers <<-\EOF
841 (cd $testroot/wt && got rm zzz > /dev/null)
842 (cd $testroot/wt && got stage > /dev/null)
844 # unstage first hunk and quit; and don't pass a path argument to
845 # ensure that we don't skip asking about the 'zzz' file after 'quit'
846 printf "y\nq\nn\n" > $testroot/patchscript
847 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
850 if [ $ret -ne 0 ]; then
851 echo "got unstage command failed unexpectedly" >&2
852 test_done "$testroot" "1"
855 cat > $testroot/stdout.expected <<EOF
856 -----------------------------------------------
864 -----------------------------------------------
865 M numbers (change 1 of 3)
866 unstage this change? [y/n/q] y
867 -----------------------------------------------
877 -----------------------------------------------
878 M numbers (change 2 of 3)
879 unstage this change? [y/n/q] q
882 unstage this deletion? [y/n] n
884 cmp -s $testroot/stdout.expected $testroot/stdout
886 if [ $ret -ne 0 ]; then
887 diff -u $testroot/stdout.expected $testroot/stdout
888 test_done "$testroot" "$ret"
892 (cd $testroot/wt && got status > $testroot/stdout)
893 echo "MM numbers" > $testroot/stdout.expected
894 echo " D zzz" >> $testroot/stdout.expected
895 cmp -s $testroot/stdout.expected $testroot/stdout
897 if [ $ret -ne 0 ]; then
898 diff -u $testroot/stdout.expected $testroot/stdout
899 test_done "$testroot" "$ret"
903 (cd $testroot/wt && got diff > $testroot/stdout)
905 echo "diff $testroot/wt" > $testroot/stdout.expected
906 echo "commit - $commit_id" >> $testroot/stdout.expected
907 echo "path + $testroot/wt" >> $testroot/stdout.expected
908 echo -n 'blob - ' >> $testroot/stdout.expected
909 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
910 tr -d '\n' >> $testroot/stdout.expected
911 echo " (staged)" >> $testroot/stdout.expected
912 echo "file + numbers" >> $testroot/stdout.expected
913 echo "--- numbers" >> $testroot/stdout.expected
914 echo "+++ numbers" >> $testroot/stdout.expected
915 echo "@@ -1,5 +1,5 @@" >> $testroot/stdout.expected
916 echo " 1" >> $testroot/stdout.expected
917 echo "-2" >> $testroot/stdout.expected
918 echo "+a" >> $testroot/stdout.expected
919 echo " 3" >> $testroot/stdout.expected
920 echo " 4" >> $testroot/stdout.expected
921 echo " 5" >> $testroot/stdout.expected
922 cmp -s $testroot/stdout.expected $testroot/stdout
924 if [ $ret -ne 0 ]; then
925 diff -u $testroot/stdout.expected $testroot/stdout
926 test_done "$testroot" "$ret"
930 (cd $testroot/wt && got diff -s > $testroot/stdout)
931 echo "diff -s $testroot/wt" > $testroot/stdout.expected
932 echo "commit - $commit_id" >> $testroot/stdout.expected
933 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
934 echo -n 'blob - ' >> $testroot/stdout.expected
935 got tree -r $testroot/repo -i -c $commit_id \
936 | grep 'numbers$' | cut -d' ' -f 1 \
937 >> $testroot/stdout.expected
938 echo -n 'blob + ' >> $testroot/stdout.expected
939 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
940 >> $testroot/stdout.expected
941 cat >> $testroot/stdout.expected <<EOF
960 echo -n 'blob - ' >> $testroot/stdout.expected
961 got tree -r $testroot/repo -i | grep 'zzz$' | cut -d' ' -f 1 \
962 >> $testroot/stdout.expected
963 echo 'blob + /dev/null' >> $testroot/stdout.expected
964 echo "--- zzz" >> $testroot/stdout.expected
965 echo "+++ /dev/null" >> $testroot/stdout.expected
966 echo "@@ -1 +0,0 @@" >> $testroot/stdout.expected
967 echo "-zzz" >> $testroot/stdout.expected
968 cmp -s $testroot/stdout.expected $testroot/stdout
970 if [ $ret -ne 0 ]; then
971 diff -u $testroot/stdout.expected $testroot/stdout
973 test_done "$testroot" "$ret"
976 test_unstage_symlink() {
977 local testroot=`test_init unstage_symlink`
979 (cd $testroot/repo && ln -s alpha alpha.link)
980 (cd $testroot/repo && ln -s epsilon epsilon.link)
981 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
982 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
983 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
984 git -C $testroot/repo add .
985 git_commit $testroot/repo -m "add symlinks"
986 local head_commit=`git_show_head $testroot/repo`
988 got checkout $testroot/repo $testroot/wt > /dev/null
990 if [ $ret -ne 0 ]; then
991 test_done "$testroot" "$ret"
995 (cd $testroot/wt && ln -sf beta alpha.link)
996 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
997 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
998 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
999 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
1000 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1001 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1002 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1003 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1004 (cd $testroot/wt && got add zeta.link > /dev/null)
1006 (cd $testroot/wt && got stage -S > /dev/null)
1008 (cd $testroot/wt && got status > $testroot/stdout)
1009 cat > $testroot/stdout.expected <<EOF
1018 cmp -s $testroot/stdout.expected $testroot/stdout
1020 if [ $ret -ne 0 ]; then
1021 diff -u $testroot/stdout.expected $testroot/stdout
1022 test_done "$testroot" "$ret"
1026 (cd $testroot/wt && got unstage > $testroot/stdout)
1028 if [ $ret -ne 0 ]; then
1029 echo "got unstage command failed unexpectedly" >&2
1030 test_done "$testroot" "1"
1034 cat > $testroot/stdout.expected <<EOF
1044 cmp -s $testroot/stdout.expected $testroot/stdout
1046 if [ $ret -ne 0 ]; then
1047 diff -u $testroot/stdout.expected $testroot/stdout
1048 test_done "$testroot" "$ret"
1052 if [ ! -h $testroot/wt/alpha.link ]; then
1053 echo "alpha.link is not a symlink"
1054 test_done "$testroot" "1"
1058 readlink $testroot/wt/alpha.link > $testroot/stdout
1059 echo "beta" > $testroot/stdout.expected
1060 cmp -s $testroot/stdout.expected $testroot/stdout
1062 if [ $ret -ne 0 ]; then
1063 diff -u $testroot/stdout.expected $testroot/stdout
1064 test_done "$testroot" "$ret"
1068 if [ ! -h $testroot/wt/epsilon.link ]; then
1069 echo "epsilon.link is not a symlink"
1070 test_done "$testroot" "1"
1074 readlink $testroot/wt/epsilon.link > $testroot/stdout
1075 echo "gamma" > $testroot/stdout.expected
1076 cmp -s $testroot/stdout.expected $testroot/stdout
1078 if [ $ret -ne 0 ]; then
1079 diff -u $testroot/stdout.expected $testroot/stdout
1080 test_done "$testroot" "$ret"
1084 if [ ! -h $testroot/wt/epsilon/beta.link ]; then
1085 echo "epsilon/beta.link is not a symlink"
1086 test_done "$testroot" "1"
1090 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1091 echo "../gamma/delta" > $testroot/stdout.expected
1092 cmp -s $testroot/stdout.expected $testroot/stdout
1094 if [ $ret -ne 0 ]; then
1095 diff -u $testroot/stdout.expected $testroot/stdout
1096 test_done "$testroot" "$ret"
1100 if [ ! -f $testroot/wt/dotgotfoo.link ]; then
1101 echo "dotgotfoo.link is a symlink"
1102 test_done "$testroot" "1"
1106 echo "this is regular file foo" > $testroot/content.expected
1107 cp $testroot/wt/dotgotfoo.link $testroot/content
1108 cmp -s $testroot/content.expected $testroot/content
1110 if [ $ret -ne 0 ]; then
1111 diff -u $testroot/content.expected $testroot/content
1112 test_done "$testroot" "$ret"
1116 # bad symlinks are allowed as-is for commit and stage/unstage
1117 if [ ! -h $testroot/wt/dotgotbar.link ]; then
1118 echo "dotgotbar.link is not a symlink"
1119 test_done "$testroot" "1"
1123 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
1124 echo ".got/bar" > $testroot/stdout.expected
1125 cmp -s $testroot/stdout.expected $testroot/stdout
1127 if [ $ret -ne 0 ]; then
1128 diff -u $testroot/stdout.expected $testroot/stdout
1129 test_done "$testroot" "$ret"
1133 if [ -e $testroot/wt/nonexistent.link ]; then
1134 echo "nonexistent.link exists on disk"
1135 test_done "$testroot" "1"
1139 if [ ! -h $testroot/wt/zeta.link ]; then
1140 echo "zeta.link is not a symlink"
1141 test_done "$testroot" "1"
1145 readlink $testroot/wt/zeta.link > $testroot/stdout
1146 echo "gamma/delta" > $testroot/stdout.expected
1147 cmp -s $testroot/stdout.expected $testroot/stdout
1149 if [ $ret -ne 0 ]; then
1150 diff -u $testroot/stdout.expected $testroot/stdout
1151 test_done "$testroot" "$ret"
1155 test_done "$testroot" "0"
1158 test_unstage_patch_symlink() {
1159 local testroot=`test_init unstage_patch_symlink`
1161 (cd $testroot/repo && ln -s alpha alpha.link)
1162 (cd $testroot/repo && ln -s epsilon epsilon.link)
1163 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1164 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1165 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1166 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1167 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1168 git -C $testroot/repo add .
1169 git_commit $testroot/repo -m "add symlinks"
1170 local commit_id1=`git_show_head $testroot/repo`
1172 got checkout $testroot/repo $testroot/wt > /dev/null
1174 if [ $ret -ne 0 ]; then
1175 test_done "$testroot" "$ret"
1179 # symlink to file A now points to file B
1180 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1181 # symlink to a directory A now points to file B
1182 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1183 # "bad" symlink now contains a different target path
1184 echo "foo" > $testroot/wt/passwd.link
1185 # relative symlink to directory A now points to relative directory B
1186 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1188 # an unversioned symlink
1189 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1190 # symlink to file A now points to non-existent file B
1191 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1193 (cd $testroot/wt && got rm zeta.link > /dev/null)
1194 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1196 (cd $testroot/wt && ln -sf beta new.link)
1197 (cd $testroot/wt && got add new.link > /dev/null)
1198 (cd $testroot/wt && ln -sf beta zeta3.link)
1199 (cd $testroot/wt && got add zeta3.link > /dev/null)
1201 (cd $testroot/wt && got stage -S > /dev/null)
1203 (cd $testroot/wt && got status > $testroot/stdout)
1204 cat > $testroot/stdout.expected <<EOF
1216 cmp -s $testroot/stdout.expected $testroot/stdout
1218 if [ $ret -ne 0 ]; then
1219 diff -u $testroot/stdout.expected $testroot/stdout
1220 test_done "$testroot" "$ret"
1224 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1225 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1228 if [ $ret -ne 0 ]; then
1229 echo "got unstage command failed unexpectedly" >&2
1230 test_done "$testroot" "1"
1234 cat > $testroot/stdout.expected <<EOF
1235 -----------------------------------------------
1238 \ No newline at end of file
1240 \ No newline at end of file
1241 -----------------------------------------------
1242 M alpha.link (change 1 of 1)
1243 unstage this change? [y/n/q] y
1245 -----------------------------------------------
1248 \ No newline at end of file
1250 \ No newline at end of file
1251 -----------------------------------------------
1252 M epsilon/beta.link (change 1 of 1)
1253 unstage this change? [y/n/q] n
1254 -----------------------------------------------
1257 \ No newline at end of file
1259 \ No newline at end of file
1260 -----------------------------------------------
1261 M epsilon.link (change 1 of 1)
1262 unstage this change? [y/n/q] y
1265 unstage this addition? [y/n] n
1266 -----------------------------------------------
1269 \ No newline at end of file
1271 \ No newline at end of file
1272 -----------------------------------------------
1273 M nonexistent.link (change 1 of 1)
1274 unstage this change? [y/n/q] y
1276 -----------------------------------------------
1279 \ No newline at end of file
1281 -----------------------------------------------
1282 M passwd.link (change 1 of 1)
1283 unstage this change? [y/n/q] y
1286 unstage this deletion? [y/n] n
1288 unstage this deletion? [y/n] y
1291 unstage this addition? [y/n] y
1294 cmp -s $testroot/stdout.expected $testroot/stdout
1296 if [ $ret -ne 0 ]; then
1297 diff -u $testroot/stdout.expected $testroot/stdout
1298 test_done "$testroot" "$ret"
1302 if ! [ -h $testroot/wt/alpha.link ]; then
1303 echo "alpha.link is not a symlink"
1304 test_done "$testroot" "1"
1308 readlink $testroot/wt/alpha.link > $testroot/stdout
1309 echo "gamma/delta" > $testroot/stdout.expected
1310 cmp -s $testroot/stdout.expected $testroot/stdout
1312 if [ $ret -ne 0 ]; then
1313 diff -u $testroot/stdout.expected $testroot/stdout
1314 test_done "$testroot" "$ret"
1318 if ! [ -h $testroot/wt/epsilon.link ]; then
1319 echo "epsilon.link is not a symlink"
1320 test_done "$testroot" "1"
1324 readlink $testroot/wt/epsilon.link > $testroot/stdout
1325 echo "beta" > $testroot/stdout.expected
1326 cmp -s $testroot/stdout.expected $testroot/stdout
1328 if [ $ret -ne 0 ]; then
1329 diff -u $testroot/stdout.expected $testroot/stdout
1330 test_done "$testroot" "$ret"
1334 if [ -h $testroot/wt/passwd.link ]; then
1335 echo "passwd.link should not be a symlink" >&2
1336 test_done "$testroot" "1"
1340 echo "foo" > $testroot/content.expected
1341 cp $testroot/wt/passwd.link $testroot/content
1343 cmp -s $testroot/content.expected $testroot/content
1345 if [ $ret -ne 0 ]; then
1346 diff -u $testroot/content.expected $testroot/content
1347 test_done "$testroot" "$ret"
1351 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1352 echo "../gamma" > $testroot/stdout.expected
1353 cmp -s $testroot/stdout.expected $testroot/stdout
1355 if [ $ret -ne 0 ]; then
1356 diff -u $testroot/stdout.expected $testroot/stdout
1357 test_done "$testroot" "$ret"
1361 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1362 echo "nonexistent2" > $testroot/stdout.expected
1363 cmp -s $testroot/stdout.expected $testroot/stdout
1365 if [ $ret -ne 0 ]; then
1366 diff -u $testroot/stdout.expected $testroot/stdout
1367 test_done "$testroot" "$ret"
1371 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1372 echo "dotgotfoo.link is not a symlink " >&2
1373 test_done "$testroot" "1"
1376 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1377 echo ".got/foo" > $testroot/stdout.expected
1378 cmp -s $testroot/stdout.expected $testroot/stdout
1380 if [ $ret -ne 0 ]; then
1381 diff -u $testroot/stdout.expected $testroot/stdout
1382 test_done "$testroot" "$ret"
1387 if [ -e $testroot/wt/zeta.link ]; then
1388 echo -n "zeta.link should not exist on disk" >&2
1389 test_done "$testroot" "1"
1393 if [ -e $testroot/wt/zeta2.link ]; then
1394 echo -n "zeta2.link exists on disk" >&2
1395 test_done "$testroot" "1"
1399 if [ ! -h $testroot/wt/zeta3.link ]; then
1400 echo -n "zeta3.link is not a symlink" >&2
1401 test_done "$testroot" "1"
1405 readlink $testroot/wt/zeta3.link > $testroot/stdout
1406 echo "beta" > $testroot/stdout.expected
1407 cmp -s $testroot/stdout.expected $testroot/stdout
1409 if [ $ret -ne 0 ]; then
1410 diff -u $testroot/stdout.expected $testroot/stdout
1411 test_done "$testroot" "$ret"
1415 if [ ! -h $testroot/wt/new.link ]; then
1416 echo -n "new.link is not a symlink" >&2
1417 test_done "$testroot" "1"
1421 (cd $testroot/wt && got status > $testroot/stdout)
1422 echo "M alpha.link" > $testroot/stdout.expected
1423 echo "? dotgotfoo.link" >> $testroot/stdout.expected
1424 echo " M epsilon/beta.link" >> $testroot/stdout.expected
1425 echo "M epsilon.link" >> $testroot/stdout.expected
1426 echo " A new.link" >> $testroot/stdout.expected
1427 echo "M nonexistent.link" >> $testroot/stdout.expected
1428 echo "M passwd.link" >> $testroot/stdout.expected
1429 echo " D zeta.link" >> $testroot/stdout.expected
1430 echo "D zeta2.link" >> $testroot/stdout.expected
1431 echo "A zeta3.link" >> $testroot/stdout.expected
1432 cmp -s $testroot/stdout.expected $testroot/stdout
1434 if [ $ret -ne 0 ]; then
1435 diff -u $testroot/stdout.expected $testroot/stdout
1438 test_done "$testroot" "$ret"
1442 run_test test_unstage_basic
1443 run_test test_unstage_unversioned
1444 run_test test_unstage_nonexistent
1445 run_test test_unstage_patch
1446 run_test test_unstage_patch_added
1447 run_test test_unstage_patch_removed
1448 run_test test_unstage_patch_quit
1449 run_test test_unstage_symlink
1450 run_test test_unstage_patch_symlink