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
213 test_must_be_empty actual
216 test_expect_success 'subdirectory ignore (l1/l2)' '
219 git ls-files -o --exclude-standard
221 test_must_be_empty actual
224 test_expect_success 'subdirectory ignore (l1)' '
227 git ls-files -o --exclude-standard
229 test_must_be_empty actual
232 test_expect_success 'show/hide empty ignored directory (setup)' '
237 test_expect_success 'show empty ignored directory with --directory' '
240 git ls-files -o -i --exclude l1 --directory
243 test_cmp expect actual
246 test_expect_success 'hide empty ignored directory with --no-empty-directory' '
249 git ls-files -o -i --exclude l1 --directory --no-empty-directory
251 test_must_be_empty actual
254 test_expect_success 'show/hide empty ignored sub-directory (setup)' '
258 git add -f l1/tracked
262 test_expect_success 'show empty ignored sub-directory with --directory' '
265 git ls-files -o -i --exclude l1 --directory
267 echo l1/l2/ >expect &&
268 test_cmp expect actual
271 test_expect_success 'hide empty ignored sub-directory with --no-empty-directory' '
274 git ls-files -o -i --exclude l1 --directory --no-empty-directory
276 test_must_be_empty actual
279 test_expect_success 'pattern matches prefix completely' '
281 git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
282 test_cmp expect 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
297 test_expect_success 'ls-files with "**" patterns and no slashes' '
299 git ls-files -o -i --exclude "one**a.1" >actual &&
300 test_cmp expect actual