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
15 for dir
in . one one
/two three
18 for i
in 1 2 3 4 5 6 7 8
66 !*.8' >one
/two
/.gitignore
68 allignores
='.gitignore one/.gitignore one/two/.gitignore'
70 test_expect_success
'git ls-files --others with various exclude options.' '
71 git ls-files --others \
73 --exclude-per-directory=.gitignore \
74 --exclude-from=.git/ignore \
76 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
'git ls-files --others with \r\n line endings.' '
83 git ls-files --others \
85 --exclude-per-directory=.gitignore \
86 --exclude-from=.git/ignore \
88 test_cmp expect output
91 test_expect_success
'setup skip-worktree gitignore' '
92 git add $allignores &&
93 git update-index --skip-worktree $allignores &&
97 test_expect_success
'git ls-files --others with various exclude options.' '
98 git ls-files --others \
100 --exclude-per-directory=.gitignore \
101 --exclude-from=.git/ignore \
103 test_cmp expect output
106 test_expect_success
'restore gitignore' '
107 git checkout --ignore-skip-worktree-bits $allignores &&
111 cat > excludes-file
<<\EOF
117 git config core.excludesFile excludes-file
119 git
-c status.displayCommentPrefix
=true status |
grep "^# " > output
129 test_expect_success
'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
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
158 test_expect_success
'trailing slash in exclude forces directory match (1)' '
161 git ls-files --others --exclude=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 &&
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
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
197 test_expect_success
'subdirectory ignore (setup)' '
198 mkdir -p top/l1/l2 &&
202 echo /.gitignore >.gitignore &&
203 echo l1 >>.gitignore &&
204 echo l2 >l1/.gitignore &&
209 test_expect_success
'subdirectory ignore (toplevel)' '
212 git ls-files -o --exclude-standard
214 test_must_be_empty actual
217 test_expect_success
'subdirectory ignore (l1/l2)' '
220 git ls-files -o --exclude-standard
222 test_must_be_empty actual
225 test_expect_success
'subdirectory ignore (l1)' '
228 git ls-files -o --exclude-standard
230 test_must_be_empty actual
233 test_expect_success
'show/hide empty ignored directory (setup)' '
238 test_expect_success
'show empty ignored directory with --directory' '
241 git ls-files -o -i --exclude l1 --directory
244 test_cmp expect actual
247 test_expect_success
'hide empty ignored directory with --no-empty-directory' '
250 git ls-files -o -i --exclude l1 --directory --no-empty-directory
252 test_must_be_empty actual
255 test_expect_success
'show/hide empty ignored sub-directory (setup)' '
259 git add -f l1/tracked
263 test_expect_success
'show empty ignored sub-directory with --directory' '
266 git ls-files -o -i --exclude l1 --directory
268 echo l1/l2/ >expect &&
269 test_cmp expect actual
272 test_expect_success
'hide empty ignored sub-directory with --no-empty-directory' '
275 git ls-files -o -i --exclude l1 --directory --no-empty-directory
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 &&
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