The thirteenth batch
[git.git] / t / t3007-ls-files-recurse-submodules.sh
blobf04bdc8c78b6e852d04ab4b93446248e40459f13
1 #!/bin/sh
3 test_description='Test ls-files recurse-submodules feature
5 This test verifies the recurse-submodules feature correctly lists files from
6 submodules.
9 TEST_PASSES_SANITIZE_LEAK=true
10 . ./test-lib.sh
12 test_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"
26 test_expect_success 'ls-files correctly outputs files in submodule' '
27 cat >expect <<-\EOF &&
28 .gitmodules
30 b/b
31 submodule/c
32 EOF
34 git ls-files --recurse-submodules >actual &&
35 test_cmp expect actual
38 test_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) &&
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
51 git ls-files --stage --recurse-submodules >actual &&
52 test_cmp expect actual
55 test_expect_success 'ls-files correctly outputs files in submodule with -z' '
56 lf_to_nul >expect <<-\EOF &&
57 .gitmodules
59 b/b
60 submodule/c
61 EOF
63 git ls-files --recurse-submodules -z >actual &&
64 test_cmp expect actual
67 test_expect_success 'ls-files does not output files not added to a repo' '
68 cat >expect <<-\EOF &&
69 .gitmodules
71 b/b
72 submodule/c
73 EOF
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
82 test_expect_success 'ls-files recurses more than 1 level' '
83 cat >expect <<-\EOF &&
84 .gitmodules
86 b/b
87 submodule/.gitmodules
88 submodule/c
89 submodule/subsub/d
90 EOF
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" &&
98 git submodule absorbgitdirs &&
99 git ls-files --recurse-submodules >actual &&
100 test_cmp expect actual
103 test_expect_success 'ls-files works with GIT_DIR' '
104 cat >expect <<-\EOF &&
105 .gitmodules
107 subsub/d
110 git --git-dir=submodule/.git ls-files --recurse-submodules >actual &&
111 test_cmp expect actual
114 test_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" &&
134 cat >expect <<-\EOF &&
135 .gitmodules
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
149 git ls-files --recurse-submodules >actual &&
150 test_cmp expect actual &&
151 git ls-files --recurse-submodules "*" >actual &&
152 test_cmp expect actual
155 test_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" &&
160 cat >expect <<-\EOF &&
161 .gitmodules
164 h.txt
165 sib/file
166 sub/file
167 submodule
170 git ls-files --recurse-submodules >actual &&
171 test_cmp expect actual &&
173 git config --bool submodule.submodule.active "true" &&
174 git -C submodule config --bool submodule.subsub.active "false" &&
176 cat >expect <<-\EOF &&
177 .gitmodules
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
190 git ls-files --recurse-submodules >actual &&
191 test_cmp expect actual
194 test_expect_success '--recurse-submodules and pathspecs' '
195 cat >expect <<-\EOF &&
196 h.txt
197 submodule/g.txt
198 submodule/subsub/e.txt
201 git ls-files --recurse-submodules "*.txt" >actual &&
202 test_cmp expect actual
205 test_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
213 git ls-files --recurse-submodules ":(icase)*.txt" >actual &&
214 test_cmp expect actual
217 test_expect_success '--recurse-submodules and pathspecs' '
218 cat >expect <<-\EOF &&
219 h.txt
220 submodule/f.TXT
221 submodule/g.txt
224 git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual &&
225 test_cmp expect actual
228 test_expect_success '--recurse-submodules and pathspecs' '
229 cat >expect <<-\EOF &&
230 sub/file
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
245 test_expect_success '--recurse-submodules and pathspecs' '
246 cat >expect <<-\EOF &&
247 sib/file
248 sub/file
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
259 test_expect_success '--recurse-submodules and relative paths' '
260 # From subdir
261 cat >expect <<-\EOF &&
264 git -C b ls-files --recurse-submodules >actual &&
265 test_cmp expect actual &&
267 # Relative path to top
268 cat >expect <<-\EOF &&
269 ../.gitmodules
270 ../a
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
282 git -C b ls-files --recurse-submodules -- .. >actual &&
283 test_cmp expect actual &&
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
294 git -C b ls-files --recurse-submodules -- ../submodule >actual &&
295 test_cmp expect actual
298 test_expect_success '--recurse-submodules does not support --error-unmatch' '
299 test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual &&
300 test_grep "does not support --error-unmatch" actual
303 test_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
309 test_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" &&
313 test_must_fail git ls-files --recurse-submodules 2>err &&
314 grep "bad boolean config value" err
317 test_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" &&
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" &&
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
336 test_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 &&
339 test_grep 'unsupported mode' actual
343 test_incompatible_with_recurse_submodules --deleted
344 test_incompatible_with_recurse_submodules --modified
345 test_incompatible_with_recurse_submodules --others
346 test_incompatible_with_recurse_submodules --killed
347 test_incompatible_with_recurse_submodules --unmerged
349 test_done