Merge branch 'ds/add-rm-with-sparse-index'
[git/debian.git] / t / t3001-ls-files-others-exclude.sh
blob48cec4e5f88501db3287a47063ad2788807e205a
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git ls-files --others --exclude
8 This test runs git ls-files --others and tests --exclude patterns.
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
14 rm -fr one three
15 for dir in . one one/two three
17 mkdir -p $dir &&
18 for i in 1 2 3 4 5 6 7 8
20 >$dir/a.$i
21 done
22 done
23 >"#ignore1"
24 >"#ignore2"
25 >"#hidden"
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
48 echo '.gitignore
49 \#ignore1
50 \#ignore2*
51 \#hid*n
52 output
53 expect
54 .gitignore
55 *.7
56 !*.8' >.git/ignore
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
68 allignores='.gitignore one/.gitignore one/two/.gitignore'
70 test_expect_success \
71 'git ls-files --others with various exclude options.' \
72 'git ls-files --others \
73 --exclude=\*.6 \
74 --exclude-per-directory=.gitignore \
75 --exclude-from=.git/ignore \
76 >output &&
77 test_cmp expect output'
79 # Test \r\n (MSDOS-like systems)
80 printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
82 test_expect_success \
83 'git ls-files --others with \r\n line endings.' \
84 'git ls-files --others \
85 --exclude=\*.6 \
86 --exclude-per-directory=.gitignore \
87 --exclude-from=.git/ignore \
88 >output &&
89 test_cmp expect output'
91 test_expect_success 'setup skip-worktree gitignore' '
92 git add $allignores &&
93 git update-index --skip-worktree $allignores &&
94 rm $allignores
97 test_expect_success \
98 'git ls-files --others with various exclude options.' \
99 'git ls-files --others \
100 --exclude=\*.6 \
101 --exclude-per-directory=.gitignore \
102 --exclude-from=.git/ignore \
103 >output &&
104 test_cmp expect output'
106 test_expect_success !SANITIZE_LEAK 'restore gitignore' '
107 git checkout --ignore-skip-worktree-bits $allignores &&
108 rm .git/index
111 cat > excludes-file <<\EOF
112 *.[1-8]
117 git config core.excludesFile excludes-file
119 git -c status.displayCommentPrefix=true status | grep "^# " > output
121 cat > expect << EOF
122 # .gitignore
123 # a.6
124 # one/
125 # output
126 # three/
129 test_expect_success !SANITIZE_LEAK 'git status honors core.excludesfile' \
130 'test_cmp expect output'
132 test_expect_success 'trailing slash in exclude allows directory match(1)' '
134 git ls-files --others --exclude=one/ >output &&
135 if grep "^one/" output
136 then
137 echo Ooops
138 false
139 else
140 : happy
145 test_expect_success 'trailing slash in exclude allows directory match (2)' '
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
158 test_expect_success 'trailing slash in exclude forces directory match (1)' '
160 >two &&
161 git ls-files --others --exclude=two/ >output &&
162 grep "^two" output
166 test_expect_success 'trailing slash in exclude forces directory match (2)' '
168 git ls-files --others --exclude=one/a.1/ >output &&
169 grep "^one/a.1" output
173 test_expect_success 'negated exclude matches can override previous ones' '
175 git ls-files --others --exclude="a.*" --exclude="!a.1" >output &&
176 grep "^a.1" output
179 test_expect_success 'excluded directory overrides content patterns' '
181 git ls-files --others --exclude="one" --exclude="!one/a.1" >output &&
182 if grep "^one/a.1" output
183 then
184 false
188 test_expect_success 'negated directory doesn'\''t affect content patterns' '
190 git ls-files --others --exclude="!one" --exclude="one/a.1" >output &&
191 if grep "^one/a.1" output
192 then
193 false
197 test_expect_success 'subdirectory ignore (setup)' '
198 mkdir -p top/l1/l2 &&
200 cd top &&
201 git init &&
202 echo /.gitignore >.gitignore &&
203 echo l1 >>.gitignore &&
204 echo l2 >l1/.gitignore &&
205 >l1/l2/l1
209 test_expect_success 'subdirectory ignore (toplevel)' '
211 cd top &&
212 git ls-files -o --exclude-standard
213 ) >actual &&
214 test_must_be_empty actual
217 test_expect_success 'subdirectory ignore (l1/l2)' '
219 cd top/l1/l2 &&
220 git ls-files -o --exclude-standard
221 ) >actual &&
222 test_must_be_empty actual
225 test_expect_success 'subdirectory ignore (l1)' '
227 cd top/l1 &&
228 git ls-files -o --exclude-standard
229 ) >actual &&
230 test_must_be_empty actual
233 test_expect_success 'show/hide empty ignored directory (setup)' '
234 rm top/l1/l2/l1 &&
235 rm top/l1/.gitignore
238 test_expect_success 'show empty ignored directory with --directory' '
240 cd top &&
241 git ls-files -o -i --exclude l1 --directory
242 ) >actual &&
243 echo l1/ >expect &&
244 test_cmp expect actual
247 test_expect_success 'hide empty ignored directory with --no-empty-directory' '
249 cd top &&
250 git ls-files -o -i --exclude l1 --directory --no-empty-directory
251 ) >actual &&
252 test_must_be_empty actual
255 test_expect_success 'show/hide empty ignored sub-directory (setup)' '
256 > top/l1/tracked &&
258 cd top &&
259 git add -f l1/tracked
263 test_expect_success 'show empty ignored sub-directory with --directory' '
265 cd top &&
266 git ls-files -o -i --exclude l1 --directory
267 ) >actual &&
268 echo l1/l2/ >expect &&
269 test_cmp expect actual
272 test_expect_success 'hide empty ignored sub-directory with --no-empty-directory' '
274 cd top &&
275 git ls-files -o -i --exclude l1 --directory --no-empty-directory
276 ) >actual &&
277 test_must_be_empty actual
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
285 test_expect_success 'ls-files with "**" patterns' '
286 cat <<\EOF >expect &&
288 one/a.1
289 one/two/a.1
290 three/a.1
292 git ls-files -o -i --exclude "**/a.1" >actual &&
293 test_cmp expect actual
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
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
307 test_done