3 # Copyright (c) 2005 Junio C Hamano
4 # Copyright (c) 2005 Robert Fitzsimons
7 test_description
='git ls-tree directory and filenames handling.
9 This test runs git ls-tree with the following in a tree.
13 path0/a/b/c/1.txt - a file in a directory
14 path1/b/c/1.txt - a file in a directory
15 path2/1.txt - a file in a directory
16 path3/1.txt - a file in a directory
17 path3/2.txt - a file in a directory
19 Test the handling of multiple directories which have matching file
20 entries. Also test odd filename and missing entries handling.
23 TEST_PASSES_SANITIZE_LEAK
=true
26 test_expect_success
'setup' '
29 mkdir path0 path0/a path0/a/b path0/a/b/c &&
30 echo 111 >path0/a/b/c/1.txt &&
31 mkdir path1 path1/b path1/b/c &&
32 echo 111 >path1/b/c/1.txt &&
34 echo 111 >path2/1.txt &&
36 echo 111 >path3/1.txt &&
37 echo 222 >path3/2.txt &&
38 find *.txt path* \( -type f -o -type l \) -print |
39 xargs git update-index --add &&
40 tree=$(git write-tree) &&
45 sed -e "s/ $OID_REGEX / X /" <current
>check
&&
46 test_cmp expected check
49 test_expect_success
'ls-tree plain' '
50 git ls-tree $tree >current &&
51 cat >expected <<\EOF &&
62 # Recursive does not show tree nodes anymore...
63 test_expect_success
'ls-tree recursive' '
64 git ls-tree -r $tree >current &&
65 cat >expected <<\EOF &&
68 100644 blob X path0/a/b/c/1.txt
69 100644 blob X path1/b/c/1.txt
70 100644 blob X path2/1.txt
71 100644 blob X path3/1.txt
72 100644 blob X path3/2.txt
77 test_expect_success
'ls-tree filter 1.txt' '
78 git ls-tree $tree 1.txt >current &&
79 cat >expected <<\EOF &&
85 test_expect_success
'ls-tree filter path1/b/c/1.txt' '
86 git ls-tree $tree path1/b/c/1.txt >current &&
87 cat >expected <<\EOF &&
88 100644 blob X path1/b/c/1.txt
93 test_expect_success
'ls-tree filter all 1.txt files' '
94 git ls-tree $tree 1.txt path0/a/b/c/1.txt \
95 path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
96 cat >expected <<\EOF &&
98 100644 blob X path0/a/b/c/1.txt
99 100644 blob X path1/b/c/1.txt
100 100644 blob X path2/1.txt
101 100644 blob X path3/1.txt
106 # I am not so sure about this one after ls-tree doing pathspec match.
107 # Having both path0/a and path0/a/b/c makes path0/a redundant, and
108 # it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified.
109 test_expect_success
'ls-tree filter directories' '
110 git ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
111 cat >expected <<\EOF &&
112 040000 tree X path0/a/b/c
113 040000 tree X path1/b/c
120 # Again, duplicates are filtered away so this is equivalent to
121 # having 1.txt and path3
122 test_expect_success
'ls-tree filter odd names' '
123 git ls-tree $tree 1.txt ./1.txt .//1.txt \
124 path3/1.txt path3/./1.txt path3 path3// >current &&
125 cat >expected <<\EOF &&
127 100644 blob X path3/1.txt
128 100644 blob X path3/2.txt
133 test_expect_success
'ls-tree filter missing files and extra slashes' '
134 git ls-tree $tree 1.txt/ abc.txt \
135 path3//23.txt path3/2.txt/// >current &&
140 test_expect_success
'ls-tree filter is leading path match' '
141 git ls-tree $tree pa path3/a >current &&
146 test_expect_success
'ls-tree --full-name' '
149 git ls-tree --full-name $tree a
151 cat >expected <<\EOF &&
152 040000 tree X path0/a
157 test_expect_success
'ls-tree --no-full-name' '
158 git -C path0 ls-tree --no-full-name $tree a >current &&
159 cat >expected <<-EOF &&
165 test_expect_success
'ls-tree --full-tree' '
168 git ls-tree --full-tree $tree
170 cat >expected <<\EOF &&
181 test_expect_success
'ls-tree --full-tree -r' '
184 git ls-tree --full-tree -r $tree
186 cat >expected <<\EOF &&
189 100644 blob X path0/a/b/c/1.txt
190 100644 blob X path1/b/c/1.txt
191 100644 blob X path2/1.txt
192 100644 blob X path3/1.txt
193 100644 blob X path3/2.txt
198 test_expect_success
'ls-tree --abbrev=5' '
199 git ls-tree --abbrev=5 $tree >current &&
200 sed -e "s/ $_x05[0-9a-f]* / X /" <current >check &&
201 cat >expected <<\EOF &&
209 test_cmp expected check
212 for opt
in --name-only --name-status
214 test_expect_success
"ls-tree $opt" '
215 git ls-tree $opt $tree >current &&
216 cat >expected <<-\EOF &&
227 test_expect_success
"ls-tree $opt -r" '
228 git ls-tree $opt -r $tree >current &&
229 cat >expected <<-\EOF &&