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)
37 echo 'M alpha' > $testroot/stdout.expected
38 echo 'D beta' >> $testroot/stdout.expected
39 echo '! epsilon/zeta' >> $testroot/stdout.expected
40 echo '? foo' >> $testroot/stdout.expected
41 echo 'A new' >> $testroot/stdout.expected
43 (cd $testroot/wt && got status > $testroot/stdout)
45 cmp -s $testroot/stdout.expected $testroot/stdout
46 ret="$?"
47 if [ "$ret" != "0" ]; then
48 diff -u $testroot/stdout.expected $testroot/stdout
49 fi
50 test_done "$testroot" "$ret"
51 }
53 function test_status_subdir_no_mods {
54 local testroot=`test_init status_subdir_no_mods 1`
56 mkdir $testroot/repo/Basic/
57 mkdir $testroot/repo/Basic/Targets/
58 touch $testroot/repo/Basic/Targets/AArch64.cpp
59 touch $testroot/repo/Basic/Targets.cpp
60 touch $testroot/repo/Basic/Targets.h
61 (cd $testroot/repo && git add .)
62 git_commit $testroot/repo -m "add subdir with files"
64 got checkout $testroot/repo $testroot/wt > /dev/null
65 ret="$?"
66 if [ "$ret" != "0" ]; then
67 test_done "$testroot" "$ret"
68 return 1
69 fi
71 touch $testroot/stdout.expected
73 # This used to erroneously print:
74 #
75 # ! Basic/Targets.cpp
76 # ? Basic/Targets.cpp
77 (cd $testroot/wt && got status > $testroot/stdout)
79 cmp -s $testroot/stdout.expected $testroot/stdout
80 ret="$?"
81 if [ "$ret" != "0" ]; then
82 diff -u $testroot/stdout.expected $testroot/stdout
83 fi
84 test_done "$testroot" "$ret"
85 }
87 function test_status_subdir_no_mods2 {
88 local testroot=`test_init status_subdir_no_mods2 1`
90 mkdir $testroot/repo/AST
91 touch $testroot/repo/AST/APValue.cpp
92 mkdir $testroot/repo/ASTMatchers
93 touch $testroot/repo/ASTMatchers/ASTMatchFinder.cpp
94 mkdir $testroot/repo/Frontend
95 touch $testroot/repo/Frontend/ASTConsumers.cpp
96 mkdir $testroot/repo/Frontend/Rewrite
97 touch $testroot/repo/Frontend/Rewrite/CMakeLists.txt
98 mkdir $testroot/repo/FrontendTool
99 touch $testroot/repo/FrontendTool/CMakeLists.txt
100 touch $testroot/repo/FrontendTool/ExecuteCompilerInvocation.cpp
101 (cd $testroot/repo && git add .)
102 git_commit $testroot/repo -m "add subdir with files"
104 got checkout $testroot/repo $testroot/wt > /dev/null
105 ret="$?"
106 if [ "$ret" != "0" ]; then
107 test_done "$testroot" "$ret"
108 return 1
109 fi
111 touch $testroot/stdout.expected
113 # This used to erroneously print:
115 # ! AST/APValue.cpp
116 # ? AST/APValue.cpp
117 # ! Frontend/ASTConsumers.cpp
118 # ! Frontend/Rewrite/CMakeLists.txt
119 # ? Frontend/ASTConsumers.cpp
120 # ? Frontend/Rewrite/CMakeLists.txt
121 (cd $testroot/wt && got status > $testroot/stdout)
123 cmp -s $testroot/stdout.expected $testroot/stdout
124 ret="$?"
125 if [ "$ret" != "0" ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 fi
128 test_done "$testroot" "$ret"
131 function test_status_obstructed {
132 local testroot=`test_init status_obstructed`
134 got checkout $testroot/repo $testroot/wt > /dev/null
135 ret="$?"
136 if [ "$ret" != "0" ]; then
137 test_done "$testroot" "$ret"
138 return 1
139 fi
141 rm $testroot/wt/epsilon/zeta
142 mkdir $testroot/wt/epsilon/zeta
144 echo '~ epsilon/zeta' > $testroot/stdout.expected
146 (cd $testroot/wt && got status > $testroot/stdout)
148 cmp -s $testroot/stdout.expected $testroot/stdout
149 ret="$?"
150 if [ "$ret" != "0" ]; then
151 diff -u $testroot/stdout.expected $testroot/stdout
152 fi
153 test_done "$testroot" "$ret"
156 function test_status_shows_local_mods_after_update {
157 local testroot=`test_init status_shows_local_mods_after_update 1`
159 echo "1" > $testroot/repo/numbers
160 echo "2" >> $testroot/repo/numbers
161 echo "3" >> $testroot/repo/numbers
162 echo "4" >> $testroot/repo/numbers
163 echo "5" >> $testroot/repo/numbers
164 echo "6" >> $testroot/repo/numbers
165 echo "7" >> $testroot/repo/numbers
166 echo "8" >> $testroot/repo/numbers
167 (cd $testroot/repo && git add numbers)
168 git_commit $testroot/repo -m "added numbers file"
170 got checkout $testroot/repo $testroot/wt > /dev/null
171 ret="$?"
172 if [ "$ret" != "0" ]; then
173 test_done "$testroot" "$ret"
174 return 1
175 fi
177 sed -i 's/2/22/' $testroot/repo/numbers
178 git_commit $testroot/repo -m "modified line 2"
180 # modify line 7; both changes should merge cleanly
181 sed -i 's/7/77/' $testroot/wt/numbers
183 echo "G numbers" > $testroot/stdout.expected
184 echo -n "Updated to commit " >> $testroot/stdout.expected
185 git_show_head $testroot/repo >> $testroot/stdout.expected
186 echo >> $testroot/stdout.expected
188 (cd $testroot/wt && got update > $testroot/stdout)
190 cmp -s $testroot/stdout.expected $testroot/stdout
191 ret="$?"
192 if [ "$ret" != "0" ]; then
193 diff -u $testroot/stdout.expected $testroot/stdout
194 test_done "$testroot" "$ret"
195 return 1
196 fi
198 echo 'M numbers' > $testroot/stdout.expected
200 (cd $testroot/wt && got status > $testroot/stdout)
202 cmp -s $testroot/stdout.expected $testroot/stdout
203 ret="$?"
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 fi
207 test_done "$testroot" "$ret"
210 function test_status_unversioned_subdirs {
211 local testroot=`test_init status_unversioned_subdirs 1`
213 mkdir $testroot/repo/cdfs/
214 touch $testroot/repo/cdfs/Makefile
215 mkdir $testroot/repo/common/
216 touch $testroot/repo/common/Makefile
217 mkdir $testroot/repo/iso/
218 touch $testroot/repo/iso/Makefile
219 mkdir $testroot/repo/ramdisk/
220 touch $testroot/repo/ramdisk/Makefile
221 touch $testroot/repo/ramdisk/list.local
222 mkdir $testroot/repo/ramdisk_cd/
223 touch $testroot/repo/ramdisk_cd/Makefile
224 touch $testroot/repo/ramdisk_cd/list.local
225 (cd $testroot/repo && git add .)
226 git_commit $testroot/repo -m "first commit"
228 got checkout $testroot/repo $testroot/wt > /dev/null
229 ret="$?"
230 if [ "$ret" != "0" ]; then
231 test_done "$testroot" "$ret"
232 return 1
233 fi
235 mkdir $testroot/wt/cdfs/obj
236 mkdir $testroot/wt/ramdisk/obj
237 mkdir $testroot/wt/ramdisk_cd/obj
238 mkdir $testroot/wt/iso/obj
240 echo -n > $testroot/stdout.expected
242 # This used to erroneously print:
244 # ! ramdisk_cd/Makefile
245 # ! ramdisk_cd/list.local
246 # ? ramdisk_cd/Makefile
247 # ? ramdisk_cd/list.local
248 (cd $testroot/wt && got status > $testroot/stdout)
250 cmp -s $testroot/stdout.expected $testroot/stdout
251 ret="$?"
252 if [ "$ret" != "0" ]; then
253 diff -u $testroot/stdout.expected $testroot/stdout
254 fi
255 test_done "$testroot" "$ret"
258 # 'got status' ignores symlinks at present; this might change eventually
259 function test_status_ignores_symlink {
260 local testroot=`test_init status_ignores_symlink 1`
262 mkdir $testroot/repo/ramdisk/
263 touch $testroot/repo/ramdisk/Makefile
264 (cd $testroot/repo && git add .)
265 git_commit $testroot/repo -m "first commit"
267 got checkout $testroot/repo $testroot/wt > /dev/null
268 ret="$?"
269 if [ "$ret" != "0" ]; then
270 test_done "$testroot" "$ret"
271 return 1
272 fi
274 ln -s /usr/obj/distrib/i386/ramdisk $testroot/wt/ramdisk/obj
276 echo -n > $testroot/stdout.expected
278 (cd $testroot/wt && got status > $testroot/stdout)
280 cmp -s $testroot/stdout.expected $testroot/stdout
281 ret="$?"
282 if [ "$ret" != "0" ]; then
283 diff -u $testroot/stdout.expected $testroot/stdout
284 fi
285 test_done "$testroot" "$ret"
288 function test_status_shows_no_mods_after_complete_merge {
289 local testroot=`test_init status_shows_no_mods_after_complete_merge 1`
291 # make this file larger than the usual blob buffer size of 8192
292 echo -n > $testroot/repo/numbers
293 for i in `jot 16384`; do
294 echo "$i" >> $testroot/repo/numbers
295 done
297 (cd $testroot/repo && git add numbers)
298 git_commit $testroot/repo -m "added numbers file"
300 got checkout $testroot/repo $testroot/wt > /dev/null
301 ret="$?"
302 if [ "$ret" != "0" ]; then
303 test_done "$testroot" "$ret"
304 return 1
305 fi
307 sed -i 's/2/22/' $testroot/repo/numbers
308 git_commit $testroot/repo -m "modified line 2"
310 sleep 1
311 # modify line 2 again; no local changes are left after merge
312 sed -i 's/2/22/' $testroot/wt/numbers
314 echo "G numbers" > $testroot/stdout.expected
315 echo -n "Updated to commit " >> $testroot/stdout.expected
316 git_show_head $testroot/repo >> $testroot/stdout.expected
317 echo >> $testroot/stdout.expected
319 (cd $testroot/wt && got update > $testroot/stdout)
321 cmp -s $testroot/stdout.expected $testroot/stdout
322 ret="$?"
323 if [ "$ret" != "0" ]; then
324 diff -u $testroot/stdout.expected $testroot/stdout
325 test_done "$testroot" "$ret"
326 return 1
327 fi
329 echo -n > $testroot/stdout.expected
331 (cd $testroot/wt && got status > $testroot/stdout)
333 cmp -s $testroot/stdout.expected $testroot/stdout
334 ret="$?"
335 if [ "$ret" != "0" ]; then
336 diff -u $testroot/stdout.expected $testroot/stdout
337 fi
338 test_done "$testroot" "$ret"
341 function test_status_shows_conflict {
342 local testroot=`test_init status_shows_conflict 1`
344 echo "1" > $testroot/repo/numbers
345 echo "2" >> $testroot/repo/numbers
346 echo "3" >> $testroot/repo/numbers
347 echo "4" >> $testroot/repo/numbers
348 echo "5" >> $testroot/repo/numbers
349 echo "6" >> $testroot/repo/numbers
350 echo "7" >> $testroot/repo/numbers
351 echo "8" >> $testroot/repo/numbers
352 (cd $testroot/repo && git add numbers)
353 git_commit $testroot/repo -m "added numbers file"
355 got checkout $testroot/repo $testroot/wt > /dev/null
356 ret="$?"
357 if [ "$ret" != "0" ]; then
358 test_done "$testroot" "$ret"
359 return 1
360 fi
362 sed -i 's/2/22/' $testroot/repo/numbers
363 git_commit $testroot/repo -m "modified line 2"
365 # modify line 2 in a conflicting way
366 sed -i 's/2/77/' $testroot/wt/numbers
368 echo "C numbers" > $testroot/stdout.expected
369 echo -n "Updated to commit " >> $testroot/stdout.expected
370 git_show_head $testroot/repo >> $testroot/stdout.expected
371 echo >> $testroot/stdout.expected
373 (cd $testroot/wt && got update > $testroot/stdout)
375 cmp -s $testroot/stdout.expected $testroot/stdout
376 ret="$?"
377 if [ "$ret" != "0" ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 test_done "$testroot" "$ret"
380 return 1
381 fi
383 echo 'C numbers' > $testroot/stdout.expected
385 (cd $testroot/wt && got status > $testroot/stdout)
387 cmp -s $testroot/stdout.expected $testroot/stdout
388 ret="$?"
389 if [ "$ret" != "0" ]; then
390 diff -u $testroot/stdout.expected $testroot/stdout
391 fi
392 test_done "$testroot" "$ret"
395 function test_status_empty_dir {
396 local testroot=`test_init status_empty_dir`
398 got checkout $testroot/repo $testroot/wt > /dev/null
399 ret="$?"
400 if [ "$ret" != "0" ]; then
401 test_done "$testroot" "$ret"
402 return 1
403 fi
405 rm $testroot/wt/epsilon/zeta
407 echo '! epsilon/zeta' > $testroot/stdout.expected
409 (cd $testroot/wt && got status epsilon > $testroot/stdout)
411 cmp -s $testroot/stdout.expected $testroot/stdout
412 ret="$?"
413 if [ "$ret" != "0" ]; then
414 diff -u $testroot/stdout.expected $testroot/stdout
415 fi
416 test_done "$testroot" "$ret"
419 function test_status_empty_dir_unversioned_file {
420 local testroot=`test_init status_empty_dir_unversioned_file`
422 got checkout $testroot/repo $testroot/wt > /dev/null
423 ret="$?"
424 if [ "$ret" != "0" ]; then
425 test_done "$testroot" "$ret"
426 return 1
427 fi
429 rm $testroot/wt/epsilon/zeta
430 touch $testroot/wt/epsilon/unversioned
432 echo '? epsilon/unversioned' > $testroot/stdout.expected
433 echo '! epsilon/zeta' >> $testroot/stdout.expected
435 (cd $testroot/wt && got status epsilon > $testroot/stdout)
437 cmp -s $testroot/stdout.expected $testroot/stdout
438 ret="$?"
439 if [ "$ret" != "0" ]; then
440 diff -u $testroot/stdout.expected $testroot/stdout
441 fi
442 test_done "$testroot" "$ret"
445 function test_status_many_paths {
446 local testroot=`test_init status_many_paths`
448 got checkout $testroot/repo $testroot/wt > /dev/null
449 ret="$?"
450 if [ "$ret" != "0" ]; then
451 test_done "$testroot" "$ret"
452 return 1
453 fi
455 echo "modified alpha" > $testroot/wt/alpha
456 (cd $testroot/wt && got rm beta >/dev/null)
457 echo "unversioned file" > $testroot/wt/foo
458 rm $testroot/wt/epsilon/zeta
459 touch $testroot/wt/beta
460 echo "new file" > $testroot/wt/new
461 mkdir $testroot/wt/newdir
462 (cd $testroot/wt && got add new >/dev/null)
464 (cd $testroot/wt && got status newdir > $testroot/stdout.expected)
465 (cd $testroot/wt && got status alpha >> $testroot/stdout.expected)
466 (cd $testroot/wt && got status epsilon >> $testroot/stdout.expected)
467 (cd $testroot/wt && got status foo >> $testroot/stdout.expected)
468 (cd $testroot/wt && got status new >> $testroot/stdout.expected)
469 (cd $testroot/wt && got status beta >> $testroot/stdout.expected)
470 (cd $testroot/wt && got status . >> $testroot/stdout.expected)
472 (cd $testroot/wt && got status newdir alpha epsilon foo new beta . \
473 > $testroot/stdout)
475 cmp -s $testroot/stdout.expected $testroot/stdout
476 ret="$?"
477 if [ "$ret" != "0" ]; then
478 diff -u $testroot/stdout.expected $testroot/stdout
479 fi
480 test_done "$testroot" "$ret"
483 function test_status_cvsignore {
484 local testroot=`test_init status_cvsignore`
486 got checkout $testroot/repo $testroot/wt > /dev/null
487 ret="$?"
488 if [ "$ret" != "0" ]; then
489 test_done "$testroot" "$ret"
490 return 1
491 fi
493 echo "unversioned file" > $testroot/wt/foo
494 echo "unversioned file" > $testroot/wt/foop
495 echo "unversioned file" > $testroot/wt/epsilon/bar
496 echo "unversioned file" > $testroot/wt/epsilon/boo
497 echo "unversioned file" > $testroot/wt/epsilon/moo
498 echo "foo" > $testroot/wt/.cvsignore
499 echo "bar" > $testroot/wt/epsilon/.cvsignore
500 echo "moo" >> $testroot/wt/epsilon/.cvsignore
502 echo '? .cvsignore' > $testroot/stdout.expected
503 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
504 echo '? epsilon/boo' >> $testroot/stdout.expected
505 echo '? foop' >> $testroot/stdout.expected
506 (cd $testroot/wt && got status > $testroot/stdout)
508 cmp -s $testroot/stdout.expected $testroot/stdout
509 ret="$?"
510 if [ "$ret" != "0" ]; then
511 diff -u $testroot/stdout.expected $testroot/stdout
512 test_done "$testroot" "$ret"
513 return 1
514 fi
516 echo '? .cvsignore' > $testroot/stdout.expected
517 echo '? epsilon/.cvsignore' >> $testroot/stdout.expected
518 echo '? epsilon/boo' >> $testroot/stdout.expected
519 echo '? foop' >> $testroot/stdout.expected
520 (cd $testroot/wt/gamma && got status > $testroot/stdout)
522 cmp -s $testroot/stdout.expected $testroot/stdout
523 ret="$?"
524 if [ "$ret" != "0" ]; then
525 diff -u $testroot/stdout.expected $testroot/stdout
526 fi
527 test_done "$testroot" "$ret"
530 run_test test_status_basic
531 run_test test_status_subdir_no_mods
532 run_test test_status_subdir_no_mods2
533 run_test test_status_obstructed
534 run_test test_status_shows_local_mods_after_update
535 run_test test_status_unversioned_subdirs
536 run_test test_status_ignores_symlink
537 run_test test_status_shows_no_mods_after_complete_merge
538 run_test test_status_shows_conflict
539 run_test test_status_empty_dir
540 run_test test_status_empty_dir_unversioned_file
541 run_test test_status_many_paths
542 run_test test_status_cvsignore