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 function test_status_basic {
20 local testroot=`test_init status_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "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" != "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 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
68 ret="$?"
69 if [ "$ret" != "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" != "0" ]; then
85 diff -u $testroot/stdout.expected $testroot/stdout
86 fi
87 test_done "$testroot" "$ret"
88 }
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
108 ret="$?"
109 if [ "$ret" != "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" != "0" ]; then
129 diff -u $testroot/stdout.expected $testroot/stdout
130 fi
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
138 ret="$?"
139 if [ "$ret" != "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" != "0" ]; then
154 diff -u $testroot/stdout.expected $testroot/stdout
155 fi
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
174 ret="$?"
175 if [ "$ret" != "0" ]; then
176 test_done "$testroot" "$ret"
177 return 1
178 fi
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
194 ret="$?"
195 if [ "$ret" != "0" ]; then
196 diff -u $testroot/stdout.expected $testroot/stdout
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 echo 'M numbers' > $testroot/stdout.expected
203 (cd $testroot/wt && got status > $testroot/stdout)
205 cmp -s $testroot/stdout.expected $testroot/stdout
206 ret="$?"
207 if [ "$ret" != "0" ]; then
208 diff -u $testroot/stdout.expected $testroot/stdout
209 fi
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
232 ret="$?"
233 if [ "$ret" != "0" ]; then
234 test_done "$testroot" "$ret"
235 return 1
236 fi
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
254 ret="$?"
255 if [ "$ret" != "0" ]; then
256 diff -u $testroot/stdout.expected $testroot/stdout
257 fi
258 test_done "$testroot" "$ret"
261 # 'got status' ignores symlinks at present; this might change eventually
262 function test_status_ignores_symlink {
263 local testroot=`test_init status_ignores_symlink 1`
265 mkdir $testroot/repo/ramdisk/
266 touch $testroot/repo/ramdisk/Makefile
267 (cd $testroot/repo && git add .)
268 git_commit $testroot/repo -m "first commit"
270 got checkout $testroot/repo $testroot/wt > /dev/null
271 ret="$?"
272 if [ "$ret" != "0" ]; then
273 test_done "$testroot" "$ret"
274 return 1
275 fi
277 ln -s /usr/obj/distrib/i386/ramdisk $testroot/wt/ramdisk/obj
279 echo -n > $testroot/stdout.expected
281 (cd $testroot/wt && got status > $testroot/stdout)
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret="$?"
285 if [ "$ret" != "0" ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 fi
288 test_done "$testroot" "$ret"
291 function test_status_shows_no_mods_after_complete_merge {
292 local testroot=`test_init status_shows_no_mods_after_complete_merge 1`
294 # make this file larger than the usual blob buffer size of 8192
295 echo -n > $testroot/repo/numbers
296 for i in `jot 16384`; do
297 echo "$i" >> $testroot/repo/numbers
298 done
300 (cd $testroot/repo && git add numbers)
301 git_commit $testroot/repo -m "added numbers file"
303 got checkout $testroot/repo $testroot/wt > /dev/null
304 ret="$?"
305 if [ "$ret" != "0" ]; then
306 test_done "$testroot" "$ret"
307 return 1
308 fi
310 sed -i 's/2/22/' $testroot/repo/numbers
311 git_commit $testroot/repo -m "modified line 2"
313 sleep 1
314 # modify line 2 again; no local changes are left after merge
315 sed -i 's/2/22/' $testroot/wt/numbers
317 echo "G numbers" > $testroot/stdout.expected
318 echo -n "Updated to commit " >> $testroot/stdout.expected
319 git_show_head $testroot/repo >> $testroot/stdout.expected
320 echo >> $testroot/stdout.expected
322 (cd $testroot/wt && got update > $testroot/stdout)
324 cmp -s $testroot/stdout.expected $testroot/stdout
325 ret="$?"
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
329 return 1
330 fi
332 echo -n > $testroot/stdout.expected
334 (cd $testroot/wt && got status > $testroot/stdout)
336 cmp -s $testroot/stdout.expected $testroot/stdout
337 ret="$?"
338 if [ "$ret" != "0" ]; then
339 diff -u $testroot/stdout.expected $testroot/stdout
340 fi
341 test_done "$testroot" "$ret"
344 function test_status_shows_conflict {
345 local testroot=`test_init status_shows_conflict 1`
347 echo "1" > $testroot/repo/numbers
348 echo "2" >> $testroot/repo/numbers
349 echo "3" >> $testroot/repo/numbers
350 echo "4" >> $testroot/repo/numbers
351 echo "5" >> $testroot/repo/numbers
352 echo "6" >> $testroot/repo/numbers
353 echo "7" >> $testroot/repo/numbers
354 echo "8" >> $testroot/repo/numbers
355 (cd $testroot/repo && git add numbers)
356 git_commit $testroot/repo -m "added numbers file"
358 got checkout $testroot/repo $testroot/wt > /dev/null
359 ret="$?"
360 if [ "$ret" != "0" ]; then
361 test_done "$testroot" "$ret"
362 return 1
363 fi
365 sed -i 's/2/22/' $testroot/repo/numbers
366 git_commit $testroot/repo -m "modified line 2"
368 # modify line 2 in a conflicting way
369 sed -i 's/2/77/' $testroot/wt/numbers
371 echo "C numbers" > $testroot/stdout.expected
372 echo -n "Updated to commit " >> $testroot/stdout.expected
373 git_show_head $testroot/repo >> $testroot/stdout.expected
374 echo >> $testroot/stdout.expected
375 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
377 (cd $testroot/wt && got update > $testroot/stdout)
379 cmp -s $testroot/stdout.expected $testroot/stdout
380 ret="$?"
381 if [ "$ret" != "0" ]; then
382 diff -u $testroot/stdout.expected $testroot/stdout
383 test_done "$testroot" "$ret"
384 return 1
385 fi
387 echo 'C numbers' > $testroot/stdout.expected
389 (cd $testroot/wt && got status > $testroot/stdout)
391 cmp -s $testroot/stdout.expected $testroot/stdout
392 ret="$?"
393 if [ "$ret" != "0" ]; then
394 diff -u $testroot/stdout.expected $testroot/stdout
395 fi
396 test_done "$testroot" "$ret"
399 function test_status_empty_dir {
400 local testroot=`test_init status_empty_dir`
402 got checkout $testroot/repo $testroot/wt > /dev/null
403 ret="$?"
404 if [ "$ret" != "0" ]; then
405 test_done "$testroot" "$ret"
406 return 1
407 fi
409 rm $testroot/wt/epsilon/zeta
411 echo '! epsilon/zeta' > $testroot/stdout.expected
413 (cd $testroot/wt && got status epsilon > $testroot/stdout)
415 cmp -s $testroot/stdout.expected $testroot/stdout
416 ret="$?"
417 if [ "$ret" != "0" ]; then
418 diff -u $testroot/stdout.expected $testroot/stdout
419 fi
420 test_done "$testroot" "$ret"
423 function test_status_empty_dir_unversioned_file {
424 local testroot=`test_init status_empty_dir_unversioned_file`
426 got checkout $testroot/repo $testroot/wt > /dev/null
427 ret="$?"
428 if [ "$ret" != "0" ]; then
429 test_done "$testroot" "$ret"
430 return 1
431 fi
433 rm $testroot/wt/epsilon/zeta
434 touch $testroot/wt/epsilon/unversioned
436 echo '? epsilon/unversioned' > $testroot/stdout.expected
437 echo '! epsilon/zeta' >> $testroot/stdout.expected
439 (cd $testroot/wt && got status epsilon > $testroot/stdout)
441 cmp -s $testroot/stdout.expected $testroot/stdout
442 ret="$?"
443 if [ "$ret" != "0" ]; then
444 diff -u $testroot/stdout.expected $testroot/stdout
445 fi
446 test_done "$testroot" "$ret"
449 function test_status_many_paths {
450 local testroot=`test_init status_many_paths`
452 got checkout $testroot/repo $testroot/wt > /dev/null
453 ret="$?"
454 if [ "$ret" != "0" ]; then
455 test_done "$testroot" "$ret"
456 return 1
457 fi
459 echo "modified alpha" > $testroot/wt/alpha
460 (cd $testroot/wt && got rm beta >/dev/null)
461 echo "unversioned file" > $testroot/wt/foo
462 rm $testroot/wt/epsilon/zeta
463 touch $testroot/wt/beta
464 echo "new file" > $testroot/wt/new
465 mkdir $testroot/wt/newdir
466 (cd $testroot/wt && got add new >/dev/null)
468 (cd $testroot/wt && got status newdir > $testroot/stdout.expected)
469 (cd $testroot/wt && got status alpha >> $testroot/stdout.expected)
470 (cd $testroot/wt && got status epsilon >> $testroot/stdout.expected)
471 (cd $testroot/wt && got status foo >> $testroot/stdout.expected)
472 (cd $testroot/wt && got status new >> $testroot/stdout.expected)
473 (cd $testroot/wt && got status beta >> $testroot/stdout.expected)
474 (cd $testroot/wt && got status . >> $testroot/stdout.expected)
476 (cd $testroot/wt && got status newdir alpha epsilon foo new beta . \
477 > $testroot/stdout)
479 cmp -s $testroot/stdout.expected $testroot/stdout
480 ret="$?"
481 if [ "$ret" != "0" ]; then
482 diff -u $testroot/stdout.expected $testroot/stdout
483 fi
484 test_done "$testroot" "$ret"
487 function test_status_cvsignore {
488 local testroot=`test_init status_cvsignore`
490 got checkout $testroot/repo $testroot/wt > /dev/null
491 ret="$?"
492 if [ "$ret" != "0" ]; then
493 test_done "$testroot" "$ret"
494 return 1
495 fi
497 echo "unversioned file" > $testroot/wt/foo
498 echo "unversioned file" > $testroot/wt/foop
499 echo "unversioned file" > $testroot/wt/epsilon/foo
500 echo "unversioned file" > $testroot/wt/epsilon/bar
501 echo "unversioned file" > $testroot/wt/epsilon/boo
502 echo "unversioned file" > $testroot/wt/epsilon/moo
503 mkdir -p $testroot/wt/epsilon/new/
504 echo "unversioned file" > $testroot/wt/epsilon/new/foo
505 echo "**/foo" > $testroot/wt/.cvsignore
506 echo "bar" > $testroot/wt/epsilon/.cvsignore
507 echo "moo" >> $testroot/wt/epsilon/.cvsignore
509 echo '? .cvsignore' > $testroot/stdout.expected
510 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
511 echo '? epsilon/boo' >> $testroot/stdout.expected
512 echo '? foop' >> $testroot/stdout.expected
513 (cd $testroot/wt && got status > $testroot/stdout)
515 cmp -s $testroot/stdout.expected $testroot/stdout
516 ret="$?"
517 if [ "$ret" != "0" ]; then
518 diff -u $testroot/stdout.expected $testroot/stdout
519 test_done "$testroot" "$ret"
520 return 1
521 fi
523 echo '? epsilon/.cvsignore' > $testroot/stdout.expected
524 echo '? epsilon/boo' >> $testroot/stdout.expected
525 (cd $testroot/wt && got status epsilon > $testroot/stdout)
527 cmp -s $testroot/stdout.expected $testroot/stdout
528 ret="$?"
529 if [ "$ret" != "0" ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 test_done "$testroot" "$ret"
532 return 1
533 fi
535 echo -n '' > $testroot/stdout.expected
536 (cd $testroot/wt && got status epsilon/new > $testroot/stdout)
538 cmp -s $testroot/stdout.expected $testroot/stdout
539 ret="$?"
540 if [ "$ret" != "0" ]; then
541 diff -u $testroot/stdout.expected $testroot/stdout
542 test_done "$testroot" "$ret"
543 return 1
544 fi
546 echo '? .cvsignore' > $testroot/stdout.expected
547 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
548 echo '? epsilon/boo' >> $testroot/stdout.expected
549 echo '? foop' >> $testroot/stdout.expected
550 (cd $testroot/wt/gamma && got status > $testroot/stdout)
552 cmp -s $testroot/stdout.expected $testroot/stdout
553 ret="$?"
554 if [ "$ret" != "0" ]; then
555 diff -u $testroot/stdout.expected $testroot/stdout
556 fi
557 test_done "$testroot" "$ret"
560 function test_status_gitignore {
561 local testroot=`test_init status_gitignore`
563 got checkout $testroot/repo $testroot/wt > /dev/null
564 ret="$?"
565 if [ "$ret" != "0" ]; then
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 echo "unversioned file" > $testroot/wt/foo
571 echo "unversioned file" > $testroot/wt/foop
572 echo "unversioned file" > $testroot/wt/barp
573 echo "unversioned file" > $testroot/wt/epsilon/bar
574 echo "unversioned file" > $testroot/wt/epsilon/boo
575 echo "unversioned file" > $testroot/wt/epsilon/moo
576 mkdir -p $testroot/wt/a/b/c/
577 echo "unversioned file" > $testroot/wt/a/b/c/foo
578 echo "unversioned file" > $testroot/wt/a/b/c/zoo
579 echo "foo" > $testroot/wt/.gitignore
580 echo "bar*" >> $testroot/wt/.gitignore
581 echo "epsilon/**" >> $testroot/wt/.gitignore
582 echo "a/**/foo" >> $testroot/wt/.gitignore
583 echo "**/zoo" >> $testroot/wt/.gitignore
585 echo '? .gitignore' > $testroot/stdout.expected
586 echo '? foop' >> $testroot/stdout.expected
587 (cd $testroot/wt && got status > $testroot/stdout)
589 cmp -s $testroot/stdout.expected $testroot/stdout
590 ret="$?"
591 if [ "$ret" != "0" ]; then
592 diff -u $testroot/stdout.expected $testroot/stdout
593 test_done "$testroot" "$ret"
594 return 1
595 fi
597 echo '? .gitignore' > $testroot/stdout.expected
598 echo '? foop' >> $testroot/stdout.expected
599 (cd $testroot/wt/gamma && got status > $testroot/stdout)
601 cmp -s $testroot/stdout.expected $testroot/stdout
602 ret="$?"
603 if [ "$ret" != "0" ]; then
604 diff -u $testroot/stdout.expected $testroot/stdout
605 fi
606 test_done "$testroot" "$ret"
609 run_test test_status_basic
610 run_test test_status_subdir_no_mods
611 run_test test_status_subdir_no_mods2
612 run_test test_status_obstructed
613 run_test test_status_shows_local_mods_after_update
614 run_test test_status_unversioned_subdirs
615 run_test test_status_ignores_symlink
616 run_test test_status_shows_no_mods_after_complete_merge
617 run_test test_status_shows_conflict
618 run_test test_status_empty_dir
619 run_test test_status_empty_dir_unversioned_file
620 run_test test_status_many_paths
621 run_test test_status_cvsignore
622 run_test test_status_gitignore