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 && rm epsilon.link && ln -s 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 && rm epsilon.link && ln -s beta epsilon.link)
2063 # modeified symlink to file A vs modified symlink to dir B
2064 (cd $testroot/wt && rm epsilon/beta.link && ln -s ../gamma \
2065 epsilon/beta.link)
2066 # added regular file A vs added bad symlink to file A
2067 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
2068 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2069 # added bad symlink to file A vs added regular file A
2070 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
2071 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2072 # removed symlink to non-existent file A vs modified symlink
2073 # to nonexistent file B
2074 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
2075 # modified symlink to file A vs removed symlink to file A
2076 (cd $testroot/wt && got rm zeta.link > /dev/null)
2077 # added symlink to file A vs added symlink to file B
2078 (cd $testroot/wt && ln -sf beta new.link)
2079 (cd $testroot/wt && got add new.link > /dev/null)
2081 (cd $testroot/wt && got update > $testroot/stdout)
2083 echo "C alpha.link" >> $testroot/stdout.expected
2084 echo "C dotgotbar.link" >> $testroot/stdout.expected
2085 echo "C dotgotfoo.link" >> $testroot/stdout.expected
2086 echo "C epsilon/beta.link" >> $testroot/stdout.expected
2087 echo "C epsilon.link" >> $testroot/stdout.expected
2088 echo "C new.link" >> $testroot/stdout.expected
2089 echo "C nonexistent.link" >> $testroot/stdout.expected
2090 echo "G zeta.link" >> $testroot/stdout.expected
2091 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2092 git_show_head $testroot/repo >> $testroot/stdout.expected
2093 echo >> $testroot/stdout.expected
2094 echo "Files with new merge conflicts: 7" >> $testroot/stdout.expected
2096 cmp -s $testroot/stdout.expected $testroot/stdout
2097 ret=$?
2098 if [ $ret -ne 0 ]; then
2099 diff -u $testroot/stdout.expected $testroot/stdout
2100 test_done "$testroot" "$ret"
2101 return 1
2104 if [ -h $testroot/wt/alpha.link ]; then
2105 echo "alpha.link is a symlink"
2106 test_done "$testroot" "1"
2107 return 1
2110 echo "<<<<<<< merged change: commit $commit_id2" \
2111 > $testroot/content.expected
2112 echo "beta" >> $testroot/content.expected
2113 echo "3-way merge base: commit $commit_id1" \
2114 >> $testroot/content.expected
2115 echo "alpha" >> $testroot/content.expected
2116 echo "=======" >> $testroot/content.expected
2117 echo "gamma/delta" >> $testroot/content.expected
2118 echo '>>>>>>>' >> $testroot/content.expected
2119 echo -n "" >> $testroot/content.expected
2121 cp $testroot/wt/alpha.link $testroot/content
2122 cmp -s $testroot/content.expected $testroot/content
2123 ret=$?
2124 if [ $ret -ne 0 ]; then
2125 diff -u $testroot/content.expected $testroot/content
2126 test_done "$testroot" "$ret"
2127 return 1
2130 if [ -h $testroot/wt/epsilon.link ]; then
2131 echo "epsilon.link is a symlink"
2132 test_done "$testroot" "1"
2133 return 1
2136 echo "<<<<<<< merged change: commit $commit_id2" \
2137 > $testroot/content.expected
2138 echo "gamma" >> $testroot/content.expected
2139 echo "3-way merge base: commit $commit_id1" \
2140 >> $testroot/content.expected
2141 echo "epsilon" >> $testroot/content.expected
2142 echo "=======" >> $testroot/content.expected
2143 echo "beta" >> $testroot/content.expected
2144 echo '>>>>>>>' >> $testroot/content.expected
2145 echo -n "" >> $testroot/content.expected
2147 cp $testroot/wt/epsilon.link $testroot/content
2148 cmp -s $testroot/content.expected $testroot/content
2149 ret=$?
2150 if [ $ret -ne 0 ]; then
2151 diff -u $testroot/content.expected $testroot/content
2152 test_done "$testroot" "$ret"
2153 return 1
2156 if [ -h $testroot/wt/passwd.link ]; then
2157 echo -n "passwd.link symlink points outside of work tree: " >&2
2158 readlink $testroot/wt/passwd.link >&2
2159 test_done "$testroot" "1"
2160 return 1
2163 echo -n "/etc/passwd" > $testroot/content.expected
2164 cp $testroot/wt/passwd.link $testroot/content
2166 cmp -s $testroot/content.expected $testroot/content
2167 ret=$?
2168 if [ $ret -ne 0 ]; then
2169 diff -u $testroot/content.expected $testroot/content
2170 test_done "$testroot" "$ret"
2171 return 1
2174 if [ -h $testroot/wt/epsilon/beta.link ]; then
2175 echo "epsilon/beta.link is a symlink"
2176 test_done "$testroot" "1"
2177 return 1
2180 echo "<<<<<<< merged change: commit $commit_id2" \
2181 > $testroot/content.expected
2182 echo "../gamma/delta" >> $testroot/content.expected
2183 echo "3-way merge base: commit $commit_id1" \
2184 >> $testroot/content.expected
2185 echo "../beta" >> $testroot/content.expected
2186 echo "=======" >> $testroot/content.expected
2187 echo "../gamma" >> $testroot/content.expected
2188 echo '>>>>>>>' >> $testroot/content.expected
2189 echo -n "" >> $testroot/content.expected
2191 cp $testroot/wt/epsilon/beta.link $testroot/content
2192 cmp -s $testroot/content.expected $testroot/content
2193 ret=$?
2194 if [ $ret -ne 0 ]; then
2195 diff -u $testroot/content.expected $testroot/content
2196 test_done "$testroot" "$ret"
2197 return 1
2200 if [ -h $testroot/wt/nonexistent.link ]; then
2201 echo -n "nonexistent.link still exists on disk: " >&2
2202 readlink $testroot/wt/nonexistent.link >&2
2203 test_done "$testroot" "1"
2204 return 1
2207 echo "<<<<<<< merged change: commit $commit_id2" \
2208 > $testroot/content.expected
2209 echo "(symlink was deleted)" >> $testroot/content.expected
2210 echo "=======" >> $testroot/content.expected
2211 echo "nonexistent2" >> $testroot/content.expected
2212 echo '>>>>>>>' >> $testroot/content.expected
2213 echo -n "" >> $testroot/content.expected
2215 cp $testroot/wt/nonexistent.link $testroot/content
2216 cmp -s $testroot/content.expected $testroot/content
2217 ret=$?
2218 if [ $ret -ne 0 ]; then
2219 diff -u $testroot/content.expected $testroot/content
2220 test_done "$testroot" "$ret"
2221 return 1
2224 if [ -h $testroot/wt/dotgotfoo.link ]; then
2225 echo "dotgotfoo.link is a symlink"
2226 test_done "$testroot" "1"
2227 return 1
2230 echo "<<<<<<< merged change: commit $commit_id2" \
2231 > $testroot/content.expected
2232 echo "this is regular file foo" >> $testroot/content.expected
2233 echo "=======" >> $testroot/content.expected
2234 echo -n ".got/bar" >> $testroot/content.expected
2235 echo '>>>>>>>' >> $testroot/content.expected
2236 echo -n "" >> $testroot/content.expected
2238 cp $testroot/wt/dotgotfoo.link $testroot/content
2239 cmp -s $testroot/content.expected $testroot/content
2240 ret=$?
2241 if [ $ret -ne 0 ]; then
2242 diff -u $testroot/content.expected $testroot/content
2243 test_done "$testroot" "$ret"
2244 return 1
2247 if [ -h $testroot/wt/dotgotbar.link ]; then
2248 echo "dotgotbar.link is a symlink"
2249 test_done "$testroot" "1"
2250 return 1
2252 echo "<<<<<<< merged change: commit $commit_id2" \
2253 > $testroot/content.expected
2254 echo -n ".got/bar" >> $testroot/content.expected
2255 echo "=======" >> $testroot/content.expected
2256 echo "this is regular file bar" >> $testroot/content.expected
2257 echo '>>>>>>>' >> $testroot/content.expected
2258 echo -n "" >> $testroot/content.expected
2260 cp $testroot/wt/dotgotbar.link $testroot/content
2261 cmp -s $testroot/content.expected $testroot/content
2262 ret=$?
2263 if [ $ret -ne 0 ]; then
2264 diff -u $testroot/content.expected $testroot/content
2265 test_done "$testroot" "$ret"
2266 return 1
2269 if [ -h $testroot/wt/new.link ]; then
2270 echo "new.link is a symlink"
2271 test_done "$testroot" "1"
2272 return 1
2275 echo "<<<<<<< merged change: commit $commit_id2" \
2276 > $testroot/content.expected
2277 echo "alpha" >> $testroot/content.expected
2278 echo "=======" >> $testroot/content.expected
2279 echo "beta" >> $testroot/content.expected
2280 echo '>>>>>>>' >> $testroot/content.expected
2281 echo -n "" >> $testroot/content.expected
2283 cp $testroot/wt/new.link $testroot/content
2284 cmp -s $testroot/content.expected $testroot/content
2285 ret=$?
2286 if [ $ret -ne 0 ]; then
2287 diff -u $testroot/content.expected $testroot/content
2288 test_done "$testroot" "$ret"
2289 return 1
2292 echo "A dotgotfoo.link" > $testroot/stdout.expected
2293 echo "M new.link" >> $testroot/stdout.expected
2294 echo "D nonexistent.link" >> $testroot/stdout.expected
2295 (cd $testroot/wt && got status > $testroot/stdout)
2296 ret=$?
2297 if [ $ret -ne 0 ]; then
2298 diff -u $testroot/stdout.expected $testroot/stdout
2299 test_done "$testroot" "$ret"
2300 return 1
2303 test_done "$testroot" "0"
2307 test_update_single_file() {
2308 local testroot=`test_init update_single_file 1`
2310 echo c1 > $testroot/repo/c
2311 (cd $testroot/repo && git add .)
2312 git_commit $testroot/repo -m "adding file c"
2313 local commit_id1=`git_show_head $testroot/repo`
2315 echo a > $testroot/repo/a
2316 echo b > $testroot/repo/b
2317 echo c2 > $testroot/repo/c
2318 (cd $testroot/repo && git add .)
2319 git_commit $testroot/repo -m "add files a and b, change c"
2320 local commit_id2=`git_show_head $testroot/repo`
2322 (cd $testroot/repo && git rm -qf c)
2323 git_commit $testroot/repo -m "remove file c"
2324 local commit_id3=`git_show_head $testroot/repo`
2326 got checkout -c $commit_id2 $testroot/repo $testroot/wt > /dev/null
2327 ret=$?
2328 if [ $ret -ne 0 ]; then
2329 test_done "$testroot" "$ret"
2330 return 1
2333 echo "U c" > $testroot/stdout.expected
2334 echo "Updated to refs/heads/master: $commit_id1" \
2335 >> $testroot/stdout.expected
2337 (cd $testroot/wt && got update -c $commit_id1 c \
2338 > $testroot/stdout)
2340 cmp -s $testroot/stdout.expected $testroot/stdout
2341 ret=$?
2342 if [ $ret -ne 0 ]; then
2343 diff -u $testroot/stdout.expected $testroot/stdout
2344 test_done "$testroot" "$ret"
2345 return 1
2348 echo c1 > $testroot/content.expected
2349 cat $testroot/wt/c > $testroot/content
2351 cmp -s $testroot/content.expected $testroot/content
2352 ret=$?
2353 if [ $ret -ne 0 ]; then
2354 diff -u $testroot/content.expected $testroot/content
2355 test_done "$testroot" "$ret"
2356 return 1
2359 echo "U c" > $testroot/stdout.expected
2360 echo "Updated to refs/heads/master: $commit_id2" \
2361 >> $testroot/stdout.expected
2363 (cd $testroot/wt && got update -c $commit_id2 c > $testroot/stdout)
2365 cmp -s $testroot/stdout.expected $testroot/stdout
2366 ret=$?
2367 if [ $ret -ne 0 ]; then
2368 diff -u $testroot/stdout.expected $testroot/stdout
2369 test_done "$testroot" "$ret"
2370 return 1
2373 echo c2 > $testroot/content.expected
2374 cat $testroot/wt/c > $testroot/content
2376 cmp -s $testroot/content.expected $testroot/content
2377 ret=$?
2378 if [ $ret -ne 0 ]; then
2379 diff -u $testroot/content.expected $testroot/content
2380 test_done "$testroot" "$ret"
2381 return 1
2384 echo "D c" > $testroot/stdout.expected
2385 echo "Updated to refs/heads/master: $commit_id3" \
2386 >> $testroot/stdout.expected
2388 (cd $testroot/wt && got update -c $commit_id3 c \
2389 > $testroot/stdout 2> $testroot/stderr)
2391 echo "got: /c: no such entry found in tree" > $testroot/stderr.expected
2392 cmp -s $testroot/stderr.expected $testroot/stderr
2393 ret=$?
2394 if [ $ret -ne 0 ]; then
2395 diff -u $testroot/stderr.expected $testroot/stderr
2396 test_done "$testroot" "$ret"
2397 return 1
2400 echo -n > $testroot/stdout.expected
2401 cmp -s $testroot/stdout.expected $testroot/stdout
2402 ret=$?
2403 if [ $ret -ne 0 ]; then
2404 diff -u $testroot/stdout.expected $testroot/stdout
2405 test_done "$testroot" "$ret"
2406 return 1
2409 echo "D c" > $testroot/stdout.expected
2410 echo "Updated to refs/heads/master: $commit_id3" \
2411 >> $testroot/stdout.expected
2413 (cd $testroot/wt && got update -c $commit_id3 > $testroot/stdout)
2414 cmp -s $testroot/stdout.expected $testroot/stdout
2415 ret=$?
2416 if [ $ret -ne 0 ]; then
2417 diff -u $testroot/stdout.expected $testroot/stdout
2418 test_done "$testroot" "$ret"
2419 return 1
2422 if [ -e $testroot/wt/c ]; then
2423 echo "removed file c still exists on disk" >&2
2424 test_done "$testroot" "1"
2425 return 1
2428 test_done "$testroot" "0"
2429 return 0
2432 test_update_file_skipped_due_to_conflict() {
2433 local testroot=`test_init update_file_skipped_due_to_conflict`
2434 local commit_id0=`git_show_head $testroot/repo`
2435 blob_id0=`get_blob_id $testroot/repo "" beta`
2437 echo "changed beta" > $testroot/repo/beta
2438 git_commit $testroot/repo -m "changed beta"
2439 local commit_id1=`git_show_head $testroot/repo`
2440 blob_id1=`get_blob_id $testroot/repo "" beta`
2442 got checkout $testroot/repo $testroot/wt > /dev/null
2443 ret=$?
2444 if [ $ret -ne 0 ]; then
2445 test_done "$testroot" "$ret"
2446 return 1
2449 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2450 cut -d ':' -f 2 | tr -d ' ')`
2451 if [ "$blob_id" != "$blob_id1" ]; then
2452 echo "file beta has the wrong base blob ID" >&2
2453 test_done "$testroot" "1"
2454 return 1
2457 commit_id=`(cd $testroot/wt && got info beta | \
2458 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2459 if [ "$commit_id" != "$commit_id1" ]; then
2460 echo "file beta has the wrong base commit ID" >&2
2461 test_done "$testroot" "1"
2462 return 1
2465 echo "modified beta" > $testroot/wt/beta
2467 (cd $testroot/wt && got update -c $commit_id0 > $testroot/stdout)
2469 echo "C beta" > $testroot/stdout.expected
2470 echo "Updated to refs/heads/master: $commit_id0" \
2471 >> $testroot/stdout.expected
2472 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2473 cmp -s $testroot/stdout.expected $testroot/stdout
2474 ret=$?
2475 if [ $ret -ne 0 ]; then
2476 diff -u $testroot/stdout.expected $testroot/stdout
2477 test_done "$testroot" "$ret"
2478 return 1
2481 echo "<<<<<<< merged change: commit $commit_id0" \
2482 > $testroot/content.expected
2483 echo "beta" >> $testroot/content.expected
2484 echo "||||||| 3-way merge base: commit $commit_id1" \
2485 >> $testroot/content.expected
2486 echo "changed beta" >> $testroot/content.expected
2487 echo "=======" >> $testroot/content.expected
2488 echo "modified beta" >> $testroot/content.expected
2489 echo ">>>>>>>" >> $testroot/content.expected
2491 cat $testroot/wt/beta > $testroot/content
2493 cmp -s $testroot/content.expected $testroot/content
2494 ret=$?
2495 if [ $ret -ne 0 ]; then
2496 diff -u $testroot/content.expected $testroot/content
2497 test_done "$testroot" "$ret"
2498 return 1
2501 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2502 cut -d ':' -f 2 | tr -d ' ')`
2503 if [ "$blob_id" != "$blob_id0" ]; then
2504 echo "file beta has the wrong base blob ID" >&2
2505 test_done "$testroot" "1"
2506 return 1
2509 commit_id=`(cd $testroot/wt && got info beta | \
2510 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2511 if [ "$commit_id" != "$commit_id0" ]; then
2512 echo "file beta has the wrong base commit ID" >&2
2513 test_done "$testroot" "1"
2514 return 1
2517 # update to the latest commit again; this skips beta
2518 (cd $testroot/wt && got update > $testroot/stdout)
2519 echo "# beta" > $testroot/stdout.expected
2520 echo "Updated to refs/heads/master: $commit_id1" \
2521 >> $testroot/stdout.expected
2522 echo "Files not updated because of existing merge conflicts: 1" \
2523 >> $testroot/stdout.expected
2524 cmp -s $testroot/stdout.expected $testroot/stdout
2525 ret=$?
2526 if [ $ret -ne 0 ]; then
2527 diff -u $testroot/stdout.expected $testroot/stdout
2528 test_done "$testroot" "$ret"
2529 return 1
2532 # blob ID of beta should not have changed
2533 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2534 cut -d ':' -f 2 | tr -d ' ')`
2535 if [ "$blob_id" != "$blob_id0" ]; then
2536 echo "file beta has the wrong base blob ID" >&2
2537 test_done "$testroot" "1"
2538 return 1
2541 # commit ID of beta should not have changed; There was a bug
2542 # here where the commit ID had been changed even though the
2543 # file was not updated.
2544 commit_id=`(cd $testroot/wt && got info beta | \
2545 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2546 if [ "$commit_id" != "$commit_id0" ]; then
2547 echo "file beta has the wrong base commit ID: $commit_id" >&2
2548 test_done "$testroot" "1"
2549 return 1
2552 # beta is still conflicted and based on commit 0
2553 echo 'C beta' > $testroot/stdout.expected
2554 (cd $testroot/wt && got status > $testroot/stdout)
2555 cmp -s $testroot/stdout.expected $testroot/stdout
2556 ret=$?
2557 if [ $ret -ne 0 ]; then
2558 diff -u $testroot/stdout.expected $testroot/stdout
2559 test_done "$testroot" "$ret"
2560 return 1
2563 # resolve the conflict via revert
2564 (cd $testroot/wt && got revert beta >/dev/null)
2566 # beta now matches its base blob which is still from commit 0
2567 echo "beta" > $testroot/content.expected
2568 cat $testroot/wt/beta > $testroot/content
2569 cmp -s $testroot/content.expected $testroot/content
2570 ret=$?
2571 if [ $ret -ne 0 ]; then
2572 diff -u $testroot/content.expected $testroot/content
2573 test_done "$testroot" "$ret"
2574 return 1
2577 # updating to the latest commit should now update beta
2578 (cd $testroot/wt && got update > $testroot/stdout)
2579 echo "U beta" > $testroot/stdout.expected
2580 echo "Updated to refs/heads/master: $commit_id1" \
2581 >> $testroot/stdout.expected
2582 cmp -s $testroot/stdout.expected $testroot/stdout
2583 ret=$?
2584 if [ $ret -ne 0 ]; then
2585 diff -u $testroot/stdout.expected $testroot/stdout
2586 test_done "$testroot" "$ret"
2587 return 1
2590 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2591 cut -d ':' -f 2 | tr -d ' ')`
2592 if [ "$blob_id" != "$blob_id1" ]; then
2593 echo "file beta has the wrong base blob ID" >&2
2594 test_done "$testroot" "1"
2595 return 1
2598 commit_id=`(cd $testroot/wt && got info beta | \
2599 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2600 if [ "$commit_id" != "$commit_id1" ]; then
2601 echo "file beta has the wrong base commit ID: $commit_id" >&2
2602 test_done "$testroot" "1"
2603 return 1
2606 echo "changed beta" > $testroot/content.expected
2607 cat $testroot/wt/beta > $testroot/content
2608 cmp -s $testroot/content.expected $testroot/content
2609 ret=$?
2610 if [ $ret -ne 0 ]; then
2611 diff -u $testroot/content.expected $testroot/content
2613 test_done "$testroot" "$ret"
2616 test_update_file_skipped_due_to_obstruction() {
2617 local testroot=`test_init update_file_skipped_due_to_obstruction`
2618 local commit_id0=`git_show_head $testroot/repo`
2619 blob_id0=`get_blob_id $testroot/repo "" beta`
2621 echo "changed beta" > $testroot/repo/beta
2622 echo "new file" > $testroot/repo/new
2623 (cd $testroot/repo && git add new)
2624 git_commit $testroot/repo -m "changed beta"
2625 local commit_id1=`git_show_head $testroot/repo`
2626 blob_id1=`get_blob_id $testroot/repo "" beta`
2628 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
2629 ret=$?
2630 if [ $ret -ne 0 ]; then
2631 test_done "$testroot" "$ret"
2632 return 1
2635 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2636 cut -d ':' -f 2 | tr -d ' ')`
2637 if [ "$blob_id" != "$blob_id0" ]; then
2638 echo "file beta has the wrong base blob ID" >&2
2639 test_done "$testroot" "1"
2640 return 1
2643 commit_id=`(cd $testroot/wt && got info beta | \
2644 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2645 if [ "$commit_id" != "$commit_id0" ]; then
2646 echo "file beta has the wrong base commit ID" >&2
2647 test_done "$testroot" "1"
2648 return 1
2651 rm $testroot/wt/beta
2652 mkdir -p $testroot/wt/beta/psi
2653 mkdir -p $testroot/wt/new
2655 # update to the latest commit; this skips beta and the new file
2656 (cd $testroot/wt && got update > $testroot/stdout)
2657 ret=$?
2658 if [ $ret -ne 0 ]; then
2659 echo "update failed unexpectedly" >&2
2660 test_done "$testroot" "1"
2661 return 1
2664 echo "~ beta" > $testroot/stdout.expected
2665 echo "~ new" >> $testroot/stdout.expected
2666 echo "Updated to refs/heads/master: $commit_id1" \
2667 >> $testroot/stdout.expected
2668 echo "File paths obstructed by a non-regular file: 2" \
2669 >> $testroot/stdout.expected
2670 cmp -s $testroot/stdout.expected $testroot/stdout
2671 ret=$?
2672 if [ $ret -ne 0 ]; then
2673 diff -u $testroot/stdout.expected $testroot/stdout
2674 test_done "$testroot" "$ret"
2675 return 1
2678 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2679 cut -d ':' -f 2 | tr -d ' ')`
2680 if [ "$blob_id" != "$blob_id0" ]; then
2681 echo "file beta has the wrong base blob ID" >&2
2682 test_done "$testroot" "1"
2683 return 1
2686 commit_id=`(cd $testroot/wt && got info beta | \
2687 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2688 if [ "$commit_id" != "$commit_id0" ]; then
2689 echo "file beta has the wrong base commit ID" >&2
2690 test_done "$testroot" "1"
2691 return 1
2694 # remove the directory which obstructs file beta
2695 rm -r $testroot/wt/beta
2697 # updating to the latest commit should now update beta
2698 (cd $testroot/wt && got update > $testroot/stdout)
2699 echo "! beta" > $testroot/stdout.expected
2700 echo "~ new" >> $testroot/stdout.expected
2701 echo "Updated to refs/heads/master: $commit_id1" \
2702 >> $testroot/stdout.expected
2703 echo "File paths obstructed by a non-regular file: 1" \
2704 >> $testroot/stdout.expected
2705 cmp -s $testroot/stdout.expected $testroot/stdout
2706 ret=$?
2707 if [ $ret -ne 0 ]; then
2708 diff -u $testroot/stdout.expected $testroot/stdout
2709 test_done "$testroot" "$ret"
2710 return 1
2713 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2714 cut -d ':' -f 2 | tr -d ' ')`
2715 if [ "$blob_id" != "$blob_id1" ]; then
2716 echo "file beta has the wrong base blob ID" >&2
2717 test_done "$testroot" "1"
2718 return 1
2721 commit_id=`(cd $testroot/wt && got info beta | \
2722 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2723 if [ "$commit_id" != "$commit_id1" ]; then
2724 echo "file beta has the wrong base commit ID: $commit_id" >&2
2725 test_done "$testroot" "1"
2726 return 1
2729 echo "changed beta" > $testroot/content.expected
2730 cat $testroot/wt/beta > $testroot/content
2731 cmp -s $testroot/content.expected $testroot/content
2732 ret=$?
2733 if [ $ret -ne 0 ]; then
2734 diff -u $testroot/content.expected $testroot/content
2736 test_done "$testroot" "$ret"
2739 test_update_quiet() {
2740 local testroot=`test_init update_quiet`
2742 got checkout $testroot/repo $testroot/wt > /dev/null
2743 ret=$?
2744 if [ $ret -ne 0 ]; then
2745 test_done "$testroot" "$ret"
2746 return 1
2749 echo "modified alpha" > $testroot/repo/alpha
2750 git_commit $testroot/repo -m "modified alpha"
2752 echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected
2753 git_show_head $testroot/repo >> $testroot/stdout.expected
2754 echo >> $testroot/stdout.expected
2756 (cd $testroot/wt && got update -q > $testroot/stdout)
2758 cmp -s $testroot/stdout.expected $testroot/stdout
2759 ret=$?
2760 if [ $ret -ne 0 ]; then
2761 diff -u $testroot/stdout.expected $testroot/stdout
2762 test_done "$testroot" "$ret"
2763 return 1
2766 echo "modified alpha" > $testroot/content.expected
2767 cat $testroot/wt/alpha > $testroot/content
2769 cmp -s $testroot/content.expected $testroot/content
2770 ret=$?
2771 if [ $ret -ne 0 ]; then
2772 diff -u $testroot/content.expected $testroot/content
2774 test_done "$testroot" "$ret"
2777 test_update_binary_file() {
2778 local testroot=`test_init update_binary_file`
2779 local commit_id0=`git_show_head $testroot/repo`
2781 got checkout $testroot/repo $testroot/wt > /dev/null
2782 ret=$?
2783 if [ $ret -ne 0 ]; then
2784 test_done "$testroot" "$ret"
2785 return 1
2788 cp /bin/ls $testroot/wt/foo
2789 chmod 755 $testroot/wt/foo
2790 (cd $testroot/wt && got add foo >/dev/null)
2791 (cd $testroot/wt && got commit -m 'add binary file' > /dev/null)
2792 local commit_id1=`git_show_head $testroot/repo`
2794 cp /bin/cat $testroot/wt/foo
2795 chmod 755 $testroot/wt/foo
2796 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2797 local commit_id2=`git_show_head $testroot/repo`
2799 cp /bin/cp $testroot/wt/foo
2800 chmod 755 $testroot/wt/foo
2801 (cd $testroot/wt && got commit -m 'change binary file' > /dev/null)
2802 local commit_id3=`git_show_head $testroot/repo`
2804 (cd $testroot/wt && got rm foo >/dev/null)
2805 (cd $testroot/wt && got commit -m 'remove binary file' > /dev/null)
2806 local commit_id4=`git_show_head $testroot/repo`
2808 # backdate the work tree to make it usable for updating
2809 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2811 # update which adds a binary file
2812 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2814 echo "A foo" > $testroot/stdout.expected
2815 echo -n "Updated to refs/heads/master: $commit_id1" \
2816 >> $testroot/stdout.expected
2817 echo >> $testroot/stdout.expected
2818 cmp -s $testroot/stdout.expected $testroot/stdout
2819 ret=$?
2820 if [ $ret -ne 0 ]; then
2821 diff -u $testroot/stdout.expected $testroot/stdout
2822 test_done "$testroot" "$ret"
2823 return 1
2826 cp /bin/ls $testroot/content.expected
2827 chmod 755 $testroot/content.expected
2828 cat $testroot/wt/foo > $testroot/content
2830 cmp -s $testroot/content.expected $testroot/content
2831 ret=$?
2832 if [ $ret -ne 0 ]; then
2833 diff -u $testroot/content.expected $testroot/content
2834 test_done "$testroot" "$ret"
2835 return 1
2838 # update which adds a conflicting binary file
2839 (cd $testroot/wt && got up -c $commit_id0 > /dev/null)
2840 cp /bin/cat $testroot/wt/foo
2841 chmod 755 $testroot/wt/foo
2842 (cd $testroot/wt && got add foo > /dev/null)
2843 (cd $testroot/wt && got up -c $commit_id1 > $testroot/stdout)
2845 echo "C foo" > $testroot/stdout.expected
2846 echo "Updated to refs/heads/master: $commit_id1" \
2847 >> $testroot/stdout.expected
2848 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2849 cmp -s $testroot/stdout.expected $testroot/stdout
2850 ret=$?
2851 if [ $ret -ne 0 ]; then
2852 diff -u $testroot/stdout.expected $testroot/stdout
2853 test_done "$testroot" "$ret"
2854 return 1
2857 echo "Binary files differ and cannot be merged automatically:" \
2858 > $testroot/content.expected
2859 echo "<<<<<<< merged change: commit $commit_id1" \
2860 >> $testroot/content.expected
2861 echo -n "file " >> $testroot/content.expected
2862 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2863 echo '=======' >> $testroot/content.expected
2864 echo -n "file " >> $testroot/content.expected
2865 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2866 echo ">>>>>>>" >> $testroot/content.expected
2867 cat $testroot/wt/foo > $testroot/content
2869 cmp -s $testroot/content.expected $testroot/content
2870 ret=$?
2871 if [ $ret -ne 0 ]; then
2872 diff -u $testroot/content.expected $testroot/content
2873 test_done "$testroot" "$ret"
2874 return 1
2877 cp /bin/ls $testroot/content.expected
2878 chmod 755 $testroot/content.expected
2879 cat $testroot/wt/foo-1-* > $testroot/content
2881 cmp -s $testroot/content.expected $testroot/content
2882 ret=$?
2883 if [ $ret -ne 0 ]; then
2884 diff -u $testroot/content.expected $testroot/content
2885 test_done "$testroot" "$ret"
2886 return 1
2889 cp /bin/cat $testroot/content.expected
2890 chmod 755 $testroot/content.expected
2891 cat $testroot/wt/foo-2-* > $testroot/content
2893 cmp -s $testroot/content.expected $testroot/content
2894 ret=$?
2895 if [ $ret -ne 0 ]; then
2896 diff -u $testroot/content.expected $testroot/content
2897 test_done "$testroot" "$ret"
2898 return 1
2901 # tidy up
2902 (cd $testroot/wt && got revert -R . >/dev/null)
2903 rm $testroot/wt/foo-1-* $testroot/wt/foo-2-*
2904 (cd $testroot/wt && got up -c $commit_id1 > /dev/null)
2906 # update which changes a binary file
2907 (cd $testroot/wt && got up -c $commit_id2 > $testroot/stdout)
2909 echo "U foo" > $testroot/stdout.expected
2910 echo -n "Updated to refs/heads/master: $commit_id2" \
2911 >> $testroot/stdout.expected
2912 echo >> $testroot/stdout.expected
2913 cmp -s $testroot/stdout.expected $testroot/stdout
2914 ret=$?
2915 if [ $ret -ne 0 ]; then
2916 diff -u $testroot/stdout.expected $testroot/stdout
2917 test_done "$testroot" "$ret"
2918 return 1
2921 cp /bin/cat $testroot/content.expected
2922 chmod 755 $testroot/content.expected
2923 cat $testroot/wt/foo > $testroot/content
2925 cmp -s $testroot/content.expected $testroot/content
2926 ret=$?
2927 if [ $ret -ne 0 ]; then
2928 diff -u $testroot/content.expected $testroot/content
2929 test_done "$testroot" "$ret"
2930 return 1
2933 # update which changes a locally modified binary file
2934 cp /bin/ls $testroot/wt/foo
2935 chmod 755 $testroot/wt/foo
2936 (cd $testroot/wt && got up -c $commit_id3 > $testroot/stdout)
2938 echo "C foo" > $testroot/stdout.expected
2939 echo -n "Updated to refs/heads/master: $commit_id3" \
2940 >> $testroot/stdout.expected
2941 echo >> $testroot/stdout.expected
2942 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2943 cmp -s $testroot/stdout.expected $testroot/stdout
2944 ret=$?
2945 if [ $ret -ne 0 ]; then
2946 diff -u $testroot/stdout.expected $testroot/stdout
2947 test_done "$testroot" "$ret"
2948 return 1
2951 echo "Binary files differ and cannot be merged automatically:" \
2952 > $testroot/content.expected
2953 echo "<<<<<<< merged change: commit $commit_id3" \
2954 >> $testroot/content.expected
2955 echo -n "file " >> $testroot/content.expected
2956 ls $testroot/wt/foo-1-* >> $testroot/content.expected
2957 echo "||||||| 3-way merge base: commit $commit_id2" \
2958 >> $testroot/content.expected
2959 echo -n "file " >> $testroot/content.expected
2960 ls $testroot/wt/foo-orig-* >> $testroot/content.expected
2961 echo '=======' >> $testroot/content.expected
2962 echo -n "file " >> $testroot/content.expected
2963 ls $testroot/wt/foo-2-* >> $testroot/content.expected
2964 echo ">>>>>>>" >> $testroot/content.expected
2965 cat $testroot/wt/foo > $testroot/content
2967 cmp -s $testroot/content.expected $testroot/content
2968 ret=$?
2969 if [ $ret -ne 0 ]; then
2970 diff -u $testroot/content.expected $testroot/content
2971 test_done "$testroot" "$ret"
2972 return 1
2975 cp /bin/cp $testroot/content.expected
2976 chmod 755 $testroot/content.expected
2977 cp $testroot/wt/foo-1-* $testroot/content
2978 cmp -s $testroot/content.expected $testroot/content
2979 ret=$?
2980 if [ $ret -ne 0 ]; then
2981 diff -u $testroot/content.expected $testroot/content
2982 test_done "$testroot" "$ret"
2983 return 1
2986 cp /bin/ls $testroot/content.expected
2987 chmod 755 $testroot/content.expected
2988 cp $testroot/wt/foo-2-* $testroot/content
2989 cmp -s $testroot/content.expected $testroot/content
2990 ret=$?
2991 if [ $ret -ne 0 ]; then
2992 diff -u $testroot/content.expected $testroot/content
2993 test_done "$testroot" "$ret"
2994 return 1
2997 (cd $testroot/wt && got status > $testroot/stdout)
2998 echo 'C foo' > $testroot/stdout.expected
2999 echo -n '? ' >> $testroot/stdout.expected
3000 (cd $testroot/wt && ls foo-1-* >> $testroot/stdout.expected)
3001 echo -n '? ' >> $testroot/stdout.expected
3002 (cd $testroot/wt && ls foo-2-* >> $testroot/stdout.expected)
3003 echo -n '? ' >> $testroot/stdout.expected
3004 (cd $testroot/wt && ls foo-orig-* >> $testroot/stdout.expected)
3005 cmp -s $testroot/stdout.expected $testroot/stdout
3006 ret=$?
3007 if [ $ret -ne 0 ]; then
3008 diff -u $testroot/stdout.expected $testroot/stdout
3009 test_done "$testroot" "$ret"
3010 return 1
3013 # tidy up
3014 (cd $testroot/wt && got revert -R . > /dev/null)
3015 rm $testroot/wt/foo-orig-* $testroot/wt/foo-1-* $testroot/wt/foo-2-*
3017 # update which deletes a binary file
3018 (cd $testroot/wt && got up -c $commit_id4 > $testroot/stdout)
3019 echo "D foo" > $testroot/stdout.expected
3020 echo -n "Updated to refs/heads/master: $commit_id4" \
3021 >> $testroot/stdout.expected
3022 echo >> $testroot/stdout.expected
3023 cmp -s $testroot/stdout.expected $testroot/stdout
3024 ret=$?
3025 if [ $ret -ne 0 ]; then
3026 diff -u $testroot/stdout.expected $testroot/stdout
3027 test_done "$testroot" "$ret"
3030 if [ -e $testroot/wt/foo ]; then
3031 echo "removed file foo still exists on disk" >&2
3032 test_done "$testroot" "1"
3033 return 1
3035 test_done "$testroot" "0"
3038 test_update_umask() {
3039 local testroot=`test_init update_binary_file`
3041 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
3042 ret=$?
3043 if [ $ret -ne 0 ]; then
3044 test_done "$testroot" "$ret"
3045 return 1
3048 rm "$testroot/wt/alpha"
3050 # using a subshell to avoid clobbering global umask
3051 (umask 022 && cd "$testroot/wt" && got update alpha) \
3052 >/dev/null 2>/dev/null
3053 ret=$?
3054 if [ $ret -ne 0 ]; then
3055 test_done "$testroot" $ret
3056 return 1
3059 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-r--r--; then
3060 echo "alpha is not 0644" >&2
3061 test_done "$testroot" 1
3062 return 1
3065 rm "$testroot/wt/alpha"
3067 # using a subshell to avoid clobbering global umask
3068 (umask 044 && cd "$testroot/wt" && got update alpha) \
3069 >/dev/null 2>/dev/null
3070 ret=$?
3071 if [ $ret -ne 0 ]; then
3072 test_done "$testroot" $ret
3073 return 1
3076 if ! ls -l "$testroot/wt/alpha" | grep -q ^-rw-------; then
3077 echo "alpha is not 0600" >&2
3078 test_done "$testroot" 1
3079 return 1
3082 rm "$testroot/wt/alpha"
3084 # using a subshell to avoid clobbering global umask
3085 (umask 222 && cd "$testroot/wt" && got update alpha) \
3086 >/dev/null 2>/dev/null
3087 ret=$?
3088 if [ $ret -ne 0 ]; then
3089 test_done "$testroot" $ret
3090 return 1
3093 if ! ls -l "$testroot/wt/alpha" | grep -q ^-r--r--r--; then
3094 echo "alpha is not 0444" >&2
3095 test_done "$testroot" 1
3096 return 1;
3099 test_done "$testroot" 0
3102 test_parseargs "$@"
3103 run_test test_update_basic
3104 run_test test_update_adds_file
3105 run_test test_update_deletes_file
3106 run_test test_update_deletes_dir
3107 run_test test_update_deletes_dir_with_path_prefix
3108 run_test test_update_deletes_dir_recursively
3109 run_test test_update_sibling_dirs_with_common_prefix
3110 run_test test_update_dir_with_dot_sibling
3111 run_test test_update_moves_files_upwards
3112 run_test test_update_moves_files_to_new_dir
3113 run_test test_update_creates_missing_parent
3114 run_test test_update_creates_missing_parent_with_subdir
3115 run_test test_update_file_in_subsubdir
3116 run_test test_update_changes_file_to_dir
3117 run_test test_update_merges_file_edits
3118 run_test test_update_keeps_xbit
3119 run_test test_update_clears_xbit
3120 run_test test_update_restores_missing_file
3121 run_test test_update_conflict_wt_add_vs_repo_add
3122 run_test test_update_conflict_wt_edit_vs_repo_rm
3123 run_test test_update_conflict_wt_rm_vs_repo_edit
3124 run_test test_update_conflict_wt_rm_vs_repo_rm
3125 run_test test_update_partial
3126 run_test test_update_partial_add
3127 run_test test_update_partial_rm
3128 run_test test_update_partial_dir
3129 run_test test_update_moved_branch_ref
3130 run_test test_update_to_another_branch
3131 run_test test_update_to_commit_on_wrong_branch
3132 run_test test_update_bumps_base_commit_id
3133 run_test test_update_tag
3134 run_test test_update_toggles_xbit
3135 run_test test_update_preserves_conflicted_file
3136 run_test test_update_modified_submodules
3137 run_test test_update_adds_submodule
3138 run_test test_update_conflict_wt_file_vs_repo_submodule
3139 run_test test_update_adds_symlink
3140 run_test test_update_deletes_symlink
3141 run_test test_update_symlink_conflicts
3142 run_test test_update_single_file
3143 run_test test_update_file_skipped_due_to_conflict
3144 run_test test_update_file_skipped_due_to_obstruction
3145 run_test test_update_quiet
3146 run_test test_update_binary_file
3147 run_test test_update_umask