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"
646 got checkout $testroot/repo $testroot/wt > /dev/null
647 ret="$?"
648 if [ "$ret" != "0" ]; then
649 test_done "$testroot" "$ret"
650 return 1
651 fi
653 echo "modified alpha" > $testroot/repo/alpha
654 echo "modified beta" > $testroot/repo/beta
655 sed -i 's/2/22/' $testroot/repo/numbers
656 git_commit $testroot/repo -m "modified 3 files"
658 echo "modified alpha, too" > $testroot/wt/alpha
659 touch $testroot/wt/beta
660 sed -i 's/7/77/' $testroot/wt/numbers
662 echo "C alpha" > $testroot/stdout.expected
663 echo "U beta" >> $testroot/stdout.expected
664 echo "G numbers" >> $testroot/stdout.expected
665 echo -n "Updated to commit " >> $testroot/stdout.expected
666 git_show_head $testroot/repo >> $testroot/stdout.expected
667 echo >> $testroot/stdout.expected
669 (cd $testroot/wt && got update > $testroot/stdout)
671 cmp -s $testroot/stdout.expected $testroot/stdout
672 ret="$?"
673 if [ "$ret" != "0" ]; then
674 diff -u $testroot/stdout.expected $testroot/stdout
675 test_done "$testroot" "$ret"
676 return 1
677 fi
679 echo -n "<<<<<<< commit " > $testroot/content.expected
680 git_show_head $testroot/repo >> $testroot/content.expected
681 echo >> $testroot/content.expected
682 echo "modified alpha" >> $testroot/content.expected
683 echo "|||||||" >> $testroot/content.expected
684 echo "alpha" >> $testroot/content.expected
685 echo "=======" >> $testroot/content.expected
686 echo "modified alpha, too" >> $testroot/content.expected
687 echo '>>>>>>> alpha' >> $testroot/content.expected
688 echo "modified beta" >> $testroot/content.expected
689 echo "1" >> $testroot/content.expected
690 echo "22" >> $testroot/content.expected
691 echo "3" >> $testroot/content.expected
692 echo "4" >> $testroot/content.expected
693 echo "5" >> $testroot/content.expected
694 echo "6" >> $testroot/content.expected
695 echo "77" >> $testroot/content.expected
696 echo "8" >> $testroot/content.expected
698 cat $testroot/wt/alpha > $testroot/content
699 cat $testroot/wt/beta >> $testroot/content
700 cat $testroot/wt/numbers >> $testroot/content
702 cmp -s $testroot/content.expected $testroot/content
703 ret="$?"
704 if [ "$ret" != "0" ]; then
705 diff -u $testroot/content.expected $testroot/content
706 fi
707 test_done "$testroot" "$ret"
710 function test_update_keeps_xbit {
711 local testroot=`test_init update_keeps_xbit 1`
713 touch $testroot/repo/xfile
714 chmod +x $testroot/repo/xfile
715 (cd $testroot/repo && git add .)
716 git_commit $testroot/repo -m "adding executable file"
718 got checkout $testroot/repo $testroot/wt > $testroot/stdout
719 ret="$?"
720 if [ "$ret" != "0" ]; then
721 test_done "$testroot" "$ret"
722 return 1
723 fi
725 echo foo > $testroot/repo/xfile
726 git_commit $testroot/repo -m "changed executable file"
728 echo "U xfile" > $testroot/stdout.expected
729 echo -n "Updated to commit " >> $testroot/stdout.expected
730 git_show_head $testroot/repo >> $testroot/stdout.expected
731 echo >> $testroot/stdout.expected
733 (cd $testroot/wt && got update > $testroot/stdout)
734 ret="$?"
735 if [ "$ret" != "0" ]; then
736 test_done "$testroot" "$ret"
737 return 1
738 fi
740 cmp -s $testroot/stdout.expected $testroot/stdout
741 ret="$?"
742 if [ "$ret" != "0" ]; then
743 diff -u $testroot/stdout.expected $testroot/stdout
744 test_done "$testroot" "$ret"
745 return 1
746 fi
748 ls -l $testroot/wt/xfile | grep -q '^-rwx'
749 ret="$?"
750 if [ "$ret" != "0" ]; then
751 echo "file is not executable" >&2
752 ls -l $testroot/wt/xfile >&2
753 fi
754 test_done "$testroot" "$ret"
757 function test_update_clears_xbit {
758 local testroot=`test_init update_clears_xbit 1`
760 touch $testroot/repo/xfile
761 chmod +x $testroot/repo/xfile
762 (cd $testroot/repo && git add .)
763 git_commit $testroot/repo -m "adding executable file"
765 got checkout $testroot/repo $testroot/wt > $testroot/stdout
766 ret="$?"
767 if [ "$ret" != "0" ]; then
768 test_done "$testroot" "$ret"
769 return 1
770 fi
772 ls -l $testroot/wt/xfile | grep -q '^-rwx'
773 ret="$?"
774 if [ "$ret" != "0" ]; then
775 echo "file is not executable" >&2
776 ls -l $testroot/wt/xfile >&2
777 test_done "$testroot" "$ret"
778 return 1
779 fi
781 # XXX git seems to require a file edit when flipping the x bit?
782 echo foo > $testroot/repo/xfile
783 chmod -x $testroot/repo/xfile
784 git_commit $testroot/repo -m "not an executable file anymore"
786 echo "U xfile" > $testroot/stdout.expected
787 echo -n "Updated to commit " >> $testroot/stdout.expected
788 git_show_head $testroot/repo >> $testroot/stdout.expected
789 echo >> $testroot/stdout.expected
791 (cd $testroot/wt && got update > $testroot/stdout)
792 ret="$?"
793 if [ "$ret" != "0" ]; then
794 test_done "$testroot" "$ret"
795 return 1
796 fi
798 cmp -s $testroot/stdout.expected $testroot/stdout
799 ret="$?"
800 if [ "$ret" != "0" ]; then
801 diff -u $testroot/stdout.expected $testroot/stdout
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 ls -l $testroot/wt/xfile | grep -q '^-rw-'
807 ret="$?"
808 if [ "$ret" != "0" ]; then
809 echo "file is unexpectedly executable" >&2
810 ls -l $testroot/wt/xfile >&2
811 fi
812 test_done "$testroot" "$ret"
815 function test_update_restores_missing_file {
816 local testroot=`test_init update_restores_missing_file`
818 got checkout $testroot/repo $testroot/wt > /dev/null
819 ret="$?"
820 if [ "$ret" != "0" ]; then
821 test_done "$testroot" "$ret"
822 return 1
823 fi
825 rm $testroot/wt/alpha
827 echo "! alpha" > $testroot/stdout.expected
828 echo -n "Updated to commit " >> $testroot/stdout.expected
829 git_show_head $testroot/repo >> $testroot/stdout.expected
830 echo >> $testroot/stdout.expected
831 (cd $testroot/wt && got update > $testroot/stdout)
833 cmp -s $testroot/stdout.expected $testroot/stdout
834 ret="$?"
835 if [ "$ret" != "0" ]; then
836 diff -u $testroot/stdout.expected $testroot/stdout
837 test_done "$testroot" "$ret"
838 return 1
839 fi
841 echo "alpha" > $testroot/content.expected
843 cat $testroot/wt/alpha > $testroot/content
845 cmp -s $testroot/content.expected $testroot/content
846 ret="$?"
847 if [ "$ret" != "0" ]; then
848 diff -u $testroot/content.expected $testroot/content
849 fi
850 test_done "$testroot" "$ret"
853 function test_update_conflict_wt_add_vs_repo_add {
854 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
856 got checkout $testroot/repo $testroot/wt > /dev/null
857 ret="$?"
858 if [ "$ret" != "0" ]; then
859 test_done "$testroot" "$ret"
860 return 1
861 fi
863 echo "new" > $testroot/repo/gamma/new
864 (cd $testroot/repo && git add .)
865 git_commit $testroot/repo -m "adding a new file"
867 echo "also new" > $testroot/wt/gamma/new
868 (cd $testroot/wt && got add gamma/new >/dev/null)
870 (cd $testroot/wt && got update > $testroot/stdout)
872 echo "C gamma/new" > $testroot/stdout.expected
873 echo -n "Updated to commit " >> $testroot/stdout.expected
874 git_show_head $testroot/repo >> $testroot/stdout.expected
875 echo >> $testroot/stdout.expected
876 cmp -s $testroot/stdout.expected $testroot/stdout
877 ret="$?"
878 if [ "$ret" != "0" ]; then
879 diff -u $testroot/stdout.expected $testroot/stdout
880 test_done "$testroot" "$ret"
881 return 1
882 fi
884 echo -n "<<<<<<< commit " > $testroot/content.expected
885 git_show_head $testroot/repo >> $testroot/content.expected
886 echo >> $testroot/content.expected
887 echo "new" >> $testroot/content.expected
888 echo "=======" >> $testroot/content.expected
889 echo "also new" >> $testroot/content.expected
890 echo '>>>>>>> gamma/new' >> $testroot/content.expected
892 cat $testroot/wt/gamma/new > $testroot/content
894 cmp -s $testroot/content.expected $testroot/content
895 ret="$?"
896 if [ "$ret" != "0" ]; then
897 diff -u $testroot/content.expected $testroot/content
898 test_done "$testroot" "$ret"
899 return 1
900 fi
902 # resolve the conflict
903 echo "new and also new" > $testroot/wt/gamma/new
904 echo 'M gamma/new' > $testroot/stdout.expected
905 (cd $testroot/wt && got status > $testroot/stdout)
906 cmp -s $testroot/stdout.expected $testroot/stdout
907 ret="$?"
908 if [ "$ret" != "0" ]; then
909 diff -u $testroot/stdout.expected $testroot/stdout
910 fi
911 test_done "$testroot" "$ret"
914 function test_update_conflict_wt_edit_vs_repo_rm {
915 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
917 got checkout $testroot/repo $testroot/wt > /dev/null
918 ret="$?"
919 if [ "$ret" != "0" ]; then
920 test_done "$testroot" "$ret"
921 return 1
922 fi
924 (cd $testroot/repo && git rm -q beta)
925 git_commit $testroot/repo -m "removing a file"
927 echo "modified beta" > $testroot/wt/beta
929 (cd $testroot/wt && got update > $testroot/stdout)
931 echo "G beta" > $testroot/stdout.expected
932 echo -n "Updated to commit " >> $testroot/stdout.expected
933 git_show_head $testroot/repo >> $testroot/stdout.expected
934 echo >> $testroot/stdout.expected
935 cmp -s $testroot/stdout.expected $testroot/stdout
936 ret="$?"
937 if [ "$ret" != "0" ]; then
938 diff -u $testroot/stdout.expected $testroot/stdout
939 test_done "$testroot" "$ret"
940 return 1
941 fi
943 echo "modified beta" > $testroot/content.expected
945 cat $testroot/wt/beta > $testroot/content
947 cmp -s $testroot/content.expected $testroot/content
948 ret="$?"
949 if [ "$ret" != "0" ]; then
950 diff -u $testroot/content.expected $testroot/content
951 test_done "$testroot" "$ret"
952 return 1
953 fi
955 # beta is now an added file... we don't flag tree conflicts yet
956 echo 'A beta' > $testroot/stdout.expected
957 (cd $testroot/wt && got status > $testroot/stdout)
958 cmp -s $testroot/stdout.expected $testroot/stdout
959 ret="$?"
960 if [ "$ret" != "0" ]; then
961 diff -u $testroot/stdout.expected $testroot/stdout
962 fi
963 test_done "$testroot" "$ret"
966 function test_update_conflict_wt_rm_vs_repo_edit {
967 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
969 got checkout $testroot/repo $testroot/wt > /dev/null
970 ret="$?"
971 if [ "$ret" != "0" ]; then
972 test_done "$testroot" "$ret"
973 return 1
974 fi
976 echo "modified beta" > $testroot/repo/beta
977 git_commit $testroot/repo -m "modified a file"
979 (cd $testroot/wt && got rm beta > /dev/null)
981 (cd $testroot/wt && got update > $testroot/stdout)
983 echo "G beta" > $testroot/stdout.expected
984 echo -n "Updated to commit " >> $testroot/stdout.expected
985 git_show_head $testroot/repo >> $testroot/stdout.expected
986 echo >> $testroot/stdout.expected
987 cmp -s $testroot/stdout.expected $testroot/stdout
988 ret="$?"
989 if [ "$ret" != "0" ]; then
990 diff -u $testroot/stdout.expected $testroot/stdout
991 test_done "$testroot" "$ret"
992 return 1
993 fi
995 # beta remains a deleted file... we don't flag tree conflicts yet
996 echo 'D beta' > $testroot/stdout.expected
997 (cd $testroot/wt && got status > $testroot/stdout)
998 cmp -s $testroot/stdout.expected $testroot/stdout
999 ret="$?"
1000 if [ "$ret" != "0" ]; then
1001 diff -u $testroot/stdout.expected $testroot/stdout
1002 test_done "$testroot" "$ret"
1003 return 1
1006 # 'got diff' should show post-update contents of beta being deleted
1007 local head_rev=`git_show_head $testroot/repo`
1008 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
1009 echo -n 'blob - ' >> $testroot/stdout.expected
1010 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1011 >> $testroot/stdout.expected
1012 echo 'file + /dev/null' >> $testroot/stdout.expected
1013 echo '--- beta' >> $testroot/stdout.expected
1014 echo '+++ beta' >> $testroot/stdout.expected
1015 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1016 echo '-modified beta' >> $testroot/stdout.expected
1018 (cd $testroot/wt && got diff > $testroot/stdout)
1019 cmp -s $testroot/stdout.expected $testroot/stdout
1020 ret="$?"
1021 if [ "$ret" != "0" ]; then
1022 diff -u $testroot/stdout.expected $testroot/stdout
1024 test_done "$testroot" "$ret"
1027 function test_update_conflict_wt_rm_vs_repo_rm {
1028 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1030 got checkout $testroot/repo $testroot/wt > /dev/null
1031 ret="$?"
1032 if [ "$ret" != "0" ]; then
1033 test_done "$testroot" "$ret"
1034 return 1
1037 (cd $testroot/repo && git rm -q beta)
1038 git_commit $testroot/repo -m "removing a file"
1040 (cd $testroot/wt && got rm beta > /dev/null)
1042 (cd $testroot/wt && got update > $testroot/stdout)
1044 echo "D beta" > $testroot/stdout.expected
1045 echo -n "Updated to commit " >> $testroot/stdout.expected
1046 git_show_head $testroot/repo >> $testroot/stdout.expected
1047 echo >> $testroot/stdout.expected
1048 cmp -s $testroot/stdout.expected $testroot/stdout
1049 ret="$?"
1050 if [ "$ret" != "0" ]; then
1051 diff -u $testroot/stdout.expected $testroot/stdout
1052 test_done "$testroot" "$ret"
1053 return 1
1056 # beta is now gone... we don't flag tree conflicts yet
1057 echo "N beta" > $testroot/stdout.expected
1058 echo -n > $testroot/stderr.expected
1059 (cd $testroot/wt && got status beta > $testroot/stdout \
1060 2> $testroot/stderr)
1061 cmp -s $testroot/stdout.expected $testroot/stdout
1062 ret="$?"
1063 if [ "$ret" != "0" ]; then
1064 diff -u $testroot/stdout.expected $testroot/stdout
1065 test_done "$testroot" "$ret"
1066 return 1
1068 cmp -s $testroot/stderr.expected $testroot/stderr
1069 ret="$?"
1070 if [ "$ret" != "0" ]; then
1071 diff -u $testroot/stderr.expected $testroot/stderr
1072 test_done "$testroot" "$ret"
1073 return 1
1076 if [ -e $testroot/wt/beta ]; then
1077 echo "removed file beta still exists on disk" >&2
1078 test_done "$testroot" "1"
1079 return 1
1082 test_done "$testroot" "0"
1085 function test_update_partial {
1086 local testroot=`test_init update_partial`
1088 got checkout $testroot/repo $testroot/wt > /dev/null
1089 ret="$?"
1090 if [ "$ret" != "0" ]; then
1091 test_done "$testroot" "$ret"
1092 return 1
1095 echo "modified alpha" > $testroot/repo/alpha
1096 echo "modified beta" > $testroot/repo/beta
1097 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1098 git_commit $testroot/repo -m "modified two files"
1100 echo "U alpha" > $testroot/stdout.expected
1101 echo "U beta" >> $testroot/stdout.expected
1102 echo -n "Updated to commit " >> $testroot/stdout.expected
1103 git_show_head $testroot/repo >> $testroot/stdout.expected
1104 echo >> $testroot/stdout.expected
1106 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1108 cmp -s $testroot/stdout.expected $testroot/stdout
1109 ret="$?"
1110 if [ "$ret" != "0" ]; then
1111 diff -u $testroot/stdout.expected $testroot/stdout
1112 test_done "$testroot" "$ret"
1113 return 1
1116 echo "modified alpha" > $testroot/content.expected
1117 echo "modified beta" >> $testroot/content.expected
1119 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1120 cmp -s $testroot/content.expected $testroot/content
1121 ret="$?"
1122 if [ "$ret" != "0" ]; then
1123 diff -u $testroot/content.expected $testroot/content
1124 test_done "$testroot" "$ret"
1125 return 1
1128 echo "U epsilon/zeta" > $testroot/stdout.expected
1129 echo -n "Updated to commit " >> $testroot/stdout.expected
1130 git_show_head $testroot/repo >> $testroot/stdout.expected
1131 echo >> $testroot/stdout.expected
1133 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1135 cmp -s $testroot/stdout.expected $testroot/stdout
1136 ret="$?"
1137 if [ "$ret" != "0" ]; then
1138 diff -u $testroot/stdout.expected $testroot/stdout
1139 test_done "$testroot" "$ret"
1140 return 1
1143 echo "modified epsilon/zeta" > $testroot/content.expected
1144 cat $testroot/wt/epsilon/zeta > $testroot/content
1146 cmp -s $testroot/content.expected $testroot/content
1147 ret="$?"
1148 if [ "$ret" != "0" ]; then
1149 diff -u $testroot/content.expected $testroot/content
1150 test_done "$testroot" "$ret"
1151 return 1
1154 test_done "$testroot" "$ret"
1157 function test_update_partial_add {
1158 local testroot=`test_init update_partial_add`
1160 got checkout $testroot/repo $testroot/wt > /dev/null
1161 ret="$?"
1162 if [ "$ret" != "0" ]; then
1163 test_done "$testroot" "$ret"
1164 return 1
1167 echo "new" > $testroot/repo/new
1168 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1169 (cd $testroot/repo && git add .)
1170 git_commit $testroot/repo -m "added two files"
1172 echo "A new" > $testroot/stdout.expected
1173 echo "A epsilon/new2" >> $testroot/stdout.expected
1174 echo -n "Updated to commit " >> $testroot/stdout.expected
1175 git_show_head $testroot/repo >> $testroot/stdout.expected
1176 echo >> $testroot/stdout.expected
1178 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1180 cmp -s $testroot/stdout.expected $testroot/stdout
1181 ret="$?"
1182 if [ "$ret" != "0" ]; then
1183 diff -u $testroot/stdout.expected $testroot/stdout
1184 test_done "$testroot" "$ret"
1185 return 1
1188 echo "new" > $testroot/content.expected
1189 echo "epsilon/new2" >> $testroot/content.expected
1191 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1193 cmp -s $testroot/content.expected $testroot/content
1194 ret="$?"
1195 if [ "$ret" != "0" ]; then
1196 diff -u $testroot/content.expected $testroot/content
1198 test_done "$testroot" "$ret"
1201 function test_update_partial_rm {
1202 local testroot=`test_init update_partial_rm`
1204 got checkout $testroot/repo $testroot/wt > /dev/null
1205 ret="$?"
1206 if [ "$ret" != "0" ]; then
1207 test_done "$testroot" "$ret"
1208 return 1
1211 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1212 git_commit $testroot/repo -m "removed two files"
1214 echo "got: no such entry found in tree" \
1215 > $testroot/stderr.expected
1217 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1218 ret="$?"
1219 if [ "$ret" == "0" ]; then
1220 echo "update succeeded unexpectedly" >&2
1221 test_done "$testroot" "1"
1222 return 1
1225 cmp -s $testroot/stderr.expected $testroot/stderr
1226 ret="$?"
1227 if [ "$ret" != "0" ]; then
1228 diff -u $testroot/stderr.expected $testroot/stderr
1229 test_done "$testroot" "$ret"
1230 return 1
1232 test_done "$testroot" "$ret"
1235 function test_update_partial_dir {
1236 local testroot=`test_init update_partial_dir`
1238 got checkout $testroot/repo $testroot/wt > /dev/null
1239 ret="$?"
1240 if [ "$ret" != "0" ]; then
1241 test_done "$testroot" "$ret"
1242 return 1
1245 echo "modified alpha" > $testroot/repo/alpha
1246 echo "modified beta" > $testroot/repo/beta
1247 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1248 git_commit $testroot/repo -m "modified two files"
1250 echo "U epsilon/zeta" > $testroot/stdout.expected
1251 echo -n "Updated to commit " >> $testroot/stdout.expected
1252 git_show_head $testroot/repo >> $testroot/stdout.expected
1253 echo >> $testroot/stdout.expected
1255 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1257 cmp -s $testroot/stdout.expected $testroot/stdout
1258 ret="$?"
1259 if [ "$ret" != "0" ]; then
1260 diff -u $testroot/stdout.expected $testroot/stdout
1261 test_done "$testroot" "$ret"
1262 return 1
1265 echo "modified epsilon/zeta" > $testroot/content.expected
1266 cat $testroot/wt/epsilon/zeta > $testroot/content
1268 cmp -s $testroot/content.expected $testroot/content
1269 ret="$?"
1270 if [ "$ret" != "0" ]; then
1271 diff -u $testroot/content.expected $testroot/content
1272 test_done "$testroot" "$ret"
1273 return 1
1275 test_done "$testroot" "$ret"
1279 function test_update_moved_branch_ref {
1280 local testroot=`test_init update_moved_branch_ref`
1282 git clone -q --mirror $testroot/repo $testroot/repo2
1284 echo "modified alpha with git" > $testroot/repo/alpha
1285 git_commit $testroot/repo -m "modified alpha with git"
1287 got checkout $testroot/repo2 $testroot/wt > /dev/null
1288 ret="$?"
1289 if [ "$ret" != "0" ]; then
1290 test_done "$testroot" "$ret"
1291 return 1
1294 echo "modified alpha with got" > $testroot/wt/alpha
1295 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1297 # + xxxxxxx...yyyyyyy master -> master (forced update)
1298 (cd $testroot/repo2 && git fetch -q --all)
1300 echo -n > $testroot/stdout.expected
1301 echo -n "got: work tree's head reference now points to a different " \
1302 > $testroot/stderr.expected
1303 echo "branch; new head reference and/or update -b required" \
1304 >> $testroot/stderr.expected
1306 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1308 cmp -s $testroot/stdout.expected $testroot/stdout
1309 ret="$?"
1310 if [ "$ret" != "0" ]; then
1311 diff -u $testroot/stdout.expected $testroot/stdout
1312 test_done "$testroot" "$ret"
1313 return 1
1316 cmp -s $testroot/stderr.expected $testroot/stderr
1317 ret="$?"
1318 if [ "$ret" != "0" ]; then
1319 diff -u $testroot/stderr.expected $testroot/stderr
1321 test_done "$testroot" "$ret"
1324 function test_update_to_another_branch {
1325 local testroot=`test_init update_to_another_branch`
1327 got checkout $testroot/repo $testroot/wt > /dev/null
1328 ret="$?"
1329 if [ "$ret" != "0" ]; then
1330 test_done "$testroot" "$ret"
1331 return 1
1334 echo 'refs/heads/master'> $testroot/head-ref.expected
1335 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1336 ret="$?"
1337 if [ "$ret" != "0" ]; then
1338 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1339 test_done "$testroot" "$ret"
1340 return 1
1343 (cd $testroot/repo && git checkout -q -b newbranch)
1344 echo "modified alpha on new branch" > $testroot/repo/alpha
1345 git_commit $testroot/repo -m "modified alpha on new branch"
1347 echo "modified alpha in work tree" > $testroot/wt/alpha
1349 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1350 echo "C alpha" >> $testroot/stdout.expected
1351 echo -n "Updated to commit " >> $testroot/stdout.expected
1352 git_show_head $testroot/repo >> $testroot/stdout.expected
1353 echo >> $testroot/stdout.expected
1355 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1357 cmp -s $testroot/stdout.expected $testroot/stdout
1358 ret="$?"
1359 if [ "$ret" != "0" ]; then
1360 diff -u $testroot/stdout.expected $testroot/stdout
1361 test_done "$testroot" "$ret"
1362 return 1
1365 echo -n "<<<<<<< commit " > $testroot/content.expected
1366 git_show_head $testroot/repo >> $testroot/content.expected
1367 echo >> $testroot/content.expected
1368 echo "modified alpha on new branch" >> $testroot/content.expected
1369 echo "|||||||" >> $testroot/content.expected
1370 echo "alpha" >> $testroot/content.expected
1371 echo "=======" >> $testroot/content.expected
1372 echo "modified alpha in work tree" >> $testroot/content.expected
1373 echo '>>>>>>> alpha' >> $testroot/content.expected
1375 cat $testroot/wt/alpha > $testroot/content
1377 cmp -s $testroot/content.expected $testroot/content
1378 ret="$?"
1379 if [ "$ret" != "0" ]; then
1380 diff -u $testroot/content.expected $testroot/content
1381 test_done "$testroot" "$ret"
1382 return 1
1385 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1386 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1387 ret="$?"
1388 if [ "$ret" != "0" ]; then
1389 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1390 test_done "$testroot" "$ret"
1391 return 1
1394 test_done "$testroot" "$ret"
1397 function test_update_to_commit_on_wrong_branch {
1398 local testroot=`test_init update_to_commit_on_wrong_branch`
1400 got checkout $testroot/repo $testroot/wt > /dev/null
1401 ret="$?"
1402 if [ "$ret" != "0" ]; then
1403 test_done "$testroot" "$ret"
1404 return 1
1407 (cd $testroot/repo && git checkout -q -b newbranch)
1408 echo "modified alpha on new branch" > $testroot/repo/alpha
1409 git_commit $testroot/repo -m "modified alpha on new branch"
1411 echo -n "" > $testroot/stdout.expected
1412 echo "got: target commit is on a different branch" \
1413 > $testroot/stderr.expected
1415 local head_rev=`git_show_head $testroot/repo`
1416 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1417 2> $testroot/stderr)
1419 cmp -s $testroot/stdout.expected $testroot/stdout
1420 ret="$?"
1421 if [ "$ret" != "0" ]; then
1422 diff -u $testroot/stdout.expected $testroot/stdout
1423 test_done "$testroot" "$ret"
1424 return 1
1427 cmp -s $testroot/stderr.expected $testroot/stderr
1428 ret="$?"
1429 if [ "$ret" != "0" ]; then
1430 diff -u $testroot/stderr.expected $testroot/stderr
1431 test_done "$testroot" "$ret"
1432 return 1
1435 test_done "$testroot" "$ret"
1438 function test_update_bumps_base_commit_id {
1439 local testroot=`test_init update_bumps_base_commit_id`
1441 echo "psi" > $testroot/repo/epsilon/psi
1442 (cd $testroot/repo && git add .)
1443 git_commit $testroot/repo -m "adding another file"
1445 got checkout $testroot/repo $testroot/wt > /dev/null
1446 ret="$?"
1447 if [ "$ret" != "0" ]; then
1448 test_done "$testroot" "$ret"
1449 return 1
1452 echo "modified psi" > $testroot/wt/epsilon/psi
1453 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1455 local head_rev=`git_show_head $testroot/repo`
1456 echo "M epsilon/psi" > $testroot/stdout.expected
1457 echo "Created commit $head_rev" >> $testroot/stdout.expected
1458 cmp -s $testroot/stdout.expected $testroot/stdout
1459 ret="$?"
1460 if [ "$ret" != "0" ]; then
1461 diff -u $testroot/stdout.expected $testroot/stdout
1462 test_done "$testroot" "$ret"
1463 return 1
1466 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1467 (cd $testroot/repo && git add .)
1468 git_commit $testroot/repo -m "changing zeta with git"
1470 echo "modified zeta" > $testroot/wt/epsilon/zeta
1471 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1472 2> $testroot/stderr)
1474 echo -n "" > $testroot/stdout.expected
1475 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1476 cmp -s $testroot/stderr.expected $testroot/stderr
1477 ret="$?"
1478 if [ "$ret" != "0" ]; then
1479 diff -u $testroot/stderr.expected $testroot/stderr
1480 test_done "$testroot" "$ret"
1481 return 1
1484 (cd $testroot/wt && got update > $testroot/stdout)
1486 echo "U epsilon/psi" > $testroot/stdout.expected
1487 echo "C epsilon/zeta" >> $testroot/stdout.expected
1488 echo -n "Updated to commit " >> $testroot/stdout.expected
1489 git_show_head $testroot/repo >> $testroot/stdout.expected
1490 echo >> $testroot/stdout.expected
1491 cmp -s $testroot/stdout.expected $testroot/stdout
1492 ret="$?"
1493 if [ "$ret" != "0" ]; then
1494 diff -u $testroot/stdout.expected $testroot/stdout
1495 test_done "$testroot" "$ret"
1496 return 1
1499 # resolve conflict
1500 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1502 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1504 local head_rev=`git_show_head $testroot/repo`
1505 echo "M epsilon/zeta" > $testroot/stdout.expected
1506 echo "Created commit $head_rev" >> $testroot/stdout.expected
1507 cmp -s $testroot/stdout.expected $testroot/stdout
1508 ret="$?"
1509 if [ "$ret" != "0" ]; then
1510 diff -u $testroot/stdout.expected $testroot/stdout
1511 test_done "$testroot" "$ret"
1512 return 1
1515 test_done "$testroot" "$ret"
1518 function test_update_tag {
1519 local testroot=`test_init update_tag`
1520 local tag="1.0.0"
1522 got checkout $testroot/repo $testroot/wt > /dev/null
1523 ret="$?"
1524 if [ "$ret" != "0" ]; then
1525 test_done "$testroot" "$ret"
1526 return 1
1529 echo "modified alpha" > $testroot/repo/alpha
1530 git_commit $testroot/repo -m "modified alpha"
1531 (cd $testroot/repo && git tag -m "test" -a $tag)
1533 echo "U alpha" > $testroot/stdout.expected
1534 echo -n "Updated to commit " >> $testroot/stdout.expected
1535 git_show_head $testroot/repo >> $testroot/stdout.expected
1536 echo >> $testroot/stdout.expected
1538 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1540 cmp -s $testroot/stdout.expected $testroot/stdout
1541 ret="$?"
1542 if [ "$ret" != "0" ]; then
1543 diff -u $testroot/stdout.expected $testroot/stdout
1544 test_done "$testroot" "$ret"
1545 return 1
1548 echo "modified alpha" > $testroot/content.expected
1549 cat $testroot/wt/alpha > $testroot/content
1551 cmp -s $testroot/content.expected $testroot/content
1552 ret="$?"
1553 if [ "$ret" != "0" ]; then
1554 diff -u $testroot/content.expected $testroot/content
1556 test_done "$testroot" "$ret"
1559 function test_update_toggles_xbit {
1560 local testroot=`test_init update_toggles_xbit 1`
1562 touch $testroot/repo/xfile
1563 chmod +x $testroot/repo/xfile
1564 (cd $testroot/repo && git add .)
1565 git_commit $testroot/repo -m "adding executable file"
1566 local commit_id1=`git_show_head $testroot/repo`
1568 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1569 ret="$?"
1570 if [ "$ret" != "0" ]; then
1571 test_done "$testroot" "$ret"
1572 return 1
1575 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1576 ret="$?"
1577 if [ "$ret" != "0" ]; then
1578 echo "file is not executable" >&2
1579 ls -l $testroot/wt/xfile >&2
1580 test_done "$testroot" "$ret"
1581 return 1
1584 chmod -x $testroot/wt/xfile
1585 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1586 local commit_id2=`git_show_head $testroot/repo`
1588 echo "U xfile" > $testroot/stdout.expected
1589 echo -n "Updated to commit " >> $testroot/stdout.expected
1590 git_show_head $testroot/repo >> $testroot/stdout.expected
1591 echo >> $testroot/stdout.expected
1593 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1594 ret="$?"
1595 if [ "$ret" != "0" ]; then
1596 test_done "$testroot" "$ret"
1597 return 1
1600 echo "U xfile" > $testroot/stdout.expected
1601 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
1602 cmp -s $testroot/stdout.expected $testroot/stdout
1603 ret="$?"
1604 if [ "$ret" != "0" ]; then
1605 diff -u $testroot/stdout.expected $testroot/stdout
1606 test_done "$testroot" "$ret"
1607 return 1
1611 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1612 ret="$?"
1613 if [ "$ret" != "0" ]; then
1614 echo "file is not executable" >&2
1615 ls -l $testroot/wt/xfile >&2
1616 test_done "$testroot" "$ret"
1617 return 1
1620 (cd $testroot/wt && got update > $testroot/stdout)
1621 ret="$?"
1622 if [ "$ret" != "0" ]; then
1623 test_done "$testroot" "$ret"
1624 return 1
1627 echo "U xfile" > $testroot/stdout.expected
1628 echo "Updated to commit $commit_id2" >> $testroot/stdout.expected
1629 cmp -s $testroot/stdout.expected $testroot/stdout
1630 ret="$?"
1631 if [ "$ret" != "0" ]; then
1632 diff -u $testroot/stdout.expected $testroot/stdout
1633 test_done "$testroot" "$ret"
1634 return 1
1637 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1638 ret="$?"
1639 if [ "$ret" != "0" ]; then
1640 echo "file is unexpectedly executable" >&2
1641 ls -l $testroot/wt/xfile >&2
1643 test_done "$testroot" "$ret"
1646 run_test test_update_basic
1647 run_test test_update_adds_file
1648 run_test test_update_deletes_file
1649 run_test test_update_deletes_dir
1650 run_test test_update_deletes_dir_with_path_prefix
1651 run_test test_update_deletes_dir_recursively
1652 run_test test_update_sibling_dirs_with_common_prefix
1653 run_test test_update_dir_with_dot_sibling
1654 run_test test_update_moves_files_upwards
1655 run_test test_update_moves_files_to_new_dir
1656 run_test test_update_creates_missing_parent
1657 run_test test_update_creates_missing_parent_with_subdir
1658 run_test test_update_file_in_subsubdir
1659 run_test test_update_merges_file_edits
1660 run_test test_update_keeps_xbit
1661 run_test test_update_clears_xbit
1662 run_test test_update_restores_missing_file
1663 run_test test_update_conflict_wt_add_vs_repo_add
1664 run_test test_update_conflict_wt_edit_vs_repo_rm
1665 run_test test_update_conflict_wt_rm_vs_repo_edit
1666 run_test test_update_conflict_wt_rm_vs_repo_rm
1667 run_test test_update_partial
1668 run_test test_update_partial_add
1669 run_test test_update_partial_rm
1670 run_test test_update_partial_dir
1671 run_test test_update_moved_branch_ref
1672 run_test test_update_to_another_branch
1673 run_test test_update_to_commit_on_wrong_branch
1674 run_test test_update_bumps_base_commit_id
1675 run_test test_update_tag
1676 run_test test_update_toggles_xbit