Git 2.45
[git/gitster.git] / t / t3007-ls-files-recurse-submodules.sh
blob61771eec830c0688587588ee0a334282effdb1bb
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-lib.sh
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"
25 test_expect_success 'ls-files correctly outputs files in submodule' '
26 cat >expect <<-\EOF &&
27 .gitmodules
29 b/b
30 submodule/c
31 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) &&
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
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 &&
56 .gitmodules
58 b/b
59 submodule/c
60 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 &&
68 .gitmodules
70 b/b
71 submodule/c
72 EOF
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
81 test_expect_success 'ls-files recurses more than 1 level' '
82 cat >expect <<-\EOF &&
83 .gitmodules
85 b/b
86 submodule/.gitmodules
87 submodule/c
88 submodule/subsub/d
89 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 &&
104 .gitmodules
106 subsub/d
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" &&
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" &&
133 cat >expect <<-\EOF &&
134 .gitmodules
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
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 &&
160 .gitmodules
163 h.txt
164 sib/file
165 sub/file
166 submodule
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 &&
176 .gitmodules
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
189 git ls-files --recurse-submodules >actual &&
190 test_cmp expect actual
193 test_expect_success '--recurse-submodules and pathspecs' '
194 cat >expect <<-\EOF &&
195 h.txt
196 submodule/g.txt
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 &&
206 h.txt
207 submodule/f.TXT
208 submodule/g.txt
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 &&
218 h.txt
219 submodule/f.TXT
220 submodule/g.txt
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 &&
229 sub/file
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 &&
246 sib/file
247 sub/file
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' '
259 # From subdir
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 &&
268 ../.gitmodules
269 ../a
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
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
287 ../submodule/c
288 ../submodule/f.TXT
289 ../submodule/g.txt
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
348 test_done