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 "modified alpha, too" >> $testroot/content.expected
685 echo '>>>>>>> alpha' >> $testroot/content.expected
686 echo "modified beta" >> $testroot/content.expected
687 echo "1" >> $testroot/content.expected
688 echo "22" >> $testroot/content.expected
689 echo "3" >> $testroot/content.expected
690 echo "4" >> $testroot/content.expected
691 echo "5" >> $testroot/content.expected
692 echo "6" >> $testroot/content.expected
693 echo "77" >> $testroot/content.expected
694 echo "8" >> $testroot/content.expected
696 cat $testroot/wt/alpha > $testroot/content
697 cat $testroot/wt/beta >> $testroot/content
698 cat $testroot/wt/numbers >> $testroot/content
700 cmp -s $testroot/content.expected $testroot/content
701 ret="$?"
702 if [ "$ret" != "0" ]; then
703 diff -u $testroot/content.expected $testroot/content
704 fi
705 test_done "$testroot" "$ret"
708 function test_update_keeps_xbit {
709 local testroot=`test_init update_keeps_xbit 1`
711 touch $testroot/repo/xfile
712 chmod +x $testroot/repo/xfile
713 (cd $testroot/repo && git add .)
714 git_commit $testroot/repo -m "adding executable file"
716 got checkout $testroot/repo $testroot/wt > $testroot/stdout
717 ret="$?"
718 if [ "$ret" != "0" ]; then
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 echo foo > $testroot/repo/xfile
724 git_commit $testroot/repo -m "changed executable file"
726 echo "U xfile" > $testroot/stdout.expected
727 echo -n "Updated to commit " >> $testroot/stdout.expected
728 git_show_head $testroot/repo >> $testroot/stdout.expected
729 echo >> $testroot/stdout.expected
731 (cd $testroot/wt && got update > $testroot/stdout)
732 ret="$?"
733 if [ "$ret" != "0" ]; then
734 test_done "$testroot" "$ret"
735 return 1
736 fi
738 cmp -s $testroot/stdout.expected $testroot/stdout
739 ret="$?"
740 if [ "$ret" != "0" ]; then
741 diff -u $testroot/stdout.expected $testroot/stdout
742 test_done "$testroot" "$ret"
743 return 1
744 fi
746 ls -l $testroot/wt/xfile | grep -q '^-rwx'
747 ret="$?"
748 if [ "$ret" != "0" ]; then
749 echo "file is not executable" >&2
750 ls -l $testroot/wt/xfile >&2
751 fi
752 test_done "$testroot" "$ret"
755 function test_update_clears_xbit {
756 local testroot=`test_init update_clears_xbit 1`
758 touch $testroot/repo/xfile
759 chmod +x $testroot/repo/xfile
760 (cd $testroot/repo && git add .)
761 git_commit $testroot/repo -m "adding executable file"
763 got checkout $testroot/repo $testroot/wt > $testroot/stdout
764 ret="$?"
765 if [ "$ret" != "0" ]; then
766 test_done "$testroot" "$ret"
767 return 1
768 fi
770 ls -l $testroot/wt/xfile | grep -q '^-rwx'
771 ret="$?"
772 if [ "$ret" != "0" ]; then
773 echo "file is not executable" >&2
774 ls -l $testroot/wt/xfile >&2
775 test_done "$testroot" "$ret"
776 return 1
777 fi
779 # XXX git seems to require a file edit when flipping the x bit?
780 echo foo > $testroot/repo/xfile
781 chmod -x $testroot/repo/xfile
782 git_commit $testroot/repo -m "not an executable file anymore"
784 echo "U xfile" > $testroot/stdout.expected
785 echo -n "Updated to commit " >> $testroot/stdout.expected
786 git_show_head $testroot/repo >> $testroot/stdout.expected
787 echo >> $testroot/stdout.expected
789 (cd $testroot/wt && got update > $testroot/stdout)
790 ret="$?"
791 if [ "$ret" != "0" ]; then
792 test_done "$testroot" "$ret"
793 return 1
794 fi
796 cmp -s $testroot/stdout.expected $testroot/stdout
797 ret="$?"
798 if [ "$ret" != "0" ]; then
799 diff -u $testroot/stdout.expected $testroot/stdout
800 test_done "$testroot" "$ret"
801 return 1
802 fi
804 ls -l $testroot/wt/xfile | grep -q '^-rw-'
805 ret="$?"
806 if [ "$ret" != "0" ]; then
807 echo "file is unexpectedly executable" >&2
808 ls -l $testroot/wt/xfile >&2
809 fi
810 test_done "$testroot" "$ret"
813 function test_update_restores_missing_file {
814 local testroot=`test_init update_restores_missing_file`
816 got checkout $testroot/repo $testroot/wt > /dev/null
817 ret="$?"
818 if [ "$ret" != "0" ]; then
819 test_done "$testroot" "$ret"
820 return 1
821 fi
823 rm $testroot/wt/alpha
825 echo "! alpha" > $testroot/stdout.expected
826 echo -n "Updated to commit " >> $testroot/stdout.expected
827 git_show_head $testroot/repo >> $testroot/stdout.expected
828 echo >> $testroot/stdout.expected
829 (cd $testroot/wt && got update > $testroot/stdout)
831 cmp -s $testroot/stdout.expected $testroot/stdout
832 ret="$?"
833 if [ "$ret" != "0" ]; then
834 diff -u $testroot/stdout.expected $testroot/stdout
835 test_done "$testroot" "$ret"
836 return 1
837 fi
839 echo "alpha" > $testroot/content.expected
841 cat $testroot/wt/alpha > $testroot/content
843 cmp -s $testroot/content.expected $testroot/content
844 ret="$?"
845 if [ "$ret" != "0" ]; then
846 diff -u $testroot/content.expected $testroot/content
847 fi
848 test_done "$testroot" "$ret"
851 function test_update_conflict_wt_add_vs_repo_add {
852 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
854 got checkout $testroot/repo $testroot/wt > /dev/null
855 ret="$?"
856 if [ "$ret" != "0" ]; then
857 test_done "$testroot" "$ret"
858 return 1
859 fi
861 echo "new" > $testroot/repo/gamma/new
862 (cd $testroot/repo && git add .)
863 git_commit $testroot/repo -m "adding a new file"
865 echo "also new" > $testroot/wt/gamma/new
866 (cd $testroot/wt && got add gamma/new >/dev/null)
868 (cd $testroot/wt && got update > $testroot/stdout)
870 echo "C gamma/new" > $testroot/stdout.expected
871 echo -n "Updated to commit " >> $testroot/stdout.expected
872 git_show_head $testroot/repo >> $testroot/stdout.expected
873 echo >> $testroot/stdout.expected
874 cmp -s $testroot/stdout.expected $testroot/stdout
875 ret="$?"
876 if [ "$ret" != "0" ]; then
877 diff -u $testroot/stdout.expected $testroot/stdout
878 test_done "$testroot" "$ret"
879 return 1
880 fi
882 echo -n "<<<<<<< commit " > $testroot/content.expected
883 git_show_head $testroot/repo >> $testroot/content.expected
884 echo >> $testroot/content.expected
885 echo "new" >> $testroot/content.expected
886 echo "=======" >> $testroot/content.expected
887 echo "also new" >> $testroot/content.expected
888 echo '>>>>>>> gamma/new' >> $testroot/content.expected
890 cat $testroot/wt/gamma/new > $testroot/content
892 cmp -s $testroot/content.expected $testroot/content
893 ret="$?"
894 if [ "$ret" != "0" ]; then
895 diff -u $testroot/content.expected $testroot/content
896 test_done "$testroot" "$ret"
897 return 1
898 fi
900 # resolve the conflict
901 echo "new and also new" > $testroot/wt/gamma/new
902 echo 'M gamma/new' > $testroot/stdout.expected
903 (cd $testroot/wt && got status > $testroot/stdout)
904 cmp -s $testroot/stdout.expected $testroot/stdout
905 ret="$?"
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 fi
909 test_done "$testroot" "$ret"
912 function test_update_conflict_wt_edit_vs_repo_rm {
913 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
915 got checkout $testroot/repo $testroot/wt > /dev/null
916 ret="$?"
917 if [ "$ret" != "0" ]; then
918 test_done "$testroot" "$ret"
919 return 1
920 fi
922 (cd $testroot/repo && git rm -q beta)
923 git_commit $testroot/repo -m "removing a file"
925 echo "modified beta" > $testroot/wt/beta
927 (cd $testroot/wt && got update > $testroot/stdout)
929 echo "G beta" > $testroot/stdout.expected
930 echo -n "Updated to commit " >> $testroot/stdout.expected
931 git_show_head $testroot/repo >> $testroot/stdout.expected
932 echo >> $testroot/stdout.expected
933 cmp -s $testroot/stdout.expected $testroot/stdout
934 ret="$?"
935 if [ "$ret" != "0" ]; then
936 diff -u $testroot/stdout.expected $testroot/stdout
937 test_done "$testroot" "$ret"
938 return 1
939 fi
941 echo "modified beta" > $testroot/content.expected
943 cat $testroot/wt/beta > $testroot/content
945 cmp -s $testroot/content.expected $testroot/content
946 ret="$?"
947 if [ "$ret" != "0" ]; then
948 diff -u $testroot/content.expected $testroot/content
949 test_done "$testroot" "$ret"
950 return 1
951 fi
953 # beta is now an added file... we don't flag tree conflicts yet
954 echo 'A beta' > $testroot/stdout.expected
955 (cd $testroot/wt && got status > $testroot/stdout)
956 cmp -s $testroot/stdout.expected $testroot/stdout
957 ret="$?"
958 if [ "$ret" != "0" ]; then
959 diff -u $testroot/stdout.expected $testroot/stdout
960 fi
961 test_done "$testroot" "$ret"
964 function test_update_conflict_wt_rm_vs_repo_edit {
965 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
967 got checkout $testroot/repo $testroot/wt > /dev/null
968 ret="$?"
969 if [ "$ret" != "0" ]; then
970 test_done "$testroot" "$ret"
971 return 1
972 fi
974 echo "modified beta" > $testroot/repo/beta
975 git_commit $testroot/repo -m "modified a file"
977 (cd $testroot/wt && got rm beta > /dev/null)
979 (cd $testroot/wt && got update > $testroot/stdout)
981 echo "G beta" > $testroot/stdout.expected
982 echo -n "Updated to commit " >> $testroot/stdout.expected
983 git_show_head $testroot/repo >> $testroot/stdout.expected
984 echo >> $testroot/stdout.expected
985 cmp -s $testroot/stdout.expected $testroot/stdout
986 ret="$?"
987 if [ "$ret" != "0" ]; then
988 diff -u $testroot/stdout.expected $testroot/stdout
989 test_done "$testroot" "$ret"
990 return 1
991 fi
993 # beta remains a deleted file... we don't flag tree conflicts yet
994 echo 'D beta' > $testroot/stdout.expected
995 (cd $testroot/wt && got status > $testroot/stdout)
996 cmp -s $testroot/stdout.expected $testroot/stdout
997 ret="$?"
998 if [ "$ret" != "0" ]; then
999 diff -u $testroot/stdout.expected $testroot/stdout
1000 test_done "$testroot" "$ret"
1001 return 1
1004 # 'got diff' should show post-update contents of beta being deleted
1005 local head_rev=`git_show_head $testroot/repo`
1006 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
1007 echo -n 'blob - ' >> $testroot/stdout.expected
1008 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1009 >> $testroot/stdout.expected
1010 echo 'file + /dev/null' >> $testroot/stdout.expected
1011 echo '--- beta' >> $testroot/stdout.expected
1012 echo '+++ beta' >> $testroot/stdout.expected
1013 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1014 echo '-modified beta' >> $testroot/stdout.expected
1016 (cd $testroot/wt && got diff > $testroot/stdout)
1017 cmp -s $testroot/stdout.expected $testroot/stdout
1018 ret="$?"
1019 if [ "$ret" != "0" ]; then
1020 diff -u $testroot/stdout.expected $testroot/stdout
1022 test_done "$testroot" "$ret"
1025 function test_update_conflict_wt_rm_vs_repo_rm {
1026 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1028 got checkout $testroot/repo $testroot/wt > /dev/null
1029 ret="$?"
1030 if [ "$ret" != "0" ]; then
1031 test_done "$testroot" "$ret"
1032 return 1
1035 (cd $testroot/repo && git rm -q beta)
1036 git_commit $testroot/repo -m "removing a file"
1038 (cd $testroot/wt && got rm beta > /dev/null)
1040 (cd $testroot/wt && got update > $testroot/stdout)
1042 echo "D beta" > $testroot/stdout.expected
1043 echo -n "Updated to commit " >> $testroot/stdout.expected
1044 git_show_head $testroot/repo >> $testroot/stdout.expected
1045 echo >> $testroot/stdout.expected
1046 cmp -s $testroot/stdout.expected $testroot/stdout
1047 ret="$?"
1048 if [ "$ret" != "0" ]; then
1049 diff -u $testroot/stdout.expected $testroot/stdout
1050 test_done "$testroot" "$ret"
1051 return 1
1054 # beta is now gone... we don't flag tree conflicts yet
1055 echo -n > $testroot/stdout.expected
1056 echo -n > $testroot/stderr.expected
1057 (cd $testroot/wt && got status beta > $testroot/stdout \
1058 2> $testroot/stderr)
1059 cmp -s $testroot/stdout.expected $testroot/stdout
1060 ret="$?"
1061 if [ "$ret" != "0" ]; then
1062 diff -u $testroot/stdout.expected $testroot/stdout
1063 test_done "$testroot" "$ret"
1064 return 1
1066 cmp -s $testroot/stderr.expected $testroot/stderr
1067 ret="$?"
1068 if [ "$ret" != "0" ]; then
1069 diff -u $testroot/stderr.expected $testroot/stderr
1070 test_done "$testroot" "$ret"
1071 return 1
1074 if [ -e $testroot/wt/beta ]; then
1075 echo "removed file beta still exists on disk" >&2
1076 test_done "$testroot" "1"
1077 return 1
1080 test_done "$testroot" "0"
1083 function test_update_partial {
1084 local testroot=`test_init update_partial`
1086 got checkout $testroot/repo $testroot/wt > /dev/null
1087 ret="$?"
1088 if [ "$ret" != "0" ]; then
1089 test_done "$testroot" "$ret"
1090 return 1
1093 echo "modified alpha" > $testroot/repo/alpha
1094 echo "modified beta" > $testroot/repo/beta
1095 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1096 git_commit $testroot/repo -m "modified two files"
1098 echo "U alpha" > $testroot/stdout.expected
1099 echo "U beta" >> $testroot/stdout.expected
1100 echo -n "Updated to commit " >> $testroot/stdout.expected
1101 git_show_head $testroot/repo >> $testroot/stdout.expected
1102 echo >> $testroot/stdout.expected
1104 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1106 cmp -s $testroot/stdout.expected $testroot/stdout
1107 ret="$?"
1108 if [ "$ret" != "0" ]; then
1109 diff -u $testroot/stdout.expected $testroot/stdout
1110 test_done "$testroot" "$ret"
1111 return 1
1114 echo "modified alpha" > $testroot/content.expected
1115 echo "modified beta" >> $testroot/content.expected
1117 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1118 cmp -s $testroot/content.expected $testroot/content
1119 ret="$?"
1120 if [ "$ret" != "0" ]; then
1121 diff -u $testroot/content.expected $testroot/content
1122 test_done "$testroot" "$ret"
1123 return 1
1126 echo "U epsilon/zeta" > $testroot/stdout.expected
1127 echo -n "Updated to commit " >> $testroot/stdout.expected
1128 git_show_head $testroot/repo >> $testroot/stdout.expected
1129 echo >> $testroot/stdout.expected
1131 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1133 cmp -s $testroot/stdout.expected $testroot/stdout
1134 ret="$?"
1135 if [ "$ret" != "0" ]; then
1136 diff -u $testroot/stdout.expected $testroot/stdout
1137 test_done "$testroot" "$ret"
1138 return 1
1141 echo "modified epsilon/zeta" > $testroot/content.expected
1142 cat $testroot/wt/epsilon/zeta > $testroot/content
1144 cmp -s $testroot/content.expected $testroot/content
1145 ret="$?"
1146 if [ "$ret" != "0" ]; then
1147 diff -u $testroot/content.expected $testroot/content
1148 test_done "$testroot" "$ret"
1149 return 1
1152 test_done "$testroot" "$ret"
1155 function test_update_partial_add {
1156 local testroot=`test_init update_partial_add`
1158 got checkout $testroot/repo $testroot/wt > /dev/null
1159 ret="$?"
1160 if [ "$ret" != "0" ]; then
1161 test_done "$testroot" "$ret"
1162 return 1
1165 echo "new" > $testroot/repo/new
1166 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1167 (cd $testroot/repo && git add .)
1168 git_commit $testroot/repo -m "added two files"
1170 echo "A new" > $testroot/stdout.expected
1171 echo "A epsilon/new2" >> $testroot/stdout.expected
1172 echo -n "Updated to commit " >> $testroot/stdout.expected
1173 git_show_head $testroot/repo >> $testroot/stdout.expected
1174 echo >> $testroot/stdout.expected
1176 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1178 cmp -s $testroot/stdout.expected $testroot/stdout
1179 ret="$?"
1180 if [ "$ret" != "0" ]; then
1181 diff -u $testroot/stdout.expected $testroot/stdout
1182 test_done "$testroot" "$ret"
1183 return 1
1186 echo "new" > $testroot/content.expected
1187 echo "epsilon/new2" >> $testroot/content.expected
1189 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1191 cmp -s $testroot/content.expected $testroot/content
1192 ret="$?"
1193 if [ "$ret" != "0" ]; then
1194 diff -u $testroot/content.expected $testroot/content
1196 test_done "$testroot" "$ret"
1199 function test_update_partial_rm {
1200 local testroot=`test_init update_partial_rm`
1202 got checkout $testroot/repo $testroot/wt > /dev/null
1203 ret="$?"
1204 if [ "$ret" != "0" ]; then
1205 test_done "$testroot" "$ret"
1206 return 1
1209 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1210 git_commit $testroot/repo -m "removed two files"
1212 echo "got: no such entry found in tree" \
1213 > $testroot/stderr.expected
1215 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1216 ret="$?"
1217 if [ "$ret" == "0" ]; then
1218 echo "update succeeded unexpectedly" >&2
1219 test_done "$testroot" "1"
1220 return 1
1223 cmp -s $testroot/stderr.expected $testroot/stderr
1224 ret="$?"
1225 if [ "$ret" != "0" ]; then
1226 diff -u $testroot/stderr.expected $testroot/stderr
1227 test_done "$testroot" "$ret"
1228 return 1
1230 test_done "$testroot" "$ret"
1233 function test_update_partial_dir {
1234 local testroot=`test_init update_partial_dir`
1236 got checkout $testroot/repo $testroot/wt > /dev/null
1237 ret="$?"
1238 if [ "$ret" != "0" ]; then
1239 test_done "$testroot" "$ret"
1240 return 1
1243 echo "modified alpha" > $testroot/repo/alpha
1244 echo "modified beta" > $testroot/repo/beta
1245 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1246 git_commit $testroot/repo -m "modified two files"
1248 echo "U epsilon/zeta" > $testroot/stdout.expected
1249 echo -n "Updated to commit " >> $testroot/stdout.expected
1250 git_show_head $testroot/repo >> $testroot/stdout.expected
1251 echo >> $testroot/stdout.expected
1253 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1255 cmp -s $testroot/stdout.expected $testroot/stdout
1256 ret="$?"
1257 if [ "$ret" != "0" ]; then
1258 diff -u $testroot/stdout.expected $testroot/stdout
1259 test_done "$testroot" "$ret"
1260 return 1
1263 echo "modified epsilon/zeta" > $testroot/content.expected
1264 cat $testroot/wt/epsilon/zeta > $testroot/content
1266 cmp -s $testroot/content.expected $testroot/content
1267 ret="$?"
1268 if [ "$ret" != "0" ]; then
1269 diff -u $testroot/content.expected $testroot/content
1270 test_done "$testroot" "$ret"
1271 return 1
1273 test_done "$testroot" "$ret"
1277 function test_update_moved_branch_ref {
1278 local testroot=`test_init update_moved_branch_ref`
1280 git clone -q --mirror $testroot/repo $testroot/repo2
1282 echo "modified alpha with git" > $testroot/repo/alpha
1283 git_commit $testroot/repo -m "modified alpha with git"
1285 got checkout $testroot/repo2 $testroot/wt > /dev/null
1286 ret="$?"
1287 if [ "$ret" != "0" ]; then
1288 test_done "$testroot" "$ret"
1289 return 1
1292 echo "modified alpha with got" > $testroot/wt/alpha
1293 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1295 # + xxxxxxx...yyyyyyy master -> master (forced update)
1296 (cd $testroot/repo2 && git fetch -q --all)
1298 echo -n > $testroot/stdout.expected
1299 echo -n "got: work tree's head reference now points to a different " \
1300 > $testroot/stderr.expected
1301 echo "branch; new head reference and/or update -b required" \
1302 >> $testroot/stderr.expected
1304 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1306 cmp -s $testroot/stdout.expected $testroot/stdout
1307 ret="$?"
1308 if [ "$ret" != "0" ]; then
1309 diff -u $testroot/stdout.expected $testroot/stdout
1310 test_done "$testroot" "$ret"
1311 return 1
1314 cmp -s $testroot/stderr.expected $testroot/stderr
1315 ret="$?"
1316 if [ "$ret" != "0" ]; then
1317 diff -u $testroot/stderr.expected $testroot/stderr
1319 test_done "$testroot" "$ret"
1322 function test_update_to_another_branch {
1323 local testroot=`test_init update_to_another_branch`
1325 got checkout $testroot/repo $testroot/wt > /dev/null
1326 ret="$?"
1327 if [ "$ret" != "0" ]; then
1328 test_done "$testroot" "$ret"
1329 return 1
1332 echo 'refs/heads/master'> $testroot/head-ref.expected
1333 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1334 ret="$?"
1335 if [ "$ret" != "0" ]; then
1336 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1337 test_done "$testroot" "$ret"
1338 return 1
1341 (cd $testroot/repo && git checkout -q -b newbranch)
1342 echo "modified alpha on new branch" > $testroot/repo/alpha
1343 git_commit $testroot/repo -m "modified alpha on new branch"
1345 echo "modified alpha in work tree" > $testroot/wt/alpha
1347 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1348 echo "C alpha" >> $testroot/stdout.expected
1349 echo -n "Updated to commit " >> $testroot/stdout.expected
1350 git_show_head $testroot/repo >> $testroot/stdout.expected
1351 echo >> $testroot/stdout.expected
1353 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1355 cmp -s $testroot/stdout.expected $testroot/stdout
1356 ret="$?"
1357 if [ "$ret" != "0" ]; then
1358 diff -u $testroot/stdout.expected $testroot/stdout
1359 test_done "$testroot" "$ret"
1360 return 1
1363 echo -n "<<<<<<< commit " > $testroot/content.expected
1364 git_show_head $testroot/repo >> $testroot/content.expected
1365 echo >> $testroot/content.expected
1366 echo "modified alpha on new branch" >> $testroot/content.expected
1367 echo "=======" >> $testroot/content.expected
1368 echo "modified alpha in work tree" >> $testroot/content.expected
1369 echo '>>>>>>> alpha' >> $testroot/content.expected
1371 cat $testroot/wt/alpha > $testroot/content
1373 cmp -s $testroot/content.expected $testroot/content
1374 ret="$?"
1375 if [ "$ret" != "0" ]; then
1376 diff -u $testroot/content.expected $testroot/content
1377 test_done "$testroot" "$ret"
1378 return 1
1381 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1382 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1383 ret="$?"
1384 if [ "$ret" != "0" ]; then
1385 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1386 test_done "$testroot" "$ret"
1387 return 1
1390 test_done "$testroot" "$ret"
1393 function test_update_to_commit_on_wrong_branch {
1394 local testroot=`test_init update_to_commit_on_wrong_branch`
1396 got checkout $testroot/repo $testroot/wt > /dev/null
1397 ret="$?"
1398 if [ "$ret" != "0" ]; then
1399 test_done "$testroot" "$ret"
1400 return 1
1403 (cd $testroot/repo && git checkout -q -b newbranch)
1404 echo "modified alpha on new branch" > $testroot/repo/alpha
1405 git_commit $testroot/repo -m "modified alpha on new branch"
1407 echo -n "" > $testroot/stdout.expected
1408 echo "got: target commit is on a different branch" \
1409 > $testroot/stderr.expected
1411 local head_rev=`git_show_head $testroot/repo`
1412 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1413 2> $testroot/stderr)
1415 cmp -s $testroot/stdout.expected $testroot/stdout
1416 ret="$?"
1417 if [ "$ret" != "0" ]; then
1418 diff -u $testroot/stdout.expected $testroot/stdout
1419 test_done "$testroot" "$ret"
1420 return 1
1423 cmp -s $testroot/stderr.expected $testroot/stderr
1424 ret="$?"
1425 if [ "$ret" != "0" ]; then
1426 diff -u $testroot/stderr.expected $testroot/stderr
1427 test_done "$testroot" "$ret"
1428 return 1
1431 test_done "$testroot" "$ret"
1434 function test_update_bumps_base_commit_id {
1435 local testroot=`test_init update_bumps_base_commit_id`
1437 echo "psi" > $testroot/repo/epsilon/psi
1438 (cd $testroot/repo && git add .)
1439 git_commit $testroot/repo -m "adding another file"
1441 got checkout $testroot/repo $testroot/wt > /dev/null
1442 ret="$?"
1443 if [ "$ret" != "0" ]; then
1444 test_done "$testroot" "$ret"
1445 return 1
1448 echo "modified psi" > $testroot/wt/epsilon/psi
1449 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1451 local head_rev=`git_show_head $testroot/repo`
1452 echo "M epsilon/psi" > $testroot/stdout.expected
1453 echo "Created commit $head_rev" >> $testroot/stdout.expected
1454 cmp -s $testroot/stdout.expected $testroot/stdout
1455 ret="$?"
1456 if [ "$ret" != "0" ]; then
1457 diff -u $testroot/stdout.expected $testroot/stdout
1458 test_done "$testroot" "$ret"
1459 return 1
1462 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1463 (cd $testroot/repo && git add .)
1464 git_commit $testroot/repo -m "changing zeta with git"
1466 echo "modified zeta" > $testroot/wt/epsilon/zeta
1467 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1468 2> $testroot/stderr)
1470 echo -n "" > $testroot/stdout.expected
1471 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1472 cmp -s $testroot/stderr.expected $testroot/stderr
1473 ret="$?"
1474 if [ "$ret" != "0" ]; then
1475 diff -u $testroot/stderr.expected $testroot/stderr
1476 test_done "$testroot" "$ret"
1477 return 1
1480 (cd $testroot/wt && got update > $testroot/stdout)
1482 echo "U epsilon/psi" > $testroot/stdout.expected
1483 echo "C epsilon/zeta" >> $testroot/stdout.expected
1484 echo -n "Updated to commit " >> $testroot/stdout.expected
1485 git_show_head $testroot/repo >> $testroot/stdout.expected
1486 echo >> $testroot/stdout.expected
1487 cmp -s $testroot/stdout.expected $testroot/stdout
1488 ret="$?"
1489 if [ "$ret" != "0" ]; then
1490 diff -u $testroot/stdout.expected $testroot/stdout
1491 test_done "$testroot" "$ret"
1492 return 1
1495 # resolve conflict
1496 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1498 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1500 local head_rev=`git_show_head $testroot/repo`
1501 echo "M epsilon/zeta" > $testroot/stdout.expected
1502 echo "Created commit $head_rev" >> $testroot/stdout.expected
1503 cmp -s $testroot/stdout.expected $testroot/stdout
1504 ret="$?"
1505 if [ "$ret" != "0" ]; then
1506 diff -u $testroot/stdout.expected $testroot/stdout
1507 test_done "$testroot" "$ret"
1508 return 1
1511 test_done "$testroot" "$ret"
1514 run_test test_update_basic
1515 run_test test_update_adds_file
1516 run_test test_update_deletes_file
1517 run_test test_update_deletes_dir
1518 run_test test_update_deletes_dir_with_path_prefix
1519 run_test test_update_deletes_dir_recursively
1520 run_test test_update_sibling_dirs_with_common_prefix
1521 run_test test_update_dir_with_dot_sibling
1522 run_test test_update_moves_files_upwards
1523 run_test test_update_moves_files_to_new_dir
1524 run_test test_update_creates_missing_parent
1525 run_test test_update_creates_missing_parent_with_subdir
1526 run_test test_update_file_in_subsubdir
1527 run_test test_update_merges_file_edits
1528 run_test test_update_keeps_xbit
1529 run_test test_update_clears_xbit
1530 run_test test_update_restores_missing_file
1531 run_test test_update_conflict_wt_add_vs_repo_add
1532 run_test test_update_conflict_wt_edit_vs_repo_rm
1533 run_test test_update_conflict_wt_rm_vs_repo_edit
1534 run_test test_update_conflict_wt_rm_vs_repo_rm
1535 run_test test_update_partial
1536 run_test test_update_partial_add
1537 run_test test_update_partial_rm
1538 run_test test_update_partial_dir
1539 run_test test_update_moved_branch_ref
1540 run_test test_update_to_another_branch
1541 run_test test_update_to_commit_on_wrong_branch
1542 run_test test_update_bumps_base_commit_id