3 test_description
='Test ls-files recurse-submodules feature
5 This test verifies the recurse-submodules feature correctly lists files from
9 TEST_PASSES_SANITIZE_LEAK
=true
12 test_expect_success
'setup directory structure and submodules' '
17 git commit -m "add a and b" &&
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 &&
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) &&
45 100644 $GITMODULES_HASH 0 .gitmodules
48 100644 $C_HASH 0 submodule/c
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 &&
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 &&
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 &&
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 &&
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" &&
124 echo sib >sib/file &&
125 git add h.txt sib/file &&
126 git commit -m "add h and sib/file" &&
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 &&
141 submodule/.gitmodules
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 &&
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 &&
183 submodule/.gitmodules
190 git ls-files --recurse-submodules >actual &&
191 test_cmp expect actual
194 test_expect_success
'--recurse-submodules and pathspecs' '
195 cat >expect <<-\EOF &&
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 &&
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 &&
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 &&
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 &&
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' '
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 &&
275 ../submodule/.gitmodules
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
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