3 test_description
='Test ls-files recurse-submodules feature
5 This test verifies the recurse-submodules feature correctly lists files from
11 test_expect_success
'setup directory structure and submodules' '
16 git commit -m "add a and b" &&
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"
25 test_expect_success
'ls-files correctly outputs files in submodule' '
26 cat >expect <<-\EOF &&
33 git ls-files --recurse-submodules >actual &&
34 test_cmp expect actual
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) &&
44 100644 $GITMODULES_HASH 0 .gitmodules
47 100644 $C_HASH 0 submodule/c
50 git ls-files --stage --recurse-submodules >actual &&
51 test_cmp expect actual
54 test_expect_success
'ls-files correctly outputs files in submodule with -z' '
55 lf_to_nul >expect <<-\EOF &&
62 git ls-files --recurse-submodules -z >actual &&
63 test_cmp expect actual
66 test_expect_success
'ls-files does not output files not added to a repo' '
67 cat >expect <<-\EOF &&
75 echo b >b/not_added &&
76 echo c >submodule/not_added &&
77 git ls-files --recurse-submodules >actual &&
78 test_cmp expect actual
81 test_expect_success
'ls-files recurses more than 1 level' '
82 cat >expect <<-\EOF &&
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" &&
97 git submodule absorbgitdirs &&
98 git ls-files --recurse-submodules >actual &&
99 test_cmp expect actual
102 test_expect_success
'ls-files works with GIT_DIR' '
103 cat >expect <<-\EOF &&
109 git --git-dir=submodule/.git ls-files --recurse-submodules >actual &&
110 test_cmp expect actual
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" &&
123 echo sib >sib/file &&
124 git add h.txt sib/file &&
125 git commit -m "add h and sib/file" &&
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" &&
133 cat >expect <<-\EOF &&
140 submodule/.gitmodules
145 submodule/subsub/e.txt
148 git ls-files --recurse-submodules >actual &&
149 test_cmp expect actual &&
150 git ls-files --recurse-submodules "*" >actual &&
151 test_cmp expect actual
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" &&
159 cat >expect <<-\EOF &&
169 git ls-files --recurse-submodules >actual &&
170 test_cmp expect actual &&
172 git config --bool submodule.submodule.active "true" &&
173 git -C submodule config --bool submodule.subsub.active "false" &&
175 cat >expect <<-\EOF &&
182 submodule/.gitmodules
189 git ls-files --recurse-submodules >actual &&
190 test_cmp expect actual
193 test_expect_success
'--recurse-submodules and pathspecs' '
194 cat >expect <<-\EOF &&
197 submodule/subsub/e.txt
200 git ls-files --recurse-submodules "*.txt" >actual &&
201 test_cmp expect actual
204 test_expect_success
'--recurse-submodules and pathspecs' '
205 cat >expect <<-\EOF &&
209 submodule/subsub/e.txt
212 git ls-files --recurse-submodules ":(icase)*.txt" >actual &&
213 test_cmp expect actual
216 test_expect_success
'--recurse-submodules and pathspecs' '
217 cat >expect <<-\EOF &&
223 git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual &&
224 test_cmp expect actual
227 test_expect_success
'--recurse-submodules and pathspecs' '
228 cat >expect <<-\EOF &&
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
244 test_expect_success
'--recurse-submodules and pathspecs' '
245 cat >expect <<-\EOF &&
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
258 test_expect_success
'--recurse-submodules and relative paths' '
260 cat >expect <<-\EOF &&
263 git -C b ls-files --recurse-submodules >actual &&
264 test_cmp expect actual &&
266 # Relative path to top
267 cat >expect <<-\EOF &&
274 ../submodule/.gitmodules
278 ../submodule/subsub/d
279 ../submodule/subsub/e.txt
281 git -C b ls-files --recurse-submodules -- .. >actual &&
282 test_cmp expect actual &&
284 # Relative path to submodule
285 cat >expect <<-\EOF &&
286 ../submodule/.gitmodules
290 ../submodule/subsub/d
291 ../submodule/subsub/e.txt
293 git -C b ls-files --recurse-submodules -- ../submodule >actual &&
294 test_cmp expect actual
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_grep "does not support --error-unmatch" actual
302 test_expect_success
'--recurse-submodules parses submodule repo config' '
303 test_config -C submodule index.sparse "invalid non-boolean value" &&
304 test_must_fail git ls-files --recurse-submodules 2>err &&
305 grep "bad boolean config value" err
308 test_expect_success
'--recurse-submodules parses submodule worktree config' '
309 test_config -C submodule extensions.worktreeConfig true &&
310 test_config -C submodule --worktree index.sparse "invalid non-boolean value" &&
312 test_must_fail git ls-files --recurse-submodules 2>err &&
313 grep "bad boolean config value" err
316 test_expect_success
'--recurse-submodules submodules ignore super project worktreeConfig extension' '
317 # Enable worktree config in both super project & submodule, set an
318 # invalid config in the submodule worktree config
319 test_config extensions.worktreeConfig true &&
320 test_config -C submodule extensions.worktreeConfig true &&
321 test_config -C submodule --worktree index.sparse "invalid non-boolean value" &&
323 # Now, disable the worktree config in the submodule. Note that we need
324 # to manually re-enable extensions.worktreeConfig when the test is
325 # finished, otherwise the test_unconfig of index.sparse will not work.
326 test_unconfig -C submodule extensions.worktreeConfig &&
327 test_when_finished "git -C submodule config extensions.worktreeConfig true" &&
329 # With extensions.worktreeConfig disabled in the submodule, the invalid
330 # worktree config is not picked up.
331 git ls-files --recurse-submodules 2>err &&
332 ! grep "bad boolean config value" err
335 test_incompatible_with_recurse_submodules
() {
336 test_expect_success
"--recurse-submodules and $1 are incompatible" "
337 test_must_fail git ls-files --recurse-submodules $1 2>actual &&
338 test_grep 'unsupported mode' actual
342 test_incompatible_with_recurse_submodules
--deleted
343 test_incompatible_with_recurse_submodules
--modified
344 test_incompatible_with_recurse_submodules
--others
345 test_incompatible_with_recurse_submodules
--killed
346 test_incompatible_with_recurse_submodules
--unmerged