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