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 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified alpha" > $testroot/repo/alpha
30 git_commit $testroot/repo -m "modified alpha"
32 echo "U alpha" > $testroot/stdout.expected
33 echo -n "Updated to commit " >> $testroot/stdout.expected
34 git_show_head $testroot/repo >> $testroot/stdout.expected
35 echo >> $testroot/stdout.expected
37 (cd $testroot/wt && got update > $testroot/stdout)
39 cmp -s $testroot/stdout.expected $testroot/stdout
40 ret="$?"
41 if [ "$ret" != "0" ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
43 test_done "$testroot" "$ret"
44 return 1
45 fi
47 echo "modified alpha" > $testroot/content.expected
48 cat $testroot/wt/alpha > $testroot/content
50 cmp -s $testroot/content.expected $testroot/content
51 ret="$?"
52 if [ "$ret" != "0" ]; then
53 diff -u $testroot/content.expected $testroot/content
54 fi
55 test_done "$testroot" "$ret"
56 }
58 function test_update_adds_file {
59 local testroot=`test_init update_adds_file`
61 got checkout $testroot/repo $testroot/wt > /dev/null
62 ret="$?"
63 if [ "$ret" != "0" ]; then
64 test_done "$testroot" "$ret"
65 return 1
66 fi
68 echo "new" > $testroot/repo/gamma/new
69 (cd $testroot/repo && git add .)
70 git_commit $testroot/repo -m "adding a new file"
72 echo "A gamma/new" > $testroot/stdout.expected
73 echo -n "Updated to commit " >> $testroot/stdout.expected
74 git_show_head $testroot/repo >> $testroot/stdout.expected
75 echo >> $testroot/stdout.expected
77 (cd $testroot/wt && got update > $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 test_done "$testroot" "$ret"
84 return 1
85 fi
87 echo "new" >> $testroot/content.expected
88 cat $testroot/wt/gamma/new > $testroot/content
90 cmp -s $testroot/content.expected $testroot/content
91 ret="$?"
92 if [ "$ret" != "0" ]; then
93 diff -u $testroot/content.expected $testroot/content
94 fi
95 test_done "$testroot" "$ret"
96 }
98 function test_update_deletes_file {
99 local testroot=`test_init update_deletes_file`
101 got checkout $testroot/repo $testroot/wt > /dev/null
102 ret="$?"
103 if [ "$ret" != "0" ]; then
104 test_done "$testroot" "$ret"
105 return 1
106 fi
108 (cd $testroot/repo && git_rm $testroot/repo beta)
109 git_commit $testroot/repo -m "deleting a file"
111 echo "D beta" > $testroot/stdout.expected
112 echo -n "Updated to commit " >> $testroot/stdout.expected
113 git_show_head $testroot/repo >> $testroot/stdout.expected
114 echo >> $testroot/stdout.expected
116 (cd $testroot/wt && got update > $testroot/stdout)
118 cmp -s $testroot/stdout.expected $testroot/stdout
119 ret="$?"
120 if [ "$ret" != "0" ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 test_done "$testroot" "$ret"
123 return 1
124 fi
126 if [ -e $testroot/wt/beta ]; then
127 echo "removed file beta still exists on disk" >&2
128 test_done "$testroot" "1"
129 return 1
130 fi
132 test_done "$testroot" "0"
135 function test_update_deletes_dir {
136 local testroot=`test_init update_deletes_dir`
138 got checkout $testroot/repo $testroot/wt > /dev/null
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 test_done "$testroot" "$ret"
142 return 1
143 fi
145 (cd $testroot/repo && git_rm $testroot/repo -r epsilon)
146 git_commit $testroot/repo -m "deleting a directory"
148 echo "D epsilon/zeta" > $testroot/stdout.expected
149 echo -n "Updated to commit " >> $testroot/stdout.expected
150 git_show_head $testroot/repo >> $testroot/stdout.expected
151 echo >> $testroot/stdout.expected
153 (cd $testroot/wt && got update > $testroot/stdout)
155 cmp -s $testroot/stdout.expected $testroot/stdout
156 ret="$?"
157 if [ "$ret" != "0" ]; then
158 diff -u $testroot/stdout.expected $testroot/stdout
159 test_done "$testroot" "$ret"
160 return 1
161 fi
163 if [ -e $testroot/wt/epsilon ]; then
164 echo "removed dir epsilon still exists on disk" >&2
165 test_done "$testroot" "1"
166 return 1
167 fi
169 test_done "$testroot" "0"
172 function test_update_deletes_dir_with_path_prefix {
173 local testroot=`test_init update_deletes_dir_with_path_prefix`
174 local first_rev=`git_show_head $testroot/repo`
176 mkdir $testroot/repo/epsilon/psi
177 echo mu > $testroot/repo/epsilon/psi/mu
178 (cd $testroot/repo && git add .)
179 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
181 # check out the epsilon/ sub-tree
182 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
183 ret="$?"
184 if [ "$ret" != "0" ]; then
185 test_done "$testroot" "$ret"
186 return 1
187 fi
189 # update back to first commit and expect psi/mu to be deleted
190 echo "D psi/mu" > $testroot/stdout.expected
191 echo "Updated to commit $first_rev" >> $testroot/stdout.expected
193 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
195 cmp -s $testroot/stdout.expected $testroot/stdout
196 ret="$?"
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
200 return 1
201 fi
203 if [ -e $testroot/wt/psi ]; then
204 echo "removed dir psi still exists on disk" >&2
205 test_done "$testroot" "1"
206 return 1
207 fi
209 test_done "$testroot" "0"
212 function test_update_deletes_dir_recursively {
213 local testroot=`test_init update_deletes_dir_recursively`
214 local first_rev=`git_show_head $testroot/repo`
216 mkdir $testroot/repo/epsilon/psi
217 echo mu > $testroot/repo/epsilon/psi/mu
218 mkdir $testroot/repo/epsilon/psi/chi
219 echo tau > $testroot/repo/epsilon/psi/chi/tau
220 (cd $testroot/repo && git add .)
221 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
223 # check out the epsilon/ sub-tree
224 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
225 ret="$?"
226 if [ "$ret" != "0" ]; then
227 test_done "$testroot" "$ret"
228 return 1
229 fi
231 # update back to first commit and expect psi/mu to be deleted
232 echo "D psi/chi/tau" > $testroot/stdout.expected
233 echo "D psi/mu" >> $testroot/stdout.expected
234 echo "Updated to commit $first_rev" >> $testroot/stdout.expected
236 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
238 cmp -s $testroot/stdout.expected $testroot/stdout
239 ret="$?"
240 if [ "$?" != "0" ]; then
241 diff -u $testroot/stdout.expected $testroot/stdout
242 test_done "$testroot" "$ret"
243 return 1
244 fi
246 if [ -e $testroot/wt/psi ]; then
247 echo "removed dir psi still exists on disk" >&2
248 test_done "$testroot" "1"
249 return 1
250 fi
252 test_done "$testroot" "0"
255 function test_update_sibling_dirs_with_common_prefix {
256 local testroot=`test_init update_sibling_dirs_with_common_prefix`
258 got checkout $testroot/repo $testroot/wt > /dev/null
259 ret="$?"
260 if [ "$ret" != "0" ]; then
261 test_done "$testroot" "$ret"
262 return 1
263 fi
265 mkdir $testroot/repo/epsilon2
266 echo mu > $testroot/repo/epsilon2/mu
267 (cd $testroot/repo && git add epsilon2/mu)
268 git_commit $testroot/repo -m "adding sibling of epsilon"
269 echo change > $testroot/repo/epsilon/zeta
270 git_commit $testroot/repo -m "changing epsilon/zeta"
272 echo "U epsilon/zeta" > $testroot/stdout.expected
273 echo "A epsilon2/mu" >> $testroot/stdout.expected
274 echo -n "Updated to commit " >> $testroot/stdout.expected
275 git_show_head $testroot/repo >> $testroot/stdout.expected
276 echo >> $testroot/stdout.expected
278 (cd $testroot/wt && got update > $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 test_done "$testroot" "$ret"
285 return 1
286 fi
288 echo "another change" > $testroot/repo/epsilon/zeta
289 git_commit $testroot/repo -m "changing epsilon/zeta again"
291 echo "U epsilon/zeta" > $testroot/stdout.expected
292 echo -n "Updated to commit " >> $testroot/stdout.expected
293 git_show_head $testroot/repo >> $testroot/stdout.expected
294 echo >> $testroot/stdout.expected
296 # Bug: This update used to do delete/add epsilon2/mu again:
297 # U epsilon/zeta
298 # D epsilon2/mu <--- not intended
299 # A epsilon2/mu <--- not intended
300 (cd $testroot/wt && got update > $testroot/stdout)
302 cmp -s $testroot/stdout.expected $testroot/stdout
303 ret="$?"
304 if [ "$ret" != "0" ]; then
305 diff -u $testroot/stdout.expected $testroot/stdout
306 test_done "$testroot" "$ret"
307 return 1
308 fi
310 cmp -s $testroot/stdout.expected $testroot/stdout
311 ret="$?"
312 if [ "$ret" != "0" ]; then
313 diff -u $testroot/stdout.expected $testroot/stdout
314 fi
315 test_done "$testroot" "$ret"
318 function test_update_dir_with_dot_sibling {
319 local testroot=`test_init update_dir_with_dot_sibling`
321 got checkout $testroot/repo $testroot/wt > /dev/null
322 ret="$ret"
323 if [ "$ret" != "0" ]; then
324 test_done "$testroot" "$ret"
325 return 1
326 fi
328 echo text > $testroot/repo/epsilon.txt
329 (cd $testroot/repo && git add epsilon.txt)
330 git_commit $testroot/repo -m "adding sibling of epsilon"
331 echo change > $testroot/repo/epsilon/zeta
332 git_commit $testroot/repo -m "changing epsilon/zeta"
334 echo "U epsilon/zeta" > $testroot/stdout.expected
335 echo "A epsilon.txt" >> $testroot/stdout.expected
336 echo -n "Updated to commit " >> $testroot/stdout.expected
337 git_show_head $testroot/repo >> $testroot/stdout.expected
338 echo >> $testroot/stdout.expected
340 (cd $testroot/wt && got update > $testroot/stdout)
342 cmp -s $testroot/stdout.expected $testroot/stdout
343 ret="$?"
344 if [ "$ret" != "0" ]; then
345 diff -u $testroot/stdout.expected $testroot/stdout
346 test_done "$testroot" "$ret"
347 return 1
348 fi
350 echo "another change" > $testroot/repo/epsilon/zeta
351 git_commit $testroot/repo -m "changing epsilon/zeta again"
353 echo "U epsilon/zeta" > $testroot/stdout.expected
354 echo -n "Updated to commit " >> $testroot/stdout.expected
355 git_show_head $testroot/repo >> $testroot/stdout.expected
356 echo >> $testroot/stdout.expected
358 (cd $testroot/wt && got update > $testroot/stdout)
360 cmp -s $testroot/stdout.expected $testroot/stdout
361 ret="$?"
362 if [ "$ret" != "0" ]; then
363 diff -u $testroot/stdout.expected $testroot/stdout
364 test_done "$testroot" "$ret"
365 return 1
366 fi
368 cmp -s $testroot/stdout.expected $testroot/stdout
369 ret="$?"
370 if [ "$ret" != "0" ]; then
371 diff -u $testroot/stdout.expected $testroot/stdout
372 fi
373 test_done "$testroot" "$ret"
376 function test_update_moves_files_upwards {
377 local testroot=`test_init update_moves_files_upwards`
379 mkdir $testroot/repo/epsilon/psi
380 echo mu > $testroot/repo/epsilon/psi/mu
381 mkdir $testroot/repo/epsilon/psi/chi
382 echo tau > $testroot/repo/epsilon/psi/chi/tau
383 (cd $testroot/repo && git add .)
384 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
386 got checkout $testroot/repo $testroot/wt > /dev/null
387 ret="$?"
388 if [ "$ret" != "0" ]; then
389 test_done "$testroot" "$ret"
390 return 1
391 fi
393 (cd $testroot/repo && git mv epsilon/psi/mu epsilon/mu)
394 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon/psi/tau)
395 git_commit $testroot/repo -m "moving files upwards"
397 echo "A epsilon/mu" > $testroot/stdout.expected
398 echo "D epsilon/psi/chi/tau" >> $testroot/stdout.expected
399 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
400 echo "A epsilon/psi/tau" >> $testroot/stdout.expected
401 echo -n "Updated to commit " >> $testroot/stdout.expected
402 git_show_head $testroot/repo >> $testroot/stdout.expected
403 echo >> $testroot/stdout.expected
405 (cd $testroot/wt && got update > $testroot/stdout)
407 cmp -s $testroot/stdout.expected $testroot/stdout
408 ret="$?"
409 if [ "$ret" != "0" ]; then
410 diff -u $testroot/stdout.expected $testroot/stdout
411 test_done "$testroot" "$ret"
412 return 1
413 fi
415 if [ -e $testroot/wt/epsilon/psi/chi ]; then
416 echo "removed dir epsilon/psi/chi still exists on disk" >&2
417 test_done "$testroot" "1"
418 return 1
419 fi
421 if [ -e $testroot/wt/epsilon/psi/mu ]; then
422 echo "removed file epsilon/psi/mu still exists on disk" >&2
423 test_done "$testroot" "1"
424 return 1
425 fi
427 test_done "$testroot" "0"
430 function test_update_moves_files_to_new_dir {
431 local testroot=`test_init update_moves_files_to_new_dir`
433 mkdir $testroot/repo/epsilon/psi
434 echo mu > $testroot/repo/epsilon/psi/mu
435 mkdir $testroot/repo/epsilon/psi/chi
436 echo tau > $testroot/repo/epsilon/psi/chi/tau
437 (cd $testroot/repo && git add .)
438 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
440 got checkout $testroot/repo $testroot/wt > /dev/null
441 ret="$?"
442 if [ "$ret" != "0" ]; then
443 test_done "$testroot" "$ret"
444 return 1
445 fi
447 mkdir -p $testroot/repo/epsilon-new/psi
448 (cd $testroot/repo && git mv epsilon/psi/mu epsilon-new/mu)
449 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon-new/psi/tau)
450 git_commit $testroot/repo -m "moving files upwards"
452 echo "D epsilon/psi/chi/tau" > $testroot/stdout.expected
453 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
454 echo "A epsilon-new/mu" >> $testroot/stdout.expected
455 echo "A epsilon-new/psi/tau" >> $testroot/stdout.expected
456 echo -n "Updated to commit " >> $testroot/stdout.expected
457 git_show_head $testroot/repo >> $testroot/stdout.expected
458 echo >> $testroot/stdout.expected
460 (cd $testroot/wt && got update > $testroot/stdout)
462 cmp -s $testroot/stdout.expected $testroot/stdout
463 ret="$?"
464 if [ "$ret" != "0" ]; then
465 diff -u $testroot/stdout.expected $testroot/stdout
466 test_done "$testroot" "$ret"
467 return 1
468 fi
470 if [ -e $testroot/wt/epsilon/psi/chi ]; then
471 echo "removed dir epsilon/psi/chi still exists on disk" >&2
472 test_done "$testroot" "1"
473 return 1
474 fi
476 if [ -e $testroot/wt/epsilon/psi/mu ]; then
477 echo "removed file epsilon/psi/mu still exists on disk" >&2
478 test_done "$testroot" "1"
479 return 1
480 fi
482 test_done "$testroot" "0"
485 function test_update_creates_missing_parent {
486 local testroot=`test_init update_creates_missing_parent 1`
488 touch $testroot/repo/Makefile
489 touch $testroot/repo/snake.6
490 touch $testroot/repo/snake.c
491 (cd $testroot/repo && git add .)
492 git_commit $testroot/repo -m "adding initial snake tree"
494 got checkout $testroot/repo $testroot/wt > /dev/null
495 ret="$?"
496 if [ "$ret" != "0" ]; then
497 test_done "$testroot" "$ret"
498 return 1
499 fi
501 mkdir -p $testroot/repo/snake
502 (cd $testroot/repo && git mv Makefile snake.6 snake.c snake)
503 touch $testroot/repo/snake/move.c
504 touch $testroot/repo/snake/pathnames.h
505 touch $testroot/repo/snake/snake.h
506 mkdir -p $testroot/repo/snscore
507 touch $testroot/repo/snscore/Makefile
508 touch $testroot/repo/snscore/snscore.c
509 (cd $testroot/repo && git add .)
510 git_commit $testroot/repo -m "restructuring snake tree"
512 echo "D Makefile" > $testroot/stdout.expected
513 echo "A snake/Makefile" >> $testroot/stdout.expected
514 echo "A snake/move.c" >> $testroot/stdout.expected
515 echo "A snake/pathnames.h" >> $testroot/stdout.expected
516 echo "A snake/snake.6" >> $testroot/stdout.expected
517 echo "A snake/snake.c" >> $testroot/stdout.expected
518 echo "A snake/snake.h" >> $testroot/stdout.expected
519 echo "D snake.6" >> $testroot/stdout.expected
520 echo "D snake.c" >> $testroot/stdout.expected
521 echo "A snscore/Makefile" >> $testroot/stdout.expected
522 echo "A snscore/snscore.c" >> $testroot/stdout.expected
523 echo -n "Updated to commit " >> $testroot/stdout.expected
524 git_show_head $testroot/repo >> $testroot/stdout.expected
525 echo >> $testroot/stdout.expected
527 (cd $testroot/wt && got update > $testroot/stdout)
529 cmp -s $testroot/stdout.expected $testroot/stdout
530 ret="$?"
531 if [ "$ret" != "0" ]; then
532 diff -u $testroot/stdout.expected $testroot/stdout
533 fi
534 test_done "$testroot" "$ret"
537 function test_update_creates_missing_parent_with_subdir {
538 local testroot=`test_init update_creates_missing_parent_with_subdir 1`
540 touch $testroot/repo/Makefile
541 touch $testroot/repo/snake.6
542 touch $testroot/repo/snake.c
543 (cd $testroot/repo && git add .)
544 git_commit $testroot/repo -m "adding initial snake tree"
546 got checkout $testroot/repo $testroot/wt > /dev/null
547 ret="$?"
548 if [ "$ret" != "0" ]; then
549 test_done "$testroot" "$ret"
550 return 1
551 fi
553 mkdir -p $testroot/repo/sss/snake
554 (cd $testroot/repo && git mv Makefile snake.6 snake.c sss/snake)
555 touch $testroot/repo/sss/snake/move.c
556 touch $testroot/repo/sss/snake/pathnames.h
557 touch $testroot/repo/sss/snake/snake.h
558 mkdir -p $testroot/repo/snscore
559 touch $testroot/repo/snscore/Makefile
560 touch $testroot/repo/snscore/snscore.c
561 (cd $testroot/repo && git add .)
562 git_commit $testroot/repo -m "restructuring snake tree"
564 echo "D Makefile" > $testroot/stdout.expected
565 echo "D snake.6" >> $testroot/stdout.expected
566 echo "D snake.c" >> $testroot/stdout.expected
567 echo "A snscore/Makefile" >> $testroot/stdout.expected
568 echo "A snscore/snscore.c" >> $testroot/stdout.expected
569 echo "A sss/snake/Makefile" >> $testroot/stdout.expected
570 echo "A sss/snake/move.c" >> $testroot/stdout.expected
571 echo "A sss/snake/pathnames.h" >> $testroot/stdout.expected
572 echo "A sss/snake/snake.6" >> $testroot/stdout.expected
573 echo "A sss/snake/snake.c" >> $testroot/stdout.expected
574 echo "A sss/snake/snake.h" >> $testroot/stdout.expected
575 echo -n "Updated to commit " >> $testroot/stdout.expected
576 git_show_head $testroot/repo >> $testroot/stdout.expected
577 echo >> $testroot/stdout.expected
579 (cd $testroot/wt && got update > $testroot/stdout)
581 cmp -s $testroot/stdout.expected $testroot/stdout
582 ret="$?"
583 if [ "$ret" != "0" ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 test_done "$testroot" "$ret"
586 return 1
587 fi
589 test_done "$testroot" "0"
592 function test_update_file_in_subsubdir {
593 local testroot=`test_init update_fle_in_subsubdir 1`
595 touch $testroot/repo/Makefile
596 mkdir -p $testroot/repo/altq
597 touch $testroot/repo/altq/if_altq.h
598 mkdir -p $testroot/repo/arch/alpha
599 touch $testroot/repo/arch/alpha/Makefile
600 (cd $testroot/repo && git add .)
601 git_commit $testroot/repo -m "adding initial tree"
603 got checkout $testroot/repo $testroot/wt > /dev/null
604 ret="$?"
605 if [ "$ret" != "0" ]; then
606 test_done "$testroot" "$ret"
607 return 1
608 fi
610 echo change > $testroot/repo/arch/alpha/Makefile
611 (cd $testroot/repo && git add .)
612 git_commit $testroot/repo -m "changed a file"
614 echo "U arch/alpha/Makefile" > $testroot/stdout.expected
615 echo -n "Updated to commit " >> $testroot/stdout.expected
616 git_show_head $testroot/repo >> $testroot/stdout.expected
617 echo >> $testroot/stdout.expected
619 (cd $testroot/wt && got update > $testroot/stdout)
621 cmp -s $testroot/stdout.expected $testroot/stdout
622 ret="$?"
623 if [ "$ret" != "0" ]; then
624 diff -u $testroot/stdout.expected $testroot/stdout
625 test_done "$testroot" "$ret"
626 return 1
627 fi
629 test_done "$testroot" "0"
632 function test_update_merges_file_edits {
633 local testroot=`test_init update_merges_file_edits`
635 echo "1" > $testroot/repo/numbers
636 echo "2" >> $testroot/repo/numbers
637 echo "3" >> $testroot/repo/numbers
638 echo "4" >> $testroot/repo/numbers
639 echo "5" >> $testroot/repo/numbers
640 echo "6" >> $testroot/repo/numbers
641 echo "7" >> $testroot/repo/numbers
642 echo "8" >> $testroot/repo/numbers
643 (cd $testroot/repo && git add numbers)
644 git_commit $testroot/repo -m "added numbers file"
645 local base_commit=`git_show_head $testroot/repo`
647 got checkout $testroot/repo $testroot/wt > /dev/null
648 ret="$?"
649 if [ "$ret" != "0" ]; then
650 test_done "$testroot" "$ret"
651 return 1
652 fi
654 echo "modified alpha" > $testroot/repo/alpha
655 echo "modified beta" > $testroot/repo/beta
656 sed -i 's/2/22/' $testroot/repo/numbers
657 git_commit $testroot/repo -m "modified 3 files"
659 echo "modified alpha, too" > $testroot/wt/alpha
660 touch $testroot/wt/beta
661 sed -i 's/7/77/' $testroot/wt/numbers
663 echo "C alpha" > $testroot/stdout.expected
664 echo "U beta" >> $testroot/stdout.expected
665 echo "G numbers" >> $testroot/stdout.expected
666 echo -n "Updated to commit " >> $testroot/stdout.expected
667 git_show_head $testroot/repo >> $testroot/stdout.expected
668 echo >> $testroot/stdout.expected
670 (cd $testroot/wt && got update > $testroot/stdout)
672 cmp -s $testroot/stdout.expected $testroot/stdout
673 ret="$?"
674 if [ "$ret" != "0" ]; then
675 diff -u $testroot/stdout.expected $testroot/stdout
676 test_done "$testroot" "$ret"
677 return 1
678 fi
680 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
681 git_show_head $testroot/repo >> $testroot/content.expected
682 echo >> $testroot/content.expected
683 echo "modified alpha" >> $testroot/content.expected
684 echo "||||||| 3-way merge base: commit $base_commit" \
685 >> $testroot/content.expected
686 echo "alpha" >> $testroot/content.expected
687 echo "=======" >> $testroot/content.expected
688 echo "modified alpha, too" >> $testroot/content.expected
689 echo '>>>>>>>' >> $testroot/content.expected
690 echo "modified beta" >> $testroot/content.expected
691 echo "1" >> $testroot/content.expected
692 echo "22" >> $testroot/content.expected
693 echo "3" >> $testroot/content.expected
694 echo "4" >> $testroot/content.expected
695 echo "5" >> $testroot/content.expected
696 echo "6" >> $testroot/content.expected
697 echo "77" >> $testroot/content.expected
698 echo "8" >> $testroot/content.expected
700 cat $testroot/wt/alpha > $testroot/content
701 cat $testroot/wt/beta >> $testroot/content
702 cat $testroot/wt/numbers >> $testroot/content
704 cmp -s $testroot/content.expected $testroot/content
705 ret="$?"
706 if [ "$ret" != "0" ]; then
707 diff -u $testroot/content.expected $testroot/content
708 fi
709 test_done "$testroot" "$ret"
712 function test_update_keeps_xbit {
713 local testroot=`test_init update_keeps_xbit 1`
715 touch $testroot/repo/xfile
716 chmod +x $testroot/repo/xfile
717 (cd $testroot/repo && git add .)
718 git_commit $testroot/repo -m "adding executable file"
720 got checkout $testroot/repo $testroot/wt > $testroot/stdout
721 ret="$?"
722 if [ "$ret" != "0" ]; then
723 test_done "$testroot" "$ret"
724 return 1
725 fi
727 echo foo > $testroot/repo/xfile
728 git_commit $testroot/repo -m "changed executable file"
730 echo "U xfile" > $testroot/stdout.expected
731 echo -n "Updated to commit " >> $testroot/stdout.expected
732 git_show_head $testroot/repo >> $testroot/stdout.expected
733 echo >> $testroot/stdout.expected
735 (cd $testroot/wt && got update > $testroot/stdout)
736 ret="$?"
737 if [ "$ret" != "0" ]; then
738 test_done "$testroot" "$ret"
739 return 1
740 fi
742 cmp -s $testroot/stdout.expected $testroot/stdout
743 ret="$?"
744 if [ "$ret" != "0" ]; then
745 diff -u $testroot/stdout.expected $testroot/stdout
746 test_done "$testroot" "$ret"
747 return 1
748 fi
750 ls -l $testroot/wt/xfile | grep -q '^-rwx'
751 ret="$?"
752 if [ "$ret" != "0" ]; then
753 echo "file is not executable" >&2
754 ls -l $testroot/wt/xfile >&2
755 fi
756 test_done "$testroot" "$ret"
759 function test_update_clears_xbit {
760 local testroot=`test_init update_clears_xbit 1`
762 touch $testroot/repo/xfile
763 chmod +x $testroot/repo/xfile
764 (cd $testroot/repo && git add .)
765 git_commit $testroot/repo -m "adding executable file"
767 got checkout $testroot/repo $testroot/wt > $testroot/stdout
768 ret="$?"
769 if [ "$ret" != "0" ]; then
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 ls -l $testroot/wt/xfile | grep -q '^-rwx'
775 ret="$?"
776 if [ "$ret" != "0" ]; then
777 echo "file is not executable" >&2
778 ls -l $testroot/wt/xfile >&2
779 test_done "$testroot" "$ret"
780 return 1
781 fi
783 # XXX git seems to require a file edit when flipping the x bit?
784 echo foo > $testroot/repo/xfile
785 chmod -x $testroot/repo/xfile
786 git_commit $testroot/repo -m "not an executable file anymore"
788 echo "U xfile" > $testroot/stdout.expected
789 echo -n "Updated to commit " >> $testroot/stdout.expected
790 git_show_head $testroot/repo >> $testroot/stdout.expected
791 echo >> $testroot/stdout.expected
793 (cd $testroot/wt && got update > $testroot/stdout)
794 ret="$?"
795 if [ "$ret" != "0" ]; then
796 test_done "$testroot" "$ret"
797 return 1
798 fi
800 cmp -s $testroot/stdout.expected $testroot/stdout
801 ret="$?"
802 if [ "$ret" != "0" ]; then
803 diff -u $testroot/stdout.expected $testroot/stdout
804 test_done "$testroot" "$ret"
805 return 1
806 fi
808 ls -l $testroot/wt/xfile | grep -q '^-rw-'
809 ret="$?"
810 if [ "$ret" != "0" ]; then
811 echo "file is unexpectedly executable" >&2
812 ls -l $testroot/wt/xfile >&2
813 fi
814 test_done "$testroot" "$ret"
817 function test_update_restores_missing_file {
818 local testroot=`test_init update_restores_missing_file`
820 got checkout $testroot/repo $testroot/wt > /dev/null
821 ret="$?"
822 if [ "$ret" != "0" ]; then
823 test_done "$testroot" "$ret"
824 return 1
825 fi
827 rm $testroot/wt/alpha
829 echo "! alpha" > $testroot/stdout.expected
830 echo -n "Updated to commit " >> $testroot/stdout.expected
831 git_show_head $testroot/repo >> $testroot/stdout.expected
832 echo >> $testroot/stdout.expected
833 (cd $testroot/wt && got update > $testroot/stdout)
835 cmp -s $testroot/stdout.expected $testroot/stdout
836 ret="$?"
837 if [ "$ret" != "0" ]; then
838 diff -u $testroot/stdout.expected $testroot/stdout
839 test_done "$testroot" "$ret"
840 return 1
841 fi
843 echo "alpha" > $testroot/content.expected
845 cat $testroot/wt/alpha > $testroot/content
847 cmp -s $testroot/content.expected $testroot/content
848 ret="$?"
849 if [ "$ret" != "0" ]; then
850 diff -u $testroot/content.expected $testroot/content
851 fi
852 test_done "$testroot" "$ret"
855 function test_update_conflict_wt_add_vs_repo_add {
856 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
858 got checkout $testroot/repo $testroot/wt > /dev/null
859 ret="$?"
860 if [ "$ret" != "0" ]; then
861 test_done "$testroot" "$ret"
862 return 1
863 fi
865 echo "new" > $testroot/repo/gamma/new
866 (cd $testroot/repo && git add .)
867 git_commit $testroot/repo -m "adding a new file"
869 echo "also new" > $testroot/wt/gamma/new
870 (cd $testroot/wt && got add gamma/new >/dev/null)
872 (cd $testroot/wt && got update > $testroot/stdout)
874 echo "C gamma/new" > $testroot/stdout.expected
875 echo -n "Updated to commit " >> $testroot/stdout.expected
876 git_show_head $testroot/repo >> $testroot/stdout.expected
877 echo >> $testroot/stdout.expected
878 cmp -s $testroot/stdout.expected $testroot/stdout
879 ret="$?"
880 if [ "$ret" != "0" ]; then
881 diff -u $testroot/stdout.expected $testroot/stdout
882 test_done "$testroot" "$ret"
883 return 1
884 fi
886 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
887 git_show_head $testroot/repo >> $testroot/content.expected
888 echo >> $testroot/content.expected
889 echo "new" >> $testroot/content.expected
890 echo "=======" >> $testroot/content.expected
891 echo "also new" >> $testroot/content.expected
892 echo '>>>>>>>' >> $testroot/content.expected
894 cat $testroot/wt/gamma/new > $testroot/content
896 cmp -s $testroot/content.expected $testroot/content
897 ret="$?"
898 if [ "$ret" != "0" ]; then
899 diff -u $testroot/content.expected $testroot/content
900 test_done "$testroot" "$ret"
901 return 1
902 fi
904 # resolve the conflict
905 echo "new and also new" > $testroot/wt/gamma/new
906 echo 'M gamma/new' > $testroot/stdout.expected
907 (cd $testroot/wt && got status > $testroot/stdout)
908 cmp -s $testroot/stdout.expected $testroot/stdout
909 ret="$?"
910 if [ "$ret" != "0" ]; then
911 diff -u $testroot/stdout.expected $testroot/stdout
912 fi
913 test_done "$testroot" "$ret"
916 function test_update_conflict_wt_edit_vs_repo_rm {
917 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
919 got checkout $testroot/repo $testroot/wt > /dev/null
920 ret="$?"
921 if [ "$ret" != "0" ]; then
922 test_done "$testroot" "$ret"
923 return 1
924 fi
926 (cd $testroot/repo && git rm -q beta)
927 git_commit $testroot/repo -m "removing a file"
929 echo "modified beta" > $testroot/wt/beta
931 (cd $testroot/wt && got update > $testroot/stdout)
933 echo "G beta" > $testroot/stdout.expected
934 echo -n "Updated to commit " >> $testroot/stdout.expected
935 git_show_head $testroot/repo >> $testroot/stdout.expected
936 echo >> $testroot/stdout.expected
937 cmp -s $testroot/stdout.expected $testroot/stdout
938 ret="$?"
939 if [ "$ret" != "0" ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 echo "modified beta" > $testroot/content.expected
947 cat $testroot/wt/beta > $testroot/content
949 cmp -s $testroot/content.expected $testroot/content
950 ret="$?"
951 if [ "$ret" != "0" ]; then
952 diff -u $testroot/content.expected $testroot/content
953 test_done "$testroot" "$ret"
954 return 1
955 fi
957 # beta is now an added file... we don't flag tree conflicts yet
958 echo 'A beta' > $testroot/stdout.expected
959 (cd $testroot/wt && got status > $testroot/stdout)
960 cmp -s $testroot/stdout.expected $testroot/stdout
961 ret="$?"
962 if [ "$ret" != "0" ]; then
963 diff -u $testroot/stdout.expected $testroot/stdout
964 fi
965 test_done "$testroot" "$ret"
968 function test_update_conflict_wt_rm_vs_repo_edit {
969 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
971 got checkout $testroot/repo $testroot/wt > /dev/null
972 ret="$?"
973 if [ "$ret" != "0" ]; then
974 test_done "$testroot" "$ret"
975 return 1
976 fi
978 echo "modified beta" > $testroot/repo/beta
979 git_commit $testroot/repo -m "modified a file"
981 (cd $testroot/wt && got rm beta > /dev/null)
983 (cd $testroot/wt && got update > $testroot/stdout)
985 echo "G beta" > $testroot/stdout.expected
986 echo -n "Updated to commit " >> $testroot/stdout.expected
987 git_show_head $testroot/repo >> $testroot/stdout.expected
988 echo >> $testroot/stdout.expected
989 cmp -s $testroot/stdout.expected $testroot/stdout
990 ret="$?"
991 if [ "$ret" != "0" ]; then
992 diff -u $testroot/stdout.expected $testroot/stdout
993 test_done "$testroot" "$ret"
994 return 1
995 fi
997 # beta remains a deleted file... we don't flag tree conflicts yet
998 echo 'D beta' > $testroot/stdout.expected
999 (cd $testroot/wt && got status > $testroot/stdout)
1000 cmp -s $testroot/stdout.expected $testroot/stdout
1001 ret="$?"
1002 if [ "$ret" != "0" ]; then
1003 diff -u $testroot/stdout.expected $testroot/stdout
1004 test_done "$testroot" "$ret"
1005 return 1
1008 # 'got diff' should show post-update contents of beta being deleted
1009 local head_rev=`git_show_head $testroot/repo`
1010 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
1011 echo -n 'blob - ' >> $testroot/stdout.expected
1012 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1013 >> $testroot/stdout.expected
1014 echo 'file + /dev/null' >> $testroot/stdout.expected
1015 echo '--- beta' >> $testroot/stdout.expected
1016 echo '+++ beta' >> $testroot/stdout.expected
1017 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1018 echo '-modified beta' >> $testroot/stdout.expected
1020 (cd $testroot/wt && got diff > $testroot/stdout)
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1022 ret="$?"
1023 if [ "$ret" != "0" ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1029 function test_update_conflict_wt_rm_vs_repo_rm {
1030 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1032 got checkout $testroot/repo $testroot/wt > /dev/null
1033 ret="$?"
1034 if [ "$ret" != "0" ]; then
1035 test_done "$testroot" "$ret"
1036 return 1
1039 (cd $testroot/repo && git rm -q beta)
1040 git_commit $testroot/repo -m "removing a file"
1042 (cd $testroot/wt && got rm beta > /dev/null)
1044 (cd $testroot/wt && got update > $testroot/stdout)
1046 echo "D beta" > $testroot/stdout.expected
1047 echo -n "Updated to commit " >> $testroot/stdout.expected
1048 git_show_head $testroot/repo >> $testroot/stdout.expected
1049 echo >> $testroot/stdout.expected
1050 cmp -s $testroot/stdout.expected $testroot/stdout
1051 ret="$?"
1052 if [ "$ret" != "0" ]; then
1053 diff -u $testroot/stdout.expected $testroot/stdout
1054 test_done "$testroot" "$ret"
1055 return 1
1058 # beta is now gone... we don't flag tree conflicts yet
1059 echo "N beta" > $testroot/stdout.expected
1060 echo -n > $testroot/stderr.expected
1061 (cd $testroot/wt && got status beta > $testroot/stdout \
1062 2> $testroot/stderr)
1063 cmp -s $testroot/stdout.expected $testroot/stdout
1064 ret="$?"
1065 if [ "$ret" != "0" ]; then
1066 diff -u $testroot/stdout.expected $testroot/stdout
1067 test_done "$testroot" "$ret"
1068 return 1
1070 cmp -s $testroot/stderr.expected $testroot/stderr
1071 ret="$?"
1072 if [ "$ret" != "0" ]; then
1073 diff -u $testroot/stderr.expected $testroot/stderr
1074 test_done "$testroot" "$ret"
1075 return 1
1078 if [ -e $testroot/wt/beta ]; then
1079 echo "removed file beta still exists on disk" >&2
1080 test_done "$testroot" "1"
1081 return 1
1084 test_done "$testroot" "0"
1087 function test_update_partial {
1088 local testroot=`test_init update_partial`
1090 got checkout $testroot/repo $testroot/wt > /dev/null
1091 ret="$?"
1092 if [ "$ret" != "0" ]; then
1093 test_done "$testroot" "$ret"
1094 return 1
1097 echo "modified alpha" > $testroot/repo/alpha
1098 echo "modified beta" > $testroot/repo/beta
1099 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1100 git_commit $testroot/repo -m "modified two files"
1102 echo "U alpha" > $testroot/stdout.expected
1103 echo "U beta" >> $testroot/stdout.expected
1104 echo -n "Updated to commit " >> $testroot/stdout.expected
1105 git_show_head $testroot/repo >> $testroot/stdout.expected
1106 echo >> $testroot/stdout.expected
1108 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1110 cmp -s $testroot/stdout.expected $testroot/stdout
1111 ret="$?"
1112 if [ "$ret" != "0" ]; then
1113 diff -u $testroot/stdout.expected $testroot/stdout
1114 test_done "$testroot" "$ret"
1115 return 1
1118 echo "modified alpha" > $testroot/content.expected
1119 echo "modified beta" >> $testroot/content.expected
1121 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1122 cmp -s $testroot/content.expected $testroot/content
1123 ret="$?"
1124 if [ "$ret" != "0" ]; then
1125 diff -u $testroot/content.expected $testroot/content
1126 test_done "$testroot" "$ret"
1127 return 1
1130 echo "U epsilon/zeta" > $testroot/stdout.expected
1131 echo -n "Updated to commit " >> $testroot/stdout.expected
1132 git_show_head $testroot/repo >> $testroot/stdout.expected
1133 echo >> $testroot/stdout.expected
1135 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1137 cmp -s $testroot/stdout.expected $testroot/stdout
1138 ret="$?"
1139 if [ "$ret" != "0" ]; then
1140 diff -u $testroot/stdout.expected $testroot/stdout
1141 test_done "$testroot" "$ret"
1142 return 1
1145 echo "modified epsilon/zeta" > $testroot/content.expected
1146 cat $testroot/wt/epsilon/zeta > $testroot/content
1148 cmp -s $testroot/content.expected $testroot/content
1149 ret="$?"
1150 if [ "$ret" != "0" ]; then
1151 diff -u $testroot/content.expected $testroot/content
1152 test_done "$testroot" "$ret"
1153 return 1
1156 test_done "$testroot" "$ret"
1159 function test_update_partial_add {
1160 local testroot=`test_init update_partial_add`
1162 got checkout $testroot/repo $testroot/wt > /dev/null
1163 ret="$?"
1164 if [ "$ret" != "0" ]; then
1165 test_done "$testroot" "$ret"
1166 return 1
1169 echo "new" > $testroot/repo/new
1170 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1171 (cd $testroot/repo && git add .)
1172 git_commit $testroot/repo -m "added two files"
1174 echo "A new" > $testroot/stdout.expected
1175 echo "A epsilon/new2" >> $testroot/stdout.expected
1176 echo -n "Updated to commit " >> $testroot/stdout.expected
1177 git_show_head $testroot/repo >> $testroot/stdout.expected
1178 echo >> $testroot/stdout.expected
1180 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1182 cmp -s $testroot/stdout.expected $testroot/stdout
1183 ret="$?"
1184 if [ "$ret" != "0" ]; then
1185 diff -u $testroot/stdout.expected $testroot/stdout
1186 test_done "$testroot" "$ret"
1187 return 1
1190 echo "new" > $testroot/content.expected
1191 echo "epsilon/new2" >> $testroot/content.expected
1193 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1195 cmp -s $testroot/content.expected $testroot/content
1196 ret="$?"
1197 if [ "$ret" != "0" ]; then
1198 diff -u $testroot/content.expected $testroot/content
1200 test_done "$testroot" "$ret"
1203 function test_update_partial_rm {
1204 local testroot=`test_init update_partial_rm`
1206 got checkout $testroot/repo $testroot/wt > /dev/null
1207 ret="$?"
1208 if [ "$ret" != "0" ]; then
1209 test_done "$testroot" "$ret"
1210 return 1
1213 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1214 git_commit $testroot/repo -m "removed two files"
1216 echo "got: no such entry found in tree" \
1217 > $testroot/stderr.expected
1219 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1220 ret="$?"
1221 if [ "$ret" == "0" ]; then
1222 echo "update succeeded unexpectedly" >&2
1223 test_done "$testroot" "1"
1224 return 1
1227 cmp -s $testroot/stderr.expected $testroot/stderr
1228 ret="$?"
1229 if [ "$ret" != "0" ]; then
1230 diff -u $testroot/stderr.expected $testroot/stderr
1231 test_done "$testroot" "$ret"
1232 return 1
1234 test_done "$testroot" "$ret"
1237 function test_update_partial_dir {
1238 local testroot=`test_init update_partial_dir`
1240 got checkout $testroot/repo $testroot/wt > /dev/null
1241 ret="$?"
1242 if [ "$ret" != "0" ]; then
1243 test_done "$testroot" "$ret"
1244 return 1
1247 echo "modified alpha" > $testroot/repo/alpha
1248 echo "modified beta" > $testroot/repo/beta
1249 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1250 git_commit $testroot/repo -m "modified two files"
1252 echo "U epsilon/zeta" > $testroot/stdout.expected
1253 echo -n "Updated to commit " >> $testroot/stdout.expected
1254 git_show_head $testroot/repo >> $testroot/stdout.expected
1255 echo >> $testroot/stdout.expected
1257 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1259 cmp -s $testroot/stdout.expected $testroot/stdout
1260 ret="$?"
1261 if [ "$ret" != "0" ]; then
1262 diff -u $testroot/stdout.expected $testroot/stdout
1263 test_done "$testroot" "$ret"
1264 return 1
1267 echo "modified epsilon/zeta" > $testroot/content.expected
1268 cat $testroot/wt/epsilon/zeta > $testroot/content
1270 cmp -s $testroot/content.expected $testroot/content
1271 ret="$?"
1272 if [ "$ret" != "0" ]; then
1273 diff -u $testroot/content.expected $testroot/content
1274 test_done "$testroot" "$ret"
1275 return 1
1277 test_done "$testroot" "$ret"
1281 function test_update_moved_branch_ref {
1282 local testroot=`test_init update_moved_branch_ref`
1284 git clone -q --mirror $testroot/repo $testroot/repo2
1286 echo "modified alpha with git" > $testroot/repo/alpha
1287 git_commit $testroot/repo -m "modified alpha with git"
1289 got checkout $testroot/repo2 $testroot/wt > /dev/null
1290 ret="$?"
1291 if [ "$ret" != "0" ]; then
1292 test_done "$testroot" "$ret"
1293 return 1
1296 echo "modified alpha with got" > $testroot/wt/alpha
1297 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1299 # + xxxxxxx...yyyyyyy master -> master (forced update)
1300 (cd $testroot/repo2 && git fetch -q --all)
1302 echo -n > $testroot/stdout.expected
1303 echo -n "got: work tree's head reference now points to a different " \
1304 > $testroot/stderr.expected
1305 echo "branch; new head reference and/or update -b required" \
1306 >> $testroot/stderr.expected
1308 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1310 cmp -s $testroot/stdout.expected $testroot/stdout
1311 ret="$?"
1312 if [ "$ret" != "0" ]; then
1313 diff -u $testroot/stdout.expected $testroot/stdout
1314 test_done "$testroot" "$ret"
1315 return 1
1318 cmp -s $testroot/stderr.expected $testroot/stderr
1319 ret="$?"
1320 if [ "$ret" != "0" ]; then
1321 diff -u $testroot/stderr.expected $testroot/stderr
1323 test_done "$testroot" "$ret"
1326 function test_update_to_another_branch {
1327 local testroot=`test_init update_to_another_branch`
1328 local base_commit=`git_show_head $testroot/repo`
1330 got checkout $testroot/repo $testroot/wt > /dev/null
1331 ret="$?"
1332 if [ "$ret" != "0" ]; then
1333 test_done "$testroot" "$ret"
1334 return 1
1337 echo 'refs/heads/master'> $testroot/head-ref.expected
1338 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1339 ret="$?"
1340 if [ "$ret" != "0" ]; then
1341 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1342 test_done "$testroot" "$ret"
1343 return 1
1346 (cd $testroot/repo && git checkout -q -b newbranch)
1347 echo "modified alpha on new branch" > $testroot/repo/alpha
1348 git_commit $testroot/repo -m "modified alpha on new branch"
1350 echo "modified alpha in work tree" > $testroot/wt/alpha
1352 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1353 echo "C alpha" >> $testroot/stdout.expected
1354 echo -n "Updated to commit " >> $testroot/stdout.expected
1355 git_show_head $testroot/repo >> $testroot/stdout.expected
1356 echo >> $testroot/stdout.expected
1358 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1360 cmp -s $testroot/stdout.expected $testroot/stdout
1361 ret="$?"
1362 if [ "$ret" != "0" ]; then
1363 diff -u $testroot/stdout.expected $testroot/stdout
1364 test_done "$testroot" "$ret"
1365 return 1
1368 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
1369 git_show_head $testroot/repo >> $testroot/content.expected
1370 echo >> $testroot/content.expected
1371 echo "modified alpha on new branch" >> $testroot/content.expected
1372 echo "||||||| 3-way merge base: commit $base_commit" \
1373 >> $testroot/content.expected
1374 echo "alpha" >> $testroot/content.expected
1375 echo "=======" >> $testroot/content.expected
1376 echo "modified alpha in work tree" >> $testroot/content.expected
1377 echo '>>>>>>>' >> $testroot/content.expected
1379 cat $testroot/wt/alpha > $testroot/content
1381 cmp -s $testroot/content.expected $testroot/content
1382 ret="$?"
1383 if [ "$ret" != "0" ]; then
1384 diff -u $testroot/content.expected $testroot/content
1385 test_done "$testroot" "$ret"
1386 return 1
1389 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1390 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1391 ret="$?"
1392 if [ "$ret" != "0" ]; then
1393 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1394 test_done "$testroot" "$ret"
1395 return 1
1398 test_done "$testroot" "$ret"
1401 function test_update_to_commit_on_wrong_branch {
1402 local testroot=`test_init update_to_commit_on_wrong_branch`
1404 got checkout $testroot/repo $testroot/wt > /dev/null
1405 ret="$?"
1406 if [ "$ret" != "0" ]; then
1407 test_done "$testroot" "$ret"
1408 return 1
1411 (cd $testroot/repo && git checkout -q -b newbranch)
1412 echo "modified alpha on new branch" > $testroot/repo/alpha
1413 git_commit $testroot/repo -m "modified alpha on new branch"
1415 echo -n "" > $testroot/stdout.expected
1416 echo "got: target commit is on a different branch" \
1417 > $testroot/stderr.expected
1419 local head_rev=`git_show_head $testroot/repo`
1420 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1421 2> $testroot/stderr)
1423 cmp -s $testroot/stdout.expected $testroot/stdout
1424 ret="$?"
1425 if [ "$ret" != "0" ]; then
1426 diff -u $testroot/stdout.expected $testroot/stdout
1427 test_done "$testroot" "$ret"
1428 return 1
1431 cmp -s $testroot/stderr.expected $testroot/stderr
1432 ret="$?"
1433 if [ "$ret" != "0" ]; then
1434 diff -u $testroot/stderr.expected $testroot/stderr
1435 test_done "$testroot" "$ret"
1436 return 1
1439 test_done "$testroot" "$ret"
1442 function test_update_bumps_base_commit_id {
1443 local testroot=`test_init update_bumps_base_commit_id`
1445 echo "psi" > $testroot/repo/epsilon/psi
1446 (cd $testroot/repo && git add .)
1447 git_commit $testroot/repo -m "adding another file"
1449 got checkout $testroot/repo $testroot/wt > /dev/null
1450 ret="$?"
1451 if [ "$ret" != "0" ]; then
1452 test_done "$testroot" "$ret"
1453 return 1
1456 echo "modified psi" > $testroot/wt/epsilon/psi
1457 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1459 local head_rev=`git_show_head $testroot/repo`
1460 echo "M epsilon/psi" > $testroot/stdout.expected
1461 echo "Created commit $head_rev" >> $testroot/stdout.expected
1462 cmp -s $testroot/stdout.expected $testroot/stdout
1463 ret="$?"
1464 if [ "$ret" != "0" ]; then
1465 diff -u $testroot/stdout.expected $testroot/stdout
1466 test_done "$testroot" "$ret"
1467 return 1
1470 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1471 (cd $testroot/repo && git add .)
1472 git_commit $testroot/repo -m "changing zeta with git"
1474 echo "modified zeta" > $testroot/wt/epsilon/zeta
1475 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1476 2> $testroot/stderr)
1478 echo -n "" > $testroot/stdout.expected
1479 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1480 cmp -s $testroot/stderr.expected $testroot/stderr
1481 ret="$?"
1482 if [ "$ret" != "0" ]; then
1483 diff -u $testroot/stderr.expected $testroot/stderr
1484 test_done "$testroot" "$ret"
1485 return 1
1488 (cd $testroot/wt && got update > $testroot/stdout)
1490 echo "U epsilon/psi" > $testroot/stdout.expected
1491 echo "C epsilon/zeta" >> $testroot/stdout.expected
1492 echo -n "Updated to commit " >> $testroot/stdout.expected
1493 git_show_head $testroot/repo >> $testroot/stdout.expected
1494 echo >> $testroot/stdout.expected
1495 cmp -s $testroot/stdout.expected $testroot/stdout
1496 ret="$?"
1497 if [ "$ret" != "0" ]; then
1498 diff -u $testroot/stdout.expected $testroot/stdout
1499 test_done "$testroot" "$ret"
1500 return 1
1503 # resolve conflict
1504 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1506 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1508 local head_rev=`git_show_head $testroot/repo`
1509 echo "M epsilon/zeta" > $testroot/stdout.expected
1510 echo "Created commit $head_rev" >> $testroot/stdout.expected
1511 cmp -s $testroot/stdout.expected $testroot/stdout
1512 ret="$?"
1513 if [ "$ret" != "0" ]; then
1514 diff -u $testroot/stdout.expected $testroot/stdout
1515 test_done "$testroot" "$ret"
1516 return 1
1519 test_done "$testroot" "$ret"
1522 function test_update_tag {
1523 local testroot=`test_init update_tag`
1524 local tag="1.0.0"
1526 got checkout $testroot/repo $testroot/wt > /dev/null
1527 ret="$?"
1528 if [ "$ret" != "0" ]; then
1529 test_done "$testroot" "$ret"
1530 return 1
1533 echo "modified alpha" > $testroot/repo/alpha
1534 git_commit $testroot/repo -m "modified alpha"
1535 (cd $testroot/repo && git tag -m "test" -a $tag)
1537 echo "U alpha" > $testroot/stdout.expected
1538 echo -n "Updated to commit " >> $testroot/stdout.expected
1539 git_show_head $testroot/repo >> $testroot/stdout.expected
1540 echo >> $testroot/stdout.expected
1542 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1544 cmp -s $testroot/stdout.expected $testroot/stdout
1545 ret="$?"
1546 if [ "$ret" != "0" ]; then
1547 diff -u $testroot/stdout.expected $testroot/stdout
1548 test_done "$testroot" "$ret"
1549 return 1
1552 echo "modified alpha" > $testroot/content.expected
1553 cat $testroot/wt/alpha > $testroot/content
1555 cmp -s $testroot/content.expected $testroot/content
1556 ret="$?"
1557 if [ "$ret" != "0" ]; then
1558 diff -u $testroot/content.expected $testroot/content
1560 test_done "$testroot" "$ret"
1563 function test_update_toggles_xbit {
1564 local testroot=`test_init update_toggles_xbit 1`
1566 touch $testroot/repo/xfile
1567 chmod +x $testroot/repo/xfile
1568 (cd $testroot/repo && git add .)
1569 git_commit $testroot/repo -m "adding executable file"
1570 local commit_id1=`git_show_head $testroot/repo`
1572 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1573 ret="$?"
1574 if [ "$ret" != "0" ]; then
1575 test_done "$testroot" "$ret"
1576 return 1
1579 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1580 ret="$?"
1581 if [ "$ret" != "0" ]; then
1582 echo "file is not executable" >&2
1583 ls -l $testroot/wt/xfile >&2
1584 test_done "$testroot" "$ret"
1585 return 1
1588 chmod -x $testroot/wt/xfile
1589 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1590 local commit_id2=`git_show_head $testroot/repo`
1592 echo "U xfile" > $testroot/stdout.expected
1593 echo -n "Updated to commit " >> $testroot/stdout.expected
1594 git_show_head $testroot/repo >> $testroot/stdout.expected
1595 echo >> $testroot/stdout.expected
1597 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1598 ret="$?"
1599 if [ "$ret" != "0" ]; then
1600 test_done "$testroot" "$ret"
1601 return 1
1604 echo "U xfile" > $testroot/stdout.expected
1605 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
1606 cmp -s $testroot/stdout.expected $testroot/stdout
1607 ret="$?"
1608 if [ "$ret" != "0" ]; then
1609 diff -u $testroot/stdout.expected $testroot/stdout
1610 test_done "$testroot" "$ret"
1611 return 1
1615 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1616 ret="$?"
1617 if [ "$ret" != "0" ]; then
1618 echo "file is not executable" >&2
1619 ls -l $testroot/wt/xfile >&2
1620 test_done "$testroot" "$ret"
1621 return 1
1624 (cd $testroot/wt && got update > $testroot/stdout)
1625 ret="$?"
1626 if [ "$ret" != "0" ]; then
1627 test_done "$testroot" "$ret"
1628 return 1
1631 echo "U xfile" > $testroot/stdout.expected
1632 echo "Updated to commit $commit_id2" >> $testroot/stdout.expected
1633 cmp -s $testroot/stdout.expected $testroot/stdout
1634 ret="$?"
1635 if [ "$ret" != "0" ]; then
1636 diff -u $testroot/stdout.expected $testroot/stdout
1637 test_done "$testroot" "$ret"
1638 return 1
1641 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1642 ret="$?"
1643 if [ "$ret" != "0" ]; then
1644 echo "file is unexpectedly executable" >&2
1645 ls -l $testroot/wt/xfile >&2
1647 test_done "$testroot" "$ret"
1650 run_test test_update_basic
1651 run_test test_update_adds_file
1652 run_test test_update_deletes_file
1653 run_test test_update_deletes_dir
1654 run_test test_update_deletes_dir_with_path_prefix
1655 run_test test_update_deletes_dir_recursively
1656 run_test test_update_sibling_dirs_with_common_prefix
1657 run_test test_update_dir_with_dot_sibling
1658 run_test test_update_moves_files_upwards
1659 run_test test_update_moves_files_to_new_dir
1660 run_test test_update_creates_missing_parent
1661 run_test test_update_creates_missing_parent_with_subdir
1662 run_test test_update_file_in_subsubdir
1663 run_test test_update_merges_file_edits
1664 run_test test_update_keeps_xbit
1665 run_test test_update_clears_xbit
1666 run_test test_update_restores_missing_file
1667 run_test test_update_conflict_wt_add_vs_repo_add
1668 run_test test_update_conflict_wt_edit_vs_repo_rm
1669 run_test test_update_conflict_wt_rm_vs_repo_edit
1670 run_test test_update_conflict_wt_rm_vs_repo_rm
1671 run_test test_update_partial
1672 run_test test_update_partial_add
1673 run_test test_update_partial_rm
1674 run_test test_update_partial_dir
1675 run_test test_update_moved_branch_ref
1676 run_test test_update_to_another_branch
1677 run_test test_update_to_commit_on_wrong_branch
1678 run_test test_update_bumps_base_commit_id
1679 run_test test_update_tag
1680 run_test test_update_toggles_xbit