make got-read-gotconfig clear its imsgbuf before exit in an error case
[got-portable.git] / regress / cmdline / status.sh
blob4658f16da5cb7fe8af6858c1b088531c5f6f3b08
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_status_basic() {
20 local testroot=`test_init status_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 alpha" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta >/dev/null)
31 echo "unversioned file" > $testroot/wt/foo
32 rm $testroot/wt/epsilon/zeta
33 touch $testroot/wt/beta
34 echo "new file" > $testroot/wt/new
35 (cd $testroot/wt && got add new >/dev/null)
36 mkdir -m 0000 $testroot/wt/bar
38 echo 'M alpha' > $testroot/stdout.expected
39 echo 'D beta' >> $testroot/stdout.expected
40 echo '! epsilon/zeta' >> $testroot/stdout.expected
41 echo '? foo' >> $testroot/stdout.expected
42 echo 'A new' >> $testroot/stdout.expected
44 (cd $testroot/wt && got status > $testroot/stdout)
46 cmp -s $testroot/stdout.expected $testroot/stdout
47 ret=$?
48 if [ $ret -ne 0 ]; then
49 diff -u $testroot/stdout.expected $testroot/stdout
51 chmod 700 $testroot/wt/bar
52 rmdir $testroot/wt/bar
53 test_done "$testroot" "$ret"
56 test_status_subdir_no_mods() {
57 local testroot=`test_init status_subdir_no_mods 1`
59 mkdir $testroot/repo/Basic/
60 mkdir $testroot/repo/Basic/Targets/
61 touch $testroot/repo/Basic/Targets/AArch64.cpp
62 touch $testroot/repo/Basic/Targets.cpp
63 touch $testroot/repo/Basic/Targets.h
64 git -C $testroot/repo add .
65 git_commit $testroot/repo -m "add subdir with files"
67 got checkout $testroot/repo $testroot/wt > /dev/null
68 ret=$?
69 if [ $ret -ne 0 ]; then
70 test_done "$testroot" "$ret"
71 return 1
74 touch $testroot/stdout.expected
76 # This used to erroneously print:
78 # ! Basic/Targets.cpp
79 # ? Basic/Targets.cpp
80 (cd $testroot/wt && got status > $testroot/stdout)
82 cmp -s $testroot/stdout.expected $testroot/stdout
83 ret=$?
84 if [ $ret -ne 0 ]; then
85 diff -u $testroot/stdout.expected $testroot/stdout
87 test_done "$testroot" "$ret"
90 test_status_subdir_no_mods2() {
91 local testroot=`test_init status_subdir_no_mods2 1`
93 mkdir $testroot/repo/AST
94 touch $testroot/repo/AST/APValue.cpp
95 mkdir $testroot/repo/ASTMatchers
96 touch $testroot/repo/ASTMatchers/ASTMatchFinder.cpp
97 mkdir $testroot/repo/Frontend
98 touch $testroot/repo/Frontend/ASTConsumers.cpp
99 mkdir $testroot/repo/Frontend/Rewrite
100 touch $testroot/repo/Frontend/Rewrite/CMakeLists.txt
101 mkdir $testroot/repo/FrontendTool
102 touch $testroot/repo/FrontendTool/CMakeLists.txt
103 touch $testroot/repo/FrontendTool/ExecuteCompilerInvocation.cpp
104 git -C $testroot/repo add .
105 git_commit $testroot/repo -m "add subdir with files"
107 got checkout $testroot/repo $testroot/wt > /dev/null
108 ret=$?
109 if [ $ret -ne 0 ]; then
110 test_done "$testroot" "$ret"
111 return 1
114 touch $testroot/stdout.expected
116 # This used to erroneously print:
118 # ! AST/APValue.cpp
119 # ? AST/APValue.cpp
120 # ! Frontend/ASTConsumers.cpp
121 # ! Frontend/Rewrite/CMakeLists.txt
122 # ? Frontend/ASTConsumers.cpp
123 # ? Frontend/Rewrite/CMakeLists.txt
124 (cd $testroot/wt && got status > $testroot/stdout)
126 cmp -s $testroot/stdout.expected $testroot/stdout
127 ret=$?
128 if [ $ret -ne 0 ]; then
129 diff -u $testroot/stdout.expected $testroot/stdout
131 test_done "$testroot" "$ret"
134 test_status_obstructed() {
135 local testroot=`test_init status_obstructed`
137 got checkout $testroot/repo $testroot/wt > /dev/null
138 ret=$?
139 if [ $ret -ne 0 ]; then
140 test_done "$testroot" "$ret"
141 return 1
144 rm $testroot/wt/epsilon/zeta
145 mkdir $testroot/wt/epsilon/zeta
147 echo '~ epsilon/zeta' > $testroot/stdout.expected
149 (cd $testroot/wt && got status > $testroot/stdout)
151 cmp -s $testroot/stdout.expected $testroot/stdout
152 ret=$?
153 if [ $ret -ne 0 ]; then
154 diff -u $testroot/stdout.expected $testroot/stdout
155 test_done "$testroot" "$ret"
156 return 1
159 (cd $testroot/wt && got status epsilon/zeta > $testroot/stdout)
161 cmp -s $testroot/stdout.expected $testroot/stdout
162 ret=$?
163 if [ $ret -ne 0 ]; then
164 diff -u $testroot/stdout.expected $testroot/stdout
166 test_done "$testroot" "$ret"
169 test_status_shows_local_mods_after_update() {
170 local testroot=`test_init status_shows_local_mods_after_update 1`
172 echo "1" > $testroot/repo/numbers
173 echo "2" >> $testroot/repo/numbers
174 echo "3" >> $testroot/repo/numbers
175 echo "4" >> $testroot/repo/numbers
176 echo "5" >> $testroot/repo/numbers
177 echo "6" >> $testroot/repo/numbers
178 echo "7" >> $testroot/repo/numbers
179 echo "8" >> $testroot/repo/numbers
180 git -C $testroot/repo add numbers
181 git_commit $testroot/repo -m "added numbers file"
183 got checkout $testroot/repo $testroot/wt > /dev/null
184 ret=$?
185 if [ $ret -ne 0 ]; then
186 test_done "$testroot" "$ret"
187 return 1
190 ed -s $testroot/repo/numbers <<-\EOF
191 ,s/2/22/
194 git_commit $testroot/repo -m "modified line 2"
196 # modify line 7; both changes should merge cleanly
197 ed -s $testroot/wt/numbers <<-\EOF
198 ,s/7/77/
202 echo "G numbers" > $testroot/stdout.expected
203 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
204 git_show_head $testroot/repo >> $testroot/stdout.expected
205 echo >> $testroot/stdout.expected
207 (cd $testroot/wt && got update > $testroot/stdout)
209 cmp -s $testroot/stdout.expected $testroot/stdout
210 ret=$?
211 if [ $ret -ne 0 ]; then
212 diff -u $testroot/stdout.expected $testroot/stdout
213 test_done "$testroot" "$ret"
214 return 1
217 echo 'M numbers' > $testroot/stdout.expected
219 (cd $testroot/wt && got status > $testroot/stdout)
221 cmp -s $testroot/stdout.expected $testroot/stdout
222 ret=$?
223 if [ $ret -ne 0 ]; then
224 diff -u $testroot/stdout.expected $testroot/stdout
226 test_done "$testroot" "$ret"
229 test_status_unversioned_subdirs() {
230 local testroot=`test_init status_unversioned_subdirs 1`
232 mkdir $testroot/repo/cdfs/
233 touch $testroot/repo/cdfs/Makefile
234 mkdir $testroot/repo/common/
235 touch $testroot/repo/common/Makefile
236 mkdir $testroot/repo/iso/
237 touch $testroot/repo/iso/Makefile
238 mkdir $testroot/repo/ramdisk/
239 touch $testroot/repo/ramdisk/Makefile
240 touch $testroot/repo/ramdisk/list.local
241 mkdir $testroot/repo/ramdisk_cd/
242 touch $testroot/repo/ramdisk_cd/Makefile
243 touch $testroot/repo/ramdisk_cd/list.local
244 git -C $testroot/repo add .
245 git_commit $testroot/repo -m "first commit"
247 got checkout $testroot/repo $testroot/wt > /dev/null
248 ret=$?
249 if [ $ret -ne 0 ]; then
250 test_done "$testroot" "$ret"
251 return 1
254 mkdir $testroot/wt/cdfs/obj
255 mkdir $testroot/wt/ramdisk/obj
256 mkdir $testroot/wt/ramdisk_cd/obj
257 mkdir $testroot/wt/iso/obj
259 echo -n > $testroot/stdout.expected
261 # This used to erroneously print:
263 # ! ramdisk_cd/Makefile
264 # ! ramdisk_cd/list.local
265 # ? ramdisk_cd/Makefile
266 # ? ramdisk_cd/list.local
267 (cd $testroot/wt && got status > $testroot/stdout)
269 cmp -s $testroot/stdout.expected $testroot/stdout
270 ret=$?
271 if [ $ret -ne 0 ]; then
272 diff -u $testroot/stdout.expected $testroot/stdout
274 test_done "$testroot" "$ret"
277 test_status_symlink() {
278 local testroot=`test_init status_symlink`
280 mkdir $testroot/repo/ramdisk/
281 touch $testroot/repo/ramdisk/Makefile
282 (cd $testroot/repo && ln -s alpha alpha.link)
283 (cd $testroot/repo && ln -s epsilon epsilon.link)
284 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
285 git -C $testroot/repo add .
286 git_commit $testroot/repo -m "first commit"
288 got checkout $testroot/repo $testroot/wt > /dev/null
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 test_done "$testroot" "$ret"
292 return 1
295 ln -s /usr/obj/distrib/i386/ramdisk $testroot/wt/ramdisk/obj
297 echo "? ramdisk/obj" > $testroot/stdout.expected
299 (cd $testroot/wt && got status > $testroot/stdout)
301 cmp -s $testroot/stdout.expected $testroot/stdout
302 ret=$?
303 if [ $ret -ne 0 ]; then
304 diff -u $testroot/stdout.expected $testroot/stdout
305 test_done "$testroot" "$ret"
306 return 1
309 (cd $testroot/wt && ln -sf beta alpha.link)
310 (cd $testroot/wt && rm epsilon.link && ln -s gamma epsilon.link)
312 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
313 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
314 (cd $testroot/wt && got add passwd.link epsilon/beta.link > /dev/null)
316 (cd $testroot/wt && got rm nonexistent.link > /dev/null)
318 echo 'M alpha.link' > $testroot/stdout.expected
319 echo 'A epsilon/beta.link' >> $testroot/stdout.expected
320 echo 'M epsilon.link' >> $testroot/stdout.expected
321 echo 'D nonexistent.link' >> $testroot/stdout.expected
322 echo 'A passwd.link' >> $testroot/stdout.expected
323 echo "? ramdisk/obj" >> $testroot/stdout.expected
325 (cd $testroot/wt && got status > $testroot/stdout)
327 cmp -s $testroot/stdout.expected $testroot/stdout
328 ret=$?
329 if [ $ret -ne 0 ]; then
330 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
335 test_status_shows_no_mods_after_complete_merge() {
336 local testroot=`test_init status_shows_no_mods_after_complete_merge 1`
338 # make this file larger than the usual blob buffer size of 8192
339 seq 16384 > $testroot/repo/numbers
341 git -C $testroot/repo add numbers
342 git_commit $testroot/repo -m "added numbers file"
344 got checkout $testroot/repo $testroot/wt > /dev/null
345 ret=$?
346 if [ $ret -ne 0 ]; then
347 test_done "$testroot" "$ret"
348 return 1
351 ed -s $testroot/repo/numbers <<-\EOF
352 ,s/2/22/
355 git_commit $testroot/repo -m "modified line 2"
357 # modify line 2 again; no local changes are left after merge
358 ed -s $testroot/wt/numbers <<-\EOF
359 ,s/2/22/
363 echo "G numbers" > $testroot/stdout.expected
364 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
365 git_show_head $testroot/repo >> $testroot/stdout.expected
366 echo >> $testroot/stdout.expected
368 (cd $testroot/wt && got update > $testroot/stdout)
370 cmp -s $testroot/stdout.expected $testroot/stdout
371 ret=$?
372 if [ $ret -ne 0 ]; then
373 diff -u $testroot/stdout.expected $testroot/stdout
374 test_done "$testroot" "$ret"
375 return 1
378 echo -n > $testroot/stdout.expected
380 (cd $testroot/wt && got status > $testroot/stdout)
382 cmp -s $testroot/stdout.expected $testroot/stdout
383 ret=$?
384 if [ $ret -ne 0 ]; then
385 diff -u $testroot/stdout.expected $testroot/stdout
387 test_done "$testroot" "$ret"
390 test_status_shows_conflict() {
391 local testroot=`test_init status_shows_conflict 1`
393 echo "1" > $testroot/repo/numbers
394 echo "2" >> $testroot/repo/numbers
395 echo "3" >> $testroot/repo/numbers
396 echo "4" >> $testroot/repo/numbers
397 echo "5" >> $testroot/repo/numbers
398 echo "6" >> $testroot/repo/numbers
399 echo "7" >> $testroot/repo/numbers
400 echo "8" >> $testroot/repo/numbers
401 git -C $testroot/repo add numbers
402 git_commit $testroot/repo -m "added numbers file"
404 got checkout $testroot/repo $testroot/wt > /dev/null
405 ret=$?
406 if [ $ret -ne 0 ]; then
407 test_done "$testroot" "$ret"
408 return 1
411 ed -s $testroot/repo/numbers <<-\EOF
412 ,s/2/22/
415 git_commit $testroot/repo -m "modified line 2"
417 # modify line 2 in a conflicting way
418 ed -s $testroot/wt/numbers <<-\EOF
419 ,s/2/77/
423 echo "C numbers" > $testroot/stdout.expected
424 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
425 git_show_head $testroot/repo >> $testroot/stdout.expected
426 echo >> $testroot/stdout.expected
427 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
429 (cd $testroot/wt && got update > $testroot/stdout)
431 cmp -s $testroot/stdout.expected $testroot/stdout
432 ret=$?
433 if [ $ret -ne 0 ]; then
434 diff -u $testroot/stdout.expected $testroot/stdout
435 test_done "$testroot" "$ret"
436 return 1
439 echo 'C numbers' > $testroot/stdout.expected
441 (cd $testroot/wt && got status > $testroot/stdout)
443 cmp -s $testroot/stdout.expected $testroot/stdout
444 ret=$?
445 if [ $ret -ne 0 ]; then
446 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
451 test_status_empty_dir() {
452 local testroot=`test_init status_empty_dir`
454 got checkout $testroot/repo $testroot/wt > /dev/null
455 ret=$?
456 if [ $ret -ne 0 ]; then
457 test_done "$testroot" "$ret"
458 return 1
461 rm $testroot/wt/epsilon/zeta
463 echo '! epsilon/zeta' > $testroot/stdout.expected
465 (cd $testroot/wt && got status epsilon > $testroot/stdout)
467 cmp -s $testroot/stdout.expected $testroot/stdout
468 ret=$?
469 if [ $ret -ne 0 ]; then
470 diff -u $testroot/stdout.expected $testroot/stdout
472 test_done "$testroot" "$ret"
475 test_status_empty_dir_unversioned_file() {
476 local testroot=`test_init status_empty_dir_unversioned_file`
478 got checkout $testroot/repo $testroot/wt > /dev/null
479 ret=$?
480 if [ $ret -ne 0 ]; then
481 test_done "$testroot" "$ret"
482 return 1
485 rm $testroot/wt/epsilon/zeta
486 touch $testroot/wt/epsilon/unversioned
488 echo '? epsilon/unversioned' > $testroot/stdout.expected
489 echo '! epsilon/zeta' >> $testroot/stdout.expected
491 (cd $testroot/wt && got status epsilon > $testroot/stdout)
493 cmp -s $testroot/stdout.expected $testroot/stdout
494 ret=$?
495 if [ $ret -ne 0 ]; then
496 diff -u $testroot/stdout.expected $testroot/stdout
498 test_done "$testroot" "$ret"
501 test_status_many_paths() {
502 local testroot=`test_init status_many_paths`
504 got checkout $testroot/repo $testroot/wt > /dev/null
505 ret=$?
506 if [ $ret -ne 0 ]; then
507 test_done "$testroot" "$ret"
508 return 1
511 echo "modified alpha" > $testroot/wt/alpha
512 (cd $testroot/wt && got rm beta >/dev/null)
513 echo "unversioned file" > $testroot/wt/foo
514 rm $testroot/wt/epsilon/zeta
515 touch $testroot/wt/beta
516 echo "new file" > $testroot/wt/new
517 mkdir $testroot/wt/newdir
518 (cd $testroot/wt && got add new >/dev/null)
520 (cd $testroot/wt && got status alpha > $testroot/stdout.expected)
521 (cd $testroot/wt && got status beta >> $testroot/stdout.expected)
522 (cd $testroot/wt && got status epsilon >> $testroot/stdout.expected)
523 (cd $testroot/wt && got status foo >> $testroot/stdout.expected)
524 (cd $testroot/wt && got status new >> $testroot/stdout.expected)
525 (cd $testroot/wt && got status newdir >> $testroot/stdout.expected)
526 (cd $testroot/wt && got status . >> $testroot/stdout.expected)
528 (cd $testroot/wt && got status newdir alpha epsilon foo new beta . \
529 > $testroot/stdout)
531 cmp -s $testroot/stdout.expected $testroot/stdout
532 ret=$?
533 if [ $ret -ne 0 ]; then
534 diff -u $testroot/stdout.expected $testroot/stdout
536 test_done "$testroot" "$ret"
539 test_status_cvsignore() {
540 local testroot=`test_init status_cvsignore`
542 got checkout $testroot/repo $testroot/wt > /dev/null
543 ret=$?
544 if [ $ret -ne 0 ]; then
545 test_done "$testroot" "$ret"
546 return 1
549 echo "unversioned file" > $testroot/wt/foo
550 echo "unversioned file" > $testroot/wt/foop
551 echo "unversioned file" > $testroot/wt/epsilon/foo
552 echo "unversioned file" > $testroot/wt/epsilon/bar
553 echo "unversioned file" > $testroot/wt/epsilon/boo
554 echo "unversioned file" > $testroot/wt/epsilon/moo
555 mkdir -p $testroot/wt/epsilon/new/
556 echo "unversioned file" > $testroot/wt/epsilon/new/foo
557 echo "**/foo" > $testroot/wt/.cvsignore
558 echo "**/gamma" >> $testroot/wt/.cvsignore
559 echo "bar" > $testroot/wt/epsilon/.cvsignore
560 echo "moo" >> $testroot/wt/epsilon/.cvsignore
562 echo '? .cvsignore' > $testroot/stdout.expected
563 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
564 echo '? epsilon/boo' >> $testroot/stdout.expected
565 echo '? foop' >> $testroot/stdout.expected
566 (cd $testroot/wt && got status > $testroot/stdout)
568 cmp -s $testroot/stdout.expected $testroot/stdout
569 ret=$?
570 if [ $ret -ne 0 ]; then
571 diff -u $testroot/stdout.expected $testroot/stdout
572 test_done "$testroot" "$ret"
573 return 1
576 echo '? epsilon/.cvsignore' > $testroot/stdout.expected
577 echo '? epsilon/boo' >> $testroot/stdout.expected
578 (cd $testroot/wt && got status epsilon > $testroot/stdout)
580 cmp -s $testroot/stdout.expected $testroot/stdout
581 ret=$?
582 if [ $ret -ne 0 ]; then
583 diff -u $testroot/stdout.expected $testroot/stdout
584 test_done "$testroot" "$ret"
585 return 1
588 echo -n '' > $testroot/stdout.expected
589 (cd $testroot/wt && got status epsilon/new > $testroot/stdout)
591 cmp -s $testroot/stdout.expected $testroot/stdout
592 ret=$?
593 if [ $ret -ne 0 ]; then
594 diff -u $testroot/stdout.expected $testroot/stdout
595 test_done "$testroot" "$ret"
596 return 1
599 echo '? .cvsignore' > $testroot/stdout.expected
600 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
601 echo '? epsilon/boo' >> $testroot/stdout.expected
602 echo '? foop' >> $testroot/stdout.expected
603 (cd $testroot/wt/gamma && got status > $testroot/stdout)
605 cmp -s $testroot/stdout.expected $testroot/stdout
606 ret=$?
607 if [ $ret -ne 0 ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 test_done "$testroot" "$ret"
610 return 1
613 cat > $testroot/stdout.expected <<EOF
614 ? .cvsignore
615 ? epsilon/.cvsignore
616 ? epsilon/bar
617 ? epsilon/boo
618 ? epsilon/foo
619 ? epsilon/moo
620 ? epsilon/new/foo
621 ? foo
622 ? foop
624 (cd $testroot/wt && got status -I > $testroot/stdout)
625 ret=$?
626 if [ $ret -ne 0 ]; then
627 echo "got status failed unexpectedly" >&2
628 test_done "$testroot" "1"
629 return 1
632 cmp -s $testroot/stdout.expected $testroot/stdout
633 ret=$?
634 if [ $ret -ne 0 ]; then
635 diff -u $testroot/stdout.expected $testroot/stdout
637 test_done "$testroot" "$ret"
640 test_status_gitignore() {
641 local testroot=`test_init status_gitignore`
643 got checkout $testroot/repo $testroot/wt > /dev/null
644 ret=$?
645 if [ $ret -ne 0 ]; then
646 test_done "$testroot" "$ret"
647 return 1
650 echo "unversioned file" > $testroot/wt/foo
651 echo "unversioned file" > $testroot/wt/foop
652 echo "unversioned file" > $testroot/wt/barp
653 echo "unversioned file" > $testroot/wt/epsilon/bar
654 echo "unversioned file" > $testroot/wt/epsilon/boo
655 echo "unversioned file" > $testroot/wt/epsilon/moo
656 mkdir -p $testroot/wt/a/b/c/
657 echo "unversioned file" > $testroot/wt/a/b/c/foo
658 echo "unversioned file" > $testroot/wt/a/b/c/zoo
659 echo "foo" > $testroot/wt/.gitignore
660 echo "bar*" >> $testroot/wt/.gitignore
661 echo "epsilon/**" >> $testroot/wt/.gitignore
662 echo "a/**/foo" >> $testroot/wt/.gitignore
663 echo "**/zoo" >> $testroot/wt/.gitignore
665 echo '? .gitignore' > $testroot/stdout.expected
666 echo '? foop' >> $testroot/stdout.expected
667 (cd $testroot/wt && got status > $testroot/stdout)
669 cmp -s $testroot/stdout.expected $testroot/stdout
670 ret=$?
671 if [ $ret -ne 0 ]; then
672 diff -u $testroot/stdout.expected $testroot/stdout
673 test_done "$testroot" "$ret"
674 return 1
677 echo '? .gitignore' > $testroot/stdout.expected
678 echo '? foop' >> $testroot/stdout.expected
679 (cd $testroot/wt/gamma && got status > $testroot/stdout)
681 cmp -s $testroot/stdout.expected $testroot/stdout
682 ret=$?
683 if [ $ret -ne 0 ]; then
684 diff -u $testroot/stdout.expected $testroot/stdout
685 test_done "$testroot" "$ret"
686 return 1
689 cat > $testroot/stdout.expected <<EOF
690 ? .gitignore
691 ? a/b/c/foo
692 ? a/b/c/zoo
693 ? barp
694 ? epsilon/bar
695 ? epsilon/boo
696 ? epsilon/moo
697 ? foo
698 ? foop
700 (cd $testroot/wt && got status -I > $testroot/stdout)
701 ret=$?
702 if [ $ret -ne 0 ]; then
703 echo "got status failed unexpectedly" >&2
704 test_done "$testroot" "1"
705 return 1
708 cmp -s $testroot/stdout.expected $testroot/stdout
709 ret=$?
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stdout.expected $testroot/stdout
713 test_done "$testroot" "$ret"
716 test_status_gitignore_trailing_slashes() {
717 local testroot=`test_init status_gitignore_trailing_slashes`
719 got checkout $testroot/repo $testroot/wt > /dev/null
720 ret=$?
721 if [ $ret -ne 0 ]; then
722 test_done "$testroot" "$ret"
723 return 1
726 echo "unversioned file" > $testroot/wt/foo
727 echo "unversioned file" > $testroot/wt/epsilon/bar
728 echo "unversioned file" > $testroot/wt/epsilon/boo
729 echo "unversioned file" > $testroot/wt/epsilon/moo
730 echo "unversioned file" > $testroot/wt/upsilon
732 # Match the directory epsilon but not the regular file upsilon
733 echo "*psilon/" > $testroot/wt/.gitignore
735 echo '? .gitignore' > $testroot/stdout.expected
736 echo '? foo' >> $testroot/stdout.expected
737 echo '? upsilon' >> $testroot/stdout.expected
738 (cd $testroot/wt && got status > $testroot/stdout)
740 cmp -s $testroot/stdout.expected $testroot/stdout
741 ret=$?
742 if [ $ret -ne 0 ]; then
743 diff -u $testroot/stdout.expected $testroot/stdout
745 test_done "$testroot" "$ret"
748 test_status_gitignore_comments() {
749 local testroot=`test_init status_gitignore_comments`
751 got checkout $testroot/repo $testroot/wt > /dev/null
752 ret=$?
753 if [ $ret -ne 0 ]; then
754 test_done "$testroot" "$ret"
755 return 1
758 echo "unversioned file" > $testroot/wt/foo
759 echo "unversioned file" > $testroot/wt/epsilon/bar
760 echo "unversioned file" > $testroot/wt/epsilon/boo
761 echo "unversioned file" > $testroot/wt/upsilon
763 echo "# comment" > $testroot/wt/.gitignore
764 echo "" >> $testroot/wt/.gitignore
765 echo "foo" >> $testroot/wt/.gitignore
766 echo "# comment" > $testroot/wt/epsilon/.gitignore
767 echo "" >> $testroot/wt/epsilon/.gitignore
768 echo "bar" >> $testroot/wt/epsilon/.gitignore
770 echo '? .gitignore' > $testroot/stdout.expected
771 echo '? epsilon/.gitignore' >> $testroot/stdout.expected
772 echo '? epsilon/boo' >> $testroot/stdout.expected
773 echo '? upsilon' >> $testroot/stdout.expected
774 (cd $testroot/wt && got status > $testroot/stdout)
776 cmp -s $testroot/stdout.expected $testroot/stdout
777 ret=$?
778 if [ $ret -ne 0 ]; then
779 diff -u $testroot/stdout.expected $testroot/stdout
781 test_done "$testroot" "$ret"
784 test_status_status_code() {
785 local testroot=`test_init status_status_code`
787 got checkout $testroot/repo $testroot/wt > /dev/null
788 ret=$?
789 if [ $ret -ne 0 ]; then
790 test_done "$testroot" "$ret"
791 return 1
794 echo "modified alpha" > $testroot/wt/alpha
795 (cd $testroot/wt && got rm beta >/dev/null)
796 echo "unversioned file" > $testroot/wt/foo
797 rm $testroot/wt/epsilon/zeta
798 touch $testroot/wt/beta
799 echo "new file" > $testroot/wt/new
800 (cd $testroot/wt && got add new >/dev/null)
802 (cd $testroot/wt && got status -s xDM \
803 > $testroot/stdout 2> $testroot/stderr)
804 ret=$?
805 if [ $ret -eq 0 ]; then
806 echo "status succeeded unexpectedly" >&2
807 test_done "$testroot" "1"
808 return 1
811 echo "got: invalid status code 'x'" > $testroot/stderr.expected
812 cmp -s $testroot/stderr.expected $testroot/stderr
813 ret=$?
814 if [ $ret -ne 0 ]; then
815 diff -u $testroot/stderr.expected $testroot/stderr
816 test_done "$testroot" "$ret"
817 return 1
820 echo 'M alpha' > $testroot/stdout.expected
821 (cd $testroot/wt && got status -s M > $testroot/stdout)
822 cmp -s $testroot/stdout.expected $testroot/stdout
823 ret=$?
824 if [ $ret -ne 0 ]; then
825 diff -u $testroot/stdout.expected $testroot/stdout
826 test_done "$testroot" "$ret"
827 return 1
830 echo 'D beta' > $testroot/stdout.expected
831 (cd $testroot/wt && got status -s D > $testroot/stdout)
832 cmp -s $testroot/stdout.expected $testroot/stdout
833 ret=$?
834 if [ $ret -ne 0 ]; then
835 diff -u $testroot/stdout.expected $testroot/stdout
836 test_done "$testroot" "$ret"
837 return 1
840 echo '! epsilon/zeta' > $testroot/stdout.expected
841 echo '? foo' >> $testroot/stdout.expected
842 (cd $testroot/wt && got status -s !\? > $testroot/stdout)
843 cmp -s $testroot/stdout.expected $testroot/stdout
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
847 test_done "$testroot" "$ret"
848 return 1
851 echo 'A new' > $testroot/stdout.expected
852 (cd $testroot/wt && got status -s A > $testroot/stdout)
853 cmp -s $testroot/stdout.expected $testroot/stdout
854 ret=$?
855 if [ $ret -ne 0 ]; then
856 diff -u $testroot/stdout.expected $testroot/stdout
857 test_done "$testroot" "$ret"
858 return 1
861 (cd $testroot/wt && got stage new > $testroot/stdout)
863 echo ' A new' > $testroot/stdout.expected
864 (cd $testroot/wt && got status -s A > $testroot/stdout)
865 cmp -s $testroot/stdout.expected $testroot/stdout
866 ret=$?
867 if [ $ret -ne 0 ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 test_done "$testroot" "$ret"
870 return 1
873 echo 'changed file new' > $testroot/wt/new
875 echo 'MA new' > $testroot/stdout.expected
876 (cd $testroot/wt && got status -s A > $testroot/stdout)
877 cmp -s $testroot/stdout.expected $testroot/stdout
878 ret=$?
879 if [ $ret -ne 0 ]; then
880 diff -u $testroot/stdout.expected $testroot/stdout
881 test_done "$testroot" "$ret"
882 return 1
885 echo 'M alpha' > $testroot/stdout.expected
886 echo 'MA new' >> $testroot/stdout.expected
887 (cd $testroot/wt && got status -s M > $testroot/stdout)
888 cmp -s $testroot/stdout.expected $testroot/stdout
889 ret=$?
890 if [ $ret -ne 0 ]; then
891 diff -u $testroot/stdout.expected $testroot/stdout
892 test_done "$testroot" "$ret"
893 return 1
896 test_done "$testroot" "$ret"
899 test_status_suppress() {
900 local testroot=`test_init status_suppress`
902 got checkout $testroot/repo $testroot/wt > /dev/null
903 ret=$?
904 if [ $ret -ne 0 ]; then
905 test_done "$testroot" "$ret"
906 return 1
909 echo "modified alpha" > $testroot/wt/alpha
910 (cd $testroot/wt && got rm beta >/dev/null)
911 echo "unversioned file" > $testroot/wt/foo
912 rm $testroot/wt/epsilon/zeta
913 touch $testroot/wt/beta
914 echo "new file" > $testroot/wt/new
915 (cd $testroot/wt && got add new >/dev/null)
917 (cd $testroot/wt && got status -S A -s M \
918 > $testroot/stdout 2> $testroot/stderr)
919 ret=$?
920 if [ $ret -eq 0 ]; then
921 echo "status succeeded unexpectedly" >&2
922 test_done "$testroot" "1"
923 return 1
926 echo "got: -s and -S options are mutually exclusive" \
927 > $testroot/stderr.expected
928 cmp -s $testroot/stderr.expected $testroot/stderr
929 ret=$?
930 if [ $ret -ne 0 ]; then
931 diff -u $testroot/stderr.expected $testroot/stderr
932 test_done "$testroot" "$ret"
933 return 1
936 (cd $testroot/wt && got status -s A -S M \
937 > $testroot/stdout 2> $testroot/stderr)
938 ret=$?
939 if [ $ret -eq 0 ]; then
940 echo "status succeeded unexpectedly" >&2
941 test_done "$testroot" "1"
942 return 1
945 echo "got: -S and -s options are mutually exclusive" \
946 > $testroot/stderr.expected
947 cmp -s $testroot/stderr.expected $testroot/stderr
948 ret=$?
949 if [ $ret -ne 0 ]; then
950 diff -u $testroot/stderr.expected $testroot/stderr
951 test_done "$testroot" "$ret"
952 return 1
955 (cd $testroot/wt && got status -S xDM \
956 > $testroot/stdout 2> $testroot/stderr)
957 ret=$?
958 if [ $ret -eq 0 ]; then
959 echo "status succeeded unexpectedly" >&2
960 test_done "$testroot" "1"
961 return 1
964 echo "got: invalid status code 'x'" > $testroot/stderr.expected
965 cmp -s $testroot/stderr.expected $testroot/stderr
966 ret=$?
967 if [ $ret -ne 0 ]; then
968 diff -u $testroot/stderr.expected $testroot/stderr
969 test_done "$testroot" "$ret"
970 return 1
973 echo 'M alpha' > $testroot/stdout.expected
974 (cd $testroot/wt && got status -S D\?A! > $testroot/stdout)
975 cmp -s $testroot/stdout.expected $testroot/stdout
976 ret=$?
977 if [ $ret -ne 0 ]; then
978 diff -u $testroot/stdout.expected $testroot/stdout
979 test_done "$testroot" "$ret"
980 return 1
983 echo 'D beta' > $testroot/stdout.expected
984 (cd $testroot/wt && got status -S M\?A! > $testroot/stdout)
985 cmp -s $testroot/stdout.expected $testroot/stdout
986 ret=$?
987 if [ $ret -ne 0 ]; then
988 diff -u $testroot/stdout.expected $testroot/stdout
989 test_done "$testroot" "$ret"
990 return 1
993 echo '! epsilon/zeta' > $testroot/stdout.expected
994 echo '? foo' >> $testroot/stdout.expected
995 (cd $testroot/wt && got status -S MDA > $testroot/stdout)
996 cmp -s $testroot/stdout.expected $testroot/stdout
997 ret=$?
998 if [ $ret -ne 0 ]; then
999 diff -u $testroot/stdout.expected $testroot/stdout
1000 test_done "$testroot" "$ret"
1001 return 1
1004 echo 'A new' > $testroot/stdout.expected
1005 (cd $testroot/wt && got status -S MD\?! > $testroot/stdout)
1006 cmp -s $testroot/stdout.expected $testroot/stdout
1007 ret=$?
1008 if [ $ret -ne 0 ]; then
1009 diff -u $testroot/stdout.expected $testroot/stdout
1010 test_done "$testroot" "$ret"
1011 return 1
1014 (cd $testroot/wt && got stage new > $testroot/stdout)
1016 echo ' A new' > $testroot/stdout.expected
1017 (cd $testroot/wt && got status -S MD\?! > $testroot/stdout)
1018 cmp -s $testroot/stdout.expected $testroot/stdout
1019 ret=$?
1020 if [ $ret -ne 0 ]; then
1021 diff -u $testroot/stdout.expected $testroot/stdout
1022 test_done "$testroot" "$ret"
1023 return 1
1026 echo 'changed file new' > $testroot/wt/new
1028 echo 'M alpha' > $testroot/stdout.expected
1029 echo 'MA new' >> $testroot/stdout.expected
1030 (cd $testroot/wt && got status -S D\?! > $testroot/stdout)
1031 cmp -s $testroot/stdout.expected $testroot/stdout
1032 ret=$?
1033 if [ $ret -ne 0 ]; then
1034 diff -u $testroot/stdout.expected $testroot/stdout
1035 test_done "$testroot" "$ret"
1036 return 1
1039 echo 'M alpha' > $testroot/stdout.expected
1040 (cd $testroot/wt && got status -S AD\?! > $testroot/stdout)
1041 cmp -s $testroot/stdout.expected $testroot/stdout
1042 ret=$?
1043 if [ $ret -ne 0 ]; then
1044 diff -u $testroot/stdout.expected $testroot/stdout
1045 test_done "$testroot" "$ret"
1046 return 1
1049 rm $testroot/stdout.expected
1050 touch $testroot/stdout.expected
1052 (cd $testroot/wt && got status -S MD\?! > $testroot/stdout)
1053 cmp -s $testroot/stdout.expected $testroot/stdout
1054 ret=$?
1055 if [ $ret -ne 0 ]; then
1056 diff -u $testroot/stdout.expected $testroot/stdout
1057 test_done "$testroot" "$ret"
1058 return 1
1061 test_done "$testroot" "$ret"
1064 test_status_empty_file() {
1065 local testroot=`test_init status_empty_file`
1067 got checkout $testroot/repo $testroot/wt > /dev/null
1068 ret=$?
1069 if [ $ret -ne 0 ]; then
1070 test_done "$testroot" "$ret"
1071 return 1
1074 echo -n "" > $testroot/wt/empty
1075 (cd $testroot/wt && got add empty >/dev/null)
1077 echo 'A empty' > $testroot/stdout.expected
1079 (cd $testroot/wt && got status > $testroot/stdout)
1081 cmp -s $testroot/stdout.expected $testroot/stdout
1082 ret=$?
1083 if [ $ret -ne 0 ]; then
1084 diff -u $testroot/stdout.expected $testroot/stdout
1085 test_done "$testroot" "$ret"
1086 return 1
1089 (cd $testroot/wt && got commit -m "empty file" >/dev/null)
1091 (cd $testroot/wt && got status > $testroot/stdout)
1093 echo -n > $testroot/stdout.expected
1094 cmp -s $testroot/stdout.expected $testroot/stdout
1095 ret=$?
1096 if [ $ret -ne 0 ]; then
1097 diff -u $testroot/stdout.expected $testroot/stdout
1098 test_done "$testroot" "$ret"
1099 return 1
1102 # update the timestamp; this used to make the file show up as:
1103 # M empty
1104 # which should not happen
1105 touch $testroot/wt/empty
1107 (cd $testroot/wt && got status > $testroot/stdout)
1109 echo -n > $testroot/stdout.expected
1110 cmp -s $testroot/stdout.expected $testroot/stdout
1111 ret=$?
1112 if [ $ret -ne 0 ]; then
1113 diff -u $testroot/stdout.expected $testroot/stdout
1115 test_done "$testroot" "$ret"
1118 test_status_in_repo() {
1119 local testroot=`test_init status_in_repo`
1121 (cd $testroot/repo && got status > $testroot/stdout \
1122 2> $testroot/stderr)
1124 cat > $testroot/stderr.expected <<EOF
1125 got: 'got status' needs a work tree in addition to a git repository
1126 Work trees can be checked out from this Git repository with 'got checkout'.
1127 The got(1) manual page contains more information.
1129 cmp -s $testroot/stderr.expected $testroot/stderr
1130 ret=$?
1131 if [ $ret -ne 0 ]; then
1132 diff -u $testroot/stderr.expected $testroot/stderr
1134 test_done "$testroot" "$ret"
1137 test_parseargs "$@"
1138 run_test test_status_basic
1139 run_test test_status_subdir_no_mods
1140 run_test test_status_subdir_no_mods2
1141 run_test test_status_obstructed
1142 run_test test_status_shows_local_mods_after_update
1143 run_test test_status_unversioned_subdirs
1144 run_test test_status_symlink
1145 run_test test_status_shows_no_mods_after_complete_merge
1146 run_test test_status_shows_conflict
1147 run_test test_status_empty_dir
1148 run_test test_status_empty_dir_unversioned_file
1149 run_test test_status_many_paths
1150 run_test test_status_cvsignore
1151 run_test test_status_gitignore
1152 run_test test_status_gitignore_trailing_slashes
1153 run_test test_status_gitignore_comments
1154 run_test test_status_status_code
1155 run_test test_status_suppress
1156 run_test test_status_empty_file
1157 run_test test_status_in_repo