interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t3001-ls-files-others-exclude.sh

309 lines · 5999 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='git ls-files --others --exclude
7
8This test runs git ls-files --others and tests --exclude patterns.
9'
10
11. ./test-lib.sh
12
13rm -fr one three
14for dir in . one one/two three
15do
16 mkdir -p $dir &&
17 for i in 1 2 3 4 5 6 7 8
18 do
19 >$dir/a.$i
20 done
21done
22>"#ignore1"
23>"#ignore2"
24>"#hidden"
25
26cat >expect <<EOF
27a.2
28a.4
29a.5
30a.8
31one/a.3
32one/a.4
33one/a.5
34one/a.7
35one/two/a.2
36one/two/a.3
37one/two/a.5
38one/two/a.7
39one/two/a.8
40three/a.2
41three/a.3
42three/a.4
43three/a.5
44three/a.8
45EOF
46
47echo '.gitignore
48\#ignore1
49\#ignore2*
50\#hid*n
51output
52expect
53.gitignore
54*.7
55!*.8' >.git/ignore
56
57echo '*.1
58/*.3
59!*.6' >.gitignore
60echo '*.2
61two/*.4
62!*.7
63*.8' >one/.gitignore
64echo '!*.2
65!*.8' >one/two/.gitignore
66
67allignores='.gitignore one/.gitignore one/two/.gitignore'
68
69test_expect_success 'git ls-files --others with various exclude options.' '
70 git ls-files --others \
71 --exclude=\*.6 \
72 --exclude-per-directory=.gitignore \
73 --exclude-from=.git/ignore \
74 >output &&
75 test_filter_gitconfig output &&
76 test_cmp expect output
77'
78
79# Test \r\n (MSDOS-like systems)
80printf '*.1\r\n/*.3\r\n!*.6\r\n' >.gitignore
81
82test_expect_success '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_filter_gitconfig output &&
89 test_cmp expect output
90'
91
92test_expect_success 'setup skip-worktree gitignore' '
93 git add $allignores &&
94 git update-index --skip-worktree $allignores &&
95 rm $allignores
96'
97
98test_expect_success '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_filter_gitconfig output &&
105 test_cmp expect output
106'
107
108test_expect_success 'restore gitignore' '
109 git checkout --ignore-skip-worktree-bits $allignores &&
110 rm .git/index
111'
112
113cat > excludes-file <<\EOF
114*.[1-8]
115e*
116\#*
117EOF
118
119git config core.excludesFile excludes-file
120
121git -c status.displayCommentPrefix=true status | grep "^# " > output
122
123cat > expect << EOF
124# .gitignore
125# a.6
126# one/
127# output
128# three/
129EOF
130
131test_expect_success 'git status honors core.excludesfile' \
132 'test_cmp expect output'
133
134test_expect_success 'trailing slash in exclude allows directory match(1)' '
135
136 git ls-files --others --exclude=one/ >output &&
137 if grep "^one/" output
138 then
139 echo Ooops
140 false
141 else
142 : happy
143 fi
144
145'
146
147test_expect_success 'trailing slash in exclude allows directory match (2)' '
148
149 git ls-files --others --exclude=one/two/ >output &&
150 if grep "^one/two/" output
151 then
152 echo Ooops
153 false
154 else
155 : happy
156 fi
157
158'
159
160test_expect_success 'trailing slash in exclude forces directory match (1)' '
161
162 >two &&
163 git ls-files --others --exclude=two/ >output &&
164 test_grep "^two" output
165
166'
167
168test_expect_success 'trailing slash in exclude forces directory match (2)' '
169
170 git ls-files --others --exclude=one/a.1/ >output &&
171 test_grep "^one/a.1" output
172
173'
174
175test_expect_success 'negated exclude matches can override previous ones' '
176
177 git ls-files --others --exclude="a.*" --exclude="!a.1" >output &&
178 test_grep "^a.1" output
179'
180
181test_expect_success 'excluded directory overrides content patterns' '
182
183 git ls-files --others --exclude="one" --exclude="!one/a.1" >output &&
184 if grep "^one/a.1" output
185 then
186 false
187 fi
188'
189
190test_expect_success 'negated directory doesn'\''t affect content patterns' '
191
192 git ls-files --others --exclude="!one" --exclude="one/a.1" >output &&
193 if grep "^one/a.1" output
194 then
195 false
196 fi
197'
198
199test_expect_success 'subdirectory ignore (setup)' '
200 mkdir -p top/l1/l2 &&
201 (
202 cd top &&
203 git init &&
204 echo /.gitignore >.gitignore &&
205 echo l1 >>.gitignore &&
206 echo l2 >l1/.gitignore &&
207 >l1/l2/l1
208 )
209'
210
211test_expect_success 'subdirectory ignore (toplevel)' '
212 (
213 cd top &&
214 git ls-files -o --exclude-standard
215 ) >actual &&
216 test_must_be_empty actual
217'
218
219test_expect_success 'subdirectory ignore (l1/l2)' '
220 (
221 cd top/l1/l2 &&
222 git ls-files -o --exclude-standard
223 ) >actual &&
224 test_must_be_empty actual
225'
226
227test_expect_success 'subdirectory ignore (l1)' '
228 (
229 cd top/l1 &&
230 git ls-files -o --exclude-standard
231 ) >actual &&
232 test_must_be_empty actual
233'
234
235test_expect_success 'show/hide empty ignored directory (setup)' '
236 rm top/l1/l2/l1 &&
237 rm top/l1/.gitignore
238'
239
240test_expect_success 'show empty ignored directory with --directory' '
241 (
242 cd top &&
243 git ls-files -o -i --exclude l1 --directory
244 ) >actual &&
245 echo l1/ >expect &&
246 test_cmp expect actual
247'
248
249test_expect_success 'hide empty ignored directory with --no-empty-directory' '
250 (
251 cd top &&
252 git ls-files -o -i --exclude l1 --directory --no-empty-directory
253 ) >actual &&
254 test_must_be_empty actual
255'
256
257test_expect_success 'show/hide empty ignored sub-directory (setup)' '
258 > top/l1/tracked &&
259 (
260 cd top &&
261 git add -f l1/tracked
262 )
263'
264
265test_expect_success 'show empty ignored sub-directory with --directory' '
266 (
267 cd top &&
268 git ls-files -o -i --exclude l1 --directory
269 ) >actual &&
270 echo l1/l2/ >expect &&
271 test_cmp expect actual
272'
273
274test_expect_success 'hide empty ignored sub-directory with --no-empty-directory' '
275 (
276 cd top &&
277 git ls-files -o -i --exclude l1 --directory --no-empty-directory
278 ) >actual &&
279 test_must_be_empty actual
280'
281
282test_expect_success 'pattern matches prefix completely' '
283 git ls-files -i -o --exclude "/three/a.3[abc]" >actual &&
284 test_must_be_empty actual
285'
286
287test_expect_success 'ls-files with "**" patterns' '
288 cat <<-\EOF >expect &&
289 a.1
290 one/a.1
291 one/two/a.1
292 three/a.1
293 EOF
294 git ls-files -o -i --exclude "**/a.1" >actual &&
295 test_cmp expect actual
296'
297
298test_expect_success 'ls-files with "**" patterns and --directory' '
299 # Expectation same as previous test
300 git ls-files --directory -o -i --exclude "**/a.1" >actual &&
301 test_cmp expect actual
302'
303
304test_expect_success 'ls-files with "**" patterns and no slashes' '
305 git ls-files -o -i --exclude "one**a.1" >actual &&
306 test_must_be_empty actual
307'
308
309test_done