3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git conflicts when checking files out test.'
8 # The first test registers the following filesystem structure in the
12 # path1/file1 - a file in a directory
14 # And then tries to checkout in a work tree that has the following:
16 # path0/file0 - a file in a directory
19 # The git checkout-index command should fail when attempting to checkout
20 # path0, finding it is occupied by a directory, and path1/file1, finding
21 # path1 is occupied by a non-directory. With "-f" flag, it should remove
22 # the conflicting paths and succeed.
27 # show filesystem files, just [-dl] for type and name
29 sed -e 's/^[0-9]* * [0-9]* * \([-bcdl]\)[^ ]* *[0-9]* *[^ ]* *[^ ]* *[0-9]* [A-Z][a-z][a-z] [0-9][0-9] [^ ]* /fs: \1 /'
30 # what's in the cache, just mode and name
31 git ls-files --stage |
32 sed -e 's/^\([0-9]*\) [0-9a-f]* [0-3] /ca: \1 /'
33 # what's in the tree, just mode and name.
35 sed -e 's/^\([0-9]*\) [^ ]* [0-9a-f]* /tr: \1 /'
43 'git update-index --add various paths.' \
44 'git update-index --add path0 path1/file1'
52 'git checkout-index without -f should fail on conflicting work tree.' \
53 'test_must_fail git checkout-index -a'
56 'git checkout-index with -f should succeed.' \
57 'git checkout-index -f -a'
60 'git checkout-index conflicting paths.' \
61 'test -f path0 && test -d path1 && test -f path1/file1'
63 test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
65 ln -s tar/get there &&
67 git checkout-index -a -f --prefix=there/ &&
69 git checkout-index -a -f --prefix=there/
72 # The second test registers the following filesystem structure in the cache:
74 # path2/file0 - a file in a directory
75 # path3/file1 - a file in a directory
77 # and attempts to check it out when the work tree has:
79 # path2/file0 - a file in a directory
80 # path3 - a symlink pointing at "path2"
82 # Checkout cache should fail to extract path3/file1 because the leading
83 # path path3 is occupied by a non-directory. With "-f" it should remove
84 # the symlink path3 and create directory path3 and file path3/file1.
89 'git update-index --add path2/file0' \
90 'git update-index --add path2/file0'
92 'writing tree out with git write-tree' \
93 'tree1=$(git write-tree)'
94 test_debug 'show_files $tree1'
99 'git update-index --add path3/file1' \
100 'git update-index --add path3/file1'
101 test_expect_success \
102 'writing tree out with git write-tree' \
103 'tree2=$(git write-tree)'
104 test_debug 'show_files $tree2'
107 test_expect_success \
108 'read previously written tree and checkout.' \
109 'git read-tree -m $tree1 && git checkout-index -f -a'
110 test_debug 'show_files $tree1'
112 test_expect_success \
114 'test_ln_s_add path2 path3'
115 test_expect_success \
116 'writing tree out with git write-tree' \
117 'tree3=$(git write-tree)'
118 test_debug 'show_files $tree3'
120 # Morten says "Got that?" here.
123 test_expect_success \
124 'read previously written tree and checkout.' \
125 'git read-tree $tree2 && git checkout-index -f -a'
126 test_debug 'show_files $tree2'
128 test_expect_success \
129 'checking out conflicting path with -f' \
130 'test ! -h path2 && test -d path2 &&
131 test ! -h path3 && test -d path3 &&
132 test ! -h path2/file0 && test -f path2/file0 &&
133 test ! -h path3/file1 && test -f path3/file1'