avoid needless use of STAILQ_FOREACH_SAFE, we are not removing elements here
[got.git] / regress / cmdline / unstage.sh
blob1f9c74b96419ec6eda2b937ea04a8b7cae1c8e5f
1 #!/bin/sh
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.
17 . ./common.sh
19 test_unstage_basic() {
20 local testroot=`test_init unstage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
26 return 1
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)
40 ret=$?
41 if [ $ret -ne 0 ]; then
42 echo "got unstage command failed unexpectedly" >&2
43 test_done "$testroot" "1"
44 return 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
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 diff -u $testroot/stdout.expected $testroot/stdout
54 test_done "$testroot" "$ret"
55 return 1
58 echo 'M alpha' > $testroot/stdout.expected
59 echo 'D beta' >> $testroot/stdout.expected
60 echo 'A foo' >> $testroot/stdout.expected
61 (cd $testroot/wt && got status > $testroot/stdout)
62 cmp -s $testroot/stdout.expected $testroot/stdout
63 ret=$?
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
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
74 ret=$?
75 if [ $ret -ne 0 ]; then
76 test_done "$testroot" "$ret"
77 return 1
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
98 ret=$?
99 if [ $ret -ne 0 ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 test_done "$testroot" "$ret"
102 return 1
105 (cd $testroot/wt && got unstage > $testroot/stdout)
106 ret=$?
107 if [ $ret -ne 0 ]; then
108 echo "got unstage command failed unexpectedly" >&2
109 test_done "$testroot" "1"
110 return 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
117 ret=$?
118 if [ $ret -ne 0 ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
121 return 1
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)
128 ret=$?
129 if [ $ret -ne 0 ]; then
130 echo "got unstage command failed unexpectedly" >&2
131 test_done "$testroot" "$ret"
132 return 1
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
141 ret=$?
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
152 ret=$?
153 if [ $ret -ne 0 ]; then
154 test_done "$testroot" "$ret"
155 return 1
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)
170 ret=$?
171 if [ $ret -ne 0 ]; then
172 echo "got unstage command failed unexpectedly" >&2
173 test_done "$testroot" "1"
174 return 1
177 echo -n > $testroot/stdout.expected
178 cmp -s $testroot/stdout.expected $testroot/stdout
179 ret=$?
180 if [ $ret -ne 0 ]; then
181 diff -u $testroot/stdout.expected $testroot/stdout
182 test_done "$testroot" "$ret"
183 return 1
186 cat > $testroot/stdout.expected <<EOF
187 M alpha
188 D beta
189 A foo
191 (cd $testroot/wt && got status > $testroot/stdout)
192 cmp -s $testroot/stdout.expected $testroot/stdout
193 ret=$?
194 if [ $ret -ne 0 ]; then
195 diff -u $testroot/stdout.expected $testroot/stdout
196 test_done "$testroot" "$ret"
197 return 1
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
205 !M alpha
206 D beta
207 A foo
209 (cd $testroot/wt && got status > $testroot/stdout)
210 cmp -s $testroot/stdout.expected $testroot/stdout
211 ret=$?
212 if [ $ret -ne 0 ]; then
213 diff -u $testroot/stdout.expected $testroot/stdout
214 test_done "$testroot" "$ret"
215 return 1
218 (cd $testroot/wt && got unstage > $testroot/stdout)
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 echo "got unstage command failed unexpectedly" >&2
222 test_done "$testroot" "1"
223 return 1
226 cat > $testroot/stdout.expected <<EOF
227 ! alpha
228 D beta
229 G foo
230 Files which had incoming changes but could not be found in the work tree: 1
232 cmp -s $testroot/stdout.expected $testroot/stdout
233 ret=$?
234 if [ $ret -ne 0 ]; then
235 diff -u $testroot/stdout.expected $testroot/stdout
236 test_done "$testroot" "$ret"
237 return 1
240 cat > $testroot/stdout.expected <<EOF
241 !M alpha
242 D beta
243 A foo
245 (cd $testroot/wt && got status > $testroot/stdout)
246 cmp -s $testroot/stdout.expected $testroot/stdout
247 ret=$?
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
264 ret=$?
265 if [ $ret -ne 0 ]; then
266 test_done "$testroot" "$ret"
267 return 1
270 ed -s $testroot/wt/numbers <<-\EOF
271 ,s/^2$/a/
272 ,s/^7$/b/
273 ,s/^16$/c/
277 (cd $testroot/wt && got stage > /dev/null)
278 ret=$?
279 if [ $ret -ne 0 ]; then
280 echo "got stage command failed unexpectedly" >&2
281 test_done "$testroot" "1"
282 return 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)
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 echo "got unstage command failed unexpectedly" >&2
292 test_done "$testroot" "1"
293 return 1
295 cat > $testroot/stdout.expected <<EOF
296 -----------------------------------------------
297 @@ -1,5 +1,5 @@
304 -----------------------------------------------
305 M numbers (change 1 of 3)
306 unstage this change? [y/n/q] n
307 -----------------------------------------------
308 @@ -4,7 +4,7 @@
317 -----------------------------------------------
318 M numbers (change 2 of 3)
319 unstage this change? [y/n/q] n
320 -----------------------------------------------
321 @@ -13,4 +13,4 @@
327 -----------------------------------------------
328 M numbers (change 3 of 3)
329 unstage this change? [y/n/q] n
331 cmp -s $testroot/stdout.expected $testroot/stdout
332 ret=$?
333 if [ $ret -ne 0 ]; then
334 diff -u $testroot/stdout.expected $testroot/stdout
335 test_done "$testroot" "$ret"
336 return 1
339 (cd $testroot/wt && got status > $testroot/stdout)
340 echo " M numbers" > $testroot/stdout.expected
341 cmp -s $testroot/stdout.expected $testroot/stdout
342 ret=$?
343 if [ $ret -ne 0 ]; then
344 diff -u $testroot/stdout.expected $testroot/stdout
345 test_done "$testroot" "$ret"
346 return 1
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 -----------------------------------------------
356 @@ -1,5 +1,5 @@
363 -----------------------------------------------
364 M numbers (change 1 of 3)
365 unstage this change? [y/n/q] n
366 -----------------------------------------------
367 @@ -4,7 +4,7 @@
376 -----------------------------------------------
377 M numbers (change 2 of 3)
378 unstage this change? [y/n/q] y
379 -----------------------------------------------
380 @@ -13,4 +13,4 @@
386 -----------------------------------------------
387 M numbers (change 3 of 3)
388 unstage this change? [y/n/q] n
389 G numbers
391 cmp -s $testroot/stdout.expected $testroot/stdout
392 ret=$?
393 if [ $ret -ne 0 ]; then
394 diff -u $testroot/stdout.expected $testroot/stdout
395 test_done "$testroot" "$ret"
396 return 1
399 (cd $testroot/wt && got status > $testroot/stdout)
400 echo "MM numbers" > $testroot/stdout.expected
401 cmp -s $testroot/stdout.expected $testroot/stdout
402 ret=$?
403 if [ $ret -ne 0 ]; then
404 diff -u $testroot/stdout.expected $testroot/stdout
405 test_done "$testroot" "$ret"
406 return 1
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
422 --- numbers
423 +++ numbers
424 @@ -1,5 +1,5 @@
431 @@ -13,4 +13,4 @@
438 cmp -s $testroot/stdout.expected $testroot/stdout
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
443 return 1
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
456 --- numbers
457 +++ numbers
458 @@ -4,7 +4,7 @@ a
468 cmp -s $testroot/stdout.expected $testroot/stdout
469 ret=$?
470 if [ $ret -ne 0 ]; then
471 diff -u $testroot/stdout.expected $testroot/stdout
472 test_done "$testroot" "$ret"
473 return 1
476 (cd $testroot/wt && got stage >/dev/null)
477 ret=$?
478 if [ $ret -ne 0 ]; then
479 echo "got stage command failed unexpectedly" >&2
480 test_done "$testroot" "1"
481 return 1
484 (cd $testroot/wt && got status > $testroot/stdout)
485 echo " M numbers" > $testroot/stdout.expected
486 cmp -s $testroot/stdout.expected $testroot/stdout
487 ret=$?
488 if [ $ret -ne 0 ]; then
489 diff -u $testroot/stdout.expected $testroot/stdout
490 test_done "$testroot" "$ret"
491 return 1
494 # unstage last hunk
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 -----------------------------------------------
501 @@ -1,5 +1,5 @@
508 -----------------------------------------------
509 M numbers (change 1 of 3)
510 unstage this change? [y/n/q] n
511 -----------------------------------------------
512 @@ -4,7 +4,7 @@
521 -----------------------------------------------
522 M numbers (change 2 of 3)
523 unstage this change? [y/n/q] n
524 -----------------------------------------------
525 @@ -13,4 +13,4 @@
531 -----------------------------------------------
532 M numbers (change 3 of 3)
533 unstage this change? [y/n/q] y
534 G numbers
536 cmp -s $testroot/stdout.expected $testroot/stdout
537 ret=$?
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 test_done "$testroot" "$ret"
541 return 1
544 (cd $testroot/wt && got status > $testroot/stdout)
545 echo "MM numbers" > $testroot/stdout.expected
546 cmp -s $testroot/stdout.expected $testroot/stdout
547 ret=$?
548 if [ $ret -ne 0 ]; then
549 diff -u $testroot/stdout.expected $testroot/stdout
550 test_done "$testroot" "$ret"
551 return 1
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
567 --- numbers
568 +++ numbers
569 @@ -1,10 +1,10 @@
583 cmp -s $testroot/stdout.expected $testroot/stdout
584 ret=$?
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 test_done "$testroot" "$ret"
588 return 1
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
601 --- numbers
602 +++ numbers
603 @@ -13,4 +13,4 @@ b
610 cmp -s $testroot/stdout.expected $testroot/stdout
611 ret=$?
612 if [ $ret -ne 0 ]; then
613 diff -u $testroot/stdout.expected $testroot/stdout
614 test_done "$testroot" "$ret"
615 return 1
618 (cd $testroot/wt && got stage >/dev/null)
619 ret=$?
620 if [ $ret -ne 0 ]; then
621 echo "got stage command failed unexpectedly" >&2
622 test_done "$testroot" "1"
623 return 1
626 (cd $testroot/wt && got status > $testroot/stdout)
627 echo " M numbers" > $testroot/stdout.expected
628 cmp -s $testroot/stdout.expected $testroot/stdout
629 ret=$?
630 if [ $ret -ne 0 ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 test_done "$testroot" "$ret"
633 return 1
636 # unstage all hunks
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 -----------------------------------------------
643 @@ -1,5 +1,5 @@
650 -----------------------------------------------
651 M numbers (change 1 of 3)
652 unstage this change? [y/n/q] y
653 -----------------------------------------------
654 @@ -4,7 +4,7 @@
663 -----------------------------------------------
664 M numbers (change 2 of 3)
665 unstage this change? [y/n/q] y
666 -----------------------------------------------
667 @@ -13,4 +13,4 @@
673 -----------------------------------------------
674 M numbers (change 3 of 3)
675 unstage this change? [y/n/q] y
676 G numbers
678 cmp -s $testroot/stdout.expected $testroot/stdout
679 ret=$?
680 if [ $ret -ne 0 ]; then
681 diff -u $testroot/stdout.expected $testroot/stdout
682 test_done "$testroot" "$ret"
683 return 1
686 (cd $testroot/wt && got status > $testroot/stdout)
687 echo "M numbers" > $testroot/stdout.expected
688 cmp -s $testroot/stdout.expected $testroot/stdout
689 ret=$?
690 if [ $ret -ne 0 ]; then
691 diff -u $testroot/stdout.expected $testroot/stdout
692 test_done "$testroot" "$ret"
693 return 1
696 (cd $testroot/wt && got diff -s > $testroot/stdout)
697 echo -n > $testroot/stdout.expected
698 cmp -s $testroot/stdout.expected $testroot/stdout
699 ret=$?
700 if [ $ret -ne 0 ]; then
701 diff -u $testroot/stdout.expected $testroot/stdout
702 test_done "$testroot" "$ret"
703 return 1
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
717 --- numbers
718 +++ numbers
719 @@ -1,10 +1,10 @@
732 @@ -13,4 +13,4 @@
739 cmp -s $testroot/stdout.expected $testroot/stdout
740 ret=$?
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
753 ret=$?
754 if [ $ret -ne 0 ]; then
755 test_done "$testroot" "$ret"
756 return 1
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
772 ret=$?
773 if [ $ret -ne 0 ]; then
774 diff -u $testroot/stdout.expected $testroot/stdout
775 test_done "$testroot" "$ret"
776 return 1
779 (cd $testroot/wt && got status > $testroot/stdout)
780 echo "A epsilon/new" > $testroot/stdout.expected
781 cmp -s $testroot/stdout.expected $testroot/stdout
782 ret=$?
783 if [ $ret -ne 0 ]; then
784 diff -u $testroot/stdout.expected $testroot/stdout
785 test_done "$testroot" "$ret"
786 return 1
789 (cd $testroot/wt && got diff -s > $testroot/stdout)
790 echo -n > $testroot/stdout.expected
791 cmp -s $testroot/stdout.expected $testroot/stdout
792 ret=$?
793 if [ $ret -ne 0 ]; then
794 diff -u $testroot/stdout.expected $testroot/stdout
795 test_done "$testroot" "$ret"
796 return 1
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
811 ret=$?
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
823 ret=$?
824 if [ $ret -ne 0 ]; then
825 test_done "$testroot" "$ret"
826 return 1
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
840 ret=$?
841 if [ $ret -ne 0 ]; then
842 diff -u $testroot/stdout.expected $testroot/stdout
843 test_done "$testroot" "$ret"
844 return 1
847 (cd $testroot/wt && got status > $testroot/stdout)
848 echo "D beta" > $testroot/stdout.expected
849 cmp -s $testroot/stdout.expected $testroot/stdout
850 ret=$?
851 if [ $ret -ne 0 ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
853 test_done "$testroot" "$ret"
854 return 1
857 (cd $testroot/wt && got diff -s > $testroot/stdout)
858 echo -n > $testroot/stdout.expected
859 cmp -s $testroot/stdout.expected $testroot/stdout
860 ret=$?
861 if [ $ret -ne 0 ]; then
862 diff -u $testroot/stdout.expected $testroot/stdout
863 test_done "$testroot" "$ret"
864 return 1
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
881 ret=$?
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
898 ret=$?
899 if [ $ret -ne 0 ]; then
900 test_done "$testroot" "$ret"
901 return 1
904 ed -s $testroot/wt/numbers <<-\EOF
905 ,s/^2$/a/
906 ,s/^7$/b/
907 ,s/^16$/c/
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 \
917 > $testroot/stdout)
918 ret=$?
919 if [ $ret -ne 0 ]; then
920 echo "got unstage command failed unexpectedly" >&2
921 test_done "$testroot" "1"
922 return 1
924 cat > $testroot/stdout.expected <<EOF
925 -----------------------------------------------
926 @@ -1,5 +1,5 @@
933 -----------------------------------------------
934 M numbers (change 1 of 3)
935 unstage this change? [y/n/q] y
936 -----------------------------------------------
937 @@ -4,7 +4,7 @@
946 -----------------------------------------------
947 M numbers (change 2 of 3)
948 unstage this change? [y/n/q] q
949 G numbers
950 D zzz
951 unstage this deletion? [y/n] n
953 cmp -s $testroot/stdout.expected $testroot/stdout
954 ret=$?
955 if [ $ret -ne 0 ]; then
956 diff -u $testroot/stdout.expected $testroot/stdout
957 test_done "$testroot" "$ret"
958 return 1
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
965 ret=$?
966 if [ $ret -ne 0 ]; then
967 diff -u $testroot/stdout.expected $testroot/stdout
968 test_done "$testroot" "$ret"
969 return 1
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
992 ret=$?
993 if [ $ret -ne 0 ]; then
994 diff -u $testroot/stdout.expected $testroot/stdout
995 test_done "$testroot" "$ret"
996 return 1
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
1011 --- numbers
1012 +++ numbers
1013 @@ -4,7 +4,7 @@
1022 @@ -13,4 +13,4 @@
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
1039 ret=$?
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
1059 ret=$?
1060 if [ $ret -ne 0 ]; then
1061 test_done "$testroot" "$ret"
1062 return 1
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
1080 M alpha.link
1081 A dotgotbar.link
1082 A dotgotfoo.link
1083 M epsilon/beta.link
1084 M epsilon.link
1085 D nonexistent.link
1086 A zeta.link
1088 cmp -s $testroot/stdout.expected $testroot/stdout
1089 ret=$?
1090 if [ $ret -ne 0 ]; then
1091 diff -u $testroot/stdout.expected $testroot/stdout
1092 test_done "$testroot" "$ret"
1093 return 1
1096 (cd $testroot/wt && got unstage > $testroot/stdout)
1097 ret=$?
1098 if [ $ret -ne 0 ]; then
1099 echo "got unstage command failed unexpectedly" >&2
1100 test_done "$testroot" "1"
1101 return 1
1104 cat > $testroot/stdout.expected <<EOF
1105 G alpha.link
1106 G dotgotbar.link
1107 G dotgotfoo.link
1108 G epsilon/beta.link
1109 G epsilon.link
1110 D nonexistent.link
1111 G zeta.link
1114 cmp -s $testroot/stdout.expected $testroot/stdout
1115 ret=$?
1116 if [ $ret -ne 0 ]; then
1117 diff -u $testroot/stdout.expected $testroot/stdout
1118 test_done "$testroot" "$ret"
1119 return 1
1122 if [ ! -h $testroot/wt/alpha.link ]; then
1123 echo "alpha.link is not a symlink"
1124 test_done "$testroot" "1"
1125 return 1
1128 readlink $testroot/wt/alpha.link > $testroot/stdout
1129 echo "beta" > $testroot/stdout.expected
1130 cmp -s $testroot/stdout.expected $testroot/stdout
1131 ret=$?
1132 if [ $ret -ne 0 ]; then
1133 diff -u $testroot/stdout.expected $testroot/stdout
1134 test_done "$testroot" "$ret"
1135 return 1
1138 if [ ! -h $testroot/wt/epsilon.link ]; then
1139 echo "epsilon.link is not a symlink"
1140 test_done "$testroot" "1"
1141 return 1
1144 readlink $testroot/wt/epsilon.link > $testroot/stdout
1145 echo "gamma" > $testroot/stdout.expected
1146 cmp -s $testroot/stdout.expected $testroot/stdout
1147 ret=$?
1148 if [ $ret -ne 0 ]; then
1149 diff -u $testroot/stdout.expected $testroot/stdout
1150 test_done "$testroot" "$ret"
1151 return 1
1154 if [ ! -h $testroot/wt/epsilon/beta.link ]; then
1155 echo "epsilon/beta.link is not a symlink"
1156 test_done "$testroot" "1"
1157 return 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
1163 ret=$?
1164 if [ $ret -ne 0 ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1166 test_done "$testroot" "$ret"
1167 return 1
1170 if [ ! -f $testroot/wt/dotgotfoo.link ]; then
1171 echo "dotgotfoo.link is a symlink"
1172 test_done "$testroot" "1"
1173 return 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
1179 ret=$?
1180 if [ $ret -ne 0 ]; then
1181 diff -u $testroot/content.expected $testroot/content
1182 test_done "$testroot" "$ret"
1183 return 1
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"
1190 return 1
1193 readlink $testroot/wt/dotgotbar.link > $testroot/stdout
1194 echo ".got/bar" > $testroot/stdout.expected
1195 cmp -s $testroot/stdout.expected $testroot/stdout
1196 ret=$?
1197 if [ $ret -ne 0 ]; then
1198 diff -u $testroot/stdout.expected $testroot/stdout
1199 test_done "$testroot" "$ret"
1200 return 1
1203 if [ -e $testroot/wt/nonexistent.link ]; then
1204 echo "nonexistent.link exists on disk"
1205 test_done "$testroot" "1"
1206 return 1
1209 if [ ! -h $testroot/wt/zeta.link ]; then
1210 echo "zeta.link is not a symlink"
1211 test_done "$testroot" "1"
1212 return 1
1215 readlink $testroot/wt/zeta.link > $testroot/stdout
1216 echo "gamma/delta" > $testroot/stdout.expected
1217 cmp -s $testroot/stdout.expected $testroot/stdout
1218 ret=$?
1219 if [ $ret -ne 0 ]; then
1220 diff -u $testroot/stdout.expected $testroot/stdout
1221 test_done "$testroot" "$ret"
1222 return 1
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
1243 ret=$?
1244 if [ $ret -ne 0 ]; then
1245 test_done "$testroot" "$ret"
1246 return 1
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 \
1257 epsilon/beta.link)
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)
1262 # removed symlink
1263 (cd $testroot/wt && got rm zeta.link > /dev/null)
1264 (cd $testroot/wt && got rm zeta2.link > /dev/null)
1265 # added symlink
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
1275 M alpha.link
1276 ? dotgotfoo.link
1277 M epsilon/beta.link
1278 M epsilon.link
1279 A new.link
1280 M nonexistent.link
1281 M passwd.link
1282 D zeta.link
1283 D zeta2.link
1284 A zeta3.link
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1287 ret=$?
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1290 test_done "$testroot" "$ret"
1291 return 1
1294 printf "y\nn\ny\nn\ny\ny\nn\ny\ny\n" > $testroot/patchscript
1295 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1296 > $testroot/stdout)
1297 ret=$?
1298 if [ $ret -ne 0 ]; then
1299 echo "got unstage command failed unexpectedly" >&2
1300 test_done "$testroot" "1"
1301 return 1
1304 cat > $testroot/stdout.expected <<EOF
1305 -----------------------------------------------
1306 @@ -1 +1 @@
1307 -alpha
1308 \ No newline at end of file
1309 +gamma/delta
1310 \ No newline at end of file
1311 -----------------------------------------------
1312 M alpha.link (change 1 of 1)
1313 unstage this change? [y/n/q] y
1314 G alpha.link
1315 -----------------------------------------------
1316 @@ -1 +1 @@
1317 -../beta
1318 \ No newline at end of file
1319 +../gamma
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 -----------------------------------------------
1325 @@ -1 +1 @@
1326 -epsilon
1327 \ No newline at end of file
1328 +beta
1329 \ No newline at end of file
1330 -----------------------------------------------
1331 M epsilon.link (change 1 of 1)
1332 unstage this change? [y/n/q] y
1333 G epsilon.link
1334 A new.link
1335 unstage this addition? [y/n] n
1336 -----------------------------------------------
1337 @@ -1 +1 @@
1338 -nonexistent
1339 \ No newline at end of file
1340 +nonexistent2
1341 \ No newline at end of file
1342 -----------------------------------------------
1343 M nonexistent.link (change 1 of 1)
1344 unstage this change? [y/n/q] y
1345 G nonexistent.link
1346 -----------------------------------------------
1347 @@ -1 +1 @@
1348 -/etc/passwd
1349 \ No newline at end of file
1350 +foo
1351 -----------------------------------------------
1352 M passwd.link (change 1 of 1)
1353 unstage this change? [y/n/q] y
1354 G passwd.link
1355 D zeta.link
1356 unstage this deletion? [y/n] n
1357 D zeta2.link
1358 unstage this deletion? [y/n] y
1359 D zeta2.link
1360 A zeta3.link
1361 unstage this addition? [y/n] y
1362 G zeta3.link
1364 cmp -s $testroot/stdout.expected $testroot/stdout
1365 ret=$?
1366 if [ $ret -ne 0 ]; then
1367 diff -u $testroot/stdout.expected $testroot/stdout
1368 test_done "$testroot" "$ret"
1369 return 1
1372 if ! [ -h $testroot/wt/alpha.link ]; then
1373 echo "alpha.link is not a symlink"
1374 test_done "$testroot" "1"
1375 return 1
1378 readlink $testroot/wt/alpha.link > $testroot/stdout
1379 echo "gamma/delta" > $testroot/stdout.expected
1380 cmp -s $testroot/stdout.expected $testroot/stdout
1381 ret=$?
1382 if [ $ret -ne 0 ]; then
1383 diff -u $testroot/stdout.expected $testroot/stdout
1384 test_done "$testroot" "$ret"
1385 return 1
1388 if ! [ -h $testroot/wt/epsilon.link ]; then
1389 echo "epsilon.link is not a symlink"
1390 test_done "$testroot" "1"
1391 return 1
1394 readlink $testroot/wt/epsilon.link > $testroot/stdout
1395 echo "beta" > $testroot/stdout.expected
1396 cmp -s $testroot/stdout.expected $testroot/stdout
1397 ret=$?
1398 if [ $ret -ne 0 ]; then
1399 diff -u $testroot/stdout.expected $testroot/stdout
1400 test_done "$testroot" "$ret"
1401 return 1
1404 if [ -h $testroot/wt/passwd.link ]; then
1405 echo "passwd.link should not be a symlink" >&2
1406 test_done "$testroot" "1"
1407 return 1
1410 echo "foo" > $testroot/content.expected
1411 cp $testroot/wt/passwd.link $testroot/content
1413 cmp -s $testroot/content.expected $testroot/content
1414 ret=$?
1415 if [ $ret -ne 0 ]; then
1416 diff -u $testroot/content.expected $testroot/content
1417 test_done "$testroot" "$ret"
1418 return 1
1421 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1422 echo "../gamma" > $testroot/stdout.expected
1423 cmp -s $testroot/stdout.expected $testroot/stdout
1424 ret=$?
1425 if [ $ret -ne 0 ]; then
1426 diff -u $testroot/stdout.expected $testroot/stdout
1427 test_done "$testroot" "$ret"
1428 return 1
1431 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1432 echo "nonexistent2" > $testroot/stdout.expected
1433 cmp -s $testroot/stdout.expected $testroot/stdout
1434 ret=$?
1435 if [ $ret -ne 0 ]; then
1436 diff -u $testroot/stdout.expected $testroot/stdout
1437 test_done "$testroot" "$ret"
1438 return 1
1441 if [ ! -h $testroot/wt/dotgotfoo.link ]; then
1442 echo "dotgotfoo.link is not a symlink " >&2
1443 test_done "$testroot" "1"
1444 return 1
1446 readlink $testroot/wt/dotgotfoo.link > $testroot/stdout
1447 echo ".got/foo" > $testroot/stdout.expected
1448 cmp -s $testroot/stdout.expected $testroot/stdout
1449 ret=$?
1450 if [ $ret -ne 0 ]; then
1451 diff -u $testroot/stdout.expected $testroot/stdout
1452 test_done "$testroot" "$ret"
1453 return 1
1457 if [ -e $testroot/wt/zeta.link ]; then
1458 echo -n "zeta.link should not exist on disk" >&2
1459 test_done "$testroot" "1"
1460 return 1
1463 if [ -e $testroot/wt/zeta2.link ]; then
1464 echo -n "zeta2.link exists on disk" >&2
1465 test_done "$testroot" "1"
1466 return 1
1469 if [ ! -h $testroot/wt/zeta3.link ]; then
1470 echo -n "zeta3.link is not a symlink" >&2
1471 test_done "$testroot" "1"
1472 return 1
1475 readlink $testroot/wt/zeta3.link > $testroot/stdout
1476 echo "beta" > $testroot/stdout.expected
1477 cmp -s $testroot/stdout.expected $testroot/stdout
1478 ret=$?
1479 if [ $ret -ne 0 ]; then
1480 diff -u $testroot/stdout.expected $testroot/stdout
1481 test_done "$testroot" "$ret"
1482 return 1
1485 if [ ! -h $testroot/wt/new.link ]; then
1486 echo -n "new.link is not a symlink" >&2
1487 test_done "$testroot" "1"
1488 return 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
1503 ret=$?
1504 if [ $ret -ne 0 ]; then
1505 diff -u $testroot/stdout.expected $testroot/stdout
1506 return 1
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 \
1515 > /dev/null 2>&1
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
1520 ret=$?
1521 if [ $ret -ne 0 ]; then
1522 echo "got checkout failed unexpectedly" >&2
1523 test_done "$testroot" "$ret"
1524 return 1
1527 ed -s $testroot/wt/binary <<-EOF
1529 7m16
1530 15m24
1531 23m32
1535 (cd $testroot/wt && got stage > /dev/null)
1536 ret=$?
1537 if [ $ret -ne 0 ]; then
1538 echo "got stage command failed unexpectedly" >&2
1539 test_done "$testroot" "1"
1540 return 1
1543 # cancel unstaging with 'n' response
1544 printf "n\n" > $testroot/patchscript
1545 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1546 > $testroot/stdout)
1547 ret=$?
1548 if [ $ret -ne 0 ]; then
1549 echo "got unstage command failed unexpectedly" >&2
1550 test_done "$testroot" "1"
1551 return 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
1563 ret=$?
1564 if [ $ret -ne 0 ]; then
1565 diff -u $testroot/stdout.expected $testroot/stdout
1566 test_done "$testroot" "$ret"
1567 return 1
1570 (cd $testroot/wt && got status > $testroot/stdout)
1571 echo " M binary" > $testroot/stdout.expected
1572 cmp -s $testroot/stdout.expected $testroot/stdout
1573 ret=$?
1574 if [ $ret -ne 0 ]; then
1575 diff -u $testroot/stdout.expected $testroot/stdout
1576 test_done "$testroot" "$ret"
1577 return 1
1580 # cancel unstaging with 'q' response
1581 printf "q\n" > $testroot/patchscript
1582 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1583 > $testroot/stdout)
1584 ret=$?
1585 if [ $ret -ne 0 ]; then
1586 echo "got unstage command failed unexpectedly" >&2
1587 test_done "$testroot" "1"
1588 return 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
1600 ret=$?
1601 if [ $ret -ne 0 ]; then
1602 diff -u $testroot/stdout.expected $testroot/stdout
1603 test_done "$testroot" "$ret"
1604 return 1
1607 (cd $testroot/wt && got status > $testroot/stdout)
1608 echo " M binary" > $testroot/stdout.expected
1609 cmp -s $testroot/stdout.expected $testroot/stdout
1610 ret=$?
1611 if [ $ret -ne 0 ]; then
1612 diff -u $testroot/stdout.expected $testroot/stdout
1613 test_done "$testroot" "$ret"
1614 return 1
1617 # confirm unstage with 'y'
1618 printf "y\n" > $testroot/patchscript
1619 (cd $testroot/wt && got unstage -F $testroot/patchscript -p \
1620 > $testroot/stdout)
1621 ret=$?
1622 if [ $ret -ne 0 ]; then
1623 echo "got unstage command failed unexpectedly" >&2
1624 test_done "$testroot" "1"
1625 return 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
1634 G binary
1637 cmp -s $testroot/stdout.expected $testroot/stdout
1638 ret=$?
1639 if [ $ret -ne 0 ]; then
1640 diff -u $testroot/stdout.expected $testroot/stdout
1641 test_done "$testroot" "$ret"
1642 return 1
1645 (cd $testroot/wt && got status > $testroot/stdout)
1646 echo "M binary" > $testroot/stdout.expected
1647 cmp -s $testroot/stdout.expected $testroot/stdout
1648 ret=$?
1649 if [ $ret -ne 0 ]; then
1650 diff -u $testroot/stdout.expected $testroot/stdout
1651 test_done "$testroot" "$ret"
1652 return 1
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
1660 ,s/^2$/x/
1661 ,s/^8$/y/
1662 ,s/^16$/z/
1666 (cd $testroot/wt && got stage > /dev/null)
1667 ret=$?
1668 if [ $ret -ne 0 ]; then
1669 echo "got stage command failed unexpectedly" >&2
1670 test_done "$testroot" "1"
1671 return 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 \
1677 > $testroot/stdout)
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
1685 G binary
1686 -----------------------------------------------
1687 @@ -1,5 +1,5 @@
1694 -----------------------------------------------
1695 M numbers (change 1 of 3)
1696 unstage this change? [y/n/q] n
1697 -----------------------------------------------
1698 @@ -5,7 +5,7 @@
1707 -----------------------------------------------
1708 M numbers (change 2 of 3)
1709 unstage this change? [y/n/q] n
1710 -----------------------------------------------
1711 @@ -13,4 +13,4 @@
1717 -----------------------------------------------
1718 M numbers (change 3 of 3)
1719 unstage this change? [y/n/q] y
1720 G numbers
1723 cmp -s $testroot/stdout.expected $testroot/stdout
1724 ret=$?
1725 if [ $ret -ne 0 ]; then
1726 diff -u $testroot/stdout.expected $testroot/stdout
1727 test_done "$testroot" "$ret"
1728 return 1
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
1736 ret=$?
1737 if [ $ret -ne 0 ]; then
1738 diff -u $testroot/stdout.expected $testroot/stdout
1739 test_done "$testroot" "$ret"
1740 return 1
1743 (cd $testroot/wt && got diff binary | grep '^Binary files' \
1744 > $testroot/stdout)
1745 echo "Binary files binary and binary differ" \
1746 > $testroot/stdout.expected
1748 cmp -s $testroot/stdout.expected $testroot/stdout
1749 ret=$?
1750 if [ $ret -ne 0 ]; then
1751 diff -u $testroot/stdout.expected $testroot/stdout
1752 test_done "$testroot" "$ret"
1753 return 1
1756 test_done "$testroot" 0
1759 test_parseargs "$@"
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