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