]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3101-ls-tree-dirname.sh
Merge branch 'tl/ls-tree-oid-only'
[thirdparty/git.git] / t / t3101-ls-tree-dirname.sh
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_PASSES_SANITIZE_LEAK=true
24 . ./test-lib.sh
25
26 test_expect_success 'setup' '
27 echo 111 >1.txt &&
28 echo 222 >2.txt &&
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 &&
33 mkdir path2 &&
34 echo 111 >path2/1.txt &&
35 mkdir path3 &&
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) &&
41 echo $tree
42 '
43
44 test_output () {
45 sed -e "s/ $OID_REGEX / X /" <current >check &&
46 test_cmp expected check
47 }
48
49 test_expect_success 'ls-tree plain' '
50 git ls-tree $tree >current &&
51 cat >expected <<\EOF &&
52 100644 blob X 1.txt
53 100644 blob X 2.txt
54 040000 tree X path0
55 040000 tree X path1
56 040000 tree X path2
57 040000 tree X path3
58 EOF
59 test_output
60 '
61
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 &&
66 100644 blob X 1.txt
67 100644 blob X 2.txt
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
73 EOF
74 test_output
75 '
76
77 test_expect_success 'ls-tree filter 1.txt' '
78 git ls-tree $tree 1.txt >current &&
79 cat >expected <<\EOF &&
80 100644 blob X 1.txt
81 EOF
82 test_output
83 '
84
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
89 EOF
90 test_output
91 '
92
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 &&
97 100644 blob X 1.txt
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
102 EOF
103 test_output
104 '
105
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
114 040000 tree X path2
115 040000 tree X path3
116 EOF
117 test_output
118 '
119
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 &&
126 100644 blob X 1.txt
127 100644 blob X path3/1.txt
128 100644 blob X path3/2.txt
129 EOF
130 test_output
131 '
132
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 &&
136 >expected &&
137 test_output
138 '
139
140 test_expect_success 'ls-tree filter is leading path match' '
141 git ls-tree $tree pa path3/a >current &&
142 >expected &&
143 test_output
144 '
145
146 test_expect_success 'ls-tree --full-name' '
147 (
148 cd path0 &&
149 git ls-tree --full-name $tree a
150 ) >current &&
151 cat >expected <<\EOF &&
152 040000 tree X path0/a
153 EOF
154 test_output
155 '
156
157 test_expect_success 'ls-tree --full-tree' '
158 (
159 cd path1/b/c &&
160 git ls-tree --full-tree $tree
161 ) >current &&
162 cat >expected <<\EOF &&
163 100644 blob X 1.txt
164 100644 blob X 2.txt
165 040000 tree X path0
166 040000 tree X path1
167 040000 tree X path2
168 040000 tree X path3
169 EOF
170 test_output
171 '
172
173 test_expect_success 'ls-tree --full-tree -r' '
174 (
175 cd path3/ &&
176 git ls-tree --full-tree -r $tree
177 ) >current &&
178 cat >expected <<\EOF &&
179 100644 blob X 1.txt
180 100644 blob X 2.txt
181 100644 blob X path0/a/b/c/1.txt
182 100644 blob X path1/b/c/1.txt
183 100644 blob X path2/1.txt
184 100644 blob X path3/1.txt
185 100644 blob X path3/2.txt
186 EOF
187 test_output
188 '
189
190 test_expect_success 'ls-tree --abbrev=5' '
191 git ls-tree --abbrev=5 $tree >current &&
192 sed -e "s/ $_x05[0-9a-f]* / X /" <current >check &&
193 cat >expected <<\EOF &&
194 100644 blob X 1.txt
195 100644 blob X 2.txt
196 040000 tree X path0
197 040000 tree X path1
198 040000 tree X path2
199 040000 tree X path3
200 EOF
201 test_cmp expected check
202 '
203
204 for opt in --name-only --name-status
205 do
206 test_expect_success "ls-tree $opt" '
207 git ls-tree $opt $tree >current &&
208 cat >expected <<-\EOF &&
209 1.txt
210 2.txt
211 path0
212 path1
213 path2
214 path3
215 EOF
216 test_output
217 '
218
219 test_expect_success "ls-tree $opt -r" '
220 git ls-tree $opt -r $tree >current &&
221 cat >expected <<-\EOF &&
222 1.txt
223 2.txt
224 path0/a/b/c/1.txt
225 path1/b/c/1.txt
226 path2/1.txt
227 path3/1.txt
228 path3/2.txt
229 EOF
230 test_output
231 '
232 done
233
234 test_done