]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3007-ls-files-recurse-submodules.sh
ls-files: fix recurse-submodules with nested submodules
[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
9. ./test-lib.sh
10
11test_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"
23'
24
25test_expect_success 'ls-files correctly outputs files in submodule' '
26 cat >expect <<-\EOF &&
27 .gitmodules
28 a
29 b/b
30 submodule/c
31 EOF
32
33 git ls-files --recurse-submodules >actual &&
34 test_cmp expect actual
35'
36
07c01b9f
BW
37test_expect_success 'ls-files correctly outputs files in submodule with -z' '
38 lf_to_nul >expect <<-\EOF &&
39 .gitmodules
40 a
41 b/b
42 submodule/c
43 EOF
44
45 git ls-files --recurse-submodules -z >actual &&
46 test_cmp expect actual
47'
48
e77aa336
BW
49test_expect_success 'ls-files does not output files not added to a repo' '
50 cat >expect <<-\EOF &&
51 .gitmodules
52 a
53 b/b
54 submodule/c
55 EOF
56
57 echo a >not_added &&
58 echo b >b/not_added &&
59 echo c >submodule/not_added &&
60 git ls-files --recurse-submodules >actual &&
61 test_cmp expect actual
62'
63
64test_expect_success 'ls-files recurses more than 1 level' '
65 cat >expect <<-\EOF &&
66 .gitmodules
67 a
68 b/b
69 submodule/.gitmodules
70 submodule/c
71 submodule/subsub/d
72 EOF
73
74 git init submodule/subsub &&
75 echo d >submodule/subsub/d &&
76 git -C submodule/subsub add d &&
77 git -C submodule/subsub commit -m "add d" &&
78 git -C submodule submodule add ./subsub &&
79 git -C submodule commit -m "added subsub" &&
2e5d6503 80 git submodule absorbgitdirs &&
e77aa336
BW
81 git ls-files --recurse-submodules >actual &&
82 test_cmp expect actual
83'
84
75a6315f
BW
85test_expect_success '--recurse-submodules and pathspecs setup' '
86 echo e >submodule/subsub/e.txt &&
87 git -C submodule/subsub add e.txt &&
88 git -C submodule/subsub commit -m "adding e.txt" &&
89 echo f >submodule/f.TXT &&
90 echo g >submodule/g.txt &&
91 git -C submodule add f.TXT g.txt &&
92 git -C submodule commit -m "add f and g" &&
93 echo h >h.txt &&
94 mkdir sib &&
95 echo sib >sib/file &&
96 git add h.txt sib/file &&
97 git commit -m "add h and sib/file" &&
98 git init sub &&
99 echo sub >sub/file &&
100 git -C sub add file &&
101 git -C sub commit -m "add file" &&
102 git submodule add ./sub &&
103 git commit -m "added sub" &&
104
105 cat >expect <<-\EOF &&
106 .gitmodules
107 a
108 b/b
109 h.txt
110 sib/file
111 sub/file
112 submodule/.gitmodules
113 submodule/c
114 submodule/f.TXT
115 submodule/g.txt
116 submodule/subsub/d
117 submodule/subsub/e.txt
118 EOF
119
120 git ls-files --recurse-submodules >actual &&
121 test_cmp expect actual &&
122 cat actual &&
123 git ls-files --recurse-submodules "*" >actual &&
124 test_cmp expect actual
125'
126
127test_expect_success '--recurse-submodules and pathspecs' '
128 cat >expect <<-\EOF &&
129 h.txt
130 submodule/g.txt
131 submodule/subsub/e.txt
132 EOF
133
134 git ls-files --recurse-submodules "*.txt" >actual &&
135 test_cmp expect actual
136'
137
138test_expect_success '--recurse-submodules and pathspecs' '
139 cat >expect <<-\EOF &&
140 h.txt
141 submodule/f.TXT
142 submodule/g.txt
143 submodule/subsub/e.txt
144 EOF
145
146 git ls-files --recurse-submodules ":(icase)*.txt" >actual &&
147 test_cmp expect actual
148'
149
150test_expect_success '--recurse-submodules and pathspecs' '
151 cat >expect <<-\EOF &&
152 h.txt
153 submodule/f.TXT
154 submodule/g.txt
155 EOF
156
157 git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual &&
158 test_cmp expect actual
159'
160
161test_expect_success '--recurse-submodules and pathspecs' '
162 cat >expect <<-\EOF &&
163 sub/file
164 EOF
165
166 git ls-files --recurse-submodules "sub" >actual &&
167 test_cmp expect actual &&
168 git ls-files --recurse-submodules "sub/" >actual &&
169 test_cmp expect actual &&
170 git ls-files --recurse-submodules "sub/file" >actual &&
171 test_cmp expect actual &&
172 git ls-files --recurse-submodules "su*/file" >actual &&
173 test_cmp expect actual &&
174 git ls-files --recurse-submodules "su?/file" >actual &&
175 test_cmp expect actual
176'
177
178test_expect_success '--recurse-submodules and pathspecs' '
179 cat >expect <<-\EOF &&
180 sib/file
181 sub/file
182 EOF
183
184 git ls-files --recurse-submodules "s??/file" >actual &&
185 test_cmp expect actual &&
186 git ls-files --recurse-submodules "s???file" >actual &&
187 test_cmp expect actual &&
188 git ls-files --recurse-submodules "s*file" >actual &&
189 test_cmp expect actual
e77aa336
BW
190'
191
b2dfeb7c
BW
192test_expect_success '--recurse-submodules and relative paths' '
193 # From subdir
194 cat >expect <<-\EOF &&
195 b
196 EOF
197 git -C b ls-files --recurse-submodules >actual &&
198 test_cmp expect actual &&
199
200 # Relative path to top
201 cat >expect <<-\EOF &&
202 ../.gitmodules
203 ../a
204 b
205 ../h.txt
206 ../sib/file
207 ../sub/file
208 ../submodule/.gitmodules
209 ../submodule/c
210 ../submodule/f.TXT
211 ../submodule/g.txt
212 ../submodule/subsub/d
213 ../submodule/subsub/e.txt
214 EOF
215 git -C b ls-files --recurse-submodules -- .. >actual &&
216 test_cmp expect actual &&
217
218 # Relative path to submodule
219 cat >expect <<-\EOF &&
220 ../submodule/.gitmodules
221 ../submodule/c
222 ../submodule/f.TXT
223 ../submodule/g.txt
224 ../submodule/subsub/d
225 ../submodule/subsub/e.txt
226 EOF
227 git -C b ls-files --recurse-submodules -- ../submodule >actual &&
228 test_cmp expect actual
229'
230
e77aa336
BW
231test_expect_success '--recurse-submodules does not support --error-unmatch' '
232 test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual &&
233 test_i18ngrep "does not support --error-unmatch" actual
234'
235
236test_incompatible_with_recurse_submodules () {
237 test_expect_success "--recurse-submodules and $1 are incompatible" "
238 test_must_fail git ls-files --recurse-submodules $1 2>actual &&
239 test_i18ngrep 'unsupported mode' actual
240 "
241}
242
e77aa336
BW
243test_incompatible_with_recurse_submodules --deleted
244test_incompatible_with_recurse_submodules --modified
245test_incompatible_with_recurse_submodules --others
246test_incompatible_with_recurse_submodules --stage
247test_incompatible_with_recurse_submodules --killed
248test_incompatible_with_recurse_submodules --unmerged
e77aa336
BW
249
250test_done