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
376 (cd $testroot/wt && got update > $testroot/stdout)
378 cmp -s $testroot/stdout.expected $testroot/stdout
379 ret="$?"
380 if [ "$ret" != "0" ]; then
381 diff -u $testroot/stdout.expected $testroot/stdout
382 test_done "$testroot" "$ret"
383 return 1
384 fi
386 echo 'C numbers' > $testroot/stdout.expected
388 (cd $testroot/wt && got status > $testroot/stdout)
390 cmp -s $testroot/stdout.expected $testroot/stdout
391 ret="$?"
392 if [ "$ret" != "0" ]; then
393 diff -u $testroot/stdout.expected $testroot/stdout
394 fi
395 test_done "$testroot" "$ret"
398 function test_status_empty_dir {
399 local testroot=`test_init status_empty_dir`
401 got checkout $testroot/repo $testroot/wt > /dev/null
402 ret="$?"
403 if [ "$ret" != "0" ]; then
404 test_done "$testroot" "$ret"
405 return 1
406 fi
408 rm $testroot/wt/epsilon/zeta
410 echo '! epsilon/zeta' > $testroot/stdout.expected
412 (cd $testroot/wt && got status epsilon > $testroot/stdout)
414 cmp -s $testroot/stdout.expected $testroot/stdout
415 ret="$?"
416 if [ "$ret" != "0" ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
418 fi
419 test_done "$testroot" "$ret"
422 function test_status_empty_dir_unversioned_file {
423 local testroot=`test_init status_empty_dir_unversioned_file`
425 got checkout $testroot/repo $testroot/wt > /dev/null
426 ret="$?"
427 if [ "$ret" != "0" ]; then
428 test_done "$testroot" "$ret"
429 return 1
430 fi
432 rm $testroot/wt/epsilon/zeta
433 touch $testroot/wt/epsilon/unversioned
435 echo '? epsilon/unversioned' > $testroot/stdout.expected
436 echo '! epsilon/zeta' >> $testroot/stdout.expected
438 (cd $testroot/wt && got status epsilon > $testroot/stdout)
440 cmp -s $testroot/stdout.expected $testroot/stdout
441 ret="$?"
442 if [ "$ret" != "0" ]; then
443 diff -u $testroot/stdout.expected $testroot/stdout
444 fi
445 test_done "$testroot" "$ret"
448 function test_status_many_paths {
449 local testroot=`test_init status_many_paths`
451 got checkout $testroot/repo $testroot/wt > /dev/null
452 ret="$?"
453 if [ "$ret" != "0" ]; then
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 echo "modified alpha" > $testroot/wt/alpha
459 (cd $testroot/wt && got rm beta >/dev/null)
460 echo "unversioned file" > $testroot/wt/foo
461 rm $testroot/wt/epsilon/zeta
462 touch $testroot/wt/beta
463 echo "new file" > $testroot/wt/new
464 mkdir $testroot/wt/newdir
465 (cd $testroot/wt && got add new >/dev/null)
467 (cd $testroot/wt && got status newdir > $testroot/stdout.expected)
468 (cd $testroot/wt && got status alpha >> $testroot/stdout.expected)
469 (cd $testroot/wt && got status epsilon >> $testroot/stdout.expected)
470 (cd $testroot/wt && got status foo >> $testroot/stdout.expected)
471 (cd $testroot/wt && got status new >> $testroot/stdout.expected)
472 (cd $testroot/wt && got status beta >> $testroot/stdout.expected)
473 (cd $testroot/wt && got status . >> $testroot/stdout.expected)
475 (cd $testroot/wt && got status newdir alpha epsilon foo new beta . \
476 > $testroot/stdout)
478 cmp -s $testroot/stdout.expected $testroot/stdout
479 ret="$?"
480 if [ "$ret" != "0" ]; then
481 diff -u $testroot/stdout.expected $testroot/stdout
482 fi
483 test_done "$testroot" "$ret"
486 function test_status_cvsignore {
487 local testroot=`test_init status_cvsignore`
489 got checkout $testroot/repo $testroot/wt > /dev/null
490 ret="$?"
491 if [ "$ret" != "0" ]; then
492 test_done "$testroot" "$ret"
493 return 1
494 fi
496 echo "unversioned file" > $testroot/wt/foo
497 echo "unversioned file" > $testroot/wt/foop
498 echo "unversioned file" > $testroot/wt/epsilon/bar
499 echo "unversioned file" > $testroot/wt/epsilon/boo
500 echo "unversioned file" > $testroot/wt/epsilon/moo
501 echo "foo" > $testroot/wt/.cvsignore
502 echo "bar" > $testroot/wt/epsilon/.cvsignore
503 echo "moo" >> $testroot/wt/epsilon/.cvsignore
505 echo '? .cvsignore' > $testroot/stdout.expected
506 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
507 echo '? epsilon/boo' >> $testroot/stdout.expected
508 echo '? foop' >> $testroot/stdout.expected
509 (cd $testroot/wt && got status > $testroot/stdout)
511 cmp -s $testroot/stdout.expected $testroot/stdout
512 ret="$?"
513 if [ "$ret" != "0" ]; then
514 diff -u $testroot/stdout.expected $testroot/stdout
515 test_done "$testroot" "$ret"
516 return 1
517 fi
519 echo '? .cvsignore' > $testroot/stdout.expected
520 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
521 echo '? epsilon/boo' >> $testroot/stdout.expected
522 echo '? foop' >> $testroot/stdout.expected
523 (cd $testroot/wt/gamma && got status > $testroot/stdout)
525 cmp -s $testroot/stdout.expected $testroot/stdout
526 ret="$?"
527 if [ "$ret" != "0" ]; then
528 diff -u $testroot/stdout.expected $testroot/stdout
529 fi
530 test_done "$testroot" "$ret"
533 function test_status_gitignore {
534 local testroot=`test_init status_gitignore`
536 got checkout $testroot/repo $testroot/wt > /dev/null
537 ret="$?"
538 if [ "$ret" != "0" ]; then
539 test_done "$testroot" "$ret"
540 return 1
541 fi
543 echo "unversioned file" > $testroot/wt/foo
544 echo "unversioned file" > $testroot/wt/foop
545 echo "unversioned file" > $testroot/wt/barp
546 echo "unversioned file" > $testroot/wt/epsilon/bar
547 echo "unversioned file" > $testroot/wt/epsilon/boo
548 echo "unversioned file" > $testroot/wt/epsilon/moo
549 mkdir -p $testroot/wt/a/b/c/
550 echo "unversioned file" > $testroot/wt/a/b/c/foo
551 echo "unversioned file" > $testroot/wt/a/b/c/zoo
552 echo "foo" > $testroot/wt/.gitignore
553 echo "bar*" >> $testroot/wt/.gitignore
554 echo "epsilon/**" >> $testroot/wt/.gitignore
555 echo "a/**/foo" >> $testroot/wt/.gitignore
556 echo "**/zoo" >> $testroot/wt/.gitignore
558 echo '? .gitignore' > $testroot/stdout.expected
559 echo '? foop' >> $testroot/stdout.expected
560 (cd $testroot/wt && got status > $testroot/stdout)
562 cmp -s $testroot/stdout.expected $testroot/stdout
563 ret="$?"
564 if [ "$ret" != "0" ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 echo '? .gitignore' > $testroot/stdout.expected
571 echo '? foop' >> $testroot/stdout.expected
572 (cd $testroot/wt/gamma && got status > $testroot/stdout)
574 cmp -s $testroot/stdout.expected $testroot/stdout
575 ret="$?"
576 if [ "$ret" != "0" ]; then
577 diff -u $testroot/stdout.expected $testroot/stdout
578 fi
579 test_done "$testroot" "$ret"
582 run_test test_status_basic
583 run_test test_status_subdir_no_mods
584 run_test test_status_subdir_no_mods2
585 run_test test_status_obstructed
586 run_test test_status_shows_local_mods_after_update
587 run_test test_status_unversioned_subdirs
588 run_test test_status_ignores_symlink
589 run_test test_status_shows_no_mods_after_complete_merge
590 run_test test_status_shows_conflict
591 run_test test_status_empty_dir
592 run_test test_status_empty_dir_unversioned_file
593 run_test test_status_many_paths
594 run_test test_status_cvsignore
595 run_test test_status_gitignore