Git 1.8.3-rc3
[git/git-svn.git] / t / t3001-ls-files-others-exclude.sh
blob4e3735f0cb28d2b545f59a2464ea74bea4b626a1
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-lib.sh
13 rm -fr one three
14 for dir in . one one/two three
16 mkdir -p $dir &&
17 for i in 1 2 3 4 5 6 7 8
19 >$dir/a.$i
20 done
21 done
22 >"#ignore1"
23 >"#ignore2"
24 >"#hidden"
26 cat >expect <<EOF
27 a.2
28 a.4
29 a.5
30 a.8
31 one/a.3
32 one/a.4
33 one/a.5
34 one/a.7
35 one/two/a.2
36 one/two/a.3
37 one/two/a.5
38 one/two/a.7
39 one/two/a.8
40 three/a.2
41 three/a.3
42 three/a.4
43 three/a.5
44 three/a.8
45 EOF
47 echo '.gitignore
48 \#ignore1
49 \#ignore2*
50 \#hid*n
51 output
52 expect
53 .gitignore
54 *.7
55 !*.8' >.git/ignore
57 echo '*.1
58 /*.3
59 !*.6' >.gitignore
60 echo '*.2
61 two/*.4
62 !*.7
63 *.8' >one/.gitignore
64 echo '!*.2
65 !*.8' >one/two/.gitignore
67 allignores='.gitignore one/.gitignore one/two/.gitignore'
69 test_expect_success \
70 'git ls-files --others with various exclude options.' \
71 'git ls-files --others \
72 --exclude=\*.6 \
73 --exclude-per-directory=.gitignore \
74 --exclude-from=.git/ignore \
75 >output &&
76 test_cmp expect output'
78 # Test \r\n (MSDOS-like systems)
79 printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
81 test_expect_success \
82 'git ls-files --others with \r\n line endings.' \
83 'git ls-files --others \
84 --exclude=\*.6 \
85 --exclude-per-directory=.gitignore \
86 --exclude-from=.git/ignore \
87 >output &&
88 test_cmp expect output'
90 test_expect_success 'setup skip-worktree gitignore' '
91 git add $allignores &&
92 git update-index --skip-worktree $allignores &&
93 rm $allignores
96 test_expect_success \
97 'git ls-files --others with various exclude options.' \
98 'git ls-files --others \
99 --exclude=\*.6 \
100 --exclude-per-directory=.gitignore \
101 --exclude-from=.git/ignore \
102 >output &&
103 test_cmp expect output'
105 test_expect_success 'restore gitignore' '
106 git checkout --ignore-skip-worktree-bits $allignores &&
107 rm .git/index
110 cat > excludes-file <<\EOF
111 *.[1-8]
116 git config core.excludesFile excludes-file
118 git status | grep "^# " > output
120 cat > expect << EOF
121 # .gitignore
122 # a.6
123 # one/
124 # output
125 # three/
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
135 then
136 echo Ooops
137 false
138 else
139 : happy
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
148 then
149 echo Ooops
150 false
151 else
152 : happy
157 test_expect_success 'trailing slash in exclude forces directory match (1)' '
159 >two &&
160 git ls-files --others --exclude=two/ >output &&
161 grep "^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 &&
175 grep "^a.1" output
178 test_expect_success 'subdirectory ignore (setup)' '
179 mkdir -p top/l1/l2 &&
181 cd top &&
182 git init &&
183 echo /.gitignore >.gitignore &&
184 echo l1 >>.gitignore &&
185 echo l2 >l1/.gitignore &&
186 >l1/l2/l1
190 test_expect_success 'subdirectory ignore (toplevel)' '
192 cd top &&
193 git ls-files -o --exclude-standard
194 ) >actual &&
195 >expect &&
196 test_cmp expect actual
199 test_expect_success 'subdirectory ignore (l1/l2)' '
201 cd top/l1/l2 &&
202 git ls-files -o --exclude-standard
203 ) >actual &&
204 >expect &&
205 test_cmp expect actual
208 test_expect_success 'subdirectory ignore (l1)' '
210 cd top/l1 &&
211 git ls-files -o --exclude-standard
212 ) >actual &&
213 >expect &&
214 test_cmp expect actual
217 test_expect_success 'show/hide empty ignored directory (setup)' '
218 rm top/l1/l2/l1 &&
219 rm top/l1/.gitignore
222 test_expect_success 'show empty ignored directory with --directory' '
224 cd top &&
225 git ls-files -o -i --exclude l1 --directory
226 ) >actual &&
227 echo l1/ >expect &&
228 test_cmp expect actual
231 test_expect_success 'hide empty ignored directory with --no-empty-directory' '
233 cd top &&
234 git ls-files -o -i --exclude l1 --directory --no-empty-directory
235 ) >actual &&
236 >expect &&
237 test_cmp expect actual
240 test_expect_success 'show/hide empty ignored sub-directory (setup)' '
241 > top/l1/tracked &&
243 cd top &&
244 git add -f l1/tracked
248 test_expect_success 'show empty ignored sub-directory with --directory' '
250 cd top &&
251 git ls-files -o -i --exclude l1 --directory
252 ) >actual &&
253 echo l1/l2/ >expect &&
254 test_cmp expect actual
257 test_expect_success 'hide empty ignored sub-directory with --no-empty-directory' '
259 cd top &&
260 git ls-files -o -i --exclude l1 --directory --no-empty-directory
261 ) >actual &&
262 >expect &&
263 test_cmp expect actual
266 test_expect_success 'pattern matches prefix completely' '
267 : >expect &&
268 git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
269 test_cmp expect actual
272 test_expect_success 'ls-files with "**" patterns' '
273 cat <<\EOF >expect &&
275 one/a.1
276 one/two/a.1
277 three/a.1
279 git ls-files -o -i --exclude "**/a.1" >actual
280 test_cmp expect actual
284 test_expect_success 'ls-files with "**" patterns and no slashes' '
285 : >expect &&
286 git ls-files -o -i --exclude "one**a.1" >actual &&
287 test_cmp expect actual
290 test_done