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_update_basic {
20 local testroot=`test_init update_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 if [ "$?" != "0" ]; then
24 test_done "$testroot" "$?"
25 return 1
26 fi
28 echo "modified alpha" > $testroot/repo/alpha
29 git_commit $testroot/repo -m "modified alpha"
31 echo "U alpha" > $testroot/stdout.expected
32 echo -n "Updated to commit " >> $testroot/stdout.expected
33 git_show_head $testroot/repo >> $testroot/stdout.expected
34 echo >> $testroot/stdout.expected
36 (cd $testroot/wt && got update > $testroot/stdout)
38 cmp $testroot/stdout.expected $testroot/stdout
39 if [ "$?" != "0" ]; then
40 diff -u $testroot/stdout.expected $testroot/stdout
41 test_done "$testroot" "$?"
42 return 1
43 fi
45 echo "modified alpha" > $testroot/content.expected
46 cat $testroot/wt/alpha > $testroot/content
48 cmp $testroot/content.expected $testroot/content
49 ret="$?"
50 if [ "$ret" != "0" ]; then
51 diff -u $testroot/content.expected $testroot/content
52 fi
53 test_done "$testroot" "$ret"
54 }
56 function test_update_adds_file {
57 local testroot=`test_init update_adds_file`
59 got checkout $testroot/repo $testroot/wt > /dev/null
60 if [ "$?" != "0" ]; then
61 test_done "$testroot" "$?"
62 return 1
63 fi
65 echo "new" > $testroot/repo/gamma/new
66 (cd $testroot/repo && git add .)
67 git_commit $testroot/repo -m "adding a new file"
69 echo "A gamma/new" > $testroot/stdout.expected
70 echo -n "Updated to commit " >> $testroot/stdout.expected
71 git_show_head $testroot/repo >> $testroot/stdout.expected
72 echo >> $testroot/stdout.expected
74 (cd $testroot/wt && got update > $testroot/stdout)
76 cmp $testroot/stdout.expected $testroot/stdout
77 if [ "$?" != "0" ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$?"
80 return 1
81 fi
83 echo "new" >> $testroot/content.expected
84 cat $testroot/wt/gamma/new > $testroot/content
86 cmp $testroot/content.expected $testroot/content
87 ret="$?"
88 if [ "$ret" != "0" ]; then
89 diff -u $testroot/content.expected $testroot/content
90 fi
91 test_done "$testroot" "$ret"
92 }
94 function test_update_deletes_file {
95 local testroot=`test_init update_deletes_file`
97 got checkout $testroot/repo $testroot/wt > /dev/null
98 if [ "$?" != "0" ]; then
99 test_done "$testroot" "$?"
100 return 1
101 fi
103 (cd $testroot/repo && git_rm $testroot/repo beta)
104 git_commit $testroot/repo -m "deleting a file"
106 echo "D beta" > $testroot/stdout.expected
107 echo -n "Updated to commit " >> $testroot/stdout.expected
108 git_show_head $testroot/repo >> $testroot/stdout.expected
109 echo >> $testroot/stdout.expected
111 (cd $testroot/wt && got update > $testroot/stdout)
113 cmp $testroot/stdout.expected $testroot/stdout
114 if [ "$?" != "0" ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
116 test_done "$testroot" "$?"
117 return 1
118 fi
120 if [ -e $testroot/wt/beta ]; then
121 echo "removed file beta still exists on disk" >&2
122 test_done "$testroot" "1"
123 return 1
124 fi
126 test_done "$testroot" "0"
129 function test_update_deletes_dir {
130 local testroot=`test_init update_deletes_dir`
132 got checkout $testroot/repo $testroot/wt > /dev/null
133 if [ "$?" != "0" ]; then
134 test_done "$testroot" "$?"
135 return 1
136 fi
138 (cd $testroot/repo && git_rm $testroot/repo -r epsilon)
139 git_commit $testroot/repo -m "deleting a directory"
141 echo "D epsilon/zeta" > $testroot/stdout.expected
142 echo -n "Updated to commit " >> $testroot/stdout.expected
143 git_show_head $testroot/repo >> $testroot/stdout.expected
144 echo >> $testroot/stdout.expected
146 (cd $testroot/wt && got update > $testroot/stdout)
148 cmp $testroot/stdout.expected $testroot/stdout
149 if [ "$?" != "0" ]; then
150 diff -u $testroot/stdout.expected $testroot/stdout
151 test_done "$testroot" "$?"
152 return 1
153 fi
155 if [ -e $testroot/wt/epsilon ]; then
156 echo "removed dir epsilon still exists on disk" >&2
157 test_done "$testroot" "1"
158 return 1
159 fi
161 test_done "$testroot" "0"
164 function test_update_deletes_dir_with_path_prefix {
165 local testroot=`test_init update_deletes_dir_with_path_prefix`
166 local first_rev=`git_show_head $testroot/repo`
168 mkdir $testroot/repo/epsilon/psi
169 echo mu > $testroot/repo/epsilon/psi/mu
170 (cd $testroot/repo && git add .)
171 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
173 # check out the epsilon/ sub-tree
174 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
175 if [ "$?" != "0" ]; then
176 test_done "$testroot" "$?"
177 return 1
178 fi
180 # update back to first commit and expect psi/mu to be deleted
181 echo "D psi/mu" > $testroot/stdout.expected
182 echo "Updated to commit $first_rev" >> $testroot/stdout.expected
184 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
186 cmp $testroot/stdout.expected $testroot/stdout
187 if [ "$?" != "0" ]; then
188 diff -u $testroot/stdout.expected $testroot/stdout
189 test_done "$testroot" "$?"
190 return 1
191 fi
193 if [ -e $testroot/wt/psi ]; then
194 echo "removed dir psi still exists on disk" >&2
195 test_done "$testroot" "1"
196 return 1
197 fi
199 test_done "$testroot" "0"
202 function test_update_deletes_dir_recursively {
203 local testroot=`test_init update_deletes_dir_recursively`
204 local first_rev=`git_show_head $testroot/repo`
206 mkdir $testroot/repo/epsilon/psi
207 echo mu > $testroot/repo/epsilon/psi/mu
208 mkdir $testroot/repo/epsilon/psi/chi
209 echo tau > $testroot/repo/epsilon/psi/chi/tau
210 (cd $testroot/repo && git add .)
211 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
213 # check out the epsilon/ sub-tree
214 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
215 if [ "$?" != "0" ]; then
216 test_done "$testroot" "$?"
217 return 1
218 fi
220 # update back to first commit and expect psi/mu to be deleted
221 echo "D psi/chi/tau" > $testroot/stdout.expected
222 echo "D psi/mu" >> $testroot/stdout.expected
223 echo "Updated to commit $first_rev" >> $testroot/stdout.expected
225 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
227 cmp $testroot/stdout.expected $testroot/stdout
228 if [ "$?" != "0" ]; then
229 diff -u $testroot/stdout.expected $testroot/stdout
230 test_done "$testroot" "$?"
231 return 1
232 fi
234 if [ -e $testroot/wt/psi ]; then
235 echo "removed dir psi still exists on disk" >&2
236 test_done "$testroot" "1"
237 return 1
238 fi
240 test_done "$testroot" "0"
243 function test_update_sibling_dirs_with_common_prefix {
244 local testroot=`test_init update_sibling_dirs_with_common_prefix`
246 got checkout $testroot/repo $testroot/wt > /dev/null
247 if [ "$?" != "0" ]; then
248 test_done "$testroot" "$?"
249 return 1
250 fi
252 mkdir $testroot/repo/epsilon2
253 echo mu > $testroot/repo/epsilon2/mu
254 (cd $testroot/repo && git add epsilon2/mu)
255 git_commit $testroot/repo -m "adding sibling of epsilon"
256 echo change > $testroot/repo/epsilon/zeta
257 git_commit $testroot/repo -m "changing epsilon/zeta"
259 echo "U epsilon/zeta" > $testroot/stdout.expected
260 echo "A epsilon2/mu" >> $testroot/stdout.expected
261 echo -n "Updated to commit " >> $testroot/stdout.expected
262 git_show_head $testroot/repo >> $testroot/stdout.expected
263 echo >> $testroot/stdout.expected
265 (cd $testroot/wt && got update > $testroot/stdout)
267 cmp $testroot/stdout.expected $testroot/stdout
268 if [ "$?" != "0" ]; then
269 diff -u $testroot/stdout.expected $testroot/stdout
270 test_done "$testroot" "$?"
271 return 1
272 fi
274 echo "another change" > $testroot/repo/epsilon/zeta
275 git_commit $testroot/repo -m "changing epsilon/zeta again"
277 echo "U epsilon/zeta" > $testroot/stdout.expected
278 echo -n "Updated to commit " >> $testroot/stdout.expected
279 git_show_head $testroot/repo >> $testroot/stdout.expected
280 echo >> $testroot/stdout.expected
282 # Bug: This update used to do delete/add epsilon2/mu again:
283 # U epsilon/zeta
284 # D epsilon2/mu <--- not intended
285 # A epsilon2/mu <--- not intended
286 (cd $testroot/wt && got update > $testroot/stdout)
288 cmp $testroot/stdout.expected $testroot/stdout
289 if [ "$?" != "0" ]; then
290 diff -u $testroot/stdout.expected $testroot/stdout
291 test_done "$testroot" "$?"
292 return 1
293 fi
295 cmp $testroot/stdout.expected $testroot/stdout
296 if [ "$?" != "0" ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$?"
299 return 1
300 fi
302 test_done "$testroot" "0"
305 function test_update_dir_with_dot_sibling {
306 local testroot=`test_init update_dir_with_dot_sibling`
308 got checkout $testroot/repo $testroot/wt > /dev/null
309 if [ "$?" != "0" ]; then
310 test_done "$testroot" "$?"
311 return 1
312 fi
314 echo text > $testroot/repo/epsilon.txt
315 (cd $testroot/repo && git add epsilon.txt)
316 git_commit $testroot/repo -m "adding sibling of epsilon"
317 echo change > $testroot/repo/epsilon/zeta
318 git_commit $testroot/repo -m "changing epsilon/zeta"
320 echo "A epsilon.txt" > $testroot/stdout.expected
321 echo "U epsilon/zeta" >> $testroot/stdout.expected
322 echo -n "Updated to commit " >> $testroot/stdout.expected
323 git_show_head $testroot/repo >> $testroot/stdout.expected
324 echo >> $testroot/stdout.expected
326 (cd $testroot/wt && got update > $testroot/stdout)
328 cmp $testroot/stdout.expected $testroot/stdout
329 if [ "$?" != "0" ]; then
330 diff -u $testroot/stdout.expected $testroot/stdout
331 test_done "$testroot" "$?"
332 return 1
333 fi
335 echo "another change" > $testroot/repo/epsilon/zeta
336 git_commit $testroot/repo -m "changing epsilon/zeta again"
338 echo "U epsilon/zeta" > $testroot/stdout.expected
339 echo -n "Updated to commit " >> $testroot/stdout.expected
340 git_show_head $testroot/repo >> $testroot/stdout.expected
341 echo >> $testroot/stdout.expected
343 (cd $testroot/wt && got update > $testroot/stdout)
345 cmp $testroot/stdout.expected $testroot/stdout
346 if [ "$?" != "0" ]; then
347 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$?"
349 return 1
350 fi
352 cmp $testroot/stdout.expected $testroot/stdout
353 if [ "$?" != "0" ]; then
354 diff -u $testroot/stdout.expected $testroot/stdout
355 test_done "$testroot" "$?"
356 return 1
357 fi
359 test_done "$testroot" "0"
362 function test_update_moves_files_upwards {
363 local testroot=`test_init update_moves_files_upwards`
365 mkdir $testroot/repo/epsilon/psi
366 echo mu > $testroot/repo/epsilon/psi/mu
367 mkdir $testroot/repo/epsilon/psi/chi
368 echo tau > $testroot/repo/epsilon/psi/chi/tau
369 (cd $testroot/repo && git add .)
370 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
372 got checkout $testroot/repo $testroot/wt > /dev/null
373 if [ "$?" != "0" ]; then
374 test_done "$testroot" "$?"
375 return 1
376 fi
378 (cd $testroot/repo && git mv epsilon/psi/mu epsilon/mu)
379 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon/psi/tau)
380 git_commit $testroot/repo -m "moving files upwards"
382 echo "A epsilon/mu" > $testroot/stdout.expected
383 echo "D epsilon/psi/chi/tau" >> $testroot/stdout.expected
384 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
385 echo "A epsilon/psi/tau" >> $testroot/stdout.expected
386 echo -n "Updated to commit " >> $testroot/stdout.expected
387 git_show_head $testroot/repo >> $testroot/stdout.expected
388 echo >> $testroot/stdout.expected
390 (cd $testroot/wt && got update > $testroot/stdout)
392 cmp $testroot/stdout.expected $testroot/stdout
393 if [ "$?" != "0" ]; then
394 diff -u $testroot/stdout.expected $testroot/stdout
395 test_done "$testroot" "$?"
396 return 1
397 fi
399 if [ -e $testroot/wt/epsilon/psi/chi ]; then
400 echo "removed dir epsilon/psi/chi still exists on disk" >&2
401 test_done "$testroot" "1"
402 return 1
403 fi
405 if [ -e $testroot/wt/epsilon/psi/mu ]; then
406 echo "removed file epsilon/psi/mu still exists on disk" >&2
407 test_done "$testroot" "1"
408 return 1
409 fi
411 test_done "$testroot" "0"
414 function test_update_moves_files_to_new_dir {
415 local testroot=`test_init update_moves_files_to_new_dir`
417 mkdir $testroot/repo/epsilon/psi
418 echo mu > $testroot/repo/epsilon/psi/mu
419 mkdir $testroot/repo/epsilon/psi/chi
420 echo tau > $testroot/repo/epsilon/psi/chi/tau
421 (cd $testroot/repo && git add .)
422 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
424 got checkout $testroot/repo $testroot/wt > /dev/null
425 if [ "$?" != "0" ]; then
426 test_done "$testroot" "$?"
427 return 1
428 fi
430 mkdir -p $testroot/repo/epsilon-new/psi
431 (cd $testroot/repo && git mv epsilon/psi/mu epsilon-new/mu)
432 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon-new/psi/tau)
433 git_commit $testroot/repo -m "moving files upwards"
435 echo "A epsilon-new/mu" > $testroot/stdout.expected
436 echo "A epsilon-new/psi/tau" >> $testroot/stdout.expected
437 echo "D epsilon/psi/chi/tau" >> $testroot/stdout.expected
438 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
439 echo -n "Updated to commit " >> $testroot/stdout.expected
440 git_show_head $testroot/repo >> $testroot/stdout.expected
441 echo >> $testroot/stdout.expected
443 (cd $testroot/wt && got update > $testroot/stdout)
445 cmp $testroot/stdout.expected $testroot/stdout
446 if [ "$?" != "0" ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$?"
449 return 1
450 fi
452 if [ -e $testroot/wt/epsilon/psi/chi ]; then
453 echo "removed dir epsilon/psi/chi still exists on disk" >&2
454 test_done "$testroot" "1"
455 return 1
456 fi
458 if [ -e $testroot/wt/epsilon/psi/mu ]; then
459 echo "removed file epsilon/psi/mu still exists on disk" >&2
460 test_done "$testroot" "1"
461 return 1
462 fi
464 test_done "$testroot" "0"
467 function test_update_creates_missing_parent {
468 local testroot=`test_init update_creates_missing_parent 1`
470 touch $testroot/repo/Makefile
471 touch $testroot/repo/snake.6
472 touch $testroot/repo/snake.c
473 (cd $testroot/repo && git add .)
474 git_commit $testroot/repo -m "adding initial snake tree"
476 got checkout $testroot/repo $testroot/wt > /dev/null
477 if [ "$?" != "0" ]; then
478 test_done "$testroot" "$?"
479 return 1
480 fi
482 mkdir -p $testroot/repo/snake
483 (cd $testroot/repo && git mv Makefile snake.6 snake.c snake)
484 touch $testroot/repo/snake/move.c
485 touch $testroot/repo/snake/pathnames.h
486 touch $testroot/repo/snake/snake.h
487 mkdir -p $testroot/repo/snscore
488 touch $testroot/repo/snscore/Makefile
489 touch $testroot/repo/snscore/snscore.c
490 (cd $testroot/repo && git add .)
491 git_commit $testroot/repo -m "restructuring snake tree"
493 echo "D Makefile" > $testroot/stdout.expected
494 echo "D snake.6" >> $testroot/stdout.expected
495 echo "D snake.c" >> $testroot/stdout.expected
496 echo "A snake/Makefile" >> $testroot/stdout.expected
497 echo "A snake/move.c" >> $testroot/stdout.expected
498 echo "A snake/pathnames.h" >> $testroot/stdout.expected
499 echo "A snake/snake.6" >> $testroot/stdout.expected
500 echo "A snake/snake.c" >> $testroot/stdout.expected
501 echo "A snake/snake.h" >> $testroot/stdout.expected
502 echo "A snscore/Makefile" >> $testroot/stdout.expected
503 echo "A snscore/snscore.c" >> $testroot/stdout.expected
504 echo -n "Updated to commit " >> $testroot/stdout.expected
505 git_show_head $testroot/repo >> $testroot/stdout.expected
506 echo >> $testroot/stdout.expected
508 (cd $testroot/wt && got update > $testroot/stdout)
510 cmp $testroot/stdout.expected $testroot/stdout
511 if [ "$?" != "0" ]; then
512 diff -u $testroot/stdout.expected $testroot/stdout
513 test_done "$testroot" "$?"
514 return 1
515 fi
517 test_done "$testroot" "0"
520 function test_update_creates_missing_parent_with_subdir {
521 local testroot=`test_init update_creates_missing_parent_with_subdir 1`
523 touch $testroot/repo/Makefile
524 touch $testroot/repo/snake.6
525 touch $testroot/repo/snake.c
526 (cd $testroot/repo && git add .)
527 git_commit $testroot/repo -m "adding initial snake tree"
529 got checkout $testroot/repo $testroot/wt > /dev/null
530 if [ "$?" != "0" ]; then
531 test_done "$testroot" "$?"
532 return 1
533 fi
535 mkdir -p $testroot/repo/sss/snake
536 (cd $testroot/repo && git mv Makefile snake.6 snake.c sss/snake)
537 touch $testroot/repo/sss/snake/move.c
538 touch $testroot/repo/sss/snake/pathnames.h
539 touch $testroot/repo/sss/snake/snake.h
540 mkdir -p $testroot/repo/snscore
541 touch $testroot/repo/snscore/Makefile
542 touch $testroot/repo/snscore/snscore.c
543 (cd $testroot/repo && git add .)
544 git_commit $testroot/repo -m "restructuring snake tree"
546 echo "D Makefile" > $testroot/stdout.expected
547 echo "D snake.6" >> $testroot/stdout.expected
548 echo "D snake.c" >> $testroot/stdout.expected
549 echo "A snscore/Makefile" >> $testroot/stdout.expected
550 echo "A snscore/snscore.c" >> $testroot/stdout.expected
551 echo "A sss/snake/Makefile" >> $testroot/stdout.expected
552 echo "A sss/snake/move.c" >> $testroot/stdout.expected
553 echo "A sss/snake/pathnames.h" >> $testroot/stdout.expected
554 echo "A sss/snake/snake.6" >> $testroot/stdout.expected
555 echo "A sss/snake/snake.c" >> $testroot/stdout.expected
556 echo "A sss/snake/snake.h" >> $testroot/stdout.expected
557 echo -n "Updated to commit " >> $testroot/stdout.expected
558 git_show_head $testroot/repo >> $testroot/stdout.expected
559 echo >> $testroot/stdout.expected
561 (cd $testroot/wt && got update > $testroot/stdout)
563 cmp $testroot/stdout.expected $testroot/stdout
564 if [ "$?" != "0" ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done "$testroot" "$?"
567 return 1
568 fi
570 test_done "$testroot" "0"
573 function test_update_file_in_subsubdir {
574 local testroot=`test_init update_fle_in_subsubdir 1`
576 touch $testroot/repo/Makefile
577 mkdir -p $testroot/repo/altq
578 touch $testroot/repo/altq/if_altq.h
579 mkdir -p $testroot/repo/arch/alpha
580 touch $testroot/repo/arch/alpha/Makefile
581 (cd $testroot/repo && git add .)
582 git_commit $testroot/repo -m "adding initial tree"
584 got checkout $testroot/repo $testroot/wt > /dev/null
585 if [ "$?" != "0" ]; then
586 test_done "$testroot" "$?"
587 return 1
588 fi
590 echo change > $testroot/repo/arch/alpha/Makefile
591 (cd $testroot/repo && git add .)
592 git_commit $testroot/repo -m "changed a file"
594 echo "U arch/alpha/Makefile" > $testroot/stdout.expected
595 echo -n "Updated to commit " >> $testroot/stdout.expected
596 git_show_head $testroot/repo >> $testroot/stdout.expected
597 echo >> $testroot/stdout.expected
599 (cd $testroot/wt && got update > $testroot/stdout)
601 cmp $testroot/stdout.expected $testroot/stdout
602 if [ "$?" != "0" ]; then
603 diff -u $testroot/stdout.expected $testroot/stdout
604 test_done "$testroot" "$?"
605 return 1
606 fi
608 test_done "$testroot" "0"
611 run_test test_update_basic
612 run_test test_update_adds_file
613 run_test test_update_deletes_file
614 run_test test_update_deletes_dir
615 run_test test_update_deletes_dir_with_path_prefix
616 run_test test_update_deletes_dir_recursively
617 run_test test_update_sibling_dirs_with_common_prefix
618 run_test test_update_dir_with_dot_sibling
619 run_test test_update_moves_files_upwards
620 run_test test_update_moves_files_to_new_dir
621 run_test test_update_creates_missing_parent
622 run_test test_update_creates_missing_parent_with_subdir
623 run_test test_update_file_in_subsubdir