Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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
27 fi
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
50 fi
51 chmod 700 $testroot/wt/bar
52 rmdir $testroot/wt/bar
53 test_done "$testroot" "$ret"
54 }
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 (cd $testroot/repo && git 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
72 fi
74 touch $testroot/stdout.expected
76 # This used to erroneously print:
77 #
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
86 fi
87 test_done "$testroot" "$ret"
88 }
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 (cd $testroot/repo && git 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
112 fi
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
130 fi
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
142 fi
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
157 fi
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
165 fi
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 (cd $testroot/repo && git 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
188 fi
190 ed -s $testroot/repo/numbers <<-\EOF
191 ,s/2/22/
193 EOF
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/
200 EOF
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
215 fi
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
225 fi
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 (cd $testroot/repo && git 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
252 fi
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
273 fi
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 (cd $testroot/repo && git 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
293 fi
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
307 fi
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
331 fi
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 jot 16384 > $testroot/repo/numbers
341 (cd $testroot/repo && git 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
349 fi
351 ed -s $testroot/repo/numbers <<-\EOF
352 ,s/2/22/
354 EOF
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/
361 EOF
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
376 fi
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
386 fi
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 (cd $testroot/repo && git 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
409 fi
411 ed -s $testroot/repo/numbers <<-\EOF
412 ,s/2/22/
414 EOF
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/
421 EOF
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
437 fi
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
447 fi
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
459 fi
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
471 fi
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
483 fi
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
497 fi
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
509 fi
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
535 fi
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
547 fi
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
574 fi
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
586 fi
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
597 fi
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
611 fi
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
623 EOF
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
630 fi
632 cmp -s $testroot/stdout.expected $testroot/stdout
633 ret=$?
634 if [ $ret -ne 0 ]; then
635 diff -u $testroot/stdout.expected $testroot/stdout
636 fi
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
648 fi
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
675 fi
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
687 fi
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
699 EOF
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
706 fi
708 cmp -s $testroot/stdout.expected $testroot/stdout
709 ret=$?
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stdout.expected $testroot/stdout
712 fi
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
724 fi
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
744 fi
745 test_done "$testroot" "$ret"
748 test_status_status_code() {
749 local testroot=`test_init status_status_code`
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
756 fi
758 echo "modified alpha" > $testroot/wt/alpha
759 (cd $testroot/wt && got rm beta >/dev/null)
760 echo "unversioned file" > $testroot/wt/foo
761 rm $testroot/wt/epsilon/zeta
762 touch $testroot/wt/beta
763 echo "new file" > $testroot/wt/new
764 (cd $testroot/wt && got add new >/dev/null)
766 (cd $testroot/wt && got status -s xDM \
767 > $testroot/stdout 2> $testroot/stderr)
768 ret=$?
769 if [ $ret -eq 0 ]; then
770 echo "status succeeded unexpectedly" >&2
771 test_done "$testroot" "1"
772 return 1
773 fi
775 echo "got: invalid status code 'x'" > $testroot/stderr.expected
776 cmp -s $testroot/stderr.expected $testroot/stderr
777 ret=$?
778 if [ $ret -ne 0 ]; then
779 diff -u $testroot/stderr.expected $testroot/stderr
780 test_done "$testroot" "$ret"
781 return 1
782 fi
784 echo 'M alpha' > $testroot/stdout.expected
785 (cd $testroot/wt && got status -s M > $testroot/stdout)
786 cmp -s $testroot/stdout.expected $testroot/stdout
787 ret=$?
788 if [ $ret -ne 0 ]; then
789 diff -u $testroot/stdout.expected $testroot/stdout
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 echo 'D beta' > $testroot/stdout.expected
795 (cd $testroot/wt && got status -s D > $testroot/stdout)
796 cmp -s $testroot/stdout.expected $testroot/stdout
797 ret=$?
798 if [ $ret -ne 0 ]; then
799 diff -u $testroot/stdout.expected $testroot/stdout
800 test_done "$testroot" "$ret"
801 return 1
802 fi
804 echo '! epsilon/zeta' > $testroot/stdout.expected
805 echo '? foo' >> $testroot/stdout.expected
806 (cd $testroot/wt && got status -s !\? > $testroot/stdout)
807 cmp -s $testroot/stdout.expected $testroot/stdout
808 ret=$?
809 if [ $ret -ne 0 ]; then
810 diff -u $testroot/stdout.expected $testroot/stdout
811 test_done "$testroot" "$ret"
812 return 1
813 fi
815 echo 'A new' > $testroot/stdout.expected
816 (cd $testroot/wt && got status -s A > $testroot/stdout)
817 cmp -s $testroot/stdout.expected $testroot/stdout
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 (cd $testroot/wt && got stage new > $testroot/stdout)
827 echo ' A new' > $testroot/stdout.expected
828 (cd $testroot/wt && got status -s A > $testroot/stdout)
829 cmp -s $testroot/stdout.expected $testroot/stdout
830 ret=$?
831 if [ $ret -ne 0 ]; then
832 diff -u $testroot/stdout.expected $testroot/stdout
833 test_done "$testroot" "$ret"
834 return 1
835 fi
837 echo 'changed file new' > $testroot/wt/new
839 echo 'MA new' > $testroot/stdout.expected
840 (cd $testroot/wt && got status -s A > $testroot/stdout)
841 cmp -s $testroot/stdout.expected $testroot/stdout
842 ret=$?
843 if [ $ret -ne 0 ]; then
844 diff -u $testroot/stdout.expected $testroot/stdout
845 test_done "$testroot" "$ret"
846 return 1
847 fi
849 echo 'M alpha' > $testroot/stdout.expected
850 echo 'MA new' >> $testroot/stdout.expected
851 (cd $testroot/wt && got status -s M > $testroot/stdout)
852 cmp -s $testroot/stdout.expected $testroot/stdout
853 ret=$?
854 if [ $ret -ne 0 ]; then
855 diff -u $testroot/stdout.expected $testroot/stdout
856 test_done "$testroot" "$ret"
857 return 1
858 fi
860 test_done "$testroot" "$ret"
863 test_status_suppress() {
864 local testroot=`test_init status_suppress`
866 got checkout $testroot/repo $testroot/wt > /dev/null
867 ret=$?
868 if [ $ret -ne 0 ]; then
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 echo "modified alpha" > $testroot/wt/alpha
874 (cd $testroot/wt && got rm beta >/dev/null)
875 echo "unversioned file" > $testroot/wt/foo
876 rm $testroot/wt/epsilon/zeta
877 touch $testroot/wt/beta
878 echo "new file" > $testroot/wt/new
879 (cd $testroot/wt && got add new >/dev/null)
881 (cd $testroot/wt && got status -S A -s M \
882 > $testroot/stdout 2> $testroot/stderr)
883 ret=$?
884 if [ $ret -eq 0 ]; then
885 echo "status succeeded unexpectedly" >&2
886 test_done "$testroot" "1"
887 return 1
888 fi
890 echo "got: -s and -S options are mutually exclusive" \
891 > $testroot/stderr.expected
892 cmp -s $testroot/stderr.expected $testroot/stderr
893 ret=$?
894 if [ $ret -ne 0 ]; then
895 diff -u $testroot/stderr.expected $testroot/stderr
896 test_done "$testroot" "$ret"
897 return 1
898 fi
900 (cd $testroot/wt && got status -s A -S M \
901 > $testroot/stdout 2> $testroot/stderr)
902 ret=$?
903 if [ $ret -eq 0 ]; then
904 echo "status succeeded unexpectedly" >&2
905 test_done "$testroot" "1"
906 return 1
907 fi
909 echo "got: -S and -s options are mutually exclusive" \
910 > $testroot/stderr.expected
911 cmp -s $testroot/stderr.expected $testroot/stderr
912 ret=$?
913 if [ $ret -ne 0 ]; then
914 diff -u $testroot/stderr.expected $testroot/stderr
915 test_done "$testroot" "$ret"
916 return 1
917 fi
919 (cd $testroot/wt && got status -S xDM \
920 > $testroot/stdout 2> $testroot/stderr)
921 ret=$?
922 if [ $ret -eq 0 ]; then
923 echo "status succeeded unexpectedly" >&2
924 test_done "$testroot" "1"
925 return 1
926 fi
928 echo "got: invalid status code 'x'" > $testroot/stderr.expected
929 cmp -s $testroot/stderr.expected $testroot/stderr
930 ret=$?
931 if [ $ret -ne 0 ]; then
932 diff -u $testroot/stderr.expected $testroot/stderr
933 test_done "$testroot" "$ret"
934 return 1
935 fi
937 echo 'M alpha' > $testroot/stdout.expected
938 (cd $testroot/wt && got status -S D\?A! > $testroot/stdout)
939 cmp -s $testroot/stdout.expected $testroot/stdout
940 ret=$?
941 if [ $ret -ne 0 ]; then
942 diff -u $testroot/stdout.expected $testroot/stdout
943 test_done "$testroot" "$ret"
944 return 1
945 fi
947 echo 'D beta' > $testroot/stdout.expected
948 (cd $testroot/wt && got status -S M\?A! > $testroot/stdout)
949 cmp -s $testroot/stdout.expected $testroot/stdout
950 ret=$?
951 if [ $ret -ne 0 ]; then
952 diff -u $testroot/stdout.expected $testroot/stdout
953 test_done "$testroot" "$ret"
954 return 1
955 fi
957 echo '! epsilon/zeta' > $testroot/stdout.expected
958 echo '? foo' >> $testroot/stdout.expected
959 (cd $testroot/wt && got status -S MDA > $testroot/stdout)
960 cmp -s $testroot/stdout.expected $testroot/stdout
961 ret=$?
962 if [ $ret -ne 0 ]; then
963 diff -u $testroot/stdout.expected $testroot/stdout
964 test_done "$testroot" "$ret"
965 return 1
966 fi
968 echo 'A new' > $testroot/stdout.expected
969 (cd $testroot/wt && got status -S MD\?! > $testroot/stdout)
970 cmp -s $testroot/stdout.expected $testroot/stdout
971 ret=$?
972 if [ $ret -ne 0 ]; then
973 diff -u $testroot/stdout.expected $testroot/stdout
974 test_done "$testroot" "$ret"
975 return 1
976 fi
978 (cd $testroot/wt && got stage new > $testroot/stdout)
980 echo ' A new' > $testroot/stdout.expected
981 (cd $testroot/wt && got status -S MD\?! > $testroot/stdout)
982 cmp -s $testroot/stdout.expected $testroot/stdout
983 ret=$?
984 if [ $ret -ne 0 ]; then
985 diff -u $testroot/stdout.expected $testroot/stdout
986 test_done "$testroot" "$ret"
987 return 1
988 fi
990 echo 'changed file new' > $testroot/wt/new
992 echo 'M alpha' > $testroot/stdout.expected
993 echo 'MA new' >> $testroot/stdout.expected
994 (cd $testroot/wt && got status -S D\?! > $testroot/stdout)
995 cmp -s $testroot/stdout.expected $testroot/stdout
996 ret=$?
997 if [ $ret -ne 0 ]; then
998 diff -u $testroot/stdout.expected $testroot/stdout
999 test_done "$testroot" "$ret"
1000 return 1
1003 echo 'M alpha' > $testroot/stdout.expected
1004 (cd $testroot/wt && got status -S AD\?! > $testroot/stdout)
1005 cmp -s $testroot/stdout.expected $testroot/stdout
1006 ret=$?
1007 if [ $ret -ne 0 ]; then
1008 diff -u $testroot/stdout.expected $testroot/stdout
1009 test_done "$testroot" "$ret"
1010 return 1
1013 rm $testroot/stdout.expected
1014 touch $testroot/stdout.expected
1016 (cd $testroot/wt && got status -S MD\?! > $testroot/stdout)
1017 cmp -s $testroot/stdout.expected $testroot/stdout
1018 ret=$?
1019 if [ $ret -ne 0 ]; then
1020 diff -u $testroot/stdout.expected $testroot/stdout
1021 test_done "$testroot" "$ret"
1022 return 1
1025 test_done "$testroot" "$ret"
1028 test_status_empty_file() {
1029 local testroot=`test_init status_empty_file`
1031 got checkout $testroot/repo $testroot/wt > /dev/null
1032 ret=$?
1033 if [ $ret -ne 0 ]; then
1034 test_done "$testroot" "$ret"
1035 return 1
1038 echo -n "" > $testroot/wt/empty
1039 (cd $testroot/wt && got add empty >/dev/null)
1041 echo 'A empty' > $testroot/stdout.expected
1043 (cd $testroot/wt && got status > $testroot/stdout)
1045 cmp -s $testroot/stdout.expected $testroot/stdout
1046 ret=$?
1047 if [ $ret -ne 0 ]; then
1048 diff -u $testroot/stdout.expected $testroot/stdout
1049 test_done "$testroot" "$ret"
1050 return 1
1053 (cd $testroot/wt && got commit -m "empty file" >/dev/null)
1055 (cd $testroot/wt && got status > $testroot/stdout)
1057 echo -n > $testroot/stdout.expected
1058 cmp -s $testroot/stdout.expected $testroot/stdout
1059 ret=$?
1060 if [ $ret -ne 0 ]; then
1061 diff -u $testroot/stdout.expected $testroot/stdout
1062 test_done "$testroot" "$ret"
1063 return 1
1066 # update the timestamp; this used to make the file show up as:
1067 # M empty
1068 # which should not happen
1069 touch $testroot/wt/empty
1071 (cd $testroot/wt && got status > $testroot/stdout)
1073 echo -n > $testroot/stdout.expected
1074 cmp -s $testroot/stdout.expected $testroot/stdout
1075 ret=$?
1076 if [ $ret -ne 0 ]; then
1077 diff -u $testroot/stdout.expected $testroot/stdout
1079 test_done "$testroot" "$ret"
1082 test_parseargs "$@"
1083 run_test test_status_basic
1084 run_test test_status_subdir_no_mods
1085 run_test test_status_subdir_no_mods2
1086 run_test test_status_obstructed
1087 run_test test_status_shows_local_mods_after_update
1088 run_test test_status_unversioned_subdirs
1089 run_test test_status_symlink
1090 run_test test_status_shows_no_mods_after_complete_merge
1091 run_test test_status_shows_conflict
1092 run_test test_status_empty_dir
1093 run_test test_status_empty_dir_unversioned_file
1094 run_test test_status_many_paths
1095 run_test test_status_cvsignore
1096 run_test test_status_gitignore
1097 run_test test_status_gitignore_trailing_slashes
1098 run_test test_status_status_code
1099 run_test test_status_suppress
1100 run_test test_status_empty_file