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