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
182 test_done
"$testroot" "$ret"
186 cat > $testroot/stdout.expected
<<EOF
191 (cd $testroot/wt
&& got status
> $testroot/stdout
)
192 cmp -s $testroot/stdout.expected
$testroot/stdout
194 if [ $ret -ne 0 ]; then
195 diff -u $testroot/stdout.expected
$testroot/stdout
196 test_done
"$testroot" "$ret"
200 # removing a staged file from disk and then unstaging
201 # all changes in the work tree would trigger a segfault
202 rm $testroot/wt
/alpha
204 cat > $testroot/stdout.expected
<<EOF
209 (cd $testroot/wt
&& got status
> $testroot/stdout
)
210 cmp -s $testroot/stdout.expected
$testroot/stdout
212 if [ $ret -ne 0 ]; then
213 diff -u $testroot/stdout.expected
$testroot/stdout
214 test_done
"$testroot" "$ret"
218 (cd $testroot/wt
&& got unstage
> $testroot/stdout
)
220 if [ $ret -ne 0 ]; then
221 echo "got unstage command failed unexpectedly" >&2
222 test_done
"$testroot" "1"
226 cat > $testroot/stdout.expected
<<EOF
230 Files which had incoming changes but could not be found in the work tree: 1
232 cmp -s $testroot/stdout.expected
$testroot/stdout
234 if [ $ret -ne 0 ]; then
235 diff -u $testroot/stdout.expected
$testroot/stdout
236 test_done
"$testroot" "$ret"
240 cat > $testroot/stdout.expected
<<EOF
245 (cd $testroot/wt
&& got status
> $testroot/stdout
)
246 cmp -s $testroot/stdout.expected
$testroot/stdout
248 if [ $ret -ne 0 ]; then
249 diff -u $testroot/stdout.expected
$testroot/stdout
252 test_done
"$testroot" "$ret"
255 test_unstage_patch
() {
256 local testroot
=`test_init unstage_patch`
258 seq 16 > $testroot/repo
/numbers
259 git
-C $testroot/repo add numbers
260 git_commit
$testroot/repo
-m "added numbers file"
261 local commit_id
=`git_show_head $testroot/repo`
263 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
265 if [ $ret -ne 0 ]; then
266 test_done
"$testroot" "$ret"
270 ed
-s $testroot/wt
/numbers
<<-\EOF
277 (cd $testroot/wt && got stage > /dev/null)
279 if [ $ret -ne 0 ]; then
280 echo "got stage command failed unexpectedly" >&2
281 test_done "$testroot" "1"
285 # don't unstage any hunks
286 printf "n\nn\nn\n" > $testroot/patchscript
287 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
288 numbers > $testroot/stdout)
290 if [ $ret -ne 0 ]; then
291 echo "got unstage command failed unexpectedly" >&2
292 test_done "$testroot" "1"
295 cat > $testroot/stdout.expected <<EOF
296 -----------------------------------------------
304 -----------------------------------------------
305 M numbers (change 1 of 3)
306 unstage this change? [y/n/q] n
307 -----------------------------------------------
317 -----------------------------------------------
318 M numbers (change 2 of 3)
319 unstage this change? [y/n/q] n
320 -----------------------------------------------
327 -----------------------------------------------
328 M numbers (change 3 of 3)
329 unstage this change? [y/n/q] n
331 cmp -s $testroot/stdout.expected $testroot/stdout
333 if [ $ret -ne 0 ]; then
334 diff -u $testroot/stdout.expected $testroot/stdout
335 test_done "$testroot" "$ret"
339 (cd $testroot/wt && got status > $testroot/stdout)
340 echo " M numbers" > $testroot/stdout.expected
341 cmp -s $testroot/stdout.expected $testroot/stdout
343 if [ $ret -ne 0 ]; then
344 diff -u $testroot/stdout.expected $testroot/stdout
345 test_done "$testroot" "$ret"
349 # unstage middle hunk
350 printf "n\ny\nn\n" > $testroot/patchscript
351 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
352 numbers > $testroot/stdout)
354 cat > $testroot/stdout.expected <<EOF
355 -----------------------------------------------
363 -----------------------------------------------
364 M numbers (change 1 of 3)
365 unstage this change? [y/n/q] n
366 -----------------------------------------------
376 -----------------------------------------------
377 M numbers (change 2 of 3)
378 unstage this change? [y/n/q] y
379 -----------------------------------------------
386 -----------------------------------------------
387 M numbers (change 3 of 3)
388 unstage this change? [y/n/q] n
391 cmp -s $testroot/stdout.expected $testroot/stdout
393 if [ $ret -ne 0 ]; then
394 diff -u $testroot/stdout.expected $testroot/stdout
395 test_done "$testroot" "$ret"
399 (cd $testroot/wt && got status > $testroot/stdout)
400 echo "MM numbers" > $testroot/stdout.expected
401 cmp -s $testroot/stdout.expected $testroot/stdout
403 if [ $ret -ne 0 ]; then
404 diff -u $testroot/stdout.expected $testroot/stdout
405 test_done "$testroot" "$ret"
409 (cd $testroot/wt && got diff -s > $testroot/stdout)
411 echo "diff -s $testroot/wt" > $testroot/stdout.expected
412 echo "path + $testroot/wt (staged changes)" >> $testroot/stdout.expected
413 echo "commit - $commit_id" >> $testroot/stdout.expected
414 echo -n 'blob - ' >> $testroot/stdout.expected
415 got tree -r $testroot/repo -i -c $commit_id \
416 | grep 'numbers$' | cut -d' ' -f 1 \
417 >> $testroot/stdout.expected
418 echo -n 'blob + ' >> $testroot/stdout.expected
419 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
420 >> $testroot/stdout.expected
421 cat >> $testroot/stdout.expected <<EOF
438 cmp -s $testroot/stdout.expected $testroot/stdout
440 if [ $ret -ne 0 ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
446 (cd $testroot/wt && got diff > $testroot/stdout)
447 echo "diff $testroot/wt
" > $testroot/stdout.expected
448 echo "path
+ $testroot/wt
" >> $testroot/stdout.expected
449 echo "commit
- $commit_id" >> $testroot/stdout.expected
450 echo -n 'blob - ' >> $testroot/stdout.expected
451 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
452 tr -d '\n' >> $testroot/stdout.expected
453 echo " (staged
)" >> $testroot/stdout.expected
454 echo "file + numbers
" >> $testroot/stdout.expected
455 cat >> $testroot/stdout.expected <<EOF
468 cmp -s $testroot/stdout.expected $testroot/stdout
470 if [ $ret -ne 0 ]; then
471 diff -u $testroot/stdout.expected $testroot/stdout
472 test_done "$testroot" "$ret"
476 (cd $testroot/wt && got stage >/dev/null)
478 if [ $ret -ne 0 ]; then
479 echo "got stage
command failed unexpectedly
" >&2
480 test_done "$testroot" "1"
484 (cd $testroot/wt && got status > $testroot/stdout)
485 echo " M numbers
" > $testroot/stdout.expected
486 cmp -s $testroot/stdout.expected $testroot/stdout
488 if [ $ret -ne 0 ]; then
489 diff -u $testroot/stdout.expected $testroot/stdout
490 test_done "$testroot" "$ret"
495 printf "n
\nn
\ny
\n" > $testroot/patchscript
496 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
497 numbers > $testroot/stdout)
499 cat > $testroot/stdout.expected <<EOF
500 -----------------------------------------------
508 -----------------------------------------------
509 M numbers (change 1 of 3)
510 unstage this change? [y/n/q] n
511 -----------------------------------------------
521 -----------------------------------------------
522 M numbers (change 2 of 3)
523 unstage this change? [y/n/q] n
524 -----------------------------------------------
531 -----------------------------------------------
532 M numbers (change 3 of 3)
533 unstage this change? [y/n/q] y
536 cmp -s $testroot/stdout.expected $testroot/stdout
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 test_done "$testroot" "$ret"
544 (cd $testroot/wt && got status > $testroot/stdout)
545 echo "MM numbers
" > $testroot/stdout.expected
546 cmp -s $testroot/stdout.expected $testroot/stdout
548 if [ $ret -ne 0 ]; then
549 diff -u $testroot/stdout.expected $testroot/stdout
550 test_done "$testroot" "$ret"
554 (cd $testroot/wt && got diff -s > $testroot/stdout)
556 echo "diff -s $testroot/wt
" > $testroot/stdout.expected
557 echo "path
+ $testroot/wt
(staged changes
)" >> $testroot/stdout.expected
558 echo "commit
- $commit_id" >> $testroot/stdout.expected
559 echo -n 'blob - ' >> $testroot/stdout.expected
560 got tree -r $testroot/repo -i -c $commit_id \
561 | grep 'numbers$' | cut -d' ' -f 1 \
562 >> $testroot/stdout.expected
563 echo -n 'blob + ' >> $testroot/stdout.expected
564 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
565 >> $testroot/stdout.expected
566 cat >> $testroot/stdout.expected <<EOF
583 cmp -s $testroot/stdout.expected $testroot/stdout
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 test_done "$testroot" "$ret"
591 (cd $testroot/wt && got diff > $testroot/stdout)
592 echo "diff $testroot/wt
" > $testroot/stdout.expected
593 echo "path
+ $testroot/wt
" >> $testroot/stdout.expected
594 echo "commit
- $commit_id" >> $testroot/stdout.expected
595 echo -n 'blob - ' >> $testroot/stdout.expected
596 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
597 tr -d '\n' >> $testroot/stdout.expected
598 echo " (staged
)" >> $testroot/stdout.expected
599 echo "file + numbers
" >> $testroot/stdout.expected
600 cat >> $testroot/stdout.expected <<EOF
610 cmp -s $testroot/stdout.expected $testroot/stdout
612 if [ $ret -ne 0 ]; then
613 diff -u $testroot/stdout.expected $testroot/stdout
614 test_done "$testroot" "$ret"
618 (cd $testroot/wt && got stage >/dev/null)
620 if [ $ret -ne 0 ]; then
621 echo "got stage
command failed unexpectedly
" >&2
622 test_done "$testroot" "1"
626 (cd $testroot/wt && got status > $testroot/stdout)
627 echo " M numbers
" > $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected $testroot/stdout
630 if [ $ret -ne 0 ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 test_done "$testroot" "$ret"
637 printf "y
\ny
\ny
\n" > $testroot/patchscript
638 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
639 numbers > $testroot/stdout)
641 cat > $testroot/stdout.expected <<EOF
642 -----------------------------------------------
650 -----------------------------------------------
651 M numbers (change 1 of 3)
652 unstage this change? [y/n/q] y
653 -----------------------------------------------
663 -----------------------------------------------
664 M numbers (change 2 of 3)
665 unstage this change? [y/n/q] y
666 -----------------------------------------------
673 -----------------------------------------------
674 M numbers (change 3 of 3)
675 unstage this change? [y/n/q] y
678 cmp -s $testroot/stdout.expected $testroot/stdout
680 if [ $ret -ne 0 ]; then
681 diff -u $testroot/stdout.expected $testroot/stdout
682 test_done "$testroot" "$ret"
686 (cd $testroot/wt && got status > $testroot/stdout)
687 echo "M numbers
" > $testroot/stdout.expected
688 cmp -s $testroot/stdout.expected $testroot/stdout
690 if [ $ret -ne 0 ]; then
691 diff -u $testroot/stdout.expected $testroot/stdout
692 test_done "$testroot" "$ret"
696 (cd $testroot/wt && got diff -s > $testroot/stdout)
697 echo -n > $testroot/stdout.expected
698 cmp -s $testroot/stdout.expected $testroot/stdout
700 if [ $ret -ne 0 ]; then
701 diff -u $testroot/stdout.expected $testroot/stdout
702 test_done "$testroot" "$ret"
706 (cd $testroot/wt && got diff > $testroot/stdout)
708 echo "diff $testroot/wt
" > $testroot/stdout.expected
709 echo "path
+ $testroot/wt
" >> $testroot/stdout.expected
710 echo "commit
- $commit_id" >> $testroot/stdout.expected
711 echo -n 'blob - ' >> $testroot/stdout.expected
712 got tree -r $testroot/repo -i -c $commit_id \
713 | grep 'numbers$' | cut -d' ' -f 1 \
714 >> $testroot/stdout.expected
715 echo 'file + numbers' >> $testroot/stdout.expected
716 cat >> $testroot/stdout.expected <<EOF
739 cmp -s $testroot/stdout.expected $testroot/stdout
741 if [ $ret -ne 0 ]; then
742 diff -u $testroot/stdout.expected $testroot/stdout
744 test_done "$testroot" "$ret"
748 test_unstage_patch_added() {
749 local testroot=`test_init unstage_patch_added`
750 local commit_id=`git_show_head $testroot/repo`
752 got checkout $testroot/repo $testroot/wt > /dev/null
754 if [ $ret -ne 0 ]; then
755 test_done "$testroot" "$ret"
759 echo "new
" > $testroot/wt/epsilon/new
760 (cd $testroot/wt && got add epsilon/new > /dev/null)
762 (cd $testroot/wt && got stage > /dev/null)
764 printf "y
\n" > $testroot/patchscript
765 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
766 epsilon/new > $testroot/stdout)
768 echo "A epsilon
/new
" > $testroot/stdout.expected
769 echo "unstage this addition?
[y
/n
] y
" >> $testroot/stdout.expected
770 echo "G epsilon
/new
" >> $testroot/stdout.expected
771 cmp -s $testroot/stdout.expected $testroot/stdout
773 if [ $ret -ne 0 ]; then
774 diff -u $testroot/stdout.expected $testroot/stdout
775 test_done "$testroot" "$ret"
779 (cd $testroot/wt && got status > $testroot/stdout)
780 echo "A epsilon
/new
" > $testroot/stdout.expected
781 cmp -s $testroot/stdout.expected $testroot/stdout
783 if [ $ret -ne 0 ]; then
784 diff -u $testroot/stdout.expected $testroot/stdout
785 test_done "$testroot" "$ret"
789 (cd $testroot/wt && got diff -s > $testroot/stdout)
790 echo -n > $testroot/stdout.expected
791 cmp -s $testroot/stdout.expected $testroot/stdout
793 if [ $ret -ne 0 ]; then
794 diff -u $testroot/stdout.expected $testroot/stdout
795 test_done "$testroot" "$ret"
799 (cd $testroot/wt && got diff > $testroot/stdout)
801 echo "diff $testroot/wt
" > $testroot/stdout.expected
802 echo "path
+ $testroot/wt
" >> $testroot/stdout.expected
803 echo "commit
- $commit_id" >> $testroot/stdout.expected
804 echo 'blob - /dev/null' >> $testroot/stdout.expected
805 echo 'file + epsilon/new (mode 644)' >> $testroot/stdout.expected
806 echo "--- /dev
/null
" >> $testroot/stdout.expected
807 echo "+++ epsilon
/new
" >> $testroot/stdout.expected
808 echo "@@
-0,0 +1 @@
" >> $testroot/stdout.expected
809 echo "+new
" >> $testroot/stdout.expected
810 cmp -s $testroot/stdout.expected $testroot/stdout
812 if [ $ret -ne 0 ]; then
813 diff -u $testroot/stdout.expected $testroot/stdout
815 test_done "$testroot" "$ret"
818 test_unstage_patch_removed() {
819 local testroot=`test_init unstage_patch_removed`
820 local commit_id=`git_show_head $testroot/repo`
822 got checkout $testroot/repo $testroot/wt > /dev/null
824 if [ $ret -ne 0 ]; then
825 test_done "$testroot" "$ret"
829 (cd $testroot/wt && got rm beta > /dev/null)
830 (cd $testroot/wt && got stage > /dev/null)
832 printf "y
\n" > $testroot/patchscript
833 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
834 beta > $testroot/stdout)
836 echo "D beta
" > $testroot/stdout.expected
837 echo "unstage this deletion?
[y
/n
] y
" >> $testroot/stdout.expected
838 echo "D beta
" >> $testroot/stdout.expected
839 cmp -s $testroot/stdout.expected $testroot/stdout
841 if [ $ret -ne 0 ]; then
842 diff -u $testroot/stdout.expected $testroot/stdout
843 test_done "$testroot" "$ret"
847 (cd $testroot/wt && got status > $testroot/stdout)
848 echo "D beta
" > $testroot/stdout.expected
849 cmp -s $testroot/stdout.expected $testroot/stdout
851 if [ $ret -ne 0 ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
853 test_done "$testroot" "$ret"
857 (cd $testroot/wt && got diff -s > $testroot/stdout)
858 echo -n > $testroot/stdout.expected
859 cmp -s $testroot/stdout.expected $testroot/stdout
861 if [ $ret -ne 0 ]; then
862 diff -u $testroot/stdout.expected $testroot/stdout
863 test_done "$testroot" "$ret"
867 (cd $testroot/wt && got diff > $testroot/stdout)
869 echo "diff $testroot/wt
" > $testroot/stdout.expected
870 echo "path
+ $testroot/wt
" >> $testroot/stdout.expected
871 echo "commit
- $commit_id" >> $testroot/stdout.expected
872 echo -n 'blob - ' >> $testroot/stdout.expected
873 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
874 >> $testroot/stdout.expected
875 echo 'file + /dev/null' >> $testroot/stdout.expected
876 echo "--- beta
" >> $testroot/stdout.expected
877 echo "+++ /dev
/null
" >> $testroot/stdout.expected
878 echo "@@
-1 +0,0 @@
" >> $testroot/stdout.expected
879 echo "-beta" >> $testroot/stdout.expected
880 cmp -s $testroot/stdout.expected $testroot/stdout
882 if [ $ret -ne 0 ]; then
883 diff -u $testroot/stdout.expected $testroot/stdout
885 test_done "$testroot" "$ret"
888 test_unstage_patch_quit() {
889 local testroot=`test_init unstage_patch_quit`
891 seq 16 > $testroot/repo/numbers
892 echo zzz > $testroot/repo/zzz
893 git -C $testroot/repo add numbers zzz
894 git_commit $testroot/repo -m "added files
"
895 local commit_id=`git_show_head $testroot/repo`
897 got checkout $testroot/repo $testroot/wt > /dev/null
899 if [ $ret -ne 0 ]; then
900 test_done "$testroot" "$ret"
904 ed -s $testroot/wt/numbers <<-\EOF
910 (cd $testroot/wt && got rm zzz > /dev/null)
911 (cd $testroot/wt && got stage > /dev/null)
913 # unstage first hunk and quit; and don't pass a path argument to
914 # ensure that we don't skip asking about the 'zzz' file after 'quit'
915 printf "y
\nq
\nn
\n" > $testroot/patchscript
916 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
919 if [ $ret -ne 0 ]; then
920 echo "got unstage
command failed unexpectedly
" >&2
921 test_done "$testroot" "1"
924 cat > $testroot/stdout.expected <<EOF
925 -----------------------------------------------
933 -----------------------------------------------
934 M numbers (change 1 of 3)
935 unstage this change? [y/n/q] y
936 -----------------------------------------------
946 -----------------------------------------------
947 M numbers (change 2 of 3)
948 unstage this change? [y/n/q] q
951 unstage this deletion? [y/n] n
953 cmp -s $testroot/stdout.expected $testroot/stdout
955 if [ $ret -ne 0 ]; then
956 diff -u $testroot/stdout.expected $testroot/stdout
957 test_done "$testroot" "$ret"
961 (cd $testroot/wt && got status > $testroot/stdout)
962 echo "MM numbers
" > $testroot/stdout.expected
963 echo " D zzz
" >> $testroot/stdout.expected
964 cmp -s $testroot/stdout.expected $testroot/stdout
966 if [ $ret -ne 0 ]; then
967 diff -u $testroot/stdout.expected $testroot/stdout
968 test_done "$testroot" "$ret"
972 (cd $testroot/wt && got diff > $testroot/stdout)
974 echo "diff $testroot/wt
" > $testroot/stdout.expected
975 echo "path
+ $testroot/wt
" >> $testroot/stdout.expected
976 echo "commit
- $commit_id" >> $testroot/stdout.expected
977 echo -n 'blob - ' >> $testroot/stdout.expected
978 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 | \
979 tr -d '\n' >> $testroot/stdout.expected
980 echo " (staged
)" >> $testroot/stdout.expected
981 echo "file + numbers
" >> $testroot/stdout.expected
982 echo "--- numbers
" >> $testroot/stdout.expected
983 echo "+++ numbers
" >> $testroot/stdout.expected
984 echo "@@
-1,5 +1,5 @@
" >> $testroot/stdout.expected
985 echo " 1" >> $testroot/stdout.expected
986 echo "-2" >> $testroot/stdout.expected
987 echo "+a
" >> $testroot/stdout.expected
988 echo " 3" >> $testroot/stdout.expected
989 echo " 4" >> $testroot/stdout.expected
990 echo " 5" >> $testroot/stdout.expected
991 cmp -s $testroot/stdout.expected $testroot/stdout
993 if [ $ret -ne 0 ]; then
994 diff -u $testroot/stdout.expected $testroot/stdout
995 test_done "$testroot" "$ret"
999 (cd $testroot/wt && got diff -s > $testroot/stdout)
1000 echo "diff -s $testroot/wt
" > $testroot/stdout.expected
1001 echo "path
+ $testroot/wt
(staged changes
)" >> $testroot/stdout.expected
1002 echo "commit
- $commit_id" >> $testroot/stdout.expected
1003 echo -n 'blob - ' >> $testroot/stdout.expected
1004 got tree -r $testroot/repo -i -c $commit_id \
1005 | grep 'numbers$' | cut -d' ' -f 1 \
1006 >> $testroot/stdout.expected
1007 echo -n 'blob + ' >> $testroot/stdout.expected
1008 (cd $testroot/wt && got stage -l numbers) | cut -d' ' -f 1 \
1009 >> $testroot/stdout.expected
1010 cat >> $testroot/stdout.expected <<EOF
1029 echo "commit
- $commit_id" >> $testroot/stdout.expected
1030 echo -n 'blob - ' >> $testroot/stdout.expected
1031 got tree -r $testroot/repo -i | grep 'zzz$' | cut -d' ' -f 1 \
1032 >> $testroot/stdout.expected
1033 echo 'blob + /dev/null' >> $testroot/stdout.expected
1034 echo "--- zzz
" >> $testroot/stdout.expected
1035 echo "+++ /dev
/null
" >> $testroot/stdout.expected
1036 echo "@@
-1 +0,0 @@
" >> $testroot/stdout.expected
1037 echo "-zzz" >> $testroot/stdout.expected
1038 cmp -s $testroot/stdout.expected $testroot/stdout
1040 if [ $ret -ne 0 ]; then
1041 diff -u $testroot/stdout.expected $testroot/stdout
1043 test_done "$testroot" "$ret"
1046 test_unstage_symlink() {
1047 local testroot=`test_init unstage_symlink`
1049 (cd $testroot/repo && ln -s alpha alpha.link)
1050 (cd $testroot/repo && ln -s epsilon epsilon.link)
1051 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1052 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1053 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1054 git -C $testroot/repo add .
1055 git_commit $testroot/repo -m "add symlinks
"
1056 local head_commit=`git_show_head $testroot/repo`
1058 got checkout $testroot/repo $testroot/wt > /dev/null
1060 if [ $ret -ne 0 ]; then
1061 test_done "$testroot" "$ret"
1065 (cd $testroot/wt && ln -sf beta alpha.link)
1066 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
1067 (cd $testroot/wt && ln -sf ../gamma/delta epsilon/beta.link)
1068 echo 'this is regular file foo' > $testroot/wt/dotgotfoo.link
1069 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
1070 (cd $testroot/wt && ln -sf .got/bar dotgotbar.link)
1071 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
1072 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
1073 (cd $testroot/wt && ln -sf gamma/delta zeta.link)
1074 (cd $testroot/wt && got add zeta.link > /dev/null)
1076 (cd $testroot/wt && got stage -S > /dev/null)
1078 (cd $testroot/wt && got status > $testroot/stdout)
1079 cat > $testroot/stdout.expected <<EOF
1088 cmp -s $testroot/stdout.expected $testroot/stdout
1090 if [ $ret -ne 0 ]; then
1091 diff -u $testroot/stdout.expected $testroot/stdout
1092 test_done "$testroot" "$ret"
1096 (cd $testroot/wt && got unstage > $testroot/stdout)
1098 if [ $ret -ne 0 ]; then
1099 echo "got unstage
command failed unexpectedly
" >&2
1100 test_done "$testroot" "1"
1104 cat > $testroot/stdout.expected <<EOF
1114 cmp -s $testroot/stdout.expected $testroot/stdout
1116 if [ $ret -ne 0 ]; then
1117 diff -u $testroot/stdout.expected $testroot/stdout
1118 test_done "$testroot" "$ret"
1122 if [ ! -h $testroot/wt/alpha.link ]; then
1123 echo "alpha.link is not a symlink
"
1124 test_done "$testroot" "1"
1128 readlink $testroot/wt/alpha.link > $testroot/stdout
1129 echo "beta
" > $testroot/stdout.expected
1130 cmp -s $testroot/stdout.expected $testroot/stdout
1132 if [ $ret -ne 0 ]; then
1133 diff -u $testroot/stdout.expected $testroot/stdout
1134 test_done "$testroot" "$ret"
1138 if [ ! -h $testroot/wt/epsilon.link ]; then
1139 echo "epsilon.link is not a symlink
"
1140 test_done "$testroot" "1"
1144 readlink $testroot/wt/epsilon.link > $testroot/stdout
1145 echo "gamma
" > $testroot/stdout.expected
1146 cmp -s $testroot/stdout.expected $testroot/stdout
1148 if [ $ret -ne 0 ]; then
1149 diff -u $testroot/stdout.expected $testroot/stdout
1150 test_done "$testroot" "$ret"
1154 if [ ! -h $testroot/wt/epsilon/beta.link ]; then
1155 echo "epsilon
/beta.link is not a symlink
"
1156 test_done "$testroot" "1"
1160 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1161 echo "..
/gamma
/delta
" > $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 [ ! -f $testroot/wt/dotgotfoo.link ]; then
1171 echo "dotgotfoo.link is a symlink
"
1172 test_done "$testroot" "1"
1176 echo "this is regular
file foo
" > $testroot/content.expected
1177 cp $testroot/wt/dotgotfoo.link $testroot/content
1178 cmp -s $testroot/content.expected $testroot/content
1180 if [ $ret -ne 0 ]; then
1181 diff -u $testroot/content.expected $testroot/content
1182 test_done "$testroot" "$ret"
1186 # bad symlinks are allowed as-is for commit and stage/unstage
1187 if [ ! -h $testroot/wt/dotgotbar.link ]; then
1188 echo "dotgotbar.link is not a symlink
"
1189 test_done "$testroot" "1"
1193 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
1194 echo ".got
/bar
" > $testroot/stdout.expected
1195 cmp -s $testroot/stdout.expected $testroot/stdout
1197 if [ $ret -ne 0 ]; then
1198 diff -u $testroot/stdout.expected $testroot/stdout
1199 test_done "$testroot" "$ret"
1203 if [ -e $testroot/wt/nonexistent.link ]; then
1204 echo "nonexistent.link exists on disk
"
1205 test_done "$testroot" "1"
1209 if [ ! -h $testroot/wt/zeta.link ]; then
1210 echo "zeta.link is not a symlink
"
1211 test_done "$testroot" "1"
1215 readlink $testroot/wt/zeta.link > $testroot/stdout
1216 echo "gamma
/delta
" > $testroot/stdout.expected
1217 cmp -s $testroot/stdout.expected $testroot/stdout
1219 if [ $ret -ne 0 ]; then
1220 diff -u $testroot/stdout.expected $testroot/stdout
1221 test_done "$testroot" "$ret"
1225 test_done "$testroot" "0"
1228 test_unstage_patch_symlink() {
1229 local testroot=`test_init unstage_patch_symlink`
1231 (cd $testroot/repo && ln -s alpha alpha.link)
1232 (cd $testroot/repo && ln -s epsilon epsilon.link)
1233 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1234 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1235 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1236 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1237 (cd $testroot/repo && ln -sf epsilon/zeta zeta2.link)
1238 git -C $testroot/repo add .
1239 git_commit $testroot/repo -m "add symlinks
"
1240 local commit_id1=`git_show_head $testroot/repo`
1242 got checkout $testroot/repo $testroot/wt > /dev/null
1244 if [ $ret -ne 0 ]; then
1245 test_done "$testroot" "$ret"
1249 # symlink to file A now points to file B
1250 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
1251 # symlink to a directory A now points to file B
1252 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
1253 # "bad
" symlink now contains a different target path
1254 echo "foo
" > $testroot/wt/passwd.link
1255 # relative symlink to directory A now points to relative directory B
1256 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
1258 # an unversioned symlink
1259 (cd $testroot/wt && ln -sf .got/foo dotgotfoo.link)
1260 # symlink to file A now points to non-existent file B
1261 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
1263 (cd $testroot/wt && got rm zeta.link > /dev/null)
1264 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1266 (cd $testroot/wt && ln -sf beta new.link)
1267 (cd $testroot/wt && got add new.link > /dev/null)
1268 (cd $testroot/wt && ln -sf beta zeta3.link)
1269 (cd $testroot/wt && got add zeta3.link > /dev/null)
1271 (cd $testroot/wt && got stage -S > /dev/null)
1273 (cd $testroot/wt && got status > $testroot/stdout)
1274 cat > $testroot/stdout.expected <<EOF
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1290 test_done "$testroot" "$ret"
1294 printf "y
\nn
\ny
\nn
\ny
\ny
\nn
\ny
\ny
\n" > $testroot/patchscript
1295 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1298 if [ $ret -ne 0 ]; then
1299 echo "got unstage
command failed unexpectedly
" >&2
1300 test_done "$testroot" "1"
1304 cat > $testroot/stdout.expected <<EOF
1305 -----------------------------------------------
1308 \ No newline at end of file
1310 \ No newline at end of file
1311 -----------------------------------------------
1312 M alpha.link (change 1 of 1)
1313 unstage this change? [y/n/q] y
1315 -----------------------------------------------
1318 \ No newline at end of file
1320 \ No newline at end of file
1321 -----------------------------------------------
1322 M epsilon/beta.link (change 1 of 1)
1323 unstage this change? [y/n/q] n
1324 -----------------------------------------------
1327 \ No newline at end of file
1329 \ No newline at end of file
1330 -----------------------------------------------
1331 M epsilon.link (change 1 of 1)
1332 unstage this change? [y/n/q] y
1335 unstage this addition? [y/n] n
1336 -----------------------------------------------
1339 \ No newline at end of file
1341 \ No newline at end of file
1342 -----------------------------------------------
1343 M nonexistent.link (change 1 of 1)
1344 unstage this change? [y/n/q] y
1346 -----------------------------------------------
1349 \ No newline at end of file
1351 -----------------------------------------------
1352 M passwd.link (change 1 of 1)
1353 unstage this change? [y/n/q] y
1356 unstage this deletion? [y/n] n
1358 unstage this deletion? [y/n] y
1361 unstage this addition? [y/n] y
1364 cmp -s $testroot/stdout.expected $testroot/stdout
1366 if [ $ret -ne 0 ]; then
1367 diff -u $testroot/stdout.expected $testroot/stdout
1368 test_done "$testroot" "$ret"
1372 if ! [ -h $testroot/wt/alpha.link ]; then
1373 echo "alpha.link is not a symlink
"
1374 test_done "$testroot" "1"
1378 readlink $testroot/wt/alpha.link > $testroot/stdout
1379 echo "gamma
/delta
" > $testroot/stdout.expected
1380 cmp -s $testroot/stdout.expected $testroot/stdout
1382 if [ $ret -ne 0 ]; then
1383 diff -u $testroot/stdout.expected $testroot/stdout
1384 test_done "$testroot" "$ret"
1388 if ! [ -h $testroot/wt/epsilon.link ]; then
1389 echo "epsilon.link is not a symlink
"
1390 test_done "$testroot" "1"
1394 readlink $testroot/wt/epsilon.link > $testroot/stdout
1395 echo "beta
" > $testroot/stdout.expected
1396 cmp -s $testroot/stdout.expected $testroot/stdout
1398 if [ $ret -ne 0 ]; then
1399 diff -u $testroot/stdout.expected $testroot/stdout
1400 test_done "$testroot" "$ret"
1404 if [ -h $testroot/wt/passwd.link ]; then
1405 echo "passwd.link should not be a symlink
" >&2
1406 test_done "$testroot" "1"
1410 echo "foo
" > $testroot/content.expected
1411 cp $testroot/wt/passwd.link $testroot/content
1413 cmp -s $testroot/content.expected $testroot/content
1415 if [ $ret -ne 0 ]; then
1416 diff -u $testroot/content.expected $testroot/content
1417 test_done "$testroot" "$ret"
1421 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1422 echo "..
/gamma
" > $testroot/stdout.expected
1423 cmp -s $testroot/stdout.expected $testroot/stdout
1425 if [ $ret -ne 0 ]; then
1426 diff -u $testroot/stdout.expected $testroot/stdout
1427 test_done "$testroot" "$ret"
1431 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1432 echo "nonexistent2
" > $testroot/stdout.expected
1433 cmp -s $testroot/stdout.expected $testroot/stdout
1435 if [ $ret -ne 0 ]; then
1436 diff -u $testroot/stdout.expected $testroot/stdout
1437 test_done "$testroot" "$ret"
1441 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1442 echo "dotgotfoo.link is not a symlink
" >&2
1443 test_done "$testroot" "1"
1446 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1447 echo ".got
/foo
" > $testroot/stdout.expected
1448 cmp -s $testroot/stdout.expected $testroot/stdout
1450 if [ $ret -ne 0 ]; then
1451 diff -u $testroot/stdout.expected $testroot/stdout
1452 test_done "$testroot" "$ret"
1457 if [ -e $testroot/wt/zeta.link ]; then
1458 echo -n "zeta.link should not exist on disk
" >&2
1459 test_done "$testroot" "1"
1463 if [ -e $testroot/wt/zeta2.link ]; then
1464 echo -n "zeta2.link exists on disk
" >&2
1465 test_done "$testroot" "1"
1469 if [ ! -h $testroot/wt/zeta3.link ]; then
1470 echo -n "zeta3.link is not a symlink
" >&2
1471 test_done "$testroot" "1"
1475 readlink $testroot/wt/zeta3.link > $testroot/stdout
1476 echo "beta
" > $testroot/stdout.expected
1477 cmp -s $testroot/stdout.expected $testroot/stdout
1479 if [ $ret -ne 0 ]; then
1480 diff -u $testroot/stdout.expected $testroot/stdout
1481 test_done "$testroot" "$ret"
1485 if [ ! -h $testroot/wt/new.link ]; then
1486 echo -n "new.link is not a symlink
" >&2
1487 test_done "$testroot" "1"
1491 (cd $testroot/wt && got status > $testroot/stdout)
1492 echo "M alpha.link
" > $testroot/stdout.expected
1493 echo "? dotgotfoo.link
" >> $testroot/stdout.expected
1494 echo " M epsilon
/beta.link
" >> $testroot/stdout.expected
1495 echo "M epsilon.link
" >> $testroot/stdout.expected
1496 echo " A new.link
" >> $testroot/stdout.expected
1497 echo "M nonexistent.link
" >> $testroot/stdout.expected
1498 echo "M passwd.link
" >> $testroot/stdout.expected
1499 echo " D zeta.link
" >> $testroot/stdout.expected
1500 echo "D zeta2.link
" >> $testroot/stdout.expected
1501 echo "A zeta3.link
" >> $testroot/stdout.expected
1502 cmp -s $testroot/stdout.expected $testroot/stdout
1504 if [ $ret -ne 0 ]; then
1505 diff -u $testroot/stdout.expected $testroot/stdout
1508 test_done "$testroot" "$ret"
1511 test_unstage_patch_binary() {
1512 local testroot=$(test_init unstage_patch_binary)
1514 dd if=/dev/urandom of=$testroot/repo/binary bs=1024 count=16 \
1516 git -C $testroot/repo add binary
1517 git_commit $testroot/repo -m "add binary
file"
1519 got checkout $testroot/repo $testroot/wt > /dev/null
1521 if [ $ret -ne 0 ]; then
1522 echo "got checkout failed unexpectedly
" >&2
1523 test_done "$testroot" "$ret"
1527 ed -s $testroot/wt/binary <<-EOF
1535 (cd $testroot/wt && got stage > /dev/null)
1537 if [ $ret -ne 0 ]; then
1538 echo "got stage
command failed unexpectedly
" >&2
1539 test_done "$testroot" "1"
1543 # cancel unstaging with 'n' response
1544 printf "n
\n" > $testroot/patchscript
1545 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1548 if [ $ret -ne 0 ]; then
1549 echo "got unstage
command failed unexpectedly
" >&2
1550 test_done "$testroot" "1"
1554 cat > $testroot/stdout.expected <<-EOF
1555 -----------------------------------------------
1556 Binary files binary and binary differ
1557 -----------------------------------------------
1558 M binary (change 1 of 1)
1559 unstage this change? [y/n/q] n
1562 cmp -s $testroot/stdout.expected $testroot/stdout
1564 if [ $ret -ne 0 ]; then
1565 diff -u $testroot/stdout.expected $testroot/stdout
1566 test_done "$testroot" "$ret"
1570 (cd $testroot/wt && got status > $testroot/stdout)
1571 echo " M binary
" > $testroot/stdout.expected
1572 cmp -s $testroot/stdout.expected $testroot/stdout
1574 if [ $ret -ne 0 ]; then
1575 diff -u $testroot/stdout.expected $testroot/stdout
1576 test_done "$testroot" "$ret"
1580 # cancel unstaging with 'q' response
1581 printf "q
\n" > $testroot/patchscript
1582 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1585 if [ $ret -ne 0 ]; then
1586 echo "got unstage
command failed unexpectedly
" >&2
1587 test_done "$testroot" "1"
1591 cat > $testroot/stdout.expected <<-EOF
1592 -----------------------------------------------
1593 Binary files binary and binary differ
1594 -----------------------------------------------
1595 M binary (change 1 of 1)
1596 unstage this change? [y/n/q] q
1599 cmp -s $testroot/stdout.expected $testroot/stdout
1601 if [ $ret -ne 0 ]; then
1602 diff -u $testroot/stdout.expected $testroot/stdout
1603 test_done "$testroot" "$ret"
1607 (cd $testroot/wt && got status > $testroot/stdout)
1608 echo " M binary
" > $testroot/stdout.expected
1609 cmp -s $testroot/stdout.expected $testroot/stdout
1611 if [ $ret -ne 0 ]; then
1612 diff -u $testroot/stdout.expected $testroot/stdout
1613 test_done "$testroot" "$ret"
1617 # confirm unstage with 'y'
1618 printf "y
\n" > $testroot/patchscript
1619 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1622 if [ $ret -ne 0 ]; then
1623 echo "got unstage
command failed unexpectedly
" >&2
1624 test_done "$testroot" "1"
1628 cat > $testroot/stdout.expected <<-EOF
1629 -----------------------------------------------
1630 Binary files binary and binary differ
1631 -----------------------------------------------
1632 M binary (change 1 of 1)
1633 unstage this change? [y/n/q] y
1637 cmp -s $testroot/stdout.expected $testroot/stdout
1639 if [ $ret -ne 0 ]; then
1640 diff -u $testroot/stdout.expected $testroot/stdout
1641 test_done "$testroot" "$ret"
1645 (cd $testroot/wt && got status > $testroot/stdout)
1646 echo "M binary
" > $testroot/stdout.expected
1647 cmp -s $testroot/stdout.expected $testroot/stdout
1649 if [ $ret -ne 0 ]; then
1650 diff -u $testroot/stdout.expected $testroot/stdout
1651 test_done "$testroot" "$ret"
1655 seq 16 > $testroot/wt/numbers
1656 (cd $testroot/wt && got add numbers > /dev/null)
1657 (cd $testroot/wt && got commit -m "add numbers
" numbers > /dev/null)
1659 ed -s $testroot/wt/numbers <<-EOF
1666 (cd $testroot/wt && got stage > /dev/null)
1668 if [ $ret -ne 0 ]; then
1669 echo "got stage
command failed unexpectedly
" >&2
1670 test_done "$testroot" "1"
1674 # unstage last numbers hunk and binary file
1675 printf "y
\nn
\nn
\ny
\n" > $testroot/patchscript
1676 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1679 cat > $testroot/stdout.expected <<-EOF
1680 -----------------------------------------------
1681 Binary files binary and binary differ
1682 -----------------------------------------------
1683 M binary (change 1 of 1)
1684 unstage this change? [y/n/q] y
1686 -----------------------------------------------
1694 -----------------------------------------------
1695 M numbers (change 1 of 3)
1696 unstage this change? [y/n/q] n
1697 -----------------------------------------------
1707 -----------------------------------------------
1708 M numbers (change 2 of 3)
1709 unstage this change? [y/n/q] n
1710 -----------------------------------------------
1717 -----------------------------------------------
1718 M numbers (change 3 of 3)
1719 unstage this change? [y/n/q] y
1723 cmp -s $testroot/stdout.expected $testroot/stdout
1725 if [ $ret -ne 0 ]; then
1726 diff -u $testroot/stdout.expected $testroot/stdout
1727 test_done "$testroot" "$ret"
1731 (cd $testroot/wt && got status > $testroot/stdout)
1732 echo "M binary
" > $testroot/stdout.expected
1733 echo "MM numbers
" >> $testroot/stdout.expected
1735 cmp -s $testroot/stdout.expected $testroot/stdout
1737 if [ $ret -ne 0 ]; then
1738 diff -u $testroot/stdout.expected $testroot/stdout
1739 test_done "$testroot" "$ret"
1743 (cd $testroot/wt && got diff binary | grep '^Binary files' \
1745 echo "Binary files binary and binary differ
" \
1746 > $testroot/stdout.expected
1748 cmp -s $testroot/stdout.expected $testroot/stdout
1750 if [ $ret -ne 0 ]; then
1751 diff -u $testroot/stdout.expected $testroot/stdout
1752 test_done "$testroot" "$ret"
1756 test_done "$testroot" 0
1760 run_test test_unstage_basic
1761 run_test test_unstage_unversioned
1762 run_test test_unstage_nonexistent
1763 run_test test_unstage_patch
1764 run_test test_unstage_patch_added
1765 run_test test_unstage_patch_removed
1766 run_test test_unstage_patch_quit
1767 run_test test_unstage_symlink
1768 run_test test_unstage_patch_symlink
1769 run_test test_unstage_patch_binary