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 sed -i 's/2/22/' $testroot/repo/numbers
688 git_commit $testroot/repo -m "modified 3 files"
690 echo "modified alpha, too" > $testroot/wt/alpha
691 touch $testroot/wt/beta
692 sed -i 's/7/77/' $testroot/wt/numbers
694 echo "C alpha" > $testroot/stdout.expected
695 echo "U beta" >> $testroot/stdout.expected
696 echo "G numbers" >> $testroot/stdout.expected
697 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
698 git_show_head $testroot/repo >> $testroot/stdout.expected
699 echo >> $testroot/stdout.expected
700 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
702 (cd $testroot/wt && got update > $testroot/stdout)
704 cmp -s $testroot/stdout.expected $testroot/stdout
705 ret=$?
706 if [ $ret -ne 0 ]; then
707 diff -u $testroot/stdout.expected $testroot/stdout
708 test_done "$testroot" "$ret"
709 return 1
710 fi
712 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
713 git_show_head $testroot/repo >> $testroot/content.expected
714 echo >> $testroot/content.expected
715 echo "modified alpha" >> $testroot/content.expected
716 echo "||||||| 3-way merge base: commit $base_commit" \
717 >> $testroot/content.expected
718 echo "alpha" >> $testroot/content.expected
719 echo "=======" >> $testroot/content.expected
720 echo "modified alpha, too" >> $testroot/content.expected
721 echo '>>>>>>>' >> $testroot/content.expected
722 echo "modified beta" >> $testroot/content.expected
723 echo "1" >> $testroot/content.expected
724 echo "22" >> $testroot/content.expected
725 echo "3" >> $testroot/content.expected
726 echo "4" >> $testroot/content.expected
727 echo "5" >> $testroot/content.expected
728 echo "6" >> $testroot/content.expected
729 echo "77" >> $testroot/content.expected
730 echo "8" >> $testroot/content.expected
732 cat $testroot/wt/alpha > $testroot/content
733 cat $testroot/wt/beta >> $testroot/content
734 cat $testroot/wt/numbers >> $testroot/content
736 cmp -s $testroot/content.expected $testroot/content
737 ret=$?
738 if [ $ret -ne 0 ]; then
739 diff -u $testroot/content.expected $testroot/content
740 fi
741 test_done "$testroot" "$ret"
744 test_update_keeps_xbit() {
745 local testroot=`test_init update_keeps_xbit 1`
747 touch $testroot/repo/xfile
748 chmod +x $testroot/repo/xfile
749 (cd $testroot/repo && git add .)
750 git_commit $testroot/repo -m "adding executable file"
752 got checkout $testroot/repo $testroot/wt > $testroot/stdout
753 ret=$?
754 if [ $ret -ne 0 ]; then
755 test_done "$testroot" "$ret"
756 return 1
757 fi
759 echo foo > $testroot/repo/xfile
760 git_commit $testroot/repo -m "changed executable file"
762 echo "U xfile" > $testroot/stdout.expected
763 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
764 git_show_head $testroot/repo >> $testroot/stdout.expected
765 echo >> $testroot/stdout.expected
767 (cd $testroot/wt && got update > $testroot/stdout)
768 ret=$?
769 if [ $ret -ne 0 ]; then
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 cmp -s $testroot/stdout.expected $testroot/stdout
775 ret=$?
776 if [ $ret -ne 0 ]; then
777 diff -u $testroot/stdout.expected $testroot/stdout
778 test_done "$testroot" "$ret"
779 return 1
780 fi
782 ls -l $testroot/wt/xfile | grep -q '^-rwx'
783 ret=$?
784 if [ $ret -ne 0 ]; then
785 echo "file is not executable" >&2
786 ls -l $testroot/wt/xfile >&2
787 fi
788 test_done "$testroot" "$ret"
791 test_update_clears_xbit() {
792 local testroot=`test_init update_clears_xbit 1`
794 touch $testroot/repo/xfile
795 chmod +x $testroot/repo/xfile
796 (cd $testroot/repo && git add .)
797 git_commit $testroot/repo -m "adding executable file"
799 got checkout $testroot/repo $testroot/wt > $testroot/stdout
800 ret=$?
801 if [ $ret -ne 0 ]; then
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 ls -l $testroot/wt/xfile | grep -q '^-rwx'
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 echo "file is not executable" >&2
810 ls -l $testroot/wt/xfile >&2
811 test_done "$testroot" "$ret"
812 return 1
813 fi
815 # XXX git seems to require a file edit when flipping the x bit?
816 echo foo > $testroot/repo/xfile
817 chmod -x $testroot/repo/xfile
818 git_commit $testroot/repo -m "not an executable file anymore"
820 echo "U xfile" > $testroot/stdout.expected
821 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
822 git_show_head $testroot/repo >> $testroot/stdout.expected
823 echo >> $testroot/stdout.expected
825 (cd $testroot/wt && got update > $testroot/stdout)
826 ret=$?
827 if [ $ret -ne 0 ]; then
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 cmp -s $testroot/stdout.expected $testroot/stdout
833 ret=$?
834 if [ $ret -ne 0 ]; then
835 diff -u $testroot/stdout.expected $testroot/stdout
836 test_done "$testroot" "$ret"
837 return 1
838 fi
840 ls -l $testroot/wt/xfile | grep -q '^-rw-'
841 ret=$?
842 if [ $ret -ne 0 ]; then
843 echo "file is unexpectedly executable" >&2
844 ls -l $testroot/wt/xfile >&2
845 fi
846 test_done "$testroot" "$ret"
849 test_update_restores_missing_file() {
850 local testroot=`test_init update_restores_missing_file`
852 got checkout $testroot/repo $testroot/wt > /dev/null
853 ret=$?
854 if [ $ret -ne 0 ]; then
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 rm $testroot/wt/alpha
861 echo "! alpha" > $testroot/stdout.expected
862 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
863 git_show_head $testroot/repo >> $testroot/stdout.expected
864 echo >> $testroot/stdout.expected
865 (cd $testroot/wt && got update > $testroot/stdout)
867 cmp -s $testroot/stdout.expected $testroot/stdout
868 ret=$?
869 if [ $ret -ne 0 ]; then
870 diff -u $testroot/stdout.expected $testroot/stdout
871 test_done "$testroot" "$ret"
872 return 1
873 fi
875 echo "alpha" > $testroot/content.expected
877 cat $testroot/wt/alpha > $testroot/content
879 cmp -s $testroot/content.expected $testroot/content
880 ret=$?
881 if [ $ret -ne 0 ]; then
882 diff -u $testroot/content.expected $testroot/content
883 fi
884 test_done "$testroot" "$ret"
887 test_update_conflict_wt_add_vs_repo_add() {
888 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
890 got checkout $testroot/repo $testroot/wt > /dev/null
891 ret=$?
892 if [ $ret -ne 0 ]; then
893 test_done "$testroot" "$ret"
894 return 1
895 fi
897 echo "new" > $testroot/repo/gamma/new
898 (cd $testroot/repo && git add .)
899 git_commit $testroot/repo -m "adding a new file"
901 echo "also new" > $testroot/wt/gamma/new
902 (cd $testroot/wt && got add gamma/new >/dev/null)
904 (cd $testroot/wt && got update > $testroot/stdout)
906 echo "C gamma/new" > $testroot/stdout.expected
907 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
908 git_show_head $testroot/repo >> $testroot/stdout.expected
909 echo >> $testroot/stdout.expected
910 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
912 cmp -s $testroot/stdout.expected $testroot/stdout
913 ret=$?
914 if [ $ret -ne 0 ]; then
915 diff -u $testroot/stdout.expected $testroot/stdout
916 test_done "$testroot" "$ret"
917 return 1
918 fi
920 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
921 git_show_head $testroot/repo >> $testroot/content.expected
922 echo >> $testroot/content.expected
923 echo "new" >> $testroot/content.expected
924 echo "=======" >> $testroot/content.expected
925 echo "also new" >> $testroot/content.expected
926 echo '>>>>>>>' >> $testroot/content.expected
928 cat $testroot/wt/gamma/new > $testroot/content
930 cmp -s $testroot/content.expected $testroot/content
931 ret=$?
932 if [ $ret -ne 0 ]; then
933 diff -u $testroot/content.expected $testroot/content
934 test_done "$testroot" "$ret"
935 return 1
936 fi
938 # resolve the conflict
939 echo "new and also new" > $testroot/wt/gamma/new
940 echo 'M gamma/new' > $testroot/stdout.expected
941 (cd $testroot/wt && got status > $testroot/stdout)
942 cmp -s $testroot/stdout.expected $testroot/stdout
943 ret=$?
944 if [ $ret -ne 0 ]; then
945 diff -u $testroot/stdout.expected $testroot/stdout
946 fi
947 test_done "$testroot" "$ret"
950 test_update_conflict_wt_edit_vs_repo_rm() {
951 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
953 got checkout $testroot/repo $testroot/wt > /dev/null
954 ret=$?
955 if [ $ret -ne 0 ]; then
956 test_done "$testroot" "$ret"
957 return 1
958 fi
960 (cd $testroot/repo && git rm -q beta)
961 git_commit $testroot/repo -m "removing a file"
963 echo "modified beta" > $testroot/wt/beta
965 (cd $testroot/wt && got update > $testroot/stdout)
967 echo "G beta" > $testroot/stdout.expected
968 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
969 git_show_head $testroot/repo >> $testroot/stdout.expected
970 echo >> $testroot/stdout.expected
971 cmp -s $testroot/stdout.expected $testroot/stdout
972 ret=$?
973 if [ $ret -ne 0 ]; then
974 diff -u $testroot/stdout.expected $testroot/stdout
975 test_done "$testroot" "$ret"
976 return 1
977 fi
979 echo "modified beta" > $testroot/content.expected
981 cat $testroot/wt/beta > $testroot/content
983 cmp -s $testroot/content.expected $testroot/content
984 ret=$?
985 if [ $ret -ne 0 ]; then
986 diff -u $testroot/content.expected $testroot/content
987 test_done "$testroot" "$ret"
988 return 1
989 fi
991 # beta is now an added file... we don't flag tree conflicts yet
992 echo 'A beta' > $testroot/stdout.expected
993 (cd $testroot/wt && got status > $testroot/stdout)
994 cmp -s $testroot/stdout.expected $testroot/stdout
995 ret=$?
996 if [ $ret -ne 0 ]; then
997 diff -u $testroot/stdout.expected $testroot/stdout
998 fi
999 test_done "$testroot" "$ret"
1002 test_update_conflict_wt_rm_vs_repo_edit() {
1003 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
1005 got checkout $testroot/repo $testroot/wt > /dev/null
1006 ret=$?
1007 if [ $ret -ne 0 ]; then
1008 test_done "$testroot" "$ret"
1009 return 1
1012 echo "modified beta" > $testroot/repo/beta
1013 git_commit $testroot/repo -m "modified a file"
1015 (cd $testroot/wt && got rm beta > /dev/null)
1017 (cd $testroot/wt && got update > $testroot/stdout)
1019 echo "G beta" > $testroot/stdout.expected
1020 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1021 git_show_head $testroot/repo >> $testroot/stdout.expected
1022 echo >> $testroot/stdout.expected
1023 cmp -s $testroot/stdout.expected $testroot/stdout
1024 ret=$?
1025 if [ $ret -ne 0 ]; then
1026 diff -u $testroot/stdout.expected $testroot/stdout
1027 test_done "$testroot" "$ret"
1028 return 1
1031 # beta remains a deleted file... we don't flag tree conflicts yet
1032 echo 'D beta' > $testroot/stdout.expected
1033 (cd $testroot/wt && got status > $testroot/stdout)
1034 cmp -s $testroot/stdout.expected $testroot/stdout
1035 ret=$?
1036 if [ $ret -ne 0 ]; then
1037 diff -u $testroot/stdout.expected $testroot/stdout
1038 test_done "$testroot" "$ret"
1039 return 1
1042 # 'got diff' should show post-update contents of beta being deleted
1043 local head_rev=`git_show_head $testroot/repo`
1044 echo "diff $testroot/wt" > $testroot/stdout.expected
1045 echo "commit - $head_rev" >> $testroot/stdout.expected
1046 echo "path + $testroot/wt" >> $testroot/stdout.expected
1047 echo -n 'blob - ' >> $testroot/stdout.expected
1048 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1049 >> $testroot/stdout.expected
1050 echo 'file + /dev/null' >> $testroot/stdout.expected
1051 echo '--- beta' >> $testroot/stdout.expected
1052 echo '+++ /dev/null' >> $testroot/stdout.expected
1053 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1054 echo '-modified beta' >> $testroot/stdout.expected
1056 (cd $testroot/wt && got diff > $testroot/stdout)
1057 cmp -s $testroot/stdout.expected $testroot/stdout
1058 ret=$?
1059 if [ $ret -ne 0 ]; then
1060 diff -u $testroot/stdout.expected $testroot/stdout
1062 test_done "$testroot" "$ret"
1065 test_update_conflict_wt_rm_vs_repo_rm() {
1066 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1068 got checkout $testroot/repo $testroot/wt > /dev/null
1069 ret=$?
1070 if [ $ret -ne 0 ]; then
1071 test_done "$testroot" "$ret"
1072 return 1
1075 (cd $testroot/repo && git rm -q beta)
1076 git_commit $testroot/repo -m "removing a file"
1078 (cd $testroot/wt && got rm beta > /dev/null)
1080 (cd $testroot/wt && got update > $testroot/stdout)
1082 echo "D beta" > $testroot/stdout.expected
1083 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1084 git_show_head $testroot/repo >> $testroot/stdout.expected
1085 echo >> $testroot/stdout.expected
1086 cmp -s $testroot/stdout.expected $testroot/stdout
1087 ret=$?
1088 if [ $ret -ne 0 ]; then
1089 diff -u $testroot/stdout.expected $testroot/stdout
1090 test_done "$testroot" "$ret"
1091 return 1
1094 # beta is now gone... we don't flag tree conflicts yet
1095 echo "N beta" > $testroot/stdout.expected
1096 echo -n > $testroot/stderr.expected
1097 (cd $testroot/wt && got status beta > $testroot/stdout \
1098 2> $testroot/stderr)
1099 cmp -s $testroot/stdout.expected $testroot/stdout
1100 ret=$?
1101 if [ $ret -ne 0 ]; then
1102 diff -u $testroot/stdout.expected $testroot/stdout
1103 test_done "$testroot" "$ret"
1104 return 1
1106 cmp -s $testroot/stderr.expected $testroot/stderr
1107 ret=$?
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/stderr.expected $testroot/stderr
1110 test_done "$testroot" "$ret"
1111 return 1
1114 if [ -e $testroot/wt/beta ]; then
1115 echo "removed file beta still exists on disk" >&2
1116 test_done "$testroot" "1"
1117 return 1
1120 test_done "$testroot" "0"
1123 test_update_partial() {
1124 local testroot=`test_init update_partial`
1126 got checkout $testroot/repo $testroot/wt > /dev/null
1127 ret=$?
1128 if [ $ret -ne 0 ]; then
1129 test_done "$testroot" "$ret"
1130 return 1
1133 echo "modified alpha" > $testroot/repo/alpha
1134 echo "modified beta" > $testroot/repo/beta
1135 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1136 git_commit $testroot/repo -m "modified two files"
1138 echo "U alpha" > $testroot/stdout.expected
1139 echo "U beta" >> $testroot/stdout.expected
1140 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1141 git_show_head $testroot/repo >> $testroot/stdout.expected
1142 echo >> $testroot/stdout.expected
1144 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1146 cmp -s $testroot/stdout.expected $testroot/stdout
1147 ret=$?
1148 if [ $ret -ne 0 ]; then
1149 diff -u $testroot/stdout.expected $testroot/stdout
1150 test_done "$testroot" "$ret"
1151 return 1
1154 echo "modified alpha" > $testroot/content.expected
1155 echo "modified beta" >> $testroot/content.expected
1157 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1158 cmp -s $testroot/content.expected $testroot/content
1159 ret=$?
1160 if [ $ret -ne 0 ]; then
1161 diff -u $testroot/content.expected $testroot/content
1162 test_done "$testroot" "$ret"
1163 return 1
1166 echo "U epsilon/zeta" > $testroot/stdout.expected
1167 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1168 git_show_head $testroot/repo >> $testroot/stdout.expected
1169 echo >> $testroot/stdout.expected
1171 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1173 cmp -s $testroot/stdout.expected $testroot/stdout
1174 ret=$?
1175 if [ $ret -ne 0 ]; then
1176 diff -u $testroot/stdout.expected $testroot/stdout
1177 test_done "$testroot" "$ret"
1178 return 1
1181 echo "modified epsilon/zeta" > $testroot/content.expected
1182 cat $testroot/wt/epsilon/zeta > $testroot/content
1184 cmp -s $testroot/content.expected $testroot/content
1185 ret=$?
1186 if [ $ret -ne 0 ]; then
1187 diff -u $testroot/content.expected $testroot/content
1188 test_done "$testroot" "$ret"
1189 return 1
1192 test_done "$testroot" "$ret"
1195 test_update_partial_add() {
1196 local testroot=`test_init update_partial_add`
1198 got checkout $testroot/repo $testroot/wt > /dev/null
1199 ret=$?
1200 if [ $ret -ne 0 ]; then
1201 test_done "$testroot" "$ret"
1202 return 1
1205 echo "new" > $testroot/repo/new
1206 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1207 (cd $testroot/repo && git add .)
1208 git_commit $testroot/repo -m "added two files"
1210 echo "A epsilon/new2" > $testroot/stdout.expected
1211 echo "A new" >> $testroot/stdout.expected
1212 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1213 git_show_head $testroot/repo >> $testroot/stdout.expected
1214 echo >> $testroot/stdout.expected
1216 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1218 cmp -s $testroot/stdout.expected $testroot/stdout
1219 ret=$?
1220 if [ $ret -ne 0 ]; then
1221 diff -u $testroot/stdout.expected $testroot/stdout
1222 test_done "$testroot" "$ret"
1223 return 1
1226 echo "new" > $testroot/content.expected
1227 echo "epsilon/new2" >> $testroot/content.expected
1229 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1231 cmp -s $testroot/content.expected $testroot/content
1232 ret=$?
1233 if [ $ret -ne 0 ]; then
1234 diff -u $testroot/content.expected $testroot/content
1236 test_done "$testroot" "$ret"
1239 test_update_partial_rm() {
1240 local testroot=`test_init update_partial_rm`
1242 got checkout $testroot/repo $testroot/wt > /dev/null
1243 ret=$?
1244 if [ $ret -ne 0 ]; then
1245 test_done "$testroot" "$ret"
1246 return 1
1249 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1250 git_commit $testroot/repo -m "removed two files"
1252 echo "got: /alpha: no such entry found in tree" \
1253 > $testroot/stderr.expected
1255 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1256 ret=$?
1257 if [ $ret -eq 0 ]; then
1258 echo "update succeeded unexpectedly" >&2
1259 test_done "$testroot" "1"
1260 return 1
1263 cmp -s $testroot/stderr.expected $testroot/stderr
1264 ret=$?
1265 if [ $ret -ne 0 ]; then
1266 diff -u $testroot/stderr.expected $testroot/stderr
1267 test_done "$testroot" "$ret"
1268 return 1
1270 test_done "$testroot" "$ret"
1273 test_update_partial_dir() {
1274 local testroot=`test_init update_partial_dir`
1276 got checkout $testroot/repo $testroot/wt > /dev/null
1277 ret=$?
1278 if [ $ret -ne 0 ]; then
1279 test_done "$testroot" "$ret"
1280 return 1
1283 echo "modified alpha" > $testroot/repo/alpha
1284 echo "modified beta" > $testroot/repo/beta
1285 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1286 git_commit $testroot/repo -m "modified two files"
1288 echo "U epsilon/zeta" > $testroot/stdout.expected
1289 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1290 git_show_head $testroot/repo >> $testroot/stdout.expected
1291 echo >> $testroot/stdout.expected
1293 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1295 cmp -s $testroot/stdout.expected $testroot/stdout
1296 ret=$?
1297 if [ $ret -ne 0 ]; then
1298 diff -u $testroot/stdout.expected $testroot/stdout
1299 test_done "$testroot" "$ret"
1300 return 1
1303 echo "modified epsilon/zeta" > $testroot/content.expected
1304 cat $testroot/wt/epsilon/zeta > $testroot/content
1306 cmp -s $testroot/content.expected $testroot/content
1307 ret=$?
1308 if [ $ret -ne 0 ]; then
1309 diff -u $testroot/content.expected $testroot/content
1310 test_done "$testroot" "$ret"
1311 return 1
1313 test_done "$testroot" "$ret"
1317 test_update_moved_branch_ref() {
1318 local testroot=`test_init update_moved_branch_ref`
1320 git clone -q --mirror $testroot/repo $testroot/repo2
1322 echo "modified alpha with git" > $testroot/repo/alpha
1323 git_commit $testroot/repo -m "modified alpha with git"
1325 got checkout $testroot/repo2 $testroot/wt > /dev/null
1326 ret=$?
1327 if [ $ret -ne 0 ]; then
1328 test_done "$testroot" "$ret"
1329 return 1
1332 echo "modified alpha with got" > $testroot/wt/alpha
1333 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1335 # + xxxxxxx...yyyyyyy master -> master (forced update)
1336 (cd $testroot/repo2 && git fetch -q --all)
1338 echo -n > $testroot/stdout.expected
1339 echo -n "got: work tree's head reference now points to a different " \
1340 > $testroot/stderr.expected
1341 echo "branch; new head reference and/or update -b required" \
1342 >> $testroot/stderr.expected
1344 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1346 cmp -s $testroot/stdout.expected $testroot/stdout
1347 ret=$?
1348 if [ $ret -ne 0 ]; then
1349 diff -u $testroot/stdout.expected $testroot/stdout
1350 test_done "$testroot" "$ret"
1351 return 1
1354 cmp -s $testroot/stderr.expected $testroot/stderr
1355 ret=$?
1356 if [ $ret -ne 0 ]; then
1357 diff -u $testroot/stderr.expected $testroot/stderr
1359 test_done "$testroot" "$ret"
1362 test_update_to_another_branch() {
1363 local testroot=`test_init update_to_another_branch`
1364 local base_commit=`git_show_head $testroot/repo`
1366 got checkout $testroot/repo $testroot/wt > /dev/null
1367 ret=$?
1368 if [ $ret -ne 0 ]; then
1369 test_done "$testroot" "$ret"
1370 return 1
1373 echo 'refs/heads/master'> $testroot/head-ref.expected
1374 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1375 ret=$?
1376 if [ $ret -ne 0 ]; then
1377 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1378 test_done "$testroot" "$ret"
1379 return 1
1382 (cd $testroot/repo && git checkout -q -b newbranch)
1383 echo "modified alpha on new branch" > $testroot/repo/alpha
1384 git_commit $testroot/repo -m "modified alpha on new branch"
1386 echo "modified alpha in work tree" > $testroot/wt/alpha
1388 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1389 echo "C alpha" >> $testroot/stdout.expected
1390 echo -n "Updated to refs/heads/newbranch: " >> $testroot/stdout.expected
1391 git_show_head $testroot/repo >> $testroot/stdout.expected
1392 echo >> $testroot/stdout.expected
1393 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1395 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1397 cmp -s $testroot/stdout.expected $testroot/stdout
1398 ret=$?
1399 if [ $ret -ne 0 ]; then
1400 diff -u $testroot/stdout.expected $testroot/stdout
1401 test_done "$testroot" "$ret"
1402 return 1
1405 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
1406 git_show_head $testroot/repo >> $testroot/content.expected
1407 echo >> $testroot/content.expected
1408 echo "modified alpha on new branch" >> $testroot/content.expected
1409 echo "||||||| 3-way merge base: commit $base_commit" \
1410 >> $testroot/content.expected
1411 echo "alpha" >> $testroot/content.expected
1412 echo "=======" >> $testroot/content.expected
1413 echo "modified alpha in work tree" >> $testroot/content.expected
1414 echo '>>>>>>>' >> $testroot/content.expected
1416 cat $testroot/wt/alpha > $testroot/content
1418 cmp -s $testroot/content.expected $testroot/content
1419 ret=$?
1420 if [ $ret -ne 0 ]; then
1421 diff -u $testroot/content.expected $testroot/content
1422 test_done "$testroot" "$ret"
1423 return 1
1426 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1427 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1428 ret=$?
1429 if [ $ret -ne 0 ]; then
1430 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1431 test_done "$testroot" "$ret"
1432 return 1
1435 test_done "$testroot" "$ret"
1438 test_update_to_commit_on_wrong_branch() {
1439 local testroot=`test_init update_to_commit_on_wrong_branch`
1441 got checkout $testroot/repo $testroot/wt > /dev/null
1442 ret=$?
1443 if [ $ret -ne 0 ]; then
1444 test_done "$testroot" "$ret"
1445 return 1
1448 (cd $testroot/repo && git checkout -q -b newbranch)
1449 echo "modified alpha on new branch" > $testroot/repo/alpha
1450 git_commit $testroot/repo -m "modified alpha on new branch"
1452 echo -n "" > $testroot/stdout.expected
1453 echo "got: target commit is on a different branch" \
1454 > $testroot/stderr.expected
1456 local head_rev=`git_show_head $testroot/repo`
1457 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1458 2> $testroot/stderr)
1460 cmp -s $testroot/stdout.expected $testroot/stdout
1461 ret=$?
1462 if [ $ret -ne 0 ]; then
1463 diff -u $testroot/stdout.expected $testroot/stdout
1464 test_done "$testroot" "$ret"
1465 return 1
1468 cmp -s $testroot/stderr.expected $testroot/stderr
1469 ret=$?
1470 if [ $ret -ne 0 ]; then
1471 diff -u $testroot/stderr.expected $testroot/stderr
1472 test_done "$testroot" "$ret"
1473 return 1
1476 test_done "$testroot" "$ret"
1479 test_update_bumps_base_commit_id() {
1480 local testroot=`test_init update_bumps_base_commit_id`
1482 echo "psi" > $testroot/repo/epsilon/psi
1483 (cd $testroot/repo && git add .)
1484 git_commit $testroot/repo -m "adding another file"
1486 got checkout $testroot/repo $testroot/wt > /dev/null
1487 ret=$?
1488 if [ $ret -ne 0 ]; then
1489 test_done "$testroot" "$ret"
1490 return 1
1493 echo "modified psi" > $testroot/wt/epsilon/psi
1494 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1496 local head_rev=`git_show_head $testroot/repo`
1497 echo "M epsilon/psi" > $testroot/stdout.expected
1498 echo "Created commit $head_rev" >> $testroot/stdout.expected
1499 cmp -s $testroot/stdout.expected $testroot/stdout
1500 ret=$?
1501 if [ $ret -ne 0 ]; then
1502 diff -u $testroot/stdout.expected $testroot/stdout
1503 test_done "$testroot" "$ret"
1504 return 1
1507 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1508 (cd $testroot/repo && git add .)
1509 git_commit $testroot/repo -m "changing zeta with git"
1511 echo "modified zeta" > $testroot/wt/epsilon/zeta
1512 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1513 2> $testroot/stderr)
1515 echo -n "" > $testroot/stdout.expected
1516 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1517 cmp -s $testroot/stderr.expected $testroot/stderr
1518 ret=$?
1519 if [ $ret -ne 0 ]; then
1520 diff -u $testroot/stderr.expected $testroot/stderr
1521 test_done "$testroot" "$ret"
1522 return 1
1525 (cd $testroot/wt && got update > $testroot/stdout)
1527 echo "U epsilon/psi" > $testroot/stdout.expected
1528 echo "C epsilon/zeta" >> $testroot/stdout.expected
1529 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1530 git_show_head $testroot/repo >> $testroot/stdout.expected
1531 echo >> $testroot/stdout.expected
1532 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1534 cmp -s $testroot/stdout.expected $testroot/stdout
1535 ret=$?
1536 if [ $ret -ne 0 ]; then
1537 diff -u $testroot/stdout.expected $testroot/stdout
1538 test_done "$testroot" "$ret"
1539 return 1
1542 # resolve conflict
1543 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1545 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1547 local head_rev=`git_show_head $testroot/repo`
1548 echo "M epsilon/zeta" > $testroot/stdout.expected
1549 echo "Created commit $head_rev" >> $testroot/stdout.expected
1550 cmp -s $testroot/stdout.expected $testroot/stdout
1551 ret=$?
1552 if [ $ret -ne 0 ]; then
1553 diff -u $testroot/stdout.expected $testroot/stdout
1554 test_done "$testroot" "$ret"
1555 return 1
1558 test_done "$testroot" "$ret"
1561 test_update_tag() {
1562 local testroot=`test_init update_tag`
1563 local tag="1.0.0"
1565 got checkout $testroot/repo $testroot/wt > /dev/null
1566 ret=$?
1567 if [ $ret -ne 0 ]; then
1568 test_done "$testroot" "$ret"
1569 return 1
1572 echo "modified alpha" > $testroot/repo/alpha
1573 git_commit $testroot/repo -m "modified alpha"
1574 (cd $testroot/repo && git tag -m "test" -a $tag)
1576 echo "U alpha" > $testroot/stdout.expected
1577 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1578 git_show_head $testroot/repo >> $testroot/stdout.expected
1579 echo >> $testroot/stdout.expected
1581 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1583 cmp -s $testroot/stdout.expected $testroot/stdout
1584 ret=$?
1585 if [ $ret -ne 0 ]; then
1586 diff -u $testroot/stdout.expected $testroot/stdout
1587 test_done "$testroot" "$ret"
1588 return 1
1591 echo "modified alpha" > $testroot/content.expected
1592 cat $testroot/wt/alpha > $testroot/content
1594 cmp -s $testroot/content.expected $testroot/content
1595 ret=$?
1596 if [ $ret -ne 0 ]; then
1597 diff -u $testroot/content.expected $testroot/content
1599 test_done "$testroot" "$ret"
1602 test_update_toggles_xbit() {
1603 local testroot=`test_init update_toggles_xbit 1`
1605 touch $testroot/repo/xfile
1606 chmod +x $testroot/repo/xfile
1607 (cd $testroot/repo && git add .)
1608 git_commit $testroot/repo -m "adding executable file"
1609 local commit_id1=`git_show_head $testroot/repo`
1611 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1612 ret=$?
1613 if [ $ret -ne 0 ]; then
1614 test_done "$testroot" "$ret"
1615 return 1
1618 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1619 ret=$?
1620 if [ $ret -ne 0 ]; then
1621 echo "file is not executable" >&2
1622 ls -l $testroot/wt/xfile >&2
1623 test_done "$testroot" "$ret"
1624 return 1
1627 chmod -x $testroot/wt/xfile
1628 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1629 local commit_id2=`git_show_head $testroot/repo`
1631 echo "U xfile" > $testroot/stdout.expected
1632 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1633 git_show_head $testroot/repo >> $testroot/stdout.expected
1634 echo >> $testroot/stdout.expected
1636 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1637 ret=$?
1638 if [ $ret -ne 0 ]; then
1639 test_done "$testroot" "$ret"
1640 return 1
1643 echo "U xfile" > $testroot/stdout.expected
1644 echo "Updated to refs/heads/master: $commit_id1" >> $testroot/stdout.expected
1645 cmp -s $testroot/stdout.expected $testroot/stdout
1646 ret=$?
1647 if [ $ret -ne 0 ]; then
1648 diff -u $testroot/stdout.expected $testroot/stdout
1649 test_done "$testroot" "$ret"
1650 return 1
1654 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1655 ret=$?
1656 if [ $ret -ne 0 ]; then
1657 echo "file is not executable" >&2
1658 ls -l $testroot/wt/xfile >&2
1659 test_done "$testroot" "$ret"
1660 return 1
1663 (cd $testroot/wt && got update > $testroot/stdout)
1664 ret=$?
1665 if [ $ret -ne 0 ]; then
1666 test_done "$testroot" "$ret"
1667 return 1
1670 echo "U xfile" > $testroot/stdout.expected
1671 echo "Updated to refs/heads/master: $commit_id2" \
1672 >> $testroot/stdout.expected
1673 cmp -s $testroot/stdout.expected $testroot/stdout
1674 ret=$?
1675 if [ $ret -ne 0 ]; then
1676 diff -u $testroot/stdout.expected $testroot/stdout
1677 test_done "$testroot" "$ret"
1678 return 1
1681 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1682 ret=$?
1683 if [ $ret -ne 0 ]; then
1684 echo "file is unexpectedly executable" >&2
1685 ls -l $testroot/wt/xfile >&2
1687 test_done "$testroot" "$ret"
1690 test_update_preserves_conflicted_file() {
1691 local testroot=`test_init update_preserves_conflicted_file`
1692 local commit_id0=`git_show_head $testroot/repo`
1694 echo "modified alpha" > $testroot/repo/alpha
1695 git_commit $testroot/repo -m "modified alpha"
1696 local commit_id1=`git_show_head $testroot/repo`
1698 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
1699 ret=$?
1700 if [ $ret -ne 0 ]; then
1701 test_done "$testroot" "$ret"
1702 return 1
1705 # fake a merge conflict
1706 echo '<<<<<<<' > $testroot/wt/alpha
1707 echo 'alpha' >> $testroot/wt/alpha
1708 echo '=======' >> $testroot/wt/alpha
1709 echo 'alpha, too' >> $testroot/wt/alpha
1710 echo '>>>>>>>' >> $testroot/wt/alpha
1711 cp $testroot/wt/alpha $testroot/content.expected
1713 echo "C alpha" > $testroot/stdout.expected
1714 (cd $testroot/wt && got status > $testroot/stdout)
1715 cmp -s $testroot/stdout.expected $testroot/stdout
1716 ret=$?
1717 if [ $ret -ne 0 ]; then
1718 diff -u $testroot/stdout.expected $testroot/stdout
1719 test_done "$testroot" "$ret"
1720 return 1
1723 echo "# alpha" > $testroot/stdout.expected
1724 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1725 git_show_head $testroot/repo >> $testroot/stdout.expected
1726 echo >> $testroot/stdout.expected
1727 echo "Files not updated because of existing merge conflicts: 1" \
1728 >> $testroot/stdout.expected
1729 (cd $testroot/wt && got update > $testroot/stdout)
1731 cmp -s $testroot/stdout.expected $testroot/stdout
1732 ret=$?
1733 if [ $ret -ne 0 ]; then
1734 diff -u $testroot/stdout.expected $testroot/stdout
1735 test_done "$testroot" "$ret"
1736 return 1
1739 cmp -s $testroot/content.expected $testroot/wt/alpha
1740 ret=$?
1741 if [ $ret -ne 0 ]; then
1742 diff -u $testroot/content.expected $testroot/wt/alpha
1744 test_done "$testroot" "$ret"
1747 test_update_modified_submodules() {
1748 local testroot=`test_init update_modified_submodules`
1750 make_single_file_repo $testroot/repo2 foo
1752 (cd $testroot/repo && git -c protocol.file.allow=always \
1753 submodule -q add ../repo2)
1754 (cd $testroot/repo && git commit -q -m 'adding submodule')
1756 got checkout $testroot/repo $testroot/wt > /dev/null
1758 echo "modified foo" > $testroot/repo2/foo
1759 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1761 # Update the repo/repo2 submodule link
1762 (cd $testroot/repo && git -C repo2 pull -q)
1763 (cd $testroot/repo && git add repo2)
1764 git_commit $testroot/repo -m "modified submodule link"
1766 # This update only records the new base commit. Otherwise it is a
1767 # no-op change because Got's file index does not track submodules.
1768 echo -n "Updated to refs/heads/master: " > $testroot/stdout.expected
1769 git_show_head $testroot/repo >> $testroot/stdout.expected
1770 echo >> $testroot/stdout.expected
1772 (cd $testroot/wt && got update > $testroot/stdout)
1774 cmp -s $testroot/stdout.expected $testroot/stdout
1775 ret=$?
1776 if [ $ret -ne 0 ]; then
1777 diff -u $testroot/stdout.expected $testroot/stdout
1779 test_done "$testroot" "$ret"
1782 test_update_adds_submodule() {
1783 local testroot=`test_init update_adds_submodule`
1785 got checkout $testroot/repo $testroot/wt > /dev/null
1787 make_single_file_repo $testroot/repo2 foo
1789 echo "modified foo" > $testroot/repo2/foo
1790 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1792 (cd $testroot/repo && git -c protocol.file.allow=always \
1793 submodule -q add ../repo2)
1794 (cd $testroot/repo && git commit -q -m 'adding submodule')
1796 echo "A .gitmodules" > $testroot/stdout.expected
1797 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1798 git_show_head $testroot/repo >> $testroot/stdout.expected
1799 echo >> $testroot/stdout.expected
1801 (cd $testroot/wt && got update > $testroot/stdout)
1803 cmp -s $testroot/stdout.expected $testroot/stdout
1804 ret=$?
1805 if [ $ret -ne 0 ]; then
1806 diff -u $testroot/stdout.expected $testroot/stdout
1808 test_done "$testroot" "$ret"
1811 test_update_conflict_wt_file_vs_repo_submodule() {
1812 local testroot=`test_init update_conflict_wt_file_vs_repo_submodule`
1814 got checkout $testroot/repo $testroot/wt > /dev/null
1816 make_single_file_repo $testroot/repo2 foo
1818 # Add a file which will clash with the submodule
1819 echo "This is a file called repo2" > $testroot/wt/repo2
1820 (cd $testroot/wt && got add repo2 > /dev/null)
1821 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
1822 ret=$?
1823 if [ $ret -ne 0 ]; then
1824 echo "commit failed unexpectedly" >&2
1825 test_done "$testroot" "1"
1826 return 1
1829 (cd $testroot/repo && git -c protocol.file.allow=always \
1830 submodule -q add ../repo2)
1831 (cd $testroot/repo && git commit -q -m 'adding submodule')
1833 # Modify the clashing file such that any modifications brought
1834 # in by 'got update' would require a merge.
1835 echo "This file was changed" > $testroot/wt/repo2
1837 # No conflict occurs because 'got update' ignores the submodule
1838 # and leaves the clashing file as it was.
1839 echo "A .gitmodules" > $testroot/stdout.expected
1840 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1841 git_show_head $testroot/repo >> $testroot/stdout.expected
1842 echo >> $testroot/stdout.expected
1844 (cd $testroot/wt && got update > $testroot/stdout)
1846 cmp -s $testroot/stdout.expected $testroot/stdout
1847 ret=$?
1848 if [ $ret -ne 0 ]; then
1849 diff -u $testroot/stdout.expected $testroot/stdout
1850 test_done "$testroot" "$ret"
1851 return 1
1854 (cd $testroot/wt && got status > $testroot/stdout)
1856 echo "M repo2" > $testroot/stdout.expected
1857 cmp -s $testroot/stdout.expected $testroot/stdout
1858 ret=$?
1859 if [ $ret -ne 0 ]; then
1860 diff -u $testroot/stdout.expected $testroot/stdout
1862 test_done "$testroot" "$ret"
1865 test_update_adds_symlink() {
1866 local testroot=`test_init update_adds_symlink`
1868 got checkout $testroot/repo $testroot/wt > /dev/null
1869 ret=$?
1870 if [ $ret -ne 0 ]; then
1871 echo "checkout failed unexpectedly" >&2
1872 test_done "$testroot" "$ret"
1873 return 1
1876 (cd $testroot/repo && ln -s alpha alpha.link)
1877 (cd $testroot/repo && ln -s epsilon epsilon.link)
1878 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1879 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1880 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1881 (cd $testroot/repo && git add .)
1882 git_commit $testroot/repo -m "add symlinks"
1884 echo "A alpha.link" > $testroot/stdout.expected
1885 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1886 echo "A epsilon.link" >> $testroot/stdout.expected
1887 echo "A nonexistent.link" >> $testroot/stdout.expected
1888 echo "A passwd.link" >> $testroot/stdout.expected
1889 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
1890 git_show_head $testroot/repo >> $testroot/stdout.expected
1891 echo >> $testroot/stdout.expected
1893 (cd $testroot/wt && got update > $testroot/stdout)
1895 cmp -s $testroot/stdout.expected $testroot/stdout
1896 ret=$?
1897 if [ $ret -ne 0 ]; then
1898 diff -u $testroot/stdout.expected $testroot/stdout
1899 test_done "$testroot" "$ret"
1900 return 1
1903 if ! [ -h $testroot/wt/alpha.link ]; then
1904 echo "alpha.link is not a symlink"
1905 test_done "$testroot" "1"
1906 return 1
1909 readlink $testroot/wt/alpha.link > $testroot/stdout
1910 echo "alpha" > $testroot/stdout.expected
1911 cmp -s $testroot/stdout.expected $testroot/stdout
1912 ret=$?
1913 if [ $ret -ne 0 ]; then
1914 diff -u $testroot/stdout.expected $testroot/stdout
1915 test_done "$testroot" "$ret"
1916 return 1
1919 if ! [ -h $testroot/wt/epsilon.link ]; then
1920 echo "epsilon.link is not a symlink"
1921 test_done "$testroot" "1"
1922 return 1
1925 readlink $testroot/wt/epsilon.link > $testroot/stdout
1926 echo "epsilon" > $testroot/stdout.expected
1927 cmp -s $testroot/stdout.expected $testroot/stdout
1928 ret=$?
1929 if [ $ret -ne 0 ]; then
1930 diff -u $testroot/stdout.expected $testroot/stdout
1931 test_done "$testroot" "$ret"
1932 return 1
1935 if [ -h $testroot/wt/passwd.link ]; then
1936 echo -n "passwd.link symlink points outside of work tree: " >&2
1937 readlink $testroot/wt/passwd.link >&2
1938 test_done "$testroot" "1"
1939 return 1
1942 echo -n "/etc/passwd" > $testroot/content.expected
1943 cp $testroot/wt/passwd.link $testroot/content
1945 cmp -s $testroot/content.expected $testroot/content
1946 ret=$?
1947 if [ $ret -ne 0 ]; then
1948 diff -u $testroot/content.expected $testroot/content
1949 test_done "$testroot" "$ret"
1950 return 1
1953 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1954 echo "../beta" > $testroot/stdout.expected
1955 cmp -s $testroot/stdout.expected $testroot/stdout
1956 ret=$?
1957 if [ $ret -ne 0 ]; then
1958 diff -u $testroot/stdout.expected $testroot/stdout
1959 test_done "$testroot" "$ret"
1960 return 1
1963 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1964 echo "nonexistent" > $testroot/stdout.expected
1965 cmp -s $testroot/stdout.expected $testroot/stdout
1966 ret=$?
1967 if [ $ret -ne 0 ]; then
1968 diff -u $testroot/stdout.expected $testroot/stdout
1969 test_done "$testroot" "$ret"
1970 return 1
1973 # Updating an up-to-date symlink should be a no-op.
1974 echo 'Already up-to-date' > $testroot/stdout.expected
1975 (cd $testroot/wt && got update > $testroot/stdout)
1976 cmp -s $testroot/stdout.expected $testroot/stdout
1977 ret=$?
1978 if [ $ret -ne 0 ]; then
1979 diff -u $testroot/stdout.expected $testroot/stdout
1981 test_done "$testroot" "$ret"
1984 test_update_deletes_symlink() {
1985 local testroot=`test_init update_deletes_symlink`
1987 (cd $testroot/repo && ln -s alpha alpha.link)
1988 (cd $testroot/repo && git add .)
1989 git_commit $testroot/repo -m "add symlink"
1991 got checkout $testroot/repo $testroot/wt > /dev/null
1992 ret=$?
1993 if [ $ret -ne 0 ]; then
1994 echo "checkout failed unexpectedly" >&2
1995 test_done "$testroot" "$ret"
1996 return 1
1999 (cd $testroot/repo && git rm -q alpha.link)
2000 git_commit $testroot/repo -m "delete symlink"
2002 echo "D alpha.link" > $testroot/stdout.expected
2003 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2004 git_show_head $testroot/repo >> $testroot/stdout.expected
2005 echo >> $testroot/stdout.expected
2007 (cd $testroot/wt && got update > $testroot/stdout)
2009 cmp -s $testroot/stdout.expected $testroot/stdout
2010 ret=$?
2011 if [ $ret -ne 0 ]; then
2012 diff -u $testroot/stdout.expected $testroot/stdout
2013 test_done "$testroot" "$ret"
2014 return 1
2017 if [ -e $testroot/wt/alpha.link ]; then
2018 echo "alpha.link still exists on disk"
2019 test_done "$testroot" "1"
2020 return 1
2023 test_done "$testroot" "0"
2026 test_update_symlink_conflicts() {
2027 local testroot=`test_init update_symlink_conflicts`
2029 (cd $testroot/repo && ln -s alpha alpha.link)
2030 (cd $testroot/repo && ln -s epsilon epsilon.link)
2031 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2032 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2033 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2034 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
2035 (cd $testroot/repo && git add .)
2036 git_commit $testroot/repo -m "add symlinks"
2037 local commit_id1=`git_show_head $testroot/repo`
2039 got checkout $testroot/repo $testroot/wt > /dev/null
2040 ret=$?
2041 if [ $ret -ne 0 ]; then
2042 echo "checkout failed unexpectedly" >&2
2043 test_done "$testroot" "$ret"
2044 return 1
2047 (cd $testroot/repo && ln -sf beta alpha.link)
2048 (cd $testroot/repo && ln -sfh gamma epsilon.link)
2049 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
2050 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
2051 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
2052 (cd $testroot/repo && git rm -q nonexistent.link)
2053 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
2054 (cd $testroot/repo && ln -sf alpha new.link)
2055 (cd $testroot/repo && git add .)
2056 git_commit $testroot/repo -m "change symlinks"
2057 local commit_id2=`git_show_head $testroot/repo`
2059 # modified symlink to file A vs modified symlink to file B
2060 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
2061 # modified symlink to dir A vs modified symlink to file B
2062 (cd $testroot/wt && ln -sfh beta epsilon.link)
2063 # modeified symlink to file A vs modified symlink to dir B
2064 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
2065 # added regular file A vs added bad symlink to file A
2066 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
2067 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2068 # added bad symlink to file A vs added regular file A
2069 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
2070 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2071 # removed symlink to non-existent file A vs modified symlink
2072 # to nonexistent file B
2073 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
2074 # modified symlink to file A vs removed symlink to file A
2075 (cd $testroot/wt && got rm zeta.link > /dev/null)
2076 # added symlink to file A vs added symlink to file B
2077 (cd $testroot/wt && ln -sf beta new.link)
2078 (cd $testroot/wt && got add new.link > /dev/null)
2080 (cd $testroot/wt && got update > $testroot/stdout)
2082 echo "C alpha.link" >> $testroot/stdout.expected
2083 echo "C dotgotbar.link" >> $testroot/stdout.expected
2084 echo "C dotgotfoo.link" >> $testroot/stdout.expected
2085 echo "C epsilon/beta.link" >> $testroot/stdout.expected
2086 echo "C epsilon.link" >> $testroot/stdout.expected
2087 echo "C new.link" >> $testroot/stdout.expected
2088 echo "C nonexistent.link" >> $testroot/stdout.expected
2089 echo "G zeta.link" >> $testroot/stdout.expected
2090 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2091 git_show_head $testroot/repo >> $testroot/stdout.expected
2092 echo >> $testroot/stdout.expected
2093 echo "Files with new merge conflicts: 7" >> $testroot/stdout.expected
2095 cmp -s $testroot/stdout.expected $testroot/stdout
2096 ret=$?
2097 if [ $ret -ne 0 ]; then
2098 diff -u $testroot/stdout.expected $testroot/stdout
2099 test_done "$testroot" "$ret"
2100 return 1
2103 if [ -h $testroot/wt/alpha.link ]; then
2104 echo "alpha.link is a symlink"
2105 test_done "$testroot" "1"
2106 return 1
2109 echo "<<<<<<< merged change: commit $commit_id2" \
2110 > $testroot/content.expected
2111 echo "beta" >> $testroot/content.expected
2112 echo "3-way merge base: commit $commit_id1" \
2113 >> $testroot/content.expected
2114 echo "alpha" >> $testroot/content.expected
2115 echo "=======" >> $testroot/content.expected
2116 echo "gamma/delta" >> $testroot/content.expected
2117 echo '>>>>>>>' >> $testroot/content.expected
2118 echo -n "" >> $testroot/content.expected
2120 cp $testroot/wt/alpha.link $testroot/content
2121 cmp -s $testroot/content.expected $testroot/content
2122 ret=$?
2123 if [ $ret -ne 0 ]; then
2124 diff -u $testroot/content.expected $testroot/content
2125 test_done "$testroot" "$ret"
2126 return 1
2129 if [ -h $testroot/wt/epsilon.link ]; then
2130 echo "epsilon.link is a symlink"
2131 test_done "$testroot" "1"
2132 return 1
2135 echo "<<<<<<< merged change: commit $commit_id2" \
2136 > $testroot/content.expected
2137 echo "gamma" >> $testroot/content.expected
2138 echo "3-way merge base: commit $commit_id1" \
2139 >> $testroot/content.expected
2140 echo "epsilon" >> $testroot/content.expected
2141 echo "=======" >> $testroot/content.expected
2142 echo "beta" >> $testroot/content.expected
2143 echo '>>>>>>>' >> $testroot/content.expected
2144 echo -n "" >> $testroot/content.expected
2146 cp $testroot/wt/epsilon.link $testroot/content
2147 cmp -s $testroot/content.expected $testroot/content
2148 ret=$?
2149 if [ $ret -ne 0 ]; then
2150 diff -u $testroot/content.expected $testroot/content
2151 test_done "$testroot" "$ret"
2152 return 1
2155 if [ -h $testroot/wt/passwd.link ]; then
2156 echo -n "passwd.link symlink points outside of work tree: " >&2
2157 readlink $testroot/wt/passwd.link >&2
2158 test_done "$testroot" "1"
2159 return 1
2162 echo -n "/etc/passwd" > $testroot/content.expected
2163 cp $testroot/wt/passwd.link $testroot/content
2165 cmp -s $testroot/content.expected $testroot/content
2166 ret=$?
2167 if [ $ret -ne 0 ]; then
2168 diff -u $testroot/content.expected $testroot/content
2169 test_done "$testroot" "$ret"
2170 return 1
2173 if [ -h $testroot/wt/epsilon/beta.link ]; then
2174 echo "epsilon/beta.link is a symlink"
2175 test_done "$testroot" "1"
2176 return 1
2179 echo "<<<<<<< merged change: commit $commit_id2" \
2180 > $testroot/content.expected
2181 echo "../gamma/delta" >> $testroot/content.expected
2182 echo "3-way merge base: commit $commit_id1" \
2183 >> $testroot/content.expected
2184 echo "../beta" >> $testroot/content.expected
2185 echo "=======" >> $testroot/content.expected
2186 echo "../gamma" >> $testroot/content.expected
2187 echo '>>>>>>>' >> $testroot/content.expected
2188 echo -n "" >> $testroot/content.expected
2190 cp $testroot/wt/epsilon/beta.link $testroot/content
2191 cmp -s $testroot/content.expected $testroot/content
2192 ret=$?
2193 if [ $ret -ne 0 ]; then
2194 diff -u $testroot/content.expected $testroot/content
2195 test_done "$testroot" "$ret"
2196 return 1
2199 if [ -h $testroot/wt/nonexistent.link ]; then
2200 echo -n "nonexistent.link still exists on disk: " >&2
2201 readlink $testroot/wt/nonexistent.link >&2
2202 test_done "$testroot" "1"
2203 return 1
2206 echo "<<<<<<< merged change: commit $commit_id2" \
2207 > $testroot/content.expected
2208 echo "(symlink was deleted)" >> $testroot/content.expected
2209 echo "=======" >> $testroot/content.expected
2210 echo "nonexistent2" >> $testroot/content.expected
2211 echo '>>>>>>>' >> $testroot/content.expected
2212 echo -n "" >> $testroot/content.expected
2214 cp $testroot/wt/nonexistent.link $testroot/content
2215 cmp -s $testroot/content.expected $testroot/content
2216 ret=$?
2217 if [ $ret -ne 0 ]; then
2218 diff -u $testroot/content.expected $testroot/content
2219 test_done "$testroot" "$ret"
2220 return 1
2223 if [ -h $testroot/wt/dotgotfoo.link ]; then
2224 echo "dotgotfoo.link is a symlink"
2225 test_done "$testroot" "1"
2226 return 1
2229 echo "<<<<<<< merged change: commit $commit_id2" \
2230 > $testroot/content.expected
2231 echo "this is regular file foo" >> $testroot/content.expected
2232 echo "=======" >> $testroot/content.expected
2233 echo -n ".got/bar" >> $testroot/content.expected
2234 echo '>>>>>>>' >> $testroot/content.expected
2235 echo -n "" >> $testroot/content.expected
2237 cp $testroot/wt/dotgotfoo.link $testroot/content
2238 cmp -s $testroot/content.expected $testroot/content
2239 ret=$?
2240 if [ $ret -ne 0 ]; then
2241 diff -u $testroot/content.expected $testroot/content
2242 test_done "$testroot" "$ret"
2243 return 1
2246 if [ -h $testroot/wt/dotgotbar.link ]; then
2247 echo "dotgotbar.link is a symlink"
2248 test_done "$testroot" "1"
2249 return 1
2251 echo "<<<<<<< merged change: commit $commit_id2" \
2252 > $testroot/content.expected
2253 echo -n ".got/bar" >> $testroot/content.expected
2254 echo "=======" >> $testroot/content.expected
2255 echo "this is regular file bar" >> $testroot/content.expected
2256 echo '>>>>>>>' >> $testroot/content.expected
2257 echo -n "" >> $testroot/content.expected
2259 cp $testroot/wt/dotgotbar.link $testroot/content
2260 cmp -s $testroot/content.expected $testroot/content
2261 ret=$?
2262 if [ $ret -ne 0 ]; then
2263 diff -u $testroot/content.expected $testroot/content
2264 test_done "$testroot" "$ret"
2265 return 1
2268 if [ -h $testroot/wt/new.link ]; then
2269 echo "new.link is a symlink"
2270 test_done "$testroot" "1"
2271 return 1
2274 echo "<<<<<<< merged change: commit $commit_id2" \
2275 > $testroot/content.expected
2276 echo "alpha" >> $testroot/content.expected
2277 echo "=======" >> $testroot/content.expected
2278 echo "beta" >> $testroot/content.expected
2279 echo '>>>>>>>' >> $testroot/content.expected
2280 echo -n "" >> $testroot/content.expected
2282 cp $testroot/wt/new.link $testroot/content
2283 cmp -s $testroot/content.expected $testroot/content
2284 ret=$?
2285 if [ $ret -ne 0 ]; then
2286 diff -u $testroot/content.expected $testroot/content
2287 test_done "$testroot" "$ret"
2288 return 1
2291 echo "A dotgotfoo.link" > $testroot/stdout.expected
2292 echo "M new.link" >> $testroot/stdout.expected
2293 echo "D nonexistent.link" >> $testroot/stdout.expected
2294 (cd $testroot/wt && got status > $testroot/stdout)
2295 ret=$?
2296 if [ $ret -ne 0 ]; then
2297 diff -u $testroot/stdout.expected $testroot/stdout
2298 test_done "$testroot" "$ret"
2299 return 1
2302 test_done "$testroot" "0"
2306 test_update_single_file() {
2307 local testroot=`test_init update_single_file 1`
2309 echo c1 > $testroot/repo/c
2310 (cd $testroot/repo && git add .)
2311 git_commit $testroot/repo -m "adding file c"
2312 local commit_id1=`git_show_head $testroot/repo`
2314 echo a > $testroot/repo/a
2315 echo b > $testroot/repo/b
2316 echo c2 > $testroot/repo/c
2317 (cd $testroot/repo && git add .)
2318 git_commit $testroot/repo -m "add files a and b, change c"
2319 local commit_id2=`git_show_head $testroot/repo`
2321 (cd $testroot/repo && git rm -qf c)
2322 git_commit $testroot/repo -m "remove file c"
2323 local commit_id3=`git_show_head $testroot/repo`
2325 got checkout -c $commit_id2 $testroot/repo $testroot/wt > /dev/null
2326 ret=$?
2327 if [ $ret -ne 0 ]; then
2328 test_done "$testroot" "$ret"
2329 return 1
2332 echo "U c" > $testroot/stdout.expected
2333 echo "Updated to refs/heads/master: $commit_id1" \
2334 >> $testroot/stdout.expected
2336 (cd $testroot/wt && got update -c $commit_id1 c \
2337 > $testroot/stdout)
2339 cmp -s $testroot/stdout.expected $testroot/stdout
2340 ret=$?
2341 if [ $ret -ne 0 ]; then
2342 diff -u $testroot/stdout.expected $testroot/stdout
2343 test_done "$testroot" "$ret"
2344 return 1
2347 echo c1 > $testroot/content.expected
2348 cat $testroot/wt/c > $testroot/content
2350 cmp -s $testroot/content.expected $testroot/content
2351 ret=$?
2352 if [ $ret -ne 0 ]; then
2353 diff -u $testroot/content.expected $testroot/content
2354 test_done "$testroot" "$ret"
2355 return 1
2358 echo "U c" > $testroot/stdout.expected
2359 echo "Updated to refs/heads/master: $commit_id2" \
2360 >> $testroot/stdout.expected
2362 (cd $testroot/wt && got update -c $commit_id2 c > $testroot/stdout)
2364 cmp -s $testroot/stdout.expected $testroot/stdout
2365 ret=$?
2366 if [ $ret -ne 0 ]; then
2367 diff -u $testroot/stdout.expected $testroot/stdout
2368 test_done "$testroot" "$ret"
2369 return 1
2372 echo c2 > $testroot/content.expected
2373 cat $testroot/wt/c > $testroot/content
2375 cmp -s $testroot/content.expected $testroot/content
2376 ret=$?
2377 if [ $ret -ne 0 ]; then
2378 diff -u $testroot/content.expected $testroot/content
2379 test_done "$testroot" "$ret"
2380 return 1
2383 echo "D c" > $testroot/stdout.expected
2384 echo "Updated to refs/heads/master: $commit_id3" \
2385 >> $testroot/stdout.expected
2387 (cd $testroot/wt && got update -c $commit_id3 c \
2388 > $testroot/stdout 2> $testroot/stderr)
2390 echo "got: /c: no such entry found in tree" > $testroot/stderr.expected
2391 cmp -s $testroot/stderr.expected $testroot/stderr
2392 ret=$?
2393 if [ $ret -ne 0 ]; then
2394 diff -u $testroot/stderr.expected $testroot/stderr
2395 test_done "$testroot" "$ret"
2396 return 1
2399 echo -n > $testroot/stdout.expected
2400 cmp -s $testroot/stdout.expected $testroot/stdout
2401 ret=$?
2402 if [ $ret -ne 0 ]; then
2403 diff -u $testroot/stdout.expected $testroot/stdout
2404 test_done "$testroot" "$ret"
2405 return 1
2408 echo "D c" > $testroot/stdout.expected
2409 echo "Updated to refs/heads/master: $commit_id3" \
2410 >> $testroot/stdout.expected
2412 (cd $testroot/wt && got update -c $commit_id3 > $testroot/stdout)
2413 cmp -s $testroot/stdout.expected $testroot/stdout
2414 ret=$?
2415 if [ $ret -ne 0 ]; then
2416 diff -u $testroot/stdout.expected $testroot/stdout
2417 test_done "$testroot" "$ret"
2418 return 1
2421 if [ -e $testroot/wt/c ]; then
2422 echo "removed file c still exists on disk" >&2
2423 test_done "$testroot" "1"
2424 return 1
2427 test_done "$testroot" "0"
2428 return 0
2431 test_update_file_skipped_due_to_conflict() {
2432 local testroot=`test_init update_file_skipped_due_to_conflict`
2433 local commit_id0=`git_show_head $testroot/repo`
2434 blob_id0=`get_blob_id $testroot/repo "" beta`
2436 echo "changed beta" > $testroot/repo/beta
2437 git_commit $testroot/repo -m "changed beta"
2438 local commit_id1=`git_show_head $testroot/repo`
2439 blob_id1=`get_blob_id $testroot/repo "" beta`
2441 got checkout $testroot/repo $testroot/wt > /dev/null
2442 ret=$?
2443 if [ $ret -ne 0 ]; then
2444 test_done "$testroot" "$ret"
2445 return 1
2448 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2449 cut -d ':' -f 2 | tr -d ' ')`
2450 if [ "$blob_id" != "$blob_id1" ]; then
2451 echo "file beta has the wrong base blob ID" >&2
2452 test_done "$testroot" "1"
2453 return 1
2456 commit_id=`(cd $testroot/wt && got info beta | \
2457 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2458 if [ "$commit_id" != "$commit_id1" ]; then
2459 echo "file beta has the wrong base commit ID" >&2
2460 test_done "$testroot" "1"
2461 return 1
2464 echo "modified beta" > $testroot/wt/beta
2466 (cd $testroot/wt && got update -c $commit_id0 > $testroot/stdout)
2468 echo "C beta" > $testroot/stdout.expected
2469 echo "Updated to refs/heads/master: $commit_id0" \
2470 >> $testroot/stdout.expected
2471 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2472 cmp -s $testroot/stdout.expected $testroot/stdout
2473 ret=$?
2474 if [ $ret -ne 0 ]; then
2475 diff -u $testroot/stdout.expected $testroot/stdout
2476 test_done "$testroot" "$ret"
2477 return 1
2480 echo "<<<<<<< merged change: commit $commit_id0" \
2481 > $testroot/content.expected
2482 echo "beta" >> $testroot/content.expected
2483 echo "||||||| 3-way merge base: commit $commit_id1" \
2484 >> $testroot/content.expected
2485 echo "changed beta" >> $testroot/content.expected
2486 echo "=======" >> $testroot/content.expected
2487 echo "modified beta" >> $testroot/content.expected
2488 echo ">>>>>>>" >> $testroot/content.expected
2490 cat $testroot/wt/beta > $testroot/content
2492 cmp -s $testroot/content.expected $testroot/content
2493 ret=$?
2494 if [ $ret -ne 0 ]; then
2495 diff -u $testroot/content.expected $testroot/content
2496 test_done "$testroot" "$ret"
2497 return 1
2500 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2501 cut -d ':' -f 2 | tr -d ' ')`
2502 if [ "$blob_id" != "$blob_id0" ]; then
2503 echo "file beta has the wrong base blob ID" >&2
2504 test_done "$testroot" "1"
2505 return 1
2508 commit_id=`(cd $testroot/wt && got info beta | \
2509 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2510 if [ "$commit_id" != "$commit_id0" ]; then
2511 echo "file beta has the wrong base commit ID" >&2
2512 test_done "$testroot" "1"
2513 return 1
2516 # update to the latest commit again; this skips beta
2517 (cd $testroot/wt && got update > $testroot/stdout)
2518 echo "# beta" > $testroot/stdout.expected
2519 echo "Updated to refs/heads/master: $commit_id1" \
2520 >> $testroot/stdout.expected
2521 echo "Files not updated because of existing merge conflicts: 1" \
2522 >> $testroot/stdout.expected
2523 cmp -s $testroot/stdout.expected $testroot/stdout
2524 ret=$?
2525 if [ $ret -ne 0 ]; then
2526 diff -u $testroot/stdout.expected $testroot/stdout
2527 test_done "$testroot" "$ret"
2528 return 1
2531 # blob ID of beta should not have changed
2532 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2533 cut -d ':' -f 2 | tr -d ' ')`
2534 if [ "$blob_id" != "$blob_id0" ]; then
2535 echo "file beta has the wrong base blob ID" >&2
2536 test_done "$testroot" "1"
2537 return 1
2540 # commit ID of beta should not have changed; There was a bug
2541 # here where the commit ID had been changed even though the
2542 # file was not updated.
2543 commit_id=`(cd $testroot/wt && got info beta | \
2544 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2545 if [ "$commit_id" != "$commit_id0" ]; then
2546 echo "file beta has the wrong base commit ID: $commit_id" >&2
2547 test_done "$testroot" "1"
2548 return 1
2551 # beta is still conflicted and based on commit 0
2552 echo 'C beta' > $testroot/stdout.expected
2553 (cd $testroot/wt && got status > $testroot/stdout)
2554 cmp -s $testroot/stdout.expected $testroot/stdout
2555 ret=$?
2556 if [ $ret -ne 0 ]; then
2557 diff -u $testroot/stdout.expected $testroot/stdout
2558 test_done "$testroot" "$ret"
2559 return 1
2562 # resolve the conflict via revert
2563 (cd $testroot/wt && got revert beta >/dev/null)
2565 # beta now matches its base blob which is still from commit 0
2566 echo "beta" > $testroot/content.expected
2567 cat $testroot/wt/beta > $testroot/content
2568 cmp -s $testroot/content.expected $testroot/content
2569 ret=$?
2570 if [ $ret -ne 0 ]; then
2571 diff -u $testroot/content.expected $testroot/content
2572 test_done "$testroot" "$ret"
2573 return 1
2576 # updating to the latest commit should now update beta
2577 (cd $testroot/wt && got update > $testroot/stdout)
2578 echo "U beta" > $testroot/stdout.expected
2579 echo "Updated to refs/heads/master: $commit_id1" \
2580 >> $testroot/stdout.expected
2581 cmp -s $testroot/stdout.expected $testroot/stdout
2582 ret=$?
2583 if [ $ret -ne 0 ]; then
2584 diff -u $testroot/stdout.expected $testroot/stdout
2585 test_done "$testroot" "$ret"
2586 return 1
2589 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2590 cut -d ':' -f 2 | tr -d ' ')`
2591 if [ "$blob_id" != "$blob_id1" ]; then
2592 echo "file beta has the wrong base blob ID" >&2
2593 test_done "$testroot" "1"
2594 return 1
2597 commit_id=`(cd $testroot/wt && got info beta | \
2598 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2599 if [ "$commit_id" != "$commit_id1" ]; then
2600 echo "file beta has the wrong base commit ID: $commit_id" >&2
2601 test_done "$testroot" "1"
2602 return 1
2605 echo "changed beta" > $testroot/content.expected
2606 cat $testroot/wt/beta > $testroot/content
2607 cmp -s $testroot/content.expected $testroot/content
2608 ret=$?
2609 if [ $ret -ne 0 ]; then
2610 diff -u $testroot/content.expected $testroot/content
2612 test_done "$testroot" "$ret"
2615 test_update_file_skipped_due_to_obstruction() {
2616 local testroot=`test_init update_file_skipped_due_to_obstruction`
2617 local commit_id0=`git_show_head $testroot/repo`
2618 blob_id0=`get_blob_id $testroot/repo "" beta`
2620 echo "changed beta" > $testroot/repo/beta
2621 echo "new file" > $testroot/repo/new
2622 (cd $testroot/repo && git add new)
2623 git_commit $testroot/repo -m "changed beta"
2624 local commit_id1=`git_show_head $testroot/repo`
2625 blob_id1=`get_blob_id $testroot/repo "" beta`
2627 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
2628 ret=$?
2629 if [ $ret -ne 0 ]; then
2630 test_done "$testroot" "$ret"
2631 return 1
2634 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2635 cut -d ':' -f 2 | tr -d ' ')`
2636 if [ "$blob_id" != "$blob_id0" ]; then
2637 echo "file beta has the wrong base blob ID" >&2
2638 test_done "$testroot" "1"
2639 return 1
2642 commit_id=`(cd $testroot/wt && got info beta | \
2643 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2644 if [ "$commit_id" != "$commit_id0" ]; then
2645 echo "file beta has the wrong base commit ID" >&2
2646 test_done "$testroot" "1"
2647 return 1
2650 rm $testroot/wt/beta
2651 mkdir -p $testroot/wt/beta/psi
2652 mkdir -p $testroot/wt/new
2654 # update to the latest commit; this skips beta and the new file
2655 (cd $testroot/wt && got update > $testroot/stdout)
2656 ret=$?
2657 if [ $ret -ne 0 ]; then
2658 echo "update failed unexpectedly" >&2
2659 test_done "$testroot" "1"
2660 return 1
2663 echo "~ beta" > $testroot/stdout.expected
2664 echo "~ new" >> $testroot/stdout.expected
2665 echo "Updated to refs/heads/master: $commit_id1" \
2666 >> $testroot/stdout.expected
2667 echo "File paths obstructed by a non-regular file: 2" \
2668 >> $testroot/stdout.expected
2669 cmp -s $testroot/stdout.expected $testroot/stdout
2670 ret=$?
2671 if [ $ret -ne 0 ]; then
2672 diff -u $testroot/stdout.expected $testroot/stdout
2673 test_done "$testroot" "$ret"
2674 return 1
2677 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2678 cut -d ':' -f 2 | tr -d ' ')`
2679 if [ "$blob_id" != "$blob_id0" ]; then
2680 echo "file beta has the wrong base blob ID" >&2
2681 test_done "$testroot" "1"
2682 return 1
2685 commit_id=`(cd $testroot/wt && got info beta | \
2686 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2687 if [ "$commit_id" != "$commit_id0" ]; then
2688 echo "file beta has the wrong base commit ID" >&2
2689 test_done "$testroot" "1"
2690 return 1
2693 # remove the directory which obstructs file beta
2694 rm -r $testroot/wt/beta
2696 # updating to the latest commit should now update beta
2697 (cd $testroot/wt && got update > $testroot/stdout)
2698 echo "! beta" > $testroot/stdout.expected
2699 echo "~ new" >> $testroot/stdout.expected
2700 echo "Updated to refs/heads/master: $commit_id1" \
2701 >> $testroot/stdout.expected
2702 echo "File paths obstructed by a non-regular file: 1" \
2703 >> $testroot/stdout.expected
2704 cmp -s $testroot/stdout.expected $testroot/stdout
2705 ret=$?
2706 if [ $ret -ne 0 ]; then
2707 diff -u $testroot/stdout.expected $testroot/stdout
2708 test_done "$testroot" "$ret"
2709 return 1
2712 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2713 cut -d ':' -f 2 | tr -d ' ')`
2714 if [ "$blob_id" != "$blob_id1" ]; then
2715 echo "file beta has the wrong base blob ID" >&2
2716 test_done "$testroot" "1"
2717 return 1
2720 commit_id=`(cd $testroot/wt && got info beta | \
2721 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2722 if [ "$commit_id" != "$commit_id1" ]; then
2723 echo "file beta has the wrong base commit ID: $commit_id" >&2
2724 test_done "$testroot" "1"
2725 return 1
2728 echo "changed beta" > $testroot/content.expected
2729 cat $testroot/wt/beta > $testroot/content
2730 cmp -s $testroot/content.expected $testroot/content
2731 ret=$?
2732 if [ $ret -ne 0 ]; then
2733 diff -u $testroot/content.expected $testroot/content
2735 test_done "$testroot" "$ret"
2738 test_update_quiet() {
2739 local testroot=`test_init update_quiet`
2741 got checkout $testroot/repo $testroot/wt > /dev/null
2742 ret=$?
2743 if [ $ret -ne 0 ]; then
2744 test_done "$testroot" "$ret"
2745 return 1
2748 echo "modified alpha" > $testroot/repo/alpha
2749 git_commit $testroot/repo -m "modified alpha"
2751 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2752 git_show_head $testroot/repo >> $testroot/stdout.expected
2753 echo >> $testroot/stdout.expected
2755 (cd $testroot/wt && got update -q > $testroot/stdout)
2757 cmp -s $testroot/stdout.expected $testroot/stdout
2758 ret=$?
2759 if [ $ret -ne 0 ]; then
2760 diff -u $testroot/stdout.expected $testroot/stdout
2761 test_done "$testroot" "$ret"
2762 return 1
2765 echo "modified alpha" > $testroot/content.expected
2766 cat $testroot/wt/alpha > $testroot/content
2768 cmp -s $testroot/content.expected $testroot/content
2769 ret=$?
2770 if [ $ret -ne 0 ]; then
2771 diff -u $testroot/content.expected $testroot/content
2773 test_done "$testroot" "$ret"
2776 test_update_binary_file() {
2777 local testroot=`test_init update_binary_file`
2778 local commit_id0=`git_show_head $testroot/repo`
2780 got checkout $testroot/repo $testroot/wt > /dev/null
2781 ret=$?
2782 if [ $ret -ne 0 ]; then
2783 test_done "$testroot" "$ret"
2784 return 1
2787 cp /bin/ls $testroot/wt/foo
2788 chmod 755 $testroot/wt/foo
2789 (cd $testroot/wt && got add foo >/dev/null)
2790 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
2791 local commit_id1=`git_show_head $testroot/repo`
2793 cp /bin/cat $testroot/wt/foo
2794 chmod 755 $testroot/wt/foo
2795 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2796 local commit_id2=`git_show_head $testroot/repo`
2798 cp /bin/cp $testroot/wt/foo
2799 chmod 755 $testroot/wt/foo
2800 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2801 local commit_id3=`git_show_head $testroot/repo`
2803 (cd $testroot/wt && got rm foo >/dev/null)
2804 (cd $testroot/wt && got commit -m 'remove binary file' > /dev/null)
2805 local commit_id4=`git_show_head $testroot/repo`
2807 # backdate the work tree to make it usable for updating
2808 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2810 # update which adds a binary file
2811 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2813 echo "A foo" > $testroot/stdout.expected
2814 echo -n "Updated to refs/heads/master: $commit_id1" \
2815 >> $testroot/stdout.expected
2816 echo >> $testroot/stdout.expected
2817 cmp -s $testroot/stdout.expected $testroot/stdout
2818 ret=$?
2819 if [ $ret -ne 0 ]; then
2820 diff -u $testroot/stdout.expected $testroot/stdout
2821 test_done "$testroot" "$ret"
2822 return 1
2825 cp /bin/ls $testroot/content.expected
2826 chmod 755 $testroot/content.expected
2827 cat $testroot/wt/foo > $testroot/content
2829 cmp -s $testroot/content.expected $testroot/content
2830 ret=$?
2831 if [ $ret -ne 0 ]; then
2832 diff -u $testroot/content.expected $testroot/content
2833 test_done "$testroot" "$ret"
2834 return 1
2837 # update which adds a conflicting binary file
2838 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2839 cp /bin/cat $testroot/wt/foo
2840 chmod 755 $testroot/wt/foo
2841 (cd $testroot/wt && got add foo > /dev/null)
2842 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2844 echo "C foo" > $testroot/stdout.expected
2845 echo "Updated to refs/heads/master: $commit_id1" \
2846 >> $testroot/stdout.expected
2847 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2848 cmp -s $testroot/stdout.expected $testroot/stdout
2849 ret=$?
2850 if [ $ret -ne 0 ]; then
2851 diff -u $testroot/stdout.expected $testroot/stdout
2852 test_done "$testroot" "$ret"
2853 return 1
2856 echo "Binary files differ and cannot be merged automatically:" \
2857 > $testroot/content.expected
2858 echo "<<<<<<< merged change: commit $commit_id1" \
2859 >> $testroot/content.expected
2860 echo -n "file " >> $testroot/content.expected
2861 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2862 echo '=======' >> $testroot/content.expected
2863 echo -n "file " >> $testroot/content.expected
2864 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2865 echo ">>>>>>>" >> $testroot/content.expected
2866 cat $testroot/wt/foo > $testroot/content
2868 cmp -s $testroot/content.expected $testroot/content
2869 ret=$?
2870 if [ $ret -ne 0 ]; then
2871 diff -u $testroot/content.expected $testroot/content
2872 test_done "$testroot" "$ret"
2873 return 1
2876 cp /bin/ls $testroot/content.expected
2877 chmod 755 $testroot/content.expected
2878 cat $testroot/wt/foo-1-* > $testroot/content
2880 cmp -s $testroot/content.expected $testroot/content
2881 ret=$?
2882 if [ $ret -ne 0 ]; then
2883 diff -u $testroot/content.expected $testroot/content
2884 test_done "$testroot" "$ret"
2885 return 1
2888 cp /bin/cat $testroot/content.expected
2889 chmod 755 $testroot/content.expected
2890 cat $testroot/wt/foo-2-* > $testroot/content
2892 cmp -s $testroot/content.expected $testroot/content
2893 ret=$?
2894 if [ $ret -ne 0 ]; then
2895 diff -u $testroot/content.expected $testroot/content
2896 test_done "$testroot" "$ret"
2897 return 1
2900 # tidy up
2901 (cd $testroot/wt && got revert -R . >/dev/null)
2902 rm $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2903 (cd $testroot/wt && got up -c $commit_id1 > /dev/null)
2905 # update which changes a binary file
2906 (cd $testroot/wt && got up -c $commit_id2 > $testroot/stdout)
2908 echo "U foo" > $testroot/stdout.expected
2909 echo -n "Updated to refs/heads/master: $commit_id2" \
2910 >> $testroot/stdout.expected
2911 echo >> $testroot/stdout.expected
2912 cmp -s $testroot/stdout.expected $testroot/stdout
2913 ret=$?
2914 if [ $ret -ne 0 ]; then
2915 diff -u $testroot/stdout.expected $testroot/stdout
2916 test_done "$testroot" "$ret"
2917 return 1
2920 cp /bin/cat $testroot/content.expected
2921 chmod 755 $testroot/content.expected
2922 cat $testroot/wt/foo > $testroot/content
2924 cmp -s $testroot/content.expected $testroot/content
2925 ret=$?
2926 if [ $ret -ne 0 ]; then
2927 diff -u $testroot/content.expected $testroot/content
2928 test_done "$testroot" "$ret"
2929 return 1
2932 # update which changes a locally modified binary file
2933 cp /bin/ls $testroot/wt/foo
2934 chmod 755 $testroot/wt/foo
2935 (cd $testroot/wt && got up -c $commit_id3 > $testroot/stdout)
2937 echo "C foo" > $testroot/stdout.expected
2938 echo -n "Updated to refs/heads/master: $commit_id3" \
2939 >> $testroot/stdout.expected
2940 echo >> $testroot/stdout.expected
2941 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2942 cmp -s $testroot/stdout.expected $testroot/stdout
2943 ret=$?
2944 if [ $ret -ne 0 ]; then
2945 diff -u $testroot/stdout.expected $testroot/stdout
2946 test_done "$testroot" "$ret"
2947 return 1
2950 echo "Binary files differ and cannot be merged automatically:" \
2951 > $testroot/content.expected
2952 echo "<<<<<<< merged change: commit $commit_id3" \
2953 >> $testroot/content.expected
2954 echo -n "file " >> $testroot/content.expected
2955 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2956 echo "||||||| 3-way merge base: commit $commit_id2" \
2957 >> $testroot/content.expected
2958 echo -n "file " >> $testroot/content.expected
2959 ls $testroot/wt/foo-orig-* >> $testroot/content.expected
2960 echo '=======' >> $testroot/content.expected
2961 echo -n "file " >> $testroot/content.expected
2962 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2963 echo ">>>>>>>" >> $testroot/content.expected
2964 cat $testroot/wt/foo > $testroot/content
2966 cmp -s $testroot/content.expected $testroot/content
2967 ret=$?
2968 if [ $ret -ne 0 ]; then
2969 diff -u $testroot/content.expected $testroot/content
2970 test_done "$testroot" "$ret"
2971 return 1
2974 cp /bin/cp $testroot/content.expected
2975 chmod 755 $testroot/content.expected
2976 cp $testroot/wt/foo-1-* $testroot/content
2977 cmp -s $testroot/content.expected $testroot/content
2978 ret=$?
2979 if [ $ret -ne 0 ]; then
2980 diff -u $testroot/content.expected $testroot/content
2981 test_done "$testroot" "$ret"
2982 return 1
2985 cp /bin/ls $testroot/content.expected
2986 chmod 755 $testroot/content.expected
2987 cp $testroot/wt/foo-2-* $testroot/content
2988 cmp -s $testroot/content.expected $testroot/content
2989 ret=$?
2990 if [ $ret -ne 0 ]; then
2991 diff -u $testroot/content.expected $testroot/content
2992 test_done "$testroot" "$ret"
2993 return 1
2996 (cd $testroot/wt && got status > $testroot/stdout)
2997 echo 'C foo' > $testroot/stdout.expected
2998 echo -n '? ' >> $testroot/stdout.expected
2999 (cd $testroot/wt && ls foo-1-* >> $testroot/stdout.expected)
3000 echo -n '? ' >> $testroot/stdout.expected
3001 (cd $testroot/wt && ls foo-2-* >> $testroot/stdout.expected)
3002 echo -n '? ' >> $testroot/stdout.expected
3003 (cd $testroot/wt && ls foo-orig-* >> $testroot/stdout.expected)
3004 cmp -s $testroot/stdout.expected $testroot/stdout
3005 ret=$?
3006 if [ $ret -ne 0 ]; then
3007 diff -u $testroot/stdout.expected $testroot/stdout
3008 test_done "$testroot" "$ret"
3009 return 1
3012 # tidy up
3013 (cd $testroot/wt && got revert -R . > /dev/null)
3014 rm $testroot/wt/foo-orig-* $testroot/wt/foo-1-* $testroot/wt/foo-2-*
3016 # update which deletes a binary file
3017 (cd $testroot/wt && got up -c $commit_id4 > $testroot/stdout)
3018 echo "D foo" > $testroot/stdout.expected
3019 echo -n "Updated to refs/heads/master: $commit_id4" \
3020 >> $testroot/stdout.expected
3021 echo >> $testroot/stdout.expected
3022 cmp -s $testroot/stdout.expected $testroot/stdout
3023 ret=$?
3024 if [ $ret -ne 0 ]; then
3025 diff -u $testroot/stdout.expected $testroot/stdout
3026 test_done "$testroot" "$ret"
3029 if [ -e $testroot/wt/foo ]; then
3030 echo "removed file foo still exists on disk" >&2
3031 test_done "$testroot" "1"
3032 return 1
3034 test_done "$testroot" "0"
3037 test_update_umask() {
3038 local testroot=`test_init update_binary_file`
3040 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
3041 ret=$?
3042 if [ $ret -ne 0 ]; then
3043 test_done "$testroot" "$ret"
3044 return 1
3047 rm "$testroot/wt/alpha"
3049 # using a subshell to avoid clobbering global umask
3050 (umask 022 && cd "$testroot/wt" && got update alpha) \
3051 >/dev/null 2>/dev/null
3052 ret=$?
3053 if [ $ret -ne 0 ]; then
3054 test_done "$testroot" $ret
3055 return 1
3058 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-r--r--; then
3059 echo "alpha is not 0644" >&2
3060 test_done "$testroot" 1
3061 return 1
3064 rm "$testroot/wt/alpha"
3066 # using a subshell to avoid clobbering global umask
3067 (umask 044 && cd "$testroot/wt" && got update alpha) \
3068 >/dev/null 2>/dev/null
3069 ret=$?
3070 if [ $ret -ne 0 ]; then
3071 test_done "$testroot" $ret
3072 return 1
3075 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
3076 echo "alpha is not 0600" >&2
3077 test_done "$testroot" 1
3078 return 1
3081 rm "$testroot/wt/alpha"
3083 # using a subshell to avoid clobbering global umask
3084 (umask 222 && cd "$testroot/wt" && got update alpha) \
3085 >/dev/null 2>/dev/null
3086 ret=$?
3087 if [ $ret -ne 0 ]; then
3088 test_done "$testroot" $ret
3089 return 1
3092 if ! ls -l "$testroot/wt/alpha" | grep -q ^-r--r--r--; then
3093 echo "alpha is not 0444" >&2
3094 test_done "$testroot" 1
3095 return 1;
3098 test_done "$testroot" 0
3101 test_parseargs "$@"
3102 run_test test_update_basic
3103 run_test test_update_adds_file
3104 run_test test_update_deletes_file
3105 run_test test_update_deletes_dir
3106 run_test test_update_deletes_dir_with_path_prefix
3107 run_test test_update_deletes_dir_recursively
3108 run_test test_update_sibling_dirs_with_common_prefix
3109 run_test test_update_dir_with_dot_sibling
3110 run_test test_update_moves_files_upwards
3111 run_test test_update_moves_files_to_new_dir
3112 run_test test_update_creates_missing_parent
3113 run_test test_update_creates_missing_parent_with_subdir
3114 run_test test_update_file_in_subsubdir
3115 run_test test_update_changes_file_to_dir
3116 run_test test_update_merges_file_edits
3117 run_test test_update_keeps_xbit
3118 run_test test_update_clears_xbit
3119 run_test test_update_restores_missing_file
3120 run_test test_update_conflict_wt_add_vs_repo_add
3121 run_test test_update_conflict_wt_edit_vs_repo_rm
3122 run_test test_update_conflict_wt_rm_vs_repo_edit
3123 run_test test_update_conflict_wt_rm_vs_repo_rm
3124 run_test test_update_partial
3125 run_test test_update_partial_add
3126 run_test test_update_partial_rm
3127 run_test test_update_partial_dir
3128 run_test test_update_moved_branch_ref
3129 run_test test_update_to_another_branch
3130 run_test test_update_to_commit_on_wrong_branch
3131 run_test test_update_bumps_base_commit_id
3132 run_test test_update_tag
3133 run_test test_update_toggles_xbit
3134 run_test test_update_preserves_conflicted_file
3135 run_test test_update_modified_submodules
3136 run_test test_update_adds_submodule
3137 run_test test_update_conflict_wt_file_vs_repo_submodule
3138 run_test test_update_adds_symlink
3139 run_test test_update_deletes_symlink
3140 run_test test_update_symlink_conflicts
3141 run_test test_update_single_file
3142 run_test test_update_file_skipped_due_to_conflict
3143 run_test test_update_file_skipped_due_to_obstruction
3144 run_test test_update_quiet
3145 run_test test_update_binary_file
3146 run_test test_update_umask