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.
14 for dir
in . one one
/two three
17 for i
in 1 2 3 4 5 6 7 8
65 !*.8' >one
/two
/.gitignore
67 allignores
='.gitignore one/.gitignore one/two/.gitignore'
70 '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'
78 # Test \r\n (MSDOS-like systems)
79 printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
82 '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'
90 test_expect_success
'setup skip-worktree gitignore' '
91 git add $allignores &&
92 git update-index --skip-worktree $allignores &&
97 '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'
105 test_expect_success
'restore gitignore' '
106 git checkout --ignore-skip-worktree-bits $allignores &&
110 cat > excludes-file
<<\EOF
116 git config core.excludesFile excludes-file
118 git
-c status.displayCommentPrefix
=true status |
grep "^# " > output
128 test_expect_success
'git status honors core.excludesfile' \
129 'test_cmp expect output'
131 test_expect_success
'trailing slash in exclude allows directory match(1)' '
133 git ls-files --others --exclude=one/ >output &&
134 if grep "^one/" output
144 test_expect_success
'trailing slash in exclude allows directory match (2)' '
146 git ls-files --others --exclude=one/two/ >output &&
147 if grep "^one/two/" output
157 test_expect_success
'trailing slash in exclude forces directory match (1)' '
160 git ls-files --others --exclude=two/ >output &&
165 test_expect_success
'trailing slash in exclude forces directory match (2)' '
167 git ls-files --others --exclude=one/a.1/ >output &&
168 grep "^one/a.1" output
172 test_expect_success
'negated exclude matches can override previous ones' '
174 git ls-files --others --exclude="a.*" --exclude="!a.1" >output &&
178 test_expect_success
'excluded directory overrides content patterns' '
180 git ls-files --others --exclude="one" --exclude="!one/a.1" >output &&
181 if grep "^one/a.1" output
187 test_expect_success
'negated directory doesn'\''t affect content patterns' '
189 git ls-files --others --exclude="!one" --exclude="one/a.1" >output &&
190 if grep "^one/a.1" output
196 test_expect_success
'subdirectory ignore (setup)' '
197 mkdir -p top/l1/l2 &&
201 echo /.gitignore >.gitignore &&
202 echo l1 >>.gitignore &&
203 echo l2 >l1/.gitignore &&
208 test_expect_success
'subdirectory ignore (toplevel)' '
211 git ls-files -o --exclude-standard
214 test_cmp expect actual
217 test_expect_success
'subdirectory ignore (l1/l2)' '
220 git ls-files -o --exclude-standard
223 test_cmp expect actual
226 test_expect_success
'subdirectory ignore (l1)' '
229 git ls-files -o --exclude-standard
232 test_cmp expect actual
235 test_expect_success
'show/hide empty ignored directory (setup)' '
240 test_expect_success
'show empty ignored directory with --directory' '
243 git ls-files -o -i --exclude l1 --directory
246 test_cmp expect actual
249 test_expect_success
'hide empty ignored directory with --no-empty-directory' '
252 git ls-files -o -i --exclude l1 --directory --no-empty-directory
255 test_cmp expect actual
258 test_expect_success
'show/hide empty ignored sub-directory (setup)' '
262 git add -f l1/tracked
266 test_expect_success
'show empty ignored sub-directory with --directory' '
269 git ls-files -o -i --exclude l1 --directory
271 echo l1/l2/ >expect &&
272 test_cmp expect actual
275 test_expect_success
'hide empty ignored sub-directory with --no-empty-directory' '
278 git ls-files -o -i --exclude l1 --directory --no-empty-directory
281 test_cmp expect actual
284 test_expect_success
'pattern matches prefix completely' '
286 git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
287 test_cmp expect actual
290 test_expect_success
'ls-files with "**" patterns' '
291 cat <<\EOF >expect &&
297 git ls-files -o -i --exclude "**/a.1" >actual &&
298 test_cmp expect actual
302 test_expect_success
'ls-files with "**" patterns and no slashes' '
304 git ls-files -o -i --exclude "one**a.1" >actual &&
305 test_cmp expect actual
308 test_expect_success
'negative patterns' '
309 git init reinclude &&
312 cat >.gitignore <<-\EOF &&
318 cat >fooo/.gitignore <<-\EOF &&
322 touch abc foo/def foo/bar/ghi foo/bar/bar &&
323 git ls-files -o --exclude-standard >../actual &&
324 cat >../expected <<-\EOF &&
329 test_cmp ../expected ../actual