]>
Commit | Line | Data |
---|---|---|
f87f9497 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git ls-files --others --exclude |
f87f9497 | 7 | |
5be60078 | 8 | This test runs git ls-files --others and tests --exclude patterns. |
f87f9497 JH |
9 | ' |
10 | ||
11 | . ./test-lib.sh | |
12 | ||
13 | rm -fr one three | |
14 | for dir in . one one/two three | |
15 | do | |
16 | mkdir -p $dir && | |
1df092d2 | 17 | for i in 1 2 3 4 5 6 7 8 |
f87f9497 JH |
18 | do |
19 | >$dir/a.$i | |
20 | done | |
21 | done | |
dd482eea FAG |
22 | >"#ignore1" |
23 | >"#ignore2" | |
24 | >"#hidden" | |
f87f9497 JH |
25 | |
26 | cat >expect <<EOF | |
27 | a.2 | |
28 | a.4 | |
29 | a.5 | |
1df092d2 | 30 | a.8 |
f87f9497 JH |
31 | one/a.3 |
32 | one/a.4 | |
33 | one/a.5 | |
1df092d2 JH |
34 | one/a.7 |
35 | one/two/a.2 | |
f87f9497 JH |
36 | one/two/a.3 |
37 | one/two/a.5 | |
1df092d2 JH |
38 | one/two/a.7 |
39 | one/two/a.8 | |
f87f9497 JH |
40 | three/a.2 |
41 | three/a.3 | |
42 | three/a.4 | |
43 | three/a.5 | |
1df092d2 | 44 | three/a.8 |
f87f9497 JH |
45 | EOF |
46 | ||
47 | echo '.gitignore | |
dd482eea FAG |
48 | \#ignore1 |
49 | \#ignore2* | |
50 | \#hid*n | |
f87f9497 JH |
51 | output |
52 | expect | |
53 | .gitignore | |
1df092d2 JH |
54 | *.7 |
55 | !*.8' >.git/ignore | |
f87f9497 JH |
56 | |
57 | echo '*.1 | |
1df092d2 JH |
58 | /*.3 |
59 | !*.6' >.gitignore | |
f87f9497 | 60 | echo '*.2 |
1df092d2 JH |
61 | two/*.4 |
62 | !*.7 | |
63 | *.8' >one/.gitignore | |
64 | echo '!*.2 | |
65 | !*.8' >one/two/.gitignore | |
f87f9497 | 66 | |
c28b3d6e NTND |
67 | allignores='.gitignore one/.gitignore one/two/.gitignore' |
68 | ||
f87f9497 | 69 | test_expect_success \ |
5be60078 JH |
70 | 'git ls-files --others with various exclude options.' \ |
71 | 'git ls-files --others \ | |
1df092d2 | 72 | --exclude=\*.6 \ |
f87f9497 JH |
73 | --exclude-per-directory=.gitignore \ |
74 | --exclude-from=.git/ignore \ | |
75 | >output && | |
3af82863 | 76 | test_cmp expect output' |
da7bc9b0 | 77 | |
d317e438 | 78 | # Test \r\n (MSDOS-like systems) |
0dbc4e89 | 79 | printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore |
d317e438 AR |
80 | |
81 | test_expect_success \ | |
5be60078 JH |
82 | 'git ls-files --others with \r\n line endings.' \ |
83 | 'git ls-files --others \ | |
d317e438 AR |
84 | --exclude=\*.6 \ |
85 | --exclude-per-directory=.gitignore \ | |
86 | --exclude-from=.git/ignore \ | |
87 | >output && | |
3af82863 | 88 | test_cmp expect output' |
d317e438 | 89 | |
c28b3d6e NTND |
90 | test_expect_success 'setup skip-worktree gitignore' ' |
91 | git add $allignores && | |
92 | git update-index --skip-worktree $allignores && | |
93 | rm $allignores | |
94 | ' | |
95 | ||
96 | test_expect_success \ | |
97 | 'git ls-files --others with various exclude options.' \ | |
98 | 'git ls-files --others \ | |
99 | --exclude=\*.6 \ | |
100 | --exclude-per-directory=.gitignore \ | |
101 | --exclude-from=.git/ignore \ | |
102 | >output && | |
103 | test_cmp expect output' | |
104 | ||
105 | test_expect_success 'restore gitignore' ' | |
08d595dc | 106 | git checkout --ignore-skip-worktree-bits $allignores && |
c28b3d6e NTND |
107 | rm .git/index |
108 | ' | |
109 | ||
dd482eea | 110 | cat > excludes-file <<\EOF |
0ba956d3 JS |
111 | *.[1-8] |
112 | e* | |
dd482eea | 113 | \#* |
0ba956d3 JS |
114 | EOF |
115 | ||
5be60078 | 116 | git config core.excludesFile excludes-file |
0ba956d3 | 117 | |
2556b996 | 118 | git -c status.displayCommentPrefix=true status | grep "^# " > output |
0ba956d3 JS |
119 | |
120 | cat > expect << EOF | |
121 | # .gitignore | |
122 | # a.6 | |
123 | # one/ | |
124 | # output | |
125 | # three/ | |
126 | EOF | |
127 | ||
0cb0e143 | 128 | test_expect_success 'git status honors core.excludesfile' \ |
82ebb0b6 | 129 | 'test_cmp expect output' |
0ba956d3 | 130 | |
d6b8fc30 JH |
131 | test_expect_success 'trailing slash in exclude allows directory match(1)' ' |
132 | ||
133 | git ls-files --others --exclude=one/ >output && | |
134 | if grep "^one/" output | |
135 | then | |
136 | echo Ooops | |
137 | false | |
138 | else | |
139 | : happy | |
140 | fi | |
141 | ||
142 | ' | |
143 | ||
144 | test_expect_success 'trailing slash in exclude allows directory match (2)' ' | |
145 | ||
146 | git ls-files --others --exclude=one/two/ >output && | |
147 | if grep "^one/two/" output | |
148 | then | |
149 | echo Ooops | |
150 | false | |
151 | else | |
152 | : happy | |
153 | fi | |
154 | ||
155 | ' | |
156 | ||
157 | test_expect_success 'trailing slash in exclude forces directory match (1)' ' | |
158 | ||
a48fcd83 | 159 | >two && |
d6b8fc30 JH |
160 | git ls-files --others --exclude=two/ >output && |
161 | grep "^two" output | |
162 | ||
163 | ' | |
164 | ||
165 | test_expect_success 'trailing slash in exclude forces directory match (2)' ' | |
166 | ||
167 | git ls-files --others --exclude=one/a.1/ >output && | |
168 | grep "^one/a.1" output | |
169 | ||
170 | ' | |
171 | ||
32738edf MG |
172 | test_expect_success 'negated exclude matches can override previous ones' ' |
173 | ||
174 | git ls-files --others --exclude="a.*" --exclude="!a.1" >output && | |
175 | grep "^a.1" output | |
176 | ' | |
177 | ||
5cee3493 | 178 | test_expect_success 'excluded directory overrides content patterns' ' |
c3c327de KB |
179 | |
180 | git ls-files --others --exclude="one" --exclude="!one/a.1" >output && | |
5cee3493 JH |
181 | if grep "^one/a.1" output |
182 | then | |
183 | false | |
184 | fi | |
c3c327de KB |
185 | ' |
186 | ||
187 | test_expect_success 'negated directory doesn'\''t affect content patterns' ' | |
188 | ||
189 | git ls-files --others --exclude="!one" --exclude="one/a.1" >output && | |
190 | if grep "^one/a.1" output | |
191 | then | |
192 | false | |
193 | fi | |
194 | ' | |
195 | ||
472e7469 JH |
196 | test_expect_success 'subdirectory ignore (setup)' ' |
197 | mkdir -p top/l1/l2 && | |
198 | ( | |
199 | cd top && | |
200 | git init && | |
201 | echo /.gitignore >.gitignore && | |
202 | echo l1 >>.gitignore && | |
203 | echo l2 >l1/.gitignore && | |
204 | >l1/l2/l1 | |
205 | ) | |
206 | ' | |
207 | ||
208 | test_expect_success 'subdirectory ignore (toplevel)' ' | |
209 | ( | |
210 | cd top && | |
211 | git ls-files -o --exclude-standard | |
212 | ) >actual && | |
d3c6751b | 213 | test_must_be_empty actual |
472e7469 JH |
214 | ' |
215 | ||
216 | test_expect_success 'subdirectory ignore (l1/l2)' ' | |
217 | ( | |
218 | cd top/l1/l2 && | |
219 | git ls-files -o --exclude-standard | |
220 | ) >actual && | |
d3c6751b | 221 | test_must_be_empty actual |
472e7469 JH |
222 | ' |
223 | ||
48ffef96 | 224 | test_expect_success 'subdirectory ignore (l1)' ' |
472e7469 JH |
225 | ( |
226 | cd top/l1 && | |
227 | git ls-files -o --exclude-standard | |
228 | ) >actual && | |
d3c6751b | 229 | test_must_be_empty actual |
472e7469 JH |
230 | ' |
231 | ||
184d2a8e KB |
232 | test_expect_success 'show/hide empty ignored directory (setup)' ' |
233 | rm top/l1/l2/l1 && | |
234 | rm top/l1/.gitignore | |
235 | ' | |
236 | ||
237 | test_expect_success 'show empty ignored directory with --directory' ' | |
238 | ( | |
239 | cd top && | |
240 | git ls-files -o -i --exclude l1 --directory | |
241 | ) >actual && | |
242 | echo l1/ >expect && | |
243 | test_cmp expect actual | |
244 | ' | |
245 | ||
246 | test_expect_success 'hide empty ignored directory with --no-empty-directory' ' | |
247 | ( | |
248 | cd top && | |
249 | git ls-files -o -i --exclude l1 --directory --no-empty-directory | |
250 | ) >actual && | |
d3c6751b | 251 | test_must_be_empty actual |
184d2a8e KB |
252 | ' |
253 | ||
5bd8e2d8 KB |
254 | test_expect_success 'show/hide empty ignored sub-directory (setup)' ' |
255 | > top/l1/tracked && | |
256 | ( | |
257 | cd top && | |
258 | git add -f l1/tracked | |
259 | ) | |
260 | ' | |
261 | ||
262 | test_expect_success 'show empty ignored sub-directory with --directory' ' | |
263 | ( | |
264 | cd top && | |
265 | git ls-files -o -i --exclude l1 --directory | |
266 | ) >actual && | |
267 | echo l1/l2/ >expect && | |
268 | test_cmp expect actual | |
269 | ' | |
270 | ||
271 | test_expect_success 'hide empty ignored sub-directory with --no-empty-directory' ' | |
272 | ( | |
273 | cd top && | |
274 | git ls-files -o -i --exclude l1 --directory --no-empty-directory | |
275 | ) >actual && | |
d3c6751b | 276 | test_must_be_empty actual |
5bd8e2d8 KB |
277 | ' |
278 | ||
a3ea4d71 | 279 | test_expect_success 'pattern matches prefix completely' ' |
a3ea4d71 | 280 | git ls-files -i -o --exclude "/three/a.3[abc]" >actual && |
1c5e94f4 | 281 | test_must_be_empty actual |
a3ea4d71 NTND |
282 | ' |
283 | ||
237ec6e4 NTND |
284 | test_expect_success 'ls-files with "**" patterns' ' |
285 | cat <<\EOF >expect && | |
286 | a.1 | |
287 | one/a.1 | |
288 | one/two/a.1 | |
289 | three/a.1 | |
290 | EOF | |
60687de5 | 291 | git ls-files -o -i --exclude "**/a.1" >actual && |
237ec6e4 NTND |
292 | test_cmp expect actual |
293 | ' | |
294 | ||
295 | ||
296 | test_expect_success 'ls-files with "**" patterns and no slashes' ' | |
237ec6e4 | 297 | git ls-files -o -i --exclude "one**a.1" >actual && |
1c5e94f4 | 298 | test_must_be_empty actual |
237ec6e4 NTND |
299 | ' |
300 | ||
da7bc9b0 | 301 | test_done |