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 -ne 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 refs/heads/master: " >> $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 -ne 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 -ne 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 -ne 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 refs/heads/master: " >> $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 -ne 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 -ne 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 mkdir $testroot/wtparent
102 got checkout $testroot/repo $testroot/wtparent/wt > /dev/null
103 ret=$?
104 if [ $ret -ne 0 ]; then
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/repo && git_rm $testroot/repo beta)
110 git_commit $testroot/repo -m "deleting a file"
112 echo "D beta" > $testroot/stdout.expected
113 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
114 git_show_head $testroot/repo >> $testroot/stdout.expected
115 echo >> $testroot/stdout.expected
117 # verify that no error occurs if the work tree's parent
118 # directory is not writable
119 chmod u-w $testroot/wtparent
120 (cd $testroot/wtparent/wt && got update > $testroot/stdout)
121 chmod u+w $testroot/wtparent
123 cmp -s $testroot/stdout.expected $testroot/stdout
124 ret=$?
125 if [ $ret -ne 0 ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 test_done "$testroot" "$ret"
128 return 1
129 fi
131 if [ -e $testroot/wtparent/wt/beta ]; then
132 echo "removed file beta still exists on disk" >&2
133 test_done "$testroot" "1"
134 return 1
135 fi
137 test_done "$testroot" "0"
140 test_update_deletes_dir() {
141 local testroot=`test_init update_deletes_dir`
143 got checkout $testroot/repo $testroot/wt > /dev/null
144 ret=$?
145 if [ $ret -ne 0 ]; then
146 test_done "$testroot" "$ret"
147 return 1
148 fi
150 (cd $testroot/repo && git_rm $testroot/repo -r epsilon)
151 git_commit $testroot/repo -m "deleting a directory"
153 echo "D epsilon/zeta" > $testroot/stdout.expected
154 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
155 git_show_head $testroot/repo >> $testroot/stdout.expected
156 echo >> $testroot/stdout.expected
158 (cd $testroot/wt && got update > $testroot/stdout)
160 cmp -s $testroot/stdout.expected $testroot/stdout
161 ret=$?
162 if [ $ret -ne 0 ]; then
163 diff -u $testroot/stdout.expected $testroot/stdout
164 test_done "$testroot" "$ret"
165 return 1
166 fi
168 if [ -e $testroot/wt/epsilon ]; then
169 echo "removed dir epsilon still exists on disk" >&2
170 test_done "$testroot" "1"
171 return 1
172 fi
174 test_done "$testroot" "0"
177 test_update_deletes_dir_with_path_prefix() {
178 local testroot=`test_init update_deletes_dir_with_path_prefix`
179 local first_rev=`git_show_head $testroot/repo`
181 mkdir $testroot/repo/epsilon/psi
182 echo mu > $testroot/repo/epsilon/psi/mu
183 (cd $testroot/repo && git add .)
184 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
186 # check out the epsilon/ sub-tree
187 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
188 ret=$?
189 if [ $ret -ne 0 ]; then
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 # update back to first commit and expect psi/mu to be deleted
195 echo "D psi/mu" > $testroot/stdout.expected
196 echo "Updated to refs/heads/master: $first_rev" \
197 >> $testroot/stdout.expected
199 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
201 cmp -s $testroot/stdout.expected $testroot/stdout
202 ret=$?
203 if [ $ret -ne 0 ]; then
204 diff -u $testroot/stdout.expected $testroot/stdout
205 test_done "$testroot" "$ret"
206 return 1
207 fi
209 if [ -e $testroot/wt/psi ]; then
210 echo "removed dir psi still exists on disk" >&2
211 test_done "$testroot" "1"
212 return 1
213 fi
215 test_done "$testroot" "0"
218 test_update_deletes_dir_recursively() {
219 local testroot=`test_init update_deletes_dir_recursively`
220 local first_rev=`git_show_head $testroot/repo`
222 mkdir $testroot/repo/epsilon/psi
223 echo mu > $testroot/repo/epsilon/psi/mu
224 mkdir $testroot/repo/epsilon/psi/chi
225 echo tau > $testroot/repo/epsilon/psi/chi/tau
226 (cd $testroot/repo && git add .)
227 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
229 # check out the epsilon/ sub-tree
230 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
231 ret=$?
232 if [ $ret -ne 0 ]; then
233 test_done "$testroot" "$ret"
234 return 1
235 fi
237 # update back to first commit and expect psi/mu to be deleted
238 echo "D psi/chi/tau" > $testroot/stdout.expected
239 echo "D psi/mu" >> $testroot/stdout.expected
240 echo "Updated to refs/heads/master: $first_rev" \
241 >> $testroot/stdout.expected
243 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
245 cmp -s $testroot/stdout.expected $testroot/stdout
246 ret=$?
247 if [ "$?" != "0" ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 if [ -e $testroot/wt/psi ]; then
254 echo "removed dir psi still exists on disk" >&2
255 test_done "$testroot" "1"
256 return 1
257 fi
259 test_done "$testroot" "0"
262 test_update_sibling_dirs_with_common_prefix() {
263 local testroot=`test_init update_sibling_dirs_with_common_prefix`
265 got checkout $testroot/repo $testroot/wt > /dev/null
266 ret=$?
267 if [ $ret -ne 0 ]; then
268 test_done "$testroot" "$ret"
269 return 1
270 fi
272 mkdir $testroot/repo/epsilon2
273 echo mu > $testroot/repo/epsilon2/mu
274 (cd $testroot/repo && git add epsilon2/mu)
275 git_commit $testroot/repo -m "adding sibling of epsilon"
276 echo change > $testroot/repo/epsilon/zeta
277 git_commit $testroot/repo -m "changing epsilon/zeta"
279 echo "U epsilon/zeta" > $testroot/stdout.expected
280 echo "A epsilon2/mu" >> $testroot/stdout.expected
281 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
282 git_show_head $testroot/repo >> $testroot/stdout.expected
283 echo >> $testroot/stdout.expected
285 (cd $testroot/wt && got update > $testroot/stdout)
287 cmp -s $testroot/stdout.expected $testroot/stdout
288 ret=$?
289 if [ $ret -ne 0 ]; then
290 diff -u $testroot/stdout.expected $testroot/stdout
291 test_done "$testroot" "$ret"
292 return 1
293 fi
295 echo "another change" > $testroot/repo/epsilon/zeta
296 git_commit $testroot/repo -m "changing epsilon/zeta again"
298 echo "U epsilon/zeta" > $testroot/stdout.expected
299 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
300 git_show_head $testroot/repo >> $testroot/stdout.expected
301 echo >> $testroot/stdout.expected
303 # Bug: This update used to do delete/add epsilon2/mu again:
304 # U epsilon/zeta
305 # D epsilon2/mu <--- not intended
306 # A epsilon2/mu <--- not intended
307 (cd $testroot/wt && got update > $testroot/stdout)
309 cmp -s $testroot/stdout.expected $testroot/stdout
310 ret=$?
311 if [ $ret -ne 0 ]; then
312 diff -u $testroot/stdout.expected $testroot/stdout
313 test_done "$testroot" "$ret"
314 return 1
315 fi
317 cmp -s $testroot/stdout.expected $testroot/stdout
318 ret=$?
319 if [ $ret -ne 0 ]; then
320 diff -u $testroot/stdout.expected $testroot/stdout
321 fi
322 test_done "$testroot" "$ret"
325 test_update_dir_with_dot_sibling() {
326 local testroot=`test_init update_dir_with_dot_sibling`
328 got checkout $testroot/repo $testroot/wt > /dev/null
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 test_done "$testroot" "$ret"
332 return 1
333 fi
335 echo text > $testroot/repo/epsilon.txt
336 (cd $testroot/repo && git add epsilon.txt)
337 git_commit $testroot/repo -m "adding sibling of epsilon"
338 echo change > $testroot/repo/epsilon/zeta
339 git_commit $testroot/repo -m "changing epsilon/zeta"
341 echo "U epsilon/zeta" > $testroot/stdout.expected
342 echo "A epsilon.txt" >> $testroot/stdout.expected
343 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
344 git_show_head $testroot/repo >> $testroot/stdout.expected
345 echo >> $testroot/stdout.expected
347 (cd $testroot/wt && got update > $testroot/stdout)
349 cmp -s $testroot/stdout.expected $testroot/stdout
350 ret=$?
351 if [ $ret -ne 0 ]; then
352 diff -u $testroot/stdout.expected $testroot/stdout
353 test_done "$testroot" "$ret"
354 return 1
355 fi
357 echo "another change" > $testroot/repo/epsilon/zeta
358 git_commit $testroot/repo -m "changing epsilon/zeta again"
360 echo "U epsilon/zeta" > $testroot/stdout.expected
361 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
362 git_show_head $testroot/repo >> $testroot/stdout.expected
363 echo >> $testroot/stdout.expected
365 (cd $testroot/wt && got update > $testroot/stdout)
367 cmp -s $testroot/stdout.expected $testroot/stdout
368 ret=$?
369 if [ $ret -ne 0 ]; then
370 diff -u $testroot/stdout.expected $testroot/stdout
371 test_done "$testroot" "$ret"
372 return 1
373 fi
375 cmp -s $testroot/stdout.expected $testroot/stdout
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 fi
380 test_done "$testroot" "$ret"
383 test_update_moves_files_upwards() {
384 local testroot=`test_init update_moves_files_upwards`
386 mkdir $testroot/repo/epsilon/psi
387 echo mu > $testroot/repo/epsilon/psi/mu
388 mkdir $testroot/repo/epsilon/psi/chi
389 echo tau > $testroot/repo/epsilon/psi/chi/tau
390 (cd $testroot/repo && git add .)
391 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
393 got checkout $testroot/repo $testroot/wt > /dev/null
394 ret=$?
395 if [ $ret -ne 0 ]; then
396 test_done "$testroot" "$ret"
397 return 1
398 fi
400 (cd $testroot/repo && git mv epsilon/psi/mu epsilon/mu)
401 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon/psi/tau)
402 git_commit $testroot/repo -m "moving files upwards"
404 echo "A epsilon/mu" > $testroot/stdout.expected
405 echo "D epsilon/psi/chi/tau" >> $testroot/stdout.expected
406 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
407 echo "A epsilon/psi/tau" >> $testroot/stdout.expected
408 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
409 git_show_head $testroot/repo >> $testroot/stdout.expected
410 echo >> $testroot/stdout.expected
412 (cd $testroot/wt && got update > $testroot/stdout)
414 cmp -s $testroot/stdout.expected $testroot/stdout
415 ret=$?
416 if [ $ret -ne 0 ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
418 test_done "$testroot" "$ret"
419 return 1
420 fi
422 if [ -e $testroot/wt/epsilon/psi/chi ]; then
423 echo "removed dir epsilon/psi/chi still exists on disk" >&2
424 test_done "$testroot" "1"
425 return 1
426 fi
428 if [ -e $testroot/wt/epsilon/psi/mu ]; then
429 echo "removed file epsilon/psi/mu still exists on disk" >&2
430 test_done "$testroot" "1"
431 return 1
432 fi
434 test_done "$testroot" "0"
437 test_update_moves_files_to_new_dir() {
438 local testroot=`test_init update_moves_files_to_new_dir`
440 mkdir $testroot/repo/epsilon/psi
441 echo mu > $testroot/repo/epsilon/psi/mu
442 mkdir $testroot/repo/epsilon/psi/chi
443 echo tau > $testroot/repo/epsilon/psi/chi/tau
444 (cd $testroot/repo && git add .)
445 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
447 got checkout $testroot/repo $testroot/wt > /dev/null
448 ret=$?
449 if [ $ret -ne 0 ]; then
450 test_done "$testroot" "$ret"
451 return 1
452 fi
454 mkdir -p $testroot/repo/epsilon-new/psi
455 (cd $testroot/repo && git mv epsilon/psi/mu epsilon-new/mu)
456 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon-new/psi/tau)
457 git_commit $testroot/repo -m "moving files upwards"
459 echo "D epsilon/psi/chi/tau" > $testroot/stdout.expected
460 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
461 echo "A epsilon-new/mu" >> $testroot/stdout.expected
462 echo "A epsilon-new/psi/tau" >> $testroot/stdout.expected
463 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
464 git_show_head $testroot/repo >> $testroot/stdout.expected
465 echo >> $testroot/stdout.expected
467 (cd $testroot/wt && got update > $testroot/stdout)
469 cmp -s $testroot/stdout.expected $testroot/stdout
470 ret=$?
471 if [ $ret -ne 0 ]; then
472 diff -u $testroot/stdout.expected $testroot/stdout
473 test_done "$testroot" "$ret"
474 return 1
475 fi
477 if [ -e $testroot/wt/epsilon/psi/chi ]; then
478 echo "removed dir epsilon/psi/chi still exists on disk" >&2
479 test_done "$testroot" "1"
480 return 1
481 fi
483 if [ -e $testroot/wt/epsilon/psi/mu ]; then
484 echo "removed file epsilon/psi/mu still exists on disk" >&2
485 test_done "$testroot" "1"
486 return 1
487 fi
489 test_done "$testroot" "0"
492 test_update_creates_missing_parent() {
493 local testroot=`test_init update_creates_missing_parent 1`
495 touch $testroot/repo/Makefile
496 touch $testroot/repo/snake.6
497 touch $testroot/repo/snake.c
498 (cd $testroot/repo && git add .)
499 git_commit $testroot/repo -m "adding initial snake tree"
501 got checkout $testroot/repo $testroot/wt > /dev/null
502 ret=$?
503 if [ $ret -ne 0 ]; then
504 test_done "$testroot" "$ret"
505 return 1
506 fi
508 mkdir -p $testroot/repo/snake
509 (cd $testroot/repo && git mv Makefile snake.6 snake.c snake)
510 touch $testroot/repo/snake/move.c
511 touch $testroot/repo/snake/pathnames.h
512 touch $testroot/repo/snake/snake.h
513 mkdir -p $testroot/repo/snscore
514 touch $testroot/repo/snscore/Makefile
515 touch $testroot/repo/snscore/snscore.c
516 (cd $testroot/repo && git add .)
517 git_commit $testroot/repo -m "restructuring snake tree"
519 echo "D Makefile" > $testroot/stdout.expected
520 echo "A snake/Makefile" >> $testroot/stdout.expected
521 echo "A snake/move.c" >> $testroot/stdout.expected
522 echo "A snake/pathnames.h" >> $testroot/stdout.expected
523 echo "A snake/snake.6" >> $testroot/stdout.expected
524 echo "A snake/snake.c" >> $testroot/stdout.expected
525 echo "A snake/snake.h" >> $testroot/stdout.expected
526 echo "D snake.6" >> $testroot/stdout.expected
527 echo "D snake.c" >> $testroot/stdout.expected
528 echo "A snscore/Makefile" >> $testroot/stdout.expected
529 echo "A snscore/snscore.c" >> $testroot/stdout.expected
530 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
531 git_show_head $testroot/repo >> $testroot/stdout.expected
532 echo >> $testroot/stdout.expected
534 (cd $testroot/wt && got update > $testroot/stdout)
536 cmp -s $testroot/stdout.expected $testroot/stdout
537 ret=$?
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 fi
541 test_done "$testroot" "$ret"
544 test_update_creates_missing_parent_with_subdir() {
545 local testroot=`test_init update_creates_missing_parent_with_subdir 1`
547 touch $testroot/repo/Makefile
548 touch $testroot/repo/snake.6
549 touch $testroot/repo/snake.c
550 (cd $testroot/repo && git add .)
551 git_commit $testroot/repo -m "adding initial snake tree"
553 got checkout $testroot/repo $testroot/wt > /dev/null
554 ret=$?
555 if [ $ret -ne 0 ]; then
556 test_done "$testroot" "$ret"
557 return 1
558 fi
560 mkdir -p $testroot/repo/sss/snake
561 (cd $testroot/repo && git mv Makefile snake.6 snake.c sss/snake)
562 touch $testroot/repo/sss/snake/move.c
563 touch $testroot/repo/sss/snake/pathnames.h
564 touch $testroot/repo/sss/snake/snake.h
565 mkdir -p $testroot/repo/snscore
566 touch $testroot/repo/snscore/Makefile
567 touch $testroot/repo/snscore/snscore.c
568 (cd $testroot/repo && git add .)
569 git_commit $testroot/repo -m "restructuring snake tree"
571 echo "D Makefile" > $testroot/stdout.expected
572 echo "D snake.6" >> $testroot/stdout.expected
573 echo "D snake.c" >> $testroot/stdout.expected
574 echo "A snscore/Makefile" >> $testroot/stdout.expected
575 echo "A snscore/snscore.c" >> $testroot/stdout.expected
576 echo "A sss/snake/Makefile" >> $testroot/stdout.expected
577 echo "A sss/snake/move.c" >> $testroot/stdout.expected
578 echo "A sss/snake/pathnames.h" >> $testroot/stdout.expected
579 echo "A sss/snake/snake.6" >> $testroot/stdout.expected
580 echo "A sss/snake/snake.c" >> $testroot/stdout.expected
581 echo "A sss/snake/snake.h" >> $testroot/stdout.expected
582 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
583 git_show_head $testroot/repo >> $testroot/stdout.expected
584 echo >> $testroot/stdout.expected
586 (cd $testroot/wt && got update > $testroot/stdout)
588 cmp -s $testroot/stdout.expected $testroot/stdout
589 ret=$?
590 if [ $ret -ne 0 ]; then
591 diff -u $testroot/stdout.expected $testroot/stdout
592 test_done "$testroot" "$ret"
593 return 1
594 fi
596 test_done "$testroot" "0"
599 test_update_file_in_subsubdir() {
600 local testroot=`test_init update_fle_in_subsubdir 1`
602 touch $testroot/repo/Makefile
603 mkdir -p $testroot/repo/altq
604 touch $testroot/repo/altq/if_altq.h
605 mkdir -p $testroot/repo/arch/alpha
606 touch $testroot/repo/arch/alpha/Makefile
607 (cd $testroot/repo && git add .)
608 git_commit $testroot/repo -m "adding initial tree"
610 got checkout $testroot/repo $testroot/wt > /dev/null
611 ret=$?
612 if [ $ret -ne 0 ]; then
613 test_done "$testroot" "$ret"
614 return 1
615 fi
617 echo change > $testroot/repo/arch/alpha/Makefile
618 (cd $testroot/repo && git add .)
619 git_commit $testroot/repo -m "changed a file"
621 echo "U arch/alpha/Makefile" > $testroot/stdout.expected
622 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
623 git_show_head $testroot/repo >> $testroot/stdout.expected
624 echo >> $testroot/stdout.expected
626 (cd $testroot/wt && got update > $testroot/stdout)
628 cmp -s $testroot/stdout.expected $testroot/stdout
629 ret=$?
630 if [ $ret -ne 0 ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 test_done "$testroot" "$ret"
633 return 1
634 fi
636 test_done "$testroot" "0"
639 test_update_merges_file_edits() {
640 local testroot=`test_init update_merges_file_edits`
642 echo "1" > $testroot/repo/numbers
643 echo "2" >> $testroot/repo/numbers
644 echo "3" >> $testroot/repo/numbers
645 echo "4" >> $testroot/repo/numbers
646 echo "5" >> $testroot/repo/numbers
647 echo "6" >> $testroot/repo/numbers
648 echo "7" >> $testroot/repo/numbers
649 echo "8" >> $testroot/repo/numbers
650 (cd $testroot/repo && git add numbers)
651 git_commit $testroot/repo -m "added numbers file"
652 local base_commit=`git_show_head $testroot/repo`
654 got checkout $testroot/repo $testroot/wt > /dev/null
655 ret=$?
656 if [ $ret -ne 0 ]; then
657 test_done "$testroot" "$ret"
658 return 1
659 fi
661 echo "modified alpha" > $testroot/repo/alpha
662 echo "modified beta" > $testroot/repo/beta
663 sed -i 's/2/22/' $testroot/repo/numbers
664 git_commit $testroot/repo -m "modified 3 files"
666 echo "modified alpha, too" > $testroot/wt/alpha
667 touch $testroot/wt/beta
668 sed -i 's/7/77/' $testroot/wt/numbers
670 echo "C alpha" > $testroot/stdout.expected
671 echo "U beta" >> $testroot/stdout.expected
672 echo "G numbers" >> $testroot/stdout.expected
673 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
674 git_show_head $testroot/repo >> $testroot/stdout.expected
675 echo >> $testroot/stdout.expected
676 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
678 (cd $testroot/wt && got update > $testroot/stdout)
680 cmp -s $testroot/stdout.expected $testroot/stdout
681 ret=$?
682 if [ $ret -ne 0 ]; then
683 diff -u $testroot/stdout.expected $testroot/stdout
684 test_done "$testroot" "$ret"
685 return 1
686 fi
688 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
689 git_show_head $testroot/repo >> $testroot/content.expected
690 echo >> $testroot/content.expected
691 echo "modified alpha" >> $testroot/content.expected
692 echo "||||||| 3-way merge base: commit $base_commit" \
693 >> $testroot/content.expected
694 echo "alpha" >> $testroot/content.expected
695 echo "=======" >> $testroot/content.expected
696 echo "modified alpha, too" >> $testroot/content.expected
697 echo '>>>>>>>' >> $testroot/content.expected
698 echo "modified beta" >> $testroot/content.expected
699 echo "1" >> $testroot/content.expected
700 echo "22" >> $testroot/content.expected
701 echo "3" >> $testroot/content.expected
702 echo "4" >> $testroot/content.expected
703 echo "5" >> $testroot/content.expected
704 echo "6" >> $testroot/content.expected
705 echo "77" >> $testroot/content.expected
706 echo "8" >> $testroot/content.expected
708 cat $testroot/wt/alpha > $testroot/content
709 cat $testroot/wt/beta >> $testroot/content
710 cat $testroot/wt/numbers >> $testroot/content
712 cmp -s $testroot/content.expected $testroot/content
713 ret=$?
714 if [ $ret -ne 0 ]; then
715 diff -u $testroot/content.expected $testroot/content
716 fi
717 test_done "$testroot" "$ret"
720 test_update_keeps_xbit() {
721 local testroot=`test_init update_keeps_xbit 1`
723 touch $testroot/repo/xfile
724 chmod +x $testroot/repo/xfile
725 (cd $testroot/repo && git add .)
726 git_commit $testroot/repo -m "adding executable file"
728 got checkout $testroot/repo $testroot/wt > $testroot/stdout
729 ret=$?
730 if [ $ret -ne 0 ]; then
731 test_done "$testroot" "$ret"
732 return 1
733 fi
735 echo foo > $testroot/repo/xfile
736 git_commit $testroot/repo -m "changed executable file"
738 echo "U xfile" > $testroot/stdout.expected
739 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
740 git_show_head $testroot/repo >> $testroot/stdout.expected
741 echo >> $testroot/stdout.expected
743 (cd $testroot/wt && got update > $testroot/stdout)
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 test_done "$testroot" "$ret"
747 return 1
748 fi
750 cmp -s $testroot/stdout.expected $testroot/stdout
751 ret=$?
752 if [ $ret -ne 0 ]; then
753 diff -u $testroot/stdout.expected $testroot/stdout
754 test_done "$testroot" "$ret"
755 return 1
756 fi
758 ls -l $testroot/wt/xfile | grep -q '^-rwx'
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 echo "file is not executable" >&2
762 ls -l $testroot/wt/xfile >&2
763 fi
764 test_done "$testroot" "$ret"
767 test_update_clears_xbit() {
768 local testroot=`test_init update_clears_xbit 1`
770 touch $testroot/repo/xfile
771 chmod +x $testroot/repo/xfile
772 (cd $testroot/repo && git add .)
773 git_commit $testroot/repo -m "adding executable file"
775 got checkout $testroot/repo $testroot/wt > $testroot/stdout
776 ret=$?
777 if [ $ret -ne 0 ]; then
778 test_done "$testroot" "$ret"
779 return 1
780 fi
782 ls -l $testroot/wt/xfile | grep -q '^-rwx'
783 ret=$?
784 if [ $ret -ne 0 ]; then
785 echo "file is not executable" >&2
786 ls -l $testroot/wt/xfile >&2
787 test_done "$testroot" "$ret"
788 return 1
789 fi
791 # XXX git seems to require a file edit when flipping the x bit?
792 echo foo > $testroot/repo/xfile
793 chmod -x $testroot/repo/xfile
794 git_commit $testroot/repo -m "not an executable file anymore"
796 echo "U xfile" > $testroot/stdout.expected
797 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
798 git_show_head $testroot/repo >> $testroot/stdout.expected
799 echo >> $testroot/stdout.expected
801 (cd $testroot/wt && got update > $testroot/stdout)
802 ret=$?
803 if [ $ret -ne 0 ]; then
804 test_done "$testroot" "$ret"
805 return 1
806 fi
808 cmp -s $testroot/stdout.expected $testroot/stdout
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 diff -u $testroot/stdout.expected $testroot/stdout
812 test_done "$testroot" "$ret"
813 return 1
814 fi
816 ls -l $testroot/wt/xfile | grep -q '^-rw-'
817 ret=$?
818 if [ $ret -ne 0 ]; then
819 echo "file is unexpectedly executable" >&2
820 ls -l $testroot/wt/xfile >&2
821 fi
822 test_done "$testroot" "$ret"
825 test_update_restores_missing_file() {
826 local testroot=`test_init update_restores_missing_file`
828 got checkout $testroot/repo $testroot/wt > /dev/null
829 ret=$?
830 if [ $ret -ne 0 ]; then
831 test_done "$testroot" "$ret"
832 return 1
833 fi
835 rm $testroot/wt/alpha
837 echo "! alpha" > $testroot/stdout.expected
838 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
839 git_show_head $testroot/repo >> $testroot/stdout.expected
840 echo >> $testroot/stdout.expected
841 (cd $testroot/wt && got update > $testroot/stdout)
843 cmp -s $testroot/stdout.expected $testroot/stdout
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
847 test_done "$testroot" "$ret"
848 return 1
849 fi
851 echo "alpha" > $testroot/content.expected
853 cat $testroot/wt/alpha > $testroot/content
855 cmp -s $testroot/content.expected $testroot/content
856 ret=$?
857 if [ $ret -ne 0 ]; then
858 diff -u $testroot/content.expected $testroot/content
859 fi
860 test_done "$testroot" "$ret"
863 test_update_conflict_wt_add_vs_repo_add() {
864 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
866 got checkout $testroot/repo $testroot/wt > /dev/null
867 ret=$?
868 if [ $ret -ne 0 ]; then
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 echo "new" > $testroot/repo/gamma/new
874 (cd $testroot/repo && git add .)
875 git_commit $testroot/repo -m "adding a new file"
877 echo "also new" > $testroot/wt/gamma/new
878 (cd $testroot/wt && got add gamma/new >/dev/null)
880 (cd $testroot/wt && got update > $testroot/stdout)
882 echo "C gamma/new" > $testroot/stdout.expected
883 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
884 git_show_head $testroot/repo >> $testroot/stdout.expected
885 echo >> $testroot/stdout.expected
886 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
888 cmp -s $testroot/stdout.expected $testroot/stdout
889 ret=$?
890 if [ $ret -ne 0 ]; then
891 diff -u $testroot/stdout.expected $testroot/stdout
892 test_done "$testroot" "$ret"
893 return 1
894 fi
896 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
897 git_show_head $testroot/repo >> $testroot/content.expected
898 echo >> $testroot/content.expected
899 echo "new" >> $testroot/content.expected
900 echo "=======" >> $testroot/content.expected
901 echo "also new" >> $testroot/content.expected
902 echo '>>>>>>>' >> $testroot/content.expected
904 cat $testroot/wt/gamma/new > $testroot/content
906 cmp -s $testroot/content.expected $testroot/content
907 ret=$?
908 if [ $ret -ne 0 ]; then
909 diff -u $testroot/content.expected $testroot/content
910 test_done "$testroot" "$ret"
911 return 1
912 fi
914 # resolve the conflict
915 echo "new and also new" > $testroot/wt/gamma/new
916 echo 'M gamma/new' > $testroot/stdout.expected
917 (cd $testroot/wt && got status > $testroot/stdout)
918 cmp -s $testroot/stdout.expected $testroot/stdout
919 ret=$?
920 if [ $ret -ne 0 ]; then
921 diff -u $testroot/stdout.expected $testroot/stdout
922 fi
923 test_done "$testroot" "$ret"
926 test_update_conflict_wt_edit_vs_repo_rm() {
927 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
929 got checkout $testroot/repo $testroot/wt > /dev/null
930 ret=$?
931 if [ $ret -ne 0 ]; then
932 test_done "$testroot" "$ret"
933 return 1
934 fi
936 (cd $testroot/repo && git rm -q beta)
937 git_commit $testroot/repo -m "removing a file"
939 echo "modified beta" > $testroot/wt/beta
941 (cd $testroot/wt && got update > $testroot/stdout)
943 echo "G beta" > $testroot/stdout.expected
944 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
945 git_show_head $testroot/repo >> $testroot/stdout.expected
946 echo >> $testroot/stdout.expected
947 cmp -s $testroot/stdout.expected $testroot/stdout
948 ret=$?
949 if [ $ret -ne 0 ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
951 test_done "$testroot" "$ret"
952 return 1
953 fi
955 echo "modified beta" > $testroot/content.expected
957 cat $testroot/wt/beta > $testroot/content
959 cmp -s $testroot/content.expected $testroot/content
960 ret=$?
961 if [ $ret -ne 0 ]; then
962 diff -u $testroot/content.expected $testroot/content
963 test_done "$testroot" "$ret"
964 return 1
965 fi
967 # beta is now an added file... we don't flag tree conflicts yet
968 echo 'A beta' > $testroot/stdout.expected
969 (cd $testroot/wt && got status > $testroot/stdout)
970 cmp -s $testroot/stdout.expected $testroot/stdout
971 ret=$?
972 if [ $ret -ne 0 ]; then
973 diff -u $testroot/stdout.expected $testroot/stdout
974 fi
975 test_done "$testroot" "$ret"
978 test_update_conflict_wt_rm_vs_repo_edit() {
979 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
981 got checkout $testroot/repo $testroot/wt > /dev/null
982 ret=$?
983 if [ $ret -ne 0 ]; then
984 test_done "$testroot" "$ret"
985 return 1
986 fi
988 echo "modified beta" > $testroot/repo/beta
989 git_commit $testroot/repo -m "modified a file"
991 (cd $testroot/wt && got rm beta > /dev/null)
993 (cd $testroot/wt && got update > $testroot/stdout)
995 echo "G beta" > $testroot/stdout.expected
996 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
997 git_show_head $testroot/repo >> $testroot/stdout.expected
998 echo >> $testroot/stdout.expected
999 cmp -s $testroot/stdout.expected $testroot/stdout
1000 ret=$?
1001 if [ $ret -ne 0 ]; then
1002 diff -u $testroot/stdout.expected $testroot/stdout
1003 test_done "$testroot" "$ret"
1004 return 1
1007 # beta remains a deleted file... we don't flag tree conflicts yet
1008 echo 'D beta' > $testroot/stdout.expected
1009 (cd $testroot/wt && got status > $testroot/stdout)
1010 cmp -s $testroot/stdout.expected $testroot/stdout
1011 ret=$?
1012 if [ $ret -ne 0 ]; then
1013 diff -u $testroot/stdout.expected $testroot/stdout
1014 test_done "$testroot" "$ret"
1015 return 1
1018 # 'got diff' should show post-update contents of beta being deleted
1019 local head_rev=`git_show_head $testroot/repo`
1020 echo "diff $testroot/wt" > $testroot/stdout.expected
1021 echo "commit - $head_rev" >> $testroot/stdout.expected
1022 echo "path + $testroot/wt" >> $testroot/stdout.expected
1023 echo -n 'blob - ' >> $testroot/stdout.expected
1024 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1025 >> $testroot/stdout.expected
1026 echo 'file + /dev/null' >> $testroot/stdout.expected
1027 echo '--- beta' >> $testroot/stdout.expected
1028 echo '+++ /dev/null' >> $testroot/stdout.expected
1029 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1030 echo '-modified beta' >> $testroot/stdout.expected
1032 (cd $testroot/wt && got diff > $testroot/stdout)
1033 cmp -s $testroot/stdout.expected $testroot/stdout
1034 ret=$?
1035 if [ $ret -ne 0 ]; then
1036 diff -u $testroot/stdout.expected $testroot/stdout
1038 test_done "$testroot" "$ret"
1041 test_update_conflict_wt_rm_vs_repo_rm() {
1042 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1044 got checkout $testroot/repo $testroot/wt > /dev/null
1045 ret=$?
1046 if [ $ret -ne 0 ]; then
1047 test_done "$testroot" "$ret"
1048 return 1
1051 (cd $testroot/repo && git rm -q beta)
1052 git_commit $testroot/repo -m "removing a file"
1054 (cd $testroot/wt && got rm beta > /dev/null)
1056 (cd $testroot/wt && got update > $testroot/stdout)
1058 echo "D beta" > $testroot/stdout.expected
1059 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1060 git_show_head $testroot/repo >> $testroot/stdout.expected
1061 echo >> $testroot/stdout.expected
1062 cmp -s $testroot/stdout.expected $testroot/stdout
1063 ret=$?
1064 if [ $ret -ne 0 ]; then
1065 diff -u $testroot/stdout.expected $testroot/stdout
1066 test_done "$testroot" "$ret"
1067 return 1
1070 # beta is now gone... we don't flag tree conflicts yet
1071 echo "N beta" > $testroot/stdout.expected
1072 echo -n > $testroot/stderr.expected
1073 (cd $testroot/wt && got status beta > $testroot/stdout \
1074 2> $testroot/stderr)
1075 cmp -s $testroot/stdout.expected $testroot/stdout
1076 ret=$?
1077 if [ $ret -ne 0 ]; then
1078 diff -u $testroot/stdout.expected $testroot/stdout
1079 test_done "$testroot" "$ret"
1080 return 1
1082 cmp -s $testroot/stderr.expected $testroot/stderr
1083 ret=$?
1084 if [ $ret -ne 0 ]; then
1085 diff -u $testroot/stderr.expected $testroot/stderr
1086 test_done "$testroot" "$ret"
1087 return 1
1090 if [ -e $testroot/wt/beta ]; then
1091 echo "removed file beta still exists on disk" >&2
1092 test_done "$testroot" "1"
1093 return 1
1096 test_done "$testroot" "0"
1099 test_update_partial() {
1100 local testroot=`test_init update_partial`
1102 got checkout $testroot/repo $testroot/wt > /dev/null
1103 ret=$?
1104 if [ $ret -ne 0 ]; then
1105 test_done "$testroot" "$ret"
1106 return 1
1109 echo "modified alpha" > $testroot/repo/alpha
1110 echo "modified beta" > $testroot/repo/beta
1111 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1112 git_commit $testroot/repo -m "modified two files"
1114 echo "U alpha" > $testroot/stdout.expected
1115 echo "U beta" >> $testroot/stdout.expected
1116 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1117 git_show_head $testroot/repo >> $testroot/stdout.expected
1118 echo >> $testroot/stdout.expected
1120 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1122 cmp -s $testroot/stdout.expected $testroot/stdout
1123 ret=$?
1124 if [ $ret -ne 0 ]; then
1125 diff -u $testroot/stdout.expected $testroot/stdout
1126 test_done "$testroot" "$ret"
1127 return 1
1130 echo "modified alpha" > $testroot/content.expected
1131 echo "modified beta" >> $testroot/content.expected
1133 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1134 cmp -s $testroot/content.expected $testroot/content
1135 ret=$?
1136 if [ $ret -ne 0 ]; then
1137 diff -u $testroot/content.expected $testroot/content
1138 test_done "$testroot" "$ret"
1139 return 1
1142 echo "U epsilon/zeta" > $testroot/stdout.expected
1143 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1144 git_show_head $testroot/repo >> $testroot/stdout.expected
1145 echo >> $testroot/stdout.expected
1147 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1149 cmp -s $testroot/stdout.expected $testroot/stdout
1150 ret=$?
1151 if [ $ret -ne 0 ]; then
1152 diff -u $testroot/stdout.expected $testroot/stdout
1153 test_done "$testroot" "$ret"
1154 return 1
1157 echo "modified epsilon/zeta" > $testroot/content.expected
1158 cat $testroot/wt/epsilon/zeta > $testroot/content
1160 cmp -s $testroot/content.expected $testroot/content
1161 ret=$?
1162 if [ $ret -ne 0 ]; then
1163 diff -u $testroot/content.expected $testroot/content
1164 test_done "$testroot" "$ret"
1165 return 1
1168 test_done "$testroot" "$ret"
1171 test_update_partial_add() {
1172 local testroot=`test_init update_partial_add`
1174 got checkout $testroot/repo $testroot/wt > /dev/null
1175 ret=$?
1176 if [ $ret -ne 0 ]; then
1177 test_done "$testroot" "$ret"
1178 return 1
1181 echo "new" > $testroot/repo/new
1182 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1183 (cd $testroot/repo && git add .)
1184 git_commit $testroot/repo -m "added two files"
1186 echo "A epsilon/new2" > $testroot/stdout.expected
1187 echo "A new" >> $testroot/stdout.expected
1188 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1189 git_show_head $testroot/repo >> $testroot/stdout.expected
1190 echo >> $testroot/stdout.expected
1192 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1194 cmp -s $testroot/stdout.expected $testroot/stdout
1195 ret=$?
1196 if [ $ret -ne 0 ]; then
1197 diff -u $testroot/stdout.expected $testroot/stdout
1198 test_done "$testroot" "$ret"
1199 return 1
1202 echo "new" > $testroot/content.expected
1203 echo "epsilon/new2" >> $testroot/content.expected
1205 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1207 cmp -s $testroot/content.expected $testroot/content
1208 ret=$?
1209 if [ $ret -ne 0 ]; then
1210 diff -u $testroot/content.expected $testroot/content
1212 test_done "$testroot" "$ret"
1215 test_update_partial_rm() {
1216 local testroot=`test_init update_partial_rm`
1218 got checkout $testroot/repo $testroot/wt > /dev/null
1219 ret=$?
1220 if [ $ret -ne 0 ]; then
1221 test_done "$testroot" "$ret"
1222 return 1
1225 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1226 git_commit $testroot/repo -m "removed two files"
1228 echo "got: /alpha: no such entry found in tree" \
1229 > $testroot/stderr.expected
1231 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1232 ret=$?
1233 if [ $ret -eq 0 ]; then
1234 echo "update succeeded unexpectedly" >&2
1235 test_done "$testroot" "1"
1236 return 1
1239 cmp -s $testroot/stderr.expected $testroot/stderr
1240 ret=$?
1241 if [ $ret -ne 0 ]; then
1242 diff -u $testroot/stderr.expected $testroot/stderr
1243 test_done "$testroot" "$ret"
1244 return 1
1246 test_done "$testroot" "$ret"
1249 test_update_partial_dir() {
1250 local testroot=`test_init update_partial_dir`
1252 got checkout $testroot/repo $testroot/wt > /dev/null
1253 ret=$?
1254 if [ $ret -ne 0 ]; then
1255 test_done "$testroot" "$ret"
1256 return 1
1259 echo "modified alpha" > $testroot/repo/alpha
1260 echo "modified beta" > $testroot/repo/beta
1261 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1262 git_commit $testroot/repo -m "modified two files"
1264 echo "U epsilon/zeta" > $testroot/stdout.expected
1265 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1266 git_show_head $testroot/repo >> $testroot/stdout.expected
1267 echo >> $testroot/stdout.expected
1269 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1271 cmp -s $testroot/stdout.expected $testroot/stdout
1272 ret=$?
1273 if [ $ret -ne 0 ]; then
1274 diff -u $testroot/stdout.expected $testroot/stdout
1275 test_done "$testroot" "$ret"
1276 return 1
1279 echo "modified epsilon/zeta" > $testroot/content.expected
1280 cat $testroot/wt/epsilon/zeta > $testroot/content
1282 cmp -s $testroot/content.expected $testroot/content
1283 ret=$?
1284 if [ $ret -ne 0 ]; then
1285 diff -u $testroot/content.expected $testroot/content
1286 test_done "$testroot" "$ret"
1287 return 1
1289 test_done "$testroot" "$ret"
1293 test_update_moved_branch_ref() {
1294 local testroot=`test_init update_moved_branch_ref`
1296 git clone -q --mirror $testroot/repo $testroot/repo2
1298 echo "modified alpha with git" > $testroot/repo/alpha
1299 git_commit $testroot/repo -m "modified alpha with git"
1301 got checkout $testroot/repo2 $testroot/wt > /dev/null
1302 ret=$?
1303 if [ $ret -ne 0 ]; then
1304 test_done "$testroot" "$ret"
1305 return 1
1308 echo "modified alpha with got" > $testroot/wt/alpha
1309 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1311 # + xxxxxxx...yyyyyyy master -> master (forced update)
1312 (cd $testroot/repo2 && git fetch -q --all)
1314 echo -n > $testroot/stdout.expected
1315 echo -n "got: work tree's head reference now points to a different " \
1316 > $testroot/stderr.expected
1317 echo "branch; new head reference and/or update -b required" \
1318 >> $testroot/stderr.expected
1320 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1322 cmp -s $testroot/stdout.expected $testroot/stdout
1323 ret=$?
1324 if [ $ret -ne 0 ]; then
1325 diff -u $testroot/stdout.expected $testroot/stdout
1326 test_done "$testroot" "$ret"
1327 return 1
1330 cmp -s $testroot/stderr.expected $testroot/stderr
1331 ret=$?
1332 if [ $ret -ne 0 ]; then
1333 diff -u $testroot/stderr.expected $testroot/stderr
1335 test_done "$testroot" "$ret"
1338 test_update_to_another_branch() {
1339 local testroot=`test_init update_to_another_branch`
1340 local base_commit=`git_show_head $testroot/repo`
1342 got checkout $testroot/repo $testroot/wt > /dev/null
1343 ret=$?
1344 if [ $ret -ne 0 ]; then
1345 test_done "$testroot" "$ret"
1346 return 1
1349 echo 'refs/heads/master'> $testroot/head-ref.expected
1350 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1351 ret=$?
1352 if [ $ret -ne 0 ]; then
1353 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1354 test_done "$testroot" "$ret"
1355 return 1
1358 (cd $testroot/repo && git checkout -q -b newbranch)
1359 echo "modified alpha on new branch" > $testroot/repo/alpha
1360 git_commit $testroot/repo -m "modified alpha on new branch"
1362 echo "modified alpha in work tree" > $testroot/wt/alpha
1364 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1365 echo "C alpha" >> $testroot/stdout.expected
1366 echo -n "Updated to refs/heads/newbranch: " >> $testroot/stdout.expected
1367 git_show_head $testroot/repo >> $testroot/stdout.expected
1368 echo >> $testroot/stdout.expected
1369 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1371 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1373 cmp -s $testroot/stdout.expected $testroot/stdout
1374 ret=$?
1375 if [ $ret -ne 0 ]; then
1376 diff -u $testroot/stdout.expected $testroot/stdout
1377 test_done "$testroot" "$ret"
1378 return 1
1381 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
1382 git_show_head $testroot/repo >> $testroot/content.expected
1383 echo >> $testroot/content.expected
1384 echo "modified alpha on new branch" >> $testroot/content.expected
1385 echo "||||||| 3-way merge base: commit $base_commit" \
1386 >> $testroot/content.expected
1387 echo "alpha" >> $testroot/content.expected
1388 echo "=======" >> $testroot/content.expected
1389 echo "modified alpha in work tree" >> $testroot/content.expected
1390 echo '>>>>>>>' >> $testroot/content.expected
1392 cat $testroot/wt/alpha > $testroot/content
1394 cmp -s $testroot/content.expected $testroot/content
1395 ret=$?
1396 if [ $ret -ne 0 ]; then
1397 diff -u $testroot/content.expected $testroot/content
1398 test_done "$testroot" "$ret"
1399 return 1
1402 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1403 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1404 ret=$?
1405 if [ $ret -ne 0 ]; then
1406 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1407 test_done "$testroot" "$ret"
1408 return 1
1411 test_done "$testroot" "$ret"
1414 test_update_to_commit_on_wrong_branch() {
1415 local testroot=`test_init update_to_commit_on_wrong_branch`
1417 got checkout $testroot/repo $testroot/wt > /dev/null
1418 ret=$?
1419 if [ $ret -ne 0 ]; then
1420 test_done "$testroot" "$ret"
1421 return 1
1424 (cd $testroot/repo && git checkout -q -b newbranch)
1425 echo "modified alpha on new branch" > $testroot/repo/alpha
1426 git_commit $testroot/repo -m "modified alpha on new branch"
1428 echo -n "" > $testroot/stdout.expected
1429 echo "got: target commit is on a different branch" \
1430 > $testroot/stderr.expected
1432 local head_rev=`git_show_head $testroot/repo`
1433 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1434 2> $testroot/stderr)
1436 cmp -s $testroot/stdout.expected $testroot/stdout
1437 ret=$?
1438 if [ $ret -ne 0 ]; then
1439 diff -u $testroot/stdout.expected $testroot/stdout
1440 test_done "$testroot" "$ret"
1441 return 1
1444 cmp -s $testroot/stderr.expected $testroot/stderr
1445 ret=$?
1446 if [ $ret -ne 0 ]; then
1447 diff -u $testroot/stderr.expected $testroot/stderr
1448 test_done "$testroot" "$ret"
1449 return 1
1452 test_done "$testroot" "$ret"
1455 test_update_bumps_base_commit_id() {
1456 local testroot=`test_init update_bumps_base_commit_id`
1458 echo "psi" > $testroot/repo/epsilon/psi
1459 (cd $testroot/repo && git add .)
1460 git_commit $testroot/repo -m "adding another file"
1462 got checkout $testroot/repo $testroot/wt > /dev/null
1463 ret=$?
1464 if [ $ret -ne 0 ]; then
1465 test_done "$testroot" "$ret"
1466 return 1
1469 echo "modified psi" > $testroot/wt/epsilon/psi
1470 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1472 local head_rev=`git_show_head $testroot/repo`
1473 echo "M epsilon/psi" > $testroot/stdout.expected
1474 echo "Created commit $head_rev" >> $testroot/stdout.expected
1475 cmp -s $testroot/stdout.expected $testroot/stdout
1476 ret=$?
1477 if [ $ret -ne 0 ]; then
1478 diff -u $testroot/stdout.expected $testroot/stdout
1479 test_done "$testroot" "$ret"
1480 return 1
1483 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1484 (cd $testroot/repo && git add .)
1485 git_commit $testroot/repo -m "changing zeta with git"
1487 echo "modified zeta" > $testroot/wt/epsilon/zeta
1488 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1489 2> $testroot/stderr)
1491 echo -n "" > $testroot/stdout.expected
1492 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1493 cmp -s $testroot/stderr.expected $testroot/stderr
1494 ret=$?
1495 if [ $ret -ne 0 ]; then
1496 diff -u $testroot/stderr.expected $testroot/stderr
1497 test_done "$testroot" "$ret"
1498 return 1
1501 (cd $testroot/wt && got update > $testroot/stdout)
1503 echo "U epsilon/psi" > $testroot/stdout.expected
1504 echo "C epsilon/zeta" >> $testroot/stdout.expected
1505 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1506 git_show_head $testroot/repo >> $testroot/stdout.expected
1507 echo >> $testroot/stdout.expected
1508 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1510 cmp -s $testroot/stdout.expected $testroot/stdout
1511 ret=$?
1512 if [ $ret -ne 0 ]; then
1513 diff -u $testroot/stdout.expected $testroot/stdout
1514 test_done "$testroot" "$ret"
1515 return 1
1518 # resolve conflict
1519 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1521 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1523 local head_rev=`git_show_head $testroot/repo`
1524 echo "M epsilon/zeta" > $testroot/stdout.expected
1525 echo "Created commit $head_rev" >> $testroot/stdout.expected
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1527 ret=$?
1528 if [ $ret -ne 0 ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1531 return 1
1534 test_done "$testroot" "$ret"
1537 test_update_tag() {
1538 local testroot=`test_init update_tag`
1539 local tag="1.0.0"
1541 got checkout $testroot/repo $testroot/wt > /dev/null
1542 ret=$?
1543 if [ $ret -ne 0 ]; then
1544 test_done "$testroot" "$ret"
1545 return 1
1548 echo "modified alpha" > $testroot/repo/alpha
1549 git_commit $testroot/repo -m "modified alpha"
1550 (cd $testroot/repo && git tag -m "test" -a $tag)
1552 echo "U alpha" > $testroot/stdout.expected
1553 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1554 git_show_head $testroot/repo >> $testroot/stdout.expected
1555 echo >> $testroot/stdout.expected
1557 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1559 cmp -s $testroot/stdout.expected $testroot/stdout
1560 ret=$?
1561 if [ $ret -ne 0 ]; then
1562 diff -u $testroot/stdout.expected $testroot/stdout
1563 test_done "$testroot" "$ret"
1564 return 1
1567 echo "modified alpha" > $testroot/content.expected
1568 cat $testroot/wt/alpha > $testroot/content
1570 cmp -s $testroot/content.expected $testroot/content
1571 ret=$?
1572 if [ $ret -ne 0 ]; then
1573 diff -u $testroot/content.expected $testroot/content
1575 test_done "$testroot" "$ret"
1578 test_update_toggles_xbit() {
1579 local testroot=`test_init update_toggles_xbit 1`
1581 touch $testroot/repo/xfile
1582 chmod +x $testroot/repo/xfile
1583 (cd $testroot/repo && git add .)
1584 git_commit $testroot/repo -m "adding executable file"
1585 local commit_id1=`git_show_head $testroot/repo`
1587 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1588 ret=$?
1589 if [ $ret -ne 0 ]; then
1590 test_done "$testroot" "$ret"
1591 return 1
1594 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1595 ret=$?
1596 if [ $ret -ne 0 ]; then
1597 echo "file is not executable" >&2
1598 ls -l $testroot/wt/xfile >&2
1599 test_done "$testroot" "$ret"
1600 return 1
1603 chmod -x $testroot/wt/xfile
1604 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1605 local commit_id2=`git_show_head $testroot/repo`
1607 echo "U xfile" > $testroot/stdout.expected
1608 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1609 git_show_head $testroot/repo >> $testroot/stdout.expected
1610 echo >> $testroot/stdout.expected
1612 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1613 ret=$?
1614 if [ $ret -ne 0 ]; then
1615 test_done "$testroot" "$ret"
1616 return 1
1619 echo "U xfile" > $testroot/stdout.expected
1620 echo "Updated to refs/heads/master: $commit_id1" >> $testroot/stdout.expected
1621 cmp -s $testroot/stdout.expected $testroot/stdout
1622 ret=$?
1623 if [ $ret -ne 0 ]; then
1624 diff -u $testroot/stdout.expected $testroot/stdout
1625 test_done "$testroot" "$ret"
1626 return 1
1630 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1631 ret=$?
1632 if [ $ret -ne 0 ]; then
1633 echo "file is not executable" >&2
1634 ls -l $testroot/wt/xfile >&2
1635 test_done "$testroot" "$ret"
1636 return 1
1639 (cd $testroot/wt && got update > $testroot/stdout)
1640 ret=$?
1641 if [ $ret -ne 0 ]; then
1642 test_done "$testroot" "$ret"
1643 return 1
1646 echo "U xfile" > $testroot/stdout.expected
1647 echo "Updated to refs/heads/master: $commit_id2" \
1648 >> $testroot/stdout.expected
1649 cmp -s $testroot/stdout.expected $testroot/stdout
1650 ret=$?
1651 if [ $ret -ne 0 ]; then
1652 diff -u $testroot/stdout.expected $testroot/stdout
1653 test_done "$testroot" "$ret"
1654 return 1
1657 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1658 ret=$?
1659 if [ $ret -ne 0 ]; then
1660 echo "file is unexpectedly executable" >&2
1661 ls -l $testroot/wt/xfile >&2
1663 test_done "$testroot" "$ret"
1666 test_update_preserves_conflicted_file() {
1667 local testroot=`test_init update_preserves_conflicted_file`
1668 local commit_id0=`git_show_head $testroot/repo`
1670 echo "modified alpha" > $testroot/repo/alpha
1671 git_commit $testroot/repo -m "modified alpha"
1672 local commit_id1=`git_show_head $testroot/repo`
1674 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
1675 ret=$?
1676 if [ $ret -ne 0 ]; then
1677 test_done "$testroot" "$ret"
1678 return 1
1681 # fake a merge conflict
1682 echo '<<<<<<<' > $testroot/wt/alpha
1683 echo 'alpha' >> $testroot/wt/alpha
1684 echo '=======' >> $testroot/wt/alpha
1685 echo 'alpha, too' >> $testroot/wt/alpha
1686 echo '>>>>>>>' >> $testroot/wt/alpha
1687 cp $testroot/wt/alpha $testroot/content.expected
1689 echo "C alpha" > $testroot/stdout.expected
1690 (cd $testroot/wt && got status > $testroot/stdout)
1691 cmp -s $testroot/stdout.expected $testroot/stdout
1692 ret=$?
1693 if [ $ret -ne 0 ]; then
1694 diff -u $testroot/stdout.expected $testroot/stdout
1695 test_done "$testroot" "$ret"
1696 return 1
1699 echo "# alpha" > $testroot/stdout.expected
1700 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1701 git_show_head $testroot/repo >> $testroot/stdout.expected
1702 echo >> $testroot/stdout.expected
1703 echo "Files not updated because of existing merge conflicts: 1" \
1704 >> $testroot/stdout.expected
1705 (cd $testroot/wt && got update > $testroot/stdout)
1707 cmp -s $testroot/stdout.expected $testroot/stdout
1708 ret=$?
1709 if [ $ret -ne 0 ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1711 test_done "$testroot" "$ret"
1712 return 1
1715 cmp -s $testroot/content.expected $testroot/wt/alpha
1716 ret=$?
1717 if [ $ret -ne 0 ]; then
1718 diff -u $testroot/content.expected $testroot/wt/alpha
1720 test_done "$testroot" "$ret"
1723 test_update_modified_submodules() {
1724 local testroot=`test_init update_modified_submodules`
1726 make_single_file_repo $testroot/repo2 foo
1728 (cd $testroot/repo && git submodule -q add ../repo2)
1729 (cd $testroot/repo && git commit -q -m 'adding submodule')
1731 got checkout $testroot/repo $testroot/wt > /dev/null
1733 echo "modified foo" > $testroot/repo2/foo
1734 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1736 # Update the repo/repo2 submodule link
1737 (cd $testroot/repo && git -C repo2 pull -q)
1738 (cd $testroot/repo && git add repo2)
1739 git_commit $testroot/repo -m "modified submodule link"
1741 # This update only records the new base commit. Otherwise it is a
1742 # no-op change because Got's file index does not track submodules.
1743 echo -n "Updated to refs/heads/master: " > $testroot/stdout.expected
1744 git_show_head $testroot/repo >> $testroot/stdout.expected
1745 echo >> $testroot/stdout.expected
1747 (cd $testroot/wt && got update > $testroot/stdout)
1749 cmp -s $testroot/stdout.expected $testroot/stdout
1750 ret=$?
1751 if [ $ret -ne 0 ]; then
1752 diff -u $testroot/stdout.expected $testroot/stdout
1754 test_done "$testroot" "$ret"
1757 test_update_adds_submodule() {
1758 local testroot=`test_init update_adds_submodule`
1760 got checkout $testroot/repo $testroot/wt > /dev/null
1762 make_single_file_repo $testroot/repo2 foo
1764 echo "modified foo" > $testroot/repo2/foo
1765 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1767 (cd $testroot/repo && git submodule -q add ../repo2)
1768 (cd $testroot/repo && git commit -q -m 'adding submodule')
1770 echo "A .gitmodules" > $testroot/stdout.expected
1771 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1772 git_show_head $testroot/repo >> $testroot/stdout.expected
1773 echo >> $testroot/stdout.expected
1775 (cd $testroot/wt && got update > $testroot/stdout)
1777 cmp -s $testroot/stdout.expected $testroot/stdout
1778 ret=$?
1779 if [ $ret -ne 0 ]; then
1780 diff -u $testroot/stdout.expected $testroot/stdout
1782 test_done "$testroot" "$ret"
1785 test_update_conflict_wt_file_vs_repo_submodule() {
1786 local testroot=`test_init update_conflict_wt_file_vs_repo_submodule`
1788 got checkout $testroot/repo $testroot/wt > /dev/null
1790 make_single_file_repo $testroot/repo2 foo
1792 # Add a file which will clash with the submodule
1793 echo "This is a file called repo2" > $testroot/wt/repo2
1794 (cd $testroot/wt && got add repo2 > /dev/null)
1795 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
1796 ret=$?
1797 if [ $ret -ne 0 ]; then
1798 echo "commit failed unexpectedly" >&2
1799 test_done "$testroot" "1"
1800 return 1
1803 (cd $testroot/repo && git submodule -q add ../repo2)
1804 (cd $testroot/repo && git commit -q -m 'adding submodule')
1806 # Modify the clashing file such that any modifications brought
1807 # in by 'got update' would require a merge.
1808 echo "This file was changed" > $testroot/wt/repo2
1810 # No conflict occurs because 'got update' ignores the submodule
1811 # and leaves the clashing file as it was.
1812 echo "A .gitmodules" > $testroot/stdout.expected
1813 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1814 git_show_head $testroot/repo >> $testroot/stdout.expected
1815 echo >> $testroot/stdout.expected
1817 (cd $testroot/wt && got update > $testroot/stdout)
1819 cmp -s $testroot/stdout.expected $testroot/stdout
1820 ret=$?
1821 if [ $ret -ne 0 ]; then
1822 diff -u $testroot/stdout.expected $testroot/stdout
1823 test_done "$testroot" "$ret"
1824 return 1
1827 (cd $testroot/wt && got status > $testroot/stdout)
1829 echo "M repo2" > $testroot/stdout.expected
1830 cmp -s $testroot/stdout.expected $testroot/stdout
1831 ret=$?
1832 if [ $ret -ne 0 ]; then
1833 diff -u $testroot/stdout.expected $testroot/stdout
1835 test_done "$testroot" "$ret"
1838 test_update_adds_symlink() {
1839 local testroot=`test_init update_adds_symlink`
1841 got checkout $testroot/repo $testroot/wt > /dev/null
1842 ret=$?
1843 if [ $ret -ne 0 ]; then
1844 echo "checkout failed unexpectedly" >&2
1845 test_done "$testroot" "$ret"
1846 return 1
1849 (cd $testroot/repo && ln -s alpha alpha.link)
1850 (cd $testroot/repo && ln -s epsilon epsilon.link)
1851 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1852 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1853 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1854 (cd $testroot/repo && git add .)
1855 git_commit $testroot/repo -m "add symlinks"
1857 echo "A alpha.link" > $testroot/stdout.expected
1858 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1859 echo "A epsilon.link" >> $testroot/stdout.expected
1860 echo "A nonexistent.link" >> $testroot/stdout.expected
1861 echo "A passwd.link" >> $testroot/stdout.expected
1862 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1863 git_show_head $testroot/repo >> $testroot/stdout.expected
1864 echo >> $testroot/stdout.expected
1866 (cd $testroot/wt && got update > $testroot/stdout)
1868 cmp -s $testroot/stdout.expected $testroot/stdout
1869 ret=$?
1870 if [ $ret -ne 0 ]; then
1871 diff -u $testroot/stdout.expected $testroot/stdout
1872 test_done "$testroot" "$ret"
1873 return 1
1876 if ! [ -h $testroot/wt/alpha.link ]; then
1877 echo "alpha.link is not a symlink"
1878 test_done "$testroot" "1"
1879 return 1
1882 readlink $testroot/wt/alpha.link > $testroot/stdout
1883 echo "alpha" > $testroot/stdout.expected
1884 cmp -s $testroot/stdout.expected $testroot/stdout
1885 ret=$?
1886 if [ $ret -ne 0 ]; then
1887 diff -u $testroot/stdout.expected $testroot/stdout
1888 test_done "$testroot" "$ret"
1889 return 1
1892 if ! [ -h $testroot/wt/epsilon.link ]; then
1893 echo "epsilon.link is not a symlink"
1894 test_done "$testroot" "1"
1895 return 1
1898 readlink $testroot/wt/epsilon.link > $testroot/stdout
1899 echo "epsilon" > $testroot/stdout.expected
1900 cmp -s $testroot/stdout.expected $testroot/stdout
1901 ret=$?
1902 if [ $ret -ne 0 ]; then
1903 diff -u $testroot/stdout.expected $testroot/stdout
1904 test_done "$testroot" "$ret"
1905 return 1
1908 if [ -h $testroot/wt/passwd.link ]; then
1909 echo -n "passwd.link symlink points outside of work tree: " >&2
1910 readlink $testroot/wt/passwd.link >&2
1911 test_done "$testroot" "1"
1912 return 1
1915 echo -n "/etc/passwd" > $testroot/content.expected
1916 cp $testroot/wt/passwd.link $testroot/content
1918 cmp -s $testroot/content.expected $testroot/content
1919 ret=$?
1920 if [ $ret -ne 0 ]; then
1921 diff -u $testroot/content.expected $testroot/content
1922 test_done "$testroot" "$ret"
1923 return 1
1926 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1927 echo "../beta" > $testroot/stdout.expected
1928 cmp -s $testroot/stdout.expected $testroot/stdout
1929 ret=$?
1930 if [ $ret -ne 0 ]; then
1931 diff -u $testroot/stdout.expected $testroot/stdout
1932 test_done "$testroot" "$ret"
1933 return 1
1936 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1937 echo "nonexistent" > $testroot/stdout.expected
1938 cmp -s $testroot/stdout.expected $testroot/stdout
1939 ret=$?
1940 if [ $ret -ne 0 ]; then
1941 diff -u $testroot/stdout.expected $testroot/stdout
1942 test_done "$testroot" "$ret"
1943 return 1
1946 # Updating an up-to-date symlink should be a no-op.
1947 echo 'Already up-to-date' > $testroot/stdout.expected
1948 (cd $testroot/wt && got update > $testroot/stdout)
1949 cmp -s $testroot/stdout.expected $testroot/stdout
1950 ret=$?
1951 if [ $ret -ne 0 ]; then
1952 diff -u $testroot/stdout.expected $testroot/stdout
1954 test_done "$testroot" "$ret"
1957 test_update_deletes_symlink() {
1958 local testroot=`test_init update_deletes_symlink`
1960 (cd $testroot/repo && ln -s alpha alpha.link)
1961 (cd $testroot/repo && git add .)
1962 git_commit $testroot/repo -m "add symlink"
1964 got checkout $testroot/repo $testroot/wt > /dev/null
1965 ret=$?
1966 if [ $ret -ne 0 ]; then
1967 echo "checkout failed unexpectedly" >&2
1968 test_done "$testroot" "$ret"
1969 return 1
1972 (cd $testroot/repo && git rm -q alpha.link)
1973 git_commit $testroot/repo -m "delete symlink"
1975 echo "D alpha.link" > $testroot/stdout.expected
1976 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1977 git_show_head $testroot/repo >> $testroot/stdout.expected
1978 echo >> $testroot/stdout.expected
1980 (cd $testroot/wt && got update > $testroot/stdout)
1982 cmp -s $testroot/stdout.expected $testroot/stdout
1983 ret=$?
1984 if [ $ret -ne 0 ]; then
1985 diff -u $testroot/stdout.expected $testroot/stdout
1986 test_done "$testroot" "$ret"
1987 return 1
1990 if [ -e $testroot/wt/alpha.link ]; then
1991 echo "alpha.link still exists on disk"
1992 test_done "$testroot" "1"
1993 return 1
1996 test_done "$testroot" "0"
1999 test_update_symlink_conflicts() {
2000 local testroot=`test_init update_symlink_conflicts`
2002 (cd $testroot/repo && ln -s alpha alpha.link)
2003 (cd $testroot/repo && ln -s epsilon epsilon.link)
2004 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2005 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2006 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2007 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
2008 (cd $testroot/repo && git add .)
2009 git_commit $testroot/repo -m "add symlinks"
2010 local commit_id1=`git_show_head $testroot/repo`
2012 got checkout $testroot/repo $testroot/wt > /dev/null
2013 ret=$?
2014 if [ $ret -ne 0 ]; then
2015 echo "checkout failed unexpectedly" >&2
2016 test_done "$testroot" "$ret"
2017 return 1
2020 (cd $testroot/repo && ln -sf beta alpha.link)
2021 (cd $testroot/repo && ln -sfh gamma epsilon.link)
2022 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
2023 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
2024 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
2025 (cd $testroot/repo && git rm -q nonexistent.link)
2026 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
2027 (cd $testroot/repo && ln -sf alpha new.link)
2028 (cd $testroot/repo && git add .)
2029 git_commit $testroot/repo -m "change symlinks"
2030 local commit_id2=`git_show_head $testroot/repo`
2032 # modified symlink to file A vs modified symlink to file B
2033 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
2034 # modified symlink to dir A vs modified symlink to file B
2035 (cd $testroot/wt && ln -sfh beta epsilon.link)
2036 # modeified symlink to file A vs modified symlink to dir B
2037 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
2038 # added regular file A vs added bad symlink to file A
2039 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
2040 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2041 # added bad symlink to file A vs added regular file A
2042 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
2043 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2044 # removed symlink to non-existent file A vs modified symlink
2045 # to nonexistent file B
2046 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
2047 # modified symlink to file A vs removed symlink to file A
2048 (cd $testroot/wt && got rm zeta.link > /dev/null)
2049 # added symlink to file A vs added symlink to file B
2050 (cd $testroot/wt && ln -sf beta new.link)
2051 (cd $testroot/wt && got add new.link > /dev/null)
2053 (cd $testroot/wt && got update > $testroot/stdout)
2055 echo "C alpha.link" >> $testroot/stdout.expected
2056 echo "C dotgotbar.link" >> $testroot/stdout.expected
2057 echo "C dotgotfoo.link" >> $testroot/stdout.expected
2058 echo "C epsilon/beta.link" >> $testroot/stdout.expected
2059 echo "C epsilon.link" >> $testroot/stdout.expected
2060 echo "C new.link" >> $testroot/stdout.expected
2061 echo "C nonexistent.link" >> $testroot/stdout.expected
2062 echo "G zeta.link" >> $testroot/stdout.expected
2063 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2064 git_show_head $testroot/repo >> $testroot/stdout.expected
2065 echo >> $testroot/stdout.expected
2066 echo "Files with new merge conflicts: 7" >> $testroot/stdout.expected
2068 cmp -s $testroot/stdout.expected $testroot/stdout
2069 ret=$?
2070 if [ $ret -ne 0 ]; then
2071 diff -u $testroot/stdout.expected $testroot/stdout
2072 test_done "$testroot" "$ret"
2073 return 1
2076 if [ -h $testroot/wt/alpha.link ]; then
2077 echo "alpha.link is a symlink"
2078 test_done "$testroot" "1"
2079 return 1
2082 echo "<<<<<<< merged change: commit $commit_id2" \
2083 > $testroot/content.expected
2084 echo "beta" >> $testroot/content.expected
2085 echo "3-way merge base: commit $commit_id1" \
2086 >> $testroot/content.expected
2087 echo "alpha" >> $testroot/content.expected
2088 echo "=======" >> $testroot/content.expected
2089 echo "gamma/delta" >> $testroot/content.expected
2090 echo '>>>>>>>' >> $testroot/content.expected
2091 echo -n "" >> $testroot/content.expected
2093 cp $testroot/wt/alpha.link $testroot/content
2094 cmp -s $testroot/content.expected $testroot/content
2095 ret=$?
2096 if [ $ret -ne 0 ]; then
2097 diff -u $testroot/content.expected $testroot/content
2098 test_done "$testroot" "$ret"
2099 return 1
2102 if [ -h $testroot/wt/epsilon.link ]; then
2103 echo "epsilon.link is a symlink"
2104 test_done "$testroot" "1"
2105 return 1
2108 echo "<<<<<<< merged change: commit $commit_id2" \
2109 > $testroot/content.expected
2110 echo "gamma" >> $testroot/content.expected
2111 echo "3-way merge base: commit $commit_id1" \
2112 >> $testroot/content.expected
2113 echo "epsilon" >> $testroot/content.expected
2114 echo "=======" >> $testroot/content.expected
2115 echo "beta" >> $testroot/content.expected
2116 echo '>>>>>>>' >> $testroot/content.expected
2117 echo -n "" >> $testroot/content.expected
2119 cp $testroot/wt/epsilon.link $testroot/content
2120 cmp -s $testroot/content.expected $testroot/content
2121 ret=$?
2122 if [ $ret -ne 0 ]; then
2123 diff -u $testroot/content.expected $testroot/content
2124 test_done "$testroot" "$ret"
2125 return 1
2128 if [ -h $testroot/wt/passwd.link ]; then
2129 echo -n "passwd.link symlink points outside of work tree: " >&2
2130 readlink $testroot/wt/passwd.link >&2
2131 test_done "$testroot" "1"
2132 return 1
2135 echo -n "/etc/passwd" > $testroot/content.expected
2136 cp $testroot/wt/passwd.link $testroot/content
2138 cmp -s $testroot/content.expected $testroot/content
2139 ret=$?
2140 if [ $ret -ne 0 ]; then
2141 diff -u $testroot/content.expected $testroot/content
2142 test_done "$testroot" "$ret"
2143 return 1
2146 if [ -h $testroot/wt/epsilon/beta.link ]; then
2147 echo "epsilon/beta.link is a symlink"
2148 test_done "$testroot" "1"
2149 return 1
2152 echo "<<<<<<< merged change: commit $commit_id2" \
2153 > $testroot/content.expected
2154 echo "../gamma/delta" >> $testroot/content.expected
2155 echo "3-way merge base: commit $commit_id1" \
2156 >> $testroot/content.expected
2157 echo "../beta" >> $testroot/content.expected
2158 echo "=======" >> $testroot/content.expected
2159 echo "../gamma" >> $testroot/content.expected
2160 echo '>>>>>>>' >> $testroot/content.expected
2161 echo -n "" >> $testroot/content.expected
2163 cp $testroot/wt/epsilon/beta.link $testroot/content
2164 cmp -s $testroot/content.expected $testroot/content
2165 ret=$?
2166 if [ $ret -ne 0 ]; then
2167 diff -u $testroot/content.expected $testroot/content
2168 test_done "$testroot" "$ret"
2169 return 1
2172 if [ -h $testroot/wt/nonexistent.link ]; then
2173 echo -n "nonexistent.link still exists on disk: " >&2
2174 readlink $testroot/wt/nonexistent.link >&2
2175 test_done "$testroot" "1"
2176 return 1
2179 echo "<<<<<<< merged change: commit $commit_id2" \
2180 > $testroot/content.expected
2181 echo "(symlink was deleted)" >> $testroot/content.expected
2182 echo "=======" >> $testroot/content.expected
2183 echo "nonexistent2" >> $testroot/content.expected
2184 echo '>>>>>>>' >> $testroot/content.expected
2185 echo -n "" >> $testroot/content.expected
2187 cp $testroot/wt/nonexistent.link $testroot/content
2188 cmp -s $testroot/content.expected $testroot/content
2189 ret=$?
2190 if [ $ret -ne 0 ]; then
2191 diff -u $testroot/content.expected $testroot/content
2192 test_done "$testroot" "$ret"
2193 return 1
2196 if [ -h $testroot/wt/dotgotfoo.link ]; then
2197 echo "dotgotfoo.link is a symlink"
2198 test_done "$testroot" "1"
2199 return 1
2202 echo "<<<<<<< merged change: commit $commit_id2" \
2203 > $testroot/content.expected
2204 echo "this is regular file foo" >> $testroot/content.expected
2205 echo "=======" >> $testroot/content.expected
2206 echo -n ".got/bar" >> $testroot/content.expected
2207 echo '>>>>>>>' >> $testroot/content.expected
2208 echo -n "" >> $testroot/content.expected
2210 cp $testroot/wt/dotgotfoo.link $testroot/content
2211 cmp -s $testroot/content.expected $testroot/content
2212 ret=$?
2213 if [ $ret -ne 0 ]; then
2214 diff -u $testroot/content.expected $testroot/content
2215 test_done "$testroot" "$ret"
2216 return 1
2219 if [ -h $testroot/wt/dotgotbar.link ]; then
2220 echo "dotgotbar.link is a symlink"
2221 test_done "$testroot" "1"
2222 return 1
2224 echo "<<<<<<< merged change: commit $commit_id2" \
2225 > $testroot/content.expected
2226 echo -n ".got/bar" >> $testroot/content.expected
2227 echo "=======" >> $testroot/content.expected
2228 echo "this is regular file bar" >> $testroot/content.expected
2229 echo '>>>>>>>' >> $testroot/content.expected
2230 echo -n "" >> $testroot/content.expected
2232 cp $testroot/wt/dotgotbar.link $testroot/content
2233 cmp -s $testroot/content.expected $testroot/content
2234 ret=$?
2235 if [ $ret -ne 0 ]; then
2236 diff -u $testroot/content.expected $testroot/content
2237 test_done "$testroot" "$ret"
2238 return 1
2241 if [ -h $testroot/wt/new.link ]; then
2242 echo "new.link is a symlink"
2243 test_done "$testroot" "1"
2244 return 1
2247 echo "<<<<<<< merged change: commit $commit_id2" \
2248 > $testroot/content.expected
2249 echo "alpha" >> $testroot/content.expected
2250 echo "=======" >> $testroot/content.expected
2251 echo "beta" >> $testroot/content.expected
2252 echo '>>>>>>>' >> $testroot/content.expected
2253 echo -n "" >> $testroot/content.expected
2255 cp $testroot/wt/new.link $testroot/content
2256 cmp -s $testroot/content.expected $testroot/content
2257 ret=$?
2258 if [ $ret -ne 0 ]; then
2259 diff -u $testroot/content.expected $testroot/content
2260 test_done "$testroot" "$ret"
2261 return 1
2264 echo "A dotgotfoo.link" > $testroot/stdout.expected
2265 echo "M new.link" >> $testroot/stdout.expected
2266 echo "D nonexistent.link" >> $testroot/stdout.expected
2267 (cd $testroot/wt && got status > $testroot/stdout)
2268 ret=$?
2269 if [ $ret -ne 0 ]; then
2270 diff -u $testroot/stdout.expected $testroot/stdout
2271 test_done "$testroot" "$ret"
2272 return 1
2275 test_done "$testroot" "0"
2279 test_update_single_file() {
2280 local testroot=`test_init update_single_file 1`
2282 echo c1 > $testroot/repo/c
2283 (cd $testroot/repo && git add .)
2284 git_commit $testroot/repo -m "adding file c"
2285 local commit_id1=`git_show_head $testroot/repo`
2287 echo a > $testroot/repo/a
2288 echo b > $testroot/repo/b
2289 echo c2 > $testroot/repo/c
2290 (cd $testroot/repo && git add .)
2291 git_commit $testroot/repo -m "add files a and b, change c"
2292 local commit_id2=`git_show_head $testroot/repo`
2294 (cd $testroot/repo && git rm -qf c)
2295 git_commit $testroot/repo -m "remove file c"
2296 local commit_id3=`git_show_head $testroot/repo`
2298 got checkout -c $commit_id2 $testroot/repo $testroot/wt > /dev/null
2299 ret=$?
2300 if [ $ret -ne 0 ]; then
2301 test_done "$testroot" "$ret"
2302 return 1
2305 echo "U c" > $testroot/stdout.expected
2306 echo "Updated to refs/heads/master: $commit_id1" \
2307 >> $testroot/stdout.expected
2309 (cd $testroot/wt && got update -c $commit_id1 c \
2310 > $testroot/stdout)
2312 cmp -s $testroot/stdout.expected $testroot/stdout
2313 ret=$?
2314 if [ $ret -ne 0 ]; then
2315 diff -u $testroot/stdout.expected $testroot/stdout
2316 test_done "$testroot" "$ret"
2317 return 1
2320 echo c1 > $testroot/content.expected
2321 cat $testroot/wt/c > $testroot/content
2323 cmp -s $testroot/content.expected $testroot/content
2324 ret=$?
2325 if [ $ret -ne 0 ]; then
2326 diff -u $testroot/content.expected $testroot/content
2327 test_done "$testroot" "$ret"
2328 return 1
2331 echo "U c" > $testroot/stdout.expected
2332 echo "Updated to refs/heads/master: $commit_id2" \
2333 >> $testroot/stdout.expected
2335 (cd $testroot/wt && got update -c $commit_id2 c > $testroot/stdout)
2337 cmp -s $testroot/stdout.expected $testroot/stdout
2338 ret=$?
2339 if [ $ret -ne 0 ]; then
2340 diff -u $testroot/stdout.expected $testroot/stdout
2341 test_done "$testroot" "$ret"
2342 return 1
2345 echo c2 > $testroot/content.expected
2346 cat $testroot/wt/c > $testroot/content
2348 cmp -s $testroot/content.expected $testroot/content
2349 ret=$?
2350 if [ $ret -ne 0 ]; then
2351 diff -u $testroot/content.expected $testroot/content
2352 test_done "$testroot" "$ret"
2353 return 1
2356 echo "D c" > $testroot/stdout.expected
2357 echo "Updated to refs/heads/master: $commit_id3" \
2358 >> $testroot/stdout.expected
2360 (cd $testroot/wt && got update -c $commit_id3 c \
2361 > $testroot/stdout 2> $testroot/stderr)
2363 echo "got: /c: no such entry found in tree" > $testroot/stderr.expected
2364 cmp -s $testroot/stderr.expected $testroot/stderr
2365 ret=$?
2366 if [ $ret -ne 0 ]; then
2367 diff -u $testroot/stderr.expected $testroot/stderr
2368 test_done "$testroot" "$ret"
2369 return 1
2372 echo -n > $testroot/stdout.expected
2373 cmp -s $testroot/stdout.expected $testroot/stdout
2374 ret=$?
2375 if [ $ret -ne 0 ]; then
2376 diff -u $testroot/stdout.expected $testroot/stdout
2377 test_done "$testroot" "$ret"
2378 return 1
2381 echo "D c" > $testroot/stdout.expected
2382 echo "Updated to refs/heads/master: $commit_id3" \
2383 >> $testroot/stdout.expected
2385 (cd $testroot/wt && got update -c $commit_id3 > $testroot/stdout)
2386 cmp -s $testroot/stdout.expected $testroot/stdout
2387 ret=$?
2388 if [ $ret -ne 0 ]; then
2389 diff -u $testroot/stdout.expected $testroot/stdout
2390 test_done "$testroot" "$ret"
2391 return 1
2394 if [ -e $testroot/wt/c ]; then
2395 echo "removed file c still exists on disk" >&2
2396 test_done "$testroot" "1"
2397 return 1
2400 test_done "$testroot" "0"
2401 return 0
2404 test_update_file_skipped_due_to_conflict() {
2405 local testroot=`test_init update_file_skipped_due_to_conflict`
2406 local commit_id0=`git_show_head $testroot/repo`
2407 blob_id0=`get_blob_id $testroot/repo "" beta`
2409 echo "changed beta" > $testroot/repo/beta
2410 git_commit $testroot/repo -m "changed beta"
2411 local commit_id1=`git_show_head $testroot/repo`
2412 blob_id1=`get_blob_id $testroot/repo "" beta`
2414 got checkout $testroot/repo $testroot/wt > /dev/null
2415 ret=$?
2416 if [ $ret -ne 0 ]; then
2417 test_done "$testroot" "$ret"
2418 return 1
2421 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2422 cut -d ':' -f 2 | tr -d ' ')`
2423 if [ "$blob_id" != "$blob_id1" ]; then
2424 echo "file beta has the wrong base blob ID" >&2
2425 test_done "$testroot" "1"
2426 return 1
2429 commit_id=`(cd $testroot/wt && got info beta | \
2430 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2431 if [ "$commit_id" != "$commit_id1" ]; then
2432 echo "file beta has the wrong base commit ID" >&2
2433 test_done "$testroot" "1"
2434 return 1
2437 echo "modified beta" > $testroot/wt/beta
2439 (cd $testroot/wt && got update -c $commit_id0 > $testroot/stdout)
2441 echo "C beta" > $testroot/stdout.expected
2442 echo "Updated to refs/heads/master: $commit_id0" \
2443 >> $testroot/stdout.expected
2444 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2445 cmp -s $testroot/stdout.expected $testroot/stdout
2446 ret=$?
2447 if [ $ret -ne 0 ]; then
2448 diff -u $testroot/stdout.expected $testroot/stdout
2449 test_done "$testroot" "$ret"
2450 return 1
2453 echo "<<<<<<< merged change: commit $commit_id0" \
2454 > $testroot/content.expected
2455 echo "beta" >> $testroot/content.expected
2456 echo "||||||| 3-way merge base: commit $commit_id1" \
2457 >> $testroot/content.expected
2458 echo "changed beta" >> $testroot/content.expected
2459 echo "=======" >> $testroot/content.expected
2460 echo "modified beta" >> $testroot/content.expected
2461 echo ">>>>>>>" >> $testroot/content.expected
2463 cat $testroot/wt/beta > $testroot/content
2465 cmp -s $testroot/content.expected $testroot/content
2466 ret=$?
2467 if [ $ret -ne 0 ]; then
2468 diff -u $testroot/content.expected $testroot/content
2469 test_done "$testroot" "$ret"
2470 return 1
2473 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2474 cut -d ':' -f 2 | tr -d ' ')`
2475 if [ "$blob_id" != "$blob_id0" ]; then
2476 echo "file beta has the wrong base blob ID" >&2
2477 test_done "$testroot" "1"
2478 return 1
2481 commit_id=`(cd $testroot/wt && got info beta | \
2482 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2483 if [ "$commit_id" != "$commit_id0" ]; then
2484 echo "file beta has the wrong base commit ID" >&2
2485 test_done "$testroot" "1"
2486 return 1
2489 # update to the latest commit again; this skips beta
2490 (cd $testroot/wt && got update > $testroot/stdout)
2491 echo "# beta" > $testroot/stdout.expected
2492 echo "Updated to refs/heads/master: $commit_id1" \
2493 >> $testroot/stdout.expected
2494 echo "Files not updated because of existing merge conflicts: 1" \
2495 >> $testroot/stdout.expected
2496 cmp -s $testroot/stdout.expected $testroot/stdout
2497 ret=$?
2498 if [ $ret -ne 0 ]; then
2499 diff -u $testroot/stdout.expected $testroot/stdout
2500 test_done "$testroot" "$ret"
2501 return 1
2504 # blob ID of beta should not have changed
2505 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2506 cut -d ':' -f 2 | tr -d ' ')`
2507 if [ "$blob_id" != "$blob_id0" ]; then
2508 echo "file beta has the wrong base blob ID" >&2
2509 test_done "$testroot" "1"
2510 return 1
2513 # commit ID of beta should not have changed; There was a bug
2514 # here where the commit ID had been changed even though the
2515 # file was not updated.
2516 commit_id=`(cd $testroot/wt && got info beta | \
2517 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2518 if [ "$commit_id" != "$commit_id0" ]; then
2519 echo "file beta has the wrong base commit ID: $commit_id" >&2
2520 test_done "$testroot" "1"
2521 return 1
2524 # beta is still conflicted and based on commit 0
2525 echo 'C beta' > $testroot/stdout.expected
2526 (cd $testroot/wt && got status > $testroot/stdout)
2527 cmp -s $testroot/stdout.expected $testroot/stdout
2528 ret=$?
2529 if [ $ret -ne 0 ]; then
2530 diff -u $testroot/stdout.expected $testroot/stdout
2531 test_done "$testroot" "$ret"
2532 return 1
2535 # resolve the conflict via revert
2536 (cd $testroot/wt && got revert beta >/dev/null)
2538 # beta now matches its base blob which is still from commit 0
2539 echo "beta" > $testroot/content.expected
2540 cat $testroot/wt/beta > $testroot/content
2541 cmp -s $testroot/content.expected $testroot/content
2542 ret=$?
2543 if [ $ret -ne 0 ]; then
2544 diff -u $testroot/content.expected $testroot/content
2545 test_done "$testroot" "$ret"
2546 return 1
2549 # updating to the latest commit should now update beta
2550 (cd $testroot/wt && got update > $testroot/stdout)
2551 echo "U beta" > $testroot/stdout.expected
2552 echo "Updated to refs/heads/master: $commit_id1" \
2553 >> $testroot/stdout.expected
2554 cmp -s $testroot/stdout.expected $testroot/stdout
2555 ret=$?
2556 if [ $ret -ne 0 ]; then
2557 diff -u $testroot/stdout.expected $testroot/stdout
2558 test_done "$testroot" "$ret"
2559 return 1
2562 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2563 cut -d ':' -f 2 | tr -d ' ')`
2564 if [ "$blob_id" != "$blob_id1" ]; then
2565 echo "file beta has the wrong base blob ID" >&2
2566 test_done "$testroot" "1"
2567 return 1
2570 commit_id=`(cd $testroot/wt && got info beta | \
2571 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2572 if [ "$commit_id" != "$commit_id1" ]; then
2573 echo "file beta has the wrong base commit ID: $commit_id" >&2
2574 test_done "$testroot" "1"
2575 return 1
2578 echo "changed beta" > $testroot/content.expected
2579 cat $testroot/wt/beta > $testroot/content
2580 cmp -s $testroot/content.expected $testroot/content
2581 ret=$?
2582 if [ $ret -ne 0 ]; then
2583 diff -u $testroot/content.expected $testroot/content
2585 test_done "$testroot" "$ret"
2588 test_update_file_skipped_due_to_obstruction() {
2589 local testroot=`test_init update_file_skipped_due_to_obstruction`
2590 local commit_id0=`git_show_head $testroot/repo`
2591 blob_id0=`get_blob_id $testroot/repo "" beta`
2593 echo "changed beta" > $testroot/repo/beta
2594 echo "new file" > $testroot/repo/new
2595 (cd $testroot/repo && git add new)
2596 git_commit $testroot/repo -m "changed beta"
2597 local commit_id1=`git_show_head $testroot/repo`
2598 blob_id1=`get_blob_id $testroot/repo "" beta`
2600 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
2601 ret=$?
2602 if [ $ret -ne 0 ]; then
2603 test_done "$testroot" "$ret"
2604 return 1
2607 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2608 cut -d ':' -f 2 | tr -d ' ')`
2609 if [ "$blob_id" != "$blob_id0" ]; then
2610 echo "file beta has the wrong base blob ID" >&2
2611 test_done "$testroot" "1"
2612 return 1
2615 commit_id=`(cd $testroot/wt && got info beta | \
2616 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2617 if [ "$commit_id" != "$commit_id0" ]; then
2618 echo "file beta has the wrong base commit ID" >&2
2619 test_done "$testroot" "1"
2620 return 1
2623 rm $testroot/wt/beta
2624 mkdir -p $testroot/wt/beta/psi
2625 mkdir -p $testroot/wt/new
2627 # update to the latest commit; this skips beta and the new file
2628 (cd $testroot/wt && got update > $testroot/stdout)
2629 ret=$?
2630 if [ $ret -ne 0 ]; then
2631 echo "update failed unexpectedly" >&2
2632 test_done "$testroot" "1"
2633 return 1
2636 echo "~ beta" > $testroot/stdout.expected
2637 echo "~ new" >> $testroot/stdout.expected
2638 echo "Updated to refs/heads/master: $commit_id1" \
2639 >> $testroot/stdout.expected
2640 echo "File paths obstructed by a non-regular file: 2" \
2641 >> $testroot/stdout.expected
2642 cmp -s $testroot/stdout.expected $testroot/stdout
2643 ret=$?
2644 if [ $ret -ne 0 ]; then
2645 diff -u $testroot/stdout.expected $testroot/stdout
2646 test_done "$testroot" "$ret"
2647 return 1
2650 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2651 cut -d ':' -f 2 | tr -d ' ')`
2652 if [ "$blob_id" != "$blob_id0" ]; then
2653 echo "file beta has the wrong base blob ID" >&2
2654 test_done "$testroot" "1"
2655 return 1
2658 commit_id=`(cd $testroot/wt && got info beta | \
2659 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2660 if [ "$commit_id" != "$commit_id0" ]; then
2661 echo "file beta has the wrong base commit ID" >&2
2662 test_done "$testroot" "1"
2663 return 1
2666 # remove the directory which obstructs file beta
2667 rm -r $testroot/wt/beta
2669 # updating to the latest commit should now update beta
2670 (cd $testroot/wt && got update > $testroot/stdout)
2671 echo "! beta" > $testroot/stdout.expected
2672 echo "~ new" >> $testroot/stdout.expected
2673 echo "Updated to refs/heads/master: $commit_id1" \
2674 >> $testroot/stdout.expected
2675 echo "File paths obstructed by a non-regular file: 1" \
2676 >> $testroot/stdout.expected
2677 cmp -s $testroot/stdout.expected $testroot/stdout
2678 ret=$?
2679 if [ $ret -ne 0 ]; then
2680 diff -u $testroot/stdout.expected $testroot/stdout
2681 test_done "$testroot" "$ret"
2682 return 1
2685 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2686 cut -d ':' -f 2 | tr -d ' ')`
2687 if [ "$blob_id" != "$blob_id1" ]; then
2688 echo "file beta has the wrong base blob ID" >&2
2689 test_done "$testroot" "1"
2690 return 1
2693 commit_id=`(cd $testroot/wt && got info beta | \
2694 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2695 if [ "$commit_id" != "$commit_id1" ]; then
2696 echo "file beta has the wrong base commit ID: $commit_id" >&2
2697 test_done "$testroot" "1"
2698 return 1
2701 echo "changed beta" > $testroot/content.expected
2702 cat $testroot/wt/beta > $testroot/content
2703 cmp -s $testroot/content.expected $testroot/content
2704 ret=$?
2705 if [ $ret -ne 0 ]; then
2706 diff -u $testroot/content.expected $testroot/content
2708 test_done "$testroot" "$ret"
2711 test_update_quiet() {
2712 local testroot=`test_init update_quiet`
2714 got checkout $testroot/repo $testroot/wt > /dev/null
2715 ret=$?
2716 if [ $ret -ne 0 ]; then
2717 test_done "$testroot" "$ret"
2718 return 1
2721 echo "modified alpha" > $testroot/repo/alpha
2722 git_commit $testroot/repo -m "modified alpha"
2724 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2725 git_show_head $testroot/repo >> $testroot/stdout.expected
2726 echo >> $testroot/stdout.expected
2728 (cd $testroot/wt && got update -q > $testroot/stdout)
2730 cmp -s $testroot/stdout.expected $testroot/stdout
2731 ret=$?
2732 if [ $ret -ne 0 ]; then
2733 diff -u $testroot/stdout.expected $testroot/stdout
2734 test_done "$testroot" "$ret"
2735 return 1
2738 echo "modified alpha" > $testroot/content.expected
2739 cat $testroot/wt/alpha > $testroot/content
2741 cmp -s $testroot/content.expected $testroot/content
2742 ret=$?
2743 if [ $ret -ne 0 ]; then
2744 diff -u $testroot/content.expected $testroot/content
2746 test_done "$testroot" "$ret"
2749 test_update_binary_file() {
2750 local testroot=`test_init update_binary_file`
2751 local commit_id0=`git_show_head $testroot/repo`
2753 got checkout $testroot/repo $testroot/wt > /dev/null
2754 ret=$?
2755 if [ $ret -ne 0 ]; then
2756 test_done "$testroot" "$ret"
2757 return 1
2760 cp /bin/ls $testroot/wt/foo
2761 chmod 755 $testroot/wt/foo
2762 (cd $testroot/wt && got add foo >/dev/null)
2763 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
2764 local commit_id1=`git_show_head $testroot/repo`
2766 cp /bin/cat $testroot/wt/foo
2767 chmod 755 $testroot/wt/foo
2768 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2769 local commit_id2=`git_show_head $testroot/repo`
2771 cp /bin/cp $testroot/wt/foo
2772 chmod 755 $testroot/wt/foo
2773 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2774 local commit_id3=`git_show_head $testroot/repo`
2776 (cd $testroot/wt && got rm foo >/dev/null)
2777 (cd $testroot/wt && got commit -m 'remove binary file' > /dev/null)
2778 local commit_id4=`git_show_head $testroot/repo`
2780 # backdate the work tree to make it usable for updating
2781 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2783 # update which adds a binary file
2784 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2786 echo "A foo" > $testroot/stdout.expected
2787 echo -n "Updated to refs/heads/master: $commit_id1" \
2788 >> $testroot/stdout.expected
2789 echo >> $testroot/stdout.expected
2790 cmp -s $testroot/stdout.expected $testroot/stdout
2791 ret=$?
2792 if [ $ret -ne 0 ]; then
2793 diff -u $testroot/stdout.expected $testroot/stdout
2794 test_done "$testroot" "$ret"
2795 return 1
2798 cp /bin/ls $testroot/content.expected
2799 chmod 755 $testroot/content.expected
2800 cat $testroot/wt/foo > $testroot/content
2802 cmp -s $testroot/content.expected $testroot/content
2803 ret=$?
2804 if [ $ret -ne 0 ]; then
2805 diff -u $testroot/content.expected $testroot/content
2806 test_done "$testroot" "$ret"
2807 return 1
2810 # update which adds a conflicting binary file
2811 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2812 cp /bin/cat $testroot/wt/foo
2813 chmod 755 $testroot/wt/foo
2814 (cd $testroot/wt && got add foo > /dev/null)
2815 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2817 echo "C foo" > $testroot/stdout.expected
2818 echo "Updated to refs/heads/master: $commit_id1" \
2819 >> $testroot/stdout.expected
2820 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2821 cmp -s $testroot/stdout.expected $testroot/stdout
2822 ret=$?
2823 if [ $ret -ne 0 ]; then
2824 diff -u $testroot/stdout.expected $testroot/stdout
2825 test_done "$testroot" "$ret"
2826 return 1
2829 echo "Binary files differ and cannot be merged automatically:" \
2830 > $testroot/content.expected
2831 echo "<<<<<<< merged change: commit $commit_id1" \
2832 >> $testroot/content.expected
2833 echo -n "file " >> $testroot/content.expected
2834 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2835 echo '=======' >> $testroot/content.expected
2836 echo -n "file " >> $testroot/content.expected
2837 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2838 echo ">>>>>>>" >> $testroot/content.expected
2839 cat $testroot/wt/foo > $testroot/content
2841 cmp -s $testroot/content.expected $testroot/content
2842 ret=$?
2843 if [ $ret -ne 0 ]; then
2844 diff -u $testroot/content.expected $testroot/content
2845 test_done "$testroot" "$ret"
2846 return 1
2849 cp /bin/ls $testroot/content.expected
2850 chmod 755 $testroot/content.expected
2851 cat $testroot/wt/foo-1-* > $testroot/content
2853 cmp -s $testroot/content.expected $testroot/content
2854 ret=$?
2855 if [ $ret -ne 0 ]; then
2856 diff -u $testroot/content.expected $testroot/content
2857 test_done "$testroot" "$ret"
2858 return 1
2861 cp /bin/cat $testroot/content.expected
2862 chmod 755 $testroot/content.expected
2863 cat $testroot/wt/foo-2-* > $testroot/content
2865 cmp -s $testroot/content.expected $testroot/content
2866 ret=$?
2867 if [ $ret -ne 0 ]; then
2868 diff -u $testroot/content.expected $testroot/content
2869 test_done "$testroot" "$ret"
2870 return 1
2873 # tidy up
2874 (cd $testroot/wt && got revert -R . >/dev/null)
2875 rm $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2876 (cd $testroot/wt && got up -c $commit_id1 > /dev/null)
2878 # update which changes a binary file
2879 (cd $testroot/wt && got up -c $commit_id2 > $testroot/stdout)
2881 echo "U foo" > $testroot/stdout.expected
2882 echo -n "Updated to refs/heads/master: $commit_id2" \
2883 >> $testroot/stdout.expected
2884 echo >> $testroot/stdout.expected
2885 cmp -s $testroot/stdout.expected $testroot/stdout
2886 ret=$?
2887 if [ $ret -ne 0 ]; then
2888 diff -u $testroot/stdout.expected $testroot/stdout
2889 test_done "$testroot" "$ret"
2890 return 1
2893 cp /bin/cat $testroot/content.expected
2894 chmod 755 $testroot/content.expected
2895 cat $testroot/wt/foo > $testroot/content
2897 cmp -s $testroot/content.expected $testroot/content
2898 ret=$?
2899 if [ $ret -ne 0 ]; then
2900 diff -u $testroot/content.expected $testroot/content
2901 test_done "$testroot" "$ret"
2902 return 1
2905 # update which changes a locally modified binary file
2906 cp /bin/ls $testroot/wt/foo
2907 chmod 755 $testroot/wt/foo
2908 (cd $testroot/wt && got up -c $commit_id3 > $testroot/stdout)
2910 echo "C foo" > $testroot/stdout.expected
2911 echo -n "Updated to refs/heads/master: $commit_id3" \
2912 >> $testroot/stdout.expected
2913 echo >> $testroot/stdout.expected
2914 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2915 cmp -s $testroot/stdout.expected $testroot/stdout
2916 ret=$?
2917 if [ $ret -ne 0 ]; then
2918 diff -u $testroot/stdout.expected $testroot/stdout
2919 test_done "$testroot" "$ret"
2920 return 1
2923 echo "Binary files differ and cannot be merged automatically:" \
2924 > $testroot/content.expected
2925 echo "<<<<<<< merged change: commit $commit_id3" \
2926 >> $testroot/content.expected
2927 echo -n "file " >> $testroot/content.expected
2928 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2929 echo "||||||| 3-way merge base: commit $commit_id2" \
2930 >> $testroot/content.expected
2931 echo -n "file " >> $testroot/content.expected
2932 ls $testroot/wt/foo-orig-* >> $testroot/content.expected
2933 echo '=======' >> $testroot/content.expected
2934 echo -n "file " >> $testroot/content.expected
2935 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2936 echo ">>>>>>>" >> $testroot/content.expected
2937 cat $testroot/wt/foo > $testroot/content
2939 cmp -s $testroot/content.expected $testroot/content
2940 ret=$?
2941 if [ $ret -ne 0 ]; then
2942 diff -u $testroot/content.expected $testroot/content
2943 test_done "$testroot" "$ret"
2944 return 1
2947 cp /bin/cp $testroot/content.expected
2948 chmod 755 $testroot/content.expected
2949 cp $testroot/wt/foo-1-* $testroot/content
2950 cmp -s $testroot/content.expected $testroot/content
2951 ret=$?
2952 if [ $ret -ne 0 ]; then
2953 diff -u $testroot/content.expected $testroot/content
2954 test_done "$testroot" "$ret"
2955 return 1
2958 cp /bin/ls $testroot/content.expected
2959 chmod 755 $testroot/content.expected
2960 cp $testroot/wt/foo-2-* $testroot/content
2961 cmp -s $testroot/content.expected $testroot/content
2962 ret=$?
2963 if [ $ret -ne 0 ]; then
2964 diff -u $testroot/content.expected $testroot/content
2965 test_done "$testroot" "$ret"
2966 return 1
2969 (cd $testroot/wt && got status > $testroot/stdout)
2970 echo 'C foo' > $testroot/stdout.expected
2971 echo -n '? ' >> $testroot/stdout.expected
2972 (cd $testroot/wt && ls foo-1-* >> $testroot/stdout.expected)
2973 echo -n '? ' >> $testroot/stdout.expected
2974 (cd $testroot/wt && ls foo-2-* >> $testroot/stdout.expected)
2975 echo -n '? ' >> $testroot/stdout.expected
2976 (cd $testroot/wt && ls foo-orig-* >> $testroot/stdout.expected)
2977 cmp -s $testroot/stdout.expected $testroot/stdout
2978 ret=$?
2979 if [ $ret -ne 0 ]; then
2980 diff -u $testroot/stdout.expected $testroot/stdout
2981 test_done "$testroot" "$ret"
2982 return 1
2985 # tidy up
2986 (cd $testroot/wt && got revert -R . > /dev/null)
2987 rm $testroot/wt/foo-orig-* $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2989 # update which deletes a binary file
2990 (cd $testroot/wt && got up -c $commit_id4 > $testroot/stdout)
2991 echo "D foo" > $testroot/stdout.expected
2992 echo -n "Updated to refs/heads/master: $commit_id4" \
2993 >> $testroot/stdout.expected
2994 echo >> $testroot/stdout.expected
2995 cmp -s $testroot/stdout.expected $testroot/stdout
2996 ret=$?
2997 if [ $ret -ne 0 ]; then
2998 diff -u $testroot/stdout.expected $testroot/stdout
2999 test_done "$testroot" "$ret"
3002 if [ -e $testroot/wt/foo ]; then
3003 echo "removed file foo still exists on disk" >&2
3004 test_done "$testroot" "1"
3005 return 1
3007 test_done "$testroot" "0"
3010 test_parseargs "$@"
3011 run_test test_update_basic
3012 run_test test_update_adds_file
3013 run_test test_update_deletes_file
3014 run_test test_update_deletes_dir
3015 run_test test_update_deletes_dir_with_path_prefix
3016 run_test test_update_deletes_dir_recursively
3017 run_test test_update_sibling_dirs_with_common_prefix
3018 run_test test_update_dir_with_dot_sibling
3019 run_test test_update_moves_files_upwards
3020 run_test test_update_moves_files_to_new_dir
3021 run_test test_update_creates_missing_parent
3022 run_test test_update_creates_missing_parent_with_subdir
3023 run_test test_update_file_in_subsubdir
3024 run_test test_update_merges_file_edits
3025 run_test test_update_keeps_xbit
3026 run_test test_update_clears_xbit
3027 run_test test_update_restores_missing_file
3028 run_test test_update_conflict_wt_add_vs_repo_add
3029 run_test test_update_conflict_wt_edit_vs_repo_rm
3030 run_test test_update_conflict_wt_rm_vs_repo_edit
3031 run_test test_update_conflict_wt_rm_vs_repo_rm
3032 run_test test_update_partial
3033 run_test test_update_partial_add
3034 run_test test_update_partial_rm
3035 run_test test_update_partial_dir
3036 run_test test_update_moved_branch_ref
3037 run_test test_update_to_another_branch
3038 run_test test_update_to_commit_on_wrong_branch
3039 run_test test_update_bumps_base_commit_id
3040 run_test test_update_tag
3041 run_test test_update_toggles_xbit
3042 run_test test_update_preserves_conflicted_file
3043 run_test test_update_modified_submodules
3044 run_test test_update_adds_submodule
3045 run_test test_update_conflict_wt_file_vs_repo_submodule
3046 run_test test_update_adds_symlink
3047 run_test test_update_deletes_symlink
3048 run_test test_update_symlink_conflicts
3049 run_test test_update_single_file
3050 run_test test_update_file_skipped_due_to_conflict
3051 run_test test_update_file_skipped_due_to_obstruction
3052 run_test test_update_quiet
3053 run_test test_update_binary_file