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" != "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 commit " >> $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" != "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" != "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" != "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 commit " >> $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" != "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" != "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" != "0" ]; then
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 (cd $testroot/repo && git_rm $testroot/repo beta)
110 git_commit $testroot/repo -m "deleting a file"
112 echo "D beta" > $testroot/stdout.expected
113 echo -n "Updated to commit " >> $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" != "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" != "0" ]; then
146 test_done "$testroot" "$ret"
147 return 1
148 fi
150 (cd $testroot/repo && git_rm $testroot/repo -r epsilon)
151 git_commit $testroot/repo -m "deleting a directory"
153 echo "D epsilon/zeta" > $testroot/stdout.expected
154 echo -n "Updated to commit " >> $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" != "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" != "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 commit $first_rev" >> $testroot/stdout.expected
198 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
200 cmp -s $testroot/stdout.expected $testroot/stdout
201 ret="$?"
202 if [ "$ret" != "0" ]; then
203 diff -u $testroot/stdout.expected $testroot/stdout
204 test_done "$testroot" "$ret"
205 return 1
206 fi
208 if [ -e $testroot/wt/psi ]; then
209 echo "removed dir psi still exists on disk" >&2
210 test_done "$testroot" "1"
211 return 1
212 fi
214 test_done "$testroot" "0"
217 test_update_deletes_dir_recursively() {
218 local testroot=`test_init update_deletes_dir_recursively`
219 local first_rev=`git_show_head $testroot/repo`
221 mkdir $testroot/repo/epsilon/psi
222 echo mu > $testroot/repo/epsilon/psi/mu
223 mkdir $testroot/repo/epsilon/psi/chi
224 echo tau > $testroot/repo/epsilon/psi/chi/tau
225 (cd $testroot/repo && git add .)
226 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
228 # check out the epsilon/ sub-tree
229 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
230 ret="$?"
231 if [ "$ret" != "0" ]; then
232 test_done "$testroot" "$ret"
233 return 1
234 fi
236 # update back to first commit and expect psi/mu to be deleted
237 echo "D psi/chi/tau" > $testroot/stdout.expected
238 echo "D psi/mu" >> $testroot/stdout.expected
239 echo "Updated to commit $first_rev" >> $testroot/stdout.expected
241 (cd $testroot/wt && got update -c $first_rev > $testroot/stdout)
243 cmp -s $testroot/stdout.expected $testroot/stdout
244 ret="$?"
245 if [ "$?" != "0" ]; then
246 diff -u $testroot/stdout.expected $testroot/stdout
247 test_done "$testroot" "$ret"
248 return 1
249 fi
251 if [ -e $testroot/wt/psi ]; then
252 echo "removed dir psi still exists on disk" >&2
253 test_done "$testroot" "1"
254 return 1
255 fi
257 test_done "$testroot" "0"
260 test_update_sibling_dirs_with_common_prefix() {
261 local testroot=`test_init update_sibling_dirs_with_common_prefix`
263 got checkout $testroot/repo $testroot/wt > /dev/null
264 ret="$?"
265 if [ "$ret" != "0" ]; then
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 mkdir $testroot/repo/epsilon2
271 echo mu > $testroot/repo/epsilon2/mu
272 (cd $testroot/repo && git add epsilon2/mu)
273 git_commit $testroot/repo -m "adding sibling of epsilon"
274 echo change > $testroot/repo/epsilon/zeta
275 git_commit $testroot/repo -m "changing epsilon/zeta"
277 echo "U epsilon/zeta" > $testroot/stdout.expected
278 echo "A epsilon2/mu" >> $testroot/stdout.expected
279 echo -n "Updated to commit " >> $testroot/stdout.expected
280 git_show_head $testroot/repo >> $testroot/stdout.expected
281 echo >> $testroot/stdout.expected
283 (cd $testroot/wt && got update > $testroot/stdout)
285 cmp -s $testroot/stdout.expected $testroot/stdout
286 ret="$?"
287 if [ "$ret" != "0" ]; then
288 diff -u $testroot/stdout.expected $testroot/stdout
289 test_done "$testroot" "$ret"
290 return 1
291 fi
293 echo "another change" > $testroot/repo/epsilon/zeta
294 git_commit $testroot/repo -m "changing epsilon/zeta again"
296 echo "U epsilon/zeta" > $testroot/stdout.expected
297 echo -n "Updated to commit " >> $testroot/stdout.expected
298 git_show_head $testroot/repo >> $testroot/stdout.expected
299 echo >> $testroot/stdout.expected
301 # Bug: This update used to do delete/add epsilon2/mu again:
302 # U epsilon/zeta
303 # D epsilon2/mu <--- not intended
304 # A epsilon2/mu <--- not intended
305 (cd $testroot/wt && got update > $testroot/stdout)
307 cmp -s $testroot/stdout.expected $testroot/stdout
308 ret="$?"
309 if [ "$ret" != "0" ]; then
310 diff -u $testroot/stdout.expected $testroot/stdout
311 test_done "$testroot" "$ret"
312 return 1
313 fi
315 cmp -s $testroot/stdout.expected $testroot/stdout
316 ret="$?"
317 if [ "$ret" != "0" ]; then
318 diff -u $testroot/stdout.expected $testroot/stdout
319 fi
320 test_done "$testroot" "$ret"
323 test_update_dir_with_dot_sibling() {
324 local testroot=`test_init update_dir_with_dot_sibling`
326 got checkout $testroot/repo $testroot/wt > /dev/null
327 ret="$ret"
328 if [ "$ret" != "0" ]; then
329 test_done "$testroot" "$ret"
330 return 1
331 fi
333 echo text > $testroot/repo/epsilon.txt
334 (cd $testroot/repo && git add epsilon.txt)
335 git_commit $testroot/repo -m "adding sibling of epsilon"
336 echo change > $testroot/repo/epsilon/zeta
337 git_commit $testroot/repo -m "changing epsilon/zeta"
339 echo "U epsilon/zeta" > $testroot/stdout.expected
340 echo "A epsilon.txt" >> $testroot/stdout.expected
341 echo -n "Updated to commit " >> $testroot/stdout.expected
342 git_show_head $testroot/repo >> $testroot/stdout.expected
343 echo >> $testroot/stdout.expected
345 (cd $testroot/wt && got update > $testroot/stdout)
347 cmp -s $testroot/stdout.expected $testroot/stdout
348 ret="$?"
349 if [ "$ret" != "0" ]; then
350 diff -u $testroot/stdout.expected $testroot/stdout
351 test_done "$testroot" "$ret"
352 return 1
353 fi
355 echo "another change" > $testroot/repo/epsilon/zeta
356 git_commit $testroot/repo -m "changing epsilon/zeta again"
358 echo "U epsilon/zeta" > $testroot/stdout.expected
359 echo -n "Updated to commit " >> $testroot/stdout.expected
360 git_show_head $testroot/repo >> $testroot/stdout.expected
361 echo >> $testroot/stdout.expected
363 (cd $testroot/wt && got update > $testroot/stdout)
365 cmp -s $testroot/stdout.expected $testroot/stdout
366 ret="$?"
367 if [ "$ret" != "0" ]; then
368 diff -u $testroot/stdout.expected $testroot/stdout
369 test_done "$testroot" "$ret"
370 return 1
371 fi
373 cmp -s $testroot/stdout.expected $testroot/stdout
374 ret="$?"
375 if [ "$ret" != "0" ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 fi
378 test_done "$testroot" "$ret"
381 test_update_moves_files_upwards() {
382 local testroot=`test_init update_moves_files_upwards`
384 mkdir $testroot/repo/epsilon/psi
385 echo mu > $testroot/repo/epsilon/psi/mu
386 mkdir $testroot/repo/epsilon/psi/chi
387 echo tau > $testroot/repo/epsilon/psi/chi/tau
388 (cd $testroot/repo && git add .)
389 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
391 got checkout $testroot/repo $testroot/wt > /dev/null
392 ret="$?"
393 if [ "$ret" != "0" ]; then
394 test_done "$testroot" "$ret"
395 return 1
396 fi
398 (cd $testroot/repo && git mv epsilon/psi/mu epsilon/mu)
399 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon/psi/tau)
400 git_commit $testroot/repo -m "moving files upwards"
402 echo "A epsilon/mu" > $testroot/stdout.expected
403 echo "D epsilon/psi/chi/tau" >> $testroot/stdout.expected
404 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
405 echo "A epsilon/psi/tau" >> $testroot/stdout.expected
406 echo -n "Updated to commit " >> $testroot/stdout.expected
407 git_show_head $testroot/repo >> $testroot/stdout.expected
408 echo >> $testroot/stdout.expected
410 (cd $testroot/wt && got update > $testroot/stdout)
412 cmp -s $testroot/stdout.expected $testroot/stdout
413 ret="$?"
414 if [ "$ret" != "0" ]; then
415 diff -u $testroot/stdout.expected $testroot/stdout
416 test_done "$testroot" "$ret"
417 return 1
418 fi
420 if [ -e $testroot/wt/epsilon/psi/chi ]; then
421 echo "removed dir epsilon/psi/chi still exists on disk" >&2
422 test_done "$testroot" "1"
423 return 1
424 fi
426 if [ -e $testroot/wt/epsilon/psi/mu ]; then
427 echo "removed file epsilon/psi/mu still exists on disk" >&2
428 test_done "$testroot" "1"
429 return 1
430 fi
432 test_done "$testroot" "0"
435 test_update_moves_files_to_new_dir() {
436 local testroot=`test_init update_moves_files_to_new_dir`
438 mkdir $testroot/repo/epsilon/psi
439 echo mu > $testroot/repo/epsilon/psi/mu
440 mkdir $testroot/repo/epsilon/psi/chi
441 echo tau > $testroot/repo/epsilon/psi/chi/tau
442 (cd $testroot/repo && git add .)
443 git_commit $testroot/repo -m "adding a sub-directory beneath epsilon"
445 got checkout $testroot/repo $testroot/wt > /dev/null
446 ret="$?"
447 if [ "$ret" != "0" ]; then
448 test_done "$testroot" "$ret"
449 return 1
450 fi
452 mkdir -p $testroot/repo/epsilon-new/psi
453 (cd $testroot/repo && git mv epsilon/psi/mu epsilon-new/mu)
454 (cd $testroot/repo && git mv epsilon/psi/chi/tau epsilon-new/psi/tau)
455 git_commit $testroot/repo -m "moving files upwards"
457 echo "D epsilon/psi/chi/tau" > $testroot/stdout.expected
458 echo "D epsilon/psi/mu" >> $testroot/stdout.expected
459 echo "A epsilon-new/mu" >> $testroot/stdout.expected
460 echo "A epsilon-new/psi/tau" >> $testroot/stdout.expected
461 echo -n "Updated to commit " >> $testroot/stdout.expected
462 git_show_head $testroot/repo >> $testroot/stdout.expected
463 echo >> $testroot/stdout.expected
465 (cd $testroot/wt && got update > $testroot/stdout)
467 cmp -s $testroot/stdout.expected $testroot/stdout
468 ret="$?"
469 if [ "$ret" != "0" ]; then
470 diff -u $testroot/stdout.expected $testroot/stdout
471 test_done "$testroot" "$ret"
472 return 1
473 fi
475 if [ -e $testroot/wt/epsilon/psi/chi ]; then
476 echo "removed dir epsilon/psi/chi still exists on disk" >&2
477 test_done "$testroot" "1"
478 return 1
479 fi
481 if [ -e $testroot/wt/epsilon/psi/mu ]; then
482 echo "removed file epsilon/psi/mu still exists on disk" >&2
483 test_done "$testroot" "1"
484 return 1
485 fi
487 test_done "$testroot" "0"
490 test_update_creates_missing_parent() {
491 local testroot=`test_init update_creates_missing_parent 1`
493 touch $testroot/repo/Makefile
494 touch $testroot/repo/snake.6
495 touch $testroot/repo/snake.c
496 (cd $testroot/repo && git add .)
497 git_commit $testroot/repo -m "adding initial snake tree"
499 got checkout $testroot/repo $testroot/wt > /dev/null
500 ret="$?"
501 if [ "$ret" != "0" ]; then
502 test_done "$testroot" "$ret"
503 return 1
504 fi
506 mkdir -p $testroot/repo/snake
507 (cd $testroot/repo && git mv Makefile snake.6 snake.c snake)
508 touch $testroot/repo/snake/move.c
509 touch $testroot/repo/snake/pathnames.h
510 touch $testroot/repo/snake/snake.h
511 mkdir -p $testroot/repo/snscore
512 touch $testroot/repo/snscore/Makefile
513 touch $testroot/repo/snscore/snscore.c
514 (cd $testroot/repo && git add .)
515 git_commit $testroot/repo -m "restructuring snake tree"
517 echo "D Makefile" > $testroot/stdout.expected
518 echo "A snake/Makefile" >> $testroot/stdout.expected
519 echo "A snake/move.c" >> $testroot/stdout.expected
520 echo "A snake/pathnames.h" >> $testroot/stdout.expected
521 echo "A snake/snake.6" >> $testroot/stdout.expected
522 echo "A snake/snake.c" >> $testroot/stdout.expected
523 echo "A snake/snake.h" >> $testroot/stdout.expected
524 echo "D snake.6" >> $testroot/stdout.expected
525 echo "D snake.c" >> $testroot/stdout.expected
526 echo "A snscore/Makefile" >> $testroot/stdout.expected
527 echo "A snscore/snscore.c" >> $testroot/stdout.expected
528 echo -n "Updated to commit " >> $testroot/stdout.expected
529 git_show_head $testroot/repo >> $testroot/stdout.expected
530 echo >> $testroot/stdout.expected
532 (cd $testroot/wt && got update > $testroot/stdout)
534 cmp -s $testroot/stdout.expected $testroot/stdout
535 ret="$?"
536 if [ "$ret" != "0" ]; then
537 diff -u $testroot/stdout.expected $testroot/stdout
538 fi
539 test_done "$testroot" "$ret"
542 test_update_creates_missing_parent_with_subdir() {
543 local testroot=`test_init update_creates_missing_parent_with_subdir 1`
545 touch $testroot/repo/Makefile
546 touch $testroot/repo/snake.6
547 touch $testroot/repo/snake.c
548 (cd $testroot/repo && git add .)
549 git_commit $testroot/repo -m "adding initial snake tree"
551 got checkout $testroot/repo $testroot/wt > /dev/null
552 ret="$?"
553 if [ "$ret" != "0" ]; then
554 test_done "$testroot" "$ret"
555 return 1
556 fi
558 mkdir -p $testroot/repo/sss/snake
559 (cd $testroot/repo && git mv Makefile snake.6 snake.c sss/snake)
560 touch $testroot/repo/sss/snake/move.c
561 touch $testroot/repo/sss/snake/pathnames.h
562 touch $testroot/repo/sss/snake/snake.h
563 mkdir -p $testroot/repo/snscore
564 touch $testroot/repo/snscore/Makefile
565 touch $testroot/repo/snscore/snscore.c
566 (cd $testroot/repo && git add .)
567 git_commit $testroot/repo -m "restructuring snake tree"
569 echo "D Makefile" > $testroot/stdout.expected
570 echo "D snake.6" >> $testroot/stdout.expected
571 echo "D snake.c" >> $testroot/stdout.expected
572 echo "A snscore/Makefile" >> $testroot/stdout.expected
573 echo "A snscore/snscore.c" >> $testroot/stdout.expected
574 echo "A sss/snake/Makefile" >> $testroot/stdout.expected
575 echo "A sss/snake/move.c" >> $testroot/stdout.expected
576 echo "A sss/snake/pathnames.h" >> $testroot/stdout.expected
577 echo "A sss/snake/snake.6" >> $testroot/stdout.expected
578 echo "A sss/snake/snake.c" >> $testroot/stdout.expected
579 echo "A sss/snake/snake.h" >> $testroot/stdout.expected
580 echo -n "Updated to commit " >> $testroot/stdout.expected
581 git_show_head $testroot/repo >> $testroot/stdout.expected
582 echo >> $testroot/stdout.expected
584 (cd $testroot/wt && got update > $testroot/stdout)
586 cmp -s $testroot/stdout.expected $testroot/stdout
587 ret="$?"
588 if [ "$ret" != "0" ]; then
589 diff -u $testroot/stdout.expected $testroot/stdout
590 test_done "$testroot" "$ret"
591 return 1
592 fi
594 test_done "$testroot" "0"
597 test_update_file_in_subsubdir() {
598 local testroot=`test_init update_fle_in_subsubdir 1`
600 touch $testroot/repo/Makefile
601 mkdir -p $testroot/repo/altq
602 touch $testroot/repo/altq/if_altq.h
603 mkdir -p $testroot/repo/arch/alpha
604 touch $testroot/repo/arch/alpha/Makefile
605 (cd $testroot/repo && git add .)
606 git_commit $testroot/repo -m "adding initial tree"
608 got checkout $testroot/repo $testroot/wt > /dev/null
609 ret="$?"
610 if [ "$ret" != "0" ]; then
611 test_done "$testroot" "$ret"
612 return 1
613 fi
615 echo change > $testroot/repo/arch/alpha/Makefile
616 (cd $testroot/repo && git add .)
617 git_commit $testroot/repo -m "changed a file"
619 echo "U arch/alpha/Makefile" > $testroot/stdout.expected
620 echo -n "Updated to commit " >> $testroot/stdout.expected
621 git_show_head $testroot/repo >> $testroot/stdout.expected
622 echo >> $testroot/stdout.expected
624 (cd $testroot/wt && got update > $testroot/stdout)
626 cmp -s $testroot/stdout.expected $testroot/stdout
627 ret="$?"
628 if [ "$ret" != "0" ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
631 return 1
632 fi
634 test_done "$testroot" "0"
637 test_update_merges_file_edits() {
638 local testroot=`test_init update_merges_file_edits`
640 echo "1" > $testroot/repo/numbers
641 echo "2" >> $testroot/repo/numbers
642 echo "3" >> $testroot/repo/numbers
643 echo "4" >> $testroot/repo/numbers
644 echo "5" >> $testroot/repo/numbers
645 echo "6" >> $testroot/repo/numbers
646 echo "7" >> $testroot/repo/numbers
647 echo "8" >> $testroot/repo/numbers
648 (cd $testroot/repo && git add numbers)
649 git_commit $testroot/repo -m "added numbers file"
650 local base_commit=`git_show_head $testroot/repo`
652 got checkout $testroot/repo $testroot/wt > /dev/null
653 ret="$?"
654 if [ "$ret" != "0" ]; then
655 test_done "$testroot" "$ret"
656 return 1
657 fi
659 echo "modified alpha" > $testroot/repo/alpha
660 echo "modified beta" > $testroot/repo/beta
661 sed -i 's/2/22/' $testroot/repo/numbers
662 git_commit $testroot/repo -m "modified 3 files"
664 echo "modified alpha, too" > $testroot/wt/alpha
665 touch $testroot/wt/beta
666 sed -i 's/7/77/' $testroot/wt/numbers
668 echo "C alpha" > $testroot/stdout.expected
669 echo "U beta" >> $testroot/stdout.expected
670 echo "G numbers" >> $testroot/stdout.expected
671 echo -n "Updated to commit " >> $testroot/stdout.expected
672 git_show_head $testroot/repo >> $testroot/stdout.expected
673 echo >> $testroot/stdout.expected
674 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
676 (cd $testroot/wt && got update > $testroot/stdout)
678 cmp -s $testroot/stdout.expected $testroot/stdout
679 ret="$?"
680 if [ "$ret" != "0" ]; then
681 diff -u $testroot/stdout.expected $testroot/stdout
682 test_done "$testroot" "$ret"
683 return 1
684 fi
686 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
687 git_show_head $testroot/repo >> $testroot/content.expected
688 echo >> $testroot/content.expected
689 echo "modified alpha" >> $testroot/content.expected
690 echo "||||||| 3-way merge base: commit $base_commit" \
691 >> $testroot/content.expected
692 echo "alpha" >> $testroot/content.expected
693 echo "=======" >> $testroot/content.expected
694 echo "modified alpha, too" >> $testroot/content.expected
695 echo '>>>>>>>' >> $testroot/content.expected
696 echo "modified beta" >> $testroot/content.expected
697 echo "1" >> $testroot/content.expected
698 echo "22" >> $testroot/content.expected
699 echo "3" >> $testroot/content.expected
700 echo "4" >> $testroot/content.expected
701 echo "5" >> $testroot/content.expected
702 echo "6" >> $testroot/content.expected
703 echo "77" >> $testroot/content.expected
704 echo "8" >> $testroot/content.expected
706 cat $testroot/wt/alpha > $testroot/content
707 cat $testroot/wt/beta >> $testroot/content
708 cat $testroot/wt/numbers >> $testroot/content
710 cmp -s $testroot/content.expected $testroot/content
711 ret="$?"
712 if [ "$ret" != "0" ]; then
713 diff -u $testroot/content.expected $testroot/content
714 fi
715 test_done "$testroot" "$ret"
718 test_update_keeps_xbit() {
719 local testroot=`test_init update_keeps_xbit 1`
721 touch $testroot/repo/xfile
722 chmod +x $testroot/repo/xfile
723 (cd $testroot/repo && git add .)
724 git_commit $testroot/repo -m "adding executable file"
726 got checkout $testroot/repo $testroot/wt > $testroot/stdout
727 ret="$?"
728 if [ "$ret" != "0" ]; then
729 test_done "$testroot" "$ret"
730 return 1
731 fi
733 echo foo > $testroot/repo/xfile
734 git_commit $testroot/repo -m "changed executable file"
736 echo "U xfile" > $testroot/stdout.expected
737 echo -n "Updated to commit " >> $testroot/stdout.expected
738 git_show_head $testroot/repo >> $testroot/stdout.expected
739 echo >> $testroot/stdout.expected
741 (cd $testroot/wt && got update > $testroot/stdout)
742 ret="$?"
743 if [ "$ret" != "0" ]; then
744 test_done "$testroot" "$ret"
745 return 1
746 fi
748 cmp -s $testroot/stdout.expected $testroot/stdout
749 ret="$?"
750 if [ "$ret" != "0" ]; then
751 diff -u $testroot/stdout.expected $testroot/stdout
752 test_done "$testroot" "$ret"
753 return 1
754 fi
756 ls -l $testroot/wt/xfile | grep -q '^-rwx'
757 ret="$?"
758 if [ "$ret" != "0" ]; then
759 echo "file is not executable" >&2
760 ls -l $testroot/wt/xfile >&2
761 fi
762 test_done "$testroot" "$ret"
765 test_update_clears_xbit() {
766 local testroot=`test_init update_clears_xbit 1`
768 touch $testroot/repo/xfile
769 chmod +x $testroot/repo/xfile
770 (cd $testroot/repo && git add .)
771 git_commit $testroot/repo -m "adding executable file"
773 got checkout $testroot/repo $testroot/wt > $testroot/stdout
774 ret="$?"
775 if [ "$ret" != "0" ]; then
776 test_done "$testroot" "$ret"
777 return 1
778 fi
780 ls -l $testroot/wt/xfile | grep -q '^-rwx'
781 ret="$?"
782 if [ "$ret" != "0" ]; then
783 echo "file is not executable" >&2
784 ls -l $testroot/wt/xfile >&2
785 test_done "$testroot" "$ret"
786 return 1
787 fi
789 # XXX git seems to require a file edit when flipping the x bit?
790 echo foo > $testroot/repo/xfile
791 chmod -x $testroot/repo/xfile
792 git_commit $testroot/repo -m "not an executable file anymore"
794 echo "U xfile" > $testroot/stdout.expected
795 echo -n "Updated to commit " >> $testroot/stdout.expected
796 git_show_head $testroot/repo >> $testroot/stdout.expected
797 echo >> $testroot/stdout.expected
799 (cd $testroot/wt && got update > $testroot/stdout)
800 ret="$?"
801 if [ "$ret" != "0" ]; then
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 cmp -s $testroot/stdout.expected $testroot/stdout
807 ret="$?"
808 if [ "$ret" != "0" ]; then
809 diff -u $testroot/stdout.expected $testroot/stdout
810 test_done "$testroot" "$ret"
811 return 1
812 fi
814 ls -l $testroot/wt/xfile | grep -q '^-rw-'
815 ret="$?"
816 if [ "$ret" != "0" ]; then
817 echo "file is unexpectedly executable" >&2
818 ls -l $testroot/wt/xfile >&2
819 fi
820 test_done "$testroot" "$ret"
823 test_update_restores_missing_file() {
824 local testroot=`test_init update_restores_missing_file`
826 got checkout $testroot/repo $testroot/wt > /dev/null
827 ret="$?"
828 if [ "$ret" != "0" ]; then
829 test_done "$testroot" "$ret"
830 return 1
831 fi
833 rm $testroot/wt/alpha
835 echo "! alpha" > $testroot/stdout.expected
836 echo -n "Updated to commit " >> $testroot/stdout.expected
837 git_show_head $testroot/repo >> $testroot/stdout.expected
838 echo >> $testroot/stdout.expected
839 (cd $testroot/wt && got update > $testroot/stdout)
841 cmp -s $testroot/stdout.expected $testroot/stdout
842 ret="$?"
843 if [ "$ret" != "0" ]; then
844 diff -u $testroot/stdout.expected $testroot/stdout
845 test_done "$testroot" "$ret"
846 return 1
847 fi
849 echo "alpha" > $testroot/content.expected
851 cat $testroot/wt/alpha > $testroot/content
853 cmp -s $testroot/content.expected $testroot/content
854 ret="$?"
855 if [ "$ret" != "0" ]; then
856 diff -u $testroot/content.expected $testroot/content
857 fi
858 test_done "$testroot" "$ret"
861 test_update_conflict_wt_add_vs_repo_add() {
862 local testroot=`test_init update_conflict_wt_add_vs_repo_add`
864 got checkout $testroot/repo $testroot/wt > /dev/null
865 ret="$?"
866 if [ "$ret" != "0" ]; then
867 test_done "$testroot" "$ret"
868 return 1
869 fi
871 echo "new" > $testroot/repo/gamma/new
872 (cd $testroot/repo && git add .)
873 git_commit $testroot/repo -m "adding a new file"
875 echo "also new" > $testroot/wt/gamma/new
876 (cd $testroot/wt && got add gamma/new >/dev/null)
878 (cd $testroot/wt && got update > $testroot/stdout)
880 echo "C gamma/new" > $testroot/stdout.expected
881 echo -n "Updated to commit " >> $testroot/stdout.expected
882 git_show_head $testroot/repo >> $testroot/stdout.expected
883 echo >> $testroot/stdout.expected
884 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
886 cmp -s $testroot/stdout.expected $testroot/stdout
887 ret="$?"
888 if [ "$ret" != "0" ]; then
889 diff -u $testroot/stdout.expected $testroot/stdout
890 test_done "$testroot" "$ret"
891 return 1
892 fi
894 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
895 git_show_head $testroot/repo >> $testroot/content.expected
896 echo >> $testroot/content.expected
897 echo "new" >> $testroot/content.expected
898 echo "=======" >> $testroot/content.expected
899 echo "also new" >> $testroot/content.expected
900 echo '>>>>>>>' >> $testroot/content.expected
902 cat $testroot/wt/gamma/new > $testroot/content
904 cmp -s $testroot/content.expected $testroot/content
905 ret="$?"
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/content.expected $testroot/content
908 test_done "$testroot" "$ret"
909 return 1
910 fi
912 # resolve the conflict
913 echo "new and also new" > $testroot/wt/gamma/new
914 echo 'M gamma/new' > $testroot/stdout.expected
915 (cd $testroot/wt && got status > $testroot/stdout)
916 cmp -s $testroot/stdout.expected $testroot/stdout
917 ret="$?"
918 if [ "$ret" != "0" ]; then
919 diff -u $testroot/stdout.expected $testroot/stdout
920 fi
921 test_done "$testroot" "$ret"
924 test_update_conflict_wt_edit_vs_repo_rm() {
925 local testroot=`test_init update_conflict_wt_edit_vs_repo_rm`
927 got checkout $testroot/repo $testroot/wt > /dev/null
928 ret="$?"
929 if [ "$ret" != "0" ]; then
930 test_done "$testroot" "$ret"
931 return 1
932 fi
934 (cd $testroot/repo && git rm -q beta)
935 git_commit $testroot/repo -m "removing a file"
937 echo "modified beta" > $testroot/wt/beta
939 (cd $testroot/wt && got update > $testroot/stdout)
941 echo "G beta" > $testroot/stdout.expected
942 echo -n "Updated to commit " >> $testroot/stdout.expected
943 git_show_head $testroot/repo >> $testroot/stdout.expected
944 echo >> $testroot/stdout.expected
945 cmp -s $testroot/stdout.expected $testroot/stdout
946 ret="$?"
947 if [ "$ret" != "0" ]; then
948 diff -u $testroot/stdout.expected $testroot/stdout
949 test_done "$testroot" "$ret"
950 return 1
951 fi
953 echo "modified beta" > $testroot/content.expected
955 cat $testroot/wt/beta > $testroot/content
957 cmp -s $testroot/content.expected $testroot/content
958 ret="$?"
959 if [ "$ret" != "0" ]; then
960 diff -u $testroot/content.expected $testroot/content
961 test_done "$testroot" "$ret"
962 return 1
963 fi
965 # beta is now an added file... we don't flag tree conflicts yet
966 echo 'A beta' > $testroot/stdout.expected
967 (cd $testroot/wt && got status > $testroot/stdout)
968 cmp -s $testroot/stdout.expected $testroot/stdout
969 ret="$?"
970 if [ "$ret" != "0" ]; then
971 diff -u $testroot/stdout.expected $testroot/stdout
972 fi
973 test_done "$testroot" "$ret"
976 test_update_conflict_wt_rm_vs_repo_edit() {
977 local testroot=`test_init update_conflict_wt_rm_vs_repo_edit`
979 got checkout $testroot/repo $testroot/wt > /dev/null
980 ret="$?"
981 if [ "$ret" != "0" ]; then
982 test_done "$testroot" "$ret"
983 return 1
984 fi
986 echo "modified beta" > $testroot/repo/beta
987 git_commit $testroot/repo -m "modified a file"
989 (cd $testroot/wt && got rm beta > /dev/null)
991 (cd $testroot/wt && got update > $testroot/stdout)
993 echo "G beta" > $testroot/stdout.expected
994 echo -n "Updated to commit " >> $testroot/stdout.expected
995 git_show_head $testroot/repo >> $testroot/stdout.expected
996 echo >> $testroot/stdout.expected
997 cmp -s $testroot/stdout.expected $testroot/stdout
998 ret="$?"
999 if [ "$ret" != "0" ]; then
1000 diff -u $testroot/stdout.expected $testroot/stdout
1001 test_done "$testroot" "$ret"
1002 return 1
1005 # beta remains a deleted file... we don't flag tree conflicts yet
1006 echo 'D beta' > $testroot/stdout.expected
1007 (cd $testroot/wt && got status > $testroot/stdout)
1008 cmp -s $testroot/stdout.expected $testroot/stdout
1009 ret="$?"
1010 if [ "$ret" != "0" ]; then
1011 diff -u $testroot/stdout.expected $testroot/stdout
1012 test_done "$testroot" "$ret"
1013 return 1
1016 # 'got diff' should show post-update contents of beta being deleted
1017 local head_rev=`git_show_head $testroot/repo`
1018 echo "diff $head_rev $testroot/wt" > $testroot/stdout.expected
1019 echo -n 'blob - ' >> $testroot/stdout.expected
1020 got tree -r $testroot/repo -i | grep 'beta$' | cut -d' ' -f 1 \
1021 >> $testroot/stdout.expected
1022 echo 'file + /dev/null' >> $testroot/stdout.expected
1023 echo '--- beta' >> $testroot/stdout.expected
1024 echo '+++ /dev/null' >> $testroot/stdout.expected
1025 echo '@@ -1 +0,0 @@' >> $testroot/stdout.expected
1026 echo '-modified beta' >> $testroot/stdout.expected
1028 (cd $testroot/wt && got diff > $testroot/stdout)
1029 cmp -s $testroot/stdout.expected $testroot/stdout
1030 ret="$?"
1031 if [ "$ret" != "0" ]; then
1032 diff -u $testroot/stdout.expected $testroot/stdout
1034 test_done "$testroot" "$ret"
1037 test_update_conflict_wt_rm_vs_repo_rm() {
1038 local testroot=`test_init update_conflict_wt_rm_vs_repo_rm`
1040 got checkout $testroot/repo $testroot/wt > /dev/null
1041 ret="$?"
1042 if [ "$ret" != "0" ]; then
1043 test_done "$testroot" "$ret"
1044 return 1
1047 (cd $testroot/repo && git rm -q beta)
1048 git_commit $testroot/repo -m "removing a file"
1050 (cd $testroot/wt && got rm beta > /dev/null)
1052 (cd $testroot/wt && got update > $testroot/stdout)
1054 echo "D beta" > $testroot/stdout.expected
1055 echo -n "Updated to commit " >> $testroot/stdout.expected
1056 git_show_head $testroot/repo >> $testroot/stdout.expected
1057 echo >> $testroot/stdout.expected
1058 cmp -s $testroot/stdout.expected $testroot/stdout
1059 ret="$?"
1060 if [ "$ret" != "0" ]; then
1061 diff -u $testroot/stdout.expected $testroot/stdout
1062 test_done "$testroot" "$ret"
1063 return 1
1066 # beta is now gone... we don't flag tree conflicts yet
1067 echo "N beta" > $testroot/stdout.expected
1068 echo -n > $testroot/stderr.expected
1069 (cd $testroot/wt && got status beta > $testroot/stdout \
1070 2> $testroot/stderr)
1071 cmp -s $testroot/stdout.expected $testroot/stdout
1072 ret="$?"
1073 if [ "$ret" != "0" ]; then
1074 diff -u $testroot/stdout.expected $testroot/stdout
1075 test_done "$testroot" "$ret"
1076 return 1
1078 cmp -s $testroot/stderr.expected $testroot/stderr
1079 ret="$?"
1080 if [ "$ret" != "0" ]; then
1081 diff -u $testroot/stderr.expected $testroot/stderr
1082 test_done "$testroot" "$ret"
1083 return 1
1086 if [ -e $testroot/wt/beta ]; then
1087 echo "removed file beta still exists on disk" >&2
1088 test_done "$testroot" "1"
1089 return 1
1092 test_done "$testroot" "0"
1095 test_update_partial() {
1096 local testroot=`test_init update_partial`
1098 got checkout $testroot/repo $testroot/wt > /dev/null
1099 ret="$?"
1100 if [ "$ret" != "0" ]; then
1101 test_done "$testroot" "$ret"
1102 return 1
1105 echo "modified alpha" > $testroot/repo/alpha
1106 echo "modified beta" > $testroot/repo/beta
1107 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1108 git_commit $testroot/repo -m "modified two files"
1110 echo "U alpha" > $testroot/stdout.expected
1111 echo "U beta" >> $testroot/stdout.expected
1112 echo -n "Updated to commit " >> $testroot/stdout.expected
1113 git_show_head $testroot/repo >> $testroot/stdout.expected
1114 echo >> $testroot/stdout.expected
1116 (cd $testroot/wt && got update alpha beta > $testroot/stdout)
1118 cmp -s $testroot/stdout.expected $testroot/stdout
1119 ret="$?"
1120 if [ "$ret" != "0" ]; then
1121 diff -u $testroot/stdout.expected $testroot/stdout
1122 test_done "$testroot" "$ret"
1123 return 1
1126 echo "modified alpha" > $testroot/content.expected
1127 echo "modified beta" >> $testroot/content.expected
1129 cat $testroot/wt/alpha $testroot/wt/beta > $testroot/content
1130 cmp -s $testroot/content.expected $testroot/content
1131 ret="$?"
1132 if [ "$ret" != "0" ]; then
1133 diff -u $testroot/content.expected $testroot/content
1134 test_done "$testroot" "$ret"
1135 return 1
1138 echo "U epsilon/zeta" > $testroot/stdout.expected
1139 echo -n "Updated to commit " >> $testroot/stdout.expected
1140 git_show_head $testroot/repo >> $testroot/stdout.expected
1141 echo >> $testroot/stdout.expected
1143 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1145 cmp -s $testroot/stdout.expected $testroot/stdout
1146 ret="$?"
1147 if [ "$ret" != "0" ]; then
1148 diff -u $testroot/stdout.expected $testroot/stdout
1149 test_done "$testroot" "$ret"
1150 return 1
1153 echo "modified epsilon/zeta" > $testroot/content.expected
1154 cat $testroot/wt/epsilon/zeta > $testroot/content
1156 cmp -s $testroot/content.expected $testroot/content
1157 ret="$?"
1158 if [ "$ret" != "0" ]; then
1159 diff -u $testroot/content.expected $testroot/content
1160 test_done "$testroot" "$ret"
1161 return 1
1164 test_done "$testroot" "$ret"
1167 test_update_partial_add() {
1168 local testroot=`test_init update_partial_add`
1170 got checkout $testroot/repo $testroot/wt > /dev/null
1171 ret="$?"
1172 if [ "$ret" != "0" ]; then
1173 test_done "$testroot" "$ret"
1174 return 1
1177 echo "new" > $testroot/repo/new
1178 echo "epsilon/new2" > $testroot/repo/epsilon/new2
1179 (cd $testroot/repo && git add .)
1180 git_commit $testroot/repo -m "added two files"
1182 echo "A new" > $testroot/stdout.expected
1183 echo "A epsilon/new2" >> $testroot/stdout.expected
1184 echo -n "Updated to commit " >> $testroot/stdout.expected
1185 git_show_head $testroot/repo >> $testroot/stdout.expected
1186 echo >> $testroot/stdout.expected
1188 (cd $testroot/wt && got update new epsilon/new2 > $testroot/stdout)
1190 cmp -s $testroot/stdout.expected $testroot/stdout
1191 ret="$?"
1192 if [ "$ret" != "0" ]; then
1193 diff -u $testroot/stdout.expected $testroot/stdout
1194 test_done "$testroot" "$ret"
1195 return 1
1198 echo "new" > $testroot/content.expected
1199 echo "epsilon/new2" >> $testroot/content.expected
1201 cat $testroot/wt/new $testroot/wt/epsilon/new2 > $testroot/content
1203 cmp -s $testroot/content.expected $testroot/content
1204 ret="$?"
1205 if [ "$ret" != "0" ]; then
1206 diff -u $testroot/content.expected $testroot/content
1208 test_done "$testroot" "$ret"
1211 test_update_partial_rm() {
1212 local testroot=`test_init update_partial_rm`
1214 got checkout $testroot/repo $testroot/wt > /dev/null
1215 ret="$?"
1216 if [ "$ret" != "0" ]; then
1217 test_done "$testroot" "$ret"
1218 return 1
1221 (cd $testroot/repo && git rm -q alpha epsilon/zeta)
1222 git_commit $testroot/repo -m "removed two files"
1224 echo "got: /alpha: no such entry found in tree" \
1225 > $testroot/stderr.expected
1227 (cd $testroot/wt && got update alpha epsilon/zeta 2> $testroot/stderr)
1228 ret="$?"
1229 if [ "$ret" = "0" ]; then
1230 echo "update succeeded unexpectedly" >&2
1231 test_done "$testroot" "1"
1232 return 1
1235 cmp -s $testroot/stderr.expected $testroot/stderr
1236 ret="$?"
1237 if [ "$ret" != "0" ]; then
1238 diff -u $testroot/stderr.expected $testroot/stderr
1239 test_done "$testroot" "$ret"
1240 return 1
1242 test_done "$testroot" "$ret"
1245 test_update_partial_dir() {
1246 local testroot=`test_init update_partial_dir`
1248 got checkout $testroot/repo $testroot/wt > /dev/null
1249 ret="$?"
1250 if [ "$ret" != "0" ]; then
1251 test_done "$testroot" "$ret"
1252 return 1
1255 echo "modified alpha" > $testroot/repo/alpha
1256 echo "modified beta" > $testroot/repo/beta
1257 echo "modified epsilon/zeta" > $testroot/repo/epsilon/zeta
1258 git_commit $testroot/repo -m "modified two files"
1260 echo "U epsilon/zeta" > $testroot/stdout.expected
1261 echo -n "Updated to commit " >> $testroot/stdout.expected
1262 git_show_head $testroot/repo >> $testroot/stdout.expected
1263 echo >> $testroot/stdout.expected
1265 (cd $testroot/wt && got update epsilon > $testroot/stdout)
1267 cmp -s $testroot/stdout.expected $testroot/stdout
1268 ret="$?"
1269 if [ "$ret" != "0" ]; then
1270 diff -u $testroot/stdout.expected $testroot/stdout
1271 test_done "$testroot" "$ret"
1272 return 1
1275 echo "modified epsilon/zeta" > $testroot/content.expected
1276 cat $testroot/wt/epsilon/zeta > $testroot/content
1278 cmp -s $testroot/content.expected $testroot/content
1279 ret="$?"
1280 if [ "$ret" != "0" ]; then
1281 diff -u $testroot/content.expected $testroot/content
1282 test_done "$testroot" "$ret"
1283 return 1
1285 test_done "$testroot" "$ret"
1289 test_update_moved_branch_ref() {
1290 local testroot=`test_init update_moved_branch_ref`
1292 git clone -q --mirror $testroot/repo $testroot/repo2
1294 echo "modified alpha with git" > $testroot/repo/alpha
1295 git_commit $testroot/repo -m "modified alpha with git"
1297 got checkout $testroot/repo2 $testroot/wt > /dev/null
1298 ret="$?"
1299 if [ "$ret" != "0" ]; then
1300 test_done "$testroot" "$ret"
1301 return 1
1304 echo "modified alpha with got" > $testroot/wt/alpha
1305 (cd $testroot/wt && got commit -m "modified alpha with got" > /dev/null)
1307 # + xxxxxxx...yyyyyyy master -> master (forced update)
1308 (cd $testroot/repo2 && git fetch -q --all)
1310 echo -n > $testroot/stdout.expected
1311 echo -n "got: work tree's head reference now points to a different " \
1312 > $testroot/stderr.expected
1313 echo "branch; new head reference and/or update -b required" \
1314 >> $testroot/stderr.expected
1316 (cd $testroot/wt && got update > $testroot/stdout 2> $testroot/stderr)
1318 cmp -s $testroot/stdout.expected $testroot/stdout
1319 ret="$?"
1320 if [ "$ret" != "0" ]; then
1321 diff -u $testroot/stdout.expected $testroot/stdout
1322 test_done "$testroot" "$ret"
1323 return 1
1326 cmp -s $testroot/stderr.expected $testroot/stderr
1327 ret="$?"
1328 if [ "$ret" != "0" ]; then
1329 diff -u $testroot/stderr.expected $testroot/stderr
1331 test_done "$testroot" "$ret"
1334 test_update_to_another_branch() {
1335 local testroot=`test_init update_to_another_branch`
1336 local base_commit=`git_show_head $testroot/repo`
1338 got checkout $testroot/repo $testroot/wt > /dev/null
1339 ret="$?"
1340 if [ "$ret" != "0" ]; then
1341 test_done "$testroot" "$ret"
1342 return 1
1345 echo 'refs/heads/master'> $testroot/head-ref.expected
1346 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1347 ret="$?"
1348 if [ "$ret" != "0" ]; then
1349 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1350 test_done "$testroot" "$ret"
1351 return 1
1354 (cd $testroot/repo && git checkout -q -b newbranch)
1355 echo "modified alpha on new branch" > $testroot/repo/alpha
1356 git_commit $testroot/repo -m "modified alpha on new branch"
1358 echo "modified alpha in work tree" > $testroot/wt/alpha
1360 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" > $testroot/stdout.expected
1361 echo "C alpha" >> $testroot/stdout.expected
1362 echo -n "Updated to commit " >> $testroot/stdout.expected
1363 git_show_head $testroot/repo >> $testroot/stdout.expected
1364 echo >> $testroot/stdout.expected
1365 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1367 (cd $testroot/wt && got update -b newbranch > $testroot/stdout)
1369 cmp -s $testroot/stdout.expected $testroot/stdout
1370 ret="$?"
1371 if [ "$ret" != "0" ]; then
1372 diff -u $testroot/stdout.expected $testroot/stdout
1373 test_done "$testroot" "$ret"
1374 return 1
1377 echo -n "<<<<<<< merged change: commit " > $testroot/content.expected
1378 git_show_head $testroot/repo >> $testroot/content.expected
1379 echo >> $testroot/content.expected
1380 echo "modified alpha on new branch" >> $testroot/content.expected
1381 echo "||||||| 3-way merge base: commit $base_commit" \
1382 >> $testroot/content.expected
1383 echo "alpha" >> $testroot/content.expected
1384 echo "=======" >> $testroot/content.expected
1385 echo "modified alpha in work tree" >> $testroot/content.expected
1386 echo '>>>>>>>' >> $testroot/content.expected
1388 cat $testroot/wt/alpha > $testroot/content
1390 cmp -s $testroot/content.expected $testroot/content
1391 ret="$?"
1392 if [ "$ret" != "0" ]; then
1393 diff -u $testroot/content.expected $testroot/content
1394 test_done "$testroot" "$ret"
1395 return 1
1398 echo 'refs/heads/newbranch'> $testroot/head-ref.expected
1399 cmp -s $testroot/head-ref.expected $testroot/wt/.got/head-ref
1400 ret="$?"
1401 if [ "$ret" != "0" ]; then
1402 diff -u $testroot/head-ref.expected $testroot/wt/.got/head-ref
1403 test_done "$testroot" "$ret"
1404 return 1
1407 test_done "$testroot" "$ret"
1410 test_update_to_commit_on_wrong_branch() {
1411 local testroot=`test_init update_to_commit_on_wrong_branch`
1413 got checkout $testroot/repo $testroot/wt > /dev/null
1414 ret="$?"
1415 if [ "$ret" != "0" ]; then
1416 test_done "$testroot" "$ret"
1417 return 1
1420 (cd $testroot/repo && git checkout -q -b newbranch)
1421 echo "modified alpha on new branch" > $testroot/repo/alpha
1422 git_commit $testroot/repo -m "modified alpha on new branch"
1424 echo -n "" > $testroot/stdout.expected
1425 echo "got: target commit is on a different branch" \
1426 > $testroot/stderr.expected
1428 local head_rev=`git_show_head $testroot/repo`
1429 (cd $testroot/wt && got update -c $head_rev > $testroot/stdout \
1430 2> $testroot/stderr)
1432 cmp -s $testroot/stdout.expected $testroot/stdout
1433 ret="$?"
1434 if [ "$ret" != "0" ]; then
1435 diff -u $testroot/stdout.expected $testroot/stdout
1436 test_done "$testroot" "$ret"
1437 return 1
1440 cmp -s $testroot/stderr.expected $testroot/stderr
1441 ret="$?"
1442 if [ "$ret" != "0" ]; then
1443 diff -u $testroot/stderr.expected $testroot/stderr
1444 test_done "$testroot" "$ret"
1445 return 1
1448 test_done "$testroot" "$ret"
1451 test_update_bumps_base_commit_id() {
1452 local testroot=`test_init update_bumps_base_commit_id`
1454 echo "psi" > $testroot/repo/epsilon/psi
1455 (cd $testroot/repo && git add .)
1456 git_commit $testroot/repo -m "adding another file"
1458 got checkout $testroot/repo $testroot/wt > /dev/null
1459 ret="$?"
1460 if [ "$ret" != "0" ]; then
1461 test_done "$testroot" "$ret"
1462 return 1
1465 echo "modified psi" > $testroot/wt/epsilon/psi
1466 (cd $testroot/wt && got commit -m "changed psi" > $testroot/stdout)
1468 local head_rev=`git_show_head $testroot/repo`
1469 echo "M epsilon/psi" > $testroot/stdout.expected
1470 echo "Created commit $head_rev" >> $testroot/stdout.expected
1471 cmp -s $testroot/stdout.expected $testroot/stdout
1472 ret="$?"
1473 if [ "$ret" != "0" ]; then
1474 diff -u $testroot/stdout.expected $testroot/stdout
1475 test_done "$testroot" "$ret"
1476 return 1
1479 echo "changed zeta with git" > $testroot/repo/epsilon/zeta
1480 (cd $testroot/repo && git add .)
1481 git_commit $testroot/repo -m "changing zeta with git"
1483 echo "modified zeta" > $testroot/wt/epsilon/zeta
1484 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout \
1485 2> $testroot/stderr)
1487 echo -n "" > $testroot/stdout.expected
1488 echo "got: work tree must be updated before these changes can be committed" > $testroot/stderr.expected
1489 cmp -s $testroot/stderr.expected $testroot/stderr
1490 ret="$?"
1491 if [ "$ret" != "0" ]; then
1492 diff -u $testroot/stderr.expected $testroot/stderr
1493 test_done "$testroot" "$ret"
1494 return 1
1497 (cd $testroot/wt && got update > $testroot/stdout)
1499 echo "U epsilon/psi" > $testroot/stdout.expected
1500 echo "C epsilon/zeta" >> $testroot/stdout.expected
1501 echo -n "Updated to commit " >> $testroot/stdout.expected
1502 git_show_head $testroot/repo >> $testroot/stdout.expected
1503 echo >> $testroot/stdout.expected
1504 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
1506 cmp -s $testroot/stdout.expected $testroot/stdout
1507 ret="$?"
1508 if [ "$ret" != "0" ]; then
1509 diff -u $testroot/stdout.expected $testroot/stdout
1510 test_done "$testroot" "$ret"
1511 return 1
1514 # resolve conflict
1515 echo "modified zeta with got and git" > $testroot/wt/epsilon/zeta
1517 (cd $testroot/wt && got commit -m "changed zeta" > $testroot/stdout)
1519 local head_rev=`git_show_head $testroot/repo`
1520 echo "M epsilon/zeta" > $testroot/stdout.expected
1521 echo "Created commit $head_rev" >> $testroot/stdout.expected
1522 cmp -s $testroot/stdout.expected $testroot/stdout
1523 ret="$?"
1524 if [ "$ret" != "0" ]; then
1525 diff -u $testroot/stdout.expected $testroot/stdout
1526 test_done "$testroot" "$ret"
1527 return 1
1530 test_done "$testroot" "$ret"
1533 test_update_tag() {
1534 local testroot=`test_init update_tag`
1535 local tag="1.0.0"
1537 got checkout $testroot/repo $testroot/wt > /dev/null
1538 ret="$?"
1539 if [ "$ret" != "0" ]; then
1540 test_done "$testroot" "$ret"
1541 return 1
1544 echo "modified alpha" > $testroot/repo/alpha
1545 git_commit $testroot/repo -m "modified alpha"
1546 (cd $testroot/repo && git tag -m "test" -a $tag)
1548 echo "U alpha" > $testroot/stdout.expected
1549 echo -n "Updated to commit " >> $testroot/stdout.expected
1550 git_show_head $testroot/repo >> $testroot/stdout.expected
1551 echo >> $testroot/stdout.expected
1553 (cd $testroot/wt && got update -c $tag > $testroot/stdout)
1555 cmp -s $testroot/stdout.expected $testroot/stdout
1556 ret="$?"
1557 if [ "$ret" != "0" ]; then
1558 diff -u $testroot/stdout.expected $testroot/stdout
1559 test_done "$testroot" "$ret"
1560 return 1
1563 echo "modified alpha" > $testroot/content.expected
1564 cat $testroot/wt/alpha > $testroot/content
1566 cmp -s $testroot/content.expected $testroot/content
1567 ret="$?"
1568 if [ "$ret" != "0" ]; then
1569 diff -u $testroot/content.expected $testroot/content
1571 test_done "$testroot" "$ret"
1574 test_update_toggles_xbit() {
1575 local testroot=`test_init update_toggles_xbit 1`
1577 touch $testroot/repo/xfile
1578 chmod +x $testroot/repo/xfile
1579 (cd $testroot/repo && git add .)
1580 git_commit $testroot/repo -m "adding executable file"
1581 local commit_id1=`git_show_head $testroot/repo`
1583 got checkout $testroot/repo $testroot/wt > $testroot/stdout
1584 ret="$?"
1585 if [ "$ret" != "0" ]; then
1586 test_done "$testroot" "$ret"
1587 return 1
1590 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1591 ret="$?"
1592 if [ "$ret" != "0" ]; then
1593 echo "file is not executable" >&2
1594 ls -l $testroot/wt/xfile >&2
1595 test_done "$testroot" "$ret"
1596 return 1
1599 chmod -x $testroot/wt/xfile
1600 (cd $testroot/wt && got commit -m "clear x bit" >/dev/null)
1601 local commit_id2=`git_show_head $testroot/repo`
1603 echo "U xfile" > $testroot/stdout.expected
1604 echo -n "Updated to commit " >> $testroot/stdout.expected
1605 git_show_head $testroot/repo >> $testroot/stdout.expected
1606 echo >> $testroot/stdout.expected
1608 (cd $testroot/wt && got update -c $commit_id1 > $testroot/stdout)
1609 ret="$?"
1610 if [ "$ret" != "0" ]; then
1611 test_done "$testroot" "$ret"
1612 return 1
1615 echo "U xfile" > $testroot/stdout.expected
1616 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
1617 cmp -s $testroot/stdout.expected $testroot/stdout
1618 ret="$?"
1619 if [ "$ret" != "0" ]; then
1620 diff -u $testroot/stdout.expected $testroot/stdout
1621 test_done "$testroot" "$ret"
1622 return 1
1626 ls -l $testroot/wt/xfile | grep -q '^-rwx'
1627 ret="$?"
1628 if [ "$ret" != "0" ]; then
1629 echo "file is not executable" >&2
1630 ls -l $testroot/wt/xfile >&2
1631 test_done "$testroot" "$ret"
1632 return 1
1635 (cd $testroot/wt && got update > $testroot/stdout)
1636 ret="$?"
1637 if [ "$ret" != "0" ]; then
1638 test_done "$testroot" "$ret"
1639 return 1
1642 echo "U xfile" > $testroot/stdout.expected
1643 echo "Updated to commit $commit_id2" >> $testroot/stdout.expected
1644 cmp -s $testroot/stdout.expected $testroot/stdout
1645 ret="$?"
1646 if [ "$ret" != "0" ]; then
1647 diff -u $testroot/stdout.expected $testroot/stdout
1648 test_done "$testroot" "$ret"
1649 return 1
1652 ls -l $testroot/wt/xfile | grep -q '^-rw-'
1653 ret="$?"
1654 if [ "$ret" != "0" ]; then
1655 echo "file is unexpectedly executable" >&2
1656 ls -l $testroot/wt/xfile >&2
1658 test_done "$testroot" "$ret"
1661 test_update_preserves_conflicted_file() {
1662 local testroot=`test_init update_preserves_conflicted_file`
1663 local commit_id0=`git_show_head $testroot/repo`
1665 echo "modified alpha" > $testroot/repo/alpha
1666 git_commit $testroot/repo -m "modified alpha"
1667 local commit_id1=`git_show_head $testroot/repo`
1669 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
1670 ret="$?"
1671 if [ "$ret" != "0" ]; then
1672 test_done "$testroot" "$ret"
1673 return 1
1676 # fake a merge conflict
1677 echo '<<<<<<<' > $testroot/wt/alpha
1678 echo 'alpha' >> $testroot/wt/alpha
1679 echo '=======' >> $testroot/wt/alpha
1680 echo 'alpha, too' >> $testroot/wt/alpha
1681 echo '>>>>>>>' >> $testroot/wt/alpha
1682 cp $testroot/wt/alpha $testroot/content.expected
1684 echo "C alpha" > $testroot/stdout.expected
1685 (cd $testroot/wt && got status > $testroot/stdout)
1686 cmp -s $testroot/stdout.expected $testroot/stdout
1687 ret="$?"
1688 if [ "$ret" != "0" ]; then
1689 diff -u $testroot/stdout.expected $testroot/stdout
1690 test_done "$testroot" "$ret"
1691 return 1
1694 echo "# alpha" > $testroot/stdout.expected
1695 echo -n "Updated to commit " >> $testroot/stdout.expected
1696 git_show_head $testroot/repo >> $testroot/stdout.expected
1697 echo >> $testroot/stdout.expected
1698 echo "Files not updated because of existing merge conflicts: 1" \
1699 >> $testroot/stdout.expected
1700 (cd $testroot/wt && got update > $testroot/stdout)
1702 cmp -s $testroot/stdout.expected $testroot/stdout
1703 ret="$?"
1704 if [ "$ret" != "0" ]; then
1705 diff -u $testroot/stdout.expected $testroot/stdout
1706 test_done "$testroot" "$ret"
1707 return 1
1710 cmp -s $testroot/content.expected $testroot/wt/alpha
1711 ret="$?"
1712 if [ "$ret" != "0" ]; then
1713 diff -u $testroot/content.expected $testroot/wt/alpha
1715 test_done "$testroot" "$ret"
1718 test_update_modified_submodules() {
1719 local testroot=`test_init update_modified_submodules`
1721 make_single_file_repo $testroot/repo2 foo
1723 (cd $testroot/repo && git submodule -q add ../repo2)
1724 (cd $testroot/repo && git commit -q -m 'adding submodule')
1726 got checkout $testroot/repo $testroot/wt > /dev/null
1728 echo "modified foo" > $testroot/repo2/foo
1729 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1731 # Update the repo/repo2 submodule link
1732 (cd $testroot/repo && git -C repo2 pull -q)
1733 (cd $testroot/repo && git add repo2)
1734 git_commit $testroot/repo -m "modified submodule link"
1736 # This update only records the new base commit. Otherwise it is a
1737 # no-op change because Got's file index does not track submodules.
1738 echo -n "Updated to commit " > $testroot/stdout.expected
1739 git_show_head $testroot/repo >> $testroot/stdout.expected
1740 echo >> $testroot/stdout.expected
1742 (cd $testroot/wt && got update > $testroot/stdout)
1744 cmp -s $testroot/stdout.expected $testroot/stdout
1745 ret="$?"
1746 if [ "$ret" != "0" ]; then
1747 diff -u $testroot/stdout.expected $testroot/stdout
1749 test_done "$testroot" "$ret"
1752 test_update_adds_submodule() {
1753 local testroot=`test_init update_adds_submodule`
1755 got checkout $testroot/repo $testroot/wt > /dev/null
1757 make_single_file_repo $testroot/repo2 foo
1759 echo "modified foo" > $testroot/repo2/foo
1760 (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule')
1762 (cd $testroot/repo && git submodule -q add ../repo2)
1763 (cd $testroot/repo && git commit -q -m 'adding submodule')
1765 echo "A .gitmodules" > $testroot/stdout.expected
1766 echo -n "Updated to commit " >> $testroot/stdout.expected
1767 git_show_head $testroot/repo >> $testroot/stdout.expected
1768 echo >> $testroot/stdout.expected
1770 (cd $testroot/wt && got update > $testroot/stdout)
1772 cmp -s $testroot/stdout.expected $testroot/stdout
1773 ret="$?"
1774 if [ "$ret" != "0" ]; then
1775 diff -u $testroot/stdout.expected $testroot/stdout
1777 test_done "$testroot" "$ret"
1780 test_update_conflict_wt_file_vs_repo_submodule() {
1781 local testroot=`test_init update_conflict_wt_file_vs_repo_submodule`
1783 got checkout $testroot/repo $testroot/wt > /dev/null
1785 make_single_file_repo $testroot/repo2 foo
1787 # Add a file which will clash with the submodule
1788 echo "This is a file called repo2" > $testroot/wt/repo2
1789 (cd $testroot/wt && got add repo2 > /dev/null)
1790 (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null)
1791 ret="$?"
1792 if [ "$ret" != "0" ]; then
1793 echo "commit failed unexpectedly" >&2
1794 test_done "$testroot" "1"
1795 return 1
1798 (cd $testroot/repo && git submodule -q add ../repo2)
1799 (cd $testroot/repo && git commit -q -m 'adding submodule')
1801 # Modify the clashing file such that any modifications brought
1802 # in by 'got update' would require a merge.
1803 echo "This file was changed" > $testroot/wt/repo2
1805 # No conflict occurs because 'got update' ignores the submodule
1806 # and leaves the clashing file as it was.
1807 echo "A .gitmodules" > $testroot/stdout.expected
1808 echo -n "Updated to commit " >> $testroot/stdout.expected
1809 git_show_head $testroot/repo >> $testroot/stdout.expected
1810 echo >> $testroot/stdout.expected
1812 (cd $testroot/wt && got update > $testroot/stdout)
1814 cmp -s $testroot/stdout.expected $testroot/stdout
1815 ret="$?"
1816 if [ "$ret" != "0" ]; then
1817 diff -u $testroot/stdout.expected $testroot/stdout
1818 test_done "$testroot" "$ret"
1819 return 1
1822 (cd $testroot/wt && got status > $testroot/stdout)
1824 echo "M repo2" > $testroot/stdout.expected
1825 cmp -s $testroot/stdout.expected $testroot/stdout
1826 ret="$?"
1827 if [ "$ret" != "0" ]; then
1828 diff -u $testroot/stdout.expected $testroot/stdout
1830 test_done "$testroot" "$ret"
1833 test_update_adds_symlink() {
1834 local testroot=`test_init update_adds_symlink`
1836 got checkout $testroot/repo $testroot/wt > /dev/null
1837 ret="$?"
1838 if [ "$ret" != "0" ]; then
1839 echo "checkout failed unexpectedly" >&2
1840 test_done "$testroot" "$ret"
1841 return 1
1844 (cd $testroot/repo && ln -s alpha alpha.link)
1845 (cd $testroot/repo && ln -s epsilon epsilon.link)
1846 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
1847 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
1848 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
1849 (cd $testroot/repo && git add .)
1850 git_commit $testroot/repo -m "add symlinks"
1852 echo "A alpha.link" > $testroot/stdout.expected
1853 echo "A epsilon/beta.link" >> $testroot/stdout.expected
1854 echo "A epsilon.link" >> $testroot/stdout.expected
1855 echo "A nonexistent.link" >> $testroot/stdout.expected
1856 echo "A passwd.link" >> $testroot/stdout.expected
1857 echo -n "Updated to commit " >> $testroot/stdout.expected
1858 git_show_head $testroot/repo >> $testroot/stdout.expected
1859 echo >> $testroot/stdout.expected
1861 (cd $testroot/wt && got update > $testroot/stdout)
1863 cmp -s $testroot/stdout.expected $testroot/stdout
1864 ret="$?"
1865 if [ "$ret" != "0" ]; then
1866 diff -u $testroot/stdout.expected $testroot/stdout
1867 test_done "$testroot" "$ret"
1868 return 1
1871 if ! [ -h $testroot/wt/alpha.link ]; then
1872 echo "alpha.link is not a symlink"
1873 test_done "$testroot" "1"
1874 return 1
1877 readlink $testroot/wt/alpha.link > $testroot/stdout
1878 echo "alpha" > $testroot/stdout.expected
1879 cmp -s $testroot/stdout.expected $testroot/stdout
1880 ret="$?"
1881 if [ "$ret" != "0" ]; then
1882 diff -u $testroot/stdout.expected $testroot/stdout
1883 test_done "$testroot" "$ret"
1884 return 1
1887 if ! [ -h $testroot/wt/epsilon.link ]; then
1888 echo "epsilon.link is not a symlink"
1889 test_done "$testroot" "1"
1890 return 1
1893 readlink $testroot/wt/epsilon.link > $testroot/stdout
1894 echo "epsilon" > $testroot/stdout.expected
1895 cmp -s $testroot/stdout.expected $testroot/stdout
1896 ret="$?"
1897 if [ "$ret" != "0" ]; then
1898 diff -u $testroot/stdout.expected $testroot/stdout
1899 test_done "$testroot" "$ret"
1900 return 1
1903 if [ -h $testroot/wt/passwd.link ]; then
1904 echo -n "passwd.link symlink points outside of work tree: " >&2
1905 readlink $testroot/wt/passwd.link >&2
1906 test_done "$testroot" "1"
1907 return 1
1910 echo -n "/etc/passwd" > $testroot/content.expected
1911 cp $testroot/wt/passwd.link $testroot/content
1913 cmp -s $testroot/content.expected $testroot/content
1914 ret="$?"
1915 if [ "$ret" != "0" ]; then
1916 diff -u $testroot/content.expected $testroot/content
1917 test_done "$testroot" "$ret"
1918 return 1
1921 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
1922 echo "../beta" > $testroot/stdout.expected
1923 cmp -s $testroot/stdout.expected $testroot/stdout
1924 ret="$?"
1925 if [ "$ret" != "0" ]; then
1926 diff -u $testroot/stdout.expected $testroot/stdout
1927 test_done "$testroot" "$ret"
1928 return 1
1931 readlink $testroot/wt/nonexistent.link > $testroot/stdout
1932 echo "nonexistent" > $testroot/stdout.expected
1933 cmp -s $testroot/stdout.expected $testroot/stdout
1934 ret="$?"
1935 if [ "$ret" != "0" ]; then
1936 diff -u $testroot/stdout.expected $testroot/stdout
1937 test_done "$testroot" "$ret"
1938 return 1
1941 # Updating an up-to-date symlink should be a no-op.
1942 echo 'Already up-to-date' > $testroot/stdout.expected
1943 (cd $testroot/wt && got update > $testroot/stdout)
1944 cmp -s $testroot/stdout.expected $testroot/stdout
1945 ret="$?"
1946 if [ "$ret" != "0" ]; then
1947 diff -u $testroot/stdout.expected $testroot/stdout
1949 test_done "$testroot" "$ret"
1952 test_update_deletes_symlink() {
1953 local testroot=`test_init update_deletes_symlink`
1955 (cd $testroot/repo && ln -s alpha alpha.link)
1956 (cd $testroot/repo && git add .)
1957 git_commit $testroot/repo -m "add symlink"
1959 got checkout $testroot/repo $testroot/wt > /dev/null
1960 ret="$?"
1961 if [ "$ret" != "0" ]; then
1962 echo "checkout failed unexpectedly" >&2
1963 test_done "$testroot" "$ret"
1964 return 1
1967 (cd $testroot/repo && git rm -q alpha.link)
1968 git_commit $testroot/repo -m "delete symlink"
1970 echo "D alpha.link" > $testroot/stdout.expected
1971 echo -n "Updated to commit " >> $testroot/stdout.expected
1972 git_show_head $testroot/repo >> $testroot/stdout.expected
1973 echo >> $testroot/stdout.expected
1975 (cd $testroot/wt && got update > $testroot/stdout)
1977 cmp -s $testroot/stdout.expected $testroot/stdout
1978 ret="$?"
1979 if [ "$ret" != "0" ]; then
1980 diff -u $testroot/stdout.expected $testroot/stdout
1981 test_done "$testroot" "$ret"
1982 return 1
1985 if [ -e $testroot/wt/alpha.link ]; then
1986 echo "alpha.link still exists on disk"
1987 test_done "$testroot" "1"
1988 return 1
1991 test_done "$testroot" "0"
1994 test_update_symlink_conflicts() {
1995 local testroot=`test_init update_symlink_conflicts`
1997 (cd $testroot/repo && ln -s alpha alpha.link)
1998 (cd $testroot/repo && ln -s epsilon epsilon.link)
1999 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
2000 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
2001 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
2002 (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
2003 (cd $testroot/repo && git add .)
2004 git_commit $testroot/repo -m "add symlinks"
2005 local commit_id1=`git_show_head $testroot/repo`
2007 got checkout $testroot/repo $testroot/wt > /dev/null
2008 ret="$?"
2009 if [ "$ret" != "0" ]; then
2010 echo "checkout failed unexpectedly" >&2
2011 test_done "$testroot" "$ret"
2012 return 1
2015 (cd $testroot/repo && ln -sf beta alpha.link)
2016 (cd $testroot/repo && ln -sfh gamma epsilon.link)
2017 (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
2018 echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
2019 (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
2020 (cd $testroot/repo && git rm -q nonexistent.link)
2021 (cd $testroot/repo && ln -sf gamma/delta zeta.link)
2022 (cd $testroot/repo && ln -sf alpha new.link)
2023 (cd $testroot/repo && git add .)
2024 git_commit $testroot/repo -m "change symlinks"
2025 local commit_id2=`git_show_head $testroot/repo`
2027 # modified symlink to file A vs modified symlink to file B
2028 (cd $testroot/wt && ln -sf gamma/delta alpha.link)
2029 # modified symlink to dir A vs modified symlink to file B
2030 (cd $testroot/wt && ln -sfh beta epsilon.link)
2031 # modeified symlink to file A vs modified symlink to dir B
2032 (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
2033 # added regular file A vs added bad symlink to file A
2034 (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
2035 (cd $testroot/wt && got add dotgotfoo.link > /dev/null)
2036 # added bad symlink to file A vs added regular file A
2037 echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
2038 (cd $testroot/wt && got add dotgotbar.link > /dev/null)
2039 # removed symlink to non-existent file A vs modified symlink
2040 # to nonexistent file B
2041 (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
2042 # modified symlink to file A vs removed symlink to file A
2043 (cd $testroot/wt && got rm zeta.link > /dev/null)
2044 # added symlink to file A vs added symlink to file B
2045 (cd $testroot/wt && ln -sf beta new.link)
2046 (cd $testroot/wt && got add new.link > /dev/null)
2048 (cd $testroot/wt && got update > $testroot/stdout)
2050 echo "C alpha.link" >> $testroot/stdout.expected
2051 echo "C dotgotbar.link" >> $testroot/stdout.expected
2052 echo "C dotgotfoo.link" >> $testroot/stdout.expected
2053 echo "C epsilon/beta.link" >> $testroot/stdout.expected
2054 echo "C epsilon.link" >> $testroot/stdout.expected
2055 echo "C new.link" >> $testroot/stdout.expected
2056 echo "C nonexistent.link" >> $testroot/stdout.expected
2057 echo "G zeta.link" >> $testroot/stdout.expected
2058 echo -n "Updated to commit " >> $testroot/stdout.expected
2059 git_show_head $testroot/repo >> $testroot/stdout.expected
2060 echo >> $testroot/stdout.expected
2061 echo "Files with new merge conflicts: 7" >> $testroot/stdout.expected
2063 cmp -s $testroot/stdout.expected $testroot/stdout
2064 ret="$?"
2065 if [ "$ret" != "0" ]; then
2066 diff -u $testroot/stdout.expected $testroot/stdout
2067 test_done "$testroot" "$ret"
2068 return 1
2071 if [ -h $testroot/wt/alpha.link ]; then
2072 echo "alpha.link is a symlink"
2073 test_done "$testroot" "1"
2074 return 1
2077 echo "<<<<<<< merged change: commit $commit_id2" \
2078 > $testroot/content.expected
2079 echo "beta" >> $testroot/content.expected
2080 echo "3-way merge base: commit $commit_id1" \
2081 >> $testroot/content.expected
2082 echo "alpha" >> $testroot/content.expected
2083 echo "=======" >> $testroot/content.expected
2084 echo "gamma/delta" >> $testroot/content.expected
2085 echo '>>>>>>>' >> $testroot/content.expected
2086 echo -n "" >> $testroot/content.expected
2088 cp $testroot/wt/alpha.link $testroot/content
2089 cmp -s $testroot/content.expected $testroot/content
2090 ret="$?"
2091 if [ "$ret" != "0" ]; then
2092 diff -u $testroot/content.expected $testroot/content
2093 test_done "$testroot" "$ret"
2094 return 1
2097 if [ -h $testroot/wt/epsilon.link ]; then
2098 echo "epsilon.link is a symlink"
2099 test_done "$testroot" "1"
2100 return 1
2103 echo "<<<<<<< merged change: commit $commit_id2" \
2104 > $testroot/content.expected
2105 echo "gamma" >> $testroot/content.expected
2106 echo "3-way merge base: commit $commit_id1" \
2107 >> $testroot/content.expected
2108 echo "epsilon" >> $testroot/content.expected
2109 echo "=======" >> $testroot/content.expected
2110 echo "beta" >> $testroot/content.expected
2111 echo '>>>>>>>' >> $testroot/content.expected
2112 echo -n "" >> $testroot/content.expected
2114 cp $testroot/wt/epsilon.link $testroot/content
2115 cmp -s $testroot/content.expected $testroot/content
2116 ret="$?"
2117 if [ "$ret" != "0" ]; then
2118 diff -u $testroot/content.expected $testroot/content
2119 test_done "$testroot" "$ret"
2120 return 1
2123 if [ -h $testroot/wt/passwd.link ]; then
2124 echo -n "passwd.link symlink points outside of work tree: " >&2
2125 readlink $testroot/wt/passwd.link >&2
2126 test_done "$testroot" "1"
2127 return 1
2130 echo -n "/etc/passwd" > $testroot/content.expected
2131 cp $testroot/wt/passwd.link $testroot/content
2133 cmp -s $testroot/content.expected $testroot/content
2134 ret="$?"
2135 if [ "$ret" != "0" ]; then
2136 diff -u $testroot/content.expected $testroot/content
2137 test_done "$testroot" "$ret"
2138 return 1
2141 if [ -h $testroot/wt/epsilon/beta.link ]; then
2142 echo "epsilon/beta.link is a symlink"
2143 test_done "$testroot" "1"
2144 return 1
2147 echo "<<<<<<< merged change: commit $commit_id2" \
2148 > $testroot/content.expected
2149 echo "../gamma/delta" >> $testroot/content.expected
2150 echo "3-way merge base: commit $commit_id1" \
2151 >> $testroot/content.expected
2152 echo "../beta" >> $testroot/content.expected
2153 echo "=======" >> $testroot/content.expected
2154 echo "../gamma" >> $testroot/content.expected
2155 echo '>>>>>>>' >> $testroot/content.expected
2156 echo -n "" >> $testroot/content.expected
2158 cp $testroot/wt/epsilon/beta.link $testroot/content
2159 cmp -s $testroot/content.expected $testroot/content
2160 ret="$?"
2161 if [ "$ret" != "0" ]; then
2162 diff -u $testroot/content.expected $testroot/content
2163 test_done "$testroot" "$ret"
2164 return 1
2167 if [ -h $testroot/wt/nonexistent.link ]; then
2168 echo -n "nonexistent.link still exists on disk: " >&2
2169 readlink $testroot/wt/nonexistent.link >&2
2170 test_done "$testroot" "1"
2171 return 1
2174 echo "<<<<<<< merged change: commit $commit_id2" \
2175 > $testroot/content.expected
2176 echo "(symlink was deleted)" >> $testroot/content.expected
2177 echo "=======" >> $testroot/content.expected
2178 echo "nonexistent2" >> $testroot/content.expected
2179 echo '>>>>>>>' >> $testroot/content.expected
2180 echo -n "" >> $testroot/content.expected
2182 cp $testroot/wt/nonexistent.link $testroot/content
2183 cmp -s $testroot/content.expected $testroot/content
2184 ret="$?"
2185 if [ "$ret" != "0" ]; then
2186 diff -u $testroot/content.expected $testroot/content
2187 test_done "$testroot" "$ret"
2188 return 1
2191 if [ -h $testroot/wt/dotgotfoo.link ]; then
2192 echo "dotgotfoo.link is a symlink"
2193 test_done "$testroot" "1"
2194 return 1
2197 echo "<<<<<<< merged change: commit $commit_id2" \
2198 > $testroot/content.expected
2199 echo "this is regular file foo" >> $testroot/content.expected
2200 echo "=======" >> $testroot/content.expected
2201 echo -n ".got/bar" >> $testroot/content.expected
2202 echo '>>>>>>>' >> $testroot/content.expected
2203 echo -n "" >> $testroot/content.expected
2205 cp $testroot/wt/dotgotfoo.link $testroot/content
2206 cmp -s $testroot/content.expected $testroot/content
2207 ret="$?"
2208 if [ "$ret" != "0" ]; then
2209 diff -u $testroot/content.expected $testroot/content
2210 test_done "$testroot" "$ret"
2211 return 1
2214 if [ -h $testroot/wt/dotgotbar.link ]; then
2215 echo "dotgotbar.link is a symlink"
2216 test_done "$testroot" "1"
2217 return 1
2219 echo "<<<<<<< merged change: commit $commit_id2" \
2220 > $testroot/content.expected
2221 echo -n ".got/bar" >> $testroot/content.expected
2222 echo "=======" >> $testroot/content.expected
2223 echo "this is regular file bar" >> $testroot/content.expected
2224 echo '>>>>>>>' >> $testroot/content.expected
2225 echo -n "" >> $testroot/content.expected
2227 cp $testroot/wt/dotgotbar.link $testroot/content
2228 cmp -s $testroot/content.expected $testroot/content
2229 ret="$?"
2230 if [ "$ret" != "0" ]; then
2231 diff -u $testroot/content.expected $testroot/content
2232 test_done "$testroot" "$ret"
2233 return 1
2236 if [ -h $testroot/wt/new.link ]; then
2237 echo "new.link is a symlink"
2238 test_done "$testroot" "1"
2239 return 1
2242 echo "<<<<<<< merged change: commit $commit_id2" \
2243 > $testroot/content.expected
2244 echo "alpha" >> $testroot/content.expected
2245 echo "=======" >> $testroot/content.expected
2246 echo "beta" >> $testroot/content.expected
2247 echo '>>>>>>>' >> $testroot/content.expected
2248 echo -n "" >> $testroot/content.expected
2250 cp $testroot/wt/new.link $testroot/content
2251 cmp -s $testroot/content.expected $testroot/content
2252 ret="$?"
2253 if [ "$ret" != "0" ]; then
2254 diff -u $testroot/content.expected $testroot/content
2255 test_done "$testroot" "$ret"
2256 return 1
2259 echo "A dotgotfoo.link" > $testroot/stdout.expected
2260 echo "M new.link" >> $testroot/stdout.expected
2261 echo "D nonexistent.link" >> $testroot/stdout.expected
2262 (cd $testroot/wt && got status > $testroot/stdout)
2263 if [ "$ret" != "0" ]; then
2264 diff -u $testroot/stdout.expected $testroot/stdout
2265 test_done "$testroot" "$ret"
2266 return 1
2269 test_done "$testroot" "0"
2273 test_update_single_file() {
2274 local testroot=`test_init update_single_file 1`
2276 echo c1 > $testroot/repo/c
2277 (cd $testroot/repo && git add .)
2278 git_commit $testroot/repo -m "adding file c"
2279 local commit_id1=`git_show_head $testroot/repo`
2281 echo a > $testroot/repo/a
2282 echo b > $testroot/repo/b
2283 echo c2 > $testroot/repo/c
2284 (cd $testroot/repo && git add .)
2285 git_commit $testroot/repo -m "add files a and b, change c"
2286 local commit_id2=`git_show_head $testroot/repo`
2288 (cd $testroot/repo && git rm -qf c)
2289 git_commit $testroot/repo -m "remove file c"
2290 local commit_id3=`git_show_head $testroot/repo`
2292 got checkout -c $commit_id2 $testroot/repo $testroot/wt > /dev/null
2293 ret="$?"
2294 if [ "$ret" != "0" ]; then
2295 test_done "$testroot" "$ret"
2296 return 1
2299 echo "U c" > $testroot/stdout.expected
2300 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
2302 (cd $testroot/wt && got update -c $commit_id1 c \
2303 > $testroot/stdout)
2305 cmp -s $testroot/stdout.expected $testroot/stdout
2306 ret="$?"
2307 if [ "$ret" != "0" ]; then
2308 diff -u $testroot/stdout.expected $testroot/stdout
2309 test_done "$testroot" "$ret"
2310 return 1
2313 echo c1 > $testroot/content.expected
2314 cat $testroot/wt/c > $testroot/content
2316 cmp -s $testroot/content.expected $testroot/content
2317 ret="$?"
2318 if [ "$ret" != "0" ]; then
2319 diff -u $testroot/content.expected $testroot/content
2320 test_done "$testroot" "$ret"
2321 return 1
2324 echo "U c" > $testroot/stdout.expected
2325 echo "Updated to commit $commit_id2" >> $testroot/stdout.expected
2327 (cd $testroot/wt && got update -c $commit_id2 c > $testroot/stdout)
2329 cmp -s $testroot/stdout.expected $testroot/stdout
2330 ret="$?"
2331 if [ "$ret" != "0" ]; then
2332 diff -u $testroot/stdout.expected $testroot/stdout
2333 test_done "$testroot" "$ret"
2334 return 1
2337 echo c2 > $testroot/content.expected
2338 cat $testroot/wt/c > $testroot/content
2340 cmp -s $testroot/content.expected $testroot/content
2341 ret="$?"
2342 if [ "$ret" != "0" ]; then
2343 diff -u $testroot/content.expected $testroot/content
2344 test_done "$testroot" "$ret"
2345 return 1
2348 echo "D c" > $testroot/stdout.expected
2349 echo "Updated to commit $commit_id3" >> $testroot/stdout.expected
2351 (cd $testroot/wt && got update -c $commit_id3 c \
2352 > $testroot/stdout 2> $testroot/stderr)
2354 echo "got: /c: no such entry found in tree" > $testroot/stderr.expected
2355 cmp -s $testroot/stderr.expected $testroot/stderr
2356 ret="$?"
2357 if [ "$ret" != "0" ]; then
2358 diff -u $testroot/stderr.expected $testroot/stderr
2359 test_done "$testroot" "$ret"
2360 return 1
2363 echo -n > $testroot/stdout.expected
2364 cmp -s $testroot/stdout.expected $testroot/stdout
2365 ret="$?"
2366 if [ "$ret" != "0" ]; then
2367 diff -u $testroot/stdout.expected $testroot/stdout
2368 test_done "$testroot" "$ret"
2369 return 1
2372 echo "D c" > $testroot/stdout.expected
2373 echo "Updated to commit $commit_id3" >> $testroot/stdout.expected
2375 (cd $testroot/wt && got update -c $commit_id3 > $testroot/stdout)
2376 cmp -s $testroot/stdout.expected $testroot/stdout
2377 ret="$?"
2378 if [ "$ret" != "0" ]; then
2379 diff -u $testroot/stdout.expected $testroot/stdout
2380 test_done "$testroot" "$ret"
2381 return 1
2384 if [ -e $testroot/wt/c ]; then
2385 echo "removed file c still exists on disk" >&2
2386 test_done "$testroot" "1"
2387 return 1
2390 test_done "$testroot" "0"
2391 return 0
2394 test_update_file_skipped_due_to_conflict() {
2395 local testroot=`test_init update_file_skipped_due_to_conflict`
2396 local commit_id0=`git_show_head $testroot/repo`
2397 blob_id0=`get_blob_id $testroot/repo "" beta`
2399 echo "changed beta" > $testroot/repo/beta
2400 git_commit $testroot/repo -m "changed beta"
2401 local commit_id1=`git_show_head $testroot/repo`
2402 blob_id1=`get_blob_id $testroot/repo "" beta`
2404 got checkout $testroot/repo $testroot/wt > /dev/null
2405 ret="$?"
2406 if [ "$ret" != "0" ]; then
2407 test_done "$testroot" "$ret"
2408 return 1
2411 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2412 cut -d ':' -f 2 | tr -d ' ')`
2413 if [ "$blob_id" != "$blob_id1" ]; then
2414 echo "file beta has the wrong base blob ID" >&2
2415 test_done "$testroot" "1"
2416 return 1
2419 commit_id=`(cd $testroot/wt && got info beta | \
2420 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2421 if [ "$commit_id" != "$commit_id1" ]; then
2422 echo "file beta has the wrong base commit ID" >&2
2423 test_done "$testroot" "1"
2424 return 1
2427 echo "modified beta" > $testroot/wt/beta
2429 (cd $testroot/wt && got update -c $commit_id0 > $testroot/stdout)
2431 echo "C beta" > $testroot/stdout.expected
2432 echo "Updated to commit $commit_id0" >> $testroot/stdout.expected
2433 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
2434 cmp -s $testroot/stdout.expected $testroot/stdout
2435 ret="$?"
2436 if [ "$ret" != "0" ]; then
2437 diff -u $testroot/stdout.expected $testroot/stdout
2438 test_done "$testroot" "$ret"
2439 return 1
2442 echo "<<<<<<< merged change: commit $commit_id0" \
2443 > $testroot/content.expected
2444 echo "beta" >> $testroot/content.expected
2445 echo "||||||| 3-way merge base: commit $commit_id1" \
2446 >> $testroot/content.expected
2447 echo "changed beta" >> $testroot/content.expected
2448 echo "=======" >> $testroot/content.expected
2449 echo "modified beta" >> $testroot/content.expected
2450 echo ">>>>>>>" >> $testroot/content.expected
2452 cat $testroot/wt/beta > $testroot/content
2454 cmp -s $testroot/content.expected $testroot/content
2455 ret="$?"
2456 if [ "$ret" != "0" ]; then
2457 diff -u $testroot/content.expected $testroot/content
2458 test_done "$testroot" "$ret"
2459 return 1
2462 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2463 cut -d ':' -f 2 | tr -d ' ')`
2464 if [ "$blob_id" != "$blob_id0" ]; then
2465 echo "file beta has the wrong base blob ID" >&2
2466 test_done "$testroot" "1"
2467 return 1
2470 commit_id=`(cd $testroot/wt && got info beta | \
2471 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2472 if [ "$commit_id" != "$commit_id0" ]; then
2473 echo "file beta has the wrong base commit ID" >&2
2474 test_done "$testroot" "1"
2475 return 1
2478 # update to the latest commit again; this skips beta
2479 (cd $testroot/wt && got update > $testroot/stdout)
2480 echo "# beta" > $testroot/stdout.expected
2481 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
2482 echo "Files not updated because of existing merge conflicts: 1" \
2483 >> $testroot/stdout.expected
2484 cmp -s $testroot/stdout.expected $testroot/stdout
2485 ret="$?"
2486 if [ "$ret" != "0" ]; then
2487 diff -u $testroot/stdout.expected $testroot/stdout
2488 test_done "$testroot" "$ret"
2489 return 1
2492 # blob ID of beta should not have changed
2493 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2494 cut -d ':' -f 2 | tr -d ' ')`
2495 if [ "$blob_id" != "$blob_id0" ]; then
2496 echo "file beta has the wrong base blob ID" >&2
2497 test_done "$testroot" "1"
2498 return 1
2501 # commit ID of beta should not have changed; There was a bug
2502 # here where the commit ID had been changed even though the
2503 # file was not updated.
2504 commit_id=`(cd $testroot/wt && got info beta | \
2505 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2506 if [ "$commit_id" != "$commit_id0" ]; then
2507 echo "file beta has the wrong base commit ID: $commit_id" >&2
2508 test_done "$testroot" "1"
2509 return 1
2512 # beta is still conflicted and based on commit 0
2513 echo 'C beta' > $testroot/stdout.expected
2514 (cd $testroot/wt && got status > $testroot/stdout)
2515 cmp -s $testroot/stdout.expected $testroot/stdout
2516 ret="$?"
2517 if [ "$ret" != "0" ]; then
2518 diff -u $testroot/stdout.expected $testroot/stdout
2519 test_done "$testroot" "$ret"
2520 return 1
2523 # resolve the conflict via revert
2524 (cd $testroot/wt && got revert beta >/dev/null)
2526 # beta now matches its base blob which is still from commit 0
2527 echo "beta" > $testroot/content.expected
2528 cat $testroot/wt/beta > $testroot/content
2529 cmp -s $testroot/content.expected $testroot/content
2530 ret="$?"
2531 if [ "$ret" != "0" ]; then
2532 diff -u $testroot/content.expected $testroot/content
2533 test_done "$testroot" "$ret"
2534 return 1
2537 # updating to the latest commit should now update beta
2538 (cd $testroot/wt && got update > $testroot/stdout)
2539 echo "U beta" > $testroot/stdout.expected
2540 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
2541 cmp -s $testroot/stdout.expected $testroot/stdout
2542 ret="$?"
2543 if [ "$ret" != "0" ]; then
2544 diff -u $testroot/stdout.expected $testroot/stdout
2545 test_done "$testroot" "$ret"
2546 return 1
2549 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2550 cut -d ':' -f 2 | tr -d ' ')`
2551 if [ "$blob_id" != "$blob_id1" ]; then
2552 echo "file beta has the wrong base blob ID" >&2
2553 test_done "$testroot" "1"
2554 return 1
2557 commit_id=`(cd $testroot/wt && got info beta | \
2558 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2559 if [ "$commit_id" != "$commit_id1" ]; then
2560 echo "file beta has the wrong base commit ID: $commit_id" >&2
2561 test_done "$testroot" "1"
2562 return 1
2565 echo "changed beta" > $testroot/content.expected
2566 cat $testroot/wt/beta > $testroot/content
2567 cmp -s $testroot/content.expected $testroot/content
2568 ret="$?"
2569 if [ "$ret" != "0" ]; then
2570 diff -u $testroot/content.expected $testroot/content
2572 test_done "$testroot" "$ret"
2575 test_update_file_skipped_due_to_obstruction() {
2576 local testroot=`test_init update_file_skipped_due_to_obstruction`
2577 local commit_id0=`git_show_head $testroot/repo`
2578 blob_id0=`get_blob_id $testroot/repo "" beta`
2580 echo "changed beta" > $testroot/repo/beta
2581 git_commit $testroot/repo -m "changed beta"
2582 local commit_id1=`git_show_head $testroot/repo`
2583 blob_id1=`get_blob_id $testroot/repo "" beta`
2585 got checkout -c $commit_id0 $testroot/repo $testroot/wt > /dev/null
2586 ret="$?"
2587 if [ "$ret" != "0" ]; then
2588 test_done "$testroot" "$ret"
2589 return 1
2592 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2593 cut -d ':' -f 2 | tr -d ' ')`
2594 if [ "$blob_id" != "$blob_id0" ]; then
2595 echo "file beta has the wrong base blob ID" >&2
2596 test_done "$testroot" "1"
2597 return 1
2600 commit_id=`(cd $testroot/wt && got info beta | \
2601 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2602 if [ "$commit_id" != "$commit_id0" ]; then
2603 echo "file beta has the wrong base commit ID" >&2
2604 test_done "$testroot" "1"
2605 return 1
2608 rm $testroot/wt/beta
2609 mkdir -p $testroot/wt/beta/psi
2611 # update to the latest commit; this skips beta
2612 (cd $testroot/wt && got update > $testroot/stdout)
2614 echo "~ beta" > $testroot/stdout.expected
2615 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
2616 echo "File paths obstructed by a non-regular file: 1" >> $testroot/stdout.expected
2617 cmp -s $testroot/stdout.expected $testroot/stdout
2618 ret="$?"
2619 if [ "$ret" != "0" ]; then
2620 diff -u $testroot/stdout.expected $testroot/stdout
2621 test_done "$testroot" "$ret"
2622 return 1
2625 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2626 cut -d ':' -f 2 | tr -d ' ')`
2627 if [ "$blob_id" != "$blob_id0" ]; then
2628 echo "file beta has the wrong base blob ID" >&2
2629 test_done "$testroot" "1"
2630 return 1
2633 commit_id=`(cd $testroot/wt && got info beta | \
2634 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2635 if [ "$commit_id" != "$commit_id0" ]; then
2636 echo "file beta has the wrong base commit ID" >&2
2637 test_done "$testroot" "1"
2638 return 1
2641 # remove the directory which obstructs file beta
2642 rm -r $testroot/wt/beta
2644 # updating to the latest commit should now update beta
2645 (cd $testroot/wt && got update > $testroot/stdout)
2646 echo "! beta" > $testroot/stdout.expected
2647 echo "Updated to commit $commit_id1" >> $testroot/stdout.expected
2648 cmp -s $testroot/stdout.expected $testroot/stdout
2649 ret="$?"
2650 if [ "$ret" != "0" ]; then
2651 diff -u $testroot/stdout.expected $testroot/stdout
2652 test_done "$testroot" "$ret"
2653 return 1
2656 blob_id=`(cd $testroot/wt && got info beta | grep 'blob:' | \
2657 cut -d ':' -f 2 | tr -d ' ')`
2658 if [ "$blob_id" != "$blob_id1" ]; then
2659 echo "file beta has the wrong base blob ID" >&2
2660 test_done "$testroot" "1"
2661 return 1
2664 commit_id=`(cd $testroot/wt && got info beta | \
2665 grep 'based on commit:' | cut -d ':' -f 2 | tr -d ' ')`
2666 if [ "$commit_id" != "$commit_id1" ]; then
2667 echo "file beta has the wrong base commit ID: $commit_id" >&2
2668 test_done "$testroot" "1"
2669 return 1
2672 echo "changed beta" > $testroot/content.expected
2673 cat $testroot/wt/beta > $testroot/content
2674 cmp -s $testroot/content.expected $testroot/content
2675 ret="$?"
2676 if [ "$ret" != "0" ]; then
2677 diff -u $testroot/content.expected $testroot/content
2679 test_done "$testroot" "$ret"
2683 test_parseargs "$@"
2684 run_test test_update_basic
2685 run_test test_update_adds_file
2686 run_test test_update_deletes_file
2687 run_test test_update_deletes_dir
2688 run_test test_update_deletes_dir_with_path_prefix
2689 run_test test_update_deletes_dir_recursively
2690 run_test test_update_sibling_dirs_with_common_prefix
2691 run_test test_update_dir_with_dot_sibling
2692 run_test test_update_moves_files_upwards
2693 run_test test_update_moves_files_to_new_dir
2694 run_test test_update_creates_missing_parent
2695 run_test test_update_creates_missing_parent_with_subdir
2696 run_test test_update_file_in_subsubdir
2697 run_test test_update_merges_file_edits
2698 run_test test_update_keeps_xbit
2699 run_test test_update_clears_xbit
2700 run_test test_update_restores_missing_file
2701 run_test test_update_conflict_wt_add_vs_repo_add
2702 run_test test_update_conflict_wt_edit_vs_repo_rm
2703 run_test test_update_conflict_wt_rm_vs_repo_edit
2704 run_test test_update_conflict_wt_rm_vs_repo_rm
2705 run_test test_update_partial
2706 run_test test_update_partial_add
2707 run_test test_update_partial_rm
2708 run_test test_update_partial_dir
2709 run_test test_update_moved_branch_ref
2710 run_test test_update_to_another_branch
2711 run_test test_update_to_commit_on_wrong_branch
2712 run_test test_update_bumps_base_commit_id
2713 run_test test_update_tag
2714 run_test test_update_toggles_xbit
2715 run_test test_update_preserves_conflicted_file
2716 run_test test_update_modified_submodules
2717 run_test test_update_adds_submodule
2718 run_test test_update_conflict_wt_file_vs_repo_submodule
2719 run_test test_update_adds_symlink
2720 run_test test_update_deletes_symlink
2721 run_test test_update_symlink_conflicts
2722 run_test test_update_single_file
2723 run_test test_update_file_skipped_due_to_conflict
2724 run_test test_update_file_skipped_due_to_obstruction