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_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" "$?"
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" "$?"
45 echo "modified alpha" > $testroot/content.expected
46 cat $testroot/wt/alpha > $testroot/content
48 cmp $testroot/content.expected $testroot/content
50 if [ "$ret" != "0" ]; then
51 diff -u $testroot/content.expected $testroot/content
53 test_done "$testroot" "$ret"
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" "$?"
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" "$?"
83 echo "new" >> $testroot/content.expected
84 cat $testroot/wt/gamma/new > $testroot/content
86 cmp $testroot/content.expected $testroot/content
88 if [ "$ret" != "0" ]; then
89 diff -u $testroot/content.expected $testroot/content
91 test_done "$testroot" "$ret"
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" "$?"
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" "$?"
120 if [ -e $testroot/wt/beta ]; then
121 echo "removed file beta still exists on disk" >&2
122 test_done "$testroot" "1"
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" "$?"
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" "$?"
155 if [ -e $testroot/wt/epsilon ]; then
156 echo "removed dir epsilon still exists on disk" >&2
157 test_done "$testroot" "1"
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" "$?"
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" "$?"
193 if [ -e $testroot/wt/psi ]; then
194 echo "removed dir psi still exists on disk" >&2
195 test_done "$testroot" "1"
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" "$?"
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" "$?"
234 if [ -e $testroot/wt/psi ]; then
235 echo "removed dir psi still exists on disk" >&2
236 test_done "$testroot" "1"
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" "$?"
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" "$?"
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:
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" "$?"
295 cmp $testroot/stdout.expected $testroot/stdout
296 if [ "$?" != "0" ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$?"
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" "$?"
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 "U epsilon/zeta" > $testroot/stdout.expected
321 echo "A epsilon.txt" >> $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" "$?"
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" "$?"
352 cmp $testroot/stdout.expected $testroot/stdout
353 if [ "$?" != "0" ]; then
354 diff -u $testroot/stdout.expected $testroot/stdout
355 test_done "$testroot" "$?"
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" "$?"
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" "$?"
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"
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"
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" "$?"
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 "D epsilon/psi/chi/tau" > $testroot/stdout.expected
436 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
437 echo "A epsilon-new/mu" >> $testroot/stdout.expected
438 echo "A epsilon-new/psi/tau" >> $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" "$?"
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"
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"
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" "$?"
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" "$?"
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" "$?"
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" "$?"
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" "$?"
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" "$?"
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