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 -R > $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_directory() {
71 local testroot=`test_init unstage_directory`
73 got checkout $testroot/repo $testroot/wt > /dev/null
75 if [ $ret -ne 0 ]; then
76 test_done "$testroot" "$ret"
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)
85 echo "got: unstaging directories requires -R option" \
86 > $testroot/stderr.expected
87 cmp -s $testroot/stderr.expected $testroot/stderr
89 if [ $ret -ne 0 ]; then
90 diff -u $testroot/stderr.expected $testroot/stderr
91 test_done "$testroot" "$ret"
95 (cd $testroot/wt && got unstage -R . > $testroot/stdout)
97 echo 'G test' >> $testroot/stdout.expected
99 cmp -s $testroot/stdout.expected $testroot/stdout
101 if [ $ret -ne 0 ]; then
102 diff -u $testroot/stdout.expected $testroot/stdout
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
112 if [ $ret -ne 0 ]; then
113 test_done "$testroot" "$ret"
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
136 if [ $ret -ne 0 ]; then
137 diff -u $testroot/stdout.expected $testroot/stdout
138 test_done "$testroot" "$ret"
142 (cd $testroot/wt && got unstage -R > $testroot/stdout)
144 if [ $ret -ne 0 ]; then
145 echo "got unstage command failed unexpectedly" >&2
146 test_done "$testroot" "1"
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
155 if [ $ret -ne 0 ]; then
156 diff -u $testroot/stdout.expected $testroot/stdout
157 test_done "$testroot" "$ret"
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)
166 if [ $ret -ne 0 ]; then
167 echo "got unstage command failed unexpectedly" >&2
168 test_done "$testroot" "$ret"
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
179 if [ $ret -ne 0 ]; then
180 diff -u $testroot/stdout.expected $testroot/stdout
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
190 if [ $ret -ne 0 ]; then
191 test_done "$testroot" "$ret"
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)
208 if [ $ret -ne 0 ]; then
209 echo "got unstage command failed unexpectedly" >&2
210 test_done "$testroot" "1"
214 echo -n > $testroot/stdout.expected
215 cmp -s $testroot/stdout.expected $testroot/stdout
217 if [ $ret -ne 0 ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
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
233 if [ $ret -ne 0 ]; then
234 test_done "$testroot" "$ret"
238 ed -s $testroot/wt/numbers <<-\EOF
245 (cd $testroot/wt && got stage -R > /dev/null)
247 if [ $ret -ne 0 ]; then
248 echo "got stage command failed unexpectedly" >&2
249 test_done "$testroot" "1"
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)
258 if [ $ret -ne 0 ]; then
259 echo "got unstage command failed unexpectedly" >&2
260 test_done "$testroot" "1"
263 cat > $testroot/stdout.expected <<EOF
264 -----------------------------------------------
272 -----------------------------------------------
273 M numbers (change 1 of 3)
274 unstage this change? [y/n/q] n
275 -----------------------------------------------
285 -----------------------------------------------
286 M numbers (change 2 of 3)
287 unstage this change? [y/n/q] n
288 -----------------------------------------------
295 -----------------------------------------------
296 M numbers (change 3 of 3)
297 unstage this change? [y/n/q] n
299 cmp -s $testroot/stdout.expected $testroot/stdout
301 if [ $ret -ne 0 ]; then
302 diff -u $testroot/stdout.expected $testroot/stdout
303 test_done "$testroot" "$ret"
307 (cd $testroot/wt && got status > $testroot/stdout)
308 echo " M numbers" > $testroot/stdout.expected
309 cmp -s $testroot/stdout.expected $testroot/stdout
311 if [ $ret -ne 0 ]; then
312 diff -u $testroot/stdout.expected $testroot/stdout
313 test_done "$testroot" "$ret"
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 -----------------------------------------------
331 -----------------------------------------------
332 M numbers (change 1 of 3)
333 unstage this change? [y/n/q] n
334 -----------------------------------------------
344 -----------------------------------------------
345 M numbers (change 2 of 3)
346 unstage this change? [y/n/q] y
347 -----------------------------------------------
354 -----------------------------------------------
355 M numbers (change 3 of 3)
356 unstage this change? [y/n/q] n
359 cmp -s $testroot/stdout.expected $testroot/stdout
361 if [ $ret -ne 0 ]; then
362 diff -u $testroot/stdout.expected $testroot/stdout
363 test_done "$testroot" "$ret"
367 (cd $testroot/wt && got status > $testroot/stdout)
368 echo "MM numbers" > $testroot/stdout.expected
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 -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
406 cmp -s $testroot/stdout.expected $testroot/stdout
408 if [ $ret -ne 0 ]; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
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
436 cmp -s $testroot/stdout.expected $testroot/stdout
438 if [ $ret -ne 0 ]; then
439 diff -u $testroot/stdout.expected $testroot/stdout
440 test_done "$testroot" "$ret"
444 (cd $testroot/wt && got stage -R >/dev/null)
446 if [ $ret -ne 0 ]; then
447 echo "got stage command failed unexpectedly" >&2
448 test_done "$testroot" "1"
452 (cd $testroot/wt && got status > $testroot/stdout)
453 echo " M numbers" > $testroot/stdout.expected
454 cmp -s $testroot/stdout.expected $testroot/stdout
456 if [ $ret -ne 0 ]; then
457 diff -u $testroot/stdout.expected $testroot/stdout
458 test_done "$testroot" "$ret"
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 -----------------------------------------------
476 -----------------------------------------------
477 M numbers (change 1 of 3)
478 unstage this change? [y/n/q] n
479 -----------------------------------------------
489 -----------------------------------------------
490 M numbers (change 2 of 3)
491 unstage this change? [y/n/q] n
492 -----------------------------------------------
499 -----------------------------------------------
500 M numbers (change 3 of 3)
501 unstage this change? [y/n/q] y
504 cmp -s $testroot/stdout.expected $testroot/stdout
506 if [ $ret -ne 0 ]; then
507 diff -u $testroot/stdout.expected $testroot/stdout
508 test_done "$testroot" "$ret"
512 (cd $testroot/wt && got status > $testroot/stdout)
513 echo "MM numbers" > $testroot/stdout.expected
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 -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
551 cmp -s $testroot/stdout.expected $testroot/stdout
553 if [ $ret -ne 0 ]; then
554 diff -u $testroot/stdout.expected $testroot/stdout
555 test_done "$testroot" "$ret"
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
578 cmp -s $testroot/stdout.expected $testroot/stdout
580 if [ $ret -ne 0 ]; then
581 diff -u $testroot/stdout.expected $testroot/stdout
582 test_done "$testroot" "$ret"
586 (cd $testroot/wt && got stage -R >/dev/null)
588 if [ $ret -ne 0 ]; then
589 echo "got stage command failed unexpectedly" >&2
590 test_done "$testroot" "1"
594 (cd $testroot/wt && got status > $testroot/stdout)
595 echo " M numbers" > $testroot/stdout.expected
596 cmp -s $testroot/stdout.expected $testroot/stdout
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 test_done "$testroot" "$ret"
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 -----------------------------------------------
618 -----------------------------------------------
619 M numbers (change 1 of 3)
620 unstage this change? [y/n/q] y
621 -----------------------------------------------
631 -----------------------------------------------
632 M numbers (change 2 of 3)
633 unstage this change? [y/n/q] y
634 -----------------------------------------------
641 -----------------------------------------------
642 M numbers (change 3 of 3)
643 unstage this change? [y/n/q] y
646 cmp -s $testroot/stdout.expected $testroot/stdout
648 if [ $ret -ne 0 ]; then
649 diff -u $testroot/stdout.expected $testroot/stdout
650 test_done "$testroot" "$ret"
654 (cd $testroot/wt && got status > $testroot/stdout)
655 echo "M numbers" > $testroot/stdout.expected
656 cmp -s $testroot/stdout.expected $testroot/stdout
658 if [ $ret -ne 0 ]; then
659 diff -u $testroot/stdout.expected $testroot/stdout
660 test_done "$testroot" "$ret"
664 (cd $testroot/wt && got diff -s > $testroot/stdout)
665 echo -n > $testroot/stdout.expected
666 cmp -s $testroot/stdout.expected $testroot/stdout
668 if [ $ret -ne 0 ]; then
669 diff -u $testroot/stdout.expected $testroot/stdout
670 test_done "$testroot" "$ret"
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
707 cmp -s $testroot/stdout.expected $testroot/stdout
709 if [ $ret -ne 0 ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
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
722 if [ $ret -ne 0 ]; then
723 test_done "$testroot" "$ret"
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
741 if [ $ret -ne 0 ]; then
742 diff -u $testroot/stdout.expected $testroot/stdout
743 test_done "$testroot" "$ret"
747 (cd $testroot/wt && got status > $testroot/stdout)
748 echo "A epsilon/new" > $testroot/stdout.expected
749 cmp -s $testroot/stdout.expected $testroot/stdout
751 if [ $ret -ne 0 ]; then
752 diff -u $testroot/stdout.expected $testroot/stdout
753 test_done "$testroot" "$ret"
757 (cd $testroot/wt && got diff -s > $testroot/stdout)
758 echo -n > $testroot/stdout.expected
759 cmp -s $testroot/stdout.expected $testroot/stdout
761 if [ $ret -ne 0 ]; then
762 diff -u $testroot/stdout.expected $testroot/stdout
763 test_done "$testroot" "$ret"
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
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
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
792 if [ $ret -ne 0 ]; then
793 test_done "$testroot" "$ret"
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
809 if [ $ret -ne 0 ]; then
810 diff -u $testroot/stdout.expected $testroot/stdout
811 test_done "$testroot" "$ret"
815 (cd $testroot/wt && got status > $testroot/stdout)
816 echo "D beta" > $testroot/stdout.expected
817 cmp -s $testroot/stdout.expected $testroot/stdout
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done "$testroot" "$ret"
825 (cd $testroot/wt && got diff -s > $testroot/stdout)
826 echo -n > $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
829 if [ $ret -ne 0 ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
831 test_done "$testroot" "$ret"
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
850 if [ $ret -ne 0 ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
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
867 if [ $ret -ne 0 ]; then
868 test_done "$testroot" "$ret"
872 ed -s $testroot/wt/numbers <<-\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 \
887 if [ $ret -ne 0 ]; then
888 echo "got unstage command failed unexpectedly" >&2
889 test_done "$testroot" "1"
892 cat > $testroot/stdout.expected <<EOF
893 -----------------------------------------------
901 -----------------------------------------------
902 M numbers (change 1 of 3)
903 unstage this change? [y/n/q] y
904 -----------------------------------------------
914 -----------------------------------------------
915 M numbers (change 2 of 3)
916 unstage this change? [y/n/q] q
919 unstage this deletion? [y/n] n
921 cmp -s $testroot/stdout.expected $testroot/stdout
923 if [ $ret -ne 0 ]; then
924 diff -u $testroot/stdout.expected $testroot/stdout
925 test_done "$testroot" "$ret"
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
934 if [ $ret -ne 0 ]; then
935 diff -u $testroot/stdout.expected $testroot/stdout
936 test_done "$testroot" "$ret"
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
961 if [ $ret -ne 0 ]; then
962 diff -u $testroot/stdout.expected $testroot/stdout
963 test_done "$testroot" "$ret"
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
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
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
1027 if [ $ret -ne 0 ]; then
1028 test_done "$testroot" "$ret"
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
1055 cmp -s $testroot/stdout.expected $testroot/stdout
1057 if [ $ret -ne 0 ]; then
1058 diff -u $testroot/stdout.expected $testroot/stdout
1059 test_done "$testroot" "$ret"
1063 (cd $testroot/wt && got unstage -R > $testroot/stdout)
1065 if [ $ret -ne 0 ]; then
1066 echo "got unstage command failed unexpectedly" >&2
1067 test_done "$testroot" "1"
1071 cat > $testroot/stdout.expected <<EOF
1081 cmp -s $testroot/stdout.expected $testroot/stdout
1083 if [ $ret -ne 0 ]; then
1084 diff -u $testroot/stdout.expected $testroot/stdout
1085 test_done "$testroot" "$ret"
1089 if [ ! -h $testroot/wt/alpha.link ]; then
1090 echo "alpha.link is not a symlink"
1091 test_done "$testroot" "1"
1095 readlink $testroot/wt/alpha.link > $testroot/stdout
1096 echo "beta" > $testroot/stdout.expected
1097 cmp -s $testroot/stdout.expected $testroot/stdout
1099 if [ $ret -ne 0 ]; then
1100 diff -u $testroot/stdout.expected $testroot/stdout
1101 test_done "$testroot" "$ret"
1105 if [ ! -h $testroot/wt/epsilon.link ]; then
1106 echo "epsilon.link is not a symlink"
1107 test_done "$testroot" "1"
1111 readlink $testroot/wt/epsilon.link > $testroot/stdout
1112 echo "gamma" > $testroot/stdout.expected
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1115 if [ $ret -ne 0 ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1117 test_done "$testroot" "$ret"
1121 if [ ! -h $testroot/wt/epsilon/beta.link ]; then
1122 echo "epsilon/beta.link is not a symlink"
1123 test_done "$testroot" "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
1131 if [ $ret -ne 0 ]; then
1132 diff -u $testroot/stdout.expected $testroot/stdout
1133 test_done "$testroot" "$ret"
1137 if [ ! -f $testroot/wt/dotgotfoo.link ]; then
1138 echo "dotgotfoo.link is a symlink"
1139 test_done "$testroot" "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
1147 if [ $ret -ne 0 ]; then
1148 diff -u $testroot/content.expected $testroot/content
1149 test_done "$testroot" "$ret"
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"
1160 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
1161 echo ".got/bar" > $testroot/stdout.expected
1162 cmp -s $testroot/stdout.expected $testroot/stdout
1164 if [ $ret -ne 0 ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1166 test_done "$testroot" "$ret"
1170 if [ -e $testroot/wt/nonexistent.link ]; then
1171 echo "nonexistent.link exists on disk"
1172 test_done "$testroot" "1"
1176 if [ ! -h $testroot/wt/zeta.link ]; then
1177 echo "zeta.link is not a symlink"
1178 test_done "$testroot" "1"
1182 readlink $testroot/wt/zeta.link > $testroot/stdout
1183 echo "gamma/delta" > $testroot/stdout.expected
1184 cmp -s $testroot/stdout.expected $testroot/stdout
1186 if [ $ret -ne 0 ]; then
1187 diff -u $testroot/stdout.expected $testroot/stdout
1188 test_done "$testroot" "$ret"
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
1211 if [ $ret -ne 0 ]; then
1212 test_done "$testroot" "$ret"
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 \
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)
1230 (cd $testroot/wt && got rm zeta.link > /dev/null)
1231 (cd $testroot/wt && got rm zeta2.link > /dev/null)
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
1253 cmp -s $testroot/stdout.expected $testroot/stdout
1255 if [ $ret -ne 0 ]; then
1256 diff -u $testroot/stdout.expected $testroot/stdout
1257 test_done "$testroot" "$ret"
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 \
1265 if [ $ret -ne 0 ]; then
1266 echo "got unstage command failed unexpectedly" >&2
1267 test_done "$testroot" "1"
1271 cat > $testroot/stdout.expected <<EOF
1272 -----------------------------------------------
1275 \ No newline at end of file
1277 \ No newline at end of file
1278 -----------------------------------------------
1279 M alpha.link (change 1 of 1)
1280 unstage this change? [y/n/q] y
1282 -----------------------------------------------
1285 \ No newline at end of file
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 -----------------------------------------------
1294 \ No newline at end of file
1296 \ No newline at end of file
1297 -----------------------------------------------
1298 M epsilon.link (change 1 of 1)
1299 unstage this change? [y/n/q] y
1302 unstage this addition? [y/n] n
1303 -----------------------------------------------
1306 \ No newline at end of file
1308 \ No newline at end of file
1309 -----------------------------------------------
1310 M nonexistent.link (change 1 of 1)
1311 unstage this change? [y/n/q] y
1313 -----------------------------------------------
1316 \ No newline at end of file
1318 -----------------------------------------------
1319 M passwd.link (change 1 of 1)
1320 unstage this change? [y/n/q] y
1323 unstage this deletion? [y/n] n
1325 unstage this deletion? [y/n] y
1328 unstage this addition? [y/n] y
1331 cmp -s $testroot/stdout.expected $testroot/stdout
1333 if [ $ret -ne 0 ]; then
1334 diff -u $testroot/stdout.expected $testroot/stdout
1335 test_done "$testroot" "$ret"
1339 if ! [ -h $testroot/wt/alpha.link ]; then
1340 echo "alpha.link is not a symlink"
1341 test_done "$testroot" "1"
1345 readlink $testroot/wt/alpha.link > $testroot/stdout
1346 echo "gamma/delta" > $testroot/stdout.expected
1347 cmp -s $testroot/stdout.expected $testroot/stdout
1349 if [ $ret -ne 0 ]; then
1350 diff -u $testroot/stdout.expected $testroot/stdout
1351 test_done "$testroot" "$ret"
1355 if ! [ -h $testroot/wt/epsilon.link ]; then
1356 echo "epsilon.link is not a symlink"
1357 test_done "$testroot" "1"
1361 readlink $testroot/wt/epsilon.link > $testroot/stdout
1362 echo "beta" > $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/passwd.link ]; then
1372 echo "passwd.link should not be a symlink" >&2
1373 test_done "$testroot" "1"
1377 echo "foo" > $testroot/content.expected
1378 cp $testroot/wt/passwd.link $testroot/content
1380 cmp -s $testroot/content.expected $testroot/content
1382 if [ $ret -ne 0 ]; then
1383 diff -u $testroot/content.expected $testroot/content
1384 test_done "$testroot" "$ret"
1388 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1389 echo "../gamma" > $testroot/stdout.expected
1390 cmp -s $testroot/stdout.expected $testroot/stdout
1392 if [ $ret -ne 0 ]; then
1393 diff -u $testroot/stdout.expected $testroot/stdout
1394 test_done "$testroot" "$ret"
1398 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1399 echo "nonexistent2" > $testroot/stdout.expected
1400 cmp -s $testroot/stdout.expected $testroot/stdout
1402 if [ $ret -ne 0 ]; then
1403 diff -u $testroot/stdout.expected $testroot/stdout
1404 test_done "$testroot" "$ret"
1408 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1409 echo "dotgotfoo.link is not a symlink " >&2
1410 test_done "$testroot" "1"
1413 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1414 echo ".got/foo" > $testroot/stdout.expected
1415 cmp -s $testroot/stdout.expected $testroot/stdout
1417 if [ $ret -ne 0 ]; then
1418 diff -u $testroot/stdout.expected $testroot/stdout
1419 test_done "$testroot" "$ret"
1424 if [ -e $testroot/wt/zeta.link ]; then
1425 echo -n "zeta.link should not exist on disk" >&2
1426 test_done "$testroot" "1"
1430 if [ -e $testroot/wt/zeta2.link ]; then
1431 echo -n "zeta2.link exists on disk" >&2
1432 test_done "$testroot" "1"
1436 if [ ! -h $testroot/wt/zeta3.link ]; then
1437 echo -n "zeta3.link is not a symlink" >&2
1438 test_done "$testroot" "1"
1442 readlink $testroot/wt/zeta3.link > $testroot/stdout
1443 echo "beta" > $testroot/stdout.expected
1444 cmp -s $testroot/stdout.expected $testroot/stdout
1446 if [ $ret -ne 0 ]; then
1447 diff -u $testroot/stdout.expected $testroot/stdout
1448 test_done "$testroot" "$ret"
1452 if [ ! -h $testroot/wt/new.link ]; then
1453 echo -n "new.link is not a symlink" >&2
1454 test_done "$testroot" "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
1471 if [ $ret -ne 0 ]; then
1472 diff -u $testroot/stdout.expected $testroot/stdout
1475 test_done "$testroot" "$ret"
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