]>
Commit | Line | Data |
---|---|---|
e77aa336 BW |
1 | #!/bin/sh |
2 | ||
3 | test_description='Test ls-files recurse-submodules feature | |
4 | ||
5 | This test verifies the recurse-submodules feature correctly lists files from | |
6 | submodules. | |
7 | ' | |
8 | ||
9 | . ./test-lib.sh | |
10 | ||
11 | test_expect_success 'setup directory structure and submodules' ' | |
12 | echo a >a && | |
13 | mkdir b && | |
14 | echo b >b/b && | |
15 | git add a b && | |
16 | git commit -m "add a and b" && | |
17 | git init submodule && | |
18 | echo c >submodule/c && | |
19 | git -C submodule add c && | |
20 | git -C submodule commit -m "add c" && | |
21 | git submodule add ./submodule && | |
22 | git commit -m "added submodule" | |
23 | ' | |
24 | ||
25 | test_expect_success 'ls-files correctly outputs files in submodule' ' | |
26 | cat >expect <<-\EOF && | |
27 | .gitmodules | |
28 | a | |
29 | b/b | |
30 | submodule/c | |
31 | EOF | |
32 | ||
33 | git ls-files --recurse-submodules >actual && | |
34 | test_cmp expect actual | |
35 | ' | |
36 | ||
290eada0 JT |
37 | test_expect_success '--stage' ' |
38 | GITMODULES_HASH=$(git rev-parse HEAD:.gitmodules) && | |
39 | A_HASH=$(git rev-parse HEAD:a) && | |
40 | B_HASH=$(git rev-parse HEAD:b/b) && | |
41 | C_HASH=$(git -C submodule rev-parse HEAD:c) && | |
42 | ||
43 | cat >expect <<-EOF && | |
44 | 100644 $GITMODULES_HASH 0 .gitmodules | |
45 | 100644 $A_HASH 0 a | |
46 | 100644 $B_HASH 0 b/b | |
47 | 100644 $C_HASH 0 submodule/c | |
48 | EOF | |
49 | ||
50 | git ls-files --stage --recurse-submodules >actual && | |
51 | test_cmp expect actual | |
52 | ' | |
53 | ||
07c01b9f BW |
54 | test_expect_success 'ls-files correctly outputs files in submodule with -z' ' |
55 | lf_to_nul >expect <<-\EOF && | |
56 | .gitmodules | |
57 | a | |
58 | b/b | |
59 | submodule/c | |
60 | EOF | |
61 | ||
62 | git ls-files --recurse-submodules -z >actual && | |
63 | test_cmp expect actual | |
64 | ' | |
65 | ||
e77aa336 BW |
66 | test_expect_success 'ls-files does not output files not added to a repo' ' |
67 | cat >expect <<-\EOF && | |
68 | .gitmodules | |
69 | a | |
70 | b/b | |
71 | submodule/c | |
72 | EOF | |
73 | ||
74 | echo a >not_added && | |
75 | echo b >b/not_added && | |
76 | echo c >submodule/not_added && | |
77 | git ls-files --recurse-submodules >actual && | |
78 | test_cmp expect actual | |
79 | ' | |
80 | ||
81 | test_expect_success 'ls-files recurses more than 1 level' ' | |
82 | cat >expect <<-\EOF && | |
83 | .gitmodules | |
84 | a | |
85 | b/b | |
86 | submodule/.gitmodules | |
87 | submodule/c | |
88 | submodule/subsub/d | |
89 | EOF | |
90 | ||
91 | git init submodule/subsub && | |
92 | echo d >submodule/subsub/d && | |
93 | git -C submodule/subsub add d && | |
94 | git -C submodule/subsub commit -m "add d" && | |
95 | git -C submodule submodule add ./subsub && | |
96 | git -C submodule commit -m "added subsub" && | |
2e5d6503 | 97 | git submodule absorbgitdirs && |
e77aa336 BW |
98 | git ls-files --recurse-submodules >actual && |
99 | test_cmp expect actual | |
100 | ' | |
101 | ||
2cfe66a8 JK |
102 | test_expect_success 'ls-files works with GIT_DIR' ' |
103 | cat >expect <<-\EOF && | |
104 | .gitmodules | |
105 | c | |
106 | subsub/d | |
107 | EOF | |
108 | ||
109 | git --git-dir=submodule/.git ls-files --recurse-submodules >actual && | |
110 | test_cmp expect actual | |
111 | ' | |
112 | ||
75a6315f BW |
113 | test_expect_success '--recurse-submodules and pathspecs setup' ' |
114 | echo e >submodule/subsub/e.txt && | |
115 | git -C submodule/subsub add e.txt && | |
116 | git -C submodule/subsub commit -m "adding e.txt" && | |
117 | echo f >submodule/f.TXT && | |
118 | echo g >submodule/g.txt && | |
119 | git -C submodule add f.TXT g.txt && | |
120 | git -C submodule commit -m "add f and g" && | |
121 | echo h >h.txt && | |
122 | mkdir sib && | |
123 | echo sib >sib/file && | |
124 | git add h.txt sib/file && | |
125 | git commit -m "add h and sib/file" && | |
126 | git init sub && | |
127 | echo sub >sub/file && | |
128 | git -C sub add file && | |
129 | git -C sub commit -m "add file" && | |
130 | git submodule add ./sub && | |
131 | git commit -m "added sub" && | |
132 | ||
133 | cat >expect <<-\EOF && | |
134 | .gitmodules | |
135 | a | |
136 | b/b | |
137 | h.txt | |
138 | sib/file | |
139 | sub/file | |
140 | submodule/.gitmodules | |
141 | submodule/c | |
142 | submodule/f.TXT | |
143 | submodule/g.txt | |
144 | submodule/subsub/d | |
145 | submodule/subsub/e.txt | |
146 | EOF | |
147 | ||
148 | git ls-files --recurse-submodules >actual && | |
149 | test_cmp expect actual && | |
75a6315f BW |
150 | git ls-files --recurse-submodules "*" >actual && |
151 | test_cmp expect actual | |
152 | ' | |
153 | ||
188dce13 BW |
154 | test_expect_success 'inactive submodule' ' |
155 | test_when_finished "git config --bool submodule.submodule.active true" && | |
156 | test_when_finished "git -C submodule config --bool submodule.subsub.active true" && | |
157 | git config --bool submodule.submodule.active "false" && | |
158 | ||
159 | cat >expect <<-\EOF && | |
160 | .gitmodules | |
161 | a | |
162 | b/b | |
163 | h.txt | |
164 | sib/file | |
165 | sub/file | |
166 | submodule | |
167 | EOF | |
168 | ||
169 | git ls-files --recurse-submodules >actual && | |
170 | test_cmp expect actual && | |
171 | ||
172 | git config --bool submodule.submodule.active "true" && | |
173 | git -C submodule config --bool submodule.subsub.active "false" && | |
174 | ||
175 | cat >expect <<-\EOF && | |
176 | .gitmodules | |
177 | a | |
178 | b/b | |
179 | h.txt | |
180 | sib/file | |
181 | sub/file | |
182 | submodule/.gitmodules | |
183 | submodule/c | |
184 | submodule/f.TXT | |
185 | submodule/g.txt | |
186 | submodule/subsub | |
187 | EOF | |
188 | ||
189 | git ls-files --recurse-submodules >actual && | |
190 | test_cmp expect actual | |
191 | ' | |
192 | ||
75a6315f BW |
193 | test_expect_success '--recurse-submodules and pathspecs' ' |
194 | cat >expect <<-\EOF && | |
195 | h.txt | |
196 | submodule/g.txt | |
197 | submodule/subsub/e.txt | |
198 | EOF | |
199 | ||
200 | git ls-files --recurse-submodules "*.txt" >actual && | |
201 | test_cmp expect actual | |
202 | ' | |
203 | ||
204 | test_expect_success '--recurse-submodules and pathspecs' ' | |
205 | cat >expect <<-\EOF && | |
206 | h.txt | |
207 | submodule/f.TXT | |
208 | submodule/g.txt | |
209 | submodule/subsub/e.txt | |
210 | EOF | |
211 | ||
212 | git ls-files --recurse-submodules ":(icase)*.txt" >actual && | |
213 | test_cmp expect actual | |
214 | ' | |
215 | ||
216 | test_expect_success '--recurse-submodules and pathspecs' ' | |
217 | cat >expect <<-\EOF && | |
218 | h.txt | |
219 | submodule/f.TXT | |
220 | submodule/g.txt | |
221 | EOF | |
222 | ||
223 | git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual && | |
224 | test_cmp expect actual | |
225 | ' | |
226 | ||
227 | test_expect_success '--recurse-submodules and pathspecs' ' | |
228 | cat >expect <<-\EOF && | |
229 | sub/file | |
230 | EOF | |
231 | ||
232 | git ls-files --recurse-submodules "sub" >actual && | |
233 | test_cmp expect actual && | |
234 | git ls-files --recurse-submodules "sub/" >actual && | |
235 | test_cmp expect actual && | |
236 | git ls-files --recurse-submodules "sub/file" >actual && | |
237 | test_cmp expect actual && | |
238 | git ls-files --recurse-submodules "su*/file" >actual && | |
239 | test_cmp expect actual && | |
240 | git ls-files --recurse-submodules "su?/file" >actual && | |
241 | test_cmp expect actual | |
242 | ' | |
243 | ||
244 | test_expect_success '--recurse-submodules and pathspecs' ' | |
245 | cat >expect <<-\EOF && | |
246 | sib/file | |
247 | sub/file | |
248 | EOF | |
249 | ||
250 | git ls-files --recurse-submodules "s??/file" >actual && | |
251 | test_cmp expect actual && | |
252 | git ls-files --recurse-submodules "s???file" >actual && | |
253 | test_cmp expect actual && | |
254 | git ls-files --recurse-submodules "s*file" >actual && | |
255 | test_cmp expect actual | |
e77aa336 BW |
256 | ' |
257 | ||
b2dfeb7c BW |
258 | test_expect_success '--recurse-submodules and relative paths' ' |
259 | # From subdir | |
260 | cat >expect <<-\EOF && | |
261 | b | |
262 | EOF | |
263 | git -C b ls-files --recurse-submodules >actual && | |
264 | test_cmp expect actual && | |
265 | ||
266 | # Relative path to top | |
267 | cat >expect <<-\EOF && | |
268 | ../.gitmodules | |
269 | ../a | |
270 | b | |
271 | ../h.txt | |
272 | ../sib/file | |
273 | ../sub/file | |
274 | ../submodule/.gitmodules | |
275 | ../submodule/c | |
276 | ../submodule/f.TXT | |
277 | ../submodule/g.txt | |
278 | ../submodule/subsub/d | |
279 | ../submodule/subsub/e.txt | |
280 | EOF | |
281 | git -C b ls-files --recurse-submodules -- .. >actual && | |
282 | test_cmp expect actual && | |
283 | ||
284 | # Relative path to submodule | |
285 | cat >expect <<-\EOF && | |
286 | ../submodule/.gitmodules | |
287 | ../submodule/c | |
288 | ../submodule/f.TXT | |
289 | ../submodule/g.txt | |
290 | ../submodule/subsub/d | |
291 | ../submodule/subsub/e.txt | |
292 | EOF | |
293 | git -C b ls-files --recurse-submodules -- ../submodule >actual && | |
294 | test_cmp expect actual | |
295 | ' | |
296 | ||
e77aa336 BW |
297 | test_expect_success '--recurse-submodules does not support --error-unmatch' ' |
298 | test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual && | |
299 | test_i18ngrep "does not support --error-unmatch" actual | |
300 | ' | |
301 | ||
302 | test_incompatible_with_recurse_submodules () { | |
303 | test_expect_success "--recurse-submodules and $1 are incompatible" " | |
304 | test_must_fail git ls-files --recurse-submodules $1 2>actual && | |
305 | test_i18ngrep 'unsupported mode' actual | |
306 | " | |
307 | } | |
308 | ||
e77aa336 BW |
309 | test_incompatible_with_recurse_submodules --deleted |
310 | test_incompatible_with_recurse_submodules --modified | |
311 | test_incompatible_with_recurse_submodules --others | |
e77aa336 BW |
312 | test_incompatible_with_recurse_submodules --killed |
313 | test_incompatible_with_recurse_submodules --unmerged | |
e77aa336 BW |
314 | |
315 | test_done |