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 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 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_changes_file_to_dir() {
640 local testroot=`test_init update_changes_file_to_dir`
642 got checkout $testroot/repo $testroot/wt > /dev/null
643 ret=$?
644 if [ $ret -ne 0 ]; then
645 test_done "$testroot" "$ret"
646 return 1
647 fi
649 git_rm $testroot/repo alpha
650 mkdir $testroot/repo/alpha
651 echo eta > $testroot/repo/alpha/eta
652 (cd $testroot/repo && git add alpha/eta)
653 git_commit $testroot/repo -m "changed alpha into directory"
655 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
656 ret=$?
657 if [ $ret -ne 0 ]; then
658 ret="xfail change file into directory"
659 fi
660 test_done "$testroot" "$ret"
663 test_update_merges_file_edits() {
664 local testroot=`test_init update_merges_file_edits`
666 echo "1" > $testroot/repo/numbers
667 echo "2" >> $testroot/repo/numbers
668 echo "3" >> $testroot/repo/numbers
669 echo "4" >> $testroot/repo/numbers
670 echo "5" >> $testroot/repo/numbers
671 echo "6" >> $testroot/repo/numbers
672 echo "7" >> $testroot/repo/numbers
673 echo "8" >> $testroot/repo/numbers
674 (cd $testroot/repo && git add numbers)
675 git_commit $testroot/repo -m "added numbers file"
676 local base_commit=`git_show_head $testroot/repo`
678 got checkout $testroot/repo $testroot/wt > /dev/null
679 ret=$?
680 if [ $ret -ne 0 ]; then
681 test_done "$testroot" "$ret"
682 return 1
683 fi
685 echo "modified alpha" > $testroot/repo/alpha
686 echo "modified beta" > $testroot/repo/beta
687 ed -s $testroot/repo/numbers <<-\EOF
688 ,s/2/22/
690 EOF
691 git_commit $testroot/repo -m "modified 3 files"
693 echo "modified alpha, too" > $testroot/wt/alpha
694 touch $testroot/wt/beta
695 ed -s $testroot/wt/numbers <<-\EOF
696 ,s/7/77/
698 EOF
700 echo "C alpha" > $testroot/stdout.expected
701 echo "U beta" >> $testroot/stdout.expected
702 echo "G numbers" >> $testroot/stdout.expected
703 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
704 git_show_head $testroot/repo >> $testroot/stdout.expected
705 echo >> $testroot/stdout.expected
706 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
708 (cd $testroot/wt && got update > $testroot/stdout)
710 cmp -s $testroot/stdout.expected $testroot/stdout
711 ret=$?
712 if [ $ret -ne 0 ]; then
713 diff -u $testroot/stdout.expected $testroot/stdout
714 test_done "$testroot" "$ret"
715 return 1
716 fi
718 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
719 git_show_head $testroot/repo >> $testroot/content.expected
720 echo >> $testroot/content.expected
721 echo "modified alpha" >> $testroot/content.expected
722 echo "||||||| 3-way merge base: commit $base_commit" \
723 >> $testroot/content.expected
724 echo "alpha" >> $testroot/content.expected
725 echo "=======" >> $testroot/content.expected
726 echo "modified alpha, too" >> $testroot/content.expected
727 echo '>>>>>>>' >> $testroot/content.expected
728 echo "modified beta" >> $testroot/content.expected
729 echo "1" >> $testroot/content.expected
730 echo "22" >> $testroot/content.expected
731 echo "3" >> $testroot/content.expected
732 echo "4" >> $testroot/content.expected
733 echo "5" >> $testroot/content.expected
734 echo "6" >> $testroot/content.expected
735 echo "77" >> $testroot/content.expected
736 echo "8" >> $testroot/content.expected
738 cat $testroot/wt/alpha > $testroot/content
739 cat $testroot/wt/beta >> $testroot/content
740 cat $testroot/wt/numbers >> $testroot/content
742 cmp -s $testroot/content.expected $testroot/content
743 ret=$?
744 if [ $ret -ne 0 ]; then
745 diff -u $testroot/content.expected $testroot/content
746 fi
747 test_done "$testroot" "$ret"
750 test_update_keeps_xbit() {
751 local testroot=`test_init update_keeps_xbit 1`
753 touch $testroot/repo/xfile
754 chmod +x $testroot/repo/xfile
755 (cd $testroot/repo && git add .)
756 git_commit $testroot/repo -m "adding executable file"
758 got checkout $testroot/repo $testroot/wt > $testroot/stdout
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 test_done "$testroot" "$ret"
762 return 1
763 fi
765 echo foo > $testroot/repo/xfile
766 git_commit $testroot/repo -m "changed executable file"
768 echo "U xfile" > $testroot/stdout.expected
769 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
770 git_show_head $testroot/repo >> $testroot/stdout.expected
771 echo >> $testroot/stdout.expected
773 (cd $testroot/wt && got update > $testroot/stdout)
774 ret=$?
775 if [ $ret -ne 0 ]; then
776 test_done "$testroot" "$ret"
777 return 1
778 fi
780 cmp -s $testroot/stdout.expected $testroot/stdout
781 ret=$?
782 if [ $ret -ne 0 ]; then
783 diff -u $testroot/stdout.expected $testroot/stdout
784 test_done "$testroot" "$ret"
785 return 1
786 fi
788 ls -l $testroot/wt/xfile | grep -q '^-rwx'
789 ret=$?
790 if [ $ret -ne 0 ]; then
791 echo "file is not executable" >&2
792 ls -l $testroot/wt/xfile >&2
793 fi
794 test_done "$testroot" "$ret"
797 test_update_clears_xbit() {
798 local testroot=`test_init update_clears_xbit 1`
800 touch $testroot/repo/xfile
801 chmod +x $testroot/repo/xfile
802 (cd $testroot/repo && git add .)
803 git_commit $testroot/repo -m "adding executable file"
805 got checkout $testroot/repo $testroot/wt > $testroot/stdout
806 ret=$?
807 if [ $ret -ne 0 ]; then
808 test_done "$testroot" "$ret"
809 return 1
810 fi
812 ls -l $testroot/wt/xfile | grep -q '^-rwx'
813 ret=$?
814 if [ $ret -ne 0 ]; then
815 echo "file is not executable" >&2
816 ls -l $testroot/wt/xfile >&2
817 test_done "$testroot" "$ret"
818 return 1
819 fi
821 # XXX git seems to require a file edit when flipping the x bit?
822 echo foo > $testroot/repo/xfile
823 chmod -x $testroot/repo/xfile
824 git_commit $testroot/repo -m "not an executable file anymore"
826 echo "U xfile" > $testroot/stdout.expected
827 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
828 git_show_head $testroot/repo >> $testroot/stdout.expected
829 echo >> $testroot/stdout.expected
831 (cd $testroot/wt && got update > $testroot/stdout)
832 ret=$?
833 if [ $ret -ne 0 ]; then
834 test_done "$testroot" "$ret"
835 return 1
836 fi
838 cmp -s $testroot/stdout.expected $testroot/stdout
839 ret=$?
840 if [ $ret -ne 0 ]; then
841 diff -u $testroot/stdout.expected $testroot/stdout
842 test_done "$testroot" "$ret"
843 return 1
844 fi
846 ls -l $testroot/wt/xfile | grep -q '^-rw-'
847 ret=$?
848 if [ $ret -ne 0 ]; then
849 echo "file is unexpectedly executable" >&2
850 ls -l $testroot/wt/xfile >&2
851 fi
852 test_done "$testroot" "$ret"
855 test_update_restores_missing_file() {
856 local testroot=`test_init update_restores_missing_file`
858 got checkout $testroot/repo $testroot/wt > /dev/null
859 ret=$?
860 if [ $ret -ne 0 ]; then
861 test_done "$testroot" "$ret"
862 return 1
863 fi
865 rm $testroot/wt/alpha
867 echo "! alpha" > $testroot/stdout.expected
868 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
869 git_show_head $testroot/repo >> $testroot/stdout.expected
870 echo >> $testroot/stdout.expected
871 (cd $testroot/wt && got update > $testroot/stdout)
873 cmp -s $testroot/stdout.expected $testroot/stdout
874 ret=$?
875 if [ $ret -ne 0 ]; then
876 diff -u $testroot/stdout.expected $testroot/stdout
877 test_done "$testroot" "$ret"
878 return 1
879 fi
881 echo "alpha" > $testroot/content.expected
883 cat $testroot/wt/alpha > $testroot/content
885 cmp -s $testroot/content.expected $testroot/content
886 ret=$?
887 if [ $ret -ne 0 ]; then
888 diff -u $testroot/content.expected $testroot/content
889 fi
890 test_done "$testroot" "$ret"
893 test_update_conflict_wt_add_vs_repo_add() {
894 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
896 got checkout $testroot/repo $testroot/wt > /dev/null
897 ret=$?
898 if [ $ret -ne 0 ]; then
899 test_done "$testroot" "$ret"
900 return 1
901 fi
903 echo "new" > $testroot/repo/gamma/new
904 (cd $testroot/repo && git add .)
905 git_commit $testroot/repo -m "adding a new file"
907 echo "also new" > $testroot/wt/gamma/new
908 (cd $testroot/wt && got add gamma/new >/dev/null)
910 (cd $testroot/wt && got update > $testroot/stdout)
912 echo "C gamma/new" > $testroot/stdout.expected
913 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
914 git_show_head $testroot/repo >> $testroot/stdout.expected
915 echo >> $testroot/stdout.expected
916 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
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 test_done "$testroot" "$ret"
923 return 1
924 fi
926 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
927 git_show_head $testroot/repo >> $testroot/content.expected
928 echo >> $testroot/content.expected
929 echo "new" >> $testroot/content.expected
930 echo "=======" >> $testroot/content.expected
931 echo "also new" >> $testroot/content.expected
932 echo '>>>>>>>' >> $testroot/content.expected
934 cat $testroot/wt/gamma/new > $testroot/content
936 cmp -s $testroot/content.expected $testroot/content
937 ret=$?
938 if [ $ret -ne 0 ]; then
939 diff -u $testroot/content.expected $testroot/content
940 test_done "$testroot" "$ret"
941 return 1
942 fi
944 # resolve the conflict
945 echo "new and also new" > $testroot/wt/gamma/new
946 echo 'M gamma/new' > $testroot/stdout.expected
947 (cd $testroot/wt && got status > $testroot/stdout)
948 cmp -s $testroot/stdout.expected $testroot/stdout
949 ret=$?
950 if [ $ret -ne 0 ]; then
951 diff -u $testroot/stdout.expected $testroot/stdout
952 fi
953 test_done "$testroot" "$ret"
956 test_update_conflict_wt_edit_vs_repo_rm() {
957 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
959 got checkout $testroot/repo $testroot/wt > /dev/null
960 ret=$?
961 if [ $ret -ne 0 ]; then
962 test_done "$testroot" "$ret"
963 return 1
964 fi
966 (cd $testroot/repo && git rm -q beta)
967 git_commit $testroot/repo -m "removing a file"
969 echo "modified beta" > $testroot/wt/beta
971 (cd $testroot/wt && got update > $testroot/stdout)
973 echo "G beta" > $testroot/stdout.expected
974 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
975 git_show_head $testroot/repo >> $testroot/stdout.expected
976 echo >> $testroot/stdout.expected
977 cmp -s $testroot/stdout.expected $testroot/stdout
978 ret=$?
979 if [ $ret -ne 0 ]; then
980 diff -u $testroot/stdout.expected $testroot/stdout
981 test_done "$testroot" "$ret"
982 return 1
983 fi
985 echo "modified beta" > $testroot/content.expected
987 cat $testroot/wt/beta > $testroot/content
989 cmp -s $testroot/content.expected $testroot/content
990 ret=$?
991 if [ $ret -ne 0 ]; then
992 diff -u $testroot/content.expected $testroot/content
993 test_done "$testroot" "$ret"
994 return 1
995 fi
997 # beta is now an added file... we don't flag tree conflicts yet
998 echo 'A beta' > $testroot/stdout.expected
999 (cd $testroot/wt && got status > $testroot/stdout)
1000 cmp -s $testroot/stdout.expected $testroot/stdout
1001 ret=$?
1002 if [ $ret -ne 0 ]; then
1003 diff -u $testroot/stdout.expected $testroot/stdout
1005 test_done "$testroot" "$ret"
1008 test_update_conflict_wt_rm_vs_repo_edit() {
1009 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
1011 got checkout $testroot/repo $testroot/wt > /dev/null
1012 ret=$?
1013 if [ $ret -ne 0 ]; then
1014 test_done "$testroot" "$ret"
1015 return 1
1018 echo "modified beta" > $testroot/repo/beta
1019 git_commit $testroot/repo -m "modified a file"
1021 (cd $testroot/wt && got rm beta > /dev/null)
1023 (cd $testroot/wt && got update > $testroot/stdout)
1025 echo "G beta" > $testroot/stdout.expected
1026 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1027 git_show_head $testroot/repo >> $testroot/stdout.expected
1028 echo >> $testroot/stdout.expected
1029 cmp -s $testroot/stdout.expected $testroot/stdout
1030 ret=$?
1031 if [ $ret -ne 0 ]; then
1032 diff -u $testroot/stdout.expected $testroot/stdout
1033 test_done "$testroot" "$ret"
1034 return 1
1037 # beta remains a deleted file... we don't flag tree conflicts yet
1038 echo 'D beta' > $testroot/stdout.expected
1039 (cd $testroot/wt && got status > $testroot/stdout)
1040 cmp -s $testroot/stdout.expected $testroot/stdout
1041 ret=$?
1042 if [ $ret -ne 0 ]; then
1043 diff -u $testroot/stdout.expected $testroot/stdout
1044 test_done "$testroot" "$ret"
1045 return 1
1048 # 'got diff' should show post-update contents of beta being deleted
1049 local head_rev=`git_show_head $testroot/repo`
1050 echo "diff $testroot/wt" > $testroot/stdout.expected
1051 echo "commit - $head_rev" >> $testroot/stdout.expected
1052 echo "path + $testroot/wt" >> $testroot/stdout.expected
1053 echo -n 'blob - ' >> $testroot/stdout.expected
1054 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1055 >> $testroot/stdout.expected
1056 echo 'file + /dev/null' >> $testroot/stdout.expected
1057 echo '--- beta' >> $testroot/stdout.expected
1058 echo '+++ /dev/null' >> $testroot/stdout.expected
1059 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1060 echo '-modified beta' >> $testroot/stdout.expected
1062 (cd $testroot/wt && got diff > $testroot/stdout)
1063 cmp -s $testroot/stdout.expected $testroot/stdout
1064 ret=$?
1065 if [ $ret -ne 0 ]; then
1066 diff -u $testroot/stdout.expected $testroot/stdout
1068 test_done "$testroot" "$ret"
1071 test_update_conflict_wt_rm_vs_repo_rm() {
1072 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1074 got checkout $testroot/repo $testroot/wt > /dev/null
1075 ret=$?
1076 if [ $ret -ne 0 ]; then
1077 test_done "$testroot" "$ret"
1078 return 1
1081 (cd $testroot/repo && git rm -q beta)
1082 git_commit $testroot/repo -m "removing a file"
1084 (cd $testroot/wt && got rm beta > /dev/null)
1086 (cd $testroot/wt && got update > $testroot/stdout)
1088 echo "D beta" > $testroot/stdout.expected
1089 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1090 git_show_head $testroot/repo >> $testroot/stdout.expected
1091 echo >> $testroot/stdout.expected
1092 cmp -s $testroot/stdout.expected $testroot/stdout
1093 ret=$?
1094 if [ $ret -ne 0 ]; then
1095 diff -u $testroot/stdout.expected $testroot/stdout
1096 test_done "$testroot" "$ret"
1097 return 1
1100 # beta is now gone... we don't flag tree conflicts yet
1101 echo "N beta" > $testroot/stdout.expected
1102 echo -n > $testroot/stderr.expected
1103 (cd $testroot/wt && got status beta > $testroot/stdout \
1104 2> $testroot/stderr)
1105 cmp -s $testroot/stdout.expected $testroot/stdout
1106 ret=$?
1107 if [ $ret -ne 0 ]; then
1108 diff -u $testroot/stdout.expected $testroot/stdout
1109 test_done "$testroot" "$ret"
1110 return 1
1112 cmp -s $testroot/stderr.expected $testroot/stderr
1113 ret=$?
1114 if [ $ret -ne 0 ]; then
1115 diff -u $testroot/stderr.expected $testroot/stderr
1116 test_done "$testroot" "$ret"
1117 return 1
1120 if [ -e $testroot/wt/beta ]; then
1121 echo "removed file beta still exists on disk" >&2
1122 test_done "$testroot" "1"
1123 return 1
1126 test_done "$testroot" "0"
1129 test_update_partial() {
1130 local testroot=`test_init update_partial`
1132 got checkout $testroot/repo $testroot/wt > /dev/null
1133 ret=$?
1134 if [ $ret -ne 0 ]; then
1135 test_done "$testroot" "$ret"
1136 return 1
1139 echo "modified alpha" > $testroot/repo/alpha
1140 echo "modified beta" > $testroot/repo/beta
1141 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1142 git_commit $testroot/repo -m "modified two files"
1144 echo "U alpha" > $testroot/stdout.expected
1145 echo "U beta" >> $testroot/stdout.expected
1146 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1147 git_show_head $testroot/repo >> $testroot/stdout.expected
1148 echo >> $testroot/stdout.expected
1150 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1152 cmp -s $testroot/stdout.expected $testroot/stdout
1153 ret=$?
1154 if [ $ret -ne 0 ]; then
1155 diff -u $testroot/stdout.expected $testroot/stdout
1156 test_done "$testroot" "$ret"
1157 return 1
1160 echo "modified alpha" > $testroot/content.expected
1161 echo "modified beta" >> $testroot/content.expected
1163 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1164 cmp -s $testroot/content.expected $testroot/content
1165 ret=$?
1166 if [ $ret -ne 0 ]; then
1167 diff -u $testroot/content.expected $testroot/content
1168 test_done "$testroot" "$ret"
1169 return 1
1172 echo "U epsilon/zeta" > $testroot/stdout.expected
1173 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1174 git_show_head $testroot/repo >> $testroot/stdout.expected
1175 echo >> $testroot/stdout.expected
1177 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1179 cmp -s $testroot/stdout.expected $testroot/stdout
1180 ret=$?
1181 if [ $ret -ne 0 ]; then
1182 diff -u $testroot/stdout.expected $testroot/stdout
1183 test_done "$testroot" "$ret"
1184 return 1
1187 echo "modified epsilon/zeta" > $testroot/content.expected
1188 cat $testroot/wt/epsilon/zeta > $testroot/content
1190 cmp -s $testroot/content.expected $testroot/content
1191 ret=$?
1192 if [ $ret -ne 0 ]; then
1193 diff -u $testroot/content.expected $testroot/content
1194 test_done "$testroot" "$ret"
1195 return 1
1198 test_done "$testroot" "$ret"
1201 test_update_partial_add() {
1202 local testroot=`test_init update_partial_add`
1204 got checkout $testroot/repo $testroot/wt > /dev/null
1205 ret=$?
1206 if [ $ret -ne 0 ]; then
1207 test_done "$testroot" "$ret"
1208 return 1
1211 echo "new" > $testroot/repo/new
1212 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1213 (cd $testroot/repo && git add .)
1214 git_commit $testroot/repo -m "added two files"
1216 echo "A epsilon/new2" > $testroot/stdout.expected
1217 echo "A new" >> $testroot/stdout.expected
1218 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1219 git_show_head $testroot/repo >> $testroot/stdout.expected
1220 echo >> $testroot/stdout.expected
1222 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1224 cmp -s $testroot/stdout.expected $testroot/stdout
1225 ret=$?
1226 if [ $ret -ne 0 ]; then
1227 diff -u $testroot/stdout.expected $testroot/stdout
1228 test_done "$testroot" "$ret"
1229 return 1
1232 echo "new" > $testroot/content.expected
1233 echo "epsilon/new2" >> $testroot/content.expected
1235 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1237 cmp -s $testroot/content.expected $testroot/content
1238 ret=$?
1239 if [ $ret -ne 0 ]; then
1240 diff -u $testroot/content.expected $testroot/content
1242 test_done "$testroot" "$ret"
1245 test_update_partial_rm() {
1246 local testroot=`test_init update_partial_rm`
1248 got checkout $testroot/repo $testroot/wt > /dev/null
1249 ret=$?
1250 if [ $ret -ne 0 ]; then
1251 test_done "$testroot" "$ret"
1252 return 1
1255 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1256 git_commit $testroot/repo -m "removed two files"
1258 echo "got: /alpha: no such entry found in tree" \
1259 > $testroot/stderr.expected
1261 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1262 ret=$?
1263 if [ $ret -eq 0 ]; then
1264 echo "update succeeded unexpectedly" >&2
1265 test_done "$testroot" "1"
1266 return 1
1269 cmp -s $testroot/stderr.expected $testroot/stderr
1270 ret=$?
1271 if [ $ret -ne 0 ]; then
1272 diff -u $testroot/stderr.expected $testroot/stderr
1273 test_done "$testroot" "$ret"
1274 return 1
1276 test_done "$testroot" "$ret"
1279 test_update_partial_dir() {
1280 local testroot=`test_init update_partial_dir`
1282 got checkout $testroot/repo $testroot/wt > /dev/null
1283 ret=$?
1284 if [ $ret -ne 0 ]; then
1285 test_done "$testroot" "$ret"
1286 return 1
1289 echo "modified alpha" > $testroot/repo/alpha
1290 echo "modified beta" > $testroot/repo/beta
1291 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1292 git_commit $testroot/repo -m "modified two files"
1294 echo "U epsilon/zeta" > $testroot/stdout.expected
1295 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1296 git_show_head $testroot/repo >> $testroot/stdout.expected
1297 echo >> $testroot/stdout.expected
1299 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1301 cmp -s $testroot/stdout.expected $testroot/stdout
1302 ret=$?
1303 if [ $ret -ne 0 ]; then
1304 diff -u $testroot/stdout.expected $testroot/stdout
1305 test_done "$testroot" "$ret"
1306 return 1
1309 echo "modified epsilon/zeta" > $testroot/content.expected
1310 cat $testroot/wt/epsilon/zeta > $testroot/content
1312 cmp -s $testroot/content.expected $testroot/content
1313 ret=$?
1314 if [ $ret -ne 0 ]; then
1315 diff -u $testroot/content.expected $testroot/content
1316 test_done "$testroot" "$ret"
1317 return 1
1319 test_done "$testroot" "$ret"
1323 test_update_moved_branch_ref() {
1324 local testroot=`test_init update_moved_branch_ref`
1326 git clone -q --mirror $testroot/repo $testroot/repo2
1328 echo "modified alpha with git" > $testroot/repo/alpha
1329 git_commit $testroot/repo -m "modified alpha with git"
1331 got checkout $testroot/repo2 $testroot/wt > /dev/null
1332 ret=$?
1333 if [ $ret -ne 0 ]; then
1334 test_done "$testroot" "$ret"
1335 return 1
1338 echo "modified alpha with got" > $testroot/wt/alpha
1339 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1341 # + xxxxxxx...yyyyyyy master -> master (forced update)
1342 (cd $testroot/repo2 && git fetch -q --all)
1344 echo -n > $testroot/stdout.expected
1345 echo -n "got: work tree's head reference now points to a different " \
1346 > $testroot/stderr.expected
1347 echo "branch; new head reference and/or update -b required" \
1348 >> $testroot/stderr.expected
1350 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1352 cmp -s $testroot/stdout.expected $testroot/stdout
1353 ret=$?
1354 if [ $ret -ne 0 ]; then
1355 diff -u $testroot/stdout.expected $testroot/stdout
1356 test_done "$testroot" "$ret"
1357 return 1
1360 cmp -s $testroot/stderr.expected $testroot/stderr
1361 ret=$?
1362 if [ $ret -ne 0 ]; then
1363 diff -u $testroot/stderr.expected $testroot/stderr
1365 test_done "$testroot" "$ret"
1368 test_update_to_another_branch() {
1369 local testroot=`test_init update_to_another_branch`
1370 local base_commit=`git_show_head $testroot/repo`
1372 got checkout $testroot/repo $testroot/wt > /dev/null
1373 ret=$?
1374 if [ $ret -ne 0 ]; then
1375 test_done "$testroot" "$ret"
1376 return 1
1379 echo 'refs/heads/master'> $testroot/head-ref.expected
1380 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1381 ret=$?
1382 if [ $ret -ne 0 ]; then
1383 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1384 test_done "$testroot" "$ret"
1385 return 1
1388 (cd $testroot/repo && git checkout -q -b newbranch)
1389 echo "modified alpha on new branch" > $testroot/repo/alpha
1390 git_commit $testroot/repo -m "modified alpha on new branch"
1392 echo "modified alpha in work tree" > $testroot/wt/alpha
1394 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1395 echo "C alpha" >> $testroot/stdout.expected
1396 echo -n "Updated to refs/heads/newbranch: " >> $testroot/stdout.expected
1397 git_show_head $testroot/repo >> $testroot/stdout.expected
1398 echo >> $testroot/stdout.expected
1399 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1401 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1403 cmp -s $testroot/stdout.expected $testroot/stdout
1404 ret=$?
1405 if [ $ret -ne 0 ]; then
1406 diff -u $testroot/stdout.expected $testroot/stdout
1407 test_done "$testroot" "$ret"
1408 return 1
1411 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
1412 git_show_head $testroot/repo >> $testroot/content.expected
1413 echo >> $testroot/content.expected
1414 echo "modified alpha on new branch" >> $testroot/content.expected
1415 echo "||||||| 3-way merge base: commit $base_commit" \
1416 >> $testroot/content.expected
1417 echo "alpha" >> $testroot/content.expected
1418 echo "=======" >> $testroot/content.expected
1419 echo "modified alpha in work tree" >> $testroot/content.expected
1420 echo '>>>>>>>' >> $testroot/content.expected
1422 cat $testroot/wt/alpha > $testroot/content
1424 cmp -s $testroot/content.expected $testroot/content
1425 ret=$?
1426 if [ $ret -ne 0 ]; then
1427 diff -u $testroot/content.expected $testroot/content
1428 test_done "$testroot" "$ret"
1429 return 1
1432 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1433 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1434 ret=$?
1435 if [ $ret -ne 0 ]; then
1436 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1437 test_done "$testroot" "$ret"
1438 return 1
1441 test_done "$testroot" "$ret"
1444 test_update_to_commit_on_wrong_branch() {
1445 local testroot=`test_init update_to_commit_on_wrong_branch`
1447 got checkout $testroot/repo $testroot/wt > /dev/null
1448 ret=$?
1449 if [ $ret -ne 0 ]; then
1450 test_done "$testroot" "$ret"
1451 return 1
1454 (cd $testroot/repo && git checkout -q -b newbranch)
1455 echo "modified alpha on new branch" > $testroot/repo/alpha
1456 git_commit $testroot/repo -m "modified alpha on new branch"
1458 echo -n "" > $testroot/stdout.expected
1459 echo "got: target commit is on a different branch" \
1460 > $testroot/stderr.expected
1462 local head_rev=`git_show_head $testroot/repo`
1463 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1464 2> $testroot/stderr)
1466 cmp -s $testroot/stdout.expected $testroot/stdout
1467 ret=$?
1468 if [ $ret -ne 0 ]; then
1469 diff -u $testroot/stdout.expected $testroot/stdout
1470 test_done "$testroot" "$ret"
1471 return 1
1474 cmp -s $testroot/stderr.expected $testroot/stderr
1475 ret=$?
1476 if [ $ret -ne 0 ]; then
1477 diff -u $testroot/stderr.expected $testroot/stderr
1478 test_done "$testroot" "$ret"
1479 return 1
1482 test_done "$testroot" "$ret"
1485 test_update_bumps_base_commit_id() {
1486 local testroot=`test_init update_bumps_base_commit_id`
1488 echo "psi" > $testroot/repo/epsilon/psi
1489 (cd $testroot/repo && git add .)
1490 git_commit $testroot/repo -m "adding another file"
1492 got checkout $testroot/repo $testroot/wt > /dev/null
1493 ret=$?
1494 if [ $ret -ne 0 ]; then
1495 test_done "$testroot" "$ret"
1496 return 1
1499 echo "modified psi" > $testroot/wt/epsilon/psi
1500 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1502 local head_rev=`git_show_head $testroot/repo`
1503 echo "M epsilon/psi" > $testroot/stdout.expected
1504 echo "Created commit $head_rev" >> $testroot/stdout.expected
1505 cmp -s $testroot/stdout.expected $testroot/stdout
1506 ret=$?
1507 if [ $ret -ne 0 ]; then
1508 diff -u $testroot/stdout.expected $testroot/stdout
1509 test_done "$testroot" "$ret"
1510 return 1
1513 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1514 (cd $testroot/repo && git add .)
1515 git_commit $testroot/repo -m "changing zeta with git"
1517 echo "modified zeta" > $testroot/wt/epsilon/zeta
1518 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1519 2> $testroot/stderr)
1521 echo -n "" > $testroot/stdout.expected
1522 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1523 cmp -s $testroot/stderr.expected $testroot/stderr
1524 ret=$?
1525 if [ $ret -ne 0 ]; then
1526 diff -u $testroot/stderr.expected $testroot/stderr
1527 test_done "$testroot" "$ret"
1528 return 1
1531 (cd $testroot/wt && got update > $testroot/stdout)
1533 echo "U epsilon/psi" > $testroot/stdout.expected
1534 echo "C epsilon/zeta" >> $testroot/stdout.expected
1535 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1536 git_show_head $testroot/repo >> $testroot/stdout.expected
1537 echo >> $testroot/stdout.expected
1538 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1540 cmp -s $testroot/stdout.expected $testroot/stdout
1541 ret=$?
1542 if [ $ret -ne 0 ]; then
1543 diff -u $testroot/stdout.expected $testroot/stdout
1544 test_done "$testroot" "$ret"
1545 return 1
1548 # resolve conflict
1549 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1551 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1553 local head_rev=`git_show_head $testroot/repo`
1554 echo "M epsilon/zeta" > $testroot/stdout.expected
1555 echo "Created commit $head_rev" >> $testroot/stdout.expected
1556 cmp -s $testroot/stdout.expected $testroot/stdout
1557 ret=$?
1558 if [ $ret -ne 0 ]; then
1559 diff -u $testroot/stdout.expected $testroot/stdout
1560 test_done "$testroot" "$ret"
1561 return 1
1564 test_done "$testroot" "$ret"
1567 test_update_tag() {
1568 local testroot=`test_init update_tag`
1569 local tag="1.0.0"
1571 got checkout $testroot/repo $testroot/wt > /dev/null
1572 ret=$?
1573 if [ $ret -ne 0 ]; then
1574 test_done "$testroot" "$ret"
1575 return 1
1578 echo "modified alpha" > $testroot/repo/alpha
1579 git_commit $testroot/repo -m "modified alpha"
1580 (cd $testroot/repo && git tag -m "test" -a $tag)
1582 echo "U alpha" > $testroot/stdout.expected
1583 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1584 git_show_head $testroot/repo >> $testroot/stdout.expected
1585 echo >> $testroot/stdout.expected
1587 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1589 cmp -s $testroot/stdout.expected $testroot/stdout
1590 ret=$?
1591 if [ $ret -ne 0 ]; then
1592 diff -u $testroot/stdout.expected $testroot/stdout
1593 test_done "$testroot" "$ret"
1594 return 1
1597 echo "modified alpha" > $testroot/content.expected
1598 cat $testroot/wt/alpha > $testroot/content
1600 cmp -s $testroot/content.expected $testroot/content
1601 ret=$?
1602 if [ $ret -ne 0 ]; then
1603 diff -u $testroot/content.expected $testroot/content
1605 test_done "$testroot" "$ret"
1608 test_update_toggles_xbit() {
1609 local testroot=`test_init update_toggles_xbit 1`
1611 touch $testroot/repo/xfile
1612 chmod +x $testroot/repo/xfile
1613 (cd $testroot/repo && git add .)
1614 git_commit $testroot/repo -m "adding executable file"
1615 local commit_id1=`git_show_head $testroot/repo`
1617 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1618 ret=$?
1619 if [ $ret -ne 0 ]; then
1620 test_done "$testroot" "$ret"
1621 return 1
1624 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1625 ret=$?
1626 if [ $ret -ne 0 ]; then
1627 echo "file is not executable" >&2
1628 ls -l $testroot/wt/xfile >&2
1629 test_done "$testroot" "$ret"
1630 return 1
1633 chmod -x $testroot/wt/xfile
1634 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1635 local commit_id2=`git_show_head $testroot/repo`
1637 echo "U xfile" > $testroot/stdout.expected
1638 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1639 git_show_head $testroot/repo >> $testroot/stdout.expected
1640 echo >> $testroot/stdout.expected
1642 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1643 ret=$?
1644 if [ $ret -ne 0 ]; then
1645 test_done "$testroot" "$ret"
1646 return 1
1649 echo "U xfile" > $testroot/stdout.expected
1650 echo "Updated to refs/heads/master: $commit_id1" >> $testroot/stdout.expected
1651 cmp -s $testroot/stdout.expected $testroot/stdout
1652 ret=$?
1653 if [ $ret -ne 0 ]; then
1654 diff -u $testroot/stdout.expected $testroot/stdout
1655 test_done "$testroot" "$ret"
1656 return 1
1660 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1661 ret=$?
1662 if [ $ret -ne 0 ]; then
1663 echo "file is not executable" >&2
1664 ls -l $testroot/wt/xfile >&2
1665 test_done "$testroot" "$ret"
1666 return 1
1669 (cd $testroot/wt && got update > $testroot/stdout)
1670 ret=$?
1671 if [ $ret -ne 0 ]; then
1672 test_done "$testroot" "$ret"
1673 return 1
1676 echo "U xfile" > $testroot/stdout.expected
1677 echo "Updated to refs/heads/master: $commit_id2" \
1678 >> $testroot/stdout.expected
1679 cmp -s $testroot/stdout.expected $testroot/stdout
1680 ret=$?
1681 if [ $ret -ne 0 ]; then
1682 diff -u $testroot/stdout.expected $testroot/stdout
1683 test_done "$testroot" "$ret"
1684 return 1
1687 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1688 ret=$?
1689 if [ $ret -ne 0 ]; then
1690 echo "file is unexpectedly executable" >&2
1691 ls -l $testroot/wt/xfile >&2
1693 test_done "$testroot" "$ret"
1696 test_update_preserves_conflicted_file() {
1697 local testroot=`test_init update_preserves_conflicted_file`
1698 local commit_id0=`git_show_head $testroot/repo`
1700 echo "modified alpha" > $testroot/repo/alpha
1701 git_commit $testroot/repo -m "modified alpha"
1702 local commit_id1=`git_show_head $testroot/repo`
1704 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
1705 ret=$?
1706 if [ $ret -ne 0 ]; then
1707 test_done "$testroot" "$ret"
1708 return 1
1711 # fake a merge conflict
1712 echo '<<<<<<<' > $testroot/wt/alpha
1713 echo 'alpha' >> $testroot/wt/alpha
1714 echo '=======' >> $testroot/wt/alpha
1715 echo 'alpha, too' >> $testroot/wt/alpha
1716 echo '>>>>>>>' >> $testroot/wt/alpha
1717 cp $testroot/wt/alpha $testroot/content.expected
1719 echo "C alpha" > $testroot/stdout.expected
1720 (cd $testroot/wt && got status > $testroot/stdout)
1721 cmp -s $testroot/stdout.expected $testroot/stdout
1722 ret=$?
1723 if [ $ret -ne 0 ]; then
1724 diff -u $testroot/stdout.expected $testroot/stdout
1725 test_done "$testroot" "$ret"
1726 return 1
1729 echo "# alpha" > $testroot/stdout.expected
1730 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1731 git_show_head $testroot/repo >> $testroot/stdout.expected
1732 echo >> $testroot/stdout.expected
1733 echo "Files not updated because of existing merge conflicts: 1" \
1734 >> $testroot/stdout.expected
1735 (cd $testroot/wt && got update > $testroot/stdout)
1737 cmp -s $testroot/stdout.expected $testroot/stdout
1738 ret=$?
1739 if [ $ret -ne 0 ]; then
1740 diff -u $testroot/stdout.expected $testroot/stdout
1741 test_done "$testroot" "$ret"
1742 return 1
1745 cmp -s $testroot/content.expected $testroot/wt/alpha
1746 ret=$?
1747 if [ $ret -ne 0 ]; then
1748 diff -u $testroot/content.expected $testroot/wt/alpha
1750 test_done "$testroot" "$ret"
1753 test_update_modified_submodules() {
1754 local testroot=`test_init update_modified_submodules`
1756 make_single_file_repo $testroot/repo2 foo
1758 (cd $testroot/repo && git -c protocol.file.allow=always \
1759 submodule -q add ../repo2)
1760 (cd $testroot/repo && git commit -q -m 'adding submodule')
1762 got checkout $testroot/repo $testroot/wt > /dev/null
1764 echo "modified foo" > $testroot/repo2/foo
1765 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1767 # Update the repo/repo2 submodule link
1768 (cd $testroot/repo && git -C repo2 pull -q)
1769 (cd $testroot/repo && git add repo2)
1770 git_commit $testroot/repo -m "modified submodule link"
1772 # This update only records the new base commit. Otherwise it is a
1773 # no-op change because Got's file index does not track submodules.
1774 echo -n "Updated to refs/heads/master: " > $testroot/stdout.expected
1775 git_show_head $testroot/repo >> $testroot/stdout.expected
1776 echo >> $testroot/stdout.expected
1778 (cd $testroot/wt && got update > $testroot/stdout)
1780 cmp -s $testroot/stdout.expected $testroot/stdout
1781 ret=$?
1782 if [ $ret -ne 0 ]; then
1783 diff -u $testroot/stdout.expected $testroot/stdout
1785 test_done "$testroot" "$ret"
1788 test_update_adds_submodule() {
1789 local testroot=`test_init update_adds_submodule`
1791 got checkout $testroot/repo $testroot/wt > /dev/null
1793 make_single_file_repo $testroot/repo2 foo
1795 echo "modified foo" > $testroot/repo2/foo
1796 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1798 (cd $testroot/repo && git -c protocol.file.allow=always \
1799 submodule -q add ../repo2)
1800 (cd $testroot/repo && git commit -q -m 'adding submodule')
1802 echo "A .gitmodules" > $testroot/stdout.expected
1803 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1804 git_show_head $testroot/repo >> $testroot/stdout.expected
1805 echo >> $testroot/stdout.expected
1807 (cd $testroot/wt && got update > $testroot/stdout)
1809 cmp -s $testroot/stdout.expected $testroot/stdout
1810 ret=$?
1811 if [ $ret -ne 0 ]; then
1812 diff -u $testroot/stdout.expected $testroot/stdout
1814 test_done "$testroot" "$ret"
1817 test_update_conflict_wt_file_vs_repo_submodule() {
1818 local testroot=`test_init update_conflict_wt_file_vs_repo_submodule`
1820 got checkout $testroot/repo $testroot/wt > /dev/null
1822 make_single_file_repo $testroot/repo2 foo
1824 # Add a file which will clash with the submodule
1825 echo "This is a file called repo2" > $testroot/wt/repo2
1826 (cd $testroot/wt && got add repo2 > /dev/null)
1827 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
1828 ret=$?
1829 if [ $ret -ne 0 ]; then
1830 echo "commit failed unexpectedly" >&2
1831 test_done "$testroot" "1"
1832 return 1
1835 (cd $testroot/repo && git -c protocol.file.allow=always \
1836 submodule -q add ../repo2)
1837 (cd $testroot/repo && git commit -q -m 'adding submodule')
1839 # Modify the clashing file such that any modifications brought
1840 # in by 'got update' would require a merge.
1841 echo "This file was changed" > $testroot/wt/repo2
1843 # No conflict occurs because 'got update' ignores the submodule
1844 # and leaves the clashing file as it was.
1845 echo "A .gitmodules" > $testroot/stdout.expected
1846 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1847 git_show_head $testroot/repo >> $testroot/stdout.expected
1848 echo >> $testroot/stdout.expected
1850 (cd $testroot/wt && got update > $testroot/stdout)
1852 cmp -s $testroot/stdout.expected $testroot/stdout
1853 ret=$?
1854 if [ $ret -ne 0 ]; then
1855 diff -u $testroot/stdout.expected $testroot/stdout
1856 test_done "$testroot" "$ret"
1857 return 1
1860 (cd $testroot/wt && got status > $testroot/stdout)
1862 echo "M repo2" > $testroot/stdout.expected
1863 cmp -s $testroot/stdout.expected $testroot/stdout
1864 ret=$?
1865 if [ $ret -ne 0 ]; then
1866 diff -u $testroot/stdout.expected $testroot/stdout
1868 test_done "$testroot" "$ret"
1871 test_update_adds_symlink() {
1872 local testroot=`test_init update_adds_symlink`
1874 got checkout $testroot/repo $testroot/wt > /dev/null
1875 ret=$?
1876 if [ $ret -ne 0 ]; then
1877 echo "checkout failed unexpectedly" >&2
1878 test_done "$testroot" "$ret"
1879 return 1
1882 (cd $testroot/repo && ln -s alpha alpha.link)
1883 (cd $testroot/repo && ln -s epsilon epsilon.link)
1884 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1885 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1886 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1887 (cd $testroot/repo && git add .)
1888 git_commit $testroot/repo -m "add symlinks"
1890 echo "A alpha.link" > $testroot/stdout.expected
1891 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1892 echo "A epsilon.link" >> $testroot/stdout.expected
1893 echo "A nonexistent.link" >> $testroot/stdout.expected
1894 echo "A passwd.link" >> $testroot/stdout.expected
1895 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1896 git_show_head $testroot/repo >> $testroot/stdout.expected
1897 echo >> $testroot/stdout.expected
1899 (cd $testroot/wt && got update > $testroot/stdout)
1901 cmp -s $testroot/stdout.expected $testroot/stdout
1902 ret=$?
1903 if [ $ret -ne 0 ]; then
1904 diff -u $testroot/stdout.expected $testroot/stdout
1905 test_done "$testroot" "$ret"
1906 return 1
1909 if ! [ -h $testroot/wt/alpha.link ]; then
1910 echo "alpha.link is not a symlink"
1911 test_done "$testroot" "1"
1912 return 1
1915 readlink $testroot/wt/alpha.link > $testroot/stdout
1916 echo "alpha" > $testroot/stdout.expected
1917 cmp -s $testroot/stdout.expected $testroot/stdout
1918 ret=$?
1919 if [ $ret -ne 0 ]; then
1920 diff -u $testroot/stdout.expected $testroot/stdout
1921 test_done "$testroot" "$ret"
1922 return 1
1925 if ! [ -h $testroot/wt/epsilon.link ]; then
1926 echo "epsilon.link is not a symlink"
1927 test_done "$testroot" "1"
1928 return 1
1931 readlink $testroot/wt/epsilon.link > $testroot/stdout
1932 echo "epsilon" > $testroot/stdout.expected
1933 cmp -s $testroot/stdout.expected $testroot/stdout
1934 ret=$?
1935 if [ $ret -ne 0 ]; then
1936 diff -u $testroot/stdout.expected $testroot/stdout
1937 test_done "$testroot" "$ret"
1938 return 1
1941 if [ -h $testroot/wt/passwd.link ]; then
1942 echo -n "passwd.link symlink points outside of work tree: " >&2
1943 readlink $testroot/wt/passwd.link >&2
1944 test_done "$testroot" "1"
1945 return 1
1948 echo -n "/etc/passwd" > $testroot/content.expected
1949 cp $testroot/wt/passwd.link $testroot/content
1951 cmp -s $testroot/content.expected $testroot/content
1952 ret=$?
1953 if [ $ret -ne 0 ]; then
1954 diff -u $testroot/content.expected $testroot/content
1955 test_done "$testroot" "$ret"
1956 return 1
1959 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1960 echo "../beta" > $testroot/stdout.expected
1961 cmp -s $testroot/stdout.expected $testroot/stdout
1962 ret=$?
1963 if [ $ret -ne 0 ]; then
1964 diff -u $testroot/stdout.expected $testroot/stdout
1965 test_done "$testroot" "$ret"
1966 return 1
1969 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1970 echo "nonexistent" > $testroot/stdout.expected
1971 cmp -s $testroot/stdout.expected $testroot/stdout
1972 ret=$?
1973 if [ $ret -ne 0 ]; then
1974 diff -u $testroot/stdout.expected $testroot/stdout
1975 test_done "$testroot" "$ret"
1976 return 1
1979 # Updating an up-to-date symlink should be a no-op.
1980 echo 'Already up-to-date' > $testroot/stdout.expected
1981 (cd $testroot/wt && got update > $testroot/stdout)
1982 cmp -s $testroot/stdout.expected $testroot/stdout
1983 ret=$?
1984 if [ $ret -ne 0 ]; then
1985 diff -u $testroot/stdout.expected $testroot/stdout
1987 test_done "$testroot" "$ret"
1990 test_update_deletes_symlink() {
1991 local testroot=`test_init update_deletes_symlink`
1993 (cd $testroot/repo && ln -s alpha alpha.link)
1994 (cd $testroot/repo && git add .)
1995 git_commit $testroot/repo -m "add symlink"
1997 got checkout $testroot/repo $testroot/wt > /dev/null
1998 ret=$?
1999 if [ $ret -ne 0 ]; then
2000 echo "checkout failed unexpectedly" >&2
2001 test_done "$testroot" "$ret"
2002 return 1
2005 (cd $testroot/repo && git rm -q alpha.link)
2006 git_commit $testroot/repo -m "delete symlink"
2008 echo "D alpha.link" > $testroot/stdout.expected
2009 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2010 git_show_head $testroot/repo >> $testroot/stdout.expected
2011 echo >> $testroot/stdout.expected
2013 (cd $testroot/wt && got update > $testroot/stdout)
2015 cmp -s $testroot/stdout.expected $testroot/stdout
2016 ret=$?
2017 if [ $ret -ne 0 ]; then
2018 diff -u $testroot/stdout.expected $testroot/stdout
2019 test_done "$testroot" "$ret"
2020 return 1
2023 if [ -e $testroot/wt/alpha.link ]; then
2024 echo "alpha.link still exists on disk"
2025 test_done "$testroot" "1"
2026 return 1
2029 test_done "$testroot" "0"
2032 test_update_symlink_conflicts() {
2033 local testroot=`test_init update_symlink_conflicts`
2035 (cd $testroot/repo && ln -s alpha alpha.link)
2036 (cd $testroot/repo && ln -s epsilon epsilon.link)
2037 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2038 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2039 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2040 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
2041 (cd $testroot/repo && git add .)
2042 git_commit $testroot/repo -m "add symlinks"
2043 local commit_id1=`git_show_head $testroot/repo`
2045 got checkout $testroot/repo $testroot/wt > /dev/null
2046 ret=$?
2047 if [ $ret -ne 0 ]; then
2048 echo "checkout failed unexpectedly" >&2
2049 test_done "$testroot" "$ret"
2050 return 1
2053 (cd $testroot/repo && ln -sf beta alpha.link)
2054 (cd $testroot/repo && rm epsilon.link && ln -s gamma epsilon.link)
2055 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
2056 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
2057 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
2058 (cd $testroot/repo && git rm -q nonexistent.link)
2059 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
2060 (cd $testroot/repo && ln -sf alpha new.link)
2061 (cd $testroot/repo && git add .)
2062 git_commit $testroot/repo -m "change symlinks"
2063 local commit_id2=`git_show_head $testroot/repo`
2065 # modified symlink to file A vs modified symlink to file B
2066 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
2067 # modified symlink to dir A vs modified symlink to file B
2068 (cd $testroot/wt && rm epsilon.link && ln -s beta epsilon.link)
2069 # modeified symlink to file A vs modified symlink to dir B
2070 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
2071 epsilon/beta.link)
2072 # added regular file A vs added bad symlink to file A
2073 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
2074 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2075 # added bad symlink to file A vs added regular file A
2076 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
2077 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2078 # removed symlink to non-existent file A vs modified symlink
2079 # to nonexistent file B
2080 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
2081 # modified symlink to file A vs removed symlink to file A
2082 (cd $testroot/wt && got rm zeta.link > /dev/null)
2083 # added symlink to file A vs added symlink to file B
2084 (cd $testroot/wt && ln -sf beta new.link)
2085 (cd $testroot/wt && got add new.link > /dev/null)
2087 (cd $testroot/wt && got update > $testroot/stdout)
2089 echo "C alpha.link" >> $testroot/stdout.expected
2090 echo "C dotgotbar.link" >> $testroot/stdout.expected
2091 echo "C dotgotfoo.link" >> $testroot/stdout.expected
2092 echo "C epsilon/beta.link" >> $testroot/stdout.expected
2093 echo "C epsilon.link" >> $testroot/stdout.expected
2094 echo "C new.link" >> $testroot/stdout.expected
2095 echo "C nonexistent.link" >> $testroot/stdout.expected
2096 echo "G zeta.link" >> $testroot/stdout.expected
2097 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2098 git_show_head $testroot/repo >> $testroot/stdout.expected
2099 echo >> $testroot/stdout.expected
2100 echo "Files with new merge conflicts: 7" >> $testroot/stdout.expected
2102 cmp -s $testroot/stdout.expected $testroot/stdout
2103 ret=$?
2104 if [ $ret -ne 0 ]; then
2105 diff -u $testroot/stdout.expected $testroot/stdout
2106 test_done "$testroot" "$ret"
2107 return 1
2110 if [ -h $testroot/wt/alpha.link ]; then
2111 echo "alpha.link is a symlink"
2112 test_done "$testroot" "1"
2113 return 1
2116 echo "<<<<<<< merged change: commit $commit_id2" \
2117 > $testroot/content.expected
2118 echo "beta" >> $testroot/content.expected
2119 echo "3-way merge base: commit $commit_id1" \
2120 >> $testroot/content.expected
2121 echo "alpha" >> $testroot/content.expected
2122 echo "=======" >> $testroot/content.expected
2123 echo "gamma/delta" >> $testroot/content.expected
2124 echo '>>>>>>>' >> $testroot/content.expected
2125 echo -n "" >> $testroot/content.expected
2127 cp $testroot/wt/alpha.link $testroot/content
2128 cmp -s $testroot/content.expected $testroot/content
2129 ret=$?
2130 if [ $ret -ne 0 ]; then
2131 diff -u $testroot/content.expected $testroot/content
2132 test_done "$testroot" "$ret"
2133 return 1
2136 if [ -h $testroot/wt/epsilon.link ]; then
2137 echo "epsilon.link is a symlink"
2138 test_done "$testroot" "1"
2139 return 1
2142 echo "<<<<<<< merged change: commit $commit_id2" \
2143 > $testroot/content.expected
2144 echo "gamma" >> $testroot/content.expected
2145 echo "3-way merge base: commit $commit_id1" \
2146 >> $testroot/content.expected
2147 echo "epsilon" >> $testroot/content.expected
2148 echo "=======" >> $testroot/content.expected
2149 echo "beta" >> $testroot/content.expected
2150 echo '>>>>>>>' >> $testroot/content.expected
2151 echo -n "" >> $testroot/content.expected
2153 cp $testroot/wt/epsilon.link $testroot/content
2154 cmp -s $testroot/content.expected $testroot/content
2155 ret=$?
2156 if [ $ret -ne 0 ]; then
2157 diff -u $testroot/content.expected $testroot/content
2158 test_done "$testroot" "$ret"
2159 return 1
2162 if [ -h $testroot/wt/passwd.link ]; then
2163 echo -n "passwd.link symlink points outside of work tree: " >&2
2164 readlink $testroot/wt/passwd.link >&2
2165 test_done "$testroot" "1"
2166 return 1
2169 echo -n "/etc/passwd" > $testroot/content.expected
2170 cp $testroot/wt/passwd.link $testroot/content
2172 cmp -s $testroot/content.expected $testroot/content
2173 ret=$?
2174 if [ $ret -ne 0 ]; then
2175 diff -u $testroot/content.expected $testroot/content
2176 test_done "$testroot" "$ret"
2177 return 1
2180 if [ -h $testroot/wt/epsilon/beta.link ]; then
2181 echo "epsilon/beta.link is a symlink"
2182 test_done "$testroot" "1"
2183 return 1
2186 echo "<<<<<<< merged change: commit $commit_id2" \
2187 > $testroot/content.expected
2188 echo "../gamma/delta" >> $testroot/content.expected
2189 echo "3-way merge base: commit $commit_id1" \
2190 >> $testroot/content.expected
2191 echo "../beta" >> $testroot/content.expected
2192 echo "=======" >> $testroot/content.expected
2193 echo "../gamma" >> $testroot/content.expected
2194 echo '>>>>>>>' >> $testroot/content.expected
2195 echo -n "" >> $testroot/content.expected
2197 cp $testroot/wt/epsilon/beta.link $testroot/content
2198 cmp -s $testroot/content.expected $testroot/content
2199 ret=$?
2200 if [ $ret -ne 0 ]; then
2201 diff -u $testroot/content.expected $testroot/content
2202 test_done "$testroot" "$ret"
2203 return 1
2206 if [ -h $testroot/wt/nonexistent.link ]; then
2207 echo -n "nonexistent.link still exists on disk: " >&2
2208 readlink $testroot/wt/nonexistent.link >&2
2209 test_done "$testroot" "1"
2210 return 1
2213 echo "<<<<<<< merged change: commit $commit_id2" \
2214 > $testroot/content.expected
2215 echo "(symlink was deleted)" >> $testroot/content.expected
2216 echo "=======" >> $testroot/content.expected
2217 echo "nonexistent2" >> $testroot/content.expected
2218 echo '>>>>>>>' >> $testroot/content.expected
2219 echo -n "" >> $testroot/content.expected
2221 cp $testroot/wt/nonexistent.link $testroot/content
2222 cmp -s $testroot/content.expected $testroot/content
2223 ret=$?
2224 if [ $ret -ne 0 ]; then
2225 diff -u $testroot/content.expected $testroot/content
2226 test_done "$testroot" "$ret"
2227 return 1
2230 if [ -h $testroot/wt/dotgotfoo.link ]; then
2231 echo "dotgotfoo.link is a symlink"
2232 test_done "$testroot" "1"
2233 return 1
2236 echo "<<<<<<< merged change: commit $commit_id2" \
2237 > $testroot/content.expected
2238 echo "this is regular file foo" >> $testroot/content.expected
2239 echo "=======" >> $testroot/content.expected
2240 echo -n ".got/bar" >> $testroot/content.expected
2241 echo '>>>>>>>' >> $testroot/content.expected
2242 echo -n "" >> $testroot/content.expected
2244 cp $testroot/wt/dotgotfoo.link $testroot/content
2245 cmp -s $testroot/content.expected $testroot/content
2246 ret=$?
2247 if [ $ret -ne 0 ]; then
2248 diff -u $testroot/content.expected $testroot/content
2249 test_done "$testroot" "$ret"
2250 return 1
2253 if [ -h $testroot/wt/dotgotbar.link ]; then
2254 echo "dotgotbar.link is a symlink"
2255 test_done "$testroot" "1"
2256 return 1
2258 echo "<<<<<<< merged change: commit $commit_id2" \
2259 > $testroot/content.expected
2260 echo -n ".got/bar" >> $testroot/content.expected
2261 echo "=======" >> $testroot/content.expected
2262 echo "this is regular file bar" >> $testroot/content.expected
2263 echo '>>>>>>>' >> $testroot/content.expected
2264 echo -n "" >> $testroot/content.expected
2266 cp $testroot/wt/dotgotbar.link $testroot/content
2267 cmp -s $testroot/content.expected $testroot/content
2268 ret=$?
2269 if [ $ret -ne 0 ]; then
2270 diff -u $testroot/content.expected $testroot/content
2271 test_done "$testroot" "$ret"
2272 return 1
2275 if [ -h $testroot/wt/new.link ]; then
2276 echo "new.link is a symlink"
2277 test_done "$testroot" "1"
2278 return 1
2281 echo "<<<<<<< merged change: commit $commit_id2" \
2282 > $testroot/content.expected
2283 echo "alpha" >> $testroot/content.expected
2284 echo "=======" >> $testroot/content.expected
2285 echo "beta" >> $testroot/content.expected
2286 echo '>>>>>>>' >> $testroot/content.expected
2287 echo -n "" >> $testroot/content.expected
2289 cp $testroot/wt/new.link $testroot/content
2290 cmp -s $testroot/content.expected $testroot/content
2291 ret=$?
2292 if [ $ret -ne 0 ]; then
2293 diff -u $testroot/content.expected $testroot/content
2294 test_done "$testroot" "$ret"
2295 return 1
2298 echo "A dotgotfoo.link" > $testroot/stdout.expected
2299 echo "M new.link" >> $testroot/stdout.expected
2300 echo "D nonexistent.link" >> $testroot/stdout.expected
2301 (cd $testroot/wt && got status > $testroot/stdout)
2302 ret=$?
2303 if [ $ret -ne 0 ]; then
2304 diff -u $testroot/stdout.expected $testroot/stdout
2305 test_done "$testroot" "$ret"
2306 return 1
2309 test_done "$testroot" "0"
2313 test_update_single_file() {
2314 local testroot=`test_init update_single_file 1`
2316 echo c1 > $testroot/repo/c
2317 (cd $testroot/repo && git add .)
2318 git_commit $testroot/repo -m "adding file c"
2319 local commit_id1=`git_show_head $testroot/repo`
2321 echo a > $testroot/repo/a
2322 echo b > $testroot/repo/b
2323 echo c2 > $testroot/repo/c
2324 (cd $testroot/repo && git add .)
2325 git_commit $testroot/repo -m "add files a and b, change c"
2326 local commit_id2=`git_show_head $testroot/repo`
2328 (cd $testroot/repo && git rm -qf c)
2329 git_commit $testroot/repo -m "remove file c"
2330 local commit_id3=`git_show_head $testroot/repo`
2332 got checkout -c $commit_id2 $testroot/repo $testroot/wt > /dev/null
2333 ret=$?
2334 if [ $ret -ne 0 ]; then
2335 test_done "$testroot" "$ret"
2336 return 1
2339 echo "U c" > $testroot/stdout.expected
2340 echo "Updated to refs/heads/master: $commit_id1" \
2341 >> $testroot/stdout.expected
2343 (cd $testroot/wt && got update -c $commit_id1 c \
2344 > $testroot/stdout)
2346 cmp -s $testroot/stdout.expected $testroot/stdout
2347 ret=$?
2348 if [ $ret -ne 0 ]; then
2349 diff -u $testroot/stdout.expected $testroot/stdout
2350 test_done "$testroot" "$ret"
2351 return 1
2354 echo c1 > $testroot/content.expected
2355 cat $testroot/wt/c > $testroot/content
2357 cmp -s $testroot/content.expected $testroot/content
2358 ret=$?
2359 if [ $ret -ne 0 ]; then
2360 diff -u $testroot/content.expected $testroot/content
2361 test_done "$testroot" "$ret"
2362 return 1
2365 echo "U c" > $testroot/stdout.expected
2366 echo "Updated to refs/heads/master: $commit_id2" \
2367 >> $testroot/stdout.expected
2369 (cd $testroot/wt && got update -c $commit_id2 c > $testroot/stdout)
2371 cmp -s $testroot/stdout.expected $testroot/stdout
2372 ret=$?
2373 if [ $ret -ne 0 ]; then
2374 diff -u $testroot/stdout.expected $testroot/stdout
2375 test_done "$testroot" "$ret"
2376 return 1
2379 echo c2 > $testroot/content.expected
2380 cat $testroot/wt/c > $testroot/content
2382 cmp -s $testroot/content.expected $testroot/content
2383 ret=$?
2384 if [ $ret -ne 0 ]; then
2385 diff -u $testroot/content.expected $testroot/content
2386 test_done "$testroot" "$ret"
2387 return 1
2390 echo "D c" > $testroot/stdout.expected
2391 echo "Updated to refs/heads/master: $commit_id3" \
2392 >> $testroot/stdout.expected
2394 (cd $testroot/wt && got update -c $commit_id3 c \
2395 > $testroot/stdout 2> $testroot/stderr)
2397 echo "got: /c: no such entry found in tree" > $testroot/stderr.expected
2398 cmp -s $testroot/stderr.expected $testroot/stderr
2399 ret=$?
2400 if [ $ret -ne 0 ]; then
2401 diff -u $testroot/stderr.expected $testroot/stderr
2402 test_done "$testroot" "$ret"
2403 return 1
2406 echo -n > $testroot/stdout.expected
2407 cmp -s $testroot/stdout.expected $testroot/stdout
2408 ret=$?
2409 if [ $ret -ne 0 ]; then
2410 diff -u $testroot/stdout.expected $testroot/stdout
2411 test_done "$testroot" "$ret"
2412 return 1
2415 echo "D c" > $testroot/stdout.expected
2416 echo "Updated to refs/heads/master: $commit_id3" \
2417 >> $testroot/stdout.expected
2419 (cd $testroot/wt && got update -c $commit_id3 > $testroot/stdout)
2420 cmp -s $testroot/stdout.expected $testroot/stdout
2421 ret=$?
2422 if [ $ret -ne 0 ]; then
2423 diff -u $testroot/stdout.expected $testroot/stdout
2424 test_done "$testroot" "$ret"
2425 return 1
2428 if [ -e $testroot/wt/c ]; then
2429 echo "removed file c still exists on disk" >&2
2430 test_done "$testroot" "1"
2431 return 1
2434 test_done "$testroot" "0"
2435 return 0
2438 test_update_file_skipped_due_to_conflict() {
2439 local testroot=`test_init update_file_skipped_due_to_conflict`
2440 local commit_id0=`git_show_head $testroot/repo`
2441 blob_id0=`get_blob_id $testroot/repo "" beta`
2443 echo "changed beta" > $testroot/repo/beta
2444 git_commit $testroot/repo -m "changed beta"
2445 local commit_id1=`git_show_head $testroot/repo`
2446 blob_id1=`get_blob_id $testroot/repo "" beta`
2448 got checkout $testroot/repo $testroot/wt > /dev/null
2449 ret=$?
2450 if [ $ret -ne 0 ]; then
2451 test_done "$testroot" "$ret"
2452 return 1
2455 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2456 cut -d ':' -f 2 | tr -d ' ')`
2457 if [ "$blob_id" != "$blob_id1" ]; then
2458 echo "file beta has the wrong base blob ID" >&2
2459 test_done "$testroot" "1"
2460 return 1
2463 commit_id=`(cd $testroot/wt && got info beta | \
2464 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2465 if [ "$commit_id" != "$commit_id1" ]; then
2466 echo "file beta has the wrong base commit ID" >&2
2467 test_done "$testroot" "1"
2468 return 1
2471 echo "modified beta" > $testroot/wt/beta
2473 (cd $testroot/wt && got update -c $commit_id0 > $testroot/stdout)
2475 echo "C beta" > $testroot/stdout.expected
2476 echo "Updated to refs/heads/master: $commit_id0" \
2477 >> $testroot/stdout.expected
2478 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2479 cmp -s $testroot/stdout.expected $testroot/stdout
2480 ret=$?
2481 if [ $ret -ne 0 ]; then
2482 diff -u $testroot/stdout.expected $testroot/stdout
2483 test_done "$testroot" "$ret"
2484 return 1
2487 echo "<<<<<<< merged change: commit $commit_id0" \
2488 > $testroot/content.expected
2489 echo "beta" >> $testroot/content.expected
2490 echo "||||||| 3-way merge base: commit $commit_id1" \
2491 >> $testroot/content.expected
2492 echo "changed beta" >> $testroot/content.expected
2493 echo "=======" >> $testroot/content.expected
2494 echo "modified beta" >> $testroot/content.expected
2495 echo ">>>>>>>" >> $testroot/content.expected
2497 cat $testroot/wt/beta > $testroot/content
2499 cmp -s $testroot/content.expected $testroot/content
2500 ret=$?
2501 if [ $ret -ne 0 ]; then
2502 diff -u $testroot/content.expected $testroot/content
2503 test_done "$testroot" "$ret"
2504 return 1
2507 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2508 cut -d ':' -f 2 | tr -d ' ')`
2509 if [ "$blob_id" != "$blob_id0" ]; then
2510 echo "file beta has the wrong base blob ID" >&2
2511 test_done "$testroot" "1"
2512 return 1
2515 commit_id=`(cd $testroot/wt && got info beta | \
2516 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2517 if [ "$commit_id" != "$commit_id0" ]; then
2518 echo "file beta has the wrong base commit ID" >&2
2519 test_done "$testroot" "1"
2520 return 1
2523 # update to the latest commit again; this skips beta
2524 (cd $testroot/wt && got update > $testroot/stdout)
2525 echo "# beta" > $testroot/stdout.expected
2526 echo "Updated to refs/heads/master: $commit_id1" \
2527 >> $testroot/stdout.expected
2528 echo "Files not updated because of existing merge conflicts: 1" \
2529 >> $testroot/stdout.expected
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 # blob ID of beta should not have changed
2539 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2540 cut -d ':' -f 2 | tr -d ' ')`
2541 if [ "$blob_id" != "$blob_id0" ]; then
2542 echo "file beta has the wrong base blob ID" >&2
2543 test_done "$testroot" "1"
2544 return 1
2547 # commit ID of beta should not have changed; There was a bug
2548 # here where the commit ID had been changed even though the
2549 # file was not updated.
2550 commit_id=`(cd $testroot/wt && got info beta | \
2551 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2552 if [ "$commit_id" != "$commit_id0" ]; then
2553 echo "file beta has the wrong base commit ID: $commit_id" >&2
2554 test_done "$testroot" "1"
2555 return 1
2558 # beta is still conflicted and based on commit 0
2559 echo 'C beta' > $testroot/stdout.expected
2560 (cd $testroot/wt && got status > $testroot/stdout)
2561 cmp -s $testroot/stdout.expected $testroot/stdout
2562 ret=$?
2563 if [ $ret -ne 0 ]; then
2564 diff -u $testroot/stdout.expected $testroot/stdout
2565 test_done "$testroot" "$ret"
2566 return 1
2569 # resolve the conflict via revert
2570 (cd $testroot/wt && got revert beta >/dev/null)
2572 # beta now matches its base blob which is still from commit 0
2573 echo "beta" > $testroot/content.expected
2574 cat $testroot/wt/beta > $testroot/content
2575 cmp -s $testroot/content.expected $testroot/content
2576 ret=$?
2577 if [ $ret -ne 0 ]; then
2578 diff -u $testroot/content.expected $testroot/content
2579 test_done "$testroot" "$ret"
2580 return 1
2583 # updating to the latest commit should now update beta
2584 (cd $testroot/wt && got update > $testroot/stdout)
2585 echo "U beta" > $testroot/stdout.expected
2586 echo "Updated to refs/heads/master: $commit_id1" \
2587 >> $testroot/stdout.expected
2588 cmp -s $testroot/stdout.expected $testroot/stdout
2589 ret=$?
2590 if [ $ret -ne 0 ]; then
2591 diff -u $testroot/stdout.expected $testroot/stdout
2592 test_done "$testroot" "$ret"
2593 return 1
2596 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2597 cut -d ':' -f 2 | tr -d ' ')`
2598 if [ "$blob_id" != "$blob_id1" ]; then
2599 echo "file beta has the wrong base blob ID" >&2
2600 test_done "$testroot" "1"
2601 return 1
2604 commit_id=`(cd $testroot/wt && got info beta | \
2605 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2606 if [ "$commit_id" != "$commit_id1" ]; then
2607 echo "file beta has the wrong base commit ID: $commit_id" >&2
2608 test_done "$testroot" "1"
2609 return 1
2612 echo "changed beta" > $testroot/content.expected
2613 cat $testroot/wt/beta > $testroot/content
2614 cmp -s $testroot/content.expected $testroot/content
2615 ret=$?
2616 if [ $ret -ne 0 ]; then
2617 diff -u $testroot/content.expected $testroot/content
2619 test_done "$testroot" "$ret"
2622 test_update_file_skipped_due_to_obstruction() {
2623 local testroot=`test_init update_file_skipped_due_to_obstruction`
2624 local commit_id0=`git_show_head $testroot/repo`
2625 blob_id0=`get_blob_id $testroot/repo "" beta`
2627 echo "changed beta" > $testroot/repo/beta
2628 echo "new file" > $testroot/repo/new
2629 (cd $testroot/repo && git add new)
2630 git_commit $testroot/repo -m "changed beta"
2631 local commit_id1=`git_show_head $testroot/repo`
2632 blob_id1=`get_blob_id $testroot/repo "" beta`
2634 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
2635 ret=$?
2636 if [ $ret -ne 0 ]; then
2637 test_done "$testroot" "$ret"
2638 return 1
2641 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2642 cut -d ':' -f 2 | tr -d ' ')`
2643 if [ "$blob_id" != "$blob_id0" ]; then
2644 echo "file beta has the wrong base blob ID" >&2
2645 test_done "$testroot" "1"
2646 return 1
2649 commit_id=`(cd $testroot/wt && got info beta | \
2650 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2651 if [ "$commit_id" != "$commit_id0" ]; then
2652 echo "file beta has the wrong base commit ID" >&2
2653 test_done "$testroot" "1"
2654 return 1
2657 rm $testroot/wt/beta
2658 mkdir -p $testroot/wt/beta/psi
2659 mkdir -p $testroot/wt/new
2661 # update to the latest commit; this skips beta and the new file
2662 (cd $testroot/wt && got update > $testroot/stdout)
2663 ret=$?
2664 if [ $ret -ne 0 ]; then
2665 echo "update failed unexpectedly" >&2
2666 test_done "$testroot" "1"
2667 return 1
2670 echo "~ beta" > $testroot/stdout.expected
2671 echo "~ new" >> $testroot/stdout.expected
2672 echo "Updated to refs/heads/master: $commit_id1" \
2673 >> $testroot/stdout.expected
2674 echo "File paths obstructed by a non-regular file: 2" \
2675 >> $testroot/stdout.expected
2676 cmp -s $testroot/stdout.expected $testroot/stdout
2677 ret=$?
2678 if [ $ret -ne 0 ]; then
2679 diff -u $testroot/stdout.expected $testroot/stdout
2680 test_done "$testroot" "$ret"
2681 return 1
2684 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2685 cut -d ':' -f 2 | tr -d ' ')`
2686 if [ "$blob_id" != "$blob_id0" ]; then
2687 echo "file beta has the wrong base blob ID" >&2
2688 test_done "$testroot" "1"
2689 return 1
2692 commit_id=`(cd $testroot/wt && got info beta | \
2693 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2694 if [ "$commit_id" != "$commit_id0" ]; then
2695 echo "file beta has the wrong base commit ID" >&2
2696 test_done "$testroot" "1"
2697 return 1
2700 # remove the directory which obstructs file beta
2701 rm -r $testroot/wt/beta
2703 # updating to the latest commit should now update beta
2704 (cd $testroot/wt && got update > $testroot/stdout)
2705 echo "! beta" > $testroot/stdout.expected
2706 echo "~ new" >> $testroot/stdout.expected
2707 echo "Updated to refs/heads/master: $commit_id1" \
2708 >> $testroot/stdout.expected
2709 echo "File paths obstructed by a non-regular file: 1" \
2710 >> $testroot/stdout.expected
2711 cmp -s $testroot/stdout.expected $testroot/stdout
2712 ret=$?
2713 if [ $ret -ne 0 ]; then
2714 diff -u $testroot/stdout.expected $testroot/stdout
2715 test_done "$testroot" "$ret"
2716 return 1
2719 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2720 cut -d ':' -f 2 | tr -d ' ')`
2721 if [ "$blob_id" != "$blob_id1" ]; then
2722 echo "file beta has the wrong base blob ID" >&2
2723 test_done "$testroot" "1"
2724 return 1
2727 commit_id=`(cd $testroot/wt && got info beta | \
2728 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2729 if [ "$commit_id" != "$commit_id1" ]; then
2730 echo "file beta has the wrong base commit ID: $commit_id" >&2
2731 test_done "$testroot" "1"
2732 return 1
2735 echo "changed beta" > $testroot/content.expected
2736 cat $testroot/wt/beta > $testroot/content
2737 cmp -s $testroot/content.expected $testroot/content
2738 ret=$?
2739 if [ $ret -ne 0 ]; then
2740 diff -u $testroot/content.expected $testroot/content
2742 test_done "$testroot" "$ret"
2745 test_update_quiet() {
2746 local testroot=`test_init update_quiet`
2748 got checkout $testroot/repo $testroot/wt > /dev/null
2749 ret=$?
2750 if [ $ret -ne 0 ]; then
2751 test_done "$testroot" "$ret"
2752 return 1
2755 echo "modified alpha" > $testroot/repo/alpha
2756 git_commit $testroot/repo -m "modified alpha"
2758 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2759 git_show_head $testroot/repo >> $testroot/stdout.expected
2760 echo >> $testroot/stdout.expected
2762 (cd $testroot/wt && got update -q > $testroot/stdout)
2764 cmp -s $testroot/stdout.expected $testroot/stdout
2765 ret=$?
2766 if [ $ret -ne 0 ]; then
2767 diff -u $testroot/stdout.expected $testroot/stdout
2768 test_done "$testroot" "$ret"
2769 return 1
2772 echo "modified alpha" > $testroot/content.expected
2773 cat $testroot/wt/alpha > $testroot/content
2775 cmp -s $testroot/content.expected $testroot/content
2776 ret=$?
2777 if [ $ret -ne 0 ]; then
2778 diff -u $testroot/content.expected $testroot/content
2780 test_done "$testroot" "$ret"
2783 test_update_binary_file() {
2784 local testroot=`test_init update_binary_file`
2785 local commit_id0=`git_show_head $testroot/repo`
2787 got checkout $testroot/repo $testroot/wt > /dev/null
2788 ret=$?
2789 if [ $ret -ne 0 ]; then
2790 test_done "$testroot" "$ret"
2791 return 1
2794 cp /bin/ls $testroot/wt/foo
2795 chmod 755 $testroot/wt/foo
2796 (cd $testroot/wt && got add foo >/dev/null)
2797 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
2798 local commit_id1=`git_show_head $testroot/repo`
2800 cp /bin/cat $testroot/wt/foo
2801 chmod 755 $testroot/wt/foo
2802 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2803 local commit_id2=`git_show_head $testroot/repo`
2805 cp /bin/cp $testroot/wt/foo
2806 chmod 755 $testroot/wt/foo
2807 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2808 local commit_id3=`git_show_head $testroot/repo`
2810 (cd $testroot/wt && got rm foo >/dev/null)
2811 (cd $testroot/wt && got commit -m 'remove binary file' > /dev/null)
2812 local commit_id4=`git_show_head $testroot/repo`
2814 # backdate the work tree to make it usable for updating
2815 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2817 # update which adds a binary file
2818 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2820 echo "A foo" > $testroot/stdout.expected
2821 echo -n "Updated to refs/heads/master: $commit_id1" \
2822 >> $testroot/stdout.expected
2823 echo >> $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 cp /bin/ls $testroot/content.expected
2833 chmod 755 $testroot/content.expected
2834 cat $testroot/wt/foo > $testroot/content
2836 cmp -s $testroot/content.expected $testroot/content
2837 ret=$?
2838 if [ $ret -ne 0 ]; then
2839 diff -u $testroot/content.expected $testroot/content
2840 test_done "$testroot" "$ret"
2841 return 1
2844 # update which adds a conflicting binary file
2845 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2846 cp /bin/cat $testroot/wt/foo
2847 chmod 755 $testroot/wt/foo
2848 (cd $testroot/wt && got add foo > /dev/null)
2849 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2851 echo "C foo" > $testroot/stdout.expected
2852 echo "Updated to refs/heads/master: $commit_id1" \
2853 >> $testroot/stdout.expected
2854 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2855 cmp -s $testroot/stdout.expected $testroot/stdout
2856 ret=$?
2857 if [ $ret -ne 0 ]; then
2858 diff -u $testroot/stdout.expected $testroot/stdout
2859 test_done "$testroot" "$ret"
2860 return 1
2863 echo "Binary files differ and cannot be merged automatically:" \
2864 > $testroot/content.expected
2865 echo "<<<<<<< merged change: commit $commit_id1" \
2866 >> $testroot/content.expected
2867 echo -n "file " >> $testroot/content.expected
2868 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2869 echo '=======' >> $testroot/content.expected
2870 echo -n "file " >> $testroot/content.expected
2871 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2872 echo ">>>>>>>" >> $testroot/content.expected
2873 cat $testroot/wt/foo > $testroot/content
2875 cmp -s $testroot/content.expected $testroot/content
2876 ret=$?
2877 if [ $ret -ne 0 ]; then
2878 diff -u $testroot/content.expected $testroot/content
2879 test_done "$testroot" "$ret"
2880 return 1
2883 cp /bin/ls $testroot/content.expected
2884 chmod 755 $testroot/content.expected
2885 cat $testroot/wt/foo-1-* > $testroot/content
2887 cmp -s $testroot/content.expected $testroot/content
2888 ret=$?
2889 if [ $ret -ne 0 ]; then
2890 diff -u $testroot/content.expected $testroot/content
2891 test_done "$testroot" "$ret"
2892 return 1
2895 cp /bin/cat $testroot/content.expected
2896 chmod 755 $testroot/content.expected
2897 cat $testroot/wt/foo-2-* > $testroot/content
2899 cmp -s $testroot/content.expected $testroot/content
2900 ret=$?
2901 if [ $ret -ne 0 ]; then
2902 diff -u $testroot/content.expected $testroot/content
2903 test_done "$testroot" "$ret"
2904 return 1
2907 # tidy up
2908 (cd $testroot/wt && got revert -R . >/dev/null)
2909 rm $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2910 (cd $testroot/wt && got up -c $commit_id1 > /dev/null)
2912 # update which changes a binary file
2913 (cd $testroot/wt && got up -c $commit_id2 > $testroot/stdout)
2915 echo "U foo" > $testroot/stdout.expected
2916 echo -n "Updated to refs/heads/master: $commit_id2" \
2917 >> $testroot/stdout.expected
2918 echo >> $testroot/stdout.expected
2919 cmp -s $testroot/stdout.expected $testroot/stdout
2920 ret=$?
2921 if [ $ret -ne 0 ]; then
2922 diff -u $testroot/stdout.expected $testroot/stdout
2923 test_done "$testroot" "$ret"
2924 return 1
2927 cp /bin/cat $testroot/content.expected
2928 chmod 755 $testroot/content.expected
2929 cat $testroot/wt/foo > $testroot/content
2931 cmp -s $testroot/content.expected $testroot/content
2932 ret=$?
2933 if [ $ret -ne 0 ]; then
2934 diff -u $testroot/content.expected $testroot/content
2935 test_done "$testroot" "$ret"
2936 return 1
2939 # update which changes a locally modified binary file
2940 cp /bin/ls $testroot/wt/foo
2941 chmod 755 $testroot/wt/foo
2942 (cd $testroot/wt && got up -c $commit_id3 > $testroot/stdout)
2944 echo "C foo" > $testroot/stdout.expected
2945 echo -n "Updated to refs/heads/master: $commit_id3" \
2946 >> $testroot/stdout.expected
2947 echo >> $testroot/stdout.expected
2948 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2949 cmp -s $testroot/stdout.expected $testroot/stdout
2950 ret=$?
2951 if [ $ret -ne 0 ]; then
2952 diff -u $testroot/stdout.expected $testroot/stdout
2953 test_done "$testroot" "$ret"
2954 return 1
2957 echo "Binary files differ and cannot be merged automatically:" \
2958 > $testroot/content.expected
2959 echo "<<<<<<< merged change: commit $commit_id3" \
2960 >> $testroot/content.expected
2961 echo -n "file " >> $testroot/content.expected
2962 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2963 echo "||||||| 3-way merge base: commit $commit_id2" \
2964 >> $testroot/content.expected
2965 echo -n "file " >> $testroot/content.expected
2966 ls $testroot/wt/foo-orig-* >> $testroot/content.expected
2967 echo '=======' >> $testroot/content.expected
2968 echo -n "file " >> $testroot/content.expected
2969 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2970 echo ">>>>>>>" >> $testroot/content.expected
2971 cat $testroot/wt/foo > $testroot/content
2973 cmp -s $testroot/content.expected $testroot/content
2974 ret=$?
2975 if [ $ret -ne 0 ]; then
2976 diff -u $testroot/content.expected $testroot/content
2977 test_done "$testroot" "$ret"
2978 return 1
2981 cp /bin/cp $testroot/content.expected
2982 chmod 755 $testroot/content.expected
2983 cp $testroot/wt/foo-1-* $testroot/content
2984 cmp -s $testroot/content.expected $testroot/content
2985 ret=$?
2986 if [ $ret -ne 0 ]; then
2987 diff -u $testroot/content.expected $testroot/content
2988 test_done "$testroot" "$ret"
2989 return 1
2992 cp /bin/ls $testroot/content.expected
2993 chmod 755 $testroot/content.expected
2994 cp $testroot/wt/foo-2-* $testroot/content
2995 cmp -s $testroot/content.expected $testroot/content
2996 ret=$?
2997 if [ $ret -ne 0 ]; then
2998 diff -u $testroot/content.expected $testroot/content
2999 test_done "$testroot" "$ret"
3000 return 1
3003 (cd $testroot/wt && got status > $testroot/stdout)
3004 echo 'C foo' > $testroot/stdout.expected
3005 echo -n '? ' >> $testroot/stdout.expected
3006 (cd $testroot/wt && ls foo-1-* >> $testroot/stdout.expected)
3007 echo -n '? ' >> $testroot/stdout.expected
3008 (cd $testroot/wt && ls foo-2-* >> $testroot/stdout.expected)
3009 echo -n '? ' >> $testroot/stdout.expected
3010 (cd $testroot/wt && ls foo-orig-* >> $testroot/stdout.expected)
3011 cmp -s $testroot/stdout.expected $testroot/stdout
3012 ret=$?
3013 if [ $ret -ne 0 ]; then
3014 diff -u $testroot/stdout.expected $testroot/stdout
3015 test_done "$testroot" "$ret"
3016 return 1
3019 # tidy up
3020 (cd $testroot/wt && got revert -R . > /dev/null)
3021 rm $testroot/wt/foo-orig-* $testroot/wt/foo-1-* $testroot/wt/foo-2-*
3023 # update which deletes a binary file
3024 (cd $testroot/wt && got up -c $commit_id4 > $testroot/stdout)
3025 echo "D foo" > $testroot/stdout.expected
3026 echo -n "Updated to refs/heads/master: $commit_id4" \
3027 >> $testroot/stdout.expected
3028 echo >> $testroot/stdout.expected
3029 cmp -s $testroot/stdout.expected $testroot/stdout
3030 ret=$?
3031 if [ $ret -ne 0 ]; then
3032 diff -u $testroot/stdout.expected $testroot/stdout
3033 test_done "$testroot" "$ret"
3036 if [ -e $testroot/wt/foo ]; then
3037 echo "removed file foo still exists on disk" >&2
3038 test_done "$testroot" "1"
3039 return 1
3041 test_done "$testroot" "0"
3044 test_update_umask() {
3045 local testroot=`test_init update_binary_file`
3047 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
3048 ret=$?
3049 if [ $ret -ne 0 ]; then
3050 test_done "$testroot" "$ret"
3051 return 1
3054 rm "$testroot/wt/alpha"
3056 # using a subshell to avoid clobbering global umask
3057 (umask 022 && cd "$testroot/wt" && got update alpha) \
3058 >/dev/null 2>/dev/null
3059 ret=$?
3060 if [ $ret -ne 0 ]; then
3061 test_done "$testroot" $ret
3062 return 1
3065 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-r--r--; then
3066 echo "alpha is not 0644" >&2
3067 test_done "$testroot" 1
3068 return 1
3071 rm "$testroot/wt/alpha"
3073 # using a subshell to avoid clobbering global umask
3074 (umask 044 && cd "$testroot/wt" && got update alpha) \
3075 >/dev/null 2>/dev/null
3076 ret=$?
3077 if [ $ret -ne 0 ]; then
3078 test_done "$testroot" $ret
3079 return 1
3082 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
3083 echo "alpha is not 0600" >&2
3084 test_done "$testroot" 1
3085 return 1
3088 rm "$testroot/wt/alpha"
3090 # using a subshell to avoid clobbering global umask
3091 (umask 222 && cd "$testroot/wt" && got update alpha) \
3092 >/dev/null 2>/dev/null
3093 ret=$?
3094 if [ $ret -ne 0 ]; then
3095 test_done "$testroot" $ret
3096 return 1
3099 if ! ls -l "$testroot/wt/alpha" | grep -q ^-r--r--r--; then
3100 echo "alpha is not 0444" >&2
3101 test_done "$testroot" 1
3102 return 1;
3105 test_done "$testroot" 0
3108 test_parseargs "$@"
3109 run_test test_update_basic
3110 run_test test_update_adds_file
3111 run_test test_update_deletes_file
3112 run_test test_update_deletes_dir
3113 run_test test_update_deletes_dir_with_path_prefix
3114 run_test test_update_deletes_dir_recursively
3115 run_test test_update_sibling_dirs_with_common_prefix
3116 run_test test_update_dir_with_dot_sibling
3117 run_test test_update_moves_files_upwards
3118 run_test test_update_moves_files_to_new_dir
3119 run_test test_update_creates_missing_parent
3120 run_test test_update_creates_missing_parent_with_subdir
3121 run_test test_update_file_in_subsubdir
3122 run_test test_update_changes_file_to_dir
3123 run_test test_update_merges_file_edits
3124 run_test test_update_keeps_xbit
3125 run_test test_update_clears_xbit
3126 run_test test_update_restores_missing_file
3127 run_test test_update_conflict_wt_add_vs_repo_add
3128 run_test test_update_conflict_wt_edit_vs_repo_rm
3129 run_test test_update_conflict_wt_rm_vs_repo_edit
3130 run_test test_update_conflict_wt_rm_vs_repo_rm
3131 run_test test_update_partial
3132 run_test test_update_partial_add
3133 run_test test_update_partial_rm
3134 run_test test_update_partial_dir
3135 run_test test_update_moved_branch_ref
3136 run_test test_update_to_another_branch
3137 run_test test_update_to_commit_on_wrong_branch
3138 run_test test_update_bumps_base_commit_id
3139 run_test test_update_tag
3140 run_test test_update_toggles_xbit
3141 run_test test_update_preserves_conflicted_file
3142 run_test test_update_modified_submodules
3143 run_test test_update_adds_submodule
3144 run_test test_update_conflict_wt_file_vs_repo_submodule
3145 run_test test_update_adds_symlink
3146 run_test test_update_deletes_symlink
3147 run_test test_update_symlink_conflicts
3148 run_test test_update_single_file
3149 run_test test_update_file_skipped_due_to_conflict
3150 run_test test_update_file_skipped_due_to_obstruction
3151 run_test test_update_quiet
3152 run_test test_update_binary_file
3153 run_test test_update_umask