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