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 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 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 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 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 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 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 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 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 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 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 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 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 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 test_update_merges_file_edits() {
633 local testroot=`test_init update_merges_file_edits`
635 echo "1" > $testroot/repo/numbers
636 echo "2" >> $testroot/repo/numbers
637 echo "3" >> $testroot/repo/numbers
638 echo "4" >> $testroot/repo/numbers
639 echo "5" >> $testroot/repo/numbers
640 echo "6" >> $testroot/repo/numbers
641 echo "7" >> $testroot/repo/numbers
642 echo "8" >> $testroot/repo/numbers
643 (cd $testroot/repo && git add numbers)
644 git_commit $testroot/repo -m "added numbers file"
645 local base_commit=`git_show_head $testroot/repo`
647 got checkout $testroot/repo $testroot/wt > /dev/null
648 ret="$?"
649 if [ "$ret" != "0" ]; then
650 test_done "$testroot" "$ret"
651 return 1
652 fi
654 echo "modified alpha" > $testroot/repo/alpha
655 echo "modified beta" > $testroot/repo/beta
656 sed -i 's/2/22/' $testroot/repo/numbers
657 git_commit $testroot/repo -m "modified 3 files"
659 echo "modified alpha, too" > $testroot/wt/alpha
660 touch $testroot/wt/beta
661 sed -i 's/7/77/' $testroot/wt/numbers
663 echo "C alpha" > $testroot/stdout.expected
664 echo "U beta" >> $testroot/stdout.expected
665 echo "G numbers" >> $testroot/stdout.expected
666 echo -n "Updated to commit " >> $testroot/stdout.expected
667 git_show_head $testroot/repo >> $testroot/stdout.expected
668 echo >> $testroot/stdout.expected
669 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
671 (cd $testroot/wt && got update > $testroot/stdout)
673 cmp -s $testroot/stdout.expected $testroot/stdout
674 ret="$?"
675 if [ "$ret" != "0" ]; then
676 diff -u $testroot/stdout.expected $testroot/stdout
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
682 git_show_head $testroot/repo >> $testroot/content.expected
683 echo >> $testroot/content.expected
684 echo "modified alpha" >> $testroot/content.expected
685 echo "||||||| 3-way merge base: commit $base_commit" \
686 >> $testroot/content.expected
687 echo "alpha" >> $testroot/content.expected
688 echo "=======" >> $testroot/content.expected
689 echo "modified alpha, too" >> $testroot/content.expected
690 echo '>>>>>>>' >> $testroot/content.expected
691 echo "modified beta" >> $testroot/content.expected
692 echo "1" >> $testroot/content.expected
693 echo "22" >> $testroot/content.expected
694 echo "3" >> $testroot/content.expected
695 echo "4" >> $testroot/content.expected
696 echo "5" >> $testroot/content.expected
697 echo "6" >> $testroot/content.expected
698 echo "77" >> $testroot/content.expected
699 echo "8" >> $testroot/content.expected
701 cat $testroot/wt/alpha > $testroot/content
702 cat $testroot/wt/beta >> $testroot/content
703 cat $testroot/wt/numbers >> $testroot/content
705 cmp -s $testroot/content.expected $testroot/content
706 ret="$?"
707 if [ "$ret" != "0" ]; then
708 diff -u $testroot/content.expected $testroot/content
709 fi
710 test_done "$testroot" "$ret"
713 test_update_keeps_xbit() {
714 local testroot=`test_init update_keeps_xbit 1`
716 touch $testroot/repo/xfile
717 chmod +x $testroot/repo/xfile
718 (cd $testroot/repo && git add .)
719 git_commit $testroot/repo -m "adding executable file"
721 got checkout $testroot/repo $testroot/wt > $testroot/stdout
722 ret="$?"
723 if [ "$ret" != "0" ]; then
724 test_done "$testroot" "$ret"
725 return 1
726 fi
728 echo foo > $testroot/repo/xfile
729 git_commit $testroot/repo -m "changed executable file"
731 echo "U xfile" > $testroot/stdout.expected
732 echo -n "Updated to commit " >> $testroot/stdout.expected
733 git_show_head $testroot/repo >> $testroot/stdout.expected
734 echo >> $testroot/stdout.expected
736 (cd $testroot/wt && got update > $testroot/stdout)
737 ret="$?"
738 if [ "$ret" != "0" ]; then
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 cmp -s $testroot/stdout.expected $testroot/stdout
744 ret="$?"
745 if [ "$ret" != "0" ]; then
746 diff -u $testroot/stdout.expected $testroot/stdout
747 test_done "$testroot" "$ret"
748 return 1
749 fi
751 ls -l $testroot/wt/xfile | grep -q '^-rwx'
752 ret="$?"
753 if [ "$ret" != "0" ]; then
754 echo "file is not executable" >&2
755 ls -l $testroot/wt/xfile >&2
756 fi
757 test_done "$testroot" "$ret"
760 test_update_clears_xbit() {
761 local testroot=`test_init update_clears_xbit 1`
763 touch $testroot/repo/xfile
764 chmod +x $testroot/repo/xfile
765 (cd $testroot/repo && git add .)
766 git_commit $testroot/repo -m "adding executable file"
768 got checkout $testroot/repo $testroot/wt > $testroot/stdout
769 ret="$?"
770 if [ "$ret" != "0" ]; then
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 ls -l $testroot/wt/xfile | grep -q '^-rwx'
776 ret="$?"
777 if [ "$ret" != "0" ]; then
778 echo "file is not executable" >&2
779 ls -l $testroot/wt/xfile >&2
780 test_done "$testroot" "$ret"
781 return 1
782 fi
784 # XXX git seems to require a file edit when flipping the x bit?
785 echo foo > $testroot/repo/xfile
786 chmod -x $testroot/repo/xfile
787 git_commit $testroot/repo -m "not an executable file anymore"
789 echo "U xfile" > $testroot/stdout.expected
790 echo -n "Updated to commit " >> $testroot/stdout.expected
791 git_show_head $testroot/repo >> $testroot/stdout.expected
792 echo >> $testroot/stdout.expected
794 (cd $testroot/wt && got update > $testroot/stdout)
795 ret="$?"
796 if [ "$ret" != "0" ]; then
797 test_done "$testroot" "$ret"
798 return 1
799 fi
801 cmp -s $testroot/stdout.expected $testroot/stdout
802 ret="$?"
803 if [ "$ret" != "0" ]; then
804 diff -u $testroot/stdout.expected $testroot/stdout
805 test_done "$testroot" "$ret"
806 return 1
807 fi
809 ls -l $testroot/wt/xfile | grep -q '^-rw-'
810 ret="$?"
811 if [ "$ret" != "0" ]; then
812 echo "file is unexpectedly executable" >&2
813 ls -l $testroot/wt/xfile >&2
814 fi
815 test_done "$testroot" "$ret"
818 test_update_restores_missing_file() {
819 local testroot=`test_init update_restores_missing_file`
821 got checkout $testroot/repo $testroot/wt > /dev/null
822 ret="$?"
823 if [ "$ret" != "0" ]; then
824 test_done "$testroot" "$ret"
825 return 1
826 fi
828 rm $testroot/wt/alpha
830 echo "! alpha" > $testroot/stdout.expected
831 echo -n "Updated to commit " >> $testroot/stdout.expected
832 git_show_head $testroot/repo >> $testroot/stdout.expected
833 echo >> $testroot/stdout.expected
834 (cd $testroot/wt && got update > $testroot/stdout)
836 cmp -s $testroot/stdout.expected $testroot/stdout
837 ret="$?"
838 if [ "$ret" != "0" ]; then
839 diff -u $testroot/stdout.expected $testroot/stdout
840 test_done "$testroot" "$ret"
841 return 1
842 fi
844 echo "alpha" > $testroot/content.expected
846 cat $testroot/wt/alpha > $testroot/content
848 cmp -s $testroot/content.expected $testroot/content
849 ret="$?"
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/content.expected $testroot/content
852 fi
853 test_done "$testroot" "$ret"
856 test_update_conflict_wt_add_vs_repo_add() {
857 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
859 got checkout $testroot/repo $testroot/wt > /dev/null
860 ret="$?"
861 if [ "$ret" != "0" ]; then
862 test_done "$testroot" "$ret"
863 return 1
864 fi
866 echo "new" > $testroot/repo/gamma/new
867 (cd $testroot/repo && git add .)
868 git_commit $testroot/repo -m "adding a new file"
870 echo "also new" > $testroot/wt/gamma/new
871 (cd $testroot/wt && got add gamma/new >/dev/null)
873 (cd $testroot/wt && got update > $testroot/stdout)
875 echo "C gamma/new" > $testroot/stdout.expected
876 echo -n "Updated to commit " >> $testroot/stdout.expected
877 git_show_head $testroot/repo >> $testroot/stdout.expected
878 echo >> $testroot/stdout.expected
879 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
881 cmp -s $testroot/stdout.expected $testroot/stdout
882 ret="$?"
883 if [ "$ret" != "0" ]; then
884 diff -u $testroot/stdout.expected $testroot/stdout
885 test_done "$testroot" "$ret"
886 return 1
887 fi
889 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
890 git_show_head $testroot/repo >> $testroot/content.expected
891 echo >> $testroot/content.expected
892 echo "new" >> $testroot/content.expected
893 echo "=======" >> $testroot/content.expected
894 echo "also new" >> $testroot/content.expected
895 echo '>>>>>>>' >> $testroot/content.expected
897 cat $testroot/wt/gamma/new > $testroot/content
899 cmp -s $testroot/content.expected $testroot/content
900 ret="$?"
901 if [ "$ret" != "0" ]; then
902 diff -u $testroot/content.expected $testroot/content
903 test_done "$testroot" "$ret"
904 return 1
905 fi
907 # resolve the conflict
908 echo "new and also new" > $testroot/wt/gamma/new
909 echo 'M gamma/new' > $testroot/stdout.expected
910 (cd $testroot/wt && got status > $testroot/stdout)
911 cmp -s $testroot/stdout.expected $testroot/stdout
912 ret="$?"
913 if [ "$ret" != "0" ]; then
914 diff -u $testroot/stdout.expected $testroot/stdout
915 fi
916 test_done "$testroot" "$ret"
919 test_update_conflict_wt_edit_vs_repo_rm() {
920 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
922 got checkout $testroot/repo $testroot/wt > /dev/null
923 ret="$?"
924 if [ "$ret" != "0" ]; then
925 test_done "$testroot" "$ret"
926 return 1
927 fi
929 (cd $testroot/repo && git rm -q beta)
930 git_commit $testroot/repo -m "removing a file"
932 echo "modified beta" > $testroot/wt/beta
934 (cd $testroot/wt && got update > $testroot/stdout)
936 echo "G beta" > $testroot/stdout.expected
937 echo -n "Updated to commit " >> $testroot/stdout.expected
938 git_show_head $testroot/repo >> $testroot/stdout.expected
939 echo >> $testroot/stdout.expected
940 cmp -s $testroot/stdout.expected $testroot/stdout
941 ret="$?"
942 if [ "$ret" != "0" ]; then
943 diff -u $testroot/stdout.expected $testroot/stdout
944 test_done "$testroot" "$ret"
945 return 1
946 fi
948 echo "modified beta" > $testroot/content.expected
950 cat $testroot/wt/beta > $testroot/content
952 cmp -s $testroot/content.expected $testroot/content
953 ret="$?"
954 if [ "$ret" != "0" ]; then
955 diff -u $testroot/content.expected $testroot/content
956 test_done "$testroot" "$ret"
957 return 1
958 fi
960 # beta is now an added file... we don't flag tree conflicts yet
961 echo 'A beta' > $testroot/stdout.expected
962 (cd $testroot/wt && got status > $testroot/stdout)
963 cmp -s $testroot/stdout.expected $testroot/stdout
964 ret="$?"
965 if [ "$ret" != "0" ]; then
966 diff -u $testroot/stdout.expected $testroot/stdout
967 fi
968 test_done "$testroot" "$ret"
971 test_update_conflict_wt_rm_vs_repo_edit() {
972 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
974 got checkout $testroot/repo $testroot/wt > /dev/null
975 ret="$?"
976 if [ "$ret" != "0" ]; then
977 test_done "$testroot" "$ret"
978 return 1
979 fi
981 echo "modified beta" > $testroot/repo/beta
982 git_commit $testroot/repo -m "modified a file"
984 (cd $testroot/wt && got rm beta > /dev/null)
986 (cd $testroot/wt && got update > $testroot/stdout)
988 echo "G beta" > $testroot/stdout.expected
989 echo -n "Updated to commit " >> $testroot/stdout.expected
990 git_show_head $testroot/repo >> $testroot/stdout.expected
991 echo >> $testroot/stdout.expected
992 cmp -s $testroot/stdout.expected $testroot/stdout
993 ret="$?"
994 if [ "$ret" != "0" ]; then
995 diff -u $testroot/stdout.expected $testroot/stdout
996 test_done "$testroot" "$ret"
997 return 1
998 fi
1000 # beta remains a deleted file... we don't flag tree conflicts yet
1001 echo 'D beta' > $testroot/stdout.expected
1002 (cd $testroot/wt && got status > $testroot/stdout)
1003 cmp -s $testroot/stdout.expected $testroot/stdout
1004 ret="$?"
1005 if [ "$ret" != "0" ]; then
1006 diff -u $testroot/stdout.expected $testroot/stdout
1007 test_done "$testroot" "$ret"
1008 return 1
1011 # 'got diff' should show post-update contents of beta being deleted
1012 local head_rev=`git_show_head $testroot/repo`
1013 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
1014 echo -n 'blob - ' >> $testroot/stdout.expected
1015 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1016 >> $testroot/stdout.expected
1017 echo 'file + /dev/null' >> $testroot/stdout.expected
1018 echo '--- beta' >> $testroot/stdout.expected
1019 echo '+++ /dev/null' >> $testroot/stdout.expected
1020 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1021 echo '-modified beta' >> $testroot/stdout.expected
1023 (cd $testroot/wt && got diff > $testroot/stdout)
1024 cmp -s $testroot/stdout.expected $testroot/stdout
1025 ret="$?"
1026 if [ "$ret" != "0" ]; then
1027 diff -u $testroot/stdout.expected $testroot/stdout
1029 test_done "$testroot" "$ret"
1032 test_update_conflict_wt_rm_vs_repo_rm() {
1033 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1035 got checkout $testroot/repo $testroot/wt > /dev/null
1036 ret="$?"
1037 if [ "$ret" != "0" ]; then
1038 test_done "$testroot" "$ret"
1039 return 1
1042 (cd $testroot/repo && git rm -q beta)
1043 git_commit $testroot/repo -m "removing a file"
1045 (cd $testroot/wt && got rm beta > /dev/null)
1047 (cd $testroot/wt && got update > $testroot/stdout)
1049 echo "D beta" > $testroot/stdout.expected
1050 echo -n "Updated to commit " >> $testroot/stdout.expected
1051 git_show_head $testroot/repo >> $testroot/stdout.expected
1052 echo >> $testroot/stdout.expected
1053 cmp -s $testroot/stdout.expected $testroot/stdout
1054 ret="$?"
1055 if [ "$ret" != "0" ]; then
1056 diff -u $testroot/stdout.expected $testroot/stdout
1057 test_done "$testroot" "$ret"
1058 return 1
1061 # beta is now gone... we don't flag tree conflicts yet
1062 echo "N beta" > $testroot/stdout.expected
1063 echo -n > $testroot/stderr.expected
1064 (cd $testroot/wt && got status beta > $testroot/stdout \
1065 2> $testroot/stderr)
1066 cmp -s $testroot/stdout.expected $testroot/stdout
1067 ret="$?"
1068 if [ "$ret" != "0" ]; then
1069 diff -u $testroot/stdout.expected $testroot/stdout
1070 test_done "$testroot" "$ret"
1071 return 1
1073 cmp -s $testroot/stderr.expected $testroot/stderr
1074 ret="$?"
1075 if [ "$ret" != "0" ]; then
1076 diff -u $testroot/stderr.expected $testroot/stderr
1077 test_done "$testroot" "$ret"
1078 return 1
1081 if [ -e $testroot/wt/beta ]; then
1082 echo "removed file beta still exists on disk" >&2
1083 test_done "$testroot" "1"
1084 return 1
1087 test_done "$testroot" "0"
1090 test_update_partial() {
1091 local testroot=`test_init update_partial`
1093 got checkout $testroot/repo $testroot/wt > /dev/null
1094 ret="$?"
1095 if [ "$ret" != "0" ]; then
1096 test_done "$testroot" "$ret"
1097 return 1
1100 echo "modified alpha" > $testroot/repo/alpha
1101 echo "modified beta" > $testroot/repo/beta
1102 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1103 git_commit $testroot/repo -m "modified two files"
1105 echo "U alpha" > $testroot/stdout.expected
1106 echo "U beta" >> $testroot/stdout.expected
1107 echo -n "Updated to commit " >> $testroot/stdout.expected
1108 git_show_head $testroot/repo >> $testroot/stdout.expected
1109 echo >> $testroot/stdout.expected
1111 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1114 ret="$?"
1115 if [ "$ret" != "0" ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1117 test_done "$testroot" "$ret"
1118 return 1
1121 echo "modified alpha" > $testroot/content.expected
1122 echo "modified beta" >> $testroot/content.expected
1124 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1125 cmp -s $testroot/content.expected $testroot/content
1126 ret="$?"
1127 if [ "$ret" != "0" ]; then
1128 diff -u $testroot/content.expected $testroot/content
1129 test_done "$testroot" "$ret"
1130 return 1
1133 echo "U epsilon/zeta" > $testroot/stdout.expected
1134 echo -n "Updated to commit " >> $testroot/stdout.expected
1135 git_show_head $testroot/repo >> $testroot/stdout.expected
1136 echo >> $testroot/stdout.expected
1138 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1140 cmp -s $testroot/stdout.expected $testroot/stdout
1141 ret="$?"
1142 if [ "$ret" != "0" ]; then
1143 diff -u $testroot/stdout.expected $testroot/stdout
1144 test_done "$testroot" "$ret"
1145 return 1
1148 echo "modified epsilon/zeta" > $testroot/content.expected
1149 cat $testroot/wt/epsilon/zeta > $testroot/content
1151 cmp -s $testroot/content.expected $testroot/content
1152 ret="$?"
1153 if [ "$ret" != "0" ]; then
1154 diff -u $testroot/content.expected $testroot/content
1155 test_done "$testroot" "$ret"
1156 return 1
1159 test_done "$testroot" "$ret"
1162 test_update_partial_add() {
1163 local testroot=`test_init update_partial_add`
1165 got checkout $testroot/repo $testroot/wt > /dev/null
1166 ret="$?"
1167 if [ "$ret" != "0" ]; then
1168 test_done "$testroot" "$ret"
1169 return 1
1172 echo "new" > $testroot/repo/new
1173 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1174 (cd $testroot/repo && git add .)
1175 git_commit $testroot/repo -m "added two files"
1177 echo "A new" > $testroot/stdout.expected
1178 echo "A epsilon/new2" >> $testroot/stdout.expected
1179 echo -n "Updated to commit " >> $testroot/stdout.expected
1180 git_show_head $testroot/repo >> $testroot/stdout.expected
1181 echo >> $testroot/stdout.expected
1183 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1185 cmp -s $testroot/stdout.expected $testroot/stdout
1186 ret="$?"
1187 if [ "$ret" != "0" ]; then
1188 diff -u $testroot/stdout.expected $testroot/stdout
1189 test_done "$testroot" "$ret"
1190 return 1
1193 echo "new" > $testroot/content.expected
1194 echo "epsilon/new2" >> $testroot/content.expected
1196 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1198 cmp -s $testroot/content.expected $testroot/content
1199 ret="$?"
1200 if [ "$ret" != "0" ]; then
1201 diff -u $testroot/content.expected $testroot/content
1203 test_done "$testroot" "$ret"
1206 test_update_partial_rm() {
1207 local testroot=`test_init update_partial_rm`
1209 got checkout $testroot/repo $testroot/wt > /dev/null
1210 ret="$?"
1211 if [ "$ret" != "0" ]; then
1212 test_done "$testroot" "$ret"
1213 return 1
1216 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1217 git_commit $testroot/repo -m "removed two files"
1219 echo "got: /alpha: no such entry found in tree" \
1220 > $testroot/stderr.expected
1222 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1223 ret="$?"
1224 if [ "$ret" == "0" ]; then
1225 echo "update succeeded unexpectedly" >&2
1226 test_done "$testroot" "1"
1227 return 1
1230 cmp -s $testroot/stderr.expected $testroot/stderr
1231 ret="$?"
1232 if [ "$ret" != "0" ]; then
1233 diff -u $testroot/stderr.expected $testroot/stderr
1234 test_done "$testroot" "$ret"
1235 return 1
1237 test_done "$testroot" "$ret"
1240 test_update_partial_dir() {
1241 local testroot=`test_init update_partial_dir`
1243 got checkout $testroot/repo $testroot/wt > /dev/null
1244 ret="$?"
1245 if [ "$ret" != "0" ]; then
1246 test_done "$testroot" "$ret"
1247 return 1
1250 echo "modified alpha" > $testroot/repo/alpha
1251 echo "modified beta" > $testroot/repo/beta
1252 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1253 git_commit $testroot/repo -m "modified two files"
1255 echo "U epsilon/zeta" > $testroot/stdout.expected
1256 echo -n "Updated to commit " >> $testroot/stdout.expected
1257 git_show_head $testroot/repo >> $testroot/stdout.expected
1258 echo >> $testroot/stdout.expected
1260 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1262 cmp -s $testroot/stdout.expected $testroot/stdout
1263 ret="$?"
1264 if [ "$ret" != "0" ]; then
1265 diff -u $testroot/stdout.expected $testroot/stdout
1266 test_done "$testroot" "$ret"
1267 return 1
1270 echo "modified epsilon/zeta" > $testroot/content.expected
1271 cat $testroot/wt/epsilon/zeta > $testroot/content
1273 cmp -s $testroot/content.expected $testroot/content
1274 ret="$?"
1275 if [ "$ret" != "0" ]; then
1276 diff -u $testroot/content.expected $testroot/content
1277 test_done "$testroot" "$ret"
1278 return 1
1280 test_done "$testroot" "$ret"
1284 test_update_moved_branch_ref() {
1285 local testroot=`test_init update_moved_branch_ref`
1287 git clone -q --mirror $testroot/repo $testroot/repo2
1289 echo "modified alpha with git" > $testroot/repo/alpha
1290 git_commit $testroot/repo -m "modified alpha with git"
1292 got checkout $testroot/repo2 $testroot/wt > /dev/null
1293 ret="$?"
1294 if [ "$ret" != "0" ]; then
1295 test_done "$testroot" "$ret"
1296 return 1
1299 echo "modified alpha with got" > $testroot/wt/alpha
1300 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1302 # + xxxxxxx...yyyyyyy master -> master (forced update)
1303 (cd $testroot/repo2 && git fetch -q --all)
1305 echo -n > $testroot/stdout.expected
1306 echo -n "got: work tree's head reference now points to a different " \
1307 > $testroot/stderr.expected
1308 echo "branch; new head reference and/or update -b required" \
1309 >> $testroot/stderr.expected
1311 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1313 cmp -s $testroot/stdout.expected $testroot/stdout
1314 ret="$?"
1315 if [ "$ret" != "0" ]; then
1316 diff -u $testroot/stdout.expected $testroot/stdout
1317 test_done "$testroot" "$ret"
1318 return 1
1321 cmp -s $testroot/stderr.expected $testroot/stderr
1322 ret="$?"
1323 if [ "$ret" != "0" ]; then
1324 diff -u $testroot/stderr.expected $testroot/stderr
1326 test_done "$testroot" "$ret"
1329 test_update_to_another_branch() {
1330 local testroot=`test_init update_to_another_branch`
1331 local base_commit=`git_show_head $testroot/repo`
1333 got checkout $testroot/repo $testroot/wt > /dev/null
1334 ret="$?"
1335 if [ "$ret" != "0" ]; then
1336 test_done "$testroot" "$ret"
1337 return 1
1340 echo 'refs/heads/master'> $testroot/head-ref.expected
1341 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1342 ret="$?"
1343 if [ "$ret" != "0" ]; then
1344 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1345 test_done "$testroot" "$ret"
1346 return 1
1349 (cd $testroot/repo && git checkout -q -b newbranch)
1350 echo "modified alpha on new branch" > $testroot/repo/alpha
1351 git_commit $testroot/repo -m "modified alpha on new branch"
1353 echo "modified alpha in work tree" > $testroot/wt/alpha
1355 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1356 echo "C alpha" >> $testroot/stdout.expected
1357 echo -n "Updated to commit " >> $testroot/stdout.expected
1358 git_show_head $testroot/repo >> $testroot/stdout.expected
1359 echo >> $testroot/stdout.expected
1360 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1362 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1364 cmp -s $testroot/stdout.expected $testroot/stdout
1365 ret="$?"
1366 if [ "$ret" != "0" ]; then
1367 diff -u $testroot/stdout.expected $testroot/stdout
1368 test_done "$testroot" "$ret"
1369 return 1
1372 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
1373 git_show_head $testroot/repo >> $testroot/content.expected
1374 echo >> $testroot/content.expected
1375 echo "modified alpha on new branch" >> $testroot/content.expected
1376 echo "||||||| 3-way merge base: commit $base_commit" \
1377 >> $testroot/content.expected
1378 echo "alpha" >> $testroot/content.expected
1379 echo "=======" >> $testroot/content.expected
1380 echo "modified alpha in work tree" >> $testroot/content.expected
1381 echo '>>>>>>>' >> $testroot/content.expected
1383 cat $testroot/wt/alpha > $testroot/content
1385 cmp -s $testroot/content.expected $testroot/content
1386 ret="$?"
1387 if [ "$ret" != "0" ]; then
1388 diff -u $testroot/content.expected $testroot/content
1389 test_done "$testroot" "$ret"
1390 return 1
1393 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1394 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1395 ret="$?"
1396 if [ "$ret" != "0" ]; then
1397 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1398 test_done "$testroot" "$ret"
1399 return 1
1402 test_done "$testroot" "$ret"
1405 test_update_to_commit_on_wrong_branch() {
1406 local testroot=`test_init update_to_commit_on_wrong_branch`
1408 got checkout $testroot/repo $testroot/wt > /dev/null
1409 ret="$?"
1410 if [ "$ret" != "0" ]; then
1411 test_done "$testroot" "$ret"
1412 return 1
1415 (cd $testroot/repo && git checkout -q -b newbranch)
1416 echo "modified alpha on new branch" > $testroot/repo/alpha
1417 git_commit $testroot/repo -m "modified alpha on new branch"
1419 echo -n "" > $testroot/stdout.expected
1420 echo "got: target commit is on a different branch" \
1421 > $testroot/stderr.expected
1423 local head_rev=`git_show_head $testroot/repo`
1424 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1425 2> $testroot/stderr)
1427 cmp -s $testroot/stdout.expected $testroot/stdout
1428 ret="$?"
1429 if [ "$ret" != "0" ]; then
1430 diff -u $testroot/stdout.expected $testroot/stdout
1431 test_done "$testroot" "$ret"
1432 return 1
1435 cmp -s $testroot/stderr.expected $testroot/stderr
1436 ret="$?"
1437 if [ "$ret" != "0" ]; then
1438 diff -u $testroot/stderr.expected $testroot/stderr
1439 test_done "$testroot" "$ret"
1440 return 1
1443 test_done "$testroot" "$ret"
1446 test_update_bumps_base_commit_id() {
1447 local testroot=`test_init update_bumps_base_commit_id`
1449 echo "psi" > $testroot/repo/epsilon/psi
1450 (cd $testroot/repo && git add .)
1451 git_commit $testroot/repo -m "adding another file"
1453 got checkout $testroot/repo $testroot/wt > /dev/null
1454 ret="$?"
1455 if [ "$ret" != "0" ]; then
1456 test_done "$testroot" "$ret"
1457 return 1
1460 echo "modified psi" > $testroot/wt/epsilon/psi
1461 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1463 local head_rev=`git_show_head $testroot/repo`
1464 echo "M epsilon/psi" > $testroot/stdout.expected
1465 echo "Created commit $head_rev" >> $testroot/stdout.expected
1466 cmp -s $testroot/stdout.expected $testroot/stdout
1467 ret="$?"
1468 if [ "$ret" != "0" ]; then
1469 diff -u $testroot/stdout.expected $testroot/stdout
1470 test_done "$testroot" "$ret"
1471 return 1
1474 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1475 (cd $testroot/repo && git add .)
1476 git_commit $testroot/repo -m "changing zeta with git"
1478 echo "modified zeta" > $testroot/wt/epsilon/zeta
1479 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1480 2> $testroot/stderr)
1482 echo -n "" > $testroot/stdout.expected
1483 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1484 cmp -s $testroot/stderr.expected $testroot/stderr
1485 ret="$?"
1486 if [ "$ret" != "0" ]; then
1487 diff -u $testroot/stderr.expected $testroot/stderr
1488 test_done "$testroot" "$ret"
1489 return 1
1492 (cd $testroot/wt && got update > $testroot/stdout)
1494 echo "U epsilon/psi" > $testroot/stdout.expected
1495 echo "C epsilon/zeta" >> $testroot/stdout.expected
1496 echo -n "Updated to commit " >> $testroot/stdout.expected
1497 git_show_head $testroot/repo >> $testroot/stdout.expected
1498 echo >> $testroot/stdout.expected
1499 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1501 cmp -s $testroot/stdout.expected $testroot/stdout
1502 ret="$?"
1503 if [ "$ret" != "0" ]; then
1504 diff -u $testroot/stdout.expected $testroot/stdout
1505 test_done "$testroot" "$ret"
1506 return 1
1509 # resolve conflict
1510 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1512 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1514 local head_rev=`git_show_head $testroot/repo`
1515 echo "M epsilon/zeta" > $testroot/stdout.expected
1516 echo "Created commit $head_rev" >> $testroot/stdout.expected
1517 cmp -s $testroot/stdout.expected $testroot/stdout
1518 ret="$?"
1519 if [ "$ret" != "0" ]; then
1520 diff -u $testroot/stdout.expected $testroot/stdout
1521 test_done "$testroot" "$ret"
1522 return 1
1525 test_done "$testroot" "$ret"
1528 test_update_tag() {
1529 local testroot=`test_init update_tag`
1530 local tag="1.0.0"
1532 got checkout $testroot/repo $testroot/wt > /dev/null
1533 ret="$?"
1534 if [ "$ret" != "0" ]; then
1535 test_done "$testroot" "$ret"
1536 return 1
1539 echo "modified alpha" > $testroot/repo/alpha
1540 git_commit $testroot/repo -m "modified alpha"
1541 (cd $testroot/repo && git tag -m "test" -a $tag)
1543 echo "U alpha" > $testroot/stdout.expected
1544 echo -n "Updated to commit " >> $testroot/stdout.expected
1545 git_show_head $testroot/repo >> $testroot/stdout.expected
1546 echo >> $testroot/stdout.expected
1548 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1550 cmp -s $testroot/stdout.expected $testroot/stdout
1551 ret="$?"
1552 if [ "$ret" != "0" ]; then
1553 diff -u $testroot/stdout.expected $testroot/stdout
1554 test_done "$testroot" "$ret"
1555 return 1
1558 echo "modified alpha" > $testroot/content.expected
1559 cat $testroot/wt/alpha > $testroot/content
1561 cmp -s $testroot/content.expected $testroot/content
1562 ret="$?"
1563 if [ "$ret" != "0" ]; then
1564 diff -u $testroot/content.expected $testroot/content
1566 test_done "$testroot" "$ret"
1569 test_update_toggles_xbit() {
1570 local testroot=`test_init update_toggles_xbit 1`
1572 touch $testroot/repo/xfile
1573 chmod +x $testroot/repo/xfile
1574 (cd $testroot/repo && git add .)
1575 git_commit $testroot/repo -m "adding executable file"
1576 local commit_id1=`git_show_head $testroot/repo`
1578 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1579 ret="$?"
1580 if [ "$ret" != "0" ]; then
1581 test_done "$testroot" "$ret"
1582 return 1
1585 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1586 ret="$?"
1587 if [ "$ret" != "0" ]; then
1588 echo "file is not executable" >&2
1589 ls -l $testroot/wt/xfile >&2
1590 test_done "$testroot" "$ret"
1591 return 1
1594 chmod -x $testroot/wt/xfile
1595 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1596 local commit_id2=`git_show_head $testroot/repo`
1598 echo "U xfile" > $testroot/stdout.expected
1599 echo -n "Updated to commit " >> $testroot/stdout.expected
1600 git_show_head $testroot/repo >> $testroot/stdout.expected
1601 echo >> $testroot/stdout.expected
1603 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1604 ret="$?"
1605 if [ "$ret" != "0" ]; then
1606 test_done "$testroot" "$ret"
1607 return 1
1610 echo "U xfile" > $testroot/stdout.expected
1611 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
1612 cmp -s $testroot/stdout.expected $testroot/stdout
1613 ret="$?"
1614 if [ "$ret" != "0" ]; then
1615 diff -u $testroot/stdout.expected $testroot/stdout
1616 test_done "$testroot" "$ret"
1617 return 1
1621 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1622 ret="$?"
1623 if [ "$ret" != "0" ]; then
1624 echo "file is not executable" >&2
1625 ls -l $testroot/wt/xfile >&2
1626 test_done "$testroot" "$ret"
1627 return 1
1630 (cd $testroot/wt && got update > $testroot/stdout)
1631 ret="$?"
1632 if [ "$ret" != "0" ]; then
1633 test_done "$testroot" "$ret"
1634 return 1
1637 echo "U xfile" > $testroot/stdout.expected
1638 echo "Updated to commit $commit_id2" >> $testroot/stdout.expected
1639 cmp -s $testroot/stdout.expected $testroot/stdout
1640 ret="$?"
1641 if [ "$ret" != "0" ]; then
1642 diff -u $testroot/stdout.expected $testroot/stdout
1643 test_done "$testroot" "$ret"
1644 return 1
1647 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1648 ret="$?"
1649 if [ "$ret" != "0" ]; then
1650 echo "file is unexpectedly executable" >&2
1651 ls -l $testroot/wt/xfile >&2
1653 test_done "$testroot" "$ret"
1656 test_update_preserves_conflicted_file() {
1657 local testroot=`test_init update_preserves_conflicted_file`
1658 local commit_id0=`git_show_head $testroot/repo`
1660 echo "modified alpha" > $testroot/repo/alpha
1661 git_commit $testroot/repo -m "modified alpha"
1662 local commit_id1=`git_show_head $testroot/repo`
1664 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
1665 ret="$?"
1666 if [ "$ret" != "0" ]; then
1667 test_done "$testroot" "$ret"
1668 return 1
1671 # fake a merge conflict
1672 echo '<<<<<<<' > $testroot/wt/alpha
1673 echo 'alpha' >> $testroot/wt/alpha
1674 echo '=======' >> $testroot/wt/alpha
1675 echo 'alpha, too' >> $testroot/wt/alpha
1676 echo '>>>>>>>' >> $testroot/wt/alpha
1677 cp $testroot/wt/alpha $testroot/content.expected
1679 echo "C alpha" > $testroot/stdout.expected
1680 (cd $testroot/wt && got status > $testroot/stdout)
1681 cmp -s $testroot/stdout.expected $testroot/stdout
1682 ret="$?"
1683 if [ "$ret" != "0" ]; then
1684 diff -u $testroot/stdout.expected $testroot/stdout
1685 test_done "$testroot" "$ret"
1686 return 1
1689 echo "# alpha" > $testroot/stdout.expected
1690 echo -n "Updated to commit " >> $testroot/stdout.expected
1691 git_show_head $testroot/repo >> $testroot/stdout.expected
1692 echo >> $testroot/stdout.expected
1693 echo "Files not updated because of existing merge conflicts: 1" \
1694 >> $testroot/stdout.expected
1695 (cd $testroot/wt && got update > $testroot/stdout)
1697 cmp -s $testroot/stdout.expected $testroot/stdout
1698 ret="$?"
1699 if [ "$ret" != "0" ]; then
1700 diff -u $testroot/stdout.expected $testroot/stdout
1701 test_done "$testroot" "$ret"
1702 return 1
1705 cmp -s $testroot/content.expected $testroot/wt/alpha
1706 ret="$?"
1707 if [ "$ret" != "0" ]; then
1708 diff -u $testroot/content.expected $testroot/wt/alpha
1710 test_done "$testroot" "$ret"
1713 test_update_modified_submodules() {
1714 local testroot=`test_init update_modified_submodules`
1716 make_single_file_repo $testroot/repo2 foo
1718 (cd $testroot/repo && git submodule -q add ../repo2)
1719 (cd $testroot/repo && git commit -q -m 'adding submodule')
1721 got checkout $testroot/repo $testroot/wt > /dev/null
1723 echo "modified foo" > $testroot/repo2/foo
1724 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1726 # Update the repo/repo2 submodule link
1727 (cd $testroot/repo && git -C repo2 pull -q)
1728 (cd $testroot/repo && git add repo2)
1729 git_commit $testroot/repo -m "modified submodule link"
1731 # This update only records the new base commit. Otherwise it is a
1732 # no-op change because Got's file index does not track submodules.
1733 echo -n "Updated to commit " > $testroot/stdout.expected
1734 git_show_head $testroot/repo >> $testroot/stdout.expected
1735 echo >> $testroot/stdout.expected
1737 (cd $testroot/wt && got update > $testroot/stdout)
1739 cmp -s $testroot/stdout.expected $testroot/stdout
1740 ret="$?"
1741 if [ "$ret" != "0" ]; then
1742 diff -u $testroot/stdout.expected $testroot/stdout
1744 test_done "$testroot" "$ret"
1747 test_update_adds_submodule() {
1748 local testroot=`test_init update_adds_submodule`
1750 got checkout $testroot/repo $testroot/wt > /dev/null
1752 make_single_file_repo $testroot/repo2 foo
1754 echo "modified foo" > $testroot/repo2/foo
1755 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1757 (cd $testroot/repo && git submodule -q add ../repo2)
1758 (cd $testroot/repo && git commit -q -m 'adding submodule')
1760 echo "A .gitmodules" > $testroot/stdout.expected
1761 echo -n "Updated to commit " >> $testroot/stdout.expected
1762 git_show_head $testroot/repo >> $testroot/stdout.expected
1763 echo >> $testroot/stdout.expected
1765 (cd $testroot/wt && got update > $testroot/stdout)
1767 cmp -s $testroot/stdout.expected $testroot/stdout
1768 ret="$?"
1769 if [ "$ret" != "0" ]; then
1770 diff -u $testroot/stdout.expected $testroot/stdout
1772 test_done "$testroot" "$ret"
1775 test_update_conflict_wt_file_vs_repo_submodule() {
1776 local testroot=`test_init update_conflict_wt_file_vs_repo_submodule`
1778 got checkout $testroot/repo $testroot/wt > /dev/null
1780 make_single_file_repo $testroot/repo2 foo
1782 # Add a file which will clash with the submodule
1783 echo "This is a file called repo2" > $testroot/wt/repo2
1784 (cd $testroot/wt && got add repo2 > /dev/null)
1785 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
1786 ret="$?"
1787 if [ "$ret" != "0" ]; then
1788 echo "commit failed unexpectedly" >&2
1789 test_done "$testroot" "1"
1790 return 1
1793 (cd $testroot/repo && git submodule -q add ../repo2)
1794 (cd $testroot/repo && git commit -q -m 'adding submodule')
1796 # Modify the clashing file such that any modifications brought
1797 # in by 'got update' would require a merge.
1798 echo "This file was changed" > $testroot/wt/repo2
1800 # No conflict occurs because 'got update' ignores the submodule
1801 # and leaves the clashing file as it was.
1802 echo "A .gitmodules" > $testroot/stdout.expected
1803 echo -n "Updated to commit " >> $testroot/stdout.expected
1804 git_show_head $testroot/repo >> $testroot/stdout.expected
1805 echo >> $testroot/stdout.expected
1807 (cd $testroot/wt && got update > $testroot/stdout)
1809 cmp -s $testroot/stdout.expected $testroot/stdout
1810 ret="$?"
1811 if [ "$ret" != "0" ]; then
1812 diff -u $testroot/stdout.expected $testroot/stdout
1813 test_done "$testroot" "$ret"
1814 return 1
1817 (cd $testroot/wt && got status > $testroot/stdout)
1819 echo "M repo2" > $testroot/stdout.expected
1820 cmp -s $testroot/stdout.expected $testroot/stdout
1821 ret="$?"
1822 if [ "$ret" != "0" ]; then
1823 diff -u $testroot/stdout.expected $testroot/stdout
1825 test_done "$testroot" "$ret"
1828 test_update_adds_symlink() {
1829 local testroot=`test_init update_adds_symlink`
1831 got checkout $testroot/repo $testroot/wt > /dev/null
1832 ret="$?"
1833 if [ "$ret" != "0" ]; then
1834 echo "checkout failed unexpectedly" >&2
1835 test_done "$testroot" "$ret"
1836 return 1
1839 (cd $testroot/repo && ln -s alpha alpha.link)
1840 (cd $testroot/repo && ln -s epsilon epsilon.link)
1841 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1842 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1843 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1844 (cd $testroot/repo && git add .)
1845 git_commit $testroot/repo -m "add symlinks"
1847 echo "A alpha.link" > $testroot/stdout.expected
1848 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1849 echo "A epsilon.link" >> $testroot/stdout.expected
1850 echo "A nonexistent.link" >> $testroot/stdout.expected
1851 echo "A passwd.link" >> $testroot/stdout.expected
1852 echo -n "Updated to commit " >> $testroot/stdout.expected
1853 git_show_head $testroot/repo >> $testroot/stdout.expected
1854 echo >> $testroot/stdout.expected
1856 (cd $testroot/wt && got update > $testroot/stdout)
1858 cmp -s $testroot/stdout.expected $testroot/stdout
1859 ret="$?"
1860 if [ "$ret" != "0" ]; then
1861 diff -u $testroot/stdout.expected $testroot/stdout
1862 test_done "$testroot" "$ret"
1863 return 1
1866 if ! [ -h $testroot/wt/alpha.link ]; then
1867 echo "alpha.link is not a symlink"
1868 test_done "$testroot" "1"
1869 return 1
1872 readlink $testroot/wt/alpha.link > $testroot/stdout
1873 echo "alpha" > $testroot/stdout.expected
1874 cmp -s $testroot/stdout.expected $testroot/stdout
1875 ret="$?"
1876 if [ "$ret" != "0" ]; then
1877 diff -u $testroot/stdout.expected $testroot/stdout
1878 test_done "$testroot" "$ret"
1879 return 1
1882 if ! [ -h $testroot/wt/epsilon.link ]; then
1883 echo "epsilon.link is not a symlink"
1884 test_done "$testroot" "1"
1885 return 1
1888 readlink $testroot/wt/epsilon.link > $testroot/stdout
1889 echo "epsilon" > $testroot/stdout.expected
1890 cmp -s $testroot/stdout.expected $testroot/stdout
1891 ret="$?"
1892 if [ "$ret" != "0" ]; then
1893 diff -u $testroot/stdout.expected $testroot/stdout
1894 test_done "$testroot" "$ret"
1895 return 1
1898 if [ -h $testroot/wt/passwd.link ]; then
1899 echo -n "passwd.link symlink points outside of work tree: " >&2
1900 readlink $testroot/wt/passwd.link >&2
1901 test_done "$testroot" "1"
1902 return 1
1905 echo -n "/etc/passwd" > $testroot/content.expected
1906 cp $testroot/wt/passwd.link $testroot/content
1908 cmp -s $testroot/content.expected $testroot/content
1909 ret="$?"
1910 if [ "$ret" != "0" ]; then
1911 diff -u $testroot/content.expected $testroot/content
1912 test_done "$testroot" "$ret"
1913 return 1
1916 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1917 echo "../beta" > $testroot/stdout.expected
1918 cmp -s $testroot/stdout.expected $testroot/stdout
1919 ret="$?"
1920 if [ "$ret" != "0" ]; then
1921 diff -u $testroot/stdout.expected $testroot/stdout
1922 test_done "$testroot" "$ret"
1923 return 1
1926 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1927 echo "nonexistent" > $testroot/stdout.expected
1928 cmp -s $testroot/stdout.expected $testroot/stdout
1929 ret="$?"
1930 if [ "$ret" != "0" ]; then
1931 diff -u $testroot/stdout.expected $testroot/stdout
1933 test_done "$testroot" "$ret"
1936 test_update_deletes_symlink() {
1937 local testroot=`test_init update_deletes_symlink`
1939 (cd $testroot/repo && ln -s alpha alpha.link)
1940 (cd $testroot/repo && git add .)
1941 git_commit $testroot/repo -m "add symlink"
1943 got checkout $testroot/repo $testroot/wt > /dev/null
1944 ret="$?"
1945 if [ "$ret" != "0" ]; then
1946 echo "checkout failed unexpectedly" >&2
1947 test_done "$testroot" "$ret"
1948 return 1
1951 (cd $testroot/repo && git rm -q alpha.link)
1952 git_commit $testroot/repo -m "delete symlink"
1954 echo "D alpha.link" > $testroot/stdout.expected
1955 echo -n "Updated to commit " >> $testroot/stdout.expected
1956 git_show_head $testroot/repo >> $testroot/stdout.expected
1957 echo >> $testroot/stdout.expected
1959 (cd $testroot/wt && got update > $testroot/stdout)
1961 cmp -s $testroot/stdout.expected $testroot/stdout
1962 ret="$?"
1963 if [ "$ret" != "0" ]; then
1964 diff -u $testroot/stdout.expected $testroot/stdout
1965 test_done "$testroot" "$ret"
1966 return 1
1969 if [ -e $testroot/wt/alpha.link ]; then
1970 echo "alpha.link still exists on disk"
1971 test_done "$testroot" "1"
1972 return 1
1975 test_done "$testroot" "0"
1978 test_update_symlink_conflicts() {
1979 local testroot=`test_init update_symlink_conflicts`
1981 (cd $testroot/repo && ln -s alpha alpha.link)
1982 (cd $testroot/repo && ln -s epsilon epsilon.link)
1983 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1984 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1985 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1986 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
1987 (cd $testroot/repo && git add .)
1988 git_commit $testroot/repo -m "add symlinks"
1989 local commit_id1=`git_show_head $testroot/repo`
1991 got checkout $testroot/repo $testroot/wt > /dev/null
1992 ret="$?"
1993 if [ "$ret" != "0" ]; then
1994 echo "checkout failed unexpectedly" >&2
1995 test_done "$testroot" "$ret"
1996 return 1
1999 (cd $testroot/repo && ln -sf beta alpha.link)
2000 (cd $testroot/repo && ln -sfh gamma epsilon.link)
2001 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
2002 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
2003 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
2004 (cd $testroot/repo && git rm -q nonexistent.link)
2005 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
2006 (cd $testroot/repo && ln -sf alpha new.link)
2007 (cd $testroot/repo && git add .)
2008 git_commit $testroot/repo -m "change symlinks"
2009 local commit_id2=`git_show_head $testroot/repo`
2011 # modified symlink to file A vs modified symlink to file B
2012 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
2013 # modified symlink to dir A vs modified symlink to file B
2014 (cd $testroot/wt && ln -sfh beta epsilon.link)
2015 # modeified symlink to file A vs modified symlink to dir B
2016 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
2017 # added regular file A vs added bad symlink to file A
2018 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
2019 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2020 # added bad symlink to file A vs added regular file A
2021 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
2022 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2023 # removed symlink to non-existent file A vs modified symlink
2024 # to nonexistent file B
2025 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
2026 # modified symlink to file A vs removed symlink to file A
2027 (cd $testroot/wt && got rm zeta.link > /dev/null)
2028 # added symlink to file A vs added symlink to file B
2029 (cd $testroot/wt && ln -sf beta new.link)
2030 (cd $testroot/wt && got add new.link > /dev/null)
2032 (cd $testroot/wt && got update > $testroot/stdout)
2034 echo "C alpha.link" >> $testroot/stdout.expected
2035 echo "C dotgotbar.link" >> $testroot/stdout.expected
2036 echo "C dotgotfoo.link" >> $testroot/stdout.expected
2037 echo "C epsilon/beta.link" >> $testroot/stdout.expected
2038 echo "C epsilon.link" >> $testroot/stdout.expected
2039 echo "C new.link" >> $testroot/stdout.expected
2040 echo "C nonexistent.link" >> $testroot/stdout.expected
2041 echo "G zeta.link" >> $testroot/stdout.expected
2042 echo -n "Updated to commit " >> $testroot/stdout.expected
2043 git_show_head $testroot/repo >> $testroot/stdout.expected
2044 echo >> $testroot/stdout.expected
2045 echo "Files with new merge conflicts: 7" >> $testroot/stdout.expected
2047 cmp -s $testroot/stdout.expected $testroot/stdout
2048 ret="$?"
2049 if [ "$ret" != "0" ]; then
2050 diff -u $testroot/stdout.expected $testroot/stdout
2051 test_done "$testroot" "$ret"
2052 return 1
2055 if [ -h $testroot/wt/alpha.link ]; then
2056 echo "alpha.link is a symlink"
2057 test_done "$testroot" "1"
2058 return 1
2061 echo "<<<<<<< merged change: commit $commit_id2" \
2062 > $testroot/content.expected
2063 echo "beta" >> $testroot/content.expected
2064 echo "3-way merge base: commit $commit_id1" \
2065 >> $testroot/content.expected
2066 echo "alpha" >> $testroot/content.expected
2067 echo "=======" >> $testroot/content.expected
2068 echo "gamma/delta" >> $testroot/content.expected
2069 echo '>>>>>>>' >> $testroot/content.expected
2070 echo -n "" >> $testroot/content.expected
2072 cp $testroot/wt/alpha.link $testroot/content
2073 cmp -s $testroot/content.expected $testroot/content
2074 ret="$?"
2075 if [ "$ret" != "0" ]; then
2076 diff -u $testroot/content.expected $testroot/content
2077 test_done "$testroot" "$ret"
2078 return 1
2081 if [ -h $testroot/wt/epsilon.link ]; then
2082 echo "epsilon.link is a symlink"
2083 test_done "$testroot" "1"
2084 return 1
2087 echo "<<<<<<< merged change: commit $commit_id2" \
2088 > $testroot/content.expected
2089 echo "gamma" >> $testroot/content.expected
2090 echo "3-way merge base: commit $commit_id1" \
2091 >> $testroot/content.expected
2092 echo "epsilon" >> $testroot/content.expected
2093 echo "=======" >> $testroot/content.expected
2094 echo "beta" >> $testroot/content.expected
2095 echo '>>>>>>>' >> $testroot/content.expected
2096 echo -n "" >> $testroot/content.expected
2098 cp $testroot/wt/epsilon.link $testroot/content
2099 cmp -s $testroot/content.expected $testroot/content
2100 ret="$?"
2101 if [ "$ret" != "0" ]; then
2102 diff -u $testroot/content.expected $testroot/content
2103 test_done "$testroot" "$ret"
2104 return 1
2107 if [ -h $testroot/wt/passwd.link ]; then
2108 echo -n "passwd.link symlink points outside of work tree: " >&2
2109 readlink $testroot/wt/passwd.link >&2
2110 test_done "$testroot" "1"
2111 return 1
2114 echo -n "/etc/passwd" > $testroot/content.expected
2115 cp $testroot/wt/passwd.link $testroot/content
2117 cmp -s $testroot/content.expected $testroot/content
2118 ret="$?"
2119 if [ "$ret" != "0" ]; then
2120 diff -u $testroot/content.expected $testroot/content
2121 test_done "$testroot" "$ret"
2122 return 1
2125 if [ -h $testroot/wt/epsilon/beta.link ]; then
2126 echo "epsilon/beta.link is a symlink"
2127 test_done "$testroot" "1"
2128 return 1
2131 echo "<<<<<<< merged change: commit $commit_id2" \
2132 > $testroot/content.expected
2133 echo "../gamma/delta" >> $testroot/content.expected
2134 echo "3-way merge base: commit $commit_id1" \
2135 >> $testroot/content.expected
2136 echo "../beta" >> $testroot/content.expected
2137 echo "=======" >> $testroot/content.expected
2138 echo "../gamma" >> $testroot/content.expected
2139 echo '>>>>>>>' >> $testroot/content.expected
2140 echo -n "" >> $testroot/content.expected
2142 cp $testroot/wt/epsilon/beta.link $testroot/content
2143 cmp -s $testroot/content.expected $testroot/content
2144 ret="$?"
2145 if [ "$ret" != "0" ]; then
2146 diff -u $testroot/content.expected $testroot/content
2147 test_done "$testroot" "$ret"
2148 return 1
2151 if [ -h $testroot/wt/nonexistent.link ]; then
2152 echo -n "nonexistent.link still exists on disk: " >&2
2153 readlink $testroot/wt/nonexistent.link >&2
2154 test_done "$testroot" "1"
2155 return 1
2158 echo "<<<<<<< merged change: commit $commit_id2" \
2159 > $testroot/content.expected
2160 echo "(symlink was deleted)" >> $testroot/content.expected
2161 echo "=======" >> $testroot/content.expected
2162 echo "nonexistent2" >> $testroot/content.expected
2163 echo '>>>>>>>' >> $testroot/content.expected
2164 echo -n "" >> $testroot/content.expected
2166 cp $testroot/wt/nonexistent.link $testroot/content
2167 cmp -s $testroot/content.expected $testroot/content
2168 ret="$?"
2169 if [ "$ret" != "0" ]; then
2170 diff -u $testroot/content.expected $testroot/content
2171 test_done "$testroot" "$ret"
2172 return 1
2175 if [ -h $testroot/wt/dotgotfoo.link ]; then
2176 echo "dotgotfoo.link is a symlink"
2177 test_done "$testroot" "1"
2178 return 1
2181 echo "<<<<<<< merged change: commit $commit_id2" \
2182 > $testroot/content.expected
2183 echo "this is regular file foo" >> $testroot/content.expected
2184 echo "=======" >> $testroot/content.expected
2185 echo -n ".got/bar" >> $testroot/content.expected
2186 echo '>>>>>>>' >> $testroot/content.expected
2187 echo -n "" >> $testroot/content.expected
2189 cp $testroot/wt/dotgotfoo.link $testroot/content
2190 cmp -s $testroot/content.expected $testroot/content
2191 ret="$?"
2192 if [ "$ret" != "0" ]; then
2193 diff -u $testroot/content.expected $testroot/content
2194 test_done "$testroot" "$ret"
2195 return 1
2198 if [ -h $testroot/wt/dotgotbar.link ]; then
2199 echo "dotgotbar.link is a symlink"
2200 test_done "$testroot" "1"
2201 return 1
2203 echo "<<<<<<< merged change: commit $commit_id2" \
2204 > $testroot/content.expected
2205 echo -n ".got/bar" >> $testroot/content.expected
2206 echo "=======" >> $testroot/content.expected
2207 echo "this is regular file bar" >> $testroot/content.expected
2208 echo '>>>>>>>' >> $testroot/content.expected
2209 echo -n "" >> $testroot/content.expected
2211 cp $testroot/wt/dotgotbar.link $testroot/content
2212 cmp -s $testroot/content.expected $testroot/content
2213 ret="$?"
2214 if [ "$ret" != "0" ]; then
2215 diff -u $testroot/content.expected $testroot/content
2216 test_done "$testroot" "$ret"
2217 return 1
2220 if [ -h $testroot/wt/new.link ]; then
2221 echo "new.link is a symlink"
2222 test_done "$testroot" "1"
2223 return 1
2226 echo "<<<<<<< merged change: commit $commit_id2" \
2227 > $testroot/content.expected
2228 echo "alpha" >> $testroot/content.expected
2229 echo "=======" >> $testroot/content.expected
2230 echo "beta" >> $testroot/content.expected
2231 echo '>>>>>>>' >> $testroot/content.expected
2232 echo -n "" >> $testroot/content.expected
2234 cp $testroot/wt/new.link $testroot/content
2235 cmp -s $testroot/content.expected $testroot/content
2236 ret="$?"
2237 if [ "$ret" != "0" ]; then
2238 diff -u $testroot/content.expected $testroot/content
2239 test_done "$testroot" "$ret"
2240 return 1
2243 echo "A dotgotfoo.link" > $testroot/stdout.expected
2244 echo "M new.link" >> $testroot/stdout.expected
2245 echo "D nonexistent.link" >> $testroot/stdout.expected
2246 (cd $testroot/wt && got status > $testroot/stdout)
2247 if [ "$ret" != "0" ]; then
2248 diff -u $testroot/stdout.expected $testroot/stdout
2249 test_done "$testroot" "$ret"
2250 return 1
2253 test_done "$testroot" "0"
2257 test_parseargs "$@"
2258 run_test test_update_basic
2259 run_test test_update_adds_file
2260 run_test test_update_deletes_file
2261 run_test test_update_deletes_dir
2262 run_test test_update_deletes_dir_with_path_prefix
2263 run_test test_update_deletes_dir_recursively
2264 run_test test_update_sibling_dirs_with_common_prefix
2265 run_test test_update_dir_with_dot_sibling
2266 run_test test_update_moves_files_upwards
2267 run_test test_update_moves_files_to_new_dir
2268 run_test test_update_creates_missing_parent
2269 run_test test_update_creates_missing_parent_with_subdir
2270 run_test test_update_file_in_subsubdir
2271 run_test test_update_merges_file_edits
2272 run_test test_update_keeps_xbit
2273 run_test test_update_clears_xbit
2274 run_test test_update_restores_missing_file
2275 run_test test_update_conflict_wt_add_vs_repo_add
2276 run_test test_update_conflict_wt_edit_vs_repo_rm
2277 run_test test_update_conflict_wt_rm_vs_repo_edit
2278 run_test test_update_conflict_wt_rm_vs_repo_rm
2279 run_test test_update_partial
2280 run_test test_update_partial_add
2281 run_test test_update_partial_rm
2282 run_test test_update_partial_dir
2283 run_test test_update_moved_branch_ref
2284 run_test test_update_to_another_branch
2285 run_test test_update_to_commit_on_wrong_branch
2286 run_test test_update_bumps_base_commit_id
2287 run_test test_update_tag
2288 run_test test_update_toggles_xbit
2289 run_test test_update_preserves_conflicted_file
2290 run_test test_update_modified_submodules
2291 run_test test_update_adds_submodule
2292 run_test test_update_conflict_wt_file_vs_repo_submodule
2293 run_test test_update_adds_symlink
2294 run_test test_update_deletes_symlink
2295 run_test test_update_symlink_conflicts