Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_update_basic() {
20 local testroot=`test_init update_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified alpha" > $testroot/repo/alpha
30 git_commit $testroot/repo -m "modified alpha"
32 echo "U alpha" > $testroot/stdout.expected
33 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
34 git_show_head $testroot/repo >> $testroot/stdout.expected
35 echo >> $testroot/stdout.expected
37 (cd $testroot/wt && got update > $testroot/stdout)
39 cmp -s $testroot/stdout.expected $testroot/stdout
40 ret=$?
41 if [ $ret -ne 0 ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
43 test_done "$testroot" "$ret"
44 return 1
45 fi
47 echo "modified alpha" > $testroot/content.expected
48 cat $testroot/wt/alpha > $testroot/content
50 cmp -s $testroot/content.expected $testroot/content
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 diff -u $testroot/content.expected $testroot/content
54 fi
55 test_done "$testroot" "$ret"
56 }
58 test_update_adds_file() {
59 local testroot=`test_init update_adds_file`
61 got checkout $testroot/repo $testroot/wt > /dev/null
62 ret=$?
63 if [ $ret -ne 0 ]; then
64 test_done "$testroot" "$ret"
65 return 1
66 fi
68 echo "new" > $testroot/repo/gamma/new
69 (cd $testroot/repo && git add .)
70 git_commit $testroot/repo -m "adding a new file"
72 echo "A gamma/new" > $testroot/stdout.expected
73 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
74 git_show_head $testroot/repo >> $testroot/stdout.expected
75 echo >> $testroot/stdout.expected
77 (cd $testroot/wt && got update > $testroot/stdout)
79 cmp -s $testroot/stdout.expected $testroot/stdout
80 ret=$?
81 if [ $ret -ne 0 ]; then
82 diff -u $testroot/stdout.expected $testroot/stdout
83 test_done "$testroot" "$ret"
84 return 1
85 fi
87 echo "new" >> $testroot/content.expected
88 cat $testroot/wt/gamma/new > $testroot/content
90 cmp -s $testroot/content.expected $testroot/content
91 ret=$?
92 if [ $ret -ne 0 ]; then
93 diff -u $testroot/content.expected $testroot/content
94 fi
95 test_done "$testroot" "$ret"
96 }
98 test_update_deletes_file() {
99 local testroot=`test_init update_deletes_file`
101 mkdir $testroot/wtparent
102 got checkout $testroot/repo $testroot/wtparent/wt > /dev/null
103 ret=$?
104 if [ $ret -ne 0 ]; then
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/repo && git_rm $testroot/repo beta)
110 git_commit $testroot/repo -m "deleting a file"
112 echo "D beta" > $testroot/stdout.expected
113 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
114 git_show_head $testroot/repo >> $testroot/stdout.expected
115 echo >> $testroot/stdout.expected
117 # verify that no error occurs if the work tree's parent
118 # directory is not writable
119 chmod u-w $testroot/wtparent
120 (cd $testroot/wtparent/wt && got update > $testroot/stdout)
121 chmod u+w $testroot/wtparent
123 cmp -s $testroot/stdout.expected $testroot/stdout
124 ret=$?
125 if [ $ret -ne 0 ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 test_done "$testroot" "$ret"
128 return 1
129 fi
131 if [ -e $testroot/wtparent/wt/beta ]; then
132 echo "removed file beta still exists on disk" >&2
133 test_done "$testroot" "1"
134 return 1
135 fi
137 test_done "$testroot" "0"
140 test_update_deletes_dir() {
141 local testroot=`test_init update_deletes_dir`
143 got checkout $testroot/repo $testroot/wt > /dev/null
144 ret=$?
145 if [ $ret -ne 0 ]; then
146 test_done "$testroot" "$ret"
147 return 1
148 fi
150 (cd $testroot/repo && git_rm $testroot/repo -r epsilon)
151 git_commit $testroot/repo -m "deleting a directory"
153 echo "D epsilon/zeta" > $testroot/stdout.expected
154 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
155 git_show_head $testroot/repo >> $testroot/stdout.expected
156 echo >> $testroot/stdout.expected
158 (cd $testroot/wt && got update > $testroot/stdout)
160 cmp -s $testroot/stdout.expected $testroot/stdout
161 ret=$?
162 if [ $ret -ne 0 ]; then
163 diff -u $testroot/stdout.expected $testroot/stdout
164 test_done "$testroot" "$ret"
165 return 1
166 fi
168 if [ -e $testroot/wt/epsilon ]; then
169 echo "removed dir epsilon still exists on disk" >&2
170 test_done "$testroot" "1"
171 return 1
172 fi
174 test_done "$testroot" "0"
177 test_update_deletes_dir_with_path_prefix() {
178 local testroot=`test_init update_deletes_dir_with_path_prefix`
179 local first_rev=`git_show_head $testroot/repo`
181 mkdir $testroot/repo/epsilon/psi
182 echo mu > $testroot/repo/epsilon/psi/mu
183 (cd $testroot/repo && git add .)
184 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
186 # check out the epsilon/ sub-tree
187 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
188 ret=$?
189 if [ $ret -ne 0 ]; then
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 # update back to first commit and expect psi/mu to be deleted
195 echo "D psi/mu" > $testroot/stdout.expected
196 echo "Updated to refs/heads/master: $first_rev" \
197 >> $testroot/stdout.expected
199 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
201 cmp -s $testroot/stdout.expected $testroot/stdout
202 ret=$?
203 if [ $ret -ne 0 ]; then
204 diff -u $testroot/stdout.expected $testroot/stdout
205 test_done "$testroot" "$ret"
206 return 1
207 fi
209 if [ -e $testroot/wt/psi ]; then
210 echo "removed dir psi still exists on disk" >&2
211 test_done "$testroot" "1"
212 return 1
213 fi
215 test_done "$testroot" "0"
218 test_update_deletes_dir_recursively() {
219 local testroot=`test_init update_deletes_dir_recursively`
220 local first_rev=`git_show_head $testroot/repo`
222 mkdir $testroot/repo/epsilon/psi
223 echo mu > $testroot/repo/epsilon/psi/mu
224 mkdir $testroot/repo/epsilon/psi/chi
225 echo tau > $testroot/repo/epsilon/psi/chi/tau
226 (cd $testroot/repo && git add .)
227 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
229 # check out the epsilon/ sub-tree
230 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
231 ret=$?
232 if [ $ret -ne 0 ]; then
233 test_done "$testroot" "$ret"
234 return 1
235 fi
237 # update back to first commit and expect psi/mu to be deleted
238 echo "D psi/chi/tau" > $testroot/stdout.expected
239 echo "D psi/mu" >> $testroot/stdout.expected
240 echo "Updated to refs/heads/master: $first_rev" \
241 >> $testroot/stdout.expected
243 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
245 cmp -s $testroot/stdout.expected $testroot/stdout
246 ret=$?
247 if [ "$?" != "0" ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 if [ -e $testroot/wt/psi ]; then
254 echo "removed dir psi still exists on disk" >&2
255 test_done "$testroot" "1"
256 return 1
257 fi
259 test_done "$testroot" "0"
262 test_update_sibling_dirs_with_common_prefix() {
263 local testroot=`test_init update_sibling_dirs_with_common_prefix`
265 got checkout $testroot/repo $testroot/wt > /dev/null
266 ret=$?
267 if [ $ret -ne 0 ]; then
268 test_done "$testroot" "$ret"
269 return 1
270 fi
272 mkdir $testroot/repo/epsilon2
273 echo mu > $testroot/repo/epsilon2/mu
274 (cd $testroot/repo && git add epsilon2/mu)
275 git_commit $testroot/repo -m "adding sibling of epsilon"
276 echo change > $testroot/repo/epsilon/zeta
277 git_commit $testroot/repo -m "changing epsilon/zeta"
279 echo "U epsilon/zeta" > $testroot/stdout.expected
280 echo "A epsilon2/mu" >> $testroot/stdout.expected
281 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
282 git_show_head $testroot/repo >> $testroot/stdout.expected
283 echo >> $testroot/stdout.expected
285 (cd $testroot/wt && got update > $testroot/stdout)
287 cmp -s $testroot/stdout.expected $testroot/stdout
288 ret=$?
289 if [ $ret -ne 0 ]; then
290 diff -u $testroot/stdout.expected $testroot/stdout
291 test_done "$testroot" "$ret"
292 return 1
293 fi
295 echo "another change" > $testroot/repo/epsilon/zeta
296 git_commit $testroot/repo -m "changing epsilon/zeta again"
298 echo "U epsilon/zeta" > $testroot/stdout.expected
299 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
300 git_show_head $testroot/repo >> $testroot/stdout.expected
301 echo >> $testroot/stdout.expected
303 # Bug: This update used to do delete/add epsilon2/mu again:
304 # U epsilon/zeta
305 # D epsilon2/mu <--- not intended
306 # A epsilon2/mu <--- not intended
307 (cd $testroot/wt && got update > $testroot/stdout)
309 cmp -s $testroot/stdout.expected $testroot/stdout
310 ret=$?
311 if [ $ret -ne 0 ]; then
312 diff -u $testroot/stdout.expected $testroot/stdout
313 test_done "$testroot" "$ret"
314 return 1
315 fi
317 cmp -s $testroot/stdout.expected $testroot/stdout
318 ret=$?
319 if [ $ret -ne 0 ]; then
320 diff -u $testroot/stdout.expected $testroot/stdout
321 fi
322 test_done "$testroot" "$ret"
325 test_update_dir_with_dot_sibling() {
326 local testroot=`test_init update_dir_with_dot_sibling`
328 got checkout $testroot/repo $testroot/wt > /dev/null
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 test_done "$testroot" "$ret"
332 return 1
333 fi
335 echo text > $testroot/repo/epsilon.txt
336 (cd $testroot/repo && git add epsilon.txt)
337 git_commit $testroot/repo -m "adding sibling of epsilon"
338 echo change > $testroot/repo/epsilon/zeta
339 git_commit $testroot/repo -m "changing epsilon/zeta"
341 echo "U epsilon/zeta" > $testroot/stdout.expected
342 echo "A epsilon.txt" >> $testroot/stdout.expected
343 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
344 git_show_head $testroot/repo >> $testroot/stdout.expected
345 echo >> $testroot/stdout.expected
347 (cd $testroot/wt && got update > $testroot/stdout)
349 cmp -s $testroot/stdout.expected $testroot/stdout
350 ret=$?
351 if [ $ret -ne 0 ]; then
352 diff -u $testroot/stdout.expected $testroot/stdout
353 test_done "$testroot" "$ret"
354 return 1
355 fi
357 echo "another change" > $testroot/repo/epsilon/zeta
358 git_commit $testroot/repo -m "changing epsilon/zeta again"
360 echo "U epsilon/zeta" > $testroot/stdout.expected
361 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
362 git_show_head $testroot/repo >> $testroot/stdout.expected
363 echo >> $testroot/stdout.expected
365 (cd $testroot/wt && got update > $testroot/stdout)
367 cmp -s $testroot/stdout.expected $testroot/stdout
368 ret=$?
369 if [ $ret -ne 0 ]; then
370 diff -u $testroot/stdout.expected $testroot/stdout
371 test_done "$testroot" "$ret"
372 return 1
373 fi
375 cmp -s $testroot/stdout.expected $testroot/stdout
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 fi
380 test_done "$testroot" "$ret"
383 test_update_moves_files_upwards() {
384 local testroot=`test_init update_moves_files_upwards`
386 mkdir $testroot/repo/epsilon/psi
387 echo mu > $testroot/repo/epsilon/psi/mu
388 mkdir $testroot/repo/epsilon/psi/chi
389 echo tau > $testroot/repo/epsilon/psi/chi/tau
390 (cd $testroot/repo && git add .)
391 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
393 got checkout $testroot/repo $testroot/wt > /dev/null
394 ret=$?
395 if [ $ret -ne 0 ]; then
396 test_done "$testroot" "$ret"
397 return 1
398 fi
400 (cd $testroot/repo && git mv epsilon/psi/mu epsilon/mu)
401 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon/psi/tau)
402 git_commit $testroot/repo -m "moving files upwards"
404 echo "A epsilon/mu" > $testroot/stdout.expected
405 echo "D epsilon/psi/chi/tau" >> $testroot/stdout.expected
406 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
407 echo "A epsilon/psi/tau" >> $testroot/stdout.expected
408 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
409 git_show_head $testroot/repo >> $testroot/stdout.expected
410 echo >> $testroot/stdout.expected
412 (cd $testroot/wt && got update > $testroot/stdout)
414 cmp -s $testroot/stdout.expected $testroot/stdout
415 ret=$?
416 if [ $ret -ne 0 ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
418 test_done "$testroot" "$ret"
419 return 1
420 fi
422 if [ -e $testroot/wt/epsilon/psi/chi ]; then
423 echo "removed dir epsilon/psi/chi still exists on disk" >&2
424 test_done "$testroot" "1"
425 return 1
426 fi
428 if [ -e $testroot/wt/epsilon/psi/mu ]; then
429 echo "removed file epsilon/psi/mu still exists on disk" >&2
430 test_done "$testroot" "1"
431 return 1
432 fi
434 test_done "$testroot" "0"
437 test_update_moves_files_to_new_dir() {
438 local testroot=`test_init update_moves_files_to_new_dir`
440 mkdir $testroot/repo/epsilon/psi
441 echo mu > $testroot/repo/epsilon/psi/mu
442 mkdir $testroot/repo/epsilon/psi/chi
443 echo tau > $testroot/repo/epsilon/psi/chi/tau
444 (cd $testroot/repo && git add .)
445 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
447 got checkout $testroot/repo $testroot/wt > /dev/null
448 ret=$?
449 if [ $ret -ne 0 ]; then
450 test_done "$testroot" "$ret"
451 return 1
452 fi
454 mkdir -p $testroot/repo/epsilon-new/psi
455 (cd $testroot/repo && git mv epsilon/psi/mu epsilon-new/mu)
456 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon-new/psi/tau)
457 git_commit $testroot/repo -m "moving files upwards"
459 echo "D epsilon/psi/chi/tau" > $testroot/stdout.expected
460 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
461 echo "A epsilon-new/mu" >> $testroot/stdout.expected
462 echo "A epsilon-new/psi/tau" >> $testroot/stdout.expected
463 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
464 git_show_head $testroot/repo >> $testroot/stdout.expected
465 echo >> $testroot/stdout.expected
467 (cd $testroot/wt && got update > $testroot/stdout)
469 cmp -s $testroot/stdout.expected $testroot/stdout
470 ret=$?
471 if [ $ret -ne 0 ]; then
472 diff -u $testroot/stdout.expected $testroot/stdout
473 test_done "$testroot" "$ret"
474 return 1
475 fi
477 if [ -e $testroot/wt/epsilon/psi/chi ]; then
478 echo "removed dir epsilon/psi/chi still exists on disk" >&2
479 test_done "$testroot" "1"
480 return 1
481 fi
483 if [ -e $testroot/wt/epsilon/psi/mu ]; then
484 echo "removed file epsilon/psi/mu still exists on disk" >&2
485 test_done "$testroot" "1"
486 return 1
487 fi
489 test_done "$testroot" "0"
492 test_update_creates_missing_parent() {
493 local testroot=`test_init update_creates_missing_parent 1`
495 touch $testroot/repo/Makefile
496 touch $testroot/repo/snake.6
497 touch $testroot/repo/snake.c
498 (cd $testroot/repo && git add .)
499 git_commit $testroot/repo -m "adding initial snake tree"
501 got checkout $testroot/repo $testroot/wt > /dev/null
502 ret=$?
503 if [ $ret -ne 0 ]; then
504 test_done "$testroot" "$ret"
505 return 1
506 fi
508 mkdir -p $testroot/repo/snake
509 (cd $testroot/repo && git mv Makefile snake.6 snake.c snake)
510 touch $testroot/repo/snake/move.c
511 touch $testroot/repo/snake/pathnames.h
512 touch $testroot/repo/snake/snake.h
513 mkdir -p $testroot/repo/snscore
514 touch $testroot/repo/snscore/Makefile
515 touch $testroot/repo/snscore/snscore.c
516 (cd $testroot/repo && git add .)
517 git_commit $testroot/repo -m "restructuring snake tree"
519 echo "D Makefile" > $testroot/stdout.expected
520 echo "A snake/Makefile" >> $testroot/stdout.expected
521 echo "A snake/move.c" >> $testroot/stdout.expected
522 echo "A snake/pathnames.h" >> $testroot/stdout.expected
523 echo "A snake/snake.6" >> $testroot/stdout.expected
524 echo "A snake/snake.c" >> $testroot/stdout.expected
525 echo "A snake/snake.h" >> $testroot/stdout.expected
526 echo "D snake.6" >> $testroot/stdout.expected
527 echo "D snake.c" >> $testroot/stdout.expected
528 echo "A snscore/Makefile" >> $testroot/stdout.expected
529 echo "A snscore/snscore.c" >> $testroot/stdout.expected
530 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
531 git_show_head $testroot/repo >> $testroot/stdout.expected
532 echo >> $testroot/stdout.expected
534 (cd $testroot/wt && got update > $testroot/stdout)
536 cmp -s $testroot/stdout.expected $testroot/stdout
537 ret=$?
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 fi
541 test_done "$testroot" "$ret"
544 test_update_creates_missing_parent_with_subdir() {
545 local testroot=`test_init update_creates_missing_parent_with_subdir 1`
547 touch $testroot/repo/Makefile
548 touch $testroot/repo/snake.6
549 touch $testroot/repo/snake.c
550 (cd $testroot/repo && git add .)
551 git_commit $testroot/repo -m "adding initial snake tree"
553 got checkout $testroot/repo $testroot/wt > /dev/null
554 ret=$?
555 if [ $ret -ne 0 ]; then
556 test_done "$testroot" "$ret"
557 return 1
558 fi
560 mkdir -p $testroot/repo/sss/snake
561 (cd $testroot/repo && git mv Makefile snake.6 snake.c sss/snake)
562 touch $testroot/repo/sss/snake/move.c
563 touch $testroot/repo/sss/snake/pathnames.h
564 touch $testroot/repo/sss/snake/snake.h
565 mkdir -p $testroot/repo/snscore
566 touch $testroot/repo/snscore/Makefile
567 touch $testroot/repo/snscore/snscore.c
568 (cd $testroot/repo && git add .)
569 git_commit $testroot/repo -m "restructuring snake tree"
571 echo "D Makefile" > $testroot/stdout.expected
572 echo "D snake.6" >> $testroot/stdout.expected
573 echo "D snake.c" >> $testroot/stdout.expected
574 echo "A snscore/Makefile" >> $testroot/stdout.expected
575 echo "A snscore/snscore.c" >> $testroot/stdout.expected
576 echo "A sss/snake/Makefile" >> $testroot/stdout.expected
577 echo "A sss/snake/move.c" >> $testroot/stdout.expected
578 echo "A sss/snake/pathnames.h" >> $testroot/stdout.expected
579 echo "A sss/snake/snake.6" >> $testroot/stdout.expected
580 echo "A sss/snake/snake.c" >> $testroot/stdout.expected
581 echo "A sss/snake/snake.h" >> $testroot/stdout.expected
582 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
583 git_show_head $testroot/repo >> $testroot/stdout.expected
584 echo >> $testroot/stdout.expected
586 (cd $testroot/wt && got update > $testroot/stdout)
588 cmp -s $testroot/stdout.expected $testroot/stdout
589 ret=$?
590 if [ $ret -ne 0 ]; then
591 diff -u $testroot/stdout.expected $testroot/stdout
592 test_done "$testroot" "$ret"
593 return 1
594 fi
596 test_done "$testroot" "0"
599 test_update_file_in_subsubdir() {
600 local testroot=`test_init update_fle_in_subsubdir 1`
602 touch $testroot/repo/Makefile
603 mkdir -p $testroot/repo/altq
604 touch $testroot/repo/altq/if_altq.h
605 mkdir -p $testroot/repo/arch/alpha
606 touch $testroot/repo/arch/alpha/Makefile
607 (cd $testroot/repo && git add .)
608 git_commit $testroot/repo -m "adding initial tree"
610 got checkout $testroot/repo $testroot/wt > /dev/null
611 ret=$?
612 if [ $ret -ne 0 ]; then
613 test_done "$testroot" "$ret"
614 return 1
615 fi
617 echo change > $testroot/repo/arch/alpha/Makefile
618 (cd $testroot/repo && git add .)
619 git_commit $testroot/repo -m "changed a file"
621 echo "U arch/alpha/Makefile" > $testroot/stdout.expected
622 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
623 git_show_head $testroot/repo >> $testroot/stdout.expected
624 echo >> $testroot/stdout.expected
626 (cd $testroot/wt && got update > $testroot/stdout)
628 cmp -s $testroot/stdout.expected $testroot/stdout
629 ret=$?
630 if [ $ret -ne 0 ]; then
631 diff -u $testroot/stdout.expected $testroot/stdout
632 test_done "$testroot" "$ret"
633 return 1
634 fi
636 test_done "$testroot" "0"
639 test_update_merges_file_edits() {
640 local testroot=`test_init update_merges_file_edits`
642 echo "1" > $testroot/repo/numbers
643 echo "2" >> $testroot/repo/numbers
644 echo "3" >> $testroot/repo/numbers
645 echo "4" >> $testroot/repo/numbers
646 echo "5" >> $testroot/repo/numbers
647 echo "6" >> $testroot/repo/numbers
648 echo "7" >> $testroot/repo/numbers
649 echo "8" >> $testroot/repo/numbers
650 (cd $testroot/repo && git add numbers)
651 git_commit $testroot/repo -m "added numbers file"
652 local base_commit=`git_show_head $testroot/repo`
654 got checkout $testroot/repo $testroot/wt > /dev/null
655 ret=$?
656 if [ $ret -ne 0 ]; then
657 test_done "$testroot" "$ret"
658 return 1
659 fi
661 echo "modified alpha" > $testroot/repo/alpha
662 echo "modified beta" > $testroot/repo/beta
663 sed -i 's/2/22/' $testroot/repo/numbers
664 git_commit $testroot/repo -m "modified 3 files"
666 echo "modified alpha, too" > $testroot/wt/alpha
667 touch $testroot/wt/beta
668 sed -i 's/7/77/' $testroot/wt/numbers
670 echo "C alpha" > $testroot/stdout.expected
671 echo "U beta" >> $testroot/stdout.expected
672 echo "G numbers" >> $testroot/stdout.expected
673 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
674 git_show_head $testroot/repo >> $testroot/stdout.expected
675 echo >> $testroot/stdout.expected
676 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
678 (cd $testroot/wt && got update > $testroot/stdout)
680 cmp -s $testroot/stdout.expected $testroot/stdout
681 ret=$?
682 if [ $ret -ne 0 ]; then
683 diff -u $testroot/stdout.expected $testroot/stdout
684 test_done "$testroot" "$ret"
685 return 1
686 fi
688 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
689 git_show_head $testroot/repo >> $testroot/content.expected
690 echo >> $testroot/content.expected
691 echo "modified alpha" >> $testroot/content.expected
692 echo "||||||| 3-way merge base: commit $base_commit" \
693 >> $testroot/content.expected
694 echo "alpha" >> $testroot/content.expected
695 echo "=======" >> $testroot/content.expected
696 echo "modified alpha, too" >> $testroot/content.expected
697 echo '>>>>>>>' >> $testroot/content.expected
698 echo "modified beta" >> $testroot/content.expected
699 echo "1" >> $testroot/content.expected
700 echo "22" >> $testroot/content.expected
701 echo "3" >> $testroot/content.expected
702 echo "4" >> $testroot/content.expected
703 echo "5" >> $testroot/content.expected
704 echo "6" >> $testroot/content.expected
705 echo "77" >> $testroot/content.expected
706 echo "8" >> $testroot/content.expected
708 cat $testroot/wt/alpha > $testroot/content
709 cat $testroot/wt/beta >> $testroot/content
710 cat $testroot/wt/numbers >> $testroot/content
712 cmp -s $testroot/content.expected $testroot/content
713 ret=$?
714 if [ $ret -ne 0 ]; then
715 diff -u $testroot/content.expected $testroot/content
716 fi
717 test_done "$testroot" "$ret"
720 test_update_keeps_xbit() {
721 local testroot=`test_init update_keeps_xbit 1`
723 touch $testroot/repo/xfile
724 chmod +x $testroot/repo/xfile
725 (cd $testroot/repo && git add .)
726 git_commit $testroot/repo -m "adding executable file"
728 got checkout $testroot/repo $testroot/wt > $testroot/stdout
729 ret=$?
730 if [ $ret -ne 0 ]; then
731 test_done "$testroot" "$ret"
732 return 1
733 fi
735 echo foo > $testroot/repo/xfile
736 git_commit $testroot/repo -m "changed executable file"
738 echo "U xfile" > $testroot/stdout.expected
739 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
740 git_show_head $testroot/repo >> $testroot/stdout.expected
741 echo >> $testroot/stdout.expected
743 (cd $testroot/wt && got update > $testroot/stdout)
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 test_done "$testroot" "$ret"
747 return 1
748 fi
750 cmp -s $testroot/stdout.expected $testroot/stdout
751 ret=$?
752 if [ $ret -ne 0 ]; then
753 diff -u $testroot/stdout.expected $testroot/stdout
754 test_done "$testroot" "$ret"
755 return 1
756 fi
758 ls -l $testroot/wt/xfile | grep -q '^-rwx'
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 echo "file is not executable" >&2
762 ls -l $testroot/wt/xfile >&2
763 fi
764 test_done "$testroot" "$ret"
767 test_update_clears_xbit() {
768 local testroot=`test_init update_clears_xbit 1`
770 touch $testroot/repo/xfile
771 chmod +x $testroot/repo/xfile
772 (cd $testroot/repo && git add .)
773 git_commit $testroot/repo -m "adding executable file"
775 got checkout $testroot/repo $testroot/wt > $testroot/stdout
776 ret=$?
777 if [ $ret -ne 0 ]; then
778 test_done "$testroot" "$ret"
779 return 1
780 fi
782 ls -l $testroot/wt/xfile | grep -q '^-rwx'
783 ret=$?
784 if [ $ret -ne 0 ]; then
785 echo "file is not executable" >&2
786 ls -l $testroot/wt/xfile >&2
787 test_done "$testroot" "$ret"
788 return 1
789 fi
791 # XXX git seems to require a file edit when flipping the x bit?
792 echo foo > $testroot/repo/xfile
793 chmod -x $testroot/repo/xfile
794 git_commit $testroot/repo -m "not an executable file anymore"
796 echo "U xfile" > $testroot/stdout.expected
797 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
798 git_show_head $testroot/repo >> $testroot/stdout.expected
799 echo >> $testroot/stdout.expected
801 (cd $testroot/wt && got update > $testroot/stdout)
802 ret=$?
803 if [ $ret -ne 0 ]; then
804 test_done "$testroot" "$ret"
805 return 1
806 fi
808 cmp -s $testroot/stdout.expected $testroot/stdout
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 diff -u $testroot/stdout.expected $testroot/stdout
812 test_done "$testroot" "$ret"
813 return 1
814 fi
816 ls -l $testroot/wt/xfile | grep -q '^-rw-'
817 ret=$?
818 if [ $ret -ne 0 ]; then
819 echo "file is unexpectedly executable" >&2
820 ls -l $testroot/wt/xfile >&2
821 fi
822 test_done "$testroot" "$ret"
825 test_update_restores_missing_file() {
826 local testroot=`test_init update_restores_missing_file`
828 got checkout $testroot/repo $testroot/wt > /dev/null
829 ret=$?
830 if [ $ret -ne 0 ]; then
831 test_done "$testroot" "$ret"
832 return 1
833 fi
835 rm $testroot/wt/alpha
837 echo "! alpha" > $testroot/stdout.expected
838 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
839 git_show_head $testroot/repo >> $testroot/stdout.expected
840 echo >> $testroot/stdout.expected
841 (cd $testroot/wt && got update > $testroot/stdout)
843 cmp -s $testroot/stdout.expected $testroot/stdout
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
847 test_done "$testroot" "$ret"
848 return 1
849 fi
851 echo "alpha" > $testroot/content.expected
853 cat $testroot/wt/alpha > $testroot/content
855 cmp -s $testroot/content.expected $testroot/content
856 ret=$?
857 if [ $ret -ne 0 ]; then
858 diff -u $testroot/content.expected $testroot/content
859 fi
860 test_done "$testroot" "$ret"
863 test_update_conflict_wt_add_vs_repo_add() {
864 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
866 got checkout $testroot/repo $testroot/wt > /dev/null
867 ret=$?
868 if [ $ret -ne 0 ]; then
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 echo "new" > $testroot/repo/gamma/new
874 (cd $testroot/repo && git add .)
875 git_commit $testroot/repo -m "adding a new file"
877 echo "also new" > $testroot/wt/gamma/new
878 (cd $testroot/wt && got add gamma/new >/dev/null)
880 (cd $testroot/wt && got update > $testroot/stdout)
882 echo "C gamma/new" > $testroot/stdout.expected
883 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
884 git_show_head $testroot/repo >> $testroot/stdout.expected
885 echo >> $testroot/stdout.expected
886 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
888 cmp -s $testroot/stdout.expected $testroot/stdout
889 ret=$?
890 if [ $ret -ne 0 ]; then
891 diff -u $testroot/stdout.expected $testroot/stdout
892 test_done "$testroot" "$ret"
893 return 1
894 fi
896 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
897 git_show_head $testroot/repo >> $testroot/content.expected
898 echo >> $testroot/content.expected
899 echo "new" >> $testroot/content.expected
900 echo "=======" >> $testroot/content.expected
901 echo "also new" >> $testroot/content.expected
902 echo '>>>>>>>' >> $testroot/content.expected
904 cat $testroot/wt/gamma/new > $testroot/content
906 cmp -s $testroot/content.expected $testroot/content
907 ret=$?
908 if [ $ret -ne 0 ]; then
909 diff -u $testroot/content.expected $testroot/content
910 test_done "$testroot" "$ret"
911 return 1
912 fi
914 # resolve the conflict
915 echo "new and also new" > $testroot/wt/gamma/new
916 echo 'M gamma/new' > $testroot/stdout.expected
917 (cd $testroot/wt && got status > $testroot/stdout)
918 cmp -s $testroot/stdout.expected $testroot/stdout
919 ret=$?
920 if [ $ret -ne 0 ]; then
921 diff -u $testroot/stdout.expected $testroot/stdout
922 fi
923 test_done "$testroot" "$ret"
926 test_update_conflict_wt_edit_vs_repo_rm() {
927 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
929 got checkout $testroot/repo $testroot/wt > /dev/null
930 ret=$?
931 if [ $ret -ne 0 ]; then
932 test_done "$testroot" "$ret"
933 return 1
934 fi
936 (cd $testroot/repo && git rm -q beta)
937 git_commit $testroot/repo -m "removing a file"
939 echo "modified beta" > $testroot/wt/beta
941 (cd $testroot/wt && got update > $testroot/stdout)
943 echo "G beta" > $testroot/stdout.expected
944 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
945 git_show_head $testroot/repo >> $testroot/stdout.expected
946 echo >> $testroot/stdout.expected
947 cmp -s $testroot/stdout.expected $testroot/stdout
948 ret=$?
949 if [ $ret -ne 0 ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
951 test_done "$testroot" "$ret"
952 return 1
953 fi
955 echo "modified beta" > $testroot/content.expected
957 cat $testroot/wt/beta > $testroot/content
959 cmp -s $testroot/content.expected $testroot/content
960 ret=$?
961 if [ $ret -ne 0 ]; then
962 diff -u $testroot/content.expected $testroot/content
963 test_done "$testroot" "$ret"
964 return 1
965 fi
967 # beta is now an added file... we don't flag tree conflicts yet
968 echo 'A beta' > $testroot/stdout.expected
969 (cd $testroot/wt && got status > $testroot/stdout)
970 cmp -s $testroot/stdout.expected $testroot/stdout
971 ret=$?
972 if [ $ret -ne 0 ]; then
973 diff -u $testroot/stdout.expected $testroot/stdout
974 fi
975 test_done "$testroot" "$ret"
978 test_update_conflict_wt_rm_vs_repo_edit() {
979 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
981 got checkout $testroot/repo $testroot/wt > /dev/null
982 ret=$?
983 if [ $ret -ne 0 ]; then
984 test_done "$testroot" "$ret"
985 return 1
986 fi
988 echo "modified beta" > $testroot/repo/beta
989 git_commit $testroot/repo -m "modified a file"
991 (cd $testroot/wt && got rm beta > /dev/null)
993 (cd $testroot/wt && got update > $testroot/stdout)
995 echo "G beta" > $testroot/stdout.expected
996 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
997 git_show_head $testroot/repo >> $testroot/stdout.expected
998 echo >> $testroot/stdout.expected
999 cmp -s $testroot/stdout.expected $testroot/stdout
1000 ret=$?
1001 if [ $ret -ne 0 ]; then
1002 diff -u $testroot/stdout.expected $testroot/stdout
1003 test_done "$testroot" "$ret"
1004 return 1
1007 # beta remains a deleted file... we don't flag tree conflicts yet
1008 echo 'D beta' > $testroot/stdout.expected
1009 (cd $testroot/wt && got status > $testroot/stdout)
1010 cmp -s $testroot/stdout.expected $testroot/stdout
1011 ret=$?
1012 if [ $ret -ne 0 ]; then
1013 diff -u $testroot/stdout.expected $testroot/stdout
1014 test_done "$testroot" "$ret"
1015 return 1
1018 # 'got diff' should show post-update contents of beta being deleted
1019 local head_rev=`git_show_head $testroot/repo`
1020 echo "diff $testroot/wt" > $testroot/stdout.expected
1021 echo "commit - $head_rev" >> $testroot/stdout.expected
1022 echo "path + $testroot/wt" >> $testroot/stdout.expected
1023 echo -n 'blob - ' >> $testroot/stdout.expected
1024 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1025 >> $testroot/stdout.expected
1026 echo 'file + /dev/null' >> $testroot/stdout.expected
1027 echo '--- beta' >> $testroot/stdout.expected
1028 echo '+++ /dev/null' >> $testroot/stdout.expected
1029 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1030 echo '-modified beta' >> $testroot/stdout.expected
1032 (cd $testroot/wt && got diff > $testroot/stdout)
1033 cmp -s $testroot/stdout.expected $testroot/stdout
1034 ret=$?
1035 if [ $ret -ne 0 ]; then
1036 diff -u $testroot/stdout.expected $testroot/stdout
1038 test_done "$testroot" "$ret"
1041 test_update_conflict_wt_rm_vs_repo_rm() {
1042 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1044 got checkout $testroot/repo $testroot/wt > /dev/null
1045 ret=$?
1046 if [ $ret -ne 0 ]; then
1047 test_done "$testroot" "$ret"
1048 return 1
1051 (cd $testroot/repo && git rm -q beta)
1052 git_commit $testroot/repo -m "removing a file"
1054 (cd $testroot/wt && got rm beta > /dev/null)
1056 (cd $testroot/wt && got update > $testroot/stdout)
1058 echo "D beta" > $testroot/stdout.expected
1059 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1060 git_show_head $testroot/repo >> $testroot/stdout.expected
1061 echo >> $testroot/stdout.expected
1062 cmp -s $testroot/stdout.expected $testroot/stdout
1063 ret=$?
1064 if [ $ret -ne 0 ]; then
1065 diff -u $testroot/stdout.expected $testroot/stdout
1066 test_done "$testroot" "$ret"
1067 return 1
1070 # beta is now gone... we don't flag tree conflicts yet
1071 echo "N beta" > $testroot/stdout.expected
1072 echo -n > $testroot/stderr.expected
1073 (cd $testroot/wt && got status beta > $testroot/stdout \
1074 2> $testroot/stderr)
1075 cmp -s $testroot/stdout.expected $testroot/stdout
1076 ret=$?
1077 if [ $ret -ne 0 ]; then
1078 diff -u $testroot/stdout.expected $testroot/stdout
1079 test_done "$testroot" "$ret"
1080 return 1
1082 cmp -s $testroot/stderr.expected $testroot/stderr
1083 ret=$?
1084 if [ $ret -ne 0 ]; then
1085 diff -u $testroot/stderr.expected $testroot/stderr
1086 test_done "$testroot" "$ret"
1087 return 1
1090 if [ -e $testroot/wt/beta ]; then
1091 echo "removed file beta still exists on disk" >&2
1092 test_done "$testroot" "1"
1093 return 1
1096 test_done "$testroot" "0"
1099 test_update_partial() {
1100 local testroot=`test_init update_partial`
1102 got checkout $testroot/repo $testroot/wt > /dev/null
1103 ret=$?
1104 if [ $ret -ne 0 ]; then
1105 test_done "$testroot" "$ret"
1106 return 1
1109 echo "modified alpha" > $testroot/repo/alpha
1110 echo "modified beta" > $testroot/repo/beta
1111 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1112 git_commit $testroot/repo -m "modified two files"
1114 echo "U alpha" > $testroot/stdout.expected
1115 echo "U beta" >> $testroot/stdout.expected
1116 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1117 git_show_head $testroot/repo >> $testroot/stdout.expected
1118 echo >> $testroot/stdout.expected
1120 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1122 cmp -s $testroot/stdout.expected $testroot/stdout
1123 ret=$?
1124 if [ $ret -ne 0 ]; then
1125 diff -u $testroot/stdout.expected $testroot/stdout
1126 test_done "$testroot" "$ret"
1127 return 1
1130 echo "modified alpha" > $testroot/content.expected
1131 echo "modified beta" >> $testroot/content.expected
1133 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1134 cmp -s $testroot/content.expected $testroot/content
1135 ret=$?
1136 if [ $ret -ne 0 ]; then
1137 diff -u $testroot/content.expected $testroot/content
1138 test_done "$testroot" "$ret"
1139 return 1
1142 echo "U epsilon/zeta" > $testroot/stdout.expected
1143 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1144 git_show_head $testroot/repo >> $testroot/stdout.expected
1145 echo >> $testroot/stdout.expected
1147 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1149 cmp -s $testroot/stdout.expected $testroot/stdout
1150 ret=$?
1151 if [ $ret -ne 0 ]; then
1152 diff -u $testroot/stdout.expected $testroot/stdout
1153 test_done "$testroot" "$ret"
1154 return 1
1157 echo "modified epsilon/zeta" > $testroot/content.expected
1158 cat $testroot/wt/epsilon/zeta > $testroot/content
1160 cmp -s $testroot/content.expected $testroot/content
1161 ret=$?
1162 if [ $ret -ne 0 ]; then
1163 diff -u $testroot/content.expected $testroot/content
1164 test_done "$testroot" "$ret"
1165 return 1
1168 test_done "$testroot" "$ret"
1171 test_update_partial_add() {
1172 local testroot=`test_init update_partial_add`
1174 got checkout $testroot/repo $testroot/wt > /dev/null
1175 ret=$?
1176 if [ $ret -ne 0 ]; then
1177 test_done "$testroot" "$ret"
1178 return 1
1181 echo "new" > $testroot/repo/new
1182 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1183 (cd $testroot/repo && git add .)
1184 git_commit $testroot/repo -m "added two files"
1186 echo "A epsilon/new2" > $testroot/stdout.expected
1187 echo "A new" >> $testroot/stdout.expected
1188 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1189 git_show_head $testroot/repo >> $testroot/stdout.expected
1190 echo >> $testroot/stdout.expected
1192 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1194 cmp -s $testroot/stdout.expected $testroot/stdout
1195 ret=$?
1196 if [ $ret -ne 0 ]; then
1197 diff -u $testroot/stdout.expected $testroot/stdout
1198 test_done "$testroot" "$ret"
1199 return 1
1202 echo "new" > $testroot/content.expected
1203 echo "epsilon/new2" >> $testroot/content.expected
1205 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1207 cmp -s $testroot/content.expected $testroot/content
1208 ret=$?
1209 if [ $ret -ne 0 ]; then
1210 diff -u $testroot/content.expected $testroot/content
1212 test_done "$testroot" "$ret"
1215 test_update_partial_rm() {
1216 local testroot=`test_init update_partial_rm`
1218 got checkout $testroot/repo $testroot/wt > /dev/null
1219 ret=$?
1220 if [ $ret -ne 0 ]; then
1221 test_done "$testroot" "$ret"
1222 return 1
1225 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1226 git_commit $testroot/repo -m "removed two files"
1228 echo "got: /alpha: no such entry found in tree" \
1229 > $testroot/stderr.expected
1231 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1232 ret=$?
1233 if [ $ret -eq 0 ]; then
1234 echo "update succeeded unexpectedly" >&2
1235 test_done "$testroot" "1"
1236 return 1
1239 cmp -s $testroot/stderr.expected $testroot/stderr
1240 ret=$?
1241 if [ $ret -ne 0 ]; then
1242 diff -u $testroot/stderr.expected $testroot/stderr
1243 test_done "$testroot" "$ret"
1244 return 1
1246 test_done "$testroot" "$ret"
1249 test_update_partial_dir() {
1250 local testroot=`test_init update_partial_dir`
1252 got checkout $testroot/repo $testroot/wt > /dev/null
1253 ret=$?
1254 if [ $ret -ne 0 ]; then
1255 test_done "$testroot" "$ret"
1256 return 1
1259 echo "modified alpha" > $testroot/repo/alpha
1260 echo "modified beta" > $testroot/repo/beta
1261 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1262 git_commit $testroot/repo -m "modified two files"
1264 echo "U epsilon/zeta" > $testroot/stdout.expected
1265 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1266 git_show_head $testroot/repo >> $testroot/stdout.expected
1267 echo >> $testroot/stdout.expected
1269 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1271 cmp -s $testroot/stdout.expected $testroot/stdout
1272 ret=$?
1273 if [ $ret -ne 0 ]; then
1274 diff -u $testroot/stdout.expected $testroot/stdout
1275 test_done "$testroot" "$ret"
1276 return 1
1279 echo "modified epsilon/zeta" > $testroot/content.expected
1280 cat $testroot/wt/epsilon/zeta > $testroot/content
1282 cmp -s $testroot/content.expected $testroot/content
1283 ret=$?
1284 if [ $ret -ne 0 ]; then
1285 diff -u $testroot/content.expected $testroot/content
1286 test_done "$testroot" "$ret"
1287 return 1
1289 test_done "$testroot" "$ret"
1293 test_update_moved_branch_ref() {
1294 local testroot=`test_init update_moved_branch_ref`
1296 git clone -q --mirror $testroot/repo $testroot/repo2
1298 echo "modified alpha with git" > $testroot/repo/alpha
1299 git_commit $testroot/repo -m "modified alpha with git"
1301 got checkout $testroot/repo2 $testroot/wt > /dev/null
1302 ret=$?
1303 if [ $ret -ne 0 ]; then
1304 test_done "$testroot" "$ret"
1305 return 1
1308 echo "modified alpha with got" > $testroot/wt/alpha
1309 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1311 # + xxxxxxx...yyyyyyy master -> master (forced update)
1312 (cd $testroot/repo2 && git fetch -q --all)
1314 echo -n > $testroot/stdout.expected
1315 echo -n "got: work tree's head reference now points to a different " \
1316 > $testroot/stderr.expected
1317 echo "branch; new head reference and/or update -b required" \
1318 >> $testroot/stderr.expected
1320 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1322 cmp -s $testroot/stdout.expected $testroot/stdout
1323 ret=$?
1324 if [ $ret -ne 0 ]; then
1325 diff -u $testroot/stdout.expected $testroot/stdout
1326 test_done "$testroot" "$ret"
1327 return 1
1330 cmp -s $testroot/stderr.expected $testroot/stderr
1331 ret=$?
1332 if [ $ret -ne 0 ]; then
1333 diff -u $testroot/stderr.expected $testroot/stderr
1335 test_done "$testroot" "$ret"
1338 test_update_to_another_branch() {
1339 local testroot=`test_init update_to_another_branch`
1340 local base_commit=`git_show_head $testroot/repo`
1342 got checkout $testroot/repo $testroot/wt > /dev/null
1343 ret=$?
1344 if [ $ret -ne 0 ]; then
1345 test_done "$testroot" "$ret"
1346 return 1
1349 echo 'refs/heads/master'> $testroot/head-ref.expected
1350 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1351 ret=$?
1352 if [ $ret -ne 0 ]; then
1353 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1354 test_done "$testroot" "$ret"
1355 return 1
1358 (cd $testroot/repo && git checkout -q -b newbranch)
1359 echo "modified alpha on new branch" > $testroot/repo/alpha
1360 git_commit $testroot/repo -m "modified alpha on new branch"
1362 echo "modified alpha in work tree" > $testroot/wt/alpha
1364 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1365 echo "C alpha" >> $testroot/stdout.expected
1366 echo -n "Updated to refs/heads/newbranch: " >> $testroot/stdout.expected
1367 git_show_head $testroot/repo >> $testroot/stdout.expected
1368 echo >> $testroot/stdout.expected
1369 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1371 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1373 cmp -s $testroot/stdout.expected $testroot/stdout
1374 ret=$?
1375 if [ $ret -ne 0 ]; then
1376 diff -u $testroot/stdout.expected $testroot/stdout
1377 test_done "$testroot" "$ret"
1378 return 1
1381 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
1382 git_show_head $testroot/repo >> $testroot/content.expected
1383 echo >> $testroot/content.expected
1384 echo "modified alpha on new branch" >> $testroot/content.expected
1385 echo "||||||| 3-way merge base: commit $base_commit" \
1386 >> $testroot/content.expected
1387 echo "alpha" >> $testroot/content.expected
1388 echo "=======" >> $testroot/content.expected
1389 echo "modified alpha in work tree" >> $testroot/content.expected
1390 echo '>>>>>>>' >> $testroot/content.expected
1392 cat $testroot/wt/alpha > $testroot/content
1394 cmp -s $testroot/content.expected $testroot/content
1395 ret=$?
1396 if [ $ret -ne 0 ]; then
1397 diff -u $testroot/content.expected $testroot/content
1398 test_done "$testroot" "$ret"
1399 return 1
1402 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1403 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1404 ret=$?
1405 if [ $ret -ne 0 ]; then
1406 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1407 test_done "$testroot" "$ret"
1408 return 1
1411 test_done "$testroot" "$ret"
1414 test_update_to_commit_on_wrong_branch() {
1415 local testroot=`test_init update_to_commit_on_wrong_branch`
1417 got checkout $testroot/repo $testroot/wt > /dev/null
1418 ret=$?
1419 if [ $ret -ne 0 ]; then
1420 test_done "$testroot" "$ret"
1421 return 1
1424 (cd $testroot/repo && git checkout -q -b newbranch)
1425 echo "modified alpha on new branch" > $testroot/repo/alpha
1426 git_commit $testroot/repo -m "modified alpha on new branch"
1428 echo -n "" > $testroot/stdout.expected
1429 echo "got: target commit is on a different branch" \
1430 > $testroot/stderr.expected
1432 local head_rev=`git_show_head $testroot/repo`
1433 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1434 2> $testroot/stderr)
1436 cmp -s $testroot/stdout.expected $testroot/stdout
1437 ret=$?
1438 if [ $ret -ne 0 ]; then
1439 diff -u $testroot/stdout.expected $testroot/stdout
1440 test_done "$testroot" "$ret"
1441 return 1
1444 cmp -s $testroot/stderr.expected $testroot/stderr
1445 ret=$?
1446 if [ $ret -ne 0 ]; then
1447 diff -u $testroot/stderr.expected $testroot/stderr
1448 test_done "$testroot" "$ret"
1449 return 1
1452 test_done "$testroot" "$ret"
1455 test_update_bumps_base_commit_id() {
1456 local testroot=`test_init update_bumps_base_commit_id`
1458 echo "psi" > $testroot/repo/epsilon/psi
1459 (cd $testroot/repo && git add .)
1460 git_commit $testroot/repo -m "adding another file"
1462 got checkout $testroot/repo $testroot/wt > /dev/null
1463 ret=$?
1464 if [ $ret -ne 0 ]; then
1465 test_done "$testroot" "$ret"
1466 return 1
1469 echo "modified psi" > $testroot/wt/epsilon/psi
1470 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1472 local head_rev=`git_show_head $testroot/repo`
1473 echo "M epsilon/psi" > $testroot/stdout.expected
1474 echo "Created commit $head_rev" >> $testroot/stdout.expected
1475 cmp -s $testroot/stdout.expected $testroot/stdout
1476 ret=$?
1477 if [ $ret -ne 0 ]; then
1478 diff -u $testroot/stdout.expected $testroot/stdout
1479 test_done "$testroot" "$ret"
1480 return 1
1483 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1484 (cd $testroot/repo && git add .)
1485 git_commit $testroot/repo -m "changing zeta with git"
1487 echo "modified zeta" > $testroot/wt/epsilon/zeta
1488 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1489 2> $testroot/stderr)
1491 echo -n "" > $testroot/stdout.expected
1492 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1493 cmp -s $testroot/stderr.expected $testroot/stderr
1494 ret=$?
1495 if [ $ret -ne 0 ]; then
1496 diff -u $testroot/stderr.expected $testroot/stderr
1497 test_done "$testroot" "$ret"
1498 return 1
1501 (cd $testroot/wt && got update > $testroot/stdout)
1503 echo "U epsilon/psi" > $testroot/stdout.expected
1504 echo "C epsilon/zeta" >> $testroot/stdout.expected
1505 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1506 git_show_head $testroot/repo >> $testroot/stdout.expected
1507 echo >> $testroot/stdout.expected
1508 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1510 cmp -s $testroot/stdout.expected $testroot/stdout
1511 ret=$?
1512 if [ $ret -ne 0 ]; then
1513 diff -u $testroot/stdout.expected $testroot/stdout
1514 test_done "$testroot" "$ret"
1515 return 1
1518 # resolve conflict
1519 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1521 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1523 local head_rev=`git_show_head $testroot/repo`
1524 echo "M epsilon/zeta" > $testroot/stdout.expected
1525 echo "Created commit $head_rev" >> $testroot/stdout.expected
1526 cmp -s $testroot/stdout.expected $testroot/stdout
1527 ret=$?
1528 if [ $ret -ne 0 ]; then
1529 diff -u $testroot/stdout.expected $testroot/stdout
1530 test_done "$testroot" "$ret"
1531 return 1
1534 test_done "$testroot" "$ret"
1537 test_update_tag() {
1538 local testroot=`test_init update_tag`
1539 local tag="1.0.0"
1541 got checkout $testroot/repo $testroot/wt > /dev/null
1542 ret=$?
1543 if [ $ret -ne 0 ]; then
1544 test_done "$testroot" "$ret"
1545 return 1
1548 echo "modified alpha" > $testroot/repo/alpha
1549 git_commit $testroot/repo -m "modified alpha"
1550 (cd $testroot/repo && git tag -m "test" -a $tag)
1552 echo "U alpha" > $testroot/stdout.expected
1553 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1554 git_show_head $testroot/repo >> $testroot/stdout.expected
1555 echo >> $testroot/stdout.expected
1557 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1559 cmp -s $testroot/stdout.expected $testroot/stdout
1560 ret=$?
1561 if [ $ret -ne 0 ]; then
1562 diff -u $testroot/stdout.expected $testroot/stdout
1563 test_done "$testroot" "$ret"
1564 return 1
1567 echo "modified alpha" > $testroot/content.expected
1568 cat $testroot/wt/alpha > $testroot/content
1570 cmp -s $testroot/content.expected $testroot/content
1571 ret=$?
1572 if [ $ret -ne 0 ]; then
1573 diff -u $testroot/content.expected $testroot/content
1575 test_done "$testroot" "$ret"
1578 test_update_toggles_xbit() {
1579 local testroot=`test_init update_toggles_xbit 1`
1581 touch $testroot/repo/xfile
1582 chmod +x $testroot/repo/xfile
1583 (cd $testroot/repo && git add .)
1584 git_commit $testroot/repo -m "adding executable file"
1585 local commit_id1=`git_show_head $testroot/repo`
1587 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1588 ret=$?
1589 if [ $ret -ne 0 ]; then
1590 test_done "$testroot" "$ret"
1591 return 1
1594 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1595 ret=$?
1596 if [ $ret -ne 0 ]; then
1597 echo "file is not executable" >&2
1598 ls -l $testroot/wt/xfile >&2
1599 test_done "$testroot" "$ret"
1600 return 1
1603 chmod -x $testroot/wt/xfile
1604 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1605 local commit_id2=`git_show_head $testroot/repo`
1607 echo "U xfile" > $testroot/stdout.expected
1608 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1609 git_show_head $testroot/repo >> $testroot/stdout.expected
1610 echo >> $testroot/stdout.expected
1612 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1613 ret=$?
1614 if [ $ret -ne 0 ]; then
1615 test_done "$testroot" "$ret"
1616 return 1
1619 echo "U xfile" > $testroot/stdout.expected
1620 echo "Updated to refs/heads/master: $commit_id1" >> $testroot/stdout.expected
1621 cmp -s $testroot/stdout.expected $testroot/stdout
1622 ret=$?
1623 if [ $ret -ne 0 ]; then
1624 diff -u $testroot/stdout.expected $testroot/stdout
1625 test_done "$testroot" "$ret"
1626 return 1
1630 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1631 ret=$?
1632 if [ $ret -ne 0 ]; then
1633 echo "file is not executable" >&2
1634 ls -l $testroot/wt/xfile >&2
1635 test_done "$testroot" "$ret"
1636 return 1
1639 (cd $testroot/wt && got update > $testroot/stdout)
1640 ret=$?
1641 if [ $ret -ne 0 ]; then
1642 test_done "$testroot" "$ret"
1643 return 1
1646 echo "U xfile" > $testroot/stdout.expected
1647 echo "Updated to refs/heads/master: $commit_id2" \
1648 >> $testroot/stdout.expected
1649 cmp -s $testroot/stdout.expected $testroot/stdout
1650 ret=$?
1651 if [ $ret -ne 0 ]; then
1652 diff -u $testroot/stdout.expected $testroot/stdout
1653 test_done "$testroot" "$ret"
1654 return 1
1657 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1658 ret=$?
1659 if [ $ret -ne 0 ]; then
1660 echo "file is unexpectedly executable" >&2
1661 ls -l $testroot/wt/xfile >&2
1663 test_done "$testroot" "$ret"
1666 test_update_preserves_conflicted_file() {
1667 local testroot=`test_init update_preserves_conflicted_file`
1668 local commit_id0=`git_show_head $testroot/repo`
1670 echo "modified alpha" > $testroot/repo/alpha
1671 git_commit $testroot/repo -m "modified alpha"
1672 local commit_id1=`git_show_head $testroot/repo`
1674 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
1675 ret=$?
1676 if [ $ret -ne 0 ]; then
1677 test_done "$testroot" "$ret"
1678 return 1
1681 # fake a merge conflict
1682 echo '<<<<<<<' > $testroot/wt/alpha
1683 echo 'alpha' >> $testroot/wt/alpha
1684 echo '=======' >> $testroot/wt/alpha
1685 echo 'alpha, too' >> $testroot/wt/alpha
1686 echo '>>>>>>>' >> $testroot/wt/alpha
1687 cp $testroot/wt/alpha $testroot/content.expected
1689 echo "C alpha" > $testroot/stdout.expected
1690 (cd $testroot/wt && got status > $testroot/stdout)
1691 cmp -s $testroot/stdout.expected $testroot/stdout
1692 ret=$?
1693 if [ $ret -ne 0 ]; then
1694 diff -u $testroot/stdout.expected $testroot/stdout
1695 test_done "$testroot" "$ret"
1696 return 1
1699 echo "# alpha" > $testroot/stdout.expected
1700 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1701 git_show_head $testroot/repo >> $testroot/stdout.expected
1702 echo >> $testroot/stdout.expected
1703 echo "Files not updated because of existing merge conflicts: 1" \
1704 >> $testroot/stdout.expected
1705 (cd $testroot/wt && got update > $testroot/stdout)
1707 cmp -s $testroot/stdout.expected $testroot/stdout
1708 ret=$?
1709 if [ $ret -ne 0 ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1711 test_done "$testroot" "$ret"
1712 return 1
1715 cmp -s $testroot/content.expected $testroot/wt/alpha
1716 ret=$?
1717 if [ $ret -ne 0 ]; then
1718 diff -u $testroot/content.expected $testroot/wt/alpha
1720 test_done "$testroot" "$ret"
1723 test_update_modified_submodules() {
1724 local testroot=`test_init update_modified_submodules`
1726 make_single_file_repo $testroot/repo2 foo
1728 (cd $testroot/repo && git -c protocol.file.allow=always \
1729 submodule -q add ../repo2)
1730 (cd $testroot/repo && git commit -q -m 'adding submodule')
1732 got checkout $testroot/repo $testroot/wt > /dev/null
1734 echo "modified foo" > $testroot/repo2/foo
1735 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1737 # Update the repo/repo2 submodule link
1738 (cd $testroot/repo && git -C repo2 pull -q)
1739 (cd $testroot/repo && git add repo2)
1740 git_commit $testroot/repo -m "modified submodule link"
1742 # This update only records the new base commit. Otherwise it is a
1743 # no-op change because Got's file index does not track submodules.
1744 echo -n "Updated to refs/heads/master: " > $testroot/stdout.expected
1745 git_show_head $testroot/repo >> $testroot/stdout.expected
1746 echo >> $testroot/stdout.expected
1748 (cd $testroot/wt && got update > $testroot/stdout)
1750 cmp -s $testroot/stdout.expected $testroot/stdout
1751 ret=$?
1752 if [ $ret -ne 0 ]; then
1753 diff -u $testroot/stdout.expected $testroot/stdout
1755 test_done "$testroot" "$ret"
1758 test_update_adds_submodule() {
1759 local testroot=`test_init update_adds_submodule`
1761 got checkout $testroot/repo $testroot/wt > /dev/null
1763 make_single_file_repo $testroot/repo2 foo
1765 echo "modified foo" > $testroot/repo2/foo
1766 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1768 (cd $testroot/repo && git -c protocol.file.allow=always \
1769 submodule -q add ../repo2)
1770 (cd $testroot/repo && git commit -q -m 'adding submodule')
1772 echo "A .gitmodules" > $testroot/stdout.expected
1773 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1774 git_show_head $testroot/repo >> $testroot/stdout.expected
1775 echo >> $testroot/stdout.expected
1777 (cd $testroot/wt && got update > $testroot/stdout)
1779 cmp -s $testroot/stdout.expected $testroot/stdout
1780 ret=$?
1781 if [ $ret -ne 0 ]; then
1782 diff -u $testroot/stdout.expected $testroot/stdout
1784 test_done "$testroot" "$ret"
1787 test_update_conflict_wt_file_vs_repo_submodule() {
1788 local testroot=`test_init update_conflict_wt_file_vs_repo_submodule`
1790 got checkout $testroot/repo $testroot/wt > /dev/null
1792 make_single_file_repo $testroot/repo2 foo
1794 # Add a file which will clash with the submodule
1795 echo "This is a file called repo2" > $testroot/wt/repo2
1796 (cd $testroot/wt && got add repo2 > /dev/null)
1797 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
1798 ret=$?
1799 if [ $ret -ne 0 ]; then
1800 echo "commit failed unexpectedly" >&2
1801 test_done "$testroot" "1"
1802 return 1
1805 (cd $testroot/repo && git -c protocol.file.allow=always \
1806 submodule -q add ../repo2)
1807 (cd $testroot/repo && git commit -q -m 'adding submodule')
1809 # Modify the clashing file such that any modifications brought
1810 # in by 'got update' would require a merge.
1811 echo "This file was changed" > $testroot/wt/repo2
1813 # No conflict occurs because 'got update' ignores the submodule
1814 # and leaves the clashing file as it was.
1815 echo "A .gitmodules" > $testroot/stdout.expected
1816 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1817 git_show_head $testroot/repo >> $testroot/stdout.expected
1818 echo >> $testroot/stdout.expected
1820 (cd $testroot/wt && got update > $testroot/stdout)
1822 cmp -s $testroot/stdout.expected $testroot/stdout
1823 ret=$?
1824 if [ $ret -ne 0 ]; then
1825 diff -u $testroot/stdout.expected $testroot/stdout
1826 test_done "$testroot" "$ret"
1827 return 1
1830 (cd $testroot/wt && got status > $testroot/stdout)
1832 echo "M repo2" > $testroot/stdout.expected
1833 cmp -s $testroot/stdout.expected $testroot/stdout
1834 ret=$?
1835 if [ $ret -ne 0 ]; then
1836 diff -u $testroot/stdout.expected $testroot/stdout
1838 test_done "$testroot" "$ret"
1841 test_update_adds_symlink() {
1842 local testroot=`test_init update_adds_symlink`
1844 got checkout $testroot/repo $testroot/wt > /dev/null
1845 ret=$?
1846 if [ $ret -ne 0 ]; then
1847 echo "checkout failed unexpectedly" >&2
1848 test_done "$testroot" "$ret"
1849 return 1
1852 (cd $testroot/repo && ln -s alpha alpha.link)
1853 (cd $testroot/repo && ln -s epsilon epsilon.link)
1854 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1855 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1856 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1857 (cd $testroot/repo && git add .)
1858 git_commit $testroot/repo -m "add symlinks"
1860 echo "A alpha.link" > $testroot/stdout.expected
1861 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1862 echo "A epsilon.link" >> $testroot/stdout.expected
1863 echo "A nonexistent.link" >> $testroot/stdout.expected
1864 echo "A passwd.link" >> $testroot/stdout.expected
1865 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1866 git_show_head $testroot/repo >> $testroot/stdout.expected
1867 echo >> $testroot/stdout.expected
1869 (cd $testroot/wt && got update > $testroot/stdout)
1871 cmp -s $testroot/stdout.expected $testroot/stdout
1872 ret=$?
1873 if [ $ret -ne 0 ]; then
1874 diff -u $testroot/stdout.expected $testroot/stdout
1875 test_done "$testroot" "$ret"
1876 return 1
1879 if ! [ -h $testroot/wt/alpha.link ]; then
1880 echo "alpha.link is not a symlink"
1881 test_done "$testroot" "1"
1882 return 1
1885 readlink $testroot/wt/alpha.link > $testroot/stdout
1886 echo "alpha" > $testroot/stdout.expected
1887 cmp -s $testroot/stdout.expected $testroot/stdout
1888 ret=$?
1889 if [ $ret -ne 0 ]; then
1890 diff -u $testroot/stdout.expected $testroot/stdout
1891 test_done "$testroot" "$ret"
1892 return 1
1895 if ! [ -h $testroot/wt/epsilon.link ]; then
1896 echo "epsilon.link is not a symlink"
1897 test_done "$testroot" "1"
1898 return 1
1901 readlink $testroot/wt/epsilon.link > $testroot/stdout
1902 echo "epsilon" > $testroot/stdout.expected
1903 cmp -s $testroot/stdout.expected $testroot/stdout
1904 ret=$?
1905 if [ $ret -ne 0 ]; then
1906 diff -u $testroot/stdout.expected $testroot/stdout
1907 test_done "$testroot" "$ret"
1908 return 1
1911 if [ -h $testroot/wt/passwd.link ]; then
1912 echo -n "passwd.link symlink points outside of work tree: " >&2
1913 readlink $testroot/wt/passwd.link >&2
1914 test_done "$testroot" "1"
1915 return 1
1918 echo -n "/etc/passwd" > $testroot/content.expected
1919 cp $testroot/wt/passwd.link $testroot/content
1921 cmp -s $testroot/content.expected $testroot/content
1922 ret=$?
1923 if [ $ret -ne 0 ]; then
1924 diff -u $testroot/content.expected $testroot/content
1925 test_done "$testroot" "$ret"
1926 return 1
1929 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1930 echo "../beta" > $testroot/stdout.expected
1931 cmp -s $testroot/stdout.expected $testroot/stdout
1932 ret=$?
1933 if [ $ret -ne 0 ]; then
1934 diff -u $testroot/stdout.expected $testroot/stdout
1935 test_done "$testroot" "$ret"
1936 return 1
1939 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1940 echo "nonexistent" > $testroot/stdout.expected
1941 cmp -s $testroot/stdout.expected $testroot/stdout
1942 ret=$?
1943 if [ $ret -ne 0 ]; then
1944 diff -u $testroot/stdout.expected $testroot/stdout
1945 test_done "$testroot" "$ret"
1946 return 1
1949 # Updating an up-to-date symlink should be a no-op.
1950 echo 'Already up-to-date' > $testroot/stdout.expected
1951 (cd $testroot/wt && got update > $testroot/stdout)
1952 cmp -s $testroot/stdout.expected $testroot/stdout
1953 ret=$?
1954 if [ $ret -ne 0 ]; then
1955 diff -u $testroot/stdout.expected $testroot/stdout
1957 test_done "$testroot" "$ret"
1960 test_update_deletes_symlink() {
1961 local testroot=`test_init update_deletes_symlink`
1963 (cd $testroot/repo && ln -s alpha alpha.link)
1964 (cd $testroot/repo && git add .)
1965 git_commit $testroot/repo -m "add symlink"
1967 got checkout $testroot/repo $testroot/wt > /dev/null
1968 ret=$?
1969 if [ $ret -ne 0 ]; then
1970 echo "checkout failed unexpectedly" >&2
1971 test_done "$testroot" "$ret"
1972 return 1
1975 (cd $testroot/repo && git rm -q alpha.link)
1976 git_commit $testroot/repo -m "delete symlink"
1978 echo "D alpha.link" > $testroot/stdout.expected
1979 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1980 git_show_head $testroot/repo >> $testroot/stdout.expected
1981 echo >> $testroot/stdout.expected
1983 (cd $testroot/wt && got update > $testroot/stdout)
1985 cmp -s $testroot/stdout.expected $testroot/stdout
1986 ret=$?
1987 if [ $ret -ne 0 ]; then
1988 diff -u $testroot/stdout.expected $testroot/stdout
1989 test_done "$testroot" "$ret"
1990 return 1
1993 if [ -e $testroot/wt/alpha.link ]; then
1994 echo "alpha.link still exists on disk"
1995 test_done "$testroot" "1"
1996 return 1
1999 test_done "$testroot" "0"
2002 test_update_symlink_conflicts() {
2003 local testroot=`test_init update_symlink_conflicts`
2005 (cd $testroot/repo && ln -s alpha alpha.link)
2006 (cd $testroot/repo && ln -s epsilon epsilon.link)
2007 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2008 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2009 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2010 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
2011 (cd $testroot/repo && git add .)
2012 git_commit $testroot/repo -m "add symlinks"
2013 local commit_id1=`git_show_head $testroot/repo`
2015 got checkout $testroot/repo $testroot/wt > /dev/null
2016 ret=$?
2017 if [ $ret -ne 0 ]; then
2018 echo "checkout failed unexpectedly" >&2
2019 test_done "$testroot" "$ret"
2020 return 1
2023 (cd $testroot/repo && ln -sf beta alpha.link)
2024 (cd $testroot/repo && ln -sfh gamma epsilon.link)
2025 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
2026 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
2027 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
2028 (cd $testroot/repo && git rm -q nonexistent.link)
2029 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
2030 (cd $testroot/repo && ln -sf alpha new.link)
2031 (cd $testroot/repo && git add .)
2032 git_commit $testroot/repo -m "change symlinks"
2033 local commit_id2=`git_show_head $testroot/repo`
2035 # modified symlink to file A vs modified symlink to file B
2036 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
2037 # modified symlink to dir A vs modified symlink to file B
2038 (cd $testroot/wt && ln -sfh beta epsilon.link)
2039 # modeified symlink to file A vs modified symlink to dir B
2040 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
2041 # added regular file A vs added bad symlink to file A
2042 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
2043 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2044 # added bad symlink to file A vs added regular file A
2045 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
2046 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2047 # removed symlink to non-existent file A vs modified symlink
2048 # to nonexistent file B
2049 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
2050 # modified symlink to file A vs removed symlink to file A
2051 (cd $testroot/wt && got rm zeta.link > /dev/null)
2052 # added symlink to file A vs added symlink to file B
2053 (cd $testroot/wt && ln -sf beta new.link)
2054 (cd $testroot/wt && got add new.link > /dev/null)
2056 (cd $testroot/wt && got update > $testroot/stdout)
2058 echo "C alpha.link" >> $testroot/stdout.expected
2059 echo "C dotgotbar.link" >> $testroot/stdout.expected
2060 echo "C dotgotfoo.link" >> $testroot/stdout.expected
2061 echo "C epsilon/beta.link" >> $testroot/stdout.expected
2062 echo "C epsilon.link" >> $testroot/stdout.expected
2063 echo "C new.link" >> $testroot/stdout.expected
2064 echo "C nonexistent.link" >> $testroot/stdout.expected
2065 echo "G zeta.link" >> $testroot/stdout.expected
2066 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2067 git_show_head $testroot/repo >> $testroot/stdout.expected
2068 echo >> $testroot/stdout.expected
2069 echo "Files with new merge conflicts: 7" >> $testroot/stdout.expected
2071 cmp -s $testroot/stdout.expected $testroot/stdout
2072 ret=$?
2073 if [ $ret -ne 0 ]; then
2074 diff -u $testroot/stdout.expected $testroot/stdout
2075 test_done "$testroot" "$ret"
2076 return 1
2079 if [ -h $testroot/wt/alpha.link ]; then
2080 echo "alpha.link is a symlink"
2081 test_done "$testroot" "1"
2082 return 1
2085 echo "<<<<<<< merged change: commit $commit_id2" \
2086 > $testroot/content.expected
2087 echo "beta" >> $testroot/content.expected
2088 echo "3-way merge base: commit $commit_id1" \
2089 >> $testroot/content.expected
2090 echo "alpha" >> $testroot/content.expected
2091 echo "=======" >> $testroot/content.expected
2092 echo "gamma/delta" >> $testroot/content.expected
2093 echo '>>>>>>>' >> $testroot/content.expected
2094 echo -n "" >> $testroot/content.expected
2096 cp $testroot/wt/alpha.link $testroot/content
2097 cmp -s $testroot/content.expected $testroot/content
2098 ret=$?
2099 if [ $ret -ne 0 ]; then
2100 diff -u $testroot/content.expected $testroot/content
2101 test_done "$testroot" "$ret"
2102 return 1
2105 if [ -h $testroot/wt/epsilon.link ]; then
2106 echo "epsilon.link is a symlink"
2107 test_done "$testroot" "1"
2108 return 1
2111 echo "<<<<<<< merged change: commit $commit_id2" \
2112 > $testroot/content.expected
2113 echo "gamma" >> $testroot/content.expected
2114 echo "3-way merge base: commit $commit_id1" \
2115 >> $testroot/content.expected
2116 echo "epsilon" >> $testroot/content.expected
2117 echo "=======" >> $testroot/content.expected
2118 echo "beta" >> $testroot/content.expected
2119 echo '>>>>>>>' >> $testroot/content.expected
2120 echo -n "" >> $testroot/content.expected
2122 cp $testroot/wt/epsilon.link $testroot/content
2123 cmp -s $testroot/content.expected $testroot/content
2124 ret=$?
2125 if [ $ret -ne 0 ]; then
2126 diff -u $testroot/content.expected $testroot/content
2127 test_done "$testroot" "$ret"
2128 return 1
2131 if [ -h $testroot/wt/passwd.link ]; then
2132 echo -n "passwd.link symlink points outside of work tree: " >&2
2133 readlink $testroot/wt/passwd.link >&2
2134 test_done "$testroot" "1"
2135 return 1
2138 echo -n "/etc/passwd" > $testroot/content.expected
2139 cp $testroot/wt/passwd.link $testroot/content
2141 cmp -s $testroot/content.expected $testroot/content
2142 ret=$?
2143 if [ $ret -ne 0 ]; then
2144 diff -u $testroot/content.expected $testroot/content
2145 test_done "$testroot" "$ret"
2146 return 1
2149 if [ -h $testroot/wt/epsilon/beta.link ]; then
2150 echo "epsilon/beta.link is a symlink"
2151 test_done "$testroot" "1"
2152 return 1
2155 echo "<<<<<<< merged change: commit $commit_id2" \
2156 > $testroot/content.expected
2157 echo "../gamma/delta" >> $testroot/content.expected
2158 echo "3-way merge base: commit $commit_id1" \
2159 >> $testroot/content.expected
2160 echo "../beta" >> $testroot/content.expected
2161 echo "=======" >> $testroot/content.expected
2162 echo "../gamma" >> $testroot/content.expected
2163 echo '>>>>>>>' >> $testroot/content.expected
2164 echo -n "" >> $testroot/content.expected
2166 cp $testroot/wt/epsilon/beta.link $testroot/content
2167 cmp -s $testroot/content.expected $testroot/content
2168 ret=$?
2169 if [ $ret -ne 0 ]; then
2170 diff -u $testroot/content.expected $testroot/content
2171 test_done "$testroot" "$ret"
2172 return 1
2175 if [ -h $testroot/wt/nonexistent.link ]; then
2176 echo -n "nonexistent.link still exists on disk: " >&2
2177 readlink $testroot/wt/nonexistent.link >&2
2178 test_done "$testroot" "1"
2179 return 1
2182 echo "<<<<<<< merged change: commit $commit_id2" \
2183 > $testroot/content.expected
2184 echo "(symlink was deleted)" >> $testroot/content.expected
2185 echo "=======" >> $testroot/content.expected
2186 echo "nonexistent2" >> $testroot/content.expected
2187 echo '>>>>>>>' >> $testroot/content.expected
2188 echo -n "" >> $testroot/content.expected
2190 cp $testroot/wt/nonexistent.link $testroot/content
2191 cmp -s $testroot/content.expected $testroot/content
2192 ret=$?
2193 if [ $ret -ne 0 ]; then
2194 diff -u $testroot/content.expected $testroot/content
2195 test_done "$testroot" "$ret"
2196 return 1
2199 if [ -h $testroot/wt/dotgotfoo.link ]; then
2200 echo "dotgotfoo.link is a symlink"
2201 test_done "$testroot" "1"
2202 return 1
2205 echo "<<<<<<< merged change: commit $commit_id2" \
2206 > $testroot/content.expected
2207 echo "this is regular file foo" >> $testroot/content.expected
2208 echo "=======" >> $testroot/content.expected
2209 echo -n ".got/bar" >> $testroot/content.expected
2210 echo '>>>>>>>' >> $testroot/content.expected
2211 echo -n "" >> $testroot/content.expected
2213 cp $testroot/wt/dotgotfoo.link $testroot/content
2214 cmp -s $testroot/content.expected $testroot/content
2215 ret=$?
2216 if [ $ret -ne 0 ]; then
2217 diff -u $testroot/content.expected $testroot/content
2218 test_done "$testroot" "$ret"
2219 return 1
2222 if [ -h $testroot/wt/dotgotbar.link ]; then
2223 echo "dotgotbar.link is a symlink"
2224 test_done "$testroot" "1"
2225 return 1
2227 echo "<<<<<<< merged change: commit $commit_id2" \
2228 > $testroot/content.expected
2229 echo -n ".got/bar" >> $testroot/content.expected
2230 echo "=======" >> $testroot/content.expected
2231 echo "this is regular file bar" >> $testroot/content.expected
2232 echo '>>>>>>>' >> $testroot/content.expected
2233 echo -n "" >> $testroot/content.expected
2235 cp $testroot/wt/dotgotbar.link $testroot/content
2236 cmp -s $testroot/content.expected $testroot/content
2237 ret=$?
2238 if [ $ret -ne 0 ]; then
2239 diff -u $testroot/content.expected $testroot/content
2240 test_done "$testroot" "$ret"
2241 return 1
2244 if [ -h $testroot/wt/new.link ]; then
2245 echo "new.link is a symlink"
2246 test_done "$testroot" "1"
2247 return 1
2250 echo "<<<<<<< merged change: commit $commit_id2" \
2251 > $testroot/content.expected
2252 echo "alpha" >> $testroot/content.expected
2253 echo "=======" >> $testroot/content.expected
2254 echo "beta" >> $testroot/content.expected
2255 echo '>>>>>>>' >> $testroot/content.expected
2256 echo -n "" >> $testroot/content.expected
2258 cp $testroot/wt/new.link $testroot/content
2259 cmp -s $testroot/content.expected $testroot/content
2260 ret=$?
2261 if [ $ret -ne 0 ]; then
2262 diff -u $testroot/content.expected $testroot/content
2263 test_done "$testroot" "$ret"
2264 return 1
2267 echo "A dotgotfoo.link" > $testroot/stdout.expected
2268 echo "M new.link" >> $testroot/stdout.expected
2269 echo "D nonexistent.link" >> $testroot/stdout.expected
2270 (cd $testroot/wt && got status > $testroot/stdout)
2271 ret=$?
2272 if [ $ret -ne 0 ]; then
2273 diff -u $testroot/stdout.expected $testroot/stdout
2274 test_done "$testroot" "$ret"
2275 return 1
2278 test_done "$testroot" "0"
2282 test_update_single_file() {
2283 local testroot=`test_init update_single_file 1`
2285 echo c1 > $testroot/repo/c
2286 (cd $testroot/repo && git add .)
2287 git_commit $testroot/repo -m "adding file c"
2288 local commit_id1=`git_show_head $testroot/repo`
2290 echo a > $testroot/repo/a
2291 echo b > $testroot/repo/b
2292 echo c2 > $testroot/repo/c
2293 (cd $testroot/repo && git add .)
2294 git_commit $testroot/repo -m "add files a and b, change c"
2295 local commit_id2=`git_show_head $testroot/repo`
2297 (cd $testroot/repo && git rm -qf c)
2298 git_commit $testroot/repo -m "remove file c"
2299 local commit_id3=`git_show_head $testroot/repo`
2301 got checkout -c $commit_id2 $testroot/repo $testroot/wt > /dev/null
2302 ret=$?
2303 if [ $ret -ne 0 ]; then
2304 test_done "$testroot" "$ret"
2305 return 1
2308 echo "U c" > $testroot/stdout.expected
2309 echo "Updated to refs/heads/master: $commit_id1" \
2310 >> $testroot/stdout.expected
2312 (cd $testroot/wt && got update -c $commit_id1 c \
2313 > $testroot/stdout)
2315 cmp -s $testroot/stdout.expected $testroot/stdout
2316 ret=$?
2317 if [ $ret -ne 0 ]; then
2318 diff -u $testroot/stdout.expected $testroot/stdout
2319 test_done "$testroot" "$ret"
2320 return 1
2323 echo c1 > $testroot/content.expected
2324 cat $testroot/wt/c > $testroot/content
2326 cmp -s $testroot/content.expected $testroot/content
2327 ret=$?
2328 if [ $ret -ne 0 ]; then
2329 diff -u $testroot/content.expected $testroot/content
2330 test_done "$testroot" "$ret"
2331 return 1
2334 echo "U c" > $testroot/stdout.expected
2335 echo "Updated to refs/heads/master: $commit_id2" \
2336 >> $testroot/stdout.expected
2338 (cd $testroot/wt && got update -c $commit_id2 c > $testroot/stdout)
2340 cmp -s $testroot/stdout.expected $testroot/stdout
2341 ret=$?
2342 if [ $ret -ne 0 ]; then
2343 diff -u $testroot/stdout.expected $testroot/stdout
2344 test_done "$testroot" "$ret"
2345 return 1
2348 echo c2 > $testroot/content.expected
2349 cat $testroot/wt/c > $testroot/content
2351 cmp -s $testroot/content.expected $testroot/content
2352 ret=$?
2353 if [ $ret -ne 0 ]; then
2354 diff -u $testroot/content.expected $testroot/content
2355 test_done "$testroot" "$ret"
2356 return 1
2359 echo "D c" > $testroot/stdout.expected
2360 echo "Updated to refs/heads/master: $commit_id3" \
2361 >> $testroot/stdout.expected
2363 (cd $testroot/wt && got update -c $commit_id3 c \
2364 > $testroot/stdout 2> $testroot/stderr)
2366 echo "got: /c: no such entry found in tree" > $testroot/stderr.expected
2367 cmp -s $testroot/stderr.expected $testroot/stderr
2368 ret=$?
2369 if [ $ret -ne 0 ]; then
2370 diff -u $testroot/stderr.expected $testroot/stderr
2371 test_done "$testroot" "$ret"
2372 return 1
2375 echo -n > $testroot/stdout.expected
2376 cmp -s $testroot/stdout.expected $testroot/stdout
2377 ret=$?
2378 if [ $ret -ne 0 ]; then
2379 diff -u $testroot/stdout.expected $testroot/stdout
2380 test_done "$testroot" "$ret"
2381 return 1
2384 echo "D c" > $testroot/stdout.expected
2385 echo "Updated to refs/heads/master: $commit_id3" \
2386 >> $testroot/stdout.expected
2388 (cd $testroot/wt && got update -c $commit_id3 > $testroot/stdout)
2389 cmp -s $testroot/stdout.expected $testroot/stdout
2390 ret=$?
2391 if [ $ret -ne 0 ]; then
2392 diff -u $testroot/stdout.expected $testroot/stdout
2393 test_done "$testroot" "$ret"
2394 return 1
2397 if [ -e $testroot/wt/c ]; then
2398 echo "removed file c still exists on disk" >&2
2399 test_done "$testroot" "1"
2400 return 1
2403 test_done "$testroot" "0"
2404 return 0
2407 test_update_file_skipped_due_to_conflict() {
2408 local testroot=`test_init update_file_skipped_due_to_conflict`
2409 local commit_id0=`git_show_head $testroot/repo`
2410 blob_id0=`get_blob_id $testroot/repo "" beta`
2412 echo "changed beta" > $testroot/repo/beta
2413 git_commit $testroot/repo -m "changed beta"
2414 local commit_id1=`git_show_head $testroot/repo`
2415 blob_id1=`get_blob_id $testroot/repo "" beta`
2417 got checkout $testroot/repo $testroot/wt > /dev/null
2418 ret=$?
2419 if [ $ret -ne 0 ]; then
2420 test_done "$testroot" "$ret"
2421 return 1
2424 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2425 cut -d ':' -f 2 | tr -d ' ')`
2426 if [ "$blob_id" != "$blob_id1" ]; then
2427 echo "file beta has the wrong base blob ID" >&2
2428 test_done "$testroot" "1"
2429 return 1
2432 commit_id=`(cd $testroot/wt && got info beta | \
2433 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2434 if [ "$commit_id" != "$commit_id1" ]; then
2435 echo "file beta has the wrong base commit ID" >&2
2436 test_done "$testroot" "1"
2437 return 1
2440 echo "modified beta" > $testroot/wt/beta
2442 (cd $testroot/wt && got update -c $commit_id0 > $testroot/stdout)
2444 echo "C beta" > $testroot/stdout.expected
2445 echo "Updated to refs/heads/master: $commit_id0" \
2446 >> $testroot/stdout.expected
2447 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2448 cmp -s $testroot/stdout.expected $testroot/stdout
2449 ret=$?
2450 if [ $ret -ne 0 ]; then
2451 diff -u $testroot/stdout.expected $testroot/stdout
2452 test_done "$testroot" "$ret"
2453 return 1
2456 echo "<<<<<<< merged change: commit $commit_id0" \
2457 > $testroot/content.expected
2458 echo "beta" >> $testroot/content.expected
2459 echo "||||||| 3-way merge base: commit $commit_id1" \
2460 >> $testroot/content.expected
2461 echo "changed beta" >> $testroot/content.expected
2462 echo "=======" >> $testroot/content.expected
2463 echo "modified beta" >> $testroot/content.expected
2464 echo ">>>>>>>" >> $testroot/content.expected
2466 cat $testroot/wt/beta > $testroot/content
2468 cmp -s $testroot/content.expected $testroot/content
2469 ret=$?
2470 if [ $ret -ne 0 ]; then
2471 diff -u $testroot/content.expected $testroot/content
2472 test_done "$testroot" "$ret"
2473 return 1
2476 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2477 cut -d ':' -f 2 | tr -d ' ')`
2478 if [ "$blob_id" != "$blob_id0" ]; then
2479 echo "file beta has the wrong base blob ID" >&2
2480 test_done "$testroot" "1"
2481 return 1
2484 commit_id=`(cd $testroot/wt && got info beta | \
2485 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2486 if [ "$commit_id" != "$commit_id0" ]; then
2487 echo "file beta has the wrong base commit ID" >&2
2488 test_done "$testroot" "1"
2489 return 1
2492 # update to the latest commit again; this skips beta
2493 (cd $testroot/wt && got update > $testroot/stdout)
2494 echo "# beta" > $testroot/stdout.expected
2495 echo "Updated to refs/heads/master: $commit_id1" \
2496 >> $testroot/stdout.expected
2497 echo "Files not updated because of existing merge conflicts: 1" \
2498 >> $testroot/stdout.expected
2499 cmp -s $testroot/stdout.expected $testroot/stdout
2500 ret=$?
2501 if [ $ret -ne 0 ]; then
2502 diff -u $testroot/stdout.expected $testroot/stdout
2503 test_done "$testroot" "$ret"
2504 return 1
2507 # blob ID of beta should not have changed
2508 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2509 cut -d ':' -f 2 | tr -d ' ')`
2510 if [ "$blob_id" != "$blob_id0" ]; then
2511 echo "file beta has the wrong base blob ID" >&2
2512 test_done "$testroot" "1"
2513 return 1
2516 # commit ID of beta should not have changed; There was a bug
2517 # here where the commit ID had been changed even though the
2518 # file was not updated.
2519 commit_id=`(cd $testroot/wt && got info beta | \
2520 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2521 if [ "$commit_id" != "$commit_id0" ]; then
2522 echo "file beta has the wrong base commit ID: $commit_id" >&2
2523 test_done "$testroot" "1"
2524 return 1
2527 # beta is still conflicted and based on commit 0
2528 echo 'C beta' > $testroot/stdout.expected
2529 (cd $testroot/wt && got status > $testroot/stdout)
2530 cmp -s $testroot/stdout.expected $testroot/stdout
2531 ret=$?
2532 if [ $ret -ne 0 ]; then
2533 diff -u $testroot/stdout.expected $testroot/stdout
2534 test_done "$testroot" "$ret"
2535 return 1
2538 # resolve the conflict via revert
2539 (cd $testroot/wt && got revert beta >/dev/null)
2541 # beta now matches its base blob which is still from commit 0
2542 echo "beta" > $testroot/content.expected
2543 cat $testroot/wt/beta > $testroot/content
2544 cmp -s $testroot/content.expected $testroot/content
2545 ret=$?
2546 if [ $ret -ne 0 ]; then
2547 diff -u $testroot/content.expected $testroot/content
2548 test_done "$testroot" "$ret"
2549 return 1
2552 # updating to the latest commit should now update beta
2553 (cd $testroot/wt && got update > $testroot/stdout)
2554 echo "U beta" > $testroot/stdout.expected
2555 echo "Updated to refs/heads/master: $commit_id1" \
2556 >> $testroot/stdout.expected
2557 cmp -s $testroot/stdout.expected $testroot/stdout
2558 ret=$?
2559 if [ $ret -ne 0 ]; then
2560 diff -u $testroot/stdout.expected $testroot/stdout
2561 test_done "$testroot" "$ret"
2562 return 1
2565 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2566 cut -d ':' -f 2 | tr -d ' ')`
2567 if [ "$blob_id" != "$blob_id1" ]; then
2568 echo "file beta has the wrong base blob ID" >&2
2569 test_done "$testroot" "1"
2570 return 1
2573 commit_id=`(cd $testroot/wt && got info beta | \
2574 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2575 if [ "$commit_id" != "$commit_id1" ]; then
2576 echo "file beta has the wrong base commit ID: $commit_id" >&2
2577 test_done "$testroot" "1"
2578 return 1
2581 echo "changed beta" > $testroot/content.expected
2582 cat $testroot/wt/beta > $testroot/content
2583 cmp -s $testroot/content.expected $testroot/content
2584 ret=$?
2585 if [ $ret -ne 0 ]; then
2586 diff -u $testroot/content.expected $testroot/content
2588 test_done "$testroot" "$ret"
2591 test_update_file_skipped_due_to_obstruction() {
2592 local testroot=`test_init update_file_skipped_due_to_obstruction`
2593 local commit_id0=`git_show_head $testroot/repo`
2594 blob_id0=`get_blob_id $testroot/repo "" beta`
2596 echo "changed beta" > $testroot/repo/beta
2597 echo "new file" > $testroot/repo/new
2598 (cd $testroot/repo && git add new)
2599 git_commit $testroot/repo -m "changed beta"
2600 local commit_id1=`git_show_head $testroot/repo`
2601 blob_id1=`get_blob_id $testroot/repo "" beta`
2603 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
2604 ret=$?
2605 if [ $ret -ne 0 ]; then
2606 test_done "$testroot" "$ret"
2607 return 1
2610 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2611 cut -d ':' -f 2 | tr -d ' ')`
2612 if [ "$blob_id" != "$blob_id0" ]; then
2613 echo "file beta has the wrong base blob ID" >&2
2614 test_done "$testroot" "1"
2615 return 1
2618 commit_id=`(cd $testroot/wt && got info beta | \
2619 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2620 if [ "$commit_id" != "$commit_id0" ]; then
2621 echo "file beta has the wrong base commit ID" >&2
2622 test_done "$testroot" "1"
2623 return 1
2626 rm $testroot/wt/beta
2627 mkdir -p $testroot/wt/beta/psi
2628 mkdir -p $testroot/wt/new
2630 # update to the latest commit; this skips beta and the new file
2631 (cd $testroot/wt && got update > $testroot/stdout)
2632 ret=$?
2633 if [ $ret -ne 0 ]; then
2634 echo "update failed unexpectedly" >&2
2635 test_done "$testroot" "1"
2636 return 1
2639 echo "~ beta" > $testroot/stdout.expected
2640 echo "~ new" >> $testroot/stdout.expected
2641 echo "Updated to refs/heads/master: $commit_id1" \
2642 >> $testroot/stdout.expected
2643 echo "File paths obstructed by a non-regular file: 2" \
2644 >> $testroot/stdout.expected
2645 cmp -s $testroot/stdout.expected $testroot/stdout
2646 ret=$?
2647 if [ $ret -ne 0 ]; then
2648 diff -u $testroot/stdout.expected $testroot/stdout
2649 test_done "$testroot" "$ret"
2650 return 1
2653 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2654 cut -d ':' -f 2 | tr -d ' ')`
2655 if [ "$blob_id" != "$blob_id0" ]; then
2656 echo "file beta has the wrong base blob ID" >&2
2657 test_done "$testroot" "1"
2658 return 1
2661 commit_id=`(cd $testroot/wt && got info beta | \
2662 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2663 if [ "$commit_id" != "$commit_id0" ]; then
2664 echo "file beta has the wrong base commit ID" >&2
2665 test_done "$testroot" "1"
2666 return 1
2669 # remove the directory which obstructs file beta
2670 rm -r $testroot/wt/beta
2672 # updating to the latest commit should now update beta
2673 (cd $testroot/wt && got update > $testroot/stdout)
2674 echo "! beta" > $testroot/stdout.expected
2675 echo "~ new" >> $testroot/stdout.expected
2676 echo "Updated to refs/heads/master: $commit_id1" \
2677 >> $testroot/stdout.expected
2678 echo "File paths obstructed by a non-regular file: 1" \
2679 >> $testroot/stdout.expected
2680 cmp -s $testroot/stdout.expected $testroot/stdout
2681 ret=$?
2682 if [ $ret -ne 0 ]; then
2683 diff -u $testroot/stdout.expected $testroot/stdout
2684 test_done "$testroot" "$ret"
2685 return 1
2688 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2689 cut -d ':' -f 2 | tr -d ' ')`
2690 if [ "$blob_id" != "$blob_id1" ]; then
2691 echo "file beta has the wrong base blob ID" >&2
2692 test_done "$testroot" "1"
2693 return 1
2696 commit_id=`(cd $testroot/wt && got info beta | \
2697 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2698 if [ "$commit_id" != "$commit_id1" ]; then
2699 echo "file beta has the wrong base commit ID: $commit_id" >&2
2700 test_done "$testroot" "1"
2701 return 1
2704 echo "changed beta" > $testroot/content.expected
2705 cat $testroot/wt/beta > $testroot/content
2706 cmp -s $testroot/content.expected $testroot/content
2707 ret=$?
2708 if [ $ret -ne 0 ]; then
2709 diff -u $testroot/content.expected $testroot/content
2711 test_done "$testroot" "$ret"
2714 test_update_quiet() {
2715 local testroot=`test_init update_quiet`
2717 got checkout $testroot/repo $testroot/wt > /dev/null
2718 ret=$?
2719 if [ $ret -ne 0 ]; then
2720 test_done "$testroot" "$ret"
2721 return 1
2724 echo "modified alpha" > $testroot/repo/alpha
2725 git_commit $testroot/repo -m "modified alpha"
2727 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2728 git_show_head $testroot/repo >> $testroot/stdout.expected
2729 echo >> $testroot/stdout.expected
2731 (cd $testroot/wt && got update -q > $testroot/stdout)
2733 cmp -s $testroot/stdout.expected $testroot/stdout
2734 ret=$?
2735 if [ $ret -ne 0 ]; then
2736 diff -u $testroot/stdout.expected $testroot/stdout
2737 test_done "$testroot" "$ret"
2738 return 1
2741 echo "modified alpha" > $testroot/content.expected
2742 cat $testroot/wt/alpha > $testroot/content
2744 cmp -s $testroot/content.expected $testroot/content
2745 ret=$?
2746 if [ $ret -ne 0 ]; then
2747 diff -u $testroot/content.expected $testroot/content
2749 test_done "$testroot" "$ret"
2752 test_update_binary_file() {
2753 local testroot=`test_init update_binary_file`
2754 local commit_id0=`git_show_head $testroot/repo`
2756 got checkout $testroot/repo $testroot/wt > /dev/null
2757 ret=$?
2758 if [ $ret -ne 0 ]; then
2759 test_done "$testroot" "$ret"
2760 return 1
2763 cp /bin/ls $testroot/wt/foo
2764 chmod 755 $testroot/wt/foo
2765 (cd $testroot/wt && got add foo >/dev/null)
2766 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
2767 local commit_id1=`git_show_head $testroot/repo`
2769 cp /bin/cat $testroot/wt/foo
2770 chmod 755 $testroot/wt/foo
2771 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2772 local commit_id2=`git_show_head $testroot/repo`
2774 cp /bin/cp $testroot/wt/foo
2775 chmod 755 $testroot/wt/foo
2776 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2777 local commit_id3=`git_show_head $testroot/repo`
2779 (cd $testroot/wt && got rm foo >/dev/null)
2780 (cd $testroot/wt && got commit -m 'remove binary file' > /dev/null)
2781 local commit_id4=`git_show_head $testroot/repo`
2783 # backdate the work tree to make it usable for updating
2784 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2786 # update which adds a binary file
2787 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2789 echo "A foo" > $testroot/stdout.expected
2790 echo -n "Updated to refs/heads/master: $commit_id1" \
2791 >> $testroot/stdout.expected
2792 echo >> $testroot/stdout.expected
2793 cmp -s $testroot/stdout.expected $testroot/stdout
2794 ret=$?
2795 if [ $ret -ne 0 ]; then
2796 diff -u $testroot/stdout.expected $testroot/stdout
2797 test_done "$testroot" "$ret"
2798 return 1
2801 cp /bin/ls $testroot/content.expected
2802 chmod 755 $testroot/content.expected
2803 cat $testroot/wt/foo > $testroot/content
2805 cmp -s $testroot/content.expected $testroot/content
2806 ret=$?
2807 if [ $ret -ne 0 ]; then
2808 diff -u $testroot/content.expected $testroot/content
2809 test_done "$testroot" "$ret"
2810 return 1
2813 # update which adds a conflicting binary file
2814 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2815 cp /bin/cat $testroot/wt/foo
2816 chmod 755 $testroot/wt/foo
2817 (cd $testroot/wt && got add foo > /dev/null)
2818 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2820 echo "C foo" > $testroot/stdout.expected
2821 echo "Updated to refs/heads/master: $commit_id1" \
2822 >> $testroot/stdout.expected
2823 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2824 cmp -s $testroot/stdout.expected $testroot/stdout
2825 ret=$?
2826 if [ $ret -ne 0 ]; then
2827 diff -u $testroot/stdout.expected $testroot/stdout
2828 test_done "$testroot" "$ret"
2829 return 1
2832 echo "Binary files differ and cannot be merged automatically:" \
2833 > $testroot/content.expected
2834 echo "<<<<<<< merged change: commit $commit_id1" \
2835 >> $testroot/content.expected
2836 echo -n "file " >> $testroot/content.expected
2837 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2838 echo '=======' >> $testroot/content.expected
2839 echo -n "file " >> $testroot/content.expected
2840 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2841 echo ">>>>>>>" >> $testroot/content.expected
2842 cat $testroot/wt/foo > $testroot/content
2844 cmp -s $testroot/content.expected $testroot/content
2845 ret=$?
2846 if [ $ret -ne 0 ]; then
2847 diff -u $testroot/content.expected $testroot/content
2848 test_done "$testroot" "$ret"
2849 return 1
2852 cp /bin/ls $testroot/content.expected
2853 chmod 755 $testroot/content.expected
2854 cat $testroot/wt/foo-1-* > $testroot/content
2856 cmp -s $testroot/content.expected $testroot/content
2857 ret=$?
2858 if [ $ret -ne 0 ]; then
2859 diff -u $testroot/content.expected $testroot/content
2860 test_done "$testroot" "$ret"
2861 return 1
2864 cp /bin/cat $testroot/content.expected
2865 chmod 755 $testroot/content.expected
2866 cat $testroot/wt/foo-2-* > $testroot/content
2868 cmp -s $testroot/content.expected $testroot/content
2869 ret=$?
2870 if [ $ret -ne 0 ]; then
2871 diff -u $testroot/content.expected $testroot/content
2872 test_done "$testroot" "$ret"
2873 return 1
2876 # tidy up
2877 (cd $testroot/wt && got revert -R . >/dev/null)
2878 rm $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2879 (cd $testroot/wt && got up -c $commit_id1 > /dev/null)
2881 # update which changes a binary file
2882 (cd $testroot/wt && got up -c $commit_id2 > $testroot/stdout)
2884 echo "U foo" > $testroot/stdout.expected
2885 echo -n "Updated to refs/heads/master: $commit_id2" \
2886 >> $testroot/stdout.expected
2887 echo >> $testroot/stdout.expected
2888 cmp -s $testroot/stdout.expected $testroot/stdout
2889 ret=$?
2890 if [ $ret -ne 0 ]; then
2891 diff -u $testroot/stdout.expected $testroot/stdout
2892 test_done "$testroot" "$ret"
2893 return 1
2896 cp /bin/cat $testroot/content.expected
2897 chmod 755 $testroot/content.expected
2898 cat $testroot/wt/foo > $testroot/content
2900 cmp -s $testroot/content.expected $testroot/content
2901 ret=$?
2902 if [ $ret -ne 0 ]; then
2903 diff -u $testroot/content.expected $testroot/content
2904 test_done "$testroot" "$ret"
2905 return 1
2908 # update which changes a locally modified binary file
2909 cp /bin/ls $testroot/wt/foo
2910 chmod 755 $testroot/wt/foo
2911 (cd $testroot/wt && got up -c $commit_id3 > $testroot/stdout)
2913 echo "C foo" > $testroot/stdout.expected
2914 echo -n "Updated to refs/heads/master: $commit_id3" \
2915 >> $testroot/stdout.expected
2916 echo >> $testroot/stdout.expected
2917 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2918 cmp -s $testroot/stdout.expected $testroot/stdout
2919 ret=$?
2920 if [ $ret -ne 0 ]; then
2921 diff -u $testroot/stdout.expected $testroot/stdout
2922 test_done "$testroot" "$ret"
2923 return 1
2926 echo "Binary files differ and cannot be merged automatically:" \
2927 > $testroot/content.expected
2928 echo "<<<<<<< merged change: commit $commit_id3" \
2929 >> $testroot/content.expected
2930 echo -n "file " >> $testroot/content.expected
2931 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2932 echo "||||||| 3-way merge base: commit $commit_id2" \
2933 >> $testroot/content.expected
2934 echo -n "file " >> $testroot/content.expected
2935 ls $testroot/wt/foo-orig-* >> $testroot/content.expected
2936 echo '=======' >> $testroot/content.expected
2937 echo -n "file " >> $testroot/content.expected
2938 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2939 echo ">>>>>>>" >> $testroot/content.expected
2940 cat $testroot/wt/foo > $testroot/content
2942 cmp -s $testroot/content.expected $testroot/content
2943 ret=$?
2944 if [ $ret -ne 0 ]; then
2945 diff -u $testroot/content.expected $testroot/content
2946 test_done "$testroot" "$ret"
2947 return 1
2950 cp /bin/cp $testroot/content.expected
2951 chmod 755 $testroot/content.expected
2952 cp $testroot/wt/foo-1-* $testroot/content
2953 cmp -s $testroot/content.expected $testroot/content
2954 ret=$?
2955 if [ $ret -ne 0 ]; then
2956 diff -u $testroot/content.expected $testroot/content
2957 test_done "$testroot" "$ret"
2958 return 1
2961 cp /bin/ls $testroot/content.expected
2962 chmod 755 $testroot/content.expected
2963 cp $testroot/wt/foo-2-* $testroot/content
2964 cmp -s $testroot/content.expected $testroot/content
2965 ret=$?
2966 if [ $ret -ne 0 ]; then
2967 diff -u $testroot/content.expected $testroot/content
2968 test_done "$testroot" "$ret"
2969 return 1
2972 (cd $testroot/wt && got status > $testroot/stdout)
2973 echo 'C foo' > $testroot/stdout.expected
2974 echo -n '? ' >> $testroot/stdout.expected
2975 (cd $testroot/wt && ls foo-1-* >> $testroot/stdout.expected)
2976 echo -n '? ' >> $testroot/stdout.expected
2977 (cd $testroot/wt && ls foo-2-* >> $testroot/stdout.expected)
2978 echo -n '? ' >> $testroot/stdout.expected
2979 (cd $testroot/wt && ls foo-orig-* >> $testroot/stdout.expected)
2980 cmp -s $testroot/stdout.expected $testroot/stdout
2981 ret=$?
2982 if [ $ret -ne 0 ]; then
2983 diff -u $testroot/stdout.expected $testroot/stdout
2984 test_done "$testroot" "$ret"
2985 return 1
2988 # tidy up
2989 (cd $testroot/wt && got revert -R . > /dev/null)
2990 rm $testroot/wt/foo-orig-* $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2992 # update which deletes a binary file
2993 (cd $testroot/wt && got up -c $commit_id4 > $testroot/stdout)
2994 echo "D foo" > $testroot/stdout.expected
2995 echo -n "Updated to refs/heads/master: $commit_id4" \
2996 >> $testroot/stdout.expected
2997 echo >> $testroot/stdout.expected
2998 cmp -s $testroot/stdout.expected $testroot/stdout
2999 ret=$?
3000 if [ $ret -ne 0 ]; then
3001 diff -u $testroot/stdout.expected $testroot/stdout
3002 test_done "$testroot" "$ret"
3005 if [ -e $testroot/wt/foo ]; then
3006 echo "removed file foo still exists on disk" >&2
3007 test_done "$testroot" "1"
3008 return 1
3010 test_done "$testroot" "0"
3013 test_update_umask() {
3014 local testroot=`test_init update_binary_file`
3016 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
3017 ret=$?
3018 if [ $ret -ne 0 ]; then
3019 test_done "$testroot" "$ret"
3020 return 1
3023 rm "$testroot/wt/alpha"
3025 # using a subshell to avoid clobbering global umask
3026 (umask 022 && cd "$testroot/wt" && got update alpha) \
3027 >/dev/null 2>/dev/null
3028 ret=$?
3029 if [ $ret -ne 0 ]; then
3030 test_done "$testroot" $ret
3031 return 1
3034 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-r--r--; then
3035 echo "alpha is not 0644" >&2
3036 test_done "$testroot" 1
3037 return 1
3040 rm "$testroot/wt/alpha"
3042 # using a subshell to avoid clobbering global umask
3043 (umask 044 && cd "$testroot/wt" && got update alpha) \
3044 >/dev/null 2>/dev/null
3045 ret=$?
3046 if [ $ret -ne 0 ]; then
3047 test_done "$testroot" $ret
3048 return 1
3051 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
3052 echo "alpha is not 0600" >&2
3053 test_done "$testroot" 1
3054 return 1
3057 rm "$testroot/wt/alpha"
3059 # using a subshell to avoid clobbering global umask
3060 (umask 222 && cd "$testroot/wt" && got update alpha) \
3061 >/dev/null 2>/dev/null
3062 ret=$?
3063 if [ $ret -ne 0 ]; then
3064 test_done "$testroot" $ret
3065 return 1
3068 if ! ls -l "$testroot/wt/alpha" | grep -q ^-r--r--r--; then
3069 echo "alpha is not 0444" >&2
3070 test_done "$testroot" 1
3071 return 1;
3074 test_done "$testroot" 0
3077 test_parseargs "$@"
3078 run_test test_update_basic
3079 run_test test_update_adds_file
3080 run_test test_update_deletes_file
3081 run_test test_update_deletes_dir
3082 run_test test_update_deletes_dir_with_path_prefix
3083 run_test test_update_deletes_dir_recursively
3084 run_test test_update_sibling_dirs_with_common_prefix
3085 run_test test_update_dir_with_dot_sibling
3086 run_test test_update_moves_files_upwards
3087 run_test test_update_moves_files_to_new_dir
3088 run_test test_update_creates_missing_parent
3089 run_test test_update_creates_missing_parent_with_subdir
3090 run_test test_update_file_in_subsubdir
3091 run_test test_update_merges_file_edits
3092 run_test test_update_keeps_xbit
3093 run_test test_update_clears_xbit
3094 run_test test_update_restores_missing_file
3095 run_test test_update_conflict_wt_add_vs_repo_add
3096 run_test test_update_conflict_wt_edit_vs_repo_rm
3097 run_test test_update_conflict_wt_rm_vs_repo_edit
3098 run_test test_update_conflict_wt_rm_vs_repo_rm
3099 run_test test_update_partial
3100 run_test test_update_partial_add
3101 run_test test_update_partial_rm
3102 run_test test_update_partial_dir
3103 run_test test_update_moved_branch_ref
3104 run_test test_update_to_another_branch
3105 run_test test_update_to_commit_on_wrong_branch
3106 run_test test_update_bumps_base_commit_id
3107 run_test test_update_tag
3108 run_test test_update_toggles_xbit
3109 run_test test_update_preserves_conflicted_file
3110 run_test test_update_modified_submodules
3111 run_test test_update_adds_submodule
3112 run_test test_update_conflict_wt_file_vs_repo_submodule
3113 run_test test_update_adds_symlink
3114 run_test test_update_deletes_symlink
3115 run_test test_update_symlink_conflicts
3116 run_test test_update_single_file
3117 run_test test_update_file_skipped_due_to_conflict
3118 run_test test_update_file_skipped_due_to_obstruction
3119 run_test test_update_quiet
3120 run_test test_update_binary_file
3121 run_test test_update_umask