3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 function test_status_basic {
20 local testroot=`test_init status_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
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
48 if [ "$ret" != "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 function 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
69 if [ "$ret" != "0" ]; then
70 test_done "$testroot" "$ret"
74 touch $testroot/stdout.expected
76 # This used to erroneously print:
80 (cd $testroot/wt && got status > $testroot/stdout)
82 cmp -s $testroot/stdout.expected $testroot/stdout
84 if [ "$ret" != "0" ]; then
85 diff -u $testroot/stdout.expected $testroot/stdout
87 test_done "$testroot" "$ret"
90 function 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
109 if [ "$ret" != "0" ]; then
110 test_done "$testroot" "$ret"
114 touch $testroot/stdout.expected
116 # This used to erroneously print:
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
128 if [ "$ret" != "0" ]; then
129 diff -u $testroot/stdout.expected $testroot/stdout
131 test_done "$testroot" "$ret"
134 function test_status_obstructed {
135 local testroot=`test_init status_obstructed`
137 got checkout $testroot/repo $testroot/wt > /dev/null
139 if [ "$ret" != "0" ]; then
140 test_done "$testroot" "$ret"
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
153 if [ "$ret" != "0" ]; then
154 diff -u $testroot/stdout.expected $testroot/stdout
156 test_done "$testroot" "$ret"
159 function test_status_shows_local_mods_after_update {
160 local testroot=`test_init status_shows_local_mods_after_update 1`
162 echo "1" > $testroot/repo/numbers
163 echo "2" >> $testroot/repo/numbers
164 echo "3" >> $testroot/repo/numbers
165 echo "4" >> $testroot/repo/numbers
166 echo "5" >> $testroot/repo/numbers
167 echo "6" >> $testroot/repo/numbers
168 echo "7" >> $testroot/repo/numbers
169 echo "8" >> $testroot/repo/numbers
170 (cd $testroot/repo && git add numbers)
171 git_commit $testroot/repo -m "added numbers file"
173 got checkout $testroot/repo $testroot/wt > /dev/null
175 if [ "$ret" != "0" ]; then
176 test_done "$testroot" "$ret"
180 sed -i 's/2/22/' $testroot/repo/numbers
181 git_commit $testroot/repo -m "modified line 2"
183 # modify line 7; both changes should merge cleanly
184 sed -i 's/7/77/' $testroot/wt/numbers
186 echo "G numbers" > $testroot/stdout.expected
187 echo -n "Updated to commit " >> $testroot/stdout.expected
188 git_show_head $testroot/repo >> $testroot/stdout.expected
189 echo >> $testroot/stdout.expected
191 (cd $testroot/wt && got update > $testroot/stdout)
193 cmp -s $testroot/stdout.expected $testroot/stdout
195 if [ "$ret" != "0" ]; then
196 diff -u $testroot/stdout.expected $testroot/stdout
197 test_done "$testroot" "$ret"
201 echo 'M numbers' > $testroot/stdout.expected
203 (cd $testroot/wt && got status > $testroot/stdout)
205 cmp -s $testroot/stdout.expected $testroot/stdout
207 if [ "$ret" != "0" ]; then
208 diff -u $testroot/stdout.expected $testroot/stdout
210 test_done "$testroot" "$ret"
213 function test_status_unversioned_subdirs {
214 local testroot=`test_init status_unversioned_subdirs 1`
216 mkdir $testroot/repo/cdfs/
217 touch $testroot/repo/cdfs/Makefile
218 mkdir $testroot/repo/common/
219 touch $testroot/repo/common/Makefile
220 mkdir $testroot/repo/iso/
221 touch $testroot/repo/iso/Makefile
222 mkdir $testroot/repo/ramdisk/
223 touch $testroot/repo/ramdisk/Makefile
224 touch $testroot/repo/ramdisk/list.local
225 mkdir $testroot/repo/ramdisk_cd/
226 touch $testroot/repo/ramdisk_cd/Makefile
227 touch $testroot/repo/ramdisk_cd/list.local
228 (cd $testroot/repo && git add .)
229 git_commit $testroot/repo -m "first commit"
231 got checkout $testroot/repo $testroot/wt > /dev/null
233 if [ "$ret" != "0" ]; then
234 test_done "$testroot" "$ret"
238 mkdir $testroot/wt/cdfs/obj
239 mkdir $testroot/wt/ramdisk/obj
240 mkdir $testroot/wt/ramdisk_cd/obj
241 mkdir $testroot/wt/iso/obj
243 echo -n > $testroot/stdout.expected
245 # This used to erroneously print:
247 # ! ramdisk_cd/Makefile
248 # ! ramdisk_cd/list.local
249 # ? ramdisk_cd/Makefile
250 # ? ramdisk_cd/list.local
251 (cd $testroot/wt && got status > $testroot/stdout)
253 cmp -s $testroot/stdout.expected $testroot/stdout
255 if [ "$ret" != "0" ]; then
256 diff -u $testroot/stdout.expected $testroot/stdout
258 test_done "$testroot" "$ret"
261 function test_status_symlink {
262 local testroot=`test_init status_symlink`
264 mkdir $testroot/repo/ramdisk/
265 touch $testroot/repo/ramdisk/Makefile
266 (cd $testroot/repo && git add .)
267 git_commit $testroot/repo -m "first commit"
269 got checkout $testroot/repo $testroot/wt > /dev/null
271 if [ "$ret" != "0" ]; then
272 test_done "$testroot" "$ret"
276 ln -s /usr/obj/distrib/i386/ramdisk $testroot/wt/ramdisk/obj
278 echo "? ramdisk/obj" > $testroot/stdout.expected
280 (cd $testroot/wt && got status > $testroot/stdout)
282 cmp -s $testroot/stdout.expected $testroot/stdout
284 if [ "$ret" != "0" ]; then
285 diff -u $testroot/stdout.expected $testroot/stdout
286 test_done "$testroot" "$ret"
290 (cd $testroot/wt && ln -s alpha alpha.link)
291 (cd $testroot/wt && ln -s epsilon epsilon.link)
292 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
293 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
294 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
295 (cd $testroot/wt && got add alpha.link epsilon.link \
296 passwd.link epsilon/beta.link nonexistent.link > /dev/null)
298 echo 'A alpha.link' > $testroot/stdout.expected
299 echo 'A epsilon/beta.link' >> $testroot/stdout.expected
300 echo 'A epsilon.link' >> $testroot/stdout.expected
301 echo 'A nonexistent.link' >> $testroot/stdout.expected
302 echo 'A passwd.link' >> $testroot/stdout.expected
303 echo "? ramdisk/obj" >> $testroot/stdout.expected
305 (cd $testroot/wt && got status > $testroot/stdout)
307 cmp -s $testroot/stdout.expected $testroot/stdout
309 if [ "$ret" != "0" ]; then
310 diff -u $testroot/stdout.expected $testroot/stdout
312 test_done "$testroot" "$ret"
315 function test_status_shows_no_mods_after_complete_merge {
316 local testroot=`test_init status_shows_no_mods_after_complete_merge 1`
318 # make this file larger than the usual blob buffer size of 8192
319 echo -n > $testroot/repo/numbers
320 for i in `jot 16384`; do
321 echo "$i" >> $testroot/repo/numbers
324 (cd $testroot/repo && git add numbers)
325 git_commit $testroot/repo -m "added numbers file"
327 got checkout $testroot/repo $testroot/wt > /dev/null
329 if [ "$ret" != "0" ]; then
330 test_done "$testroot" "$ret"
334 sed -i 's/2/22/' $testroot/repo/numbers
335 git_commit $testroot/repo -m "modified line 2"
338 # modify line 2 again; no local changes are left after merge
339 sed -i 's/2/22/' $testroot/wt/numbers
341 echo "G numbers" > $testroot/stdout.expected
342 echo -n "Updated to commit " >> $testroot/stdout.expected
343 git_show_head $testroot/repo >> $testroot/stdout.expected
344 echo >> $testroot/stdout.expected
346 (cd $testroot/wt && got update > $testroot/stdout)
348 cmp -s $testroot/stdout.expected $testroot/stdout
350 if [ "$ret" != "0" ]; then
351 diff -u $testroot/stdout.expected $testroot/stdout
352 test_done "$testroot" "$ret"
356 echo -n > $testroot/stdout.expected
358 (cd $testroot/wt && got status > $testroot/stdout)
360 cmp -s $testroot/stdout.expected $testroot/stdout
362 if [ "$ret" != "0" ]; then
363 diff -u $testroot/stdout.expected $testroot/stdout
365 test_done "$testroot" "$ret"
368 function test_status_shows_conflict {
369 local testroot=`test_init status_shows_conflict 1`
371 echo "1" > $testroot/repo/numbers
372 echo "2" >> $testroot/repo/numbers
373 echo "3" >> $testroot/repo/numbers
374 echo "4" >> $testroot/repo/numbers
375 echo "5" >> $testroot/repo/numbers
376 echo "6" >> $testroot/repo/numbers
377 echo "7" >> $testroot/repo/numbers
378 echo "8" >> $testroot/repo/numbers
379 (cd $testroot/repo && git add numbers)
380 git_commit $testroot/repo -m "added numbers file"
382 got checkout $testroot/repo $testroot/wt > /dev/null
384 if [ "$ret" != "0" ]; then
385 test_done "$testroot" "$ret"
389 sed -i 's/2/22/' $testroot/repo/numbers
390 git_commit $testroot/repo -m "modified line 2"
392 # modify line 2 in a conflicting way
393 sed -i 's/2/77/' $testroot/wt/numbers
395 echo "C numbers" > $testroot/stdout.expected
396 echo -n "Updated to commit " >> $testroot/stdout.expected
397 git_show_head $testroot/repo >> $testroot/stdout.expected
398 echo >> $testroot/stdout.expected
399 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
401 (cd $testroot/wt && got update > $testroot/stdout)
403 cmp -s $testroot/stdout.expected $testroot/stdout
405 if [ "$ret" != "0" ]; then
406 diff -u $testroot/stdout.expected $testroot/stdout
407 test_done "$testroot" "$ret"
411 echo 'C numbers' > $testroot/stdout.expected
413 (cd $testroot/wt && got status > $testroot/stdout)
415 cmp -s $testroot/stdout.expected $testroot/stdout
417 if [ "$ret" != "0" ]; then
418 diff -u $testroot/stdout.expected $testroot/stdout
420 test_done "$testroot" "$ret"
423 function test_status_empty_dir {
424 local testroot=`test_init status_empty_dir`
426 got checkout $testroot/repo $testroot/wt > /dev/null
428 if [ "$ret" != "0" ]; then
429 test_done "$testroot" "$ret"
433 rm $testroot/wt/epsilon/zeta
435 echo '! epsilon/zeta' > $testroot/stdout.expected
437 (cd $testroot/wt && got status epsilon > $testroot/stdout)
439 cmp -s $testroot/stdout.expected $testroot/stdout
441 if [ "$ret" != "0" ]; then
442 diff -u $testroot/stdout.expected $testroot/stdout
444 test_done "$testroot" "$ret"
447 function test_status_empty_dir_unversioned_file {
448 local testroot=`test_init status_empty_dir_unversioned_file`
450 got checkout $testroot/repo $testroot/wt > /dev/null
452 if [ "$ret" != "0" ]; then
453 test_done "$testroot" "$ret"
457 rm $testroot/wt/epsilon/zeta
458 touch $testroot/wt/epsilon/unversioned
460 echo '? epsilon/unversioned' > $testroot/stdout.expected
461 echo '! epsilon/zeta' >> $testroot/stdout.expected
463 (cd $testroot/wt && got status epsilon > $testroot/stdout)
465 cmp -s $testroot/stdout.expected $testroot/stdout
467 if [ "$ret" != "0" ]; then
468 diff -u $testroot/stdout.expected $testroot/stdout
470 test_done "$testroot" "$ret"
473 function test_status_many_paths {
474 local testroot=`test_init status_many_paths`
476 got checkout $testroot/repo $testroot/wt > /dev/null
478 if [ "$ret" != "0" ]; then
479 test_done "$testroot" "$ret"
483 echo "modified alpha" > $testroot/wt/alpha
484 (cd $testroot/wt && got rm beta >/dev/null)
485 echo "unversioned file" > $testroot/wt/foo
486 rm $testroot/wt/epsilon/zeta
487 touch $testroot/wt/beta
488 echo "new file" > $testroot/wt/new
489 mkdir $testroot/wt/newdir
490 (cd $testroot/wt && got add new >/dev/null)
492 (cd $testroot/wt && got status newdir > $testroot/stdout.expected)
493 (cd $testroot/wt && got status alpha >> $testroot/stdout.expected)
494 (cd $testroot/wt && got status epsilon >> $testroot/stdout.expected)
495 (cd $testroot/wt && got status foo >> $testroot/stdout.expected)
496 (cd $testroot/wt && got status new >> $testroot/stdout.expected)
497 (cd $testroot/wt && got status beta >> $testroot/stdout.expected)
498 (cd $testroot/wt && got status . >> $testroot/stdout.expected)
500 (cd $testroot/wt && got status newdir alpha epsilon foo new beta . \
503 cmp -s $testroot/stdout.expected $testroot/stdout
505 if [ "$ret" != "0" ]; then
506 diff -u $testroot/stdout.expected $testroot/stdout
508 test_done "$testroot" "$ret"
511 function test_status_cvsignore {
512 local testroot=`test_init status_cvsignore`
514 got checkout $testroot/repo $testroot/wt > /dev/null
516 if [ "$ret" != "0" ]; then
517 test_done "$testroot" "$ret"
521 echo "unversioned file" > $testroot/wt/foo
522 echo "unversioned file" > $testroot/wt/foop
523 echo "unversioned file" > $testroot/wt/epsilon/foo
524 echo "unversioned file" > $testroot/wt/epsilon/bar
525 echo "unversioned file" > $testroot/wt/epsilon/boo
526 echo "unversioned file" > $testroot/wt/epsilon/moo
527 mkdir -p $testroot/wt/epsilon/new/
528 echo "unversioned file" > $testroot/wt/epsilon/new/foo
529 echo "**/foo" > $testroot/wt/.cvsignore
530 echo "bar" > $testroot/wt/epsilon/.cvsignore
531 echo "moo" >> $testroot/wt/epsilon/.cvsignore
533 echo '? .cvsignore' > $testroot/stdout.expected
534 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
535 echo '? epsilon/boo' >> $testroot/stdout.expected
536 echo '? foop' >> $testroot/stdout.expected
537 (cd $testroot/wt && got status > $testroot/stdout)
539 cmp -s $testroot/stdout.expected $testroot/stdout
541 if [ "$ret" != "0" ]; then
542 diff -u $testroot/stdout.expected $testroot/stdout
543 test_done "$testroot" "$ret"
547 echo '? epsilon/.cvsignore' > $testroot/stdout.expected
548 echo '? epsilon/boo' >> $testroot/stdout.expected
549 (cd $testroot/wt && got status epsilon > $testroot/stdout)
551 cmp -s $testroot/stdout.expected $testroot/stdout
553 if [ "$ret" != "0" ]; then
554 diff -u $testroot/stdout.expected $testroot/stdout
555 test_done "$testroot" "$ret"
559 echo -n '' > $testroot/stdout.expected
560 (cd $testroot/wt && got status epsilon/new > $testroot/stdout)
562 cmp -s $testroot/stdout.expected $testroot/stdout
564 if [ "$ret" != "0" ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done "$testroot" "$ret"
570 echo '? .cvsignore' > $testroot/stdout.expected
571 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
572 echo '? epsilon/boo' >> $testroot/stdout.expected
573 echo '? foop' >> $testroot/stdout.expected
574 (cd $testroot/wt/gamma && got status > $testroot/stdout)
576 cmp -s $testroot/stdout.expected $testroot/stdout
578 if [ "$ret" != "0" ]; then
579 diff -u $testroot/stdout.expected $testroot/stdout
581 test_done "$testroot" "$ret"
584 function test_status_gitignore {
585 local testroot=`test_init status_gitignore`
587 got checkout $testroot/repo $testroot/wt > /dev/null
589 if [ "$ret" != "0" ]; then
590 test_done "$testroot" "$ret"
594 echo "unversioned file" > $testroot/wt/foo
595 echo "unversioned file" > $testroot/wt/foop
596 echo "unversioned file" > $testroot/wt/barp
597 echo "unversioned file" > $testroot/wt/epsilon/bar
598 echo "unversioned file" > $testroot/wt/epsilon/boo
599 echo "unversioned file" > $testroot/wt/epsilon/moo
600 mkdir -p $testroot/wt/a/b/c/
601 echo "unversioned file" > $testroot/wt/a/b/c/foo
602 echo "unversioned file" > $testroot/wt/a/b/c/zoo
603 echo "foo" > $testroot/wt/.gitignore
604 echo "bar*" >> $testroot/wt/.gitignore
605 echo "epsilon/**" >> $testroot/wt/.gitignore
606 echo "a/**/foo" >> $testroot/wt/.gitignore
607 echo "**/zoo" >> $testroot/wt/.gitignore
609 echo '? .gitignore' > $testroot/stdout.expected
610 echo '? foop' >> $testroot/stdout.expected
611 (cd $testroot/wt && got status > $testroot/stdout)
613 cmp -s $testroot/stdout.expected $testroot/stdout
615 if [ "$ret" != "0" ]; then
616 diff -u $testroot/stdout.expected $testroot/stdout
617 test_done "$testroot" "$ret"
621 echo '? .gitignore' > $testroot/stdout.expected
622 echo '? foop' >> $testroot/stdout.expected
623 (cd $testroot/wt/gamma && got status > $testroot/stdout)
625 cmp -s $testroot/stdout.expected $testroot/stdout
627 if [ "$ret" != "0" ]; then
628 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
633 run_test test_status_basic
634 run_test test_status_subdir_no_mods
635 run_test test_status_subdir_no_mods2
636 run_test test_status_obstructed
637 run_test test_status_shows_local_mods_after_update
638 run_test test_status_unversioned_subdirs
639 run_test test_status_symlink
640 run_test test_status_shows_no_mods_after_complete_merge
641 run_test test_status_shows_conflict
642 run_test test_status_empty_dir
643 run_test test_status_empty_dir_unversioned_file
644 run_test test_status_many_paths
645 run_test test_status_cvsignore
646 run_test test_status_gitignore