Raw
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 # Copyright (c) 2005 Robert Fitzsimons
5 #
6
7 test_description='git ls-tree directory and filenames handling.
8
9 This test runs git ls-tree with the following in a tree.
10
11 1.txt - a file
12 2.txt - a file
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
18
19 Test the handling of multiple directories which have matching file
20 entries. Also test odd filename and missing entries handling.
21 '
22
23 . ./test-lib.sh
24
25 test_expect_success 'setup' '
26 echo 111 >1.txt &&
27 echo 222 >2.txt &&
28 mkdir path0 path0/a path0/a/b path0/a/b/c &&
29 echo 111 >path0/a/b/c/1.txt &&
30 mkdir path1 path1/b path1/b/c &&
31 echo 111 >path1/b/c/1.txt &&
32 mkdir path2 &&
33 echo 111 >path2/1.txt &&
34 mkdir path3 &&
35 echo 111 >path3/1.txt &&
36 echo 222 >path3/2.txt &&
37 find *.txt path* \( -type f -o -type l \) -print |
38 xargs git update-index --add &&
39 tree=$(git write-tree) &&
40 echo $tree
41 '
42
43 test_output () {
44 sed -e "s/ $OID_REGEX / X /" <current >check &&
45 test_cmp expected check
46 }
47
48 test_expect_success 'ls-tree plain' '
49 git ls-tree $tree >current &&
50 cat >expected <<\EOF &&
51 100644 blob X 1.txt
52 100644 blob X 2.txt
53 040000 tree X path0
54 040000 tree X path1
55 040000 tree X path2
56 040000 tree X path3
57 EOF
58 test_output
59 '
60
61 # Recursive does not show tree nodes anymore...
62 test_expect_success 'ls-tree recursive' '
63 git ls-tree -r $tree >current &&
64 cat >expected <<\EOF &&
65 100644 blob X 1.txt
66 100644 blob X 2.txt
67 100644 blob X path0/a/b/c/1.txt
68 100644 blob X path1/b/c/1.txt
69 100644 blob X path2/1.txt
70 100644 blob X path3/1.txt
71 100644 blob X path3/2.txt
72 EOF
73 test_output
74 '
75
76 test_expect_success 'ls-tree filter 1.txt' '
77 git ls-tree $tree 1.txt >current &&
78 cat >expected <<\EOF &&
79 100644 blob X 1.txt
80 EOF
81 test_output
82 '
83
84 test_expect_success 'ls-tree filter path1/b/c/1.txt' '
85 git ls-tree $tree path1/b/c/1.txt >current &&
86 cat >expected <<\EOF &&
87 100644 blob X path1/b/c/1.txt
88 EOF
89 test_output
90 '
91
92 test_expect_success 'ls-tree filter all 1.txt files' '
93 git ls-tree $tree 1.txt path0/a/b/c/1.txt \
94 path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
95 cat >expected <<\EOF &&
96 100644 blob X 1.txt
97 100644 blob X path0/a/b/c/1.txt
98 100644 blob X path1/b/c/1.txt
99 100644 blob X path2/1.txt
100 100644 blob X path3/1.txt
101 EOF
102 test_output
103 '
104
105 # I am not so sure about this one after ls-tree doing pathspec match.
106 # Having both path0/a and path0/a/b/c makes path0/a redundant, and
107 # it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified.
108 test_expect_success 'ls-tree filter directories' '
109 git ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
110 cat >expected <<\EOF &&
111 040000 tree X path0/a/b/c
112 040000 tree X path1/b/c
113 040000 tree X path2
114 040000 tree X path3
115 EOF
116 test_output
117 '
118
119 # Again, duplicates are filtered away so this is equivalent to
120 # having 1.txt and path3
121 test_expect_success 'ls-tree filter odd names' '
122 git ls-tree $tree 1.txt ./1.txt .//1.txt \
123 path3/1.txt path3/./1.txt path3 path3// >current &&
124 cat >expected <<\EOF &&
125 100644 blob X 1.txt
126 100644 blob X path3/1.txt
127 100644 blob X path3/2.txt
128 EOF
129 test_output
130 '
131
132 test_expect_success 'ls-tree filter missing files and extra slashes' '
133 git ls-tree $tree 1.txt/ abc.txt \
134 path3//23.txt path3/2.txt/// >current &&
135 >expected &&
136 test_output
137 '
138
139 test_expect_success 'ls-tree filter is leading path match' '
140 git ls-tree $tree pa path3/a >current &&
141 >expected &&
142 test_output
143 '
144
145 test_expect_success 'ls-tree --full-name' '
146 (
147 cd path0 &&
148 git ls-tree --full-name $tree a
149 ) >current &&
150 cat >expected <<\EOF &&
151 040000 tree X path0/a
152 EOF
153 test_output
154 '
155
156 test_expect_success 'ls-tree --no-full-name' '
157 git -C path0 ls-tree --no-full-name $tree a >current &&
158 cat >expected <<-EOF &&
159 040000 tree X a
160 EOF
161 test_output
162 '
163
164 test_expect_success 'ls-tree --full-tree' '
165 (
166 cd path1/b/c &&
167 git ls-tree --full-tree $tree
168 ) >current &&
169 cat >expected <<\EOF &&
170 100644 blob X 1.txt
171 100644 blob X 2.txt
172 040000 tree X path0
173 040000 tree X path1
174 040000 tree X path2
175 040000 tree X path3
176 EOF
177 test_output
178 '
179
180 test_expect_success 'ls-tree --full-tree -r' '
181 (
182 cd path3/ &&
183 git ls-tree --full-tree -r $tree
184 ) >current &&
185 cat >expected <<\EOF &&
186 100644 blob X 1.txt
187 100644 blob X 2.txt
188 100644 blob X path0/a/b/c/1.txt
189 100644 blob X path1/b/c/1.txt
190 100644 blob X path2/1.txt
191 100644 blob X path3/1.txt
192 100644 blob X path3/2.txt
193 EOF
194 test_output
195 '
196
197 test_expect_success 'ls-tree --abbrev=5' '
198 git ls-tree --abbrev=5 $tree >current &&
199 sed -e "s/ $_x05[0-9a-f]* / X /" <current >check &&
200 cat >expected <<\EOF &&
201 100644 blob X 1.txt
202 100644 blob X 2.txt
203 040000 tree X path0
204 040000 tree X path1
205 040000 tree X path2
206 040000 tree X path3
207 EOF
208 test_cmp expected check
209 '
210
211 for opt in --name-only --name-status
212 do
213 test_expect_success "ls-tree $opt" '
214 git ls-tree $opt $tree >current &&
215 cat >expected <<-\EOF &&
216 1.txt
217 2.txt
218 path0
219 path1
220 path2
221 path3
222 EOF
223 test_output
224 '
225
226 test_expect_success "ls-tree $opt -r" '
227 git ls-tree $opt -r $tree >current &&
228 cat >expected <<-\EOF &&
229 1.txt
230 2.txt
231 path0/a/b/c/1.txt
232 path1/b/c/1.txt
233 path2/1.txt
234 path3/1.txt
235 path3/2.txt
236 EOF
237 test_output
238 '
239 done
240
241 test_done