Fifth batch for 2.14
[git/debian.git] / t / t3007-ls-files-recurse-submodules.sh
blobebb956fd16ccce2536591da021239453da999140
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 'ls-files correctly outputs files in submodule with -z' '
38 lf_to_nul >expect <<-\EOF &&
39 .gitmodules
41 b/b
42 submodule/c
43 EOF
45 git ls-files --recurse-submodules -z >actual &&
46 test_cmp expect actual
49 test_expect_success 'ls-files does not output files not added to a repo' '
50 cat >expect <<-\EOF &&
51 .gitmodules
53 b/b
54 submodule/c
55 EOF
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
64 test_expect_success 'ls-files recurses more than 1 level' '
65 cat >expect <<-\EOF &&
66 .gitmodules
68 b/b
69 submodule/.gitmodules
70 submodule/c
71 submodule/subsub/d
72 EOF
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" &&
80 git submodule absorbgitdirs &&
81 git ls-files --recurse-submodules >actual &&
82 test_cmp expect actual
85 test_expect_success 'ls-files works with GIT_DIR' '
86 cat >expect <<-\EOF &&
87 .gitmodules
89 subsub/d
90 EOF
92 git --git-dir=submodule/.git ls-files --recurse-submodules >actual &&
93 test_cmp expect actual
96 test_expect_success '--recurse-submodules and pathspecs setup' '
97 echo e >submodule/subsub/e.txt &&
98 git -C submodule/subsub add e.txt &&
99 git -C submodule/subsub commit -m "adding e.txt" &&
100 echo f >submodule/f.TXT &&
101 echo g >submodule/g.txt &&
102 git -C submodule add f.TXT g.txt &&
103 git -C submodule commit -m "add f and g" &&
104 echo h >h.txt &&
105 mkdir sib &&
106 echo sib >sib/file &&
107 git add h.txt sib/file &&
108 git commit -m "add h and sib/file" &&
109 git init sub &&
110 echo sub >sub/file &&
111 git -C sub add file &&
112 git -C sub commit -m "add file" &&
113 git submodule add ./sub &&
114 git commit -m "added sub" &&
116 cat >expect <<-\EOF &&
117 .gitmodules
120 h.txt
121 sib/file
122 sub/file
123 submodule/.gitmodules
124 submodule/c
125 submodule/f.TXT
126 submodule/g.txt
127 submodule/subsub/d
128 submodule/subsub/e.txt
131 git ls-files --recurse-submodules >actual &&
132 test_cmp expect actual &&
133 cat actual &&
134 git ls-files --recurse-submodules "*" >actual &&
135 test_cmp expect actual
138 test_expect_success '--recurse-submodules and pathspecs' '
139 cat >expect <<-\EOF &&
140 h.txt
141 submodule/g.txt
142 submodule/subsub/e.txt
145 git ls-files --recurse-submodules "*.txt" >actual &&
146 test_cmp expect actual
149 test_expect_success '--recurse-submodules and pathspecs' '
150 cat >expect <<-\EOF &&
151 h.txt
152 submodule/f.TXT
153 submodule/g.txt
154 submodule/subsub/e.txt
157 git ls-files --recurse-submodules ":(icase)*.txt" >actual &&
158 test_cmp expect actual
161 test_expect_success '--recurse-submodules and pathspecs' '
162 cat >expect <<-\EOF &&
163 h.txt
164 submodule/f.TXT
165 submodule/g.txt
168 git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual &&
169 test_cmp expect actual
172 test_expect_success '--recurse-submodules and pathspecs' '
173 cat >expect <<-\EOF &&
174 sub/file
177 git ls-files --recurse-submodules "sub" >actual &&
178 test_cmp expect actual &&
179 git ls-files --recurse-submodules "sub/" >actual &&
180 test_cmp expect actual &&
181 git ls-files --recurse-submodules "sub/file" >actual &&
182 test_cmp expect actual &&
183 git ls-files --recurse-submodules "su*/file" >actual &&
184 test_cmp expect actual &&
185 git ls-files --recurse-submodules "su?/file" >actual &&
186 test_cmp expect actual
189 test_expect_success '--recurse-submodules and pathspecs' '
190 cat >expect <<-\EOF &&
191 sib/file
192 sub/file
195 git ls-files --recurse-submodules "s??/file" >actual &&
196 test_cmp expect actual &&
197 git ls-files --recurse-submodules "s???file" >actual &&
198 test_cmp expect actual &&
199 git ls-files --recurse-submodules "s*file" >actual &&
200 test_cmp expect actual
203 test_expect_success '--recurse-submodules and relative paths' '
204 # From subdir
205 cat >expect <<-\EOF &&
208 git -C b ls-files --recurse-submodules >actual &&
209 test_cmp expect actual &&
211 # Relative path to top
212 cat >expect <<-\EOF &&
213 ../.gitmodules
214 ../a
216 ../h.txt
217 ../sib/file
218 ../sub/file
219 ../submodule/.gitmodules
220 ../submodule/c
221 ../submodule/f.TXT
222 ../submodule/g.txt
223 ../submodule/subsub/d
224 ../submodule/subsub/e.txt
226 git -C b ls-files --recurse-submodules -- .. >actual &&
227 test_cmp expect actual &&
229 # Relative path to submodule
230 cat >expect <<-\EOF &&
231 ../submodule/.gitmodules
232 ../submodule/c
233 ../submodule/f.TXT
234 ../submodule/g.txt
235 ../submodule/subsub/d
236 ../submodule/subsub/e.txt
238 git -C b ls-files --recurse-submodules -- ../submodule >actual &&
239 test_cmp expect actual
242 test_expect_success '--recurse-submodules does not support --error-unmatch' '
243 test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual &&
244 test_i18ngrep "does not support --error-unmatch" actual
247 test_incompatible_with_recurse_submodules () {
248 test_expect_success "--recurse-submodules and $1 are incompatible" "
249 test_must_fail git ls-files --recurse-submodules $1 2>actual &&
250 test_i18ngrep 'unsupported mode' actual
254 test_incompatible_with_recurse_submodules --deleted
255 test_incompatible_with_recurse_submodules --modified
256 test_incompatible_with_recurse_submodules --others
257 test_incompatible_with_recurse_submodules --stage
258 test_incompatible_with_recurse_submodules --killed
259 test_incompatible_with_recurse_submodules --unmerged
261 test_done