]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3001-ls-files-others-exclude.sh
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / t / t3001-ls-files-others-exclude.sh
CommitLineData
f87f9497
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git ls-files --others --exclude
f87f9497 7
5be60078 8This test runs git ls-files --others and tests --exclude patterns.
f87f9497
JH
9'
10
272f0a57 11TEST_PASSES_SANITIZE_LEAK=true
f87f9497
JH
12. ./test-lib.sh
13
14rm -fr one three
15for dir in . one one/two three
16do
17 mkdir -p $dir &&
1df092d2 18 for i in 1 2 3 4 5 6 7 8
f87f9497
JH
19 do
20 >$dir/a.$i
21 done
22done
dd482eea
FAG
23>"#ignore1"
24>"#ignore2"
25>"#hidden"
f87f9497
JH
26
27cat >expect <<EOF
28a.2
29a.4
30a.5
1df092d2 31a.8
f87f9497
JH
32one/a.3
33one/a.4
34one/a.5
1df092d2
JH
35one/a.7
36one/two/a.2
f87f9497
JH
37one/two/a.3
38one/two/a.5
1df092d2
JH
39one/two/a.7
40one/two/a.8
f87f9497
JH
41three/a.2
42three/a.3
43three/a.4
44three/a.5
1df092d2 45three/a.8
f87f9497
JH
46EOF
47
48echo '.gitignore
dd482eea
FAG
49\#ignore1
50\#ignore2*
51\#hid*n
f87f9497
JH
52output
53expect
54.gitignore
1df092d2
JH
55*.7
56!*.8' >.git/ignore
f87f9497
JH
57
58echo '*.1
1df092d2
JH
59/*.3
60!*.6' >.gitignore
f87f9497 61echo '*.2
1df092d2
JH
62two/*.4
63!*.7
64*.8' >one/.gitignore
65echo '!*.2
66!*.8' >one/two/.gitignore
f87f9497 67
c28b3d6e
NTND
68allignores='.gitignore one/.gitignore one/two/.gitignore'
69
18337d40
LL
70test_expect_success '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 \
18337d40
LL
75 >output &&
76 test_cmp expect output
77'
da7bc9b0 78
d317e438 79# Test \r\n (MSDOS-like systems)
0dbc4e89 80printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
d317e438 81
18337d40
LL
82test_expect_success '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 \
18337d40
LL
87 >output &&
88 test_cmp expect output
89'
d317e438 90
c28b3d6e
NTND
91test_expect_success 'setup skip-worktree gitignore' '
92 git add $allignores &&
93 git update-index --skip-worktree $allignores &&
94 rm $allignores
95'
96
18337d40
LL
97test_expect_success 'git ls-files --others with various exclude options.' '
98 git ls-files --others \
c28b3d6e
NTND
99 --exclude=\*.6 \
100 --exclude-per-directory=.gitignore \
101 --exclude-from=.git/ignore \
18337d40
LL
102 >output &&
103 test_cmp expect output
104'
c28b3d6e 105
96ecf699 106test_expect_success 'restore gitignore' '
08d595dc 107 git checkout --ignore-skip-worktree-bits $allignores &&
c28b3d6e
NTND
108 rm .git/index
109'
110
dd482eea 111cat > excludes-file <<\EOF
0ba956d3
JS
112*.[1-8]
113e*
dd482eea 114\#*
0ba956d3
JS
115EOF
116
5be60078 117git config core.excludesFile excludes-file
0ba956d3 118
2556b996 119git -c status.displayCommentPrefix=true status | grep "^# " > output
0ba956d3
JS
120
121cat > expect << EOF
122# .gitignore
123# a.6
124# one/
125# output
126# three/
127EOF
128
96ecf699 129test_expect_success 'git status honors core.excludesfile' \
82ebb0b6 130 'test_cmp expect output'
0ba956d3 131
d6b8fc30
JH
132test_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
145test_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
158test_expect_success 'trailing slash in exclude forces directory match (1)' '
159
a48fcd83 160 >two &&
d6b8fc30
JH
161 git ls-files --others --exclude=two/ >output &&
162 grep "^two" output
163
164'
165
166test_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
32738edf
MG
173test_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
5cee3493 179test_expect_success 'excluded directory overrides content patterns' '
c3c327de
KB
180
181 git ls-files --others --exclude="one" --exclude="!one/a.1" >output &&
5cee3493
JH
182 if grep "^one/a.1" output
183 then
184 false
185 fi
c3c327de
KB
186'
187
188test_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
472e7469
JH
197test_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
209test_expect_success 'subdirectory ignore (toplevel)' '
210 (
211 cd top &&
212 git ls-files -o --exclude-standard
213 ) >actual &&
d3c6751b 214 test_must_be_empty actual
472e7469
JH
215'
216
217test_expect_success 'subdirectory ignore (l1/l2)' '
218 (
219 cd top/l1/l2 &&
220 git ls-files -o --exclude-standard
221 ) >actual &&
d3c6751b 222 test_must_be_empty actual
472e7469
JH
223'
224
48ffef96 225test_expect_success 'subdirectory ignore (l1)' '
472e7469
JH
226 (
227 cd top/l1 &&
228 git ls-files -o --exclude-standard
229 ) >actual &&
d3c6751b 230 test_must_be_empty actual
472e7469
JH
231'
232
184d2a8e
KB
233test_expect_success 'show/hide empty ignored directory (setup)' '
234 rm top/l1/l2/l1 &&
235 rm top/l1/.gitignore
236'
237
238test_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
247test_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 &&
d3c6751b 252 test_must_be_empty actual
184d2a8e
KB
253'
254
5bd8e2d8
KB
255test_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
263test_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
272test_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 &&
d3c6751b 277 test_must_be_empty actual
5bd8e2d8
KB
278'
279
a3ea4d71 280test_expect_success 'pattern matches prefix completely' '
a3ea4d71 281 git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
1c5e94f4 282 test_must_be_empty actual
a3ea4d71
NTND
283'
284
237ec6e4 285test_expect_success 'ls-files with "**" patterns' '
18337d40
LL
286 cat <<-\EOF >expect &&
287 a.1
288 one/a.1
289 one/two/a.1
290 three/a.1
291 EOF
60687de5 292 git ls-files -o -i --exclude "**/a.1" >actual &&
237ec6e4
NTND
293 test_cmp expect actual
294'
295
dd55fc0d 296test_expect_success 'ls-files with "**" patterns and --directory' '
a97c7a8b
EN
297 # Expectation same as previous test
298 git ls-files --directory -o -i --exclude "**/a.1" >actual &&
299 test_cmp expect actual
300'
237ec6e4
NTND
301
302test_expect_success 'ls-files with "**" patterns and no slashes' '
237ec6e4 303 git ls-files -o -i --exclude "one**a.1" >actual &&
1c5e94f4 304 test_must_be_empty actual
237ec6e4
NTND
305'
306
da7bc9b0 307test_done