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 $head_rev $testroot/wt" > $testroot/stdout.expected
1021 echo -n 'blob - ' >> $testroot/stdout.expected
1022 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1023 >> $testroot/stdout.expected
1024 echo 'file + /dev/null' >> $testroot/stdout.expected
1025 echo '--- beta' >> $testroot/stdout.expected
1026 echo '+++ /dev/null' >> $testroot/stdout.expected
1027 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1028 echo '-modified beta' >> $testroot/stdout.expected
1030 (cd $testroot/wt && got diff > $testroot/stdout)
1031 cmp -s $testroot/stdout.expected $testroot/stdout
1032 ret=$?
1033 if [ $ret -ne 0 ]; then
1034 diff -u $testroot/stdout.expected $testroot/stdout
1036 test_done "$testroot" "$ret"
1039 test_update_conflict_wt_rm_vs_repo_rm() {
1040 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1042 got checkout $testroot/repo $testroot/wt > /dev/null
1043 ret=$?
1044 if [ $ret -ne 0 ]; then
1045 test_done "$testroot" "$ret"
1046 return 1
1049 (cd $testroot/repo && git rm -q beta)
1050 git_commit $testroot/repo -m "removing a file"
1052 (cd $testroot/wt && got rm beta > /dev/null)
1054 (cd $testroot/wt && got update > $testroot/stdout)
1056 echo "D beta" > $testroot/stdout.expected
1057 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1058 git_show_head $testroot/repo >> $testroot/stdout.expected
1059 echo >> $testroot/stdout.expected
1060 cmp -s $testroot/stdout.expected $testroot/stdout
1061 ret=$?
1062 if [ $ret -ne 0 ]; then
1063 diff -u $testroot/stdout.expected $testroot/stdout
1064 test_done "$testroot" "$ret"
1065 return 1
1068 # beta is now gone... we don't flag tree conflicts yet
1069 echo "N beta" > $testroot/stdout.expected
1070 echo -n > $testroot/stderr.expected
1071 (cd $testroot/wt && got status beta > $testroot/stdout \
1072 2> $testroot/stderr)
1073 cmp -s $testroot/stdout.expected $testroot/stdout
1074 ret=$?
1075 if [ $ret -ne 0 ]; then
1076 diff -u $testroot/stdout.expected $testroot/stdout
1077 test_done "$testroot" "$ret"
1078 return 1
1080 cmp -s $testroot/stderr.expected $testroot/stderr
1081 ret=$?
1082 if [ $ret -ne 0 ]; then
1083 diff -u $testroot/stderr.expected $testroot/stderr
1084 test_done "$testroot" "$ret"
1085 return 1
1088 if [ -e $testroot/wt/beta ]; then
1089 echo "removed file beta still exists on disk" >&2
1090 test_done "$testroot" "1"
1091 return 1
1094 test_done "$testroot" "0"
1097 test_update_partial() {
1098 local testroot=`test_init update_partial`
1100 got checkout $testroot/repo $testroot/wt > /dev/null
1101 ret=$?
1102 if [ $ret -ne 0 ]; then
1103 test_done "$testroot" "$ret"
1104 return 1
1107 echo "modified alpha" > $testroot/repo/alpha
1108 echo "modified beta" > $testroot/repo/beta
1109 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1110 git_commit $testroot/repo -m "modified two files"
1112 echo "U alpha" > $testroot/stdout.expected
1113 echo "U beta" >> $testroot/stdout.expected
1114 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1115 git_show_head $testroot/repo >> $testroot/stdout.expected
1116 echo >> $testroot/stdout.expected
1118 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1120 cmp -s $testroot/stdout.expected $testroot/stdout
1121 ret=$?
1122 if [ $ret -ne 0 ]; then
1123 diff -u $testroot/stdout.expected $testroot/stdout
1124 test_done "$testroot" "$ret"
1125 return 1
1128 echo "modified alpha" > $testroot/content.expected
1129 echo "modified beta" >> $testroot/content.expected
1131 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1132 cmp -s $testroot/content.expected $testroot/content
1133 ret=$?
1134 if [ $ret -ne 0 ]; then
1135 diff -u $testroot/content.expected $testroot/content
1136 test_done "$testroot" "$ret"
1137 return 1
1140 echo "U epsilon/zeta" > $testroot/stdout.expected
1141 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1142 git_show_head $testroot/repo >> $testroot/stdout.expected
1143 echo >> $testroot/stdout.expected
1145 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1147 cmp -s $testroot/stdout.expected $testroot/stdout
1148 ret=$?
1149 if [ $ret -ne 0 ]; then
1150 diff -u $testroot/stdout.expected $testroot/stdout
1151 test_done "$testroot" "$ret"
1152 return 1
1155 echo "modified epsilon/zeta" > $testroot/content.expected
1156 cat $testroot/wt/epsilon/zeta > $testroot/content
1158 cmp -s $testroot/content.expected $testroot/content
1159 ret=$?
1160 if [ $ret -ne 0 ]; then
1161 diff -u $testroot/content.expected $testroot/content
1162 test_done "$testroot" "$ret"
1163 return 1
1166 test_done "$testroot" "$ret"
1169 test_update_partial_add() {
1170 local testroot=`test_init update_partial_add`
1172 got checkout $testroot/repo $testroot/wt > /dev/null
1173 ret=$?
1174 if [ $ret -ne 0 ]; then
1175 test_done "$testroot" "$ret"
1176 return 1
1179 echo "new" > $testroot/repo/new
1180 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1181 (cd $testroot/repo && git add .)
1182 git_commit $testroot/repo -m "added two files"
1184 echo "A epsilon/new2" > $testroot/stdout.expected
1185 echo "A new" >> $testroot/stdout.expected
1186 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1187 git_show_head $testroot/repo >> $testroot/stdout.expected
1188 echo >> $testroot/stdout.expected
1190 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1192 cmp -s $testroot/stdout.expected $testroot/stdout
1193 ret=$?
1194 if [ $ret -ne 0 ]; then
1195 diff -u $testroot/stdout.expected $testroot/stdout
1196 test_done "$testroot" "$ret"
1197 return 1
1200 echo "new" > $testroot/content.expected
1201 echo "epsilon/new2" >> $testroot/content.expected
1203 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1205 cmp -s $testroot/content.expected $testroot/content
1206 ret=$?
1207 if [ $ret -ne 0 ]; then
1208 diff -u $testroot/content.expected $testroot/content
1210 test_done "$testroot" "$ret"
1213 test_update_partial_rm() {
1214 local testroot=`test_init update_partial_rm`
1216 got checkout $testroot/repo $testroot/wt > /dev/null
1217 ret=$?
1218 if [ $ret -ne 0 ]; then
1219 test_done "$testroot" "$ret"
1220 return 1
1223 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1224 git_commit $testroot/repo -m "removed two files"
1226 echo "got: /alpha: no such entry found in tree" \
1227 > $testroot/stderr.expected
1229 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1230 ret=$?
1231 if [ $ret -eq 0 ]; then
1232 echo "update succeeded unexpectedly" >&2
1233 test_done "$testroot" "1"
1234 return 1
1237 cmp -s $testroot/stderr.expected $testroot/stderr
1238 ret=$?
1239 if [ $ret -ne 0 ]; then
1240 diff -u $testroot/stderr.expected $testroot/stderr
1241 test_done "$testroot" "$ret"
1242 return 1
1244 test_done "$testroot" "$ret"
1247 test_update_partial_dir() {
1248 local testroot=`test_init update_partial_dir`
1250 got checkout $testroot/repo $testroot/wt > /dev/null
1251 ret=$?
1252 if [ $ret -ne 0 ]; then
1253 test_done "$testroot" "$ret"
1254 return 1
1257 echo "modified alpha" > $testroot/repo/alpha
1258 echo "modified beta" > $testroot/repo/beta
1259 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1260 git_commit $testroot/repo -m "modified two files"
1262 echo "U epsilon/zeta" > $testroot/stdout.expected
1263 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1264 git_show_head $testroot/repo >> $testroot/stdout.expected
1265 echo >> $testroot/stdout.expected
1267 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1269 cmp -s $testroot/stdout.expected $testroot/stdout
1270 ret=$?
1271 if [ $ret -ne 0 ]; then
1272 diff -u $testroot/stdout.expected $testroot/stdout
1273 test_done "$testroot" "$ret"
1274 return 1
1277 echo "modified epsilon/zeta" > $testroot/content.expected
1278 cat $testroot/wt/epsilon/zeta > $testroot/content
1280 cmp -s $testroot/content.expected $testroot/content
1281 ret=$?
1282 if [ $ret -ne 0 ]; then
1283 diff -u $testroot/content.expected $testroot/content
1284 test_done "$testroot" "$ret"
1285 return 1
1287 test_done "$testroot" "$ret"
1291 test_update_moved_branch_ref() {
1292 local testroot=`test_init update_moved_branch_ref`
1294 git clone -q --mirror $testroot/repo $testroot/repo2
1296 echo "modified alpha with git" > $testroot/repo/alpha
1297 git_commit $testroot/repo -m "modified alpha with git"
1299 got checkout $testroot/repo2 $testroot/wt > /dev/null
1300 ret=$?
1301 if [ $ret -ne 0 ]; then
1302 test_done "$testroot" "$ret"
1303 return 1
1306 echo "modified alpha with got" > $testroot/wt/alpha
1307 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1309 # + xxxxxxx...yyyyyyy master -> master (forced update)
1310 (cd $testroot/repo2 && git fetch -q --all)
1312 echo -n > $testroot/stdout.expected
1313 echo -n "got: work tree's head reference now points to a different " \
1314 > $testroot/stderr.expected
1315 echo "branch; new head reference and/or update -b required" \
1316 >> $testroot/stderr.expected
1318 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1320 cmp -s $testroot/stdout.expected $testroot/stdout
1321 ret=$?
1322 if [ $ret -ne 0 ]; then
1323 diff -u $testroot/stdout.expected $testroot/stdout
1324 test_done "$testroot" "$ret"
1325 return 1
1328 cmp -s $testroot/stderr.expected $testroot/stderr
1329 ret=$?
1330 if [ $ret -ne 0 ]; then
1331 diff -u $testroot/stderr.expected $testroot/stderr
1333 test_done "$testroot" "$ret"
1336 test_update_to_another_branch() {
1337 local testroot=`test_init update_to_another_branch`
1338 local base_commit=`git_show_head $testroot/repo`
1340 got checkout $testroot/repo $testroot/wt > /dev/null
1341 ret=$?
1342 if [ $ret -ne 0 ]; then
1343 test_done "$testroot" "$ret"
1344 return 1
1347 echo 'refs/heads/master'> $testroot/head-ref.expected
1348 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1349 ret=$?
1350 if [ $ret -ne 0 ]; then
1351 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1352 test_done "$testroot" "$ret"
1353 return 1
1356 (cd $testroot/repo && git checkout -q -b newbranch)
1357 echo "modified alpha on new branch" > $testroot/repo/alpha
1358 git_commit $testroot/repo -m "modified alpha on new branch"
1360 echo "modified alpha in work tree" > $testroot/wt/alpha
1362 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1363 echo "C alpha" >> $testroot/stdout.expected
1364 echo -n "Updated to refs/heads/newbranch: " >> $testroot/stdout.expected
1365 git_show_head $testroot/repo >> $testroot/stdout.expected
1366 echo >> $testroot/stdout.expected
1367 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1369 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1371 cmp -s $testroot/stdout.expected $testroot/stdout
1372 ret=$?
1373 if [ $ret -ne 0 ]; then
1374 diff -u $testroot/stdout.expected $testroot/stdout
1375 test_done "$testroot" "$ret"
1376 return 1
1379 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
1380 git_show_head $testroot/repo >> $testroot/content.expected
1381 echo >> $testroot/content.expected
1382 echo "modified alpha on new branch" >> $testroot/content.expected
1383 echo "||||||| 3-way merge base: commit $base_commit" \
1384 >> $testroot/content.expected
1385 echo "alpha" >> $testroot/content.expected
1386 echo "=======" >> $testroot/content.expected
1387 echo "modified alpha in work tree" >> $testroot/content.expected
1388 echo '>>>>>>>' >> $testroot/content.expected
1390 cat $testroot/wt/alpha > $testroot/content
1392 cmp -s $testroot/content.expected $testroot/content
1393 ret=$?
1394 if [ $ret -ne 0 ]; then
1395 diff -u $testroot/content.expected $testroot/content
1396 test_done "$testroot" "$ret"
1397 return 1
1400 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1401 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1402 ret=$?
1403 if [ $ret -ne 0 ]; then
1404 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1405 test_done "$testroot" "$ret"
1406 return 1
1409 test_done "$testroot" "$ret"
1412 test_update_to_commit_on_wrong_branch() {
1413 local testroot=`test_init update_to_commit_on_wrong_branch`
1415 got checkout $testroot/repo $testroot/wt > /dev/null
1416 ret=$?
1417 if [ $ret -ne 0 ]; then
1418 test_done "$testroot" "$ret"
1419 return 1
1422 (cd $testroot/repo && git checkout -q -b newbranch)
1423 echo "modified alpha on new branch" > $testroot/repo/alpha
1424 git_commit $testroot/repo -m "modified alpha on new branch"
1426 echo -n "" > $testroot/stdout.expected
1427 echo "got: target commit is on a different branch" \
1428 > $testroot/stderr.expected
1430 local head_rev=`git_show_head $testroot/repo`
1431 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1432 2> $testroot/stderr)
1434 cmp -s $testroot/stdout.expected $testroot/stdout
1435 ret=$?
1436 if [ $ret -ne 0 ]; then
1437 diff -u $testroot/stdout.expected $testroot/stdout
1438 test_done "$testroot" "$ret"
1439 return 1
1442 cmp -s $testroot/stderr.expected $testroot/stderr
1443 ret=$?
1444 if [ $ret -ne 0 ]; then
1445 diff -u $testroot/stderr.expected $testroot/stderr
1446 test_done "$testroot" "$ret"
1447 return 1
1450 test_done "$testroot" "$ret"
1453 test_update_bumps_base_commit_id() {
1454 local testroot=`test_init update_bumps_base_commit_id`
1456 echo "psi" > $testroot/repo/epsilon/psi
1457 (cd $testroot/repo && git add .)
1458 git_commit $testroot/repo -m "adding another file"
1460 got checkout $testroot/repo $testroot/wt > /dev/null
1461 ret=$?
1462 if [ $ret -ne 0 ]; then
1463 test_done "$testroot" "$ret"
1464 return 1
1467 echo "modified psi" > $testroot/wt/epsilon/psi
1468 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1470 local head_rev=`git_show_head $testroot/repo`
1471 echo "M epsilon/psi" > $testroot/stdout.expected
1472 echo "Created commit $head_rev" >> $testroot/stdout.expected
1473 cmp -s $testroot/stdout.expected $testroot/stdout
1474 ret=$?
1475 if [ $ret -ne 0 ]; then
1476 diff -u $testroot/stdout.expected $testroot/stdout
1477 test_done "$testroot" "$ret"
1478 return 1
1481 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1482 (cd $testroot/repo && git add .)
1483 git_commit $testroot/repo -m "changing zeta with git"
1485 echo "modified zeta" > $testroot/wt/epsilon/zeta
1486 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1487 2> $testroot/stderr)
1489 echo -n "" > $testroot/stdout.expected
1490 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1491 cmp -s $testroot/stderr.expected $testroot/stderr
1492 ret=$?
1493 if [ $ret -ne 0 ]; then
1494 diff -u $testroot/stderr.expected $testroot/stderr
1495 test_done "$testroot" "$ret"
1496 return 1
1499 (cd $testroot/wt && got update > $testroot/stdout)
1501 echo "U epsilon/psi" > $testroot/stdout.expected
1502 echo "C epsilon/zeta" >> $testroot/stdout.expected
1503 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1504 git_show_head $testroot/repo >> $testroot/stdout.expected
1505 echo >> $testroot/stdout.expected
1506 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1508 cmp -s $testroot/stdout.expected $testroot/stdout
1509 ret=$?
1510 if [ $ret -ne 0 ]; then
1511 diff -u $testroot/stdout.expected $testroot/stdout
1512 test_done "$testroot" "$ret"
1513 return 1
1516 # resolve conflict
1517 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1519 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1521 local head_rev=`git_show_head $testroot/repo`
1522 echo "M epsilon/zeta" > $testroot/stdout.expected
1523 echo "Created commit $head_rev" >> $testroot/stdout.expected
1524 cmp -s $testroot/stdout.expected $testroot/stdout
1525 ret=$?
1526 if [ $ret -ne 0 ]; then
1527 diff -u $testroot/stdout.expected $testroot/stdout
1528 test_done "$testroot" "$ret"
1529 return 1
1532 test_done "$testroot" "$ret"
1535 test_update_tag() {
1536 local testroot=`test_init update_tag`
1537 local tag="1.0.0"
1539 got checkout $testroot/repo $testroot/wt > /dev/null
1540 ret=$?
1541 if [ $ret -ne 0 ]; then
1542 test_done "$testroot" "$ret"
1543 return 1
1546 echo "modified alpha" > $testroot/repo/alpha
1547 git_commit $testroot/repo -m "modified alpha"
1548 (cd $testroot/repo && git tag -m "test" -a $tag)
1550 echo "U alpha" > $testroot/stdout.expected
1551 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1552 git_show_head $testroot/repo >> $testroot/stdout.expected
1553 echo >> $testroot/stdout.expected
1555 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1557 cmp -s $testroot/stdout.expected $testroot/stdout
1558 ret=$?
1559 if [ $ret -ne 0 ]; then
1560 diff -u $testroot/stdout.expected $testroot/stdout
1561 test_done "$testroot" "$ret"
1562 return 1
1565 echo "modified alpha" > $testroot/content.expected
1566 cat $testroot/wt/alpha > $testroot/content
1568 cmp -s $testroot/content.expected $testroot/content
1569 ret=$?
1570 if [ $ret -ne 0 ]; then
1571 diff -u $testroot/content.expected $testroot/content
1573 test_done "$testroot" "$ret"
1576 test_update_toggles_xbit() {
1577 local testroot=`test_init update_toggles_xbit 1`
1579 touch $testroot/repo/xfile
1580 chmod +x $testroot/repo/xfile
1581 (cd $testroot/repo && git add .)
1582 git_commit $testroot/repo -m "adding executable file"
1583 local commit_id1=`git_show_head $testroot/repo`
1585 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1586 ret=$?
1587 if [ $ret -ne 0 ]; then
1588 test_done "$testroot" "$ret"
1589 return 1
1592 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1593 ret=$?
1594 if [ $ret -ne 0 ]; then
1595 echo "file is not executable" >&2
1596 ls -l $testroot/wt/xfile >&2
1597 test_done "$testroot" "$ret"
1598 return 1
1601 chmod -x $testroot/wt/xfile
1602 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1603 local commit_id2=`git_show_head $testroot/repo`
1605 echo "U xfile" > $testroot/stdout.expected
1606 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1607 git_show_head $testroot/repo >> $testroot/stdout.expected
1608 echo >> $testroot/stdout.expected
1610 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1611 ret=$?
1612 if [ $ret -ne 0 ]; then
1613 test_done "$testroot" "$ret"
1614 return 1
1617 echo "U xfile" > $testroot/stdout.expected
1618 echo "Updated to refs/heads/master: $commit_id1" >> $testroot/stdout.expected
1619 cmp -s $testroot/stdout.expected $testroot/stdout
1620 ret=$?
1621 if [ $ret -ne 0 ]; then
1622 diff -u $testroot/stdout.expected $testroot/stdout
1623 test_done "$testroot" "$ret"
1624 return 1
1628 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1629 ret=$?
1630 if [ $ret -ne 0 ]; then
1631 echo "file is not executable" >&2
1632 ls -l $testroot/wt/xfile >&2
1633 test_done "$testroot" "$ret"
1634 return 1
1637 (cd $testroot/wt && got update > $testroot/stdout)
1638 ret=$?
1639 if [ $ret -ne 0 ]; then
1640 test_done "$testroot" "$ret"
1641 return 1
1644 echo "U xfile" > $testroot/stdout.expected
1645 echo "Updated to refs/heads/master: $commit_id2" \
1646 >> $testroot/stdout.expected
1647 cmp -s $testroot/stdout.expected $testroot/stdout
1648 ret=$?
1649 if [ $ret -ne 0 ]; then
1650 diff -u $testroot/stdout.expected $testroot/stdout
1651 test_done "$testroot" "$ret"
1652 return 1
1655 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1656 ret=$?
1657 if [ $ret -ne 0 ]; then
1658 echo "file is unexpectedly executable" >&2
1659 ls -l $testroot/wt/xfile >&2
1661 test_done "$testroot" "$ret"
1664 test_update_preserves_conflicted_file() {
1665 local testroot=`test_init update_preserves_conflicted_file`
1666 local commit_id0=`git_show_head $testroot/repo`
1668 echo "modified alpha" > $testroot/repo/alpha
1669 git_commit $testroot/repo -m "modified alpha"
1670 local commit_id1=`git_show_head $testroot/repo`
1672 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
1673 ret=$?
1674 if [ $ret -ne 0 ]; then
1675 test_done "$testroot" "$ret"
1676 return 1
1679 # fake a merge conflict
1680 echo '<<<<<<<' > $testroot/wt/alpha
1681 echo 'alpha' >> $testroot/wt/alpha
1682 echo '=======' >> $testroot/wt/alpha
1683 echo 'alpha, too' >> $testroot/wt/alpha
1684 echo '>>>>>>>' >> $testroot/wt/alpha
1685 cp $testroot/wt/alpha $testroot/content.expected
1687 echo "C alpha" > $testroot/stdout.expected
1688 (cd $testroot/wt && got status > $testroot/stdout)
1689 cmp -s $testroot/stdout.expected $testroot/stdout
1690 ret=$?
1691 if [ $ret -ne 0 ]; then
1692 diff -u $testroot/stdout.expected $testroot/stdout
1693 test_done "$testroot" "$ret"
1694 return 1
1697 echo "# alpha" > $testroot/stdout.expected
1698 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1699 git_show_head $testroot/repo >> $testroot/stdout.expected
1700 echo >> $testroot/stdout.expected
1701 echo "Files not updated because of existing merge conflicts: 1" \
1702 >> $testroot/stdout.expected
1703 (cd $testroot/wt && got update > $testroot/stdout)
1705 cmp -s $testroot/stdout.expected $testroot/stdout
1706 ret=$?
1707 if [ $ret -ne 0 ]; then
1708 diff -u $testroot/stdout.expected $testroot/stdout
1709 test_done "$testroot" "$ret"
1710 return 1
1713 cmp -s $testroot/content.expected $testroot/wt/alpha
1714 ret=$?
1715 if [ $ret -ne 0 ]; then
1716 diff -u $testroot/content.expected $testroot/wt/alpha
1718 test_done "$testroot" "$ret"
1721 test_update_modified_submodules() {
1722 local testroot=`test_init update_modified_submodules`
1724 make_single_file_repo $testroot/repo2 foo
1726 (cd $testroot/repo && git submodule -q add ../repo2)
1727 (cd $testroot/repo && git commit -q -m 'adding submodule')
1729 got checkout $testroot/repo $testroot/wt > /dev/null
1731 echo "modified foo" > $testroot/repo2/foo
1732 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1734 # Update the repo/repo2 submodule link
1735 (cd $testroot/repo && git -C repo2 pull -q)
1736 (cd $testroot/repo && git add repo2)
1737 git_commit $testroot/repo -m "modified submodule link"
1739 # This update only records the new base commit. Otherwise it is a
1740 # no-op change because Got's file index does not track submodules.
1741 echo -n "Updated to refs/heads/master: " > $testroot/stdout.expected
1742 git_show_head $testroot/repo >> $testroot/stdout.expected
1743 echo >> $testroot/stdout.expected
1745 (cd $testroot/wt && got update > $testroot/stdout)
1747 cmp -s $testroot/stdout.expected $testroot/stdout
1748 ret=$?
1749 if [ $ret -ne 0 ]; then
1750 diff -u $testroot/stdout.expected $testroot/stdout
1752 test_done "$testroot" "$ret"
1755 test_update_adds_submodule() {
1756 local testroot=`test_init update_adds_submodule`
1758 got checkout $testroot/repo $testroot/wt > /dev/null
1760 make_single_file_repo $testroot/repo2 foo
1762 echo "modified foo" > $testroot/repo2/foo
1763 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1765 (cd $testroot/repo && git submodule -q add ../repo2)
1766 (cd $testroot/repo && git commit -q -m 'adding submodule')
1768 echo "A .gitmodules" > $testroot/stdout.expected
1769 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1770 git_show_head $testroot/repo >> $testroot/stdout.expected
1771 echo >> $testroot/stdout.expected
1773 (cd $testroot/wt && got update > $testroot/stdout)
1775 cmp -s $testroot/stdout.expected $testroot/stdout
1776 ret=$?
1777 if [ $ret -ne 0 ]; then
1778 diff -u $testroot/stdout.expected $testroot/stdout
1780 test_done "$testroot" "$ret"
1783 test_update_conflict_wt_file_vs_repo_submodule() {
1784 local testroot=`test_init update_conflict_wt_file_vs_repo_submodule`
1786 got checkout $testroot/repo $testroot/wt > /dev/null
1788 make_single_file_repo $testroot/repo2 foo
1790 # Add a file which will clash with the submodule
1791 echo "This is a file called repo2" > $testroot/wt/repo2
1792 (cd $testroot/wt && got add repo2 > /dev/null)
1793 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
1794 ret=$?
1795 if [ $ret -ne 0 ]; then
1796 echo "commit failed unexpectedly" >&2
1797 test_done "$testroot" "1"
1798 return 1
1801 (cd $testroot/repo && git submodule -q add ../repo2)
1802 (cd $testroot/repo && git commit -q -m 'adding submodule')
1804 # Modify the clashing file such that any modifications brought
1805 # in by 'got update' would require a merge.
1806 echo "This file was changed" > $testroot/wt/repo2
1808 # No conflict occurs because 'got update' ignores the submodule
1809 # and leaves the clashing file as it was.
1810 echo "A .gitmodules" > $testroot/stdout.expected
1811 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1812 git_show_head $testroot/repo >> $testroot/stdout.expected
1813 echo >> $testroot/stdout.expected
1815 (cd $testroot/wt && got update > $testroot/stdout)
1817 cmp -s $testroot/stdout.expected $testroot/stdout
1818 ret=$?
1819 if [ $ret -ne 0 ]; then
1820 diff -u $testroot/stdout.expected $testroot/stdout
1821 test_done "$testroot" "$ret"
1822 return 1
1825 (cd $testroot/wt && got status > $testroot/stdout)
1827 echo "M repo2" > $testroot/stdout.expected
1828 cmp -s $testroot/stdout.expected $testroot/stdout
1829 ret=$?
1830 if [ $ret -ne 0 ]; then
1831 diff -u $testroot/stdout.expected $testroot/stdout
1833 test_done "$testroot" "$ret"
1836 test_update_adds_symlink() {
1837 local testroot=`test_init update_adds_symlink`
1839 got checkout $testroot/repo $testroot/wt > /dev/null
1840 ret=$?
1841 if [ $ret -ne 0 ]; then
1842 echo "checkout failed unexpectedly" >&2
1843 test_done "$testroot" "$ret"
1844 return 1
1847 (cd $testroot/repo && ln -s alpha alpha.link)
1848 (cd $testroot/repo && ln -s epsilon epsilon.link)
1849 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1850 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1851 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1852 (cd $testroot/repo && git add .)
1853 git_commit $testroot/repo -m "add symlinks"
1855 echo "A alpha.link" > $testroot/stdout.expected
1856 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1857 echo "A epsilon.link" >> $testroot/stdout.expected
1858 echo "A nonexistent.link" >> $testroot/stdout.expected
1859 echo "A passwd.link" >> $testroot/stdout.expected
1860 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1861 git_show_head $testroot/repo >> $testroot/stdout.expected
1862 echo >> $testroot/stdout.expected
1864 (cd $testroot/wt && got update > $testroot/stdout)
1866 cmp -s $testroot/stdout.expected $testroot/stdout
1867 ret=$?
1868 if [ $ret -ne 0 ]; then
1869 diff -u $testroot/stdout.expected $testroot/stdout
1870 test_done "$testroot" "$ret"
1871 return 1
1874 if ! [ -h $testroot/wt/alpha.link ]; then
1875 echo "alpha.link is not a symlink"
1876 test_done "$testroot" "1"
1877 return 1
1880 readlink $testroot/wt/alpha.link > $testroot/stdout
1881 echo "alpha" > $testroot/stdout.expected
1882 cmp -s $testroot/stdout.expected $testroot/stdout
1883 ret=$?
1884 if [ $ret -ne 0 ]; then
1885 diff -u $testroot/stdout.expected $testroot/stdout
1886 test_done "$testroot" "$ret"
1887 return 1
1890 if ! [ -h $testroot/wt/epsilon.link ]; then
1891 echo "epsilon.link is not a symlink"
1892 test_done "$testroot" "1"
1893 return 1
1896 readlink $testroot/wt/epsilon.link > $testroot/stdout
1897 echo "epsilon" > $testroot/stdout.expected
1898 cmp -s $testroot/stdout.expected $testroot/stdout
1899 ret=$?
1900 if [ $ret -ne 0 ]; then
1901 diff -u $testroot/stdout.expected $testroot/stdout
1902 test_done "$testroot" "$ret"
1903 return 1
1906 if [ -h $testroot/wt/passwd.link ]; then
1907 echo -n "passwd.link symlink points outside of work tree: " >&2
1908 readlink $testroot/wt/passwd.link >&2
1909 test_done "$testroot" "1"
1910 return 1
1913 echo -n "/etc/passwd" > $testroot/content.expected
1914 cp $testroot/wt/passwd.link $testroot/content
1916 cmp -s $testroot/content.expected $testroot/content
1917 ret=$?
1918 if [ $ret -ne 0 ]; then
1919 diff -u $testroot/content.expected $testroot/content
1920 test_done "$testroot" "$ret"
1921 return 1
1924 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1925 echo "../beta" > $testroot/stdout.expected
1926 cmp -s $testroot/stdout.expected $testroot/stdout
1927 ret=$?
1928 if [ $ret -ne 0 ]; then
1929 diff -u $testroot/stdout.expected $testroot/stdout
1930 test_done "$testroot" "$ret"
1931 return 1
1934 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1935 echo "nonexistent" > $testroot/stdout.expected
1936 cmp -s $testroot/stdout.expected $testroot/stdout
1937 ret=$?
1938 if [ $ret -ne 0 ]; then
1939 diff -u $testroot/stdout.expected $testroot/stdout
1940 test_done "$testroot" "$ret"
1941 return 1
1944 # Updating an up-to-date symlink should be a no-op.
1945 echo 'Already up-to-date' > $testroot/stdout.expected
1946 (cd $testroot/wt && got update > $testroot/stdout)
1947 cmp -s $testroot/stdout.expected $testroot/stdout
1948 ret=$?
1949 if [ $ret -ne 0 ]; then
1950 diff -u $testroot/stdout.expected $testroot/stdout
1952 test_done "$testroot" "$ret"
1955 test_update_deletes_symlink() {
1956 local testroot=`test_init update_deletes_symlink`
1958 (cd $testroot/repo && ln -s alpha alpha.link)
1959 (cd $testroot/repo && git add .)
1960 git_commit $testroot/repo -m "add symlink"
1962 got checkout $testroot/repo $testroot/wt > /dev/null
1963 ret=$?
1964 if [ $ret -ne 0 ]; then
1965 echo "checkout failed unexpectedly" >&2
1966 test_done "$testroot" "$ret"
1967 return 1
1970 (cd $testroot/repo && git rm -q alpha.link)
1971 git_commit $testroot/repo -m "delete symlink"
1973 echo "D alpha.link" > $testroot/stdout.expected
1974 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1975 git_show_head $testroot/repo >> $testroot/stdout.expected
1976 echo >> $testroot/stdout.expected
1978 (cd $testroot/wt && got update > $testroot/stdout)
1980 cmp -s $testroot/stdout.expected $testroot/stdout
1981 ret=$?
1982 if [ $ret -ne 0 ]; then
1983 diff -u $testroot/stdout.expected $testroot/stdout
1984 test_done "$testroot" "$ret"
1985 return 1
1988 if [ -e $testroot/wt/alpha.link ]; then
1989 echo "alpha.link still exists on disk"
1990 test_done "$testroot" "1"
1991 return 1
1994 test_done "$testroot" "0"
1997 test_update_symlink_conflicts() {
1998 local testroot=`test_init update_symlink_conflicts`
2000 (cd $testroot/repo && ln -s alpha alpha.link)
2001 (cd $testroot/repo && ln -s epsilon epsilon.link)
2002 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2003 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2004 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2005 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
2006 (cd $testroot/repo && git add .)
2007 git_commit $testroot/repo -m "add symlinks"
2008 local commit_id1=`git_show_head $testroot/repo`
2010 got checkout $testroot/repo $testroot/wt > /dev/null
2011 ret=$?
2012 if [ $ret -ne 0 ]; then
2013 echo "checkout failed unexpectedly" >&2
2014 test_done "$testroot" "$ret"
2015 return 1
2018 (cd $testroot/repo && ln -sf beta alpha.link)
2019 (cd $testroot/repo && ln -sfh gamma epsilon.link)
2020 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
2021 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
2022 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
2023 (cd $testroot/repo && git rm -q nonexistent.link)
2024 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
2025 (cd $testroot/repo && ln -sf alpha new.link)
2026 (cd $testroot/repo && git add .)
2027 git_commit $testroot/repo -m "change symlinks"
2028 local commit_id2=`git_show_head $testroot/repo`
2030 # modified symlink to file A vs modified symlink to file B
2031 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
2032 # modified symlink to dir A vs modified symlink to file B
2033 (cd $testroot/wt && ln -sfh beta epsilon.link)
2034 # modeified symlink to file A vs modified symlink to dir B
2035 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
2036 # added regular file A vs added bad symlink to file A
2037 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
2038 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2039 # added bad symlink to file A vs added regular file A
2040 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
2041 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2042 # removed symlink to non-existent file A vs modified symlink
2043 # to nonexistent file B
2044 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
2045 # modified symlink to file A vs removed symlink to file A
2046 (cd $testroot/wt && got rm zeta.link > /dev/null)
2047 # added symlink to file A vs added symlink to file B
2048 (cd $testroot/wt && ln -sf beta new.link)
2049 (cd $testroot/wt && got add new.link > /dev/null)
2051 (cd $testroot/wt && got update > $testroot/stdout)
2053 echo "C alpha.link" >> $testroot/stdout.expected
2054 echo "C dotgotbar.link" >> $testroot/stdout.expected
2055 echo "C dotgotfoo.link" >> $testroot/stdout.expected
2056 echo "C epsilon/beta.link" >> $testroot/stdout.expected
2057 echo "C epsilon.link" >> $testroot/stdout.expected
2058 echo "C new.link" >> $testroot/stdout.expected
2059 echo "C nonexistent.link" >> $testroot/stdout.expected
2060 echo "G zeta.link" >> $testroot/stdout.expected
2061 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2062 git_show_head $testroot/repo >> $testroot/stdout.expected
2063 echo >> $testroot/stdout.expected
2064 echo "Files with new merge conflicts: 7" >> $testroot/stdout.expected
2066 cmp -s $testroot/stdout.expected $testroot/stdout
2067 ret=$?
2068 if [ $ret -ne 0 ]; then
2069 diff -u $testroot/stdout.expected $testroot/stdout
2070 test_done "$testroot" "$ret"
2071 return 1
2074 if [ -h $testroot/wt/alpha.link ]; then
2075 echo "alpha.link is a symlink"
2076 test_done "$testroot" "1"
2077 return 1
2080 echo "<<<<<<< merged change: commit $commit_id2" \
2081 > $testroot/content.expected
2082 echo "beta" >> $testroot/content.expected
2083 echo "3-way merge base: commit $commit_id1" \
2084 >> $testroot/content.expected
2085 echo "alpha" >> $testroot/content.expected
2086 echo "=======" >> $testroot/content.expected
2087 echo "gamma/delta" >> $testroot/content.expected
2088 echo '>>>>>>>' >> $testroot/content.expected
2089 echo -n "" >> $testroot/content.expected
2091 cp $testroot/wt/alpha.link $testroot/content
2092 cmp -s $testroot/content.expected $testroot/content
2093 ret=$?
2094 if [ $ret -ne 0 ]; then
2095 diff -u $testroot/content.expected $testroot/content
2096 test_done "$testroot" "$ret"
2097 return 1
2100 if [ -h $testroot/wt/epsilon.link ]; then
2101 echo "epsilon.link is a symlink"
2102 test_done "$testroot" "1"
2103 return 1
2106 echo "<<<<<<< merged change: commit $commit_id2" \
2107 > $testroot/content.expected
2108 echo "gamma" >> $testroot/content.expected
2109 echo "3-way merge base: commit $commit_id1" \
2110 >> $testroot/content.expected
2111 echo "epsilon" >> $testroot/content.expected
2112 echo "=======" >> $testroot/content.expected
2113 echo "beta" >> $testroot/content.expected
2114 echo '>>>>>>>' >> $testroot/content.expected
2115 echo -n "" >> $testroot/content.expected
2117 cp $testroot/wt/epsilon.link $testroot/content
2118 cmp -s $testroot/content.expected $testroot/content
2119 ret=$?
2120 if [ $ret -ne 0 ]; then
2121 diff -u $testroot/content.expected $testroot/content
2122 test_done "$testroot" "$ret"
2123 return 1
2126 if [ -h $testroot/wt/passwd.link ]; then
2127 echo -n "passwd.link symlink points outside of work tree: " >&2
2128 readlink $testroot/wt/passwd.link >&2
2129 test_done "$testroot" "1"
2130 return 1
2133 echo -n "/etc/passwd" > $testroot/content.expected
2134 cp $testroot/wt/passwd.link $testroot/content
2136 cmp -s $testroot/content.expected $testroot/content
2137 ret=$?
2138 if [ $ret -ne 0 ]; then
2139 diff -u $testroot/content.expected $testroot/content
2140 test_done "$testroot" "$ret"
2141 return 1
2144 if [ -h $testroot/wt/epsilon/beta.link ]; then
2145 echo "epsilon/beta.link is a symlink"
2146 test_done "$testroot" "1"
2147 return 1
2150 echo "<<<<<<< merged change: commit $commit_id2" \
2151 > $testroot/content.expected
2152 echo "../gamma/delta" >> $testroot/content.expected
2153 echo "3-way merge base: commit $commit_id1" \
2154 >> $testroot/content.expected
2155 echo "../beta" >> $testroot/content.expected
2156 echo "=======" >> $testroot/content.expected
2157 echo "../gamma" >> $testroot/content.expected
2158 echo '>>>>>>>' >> $testroot/content.expected
2159 echo -n "" >> $testroot/content.expected
2161 cp $testroot/wt/epsilon/beta.link $testroot/content
2162 cmp -s $testroot/content.expected $testroot/content
2163 ret=$?
2164 if [ $ret -ne 0 ]; then
2165 diff -u $testroot/content.expected $testroot/content
2166 test_done "$testroot" "$ret"
2167 return 1
2170 if [ -h $testroot/wt/nonexistent.link ]; then
2171 echo -n "nonexistent.link still exists on disk: " >&2
2172 readlink $testroot/wt/nonexistent.link >&2
2173 test_done "$testroot" "1"
2174 return 1
2177 echo "<<<<<<< merged change: commit $commit_id2" \
2178 > $testroot/content.expected
2179 echo "(symlink was deleted)" >> $testroot/content.expected
2180 echo "=======" >> $testroot/content.expected
2181 echo "nonexistent2" >> $testroot/content.expected
2182 echo '>>>>>>>' >> $testroot/content.expected
2183 echo -n "" >> $testroot/content.expected
2185 cp $testroot/wt/nonexistent.link $testroot/content
2186 cmp -s $testroot/content.expected $testroot/content
2187 ret=$?
2188 if [ $ret -ne 0 ]; then
2189 diff -u $testroot/content.expected $testroot/content
2190 test_done "$testroot" "$ret"
2191 return 1
2194 if [ -h $testroot/wt/dotgotfoo.link ]; then
2195 echo "dotgotfoo.link is a symlink"
2196 test_done "$testroot" "1"
2197 return 1
2200 echo "<<<<<<< merged change: commit $commit_id2" \
2201 > $testroot/content.expected
2202 echo "this is regular file foo" >> $testroot/content.expected
2203 echo "=======" >> $testroot/content.expected
2204 echo -n ".got/bar" >> $testroot/content.expected
2205 echo '>>>>>>>' >> $testroot/content.expected
2206 echo -n "" >> $testroot/content.expected
2208 cp $testroot/wt/dotgotfoo.link $testroot/content
2209 cmp -s $testroot/content.expected $testroot/content
2210 ret=$?
2211 if [ $ret -ne 0 ]; then
2212 diff -u $testroot/content.expected $testroot/content
2213 test_done "$testroot" "$ret"
2214 return 1
2217 if [ -h $testroot/wt/dotgotbar.link ]; then
2218 echo "dotgotbar.link is a symlink"
2219 test_done "$testroot" "1"
2220 return 1
2222 echo "<<<<<<< merged change: commit $commit_id2" \
2223 > $testroot/content.expected
2224 echo -n ".got/bar" >> $testroot/content.expected
2225 echo "=======" >> $testroot/content.expected
2226 echo "this is regular file bar" >> $testroot/content.expected
2227 echo '>>>>>>>' >> $testroot/content.expected
2228 echo -n "" >> $testroot/content.expected
2230 cp $testroot/wt/dotgotbar.link $testroot/content
2231 cmp -s $testroot/content.expected $testroot/content
2232 ret=$?
2233 if [ $ret -ne 0 ]; then
2234 diff -u $testroot/content.expected $testroot/content
2235 test_done "$testroot" "$ret"
2236 return 1
2239 if [ -h $testroot/wt/new.link ]; then
2240 echo "new.link is a symlink"
2241 test_done "$testroot" "1"
2242 return 1
2245 echo "<<<<<<< merged change: commit $commit_id2" \
2246 > $testroot/content.expected
2247 echo "alpha" >> $testroot/content.expected
2248 echo "=======" >> $testroot/content.expected
2249 echo "beta" >> $testroot/content.expected
2250 echo '>>>>>>>' >> $testroot/content.expected
2251 echo -n "" >> $testroot/content.expected
2253 cp $testroot/wt/new.link $testroot/content
2254 cmp -s $testroot/content.expected $testroot/content
2255 ret=$?
2256 if [ $ret -ne 0 ]; then
2257 diff -u $testroot/content.expected $testroot/content
2258 test_done "$testroot" "$ret"
2259 return 1
2262 echo "A dotgotfoo.link" > $testroot/stdout.expected
2263 echo "M new.link" >> $testroot/stdout.expected
2264 echo "D nonexistent.link" >> $testroot/stdout.expected
2265 (cd $testroot/wt && got status > $testroot/stdout)
2266 ret=$?
2267 if [ $ret -ne 0 ]; then
2268 diff -u $testroot/stdout.expected $testroot/stdout
2269 test_done "$testroot" "$ret"
2270 return 1
2273 test_done "$testroot" "0"
2277 test_update_single_file() {
2278 local testroot=`test_init update_single_file 1`
2280 echo c1 > $testroot/repo/c
2281 (cd $testroot/repo && git add .)
2282 git_commit $testroot/repo -m "adding file c"
2283 local commit_id1=`git_show_head $testroot/repo`
2285 echo a > $testroot/repo/a
2286 echo b > $testroot/repo/b
2287 echo c2 > $testroot/repo/c
2288 (cd $testroot/repo && git add .)
2289 git_commit $testroot/repo -m "add files a and b, change c"
2290 local commit_id2=`git_show_head $testroot/repo`
2292 (cd $testroot/repo && git rm -qf c)
2293 git_commit $testroot/repo -m "remove file c"
2294 local commit_id3=`git_show_head $testroot/repo`
2296 got checkout -c $commit_id2 $testroot/repo $testroot/wt > /dev/null
2297 ret=$?
2298 if [ $ret -ne 0 ]; then
2299 test_done "$testroot" "$ret"
2300 return 1
2303 echo "U c" > $testroot/stdout.expected
2304 echo "Updated to refs/heads/master: $commit_id1" \
2305 >> $testroot/stdout.expected
2307 (cd $testroot/wt && got update -c $commit_id1 c \
2308 > $testroot/stdout)
2310 cmp -s $testroot/stdout.expected $testroot/stdout
2311 ret=$?
2312 if [ $ret -ne 0 ]; then
2313 diff -u $testroot/stdout.expected $testroot/stdout
2314 test_done "$testroot" "$ret"
2315 return 1
2318 echo c1 > $testroot/content.expected
2319 cat $testroot/wt/c > $testroot/content
2321 cmp -s $testroot/content.expected $testroot/content
2322 ret=$?
2323 if [ $ret -ne 0 ]; then
2324 diff -u $testroot/content.expected $testroot/content
2325 test_done "$testroot" "$ret"
2326 return 1
2329 echo "U c" > $testroot/stdout.expected
2330 echo "Updated to refs/heads/master: $commit_id2" \
2331 >> $testroot/stdout.expected
2333 (cd $testroot/wt && got update -c $commit_id2 c > $testroot/stdout)
2335 cmp -s $testroot/stdout.expected $testroot/stdout
2336 ret=$?
2337 if [ $ret -ne 0 ]; then
2338 diff -u $testroot/stdout.expected $testroot/stdout
2339 test_done "$testroot" "$ret"
2340 return 1
2343 echo c2 > $testroot/content.expected
2344 cat $testroot/wt/c > $testroot/content
2346 cmp -s $testroot/content.expected $testroot/content
2347 ret=$?
2348 if [ $ret -ne 0 ]; then
2349 diff -u $testroot/content.expected $testroot/content
2350 test_done "$testroot" "$ret"
2351 return 1
2354 echo "D c" > $testroot/stdout.expected
2355 echo "Updated to refs/heads/master: $commit_id3" \
2356 >> $testroot/stdout.expected
2358 (cd $testroot/wt && got update -c $commit_id3 c \
2359 > $testroot/stdout 2> $testroot/stderr)
2361 echo "got: /c: no such entry found in tree" > $testroot/stderr.expected
2362 cmp -s $testroot/stderr.expected $testroot/stderr
2363 ret=$?
2364 if [ $ret -ne 0 ]; then
2365 diff -u $testroot/stderr.expected $testroot/stderr
2366 test_done "$testroot" "$ret"
2367 return 1
2370 echo -n > $testroot/stdout.expected
2371 cmp -s $testroot/stdout.expected $testroot/stdout
2372 ret=$?
2373 if [ $ret -ne 0 ]; then
2374 diff -u $testroot/stdout.expected $testroot/stdout
2375 test_done "$testroot" "$ret"
2376 return 1
2379 echo "D c" > $testroot/stdout.expected
2380 echo "Updated to refs/heads/master: $commit_id3" \
2381 >> $testroot/stdout.expected
2383 (cd $testroot/wt && got update -c $commit_id3 > $testroot/stdout)
2384 cmp -s $testroot/stdout.expected $testroot/stdout
2385 ret=$?
2386 if [ $ret -ne 0 ]; then
2387 diff -u $testroot/stdout.expected $testroot/stdout
2388 test_done "$testroot" "$ret"
2389 return 1
2392 if [ -e $testroot/wt/c ]; then
2393 echo "removed file c still exists on disk" >&2
2394 test_done "$testroot" "1"
2395 return 1
2398 test_done "$testroot" "0"
2399 return 0
2402 test_update_file_skipped_due_to_conflict() {
2403 local testroot=`test_init update_file_skipped_due_to_conflict`
2404 local commit_id0=`git_show_head $testroot/repo`
2405 blob_id0=`get_blob_id $testroot/repo "" beta`
2407 echo "changed beta" > $testroot/repo/beta
2408 git_commit $testroot/repo -m "changed beta"
2409 local commit_id1=`git_show_head $testroot/repo`
2410 blob_id1=`get_blob_id $testroot/repo "" beta`
2412 got checkout $testroot/repo $testroot/wt > /dev/null
2413 ret=$?
2414 if [ $ret -ne 0 ]; then
2415 test_done "$testroot" "$ret"
2416 return 1
2419 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2420 cut -d ':' -f 2 | tr -d ' ')`
2421 if [ "$blob_id" != "$blob_id1" ]; then
2422 echo "file beta has the wrong base blob ID" >&2
2423 test_done "$testroot" "1"
2424 return 1
2427 commit_id=`(cd $testroot/wt && got info beta | \
2428 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2429 if [ "$commit_id" != "$commit_id1" ]; then
2430 echo "file beta has the wrong base commit ID" >&2
2431 test_done "$testroot" "1"
2432 return 1
2435 echo "modified beta" > $testroot/wt/beta
2437 (cd $testroot/wt && got update -c $commit_id0 > $testroot/stdout)
2439 echo "C beta" > $testroot/stdout.expected
2440 echo "Updated to refs/heads/master: $commit_id0" \
2441 >> $testroot/stdout.expected
2442 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2443 cmp -s $testroot/stdout.expected $testroot/stdout
2444 ret=$?
2445 if [ $ret -ne 0 ]; then
2446 diff -u $testroot/stdout.expected $testroot/stdout
2447 test_done "$testroot" "$ret"
2448 return 1
2451 echo "<<<<<<< merged change: commit $commit_id0" \
2452 > $testroot/content.expected
2453 echo "beta" >> $testroot/content.expected
2454 echo "||||||| 3-way merge base: commit $commit_id1" \
2455 >> $testroot/content.expected
2456 echo "changed beta" >> $testroot/content.expected
2457 echo "=======" >> $testroot/content.expected
2458 echo "modified beta" >> $testroot/content.expected
2459 echo ">>>>>>>" >> $testroot/content.expected
2461 cat $testroot/wt/beta > $testroot/content
2463 cmp -s $testroot/content.expected $testroot/content
2464 ret=$?
2465 if [ $ret -ne 0 ]; then
2466 diff -u $testroot/content.expected $testroot/content
2467 test_done "$testroot" "$ret"
2468 return 1
2471 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2472 cut -d ':' -f 2 | tr -d ' ')`
2473 if [ "$blob_id" != "$blob_id0" ]; then
2474 echo "file beta has the wrong base blob ID" >&2
2475 test_done "$testroot" "1"
2476 return 1
2479 commit_id=`(cd $testroot/wt && got info beta | \
2480 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2481 if [ "$commit_id" != "$commit_id0" ]; then
2482 echo "file beta has the wrong base commit ID" >&2
2483 test_done "$testroot" "1"
2484 return 1
2487 # update to the latest commit again; this skips beta
2488 (cd $testroot/wt && got update > $testroot/stdout)
2489 echo "# beta" > $testroot/stdout.expected
2490 echo "Updated to refs/heads/master: $commit_id1" \
2491 >> $testroot/stdout.expected
2492 echo "Files not updated because of existing merge conflicts: 1" \
2493 >> $testroot/stdout.expected
2494 cmp -s $testroot/stdout.expected $testroot/stdout
2495 ret=$?
2496 if [ $ret -ne 0 ]; then
2497 diff -u $testroot/stdout.expected $testroot/stdout
2498 test_done "$testroot" "$ret"
2499 return 1
2502 # blob ID of beta should not have changed
2503 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2504 cut -d ':' -f 2 | tr -d ' ')`
2505 if [ "$blob_id" != "$blob_id0" ]; then
2506 echo "file beta has the wrong base blob ID" >&2
2507 test_done "$testroot" "1"
2508 return 1
2511 # commit ID of beta should not have changed; There was a bug
2512 # here where the commit ID had been changed even though the
2513 # file was not updated.
2514 commit_id=`(cd $testroot/wt && got info beta | \
2515 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2516 if [ "$commit_id" != "$commit_id0" ]; then
2517 echo "file beta has the wrong base commit ID: $commit_id" >&2
2518 test_done "$testroot" "1"
2519 return 1
2522 # beta is still conflicted and based on commit 0
2523 echo 'C beta' > $testroot/stdout.expected
2524 (cd $testroot/wt && got status > $testroot/stdout)
2525 cmp -s $testroot/stdout.expected $testroot/stdout
2526 ret=$?
2527 if [ $ret -ne 0 ]; then
2528 diff -u $testroot/stdout.expected $testroot/stdout
2529 test_done "$testroot" "$ret"
2530 return 1
2533 # resolve the conflict via revert
2534 (cd $testroot/wt && got revert beta >/dev/null)
2536 # beta now matches its base blob which is still from commit 0
2537 echo "beta" > $testroot/content.expected
2538 cat $testroot/wt/beta > $testroot/content
2539 cmp -s $testroot/content.expected $testroot/content
2540 ret=$?
2541 if [ $ret -ne 0 ]; then
2542 diff -u $testroot/content.expected $testroot/content
2543 test_done "$testroot" "$ret"
2544 return 1
2547 # updating to the latest commit should now update beta
2548 (cd $testroot/wt && got update > $testroot/stdout)
2549 echo "U beta" > $testroot/stdout.expected
2550 echo "Updated to refs/heads/master: $commit_id1" \
2551 >> $testroot/stdout.expected
2552 cmp -s $testroot/stdout.expected $testroot/stdout
2553 ret=$?
2554 if [ $ret -ne 0 ]; then
2555 diff -u $testroot/stdout.expected $testroot/stdout
2556 test_done "$testroot" "$ret"
2557 return 1
2560 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2561 cut -d ':' -f 2 | tr -d ' ')`
2562 if [ "$blob_id" != "$blob_id1" ]; then
2563 echo "file beta has the wrong base blob ID" >&2
2564 test_done "$testroot" "1"
2565 return 1
2568 commit_id=`(cd $testroot/wt && got info beta | \
2569 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2570 if [ "$commit_id" != "$commit_id1" ]; then
2571 echo "file beta has the wrong base commit ID: $commit_id" >&2
2572 test_done "$testroot" "1"
2573 return 1
2576 echo "changed beta" > $testroot/content.expected
2577 cat $testroot/wt/beta > $testroot/content
2578 cmp -s $testroot/content.expected $testroot/content
2579 ret=$?
2580 if [ $ret -ne 0 ]; then
2581 diff -u $testroot/content.expected $testroot/content
2583 test_done "$testroot" "$ret"
2586 test_update_file_skipped_due_to_obstruction() {
2587 local testroot=`test_init update_file_skipped_due_to_obstruction`
2588 local commit_id0=`git_show_head $testroot/repo`
2589 blob_id0=`get_blob_id $testroot/repo "" beta`
2591 echo "changed beta" > $testroot/repo/beta
2592 echo "new file" > $testroot/repo/new
2593 (cd $testroot/repo && git add new)
2594 git_commit $testroot/repo -m "changed beta"
2595 local commit_id1=`git_show_head $testroot/repo`
2596 blob_id1=`get_blob_id $testroot/repo "" beta`
2598 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
2599 ret=$?
2600 if [ $ret -ne 0 ]; then
2601 test_done "$testroot" "$ret"
2602 return 1
2605 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2606 cut -d ':' -f 2 | tr -d ' ')`
2607 if [ "$blob_id" != "$blob_id0" ]; then
2608 echo "file beta has the wrong base blob ID" >&2
2609 test_done "$testroot" "1"
2610 return 1
2613 commit_id=`(cd $testroot/wt && got info beta | \
2614 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2615 if [ "$commit_id" != "$commit_id0" ]; then
2616 echo "file beta has the wrong base commit ID" >&2
2617 test_done "$testroot" "1"
2618 return 1
2621 rm $testroot/wt/beta
2622 mkdir -p $testroot/wt/beta/psi
2623 mkdir -p $testroot/wt/new
2625 # update to the latest commit; this skips beta and the new file
2626 (cd $testroot/wt && got update > $testroot/stdout)
2627 ret=$?
2628 if [ $ret -ne 0 ]; then
2629 echo "update failed unexpectedly" >&2
2630 test_done "$testroot" "1"
2631 return 1
2634 echo "~ beta" > $testroot/stdout.expected
2635 echo "~ new" >> $testroot/stdout.expected
2636 echo "Updated to refs/heads/master: $commit_id1" \
2637 >> $testroot/stdout.expected
2638 echo "File paths obstructed by a non-regular file: 2" \
2639 >> $testroot/stdout.expected
2640 cmp -s $testroot/stdout.expected $testroot/stdout
2641 ret=$?
2642 if [ $ret -ne 0 ]; then
2643 diff -u $testroot/stdout.expected $testroot/stdout
2644 test_done "$testroot" "$ret"
2645 return 1
2648 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2649 cut -d ':' -f 2 | tr -d ' ')`
2650 if [ "$blob_id" != "$blob_id0" ]; then
2651 echo "file beta has the wrong base blob ID" >&2
2652 test_done "$testroot" "1"
2653 return 1
2656 commit_id=`(cd $testroot/wt && got info beta | \
2657 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2658 if [ "$commit_id" != "$commit_id0" ]; then
2659 echo "file beta has the wrong base commit ID" >&2
2660 test_done "$testroot" "1"
2661 return 1
2664 # remove the directory which obstructs file beta
2665 rm -r $testroot/wt/beta
2667 # updating to the latest commit should now update beta
2668 (cd $testroot/wt && got update > $testroot/stdout)
2669 echo "! beta" > $testroot/stdout.expected
2670 echo "~ new" >> $testroot/stdout.expected
2671 echo "Updated to refs/heads/master: $commit_id1" \
2672 >> $testroot/stdout.expected
2673 echo "File paths obstructed by a non-regular file: 1" \
2674 >> $testroot/stdout.expected
2675 cmp -s $testroot/stdout.expected $testroot/stdout
2676 ret=$?
2677 if [ $ret -ne 0 ]; then
2678 diff -u $testroot/stdout.expected $testroot/stdout
2679 test_done "$testroot" "$ret"
2680 return 1
2683 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2684 cut -d ':' -f 2 | tr -d ' ')`
2685 if [ "$blob_id" != "$blob_id1" ]; then
2686 echo "file beta has the wrong base blob ID" >&2
2687 test_done "$testroot" "1"
2688 return 1
2691 commit_id=`(cd $testroot/wt && got info beta | \
2692 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2693 if [ "$commit_id" != "$commit_id1" ]; then
2694 echo "file beta has the wrong base commit ID: $commit_id" >&2
2695 test_done "$testroot" "1"
2696 return 1
2699 echo "changed beta" > $testroot/content.expected
2700 cat $testroot/wt/beta > $testroot/content
2701 cmp -s $testroot/content.expected $testroot/content
2702 ret=$?
2703 if [ $ret -ne 0 ]; then
2704 diff -u $testroot/content.expected $testroot/content
2706 test_done "$testroot" "$ret"
2709 test_update_quiet() {
2710 local testroot=`test_init update_quiet`
2712 got checkout $testroot/repo $testroot/wt > /dev/null
2713 ret=$?
2714 if [ $ret -ne 0 ]; then
2715 test_done "$testroot" "$ret"
2716 return 1
2719 echo "modified alpha" > $testroot/repo/alpha
2720 git_commit $testroot/repo -m "modified alpha"
2722 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2723 git_show_head $testroot/repo >> $testroot/stdout.expected
2724 echo >> $testroot/stdout.expected
2726 (cd $testroot/wt && got update -q > $testroot/stdout)
2728 cmp -s $testroot/stdout.expected $testroot/stdout
2729 ret=$?
2730 if [ $ret -ne 0 ]; then
2731 diff -u $testroot/stdout.expected $testroot/stdout
2732 test_done "$testroot" "$ret"
2733 return 1
2736 echo "modified alpha" > $testroot/content.expected
2737 cat $testroot/wt/alpha > $testroot/content
2739 cmp -s $testroot/content.expected $testroot/content
2740 ret=$?
2741 if [ $ret -ne 0 ]; then
2742 diff -u $testroot/content.expected $testroot/content
2744 test_done "$testroot" "$ret"
2747 test_update_binary_file() {
2748 local testroot=`test_init update_binary_file`
2749 local commit_id0=`git_show_head $testroot/repo`
2751 got checkout $testroot/repo $testroot/wt > /dev/null
2752 ret=$?
2753 if [ $ret -ne 0 ]; then
2754 test_done "$testroot" "$ret"
2755 return 1
2758 cp /bin/ls $testroot/wt/foo
2759 chmod 755 $testroot/wt/foo
2760 (cd $testroot/wt && got add foo >/dev/null)
2761 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
2762 local commit_id1=`git_show_head $testroot/repo`
2764 cp /bin/cat $testroot/wt/foo
2765 chmod 755 $testroot/wt/foo
2766 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2767 local commit_id2=`git_show_head $testroot/repo`
2769 cp /bin/cp $testroot/wt/foo
2770 chmod 755 $testroot/wt/foo
2771 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2772 local commit_id3=`git_show_head $testroot/repo`
2774 (cd $testroot/wt && got rm foo >/dev/null)
2775 (cd $testroot/wt && got commit -m 'remove binary file' > /dev/null)
2776 local commit_id4=`git_show_head $testroot/repo`
2778 # backdate the work tree to make it usable for updating
2779 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2781 # update which adds a binary file
2782 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2784 echo "A foo" > $testroot/stdout.expected
2785 echo -n "Updated to refs/heads/master: $commit_id1" \
2786 >> $testroot/stdout.expected
2787 echo >> $testroot/stdout.expected
2788 cmp -s $testroot/stdout.expected $testroot/stdout
2789 ret=$?
2790 if [ $ret -ne 0 ]; then
2791 diff -u $testroot/stdout.expected $testroot/stdout
2792 test_done "$testroot" "$ret"
2793 return 1
2796 cp /bin/ls $testroot/content.expected
2797 chmod 755 $testroot/content.expected
2798 cat $testroot/wt/foo > $testroot/content
2800 cmp -s $testroot/content.expected $testroot/content
2801 ret=$?
2802 if [ $ret -ne 0 ]; then
2803 diff -u $testroot/content.expected $testroot/content
2804 test_done "$testroot" "$ret"
2805 return 1
2808 # update which adds a conflicting binary file
2809 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2810 cp /bin/cat $testroot/wt/foo
2811 chmod 755 $testroot/wt/foo
2812 (cd $testroot/wt && got add foo > /dev/null)
2813 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2815 echo "C foo" > $testroot/stdout.expected
2816 echo "Updated to refs/heads/master: $commit_id1" \
2817 >> $testroot/stdout.expected
2818 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2819 cmp -s $testroot/stdout.expected $testroot/stdout
2820 ret=$?
2821 if [ $ret -ne 0 ]; then
2822 diff -u $testroot/stdout.expected $testroot/stdout
2823 test_done "$testroot" "$ret"
2824 return 1
2827 echo "Binary files differ and cannot be merged automatically:" \
2828 > $testroot/content.expected
2829 echo "<<<<<<< merged change: commit $commit_id1" \
2830 >> $testroot/content.expected
2831 echo -n "file " >> $testroot/content.expected
2832 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2833 echo '=======' >> $testroot/content.expected
2834 echo -n "file " >> $testroot/content.expected
2835 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2836 echo ">>>>>>>" >> $testroot/content.expected
2837 cat $testroot/wt/foo > $testroot/content
2839 cmp -s $testroot/content.expected $testroot/content
2840 ret=$?
2841 if [ $ret -ne 0 ]; then
2842 diff -u $testroot/content.expected $testroot/content
2843 test_done "$testroot" "$ret"
2844 return 1
2847 cp /bin/ls $testroot/content.expected
2848 chmod 755 $testroot/content.expected
2849 cat $testroot/wt/foo-1-* > $testroot/content
2851 cmp -s $testroot/content.expected $testroot/content
2852 ret=$?
2853 if [ $ret -ne 0 ]; then
2854 diff -u $testroot/content.expected $testroot/content
2855 test_done "$testroot" "$ret"
2856 return 1
2859 cp /bin/cat $testroot/content.expected
2860 chmod 755 $testroot/content.expected
2861 cat $testroot/wt/foo-2-* > $testroot/content
2863 cmp -s $testroot/content.expected $testroot/content
2864 ret=$?
2865 if [ $ret -ne 0 ]; then
2866 diff -u $testroot/content.expected $testroot/content
2867 test_done "$testroot" "$ret"
2868 return 1
2871 # tidy up
2872 (cd $testroot/wt && got revert -R . >/dev/null)
2873 rm $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2874 (cd $testroot/wt && got up -c $commit_id1 > /dev/null)
2876 # update which changes a binary file
2877 (cd $testroot/wt && got up -c $commit_id2 > $testroot/stdout)
2879 echo "U foo" > $testroot/stdout.expected
2880 echo -n "Updated to refs/heads/master: $commit_id2" \
2881 >> $testroot/stdout.expected
2882 echo >> $testroot/stdout.expected
2883 cmp -s $testroot/stdout.expected $testroot/stdout
2884 ret=$?
2885 if [ $ret -ne 0 ]; then
2886 diff -u $testroot/stdout.expected $testroot/stdout
2887 test_done "$testroot" "$ret"
2888 return 1
2891 cp /bin/cat $testroot/content.expected
2892 chmod 755 $testroot/content.expected
2893 cat $testroot/wt/foo > $testroot/content
2895 cmp -s $testroot/content.expected $testroot/content
2896 ret=$?
2897 if [ $ret -ne 0 ]; then
2898 diff -u $testroot/content.expected $testroot/content
2899 test_done "$testroot" "$ret"
2900 return 1
2903 # update which changes a locally modified binary file
2904 cp /bin/ls $testroot/wt/foo
2905 chmod 755 $testroot/wt/foo
2906 (cd $testroot/wt && got up -c $commit_id3 > $testroot/stdout)
2908 echo "C foo" > $testroot/stdout.expected
2909 echo -n "Updated to refs/heads/master: $commit_id3" \
2910 >> $testroot/stdout.expected
2911 echo >> $testroot/stdout.expected
2912 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2913 cmp -s $testroot/stdout.expected $testroot/stdout
2914 ret=$?
2915 if [ $ret -ne 0 ]; then
2916 diff -u $testroot/stdout.expected $testroot/stdout
2917 test_done "$testroot" "$ret"
2918 return 1
2921 echo "Binary files differ and cannot be merged automatically:" \
2922 > $testroot/content.expected
2923 echo "<<<<<<< merged change: commit $commit_id3" \
2924 >> $testroot/content.expected
2925 echo -n "file " >> $testroot/content.expected
2926 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2927 echo "||||||| 3-way merge base: commit $commit_id2" \
2928 >> $testroot/content.expected
2929 echo -n "file " >> $testroot/content.expected
2930 ls $testroot/wt/foo-orig-* >> $testroot/content.expected
2931 echo '=======' >> $testroot/content.expected
2932 echo -n "file " >> $testroot/content.expected
2933 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2934 echo ">>>>>>>" >> $testroot/content.expected
2935 cat $testroot/wt/foo > $testroot/content
2937 cmp -s $testroot/content.expected $testroot/content
2938 ret=$?
2939 if [ $ret -ne 0 ]; then
2940 diff -u $testroot/content.expected $testroot/content
2941 test_done "$testroot" "$ret"
2942 return 1
2945 cp /bin/cp $testroot/content.expected
2946 chmod 755 $testroot/content.expected
2947 cp $testroot/wt/foo-1-* $testroot/content
2948 cmp -s $testroot/content.expected $testroot/content
2949 ret=$?
2950 if [ $ret -ne 0 ]; then
2951 diff -u $testroot/content.expected $testroot/content
2952 test_done "$testroot" "$ret"
2953 return 1
2956 cp /bin/ls $testroot/content.expected
2957 chmod 755 $testroot/content.expected
2958 cp $testroot/wt/foo-2-* $testroot/content
2959 cmp -s $testroot/content.expected $testroot/content
2960 ret=$?
2961 if [ $ret -ne 0 ]; then
2962 diff -u $testroot/content.expected $testroot/content
2963 test_done "$testroot" "$ret"
2964 return 1
2967 (cd $testroot/wt && got status > $testroot/stdout)
2968 echo 'C foo' > $testroot/stdout.expected
2969 echo -n '? ' >> $testroot/stdout.expected
2970 (cd $testroot/wt && ls foo-1-* >> $testroot/stdout.expected)
2971 echo -n '? ' >> $testroot/stdout.expected
2972 (cd $testroot/wt && ls foo-2-* >> $testroot/stdout.expected)
2973 echo -n '? ' >> $testroot/stdout.expected
2974 (cd $testroot/wt && ls foo-orig-* >> $testroot/stdout.expected)
2975 cmp -s $testroot/stdout.expected $testroot/stdout
2976 ret=$?
2977 if [ $ret -ne 0 ]; then
2978 diff -u $testroot/stdout.expected $testroot/stdout
2979 test_done "$testroot" "$ret"
2980 return 1
2983 # tidy up
2984 (cd $testroot/wt && got revert -R . > /dev/null)
2985 rm $testroot/wt/foo-orig-* $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2987 # update which deletes a binary file
2988 (cd $testroot/wt && got up -c $commit_id4 > $testroot/stdout)
2989 echo "D foo" > $testroot/stdout.expected
2990 echo -n "Updated to refs/heads/master: $commit_id4" \
2991 >> $testroot/stdout.expected
2992 echo >> $testroot/stdout.expected
2993 cmp -s $testroot/stdout.expected $testroot/stdout
2994 ret=$?
2995 if [ $ret -ne 0 ]; then
2996 diff -u $testroot/stdout.expected $testroot/stdout
2997 test_done "$testroot" "$ret"
3000 if [ -e $testroot/wt/foo ]; then
3001 echo "removed file foo still exists on disk" >&2
3002 test_done "$testroot" "1"
3003 return 1
3005 test_done "$testroot" "0"
3008 test_parseargs "$@"
3009 run_test test_update_basic
3010 run_test test_update_adds_file
3011 run_test test_update_deletes_file
3012 run_test test_update_deletes_dir
3013 run_test test_update_deletes_dir_with_path_prefix
3014 run_test test_update_deletes_dir_recursively
3015 run_test test_update_sibling_dirs_with_common_prefix
3016 run_test test_update_dir_with_dot_sibling
3017 run_test test_update_moves_files_upwards
3018 run_test test_update_moves_files_to_new_dir
3019 run_test test_update_creates_missing_parent
3020 run_test test_update_creates_missing_parent_with_subdir
3021 run_test test_update_file_in_subsubdir
3022 run_test test_update_merges_file_edits
3023 run_test test_update_keeps_xbit
3024 run_test test_update_clears_xbit
3025 run_test test_update_restores_missing_file
3026 run_test test_update_conflict_wt_add_vs_repo_add
3027 run_test test_update_conflict_wt_edit_vs_repo_rm
3028 run_test test_update_conflict_wt_rm_vs_repo_edit
3029 run_test test_update_conflict_wt_rm_vs_repo_rm
3030 run_test test_update_partial
3031 run_test test_update_partial_add
3032 run_test test_update_partial_rm
3033 run_test test_update_partial_dir
3034 run_test test_update_moved_branch_ref
3035 run_test test_update_to_another_branch
3036 run_test test_update_to_commit_on_wrong_branch
3037 run_test test_update_bumps_base_commit_id
3038 run_test test_update_tag
3039 run_test test_update_toggles_xbit
3040 run_test test_update_preserves_conflicted_file
3041 run_test test_update_modified_submodules
3042 run_test test_update_adds_submodule
3043 run_test test_update_conflict_wt_file_vs_repo_submodule
3044 run_test test_update_adds_symlink
3045 run_test test_update_deletes_symlink
3046 run_test test_update_symlink_conflicts
3047 run_test test_update_single_file
3048 run_test test_update_file_skipped_due_to_conflict
3049 run_test test_update_file_skipped_due_to_obstruction
3050 run_test test_update_quiet
3051 run_test test_update_binary_file