Merge branch 'bw/attr-pathspec'
[git.git] / t / t3007-ls-files-recurse-submodules.sh
blob4cf6ccf5a8eadac4cc0ebb8b3091f1f3befa73a9
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 ls-files --recurse-submodules >actual &&
81 test_cmp expect actual
84 test_expect_success '--recurse-submodules and pathspecs setup' '
85 echo e >submodule/subsub/e.txt &&
86 git -C submodule/subsub add e.txt &&
87 git -C submodule/subsub commit -m "adding e.txt" &&
88 echo f >submodule/f.TXT &&
89 echo g >submodule/g.txt &&
90 git -C submodule add f.TXT g.txt &&
91 git -C submodule commit -m "add f and g" &&
92 echo h >h.txt &&
93 mkdir sib &&
94 echo sib >sib/file &&
95 git add h.txt sib/file &&
96 git commit -m "add h and sib/file" &&
97 git init sub &&
98 echo sub >sub/file &&
99 git -C sub add file &&
100 git -C sub commit -m "add file" &&
101 git submodule add ./sub &&
102 git commit -m "added sub" &&
104 cat >expect <<-\EOF &&
105 .gitmodules
108 h.txt
109 sib/file
110 sub/file
111 submodule/.gitmodules
112 submodule/c
113 submodule/f.TXT
114 submodule/g.txt
115 submodule/subsub/d
116 submodule/subsub/e.txt
119 git ls-files --recurse-submodules >actual &&
120 test_cmp expect actual &&
121 cat actual &&
122 git ls-files --recurse-submodules "*" >actual &&
123 test_cmp expect actual
126 test_expect_success '--recurse-submodules and pathspecs' '
127 cat >expect <<-\EOF &&
128 h.txt
129 submodule/g.txt
130 submodule/subsub/e.txt
133 git ls-files --recurse-submodules "*.txt" >actual &&
134 test_cmp expect actual
137 test_expect_success '--recurse-submodules and pathspecs' '
138 cat >expect <<-\EOF &&
139 h.txt
140 submodule/f.TXT
141 submodule/g.txt
142 submodule/subsub/e.txt
145 git ls-files --recurse-submodules ":(icase)*.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
156 git ls-files --recurse-submodules ":(icase)*.txt" ":(exclude)submodule/subsub/*" >actual &&
157 test_cmp expect actual
160 test_expect_success '--recurse-submodules and pathspecs' '
161 cat >expect <<-\EOF &&
162 sub/file
165 git ls-files --recurse-submodules "sub" >actual &&
166 test_cmp expect actual &&
167 git ls-files --recurse-submodules "sub/" >actual &&
168 test_cmp expect actual &&
169 git ls-files --recurse-submodules "sub/file" >actual &&
170 test_cmp expect actual &&
171 git ls-files --recurse-submodules "su*/file" >actual &&
172 test_cmp expect actual &&
173 git ls-files --recurse-submodules "su?/file" >actual &&
174 test_cmp expect actual
177 test_expect_success '--recurse-submodules and pathspecs' '
178 cat >expect <<-\EOF &&
179 sib/file
180 sub/file
183 git ls-files --recurse-submodules "s??/file" >actual &&
184 test_cmp expect actual &&
185 git ls-files --recurse-submodules "s???file" >actual &&
186 test_cmp expect actual &&
187 git ls-files --recurse-submodules "s*file" >actual &&
188 test_cmp expect actual
191 test_expect_success '--recurse-submodules and relative paths' '
192 # From subdir
193 cat >expect <<-\EOF &&
196 git -C b ls-files --recurse-submodules >actual &&
197 test_cmp expect actual &&
199 # Relative path to top
200 cat >expect <<-\EOF &&
201 ../.gitmodules
202 ../a
204 ../h.txt
205 ../sib/file
206 ../sub/file
207 ../submodule/.gitmodules
208 ../submodule/c
209 ../submodule/f.TXT
210 ../submodule/g.txt
211 ../submodule/subsub/d
212 ../submodule/subsub/e.txt
214 git -C b ls-files --recurse-submodules -- .. >actual &&
215 test_cmp expect actual &&
217 # Relative path to submodule
218 cat >expect <<-\EOF &&
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 -- ../submodule >actual &&
227 test_cmp expect actual
230 test_expect_success '--recurse-submodules does not support --error-unmatch' '
231 test_must_fail git ls-files --recurse-submodules --error-unmatch 2>actual &&
232 test_i18ngrep "does not support --error-unmatch" actual
235 test_incompatible_with_recurse_submodules () {
236 test_expect_success "--recurse-submodules and $1 are incompatible" "
237 test_must_fail git ls-files --recurse-submodules $1 2>actual &&
238 test_i18ngrep 'unsupported mode' actual
242 test_incompatible_with_recurse_submodules --deleted
243 test_incompatible_with_recurse_submodules --modified
244 test_incompatible_with_recurse_submodules --others
245 test_incompatible_with_recurse_submodules --stage
246 test_incompatible_with_recurse_submodules --killed
247 test_incompatible_with_recurse_submodules --unmerged
249 test_done