Start the 2.46 cycle
[git/gitster.git] / t / t2000-conflict-when-checking-files-out.sh
blob79fc97f1d7eb42675c85ef29b8cb36a75d7e7669
1 #!/bin/sh
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
9 # cache:
11 # path0 - a file
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
17 # path1 - a file
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.
24 TEST_PASSES_SANITIZE_LEAK=true
25 . ./test-lib.sh
27 show_files() {
28 # show filesystem files, just [-dl] for type and name
29 find path? -ls |
30 sed -e 's/^[0-9]* * [0-9]* * \([-bcdl]\)[^ ]* *[0-9]* *[^ ]* *[^ ]* *[0-9]* [A-Z][a-z][a-z] [0-9][0-9] [^ ]* /fs: \1 /'
31 # what's in the cache, just mode and name
32 git ls-files --stage |
33 sed -e 's/^\([0-9]*\) [0-9a-f]* [0-3] /ca: \1 /'
34 # what's in the tree, just mode and name.
35 git ls-tree -r "$1" |
36 sed -e 's/^\([0-9]*\) [^ ]* [0-9a-f]* /tr: \1 /'
39 date >path0
40 mkdir path1
41 date >path1/file1
43 test_expect_success \
44 'git update-index --add various paths.' \
45 'git update-index --add path0 path1/file1'
47 rm -fr path0 path1
48 mkdir path0
49 date >path0/file0
50 date >path1
52 test_expect_success \
53 'git checkout-index without -f should fail on conflicting work tree.' \
54 'test_must_fail git checkout-index -a'
56 test_expect_success \
57 'git checkout-index with -f should succeed.' \
58 'git checkout-index -f -a'
60 test_expect_success \
61 'git checkout-index conflicting paths.' \
62 'test -f path0 && test -d path1 && test -f path1/file1'
64 test_expect_success SYMLINKS 'checkout-index -f twice with --prefix' '
65 mkdir -p tar/get &&
66 ln -s tar/get there &&
67 echo first &&
68 git checkout-index -a -f --prefix=there/ &&
69 echo second &&
70 git checkout-index -a -f --prefix=there/
73 # The second test registers the following filesystem structure in the cache:
75 # path2/file0 - a file in a directory
76 # path3/file1 - a file in a directory
78 # and attempts to check it out when the work tree has:
80 # path2/file0 - a file in a directory
81 # path3 - a symlink pointing at "path2"
83 # Checkout cache should fail to extract path3/file1 because the leading
84 # path path3 is occupied by a non-directory. With "-f" it should remove
85 # the symlink path3 and create directory path3 and file path3/file1.
87 mkdir path2
88 date >path2/file0
89 test_expect_success \
90 'git update-index --add path2/file0' \
91 'git update-index --add path2/file0'
92 test_expect_success \
93 'writing tree out with git write-tree' \
94 'tree1=$(git write-tree)'
95 test_debug 'show_files $tree1'
97 mkdir path3
98 date >path3/file1
99 test_expect_success \
100 'git update-index --add path3/file1' \
101 'git update-index --add path3/file1'
102 test_expect_success \
103 'writing tree out with git write-tree' \
104 'tree2=$(git write-tree)'
105 test_debug 'show_files $tree2'
107 rm -fr path3
108 test_expect_success \
109 'read previously written tree and checkout.' \
110 'git read-tree -m $tree1 && git checkout-index -f -a'
111 test_debug 'show_files $tree1'
113 test_expect_success \
114 'add a symlink' \
115 'test_ln_s_add path2 path3'
116 test_expect_success \
117 'writing tree out with git write-tree' \
118 'tree3=$(git write-tree)'
119 test_debug 'show_files $tree3'
121 # Morten says "Got that?" here.
122 # Test begins.
124 test_expect_success \
125 'read previously written tree and checkout.' \
126 'git read-tree $tree2 && git checkout-index -f -a'
127 test_debug 'show_files $tree2'
129 test_expect_success \
130 'checking out conflicting path with -f' \
131 'test ! -h path2 && test -d path2 &&
132 test ! -h path3 && test -d path3 &&
133 test ! -h path2/file0 && test -f path2/file0 &&
134 test ! -h path3/file1 && test -f path3/file1'
136 test_done