##// END OF EJS Templates
hgignore: add escape syntax test for glob patterns...
Yuya Nishihara -
r42856:f78f3054 default
parent child Browse files
Show More
@@ -1,365 +1,388 b''
1 $ hg init ignorerepo
1 $ hg init ignorerepo
2 $ cd ignorerepo
2 $ cd ignorerepo
3
3
4 debugignore with no hgignore should be deterministic:
4 debugignore with no hgignore should be deterministic:
5 $ hg debugignore
5 $ hg debugignore
6 <nevermatcher>
6 <nevermatcher>
7
7
8 Issue562: .hgignore requires newline at end:
8 Issue562: .hgignore requires newline at end:
9
9
10 $ touch foo
10 $ touch foo
11 $ touch bar
11 $ touch bar
12 $ touch baz
12 $ touch baz
13 $ cat > makeignore.py <<EOF
13 $ cat > makeignore.py <<EOF
14 > f = open(".hgignore", "w")
14 > f = open(".hgignore", "w")
15 > f.write("ignore\n")
15 > f.write("ignore\n")
16 > f.write("foo\n")
16 > f.write("foo\n")
17 > # No EOL here
17 > # No EOL here
18 > f.write("bar")
18 > f.write("bar")
19 > f.close()
19 > f.close()
20 > EOF
20 > EOF
21
21
22 $ "$PYTHON" makeignore.py
22 $ "$PYTHON" makeignore.py
23
23
24 Should display baz only:
24 Should display baz only:
25
25
26 $ hg status
26 $ hg status
27 ? baz
27 ? baz
28
28
29 $ rm foo bar baz .hgignore makeignore.py
29 $ rm foo bar baz .hgignore makeignore.py
30
30
31 $ touch a.o
31 $ touch a.o
32 $ touch a.c
32 $ touch a.c
33 $ touch syntax
33 $ touch syntax
34 $ mkdir dir
34 $ mkdir dir
35 $ touch dir/a.o
35 $ touch dir/a.o
36 $ touch dir/b.o
36 $ touch dir/b.o
37 $ touch dir/c.o
37 $ touch dir/c.o
38
38
39 $ hg add dir/a.o
39 $ hg add dir/a.o
40 $ hg commit -m 0
40 $ hg commit -m 0
41 $ hg add dir/b.o
41 $ hg add dir/b.o
42
42
43 $ hg status
43 $ hg status
44 A dir/b.o
44 A dir/b.o
45 ? a.c
45 ? a.c
46 ? a.o
46 ? a.o
47 ? dir/c.o
47 ? dir/c.o
48 ? syntax
48 ? syntax
49
49
50 $ echo "*.o" > .hgignore
50 $ echo "*.o" > .hgignore
51 $ hg status
51 $ hg status
52 abort: $TESTTMP/ignorerepo/.hgignore: invalid pattern (relre): *.o (glob)
52 abort: $TESTTMP/ignorerepo/.hgignore: invalid pattern (relre): *.o (glob)
53 [255]
53 [255]
54
54
55 Ensure given files are relative to cwd
55 Ensure given files are relative to cwd
56
56
57 $ echo "dir/.*\.o" > .hgignore
57 $ echo "dir/.*\.o" > .hgignore
58 $ hg status -i
58 $ hg status -i
59 I dir/c.o
59 I dir/c.o
60
60
61 $ hg debugignore dir/c.o dir/missing.o
61 $ hg debugignore dir/c.o dir/missing.o
62 dir/c.o is ignored
62 dir/c.o is ignored
63 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
63 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
64 dir/missing.o is ignored
64 dir/missing.o is ignored
65 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
65 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
66 $ cd dir
66 $ cd dir
67 $ hg debugignore c.o missing.o
67 $ hg debugignore c.o missing.o
68 c.o is ignored
68 c.o is ignored
69 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
69 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
70 missing.o is ignored
70 missing.o is ignored
71 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
71 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
72
72
73 For icasefs, inexact matches also work, except for missing files
73 For icasefs, inexact matches also work, except for missing files
74
74
75 #if icasefs
75 #if icasefs
76 $ hg debugignore c.O missing.O
76 $ hg debugignore c.O missing.O
77 c.o is ignored
77 c.o is ignored
78 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
78 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
79 missing.O is not ignored
79 missing.O is not ignored
80 #endif
80 #endif
81
81
82 $ cd ..
82 $ cd ..
83
83
84 $ echo ".*\.o" > .hgignore
84 $ echo ".*\.o" > .hgignore
85 $ hg status
85 $ hg status
86 A dir/b.o
86 A dir/b.o
87 ? .hgignore
87 ? .hgignore
88 ? a.c
88 ? a.c
89 ? syntax
89 ? syntax
90
90
91 Ensure that comments work:
91 Ensure that comments work:
92
92
93 $ touch 'foo#bar' 'quux#'
93 $ touch 'foo#bar' 'quux#' 'quu0#'
94 #if no-windows
94 #if no-windows
95 $ touch 'baz\wat' 'ba0\#wat' 'ba1\\wat'
95 $ touch 'baz\' 'baz\wat' 'ba0\#wat' 'ba1\\' 'ba1\\wat' 'quu0\'
96 #endif
96 #endif
97
97 $ cat <<'EOF' >> .hgignore
98 $ cat <<'EOF' >> .hgignore
98 > # full-line comment
99 > # full-line comment
99 > # whitespace-only comment line
100 > # whitespace-only comment line
100 > syntax# pattern, no whitespace, then comment
101 > syntax# pattern, no whitespace, then comment
101 > a.c # pattern, then whitespace, then comment
102 > a.c # pattern, then whitespace, then comment
102 > baz\\# # (escaped) backslash, then comment
103 > baz\\# # (escaped) backslash, then comment
103 > ba0\\\#w # (escaped) backslash, escaped comment character, then comment
104 > ba0\\\#w # (escaped) backslash, escaped comment character, then comment
104 > ba1\\\\# # (escaped) backslashes, then comment
105 > ba1\\\\# # (escaped) backslashes, then comment
105 > foo\#b # escaped comment character
106 > foo\#b # escaped comment character
106 > quux\## escaped comment character at end of name
107 > quux\## escaped comment character at end of name
107 > EOF
108 > EOF
108 $ hg status
109 $ hg status
109 A dir/b.o
110 A dir/b.o
110 ? .hgignore
111 ? .hgignore
111 $ rm 'foo#bar' 'quux#'
112 ? quu0#
113 ? quu0\ (no-windows !)
114
115 $ cat <<'EOF' > .hgignore
116 > .*\.o
117 > syntax: glob
118 > syntax# pattern, no whitespace, then comment
119 > a.c # pattern, then whitespace, then comment
120 > baz\\#* # (escaped) backslash, then comment
121 > ba0\\\#w* # (escaped) backslash, escaped comment character, then comment
122 > ba1\\\\#* # (escaped) backslashes, then comment
123 > foo\#b* # escaped comment character
124 > quux\## escaped comment character at end of name
125 > quu0[\#]# escaped comment character inside [...]
126 > EOF
127 $ hg status
128 A dir/b.o
129 ? .hgignore
130 ? ba1\\wat (no-windows !)
131 ? baz\wat (no-windows !)
132 ? quu0\ (no-windows !)
133
134 $ rm 'foo#bar' 'quux#' 'quu0#'
112 #if no-windows
135 #if no-windows
113 $ rm 'baz\wat' 'ba0\#wat' 'ba1\\wat'
136 $ rm 'baz\' 'baz\wat' 'ba0\#wat' 'ba1\\' 'ba1\\wat' 'quu0\'
114 #endif
137 #endif
115
138
116 Check that '^\.' does not ignore the root directory:
139 Check that '^\.' does not ignore the root directory:
117
140
118 $ echo "^\." > .hgignore
141 $ echo "^\." > .hgignore
119 $ hg status
142 $ hg status
120 A dir/b.o
143 A dir/b.o
121 ? a.c
144 ? a.c
122 ? a.o
145 ? a.o
123 ? dir/c.o
146 ? dir/c.o
124 ? syntax
147 ? syntax
125
148
126 Test that patterns from ui.ignore options are read:
149 Test that patterns from ui.ignore options are read:
127
150
128 $ echo > .hgignore
151 $ echo > .hgignore
129 $ cat >> $HGRCPATH << EOF
152 $ cat >> $HGRCPATH << EOF
130 > [ui]
153 > [ui]
131 > ignore.other = $TESTTMP/ignorerepo/.hg/testhgignore
154 > ignore.other = $TESTTMP/ignorerepo/.hg/testhgignore
132 > EOF
155 > EOF
133 $ echo "glob:**.o" > .hg/testhgignore
156 $ echo "glob:**.o" > .hg/testhgignore
134 $ hg status
157 $ hg status
135 A dir/b.o
158 A dir/b.o
136 ? .hgignore
159 ? .hgignore
137 ? a.c
160 ? a.c
138 ? syntax
161 ? syntax
139
162
140 empty out testhgignore
163 empty out testhgignore
141 $ echo > .hg/testhgignore
164 $ echo > .hg/testhgignore
142
165
143 Test relative ignore path (issue4473):
166 Test relative ignore path (issue4473):
144
167
145 $ cat >> $HGRCPATH << EOF
168 $ cat >> $HGRCPATH << EOF
146 > [ui]
169 > [ui]
147 > ignore.relative = .hg/testhgignorerel
170 > ignore.relative = .hg/testhgignorerel
148 > EOF
171 > EOF
149 $ echo "glob:*.o" > .hg/testhgignorerel
172 $ echo "glob:*.o" > .hg/testhgignorerel
150 $ cd dir
173 $ cd dir
151 $ hg status
174 $ hg status
152 A dir/b.o
175 A dir/b.o
153 ? .hgignore
176 ? .hgignore
154 ? a.c
177 ? a.c
155 ? syntax
178 ? syntax
156
179
157 $ cd ..
180 $ cd ..
158 $ echo > .hg/testhgignorerel
181 $ echo > .hg/testhgignorerel
159 $ echo "syntax: glob" > .hgignore
182 $ echo "syntax: glob" > .hgignore
160 $ echo "re:.*\.o" >> .hgignore
183 $ echo "re:.*\.o" >> .hgignore
161 $ hg status
184 $ hg status
162 A dir/b.o
185 A dir/b.o
163 ? .hgignore
186 ? .hgignore
164 ? a.c
187 ? a.c
165 ? syntax
188 ? syntax
166
189
167 $ echo "syntax: invalid" > .hgignore
190 $ echo "syntax: invalid" > .hgignore
168 $ hg status
191 $ hg status
169 $TESTTMP/ignorerepo/.hgignore: ignoring invalid syntax 'invalid'
192 $TESTTMP/ignorerepo/.hgignore: ignoring invalid syntax 'invalid'
170 A dir/b.o
193 A dir/b.o
171 ? .hgignore
194 ? .hgignore
172 ? a.c
195 ? a.c
173 ? a.o
196 ? a.o
174 ? dir/c.o
197 ? dir/c.o
175 ? syntax
198 ? syntax
176
199
177 $ echo "syntax: glob" > .hgignore
200 $ echo "syntax: glob" > .hgignore
178 $ echo "*.o" >> .hgignore
201 $ echo "*.o" >> .hgignore
179 $ hg status
202 $ hg status
180 A dir/b.o
203 A dir/b.o
181 ? .hgignore
204 ? .hgignore
182 ? a.c
205 ? a.c
183 ? syntax
206 ? syntax
184
207
185 $ echo "relglob:syntax*" > .hgignore
208 $ echo "relglob:syntax*" > .hgignore
186 $ hg status
209 $ hg status
187 A dir/b.o
210 A dir/b.o
188 ? .hgignore
211 ? .hgignore
189 ? a.c
212 ? a.c
190 ? a.o
213 ? a.o
191 ? dir/c.o
214 ? dir/c.o
192
215
193 $ echo "relglob:*" > .hgignore
216 $ echo "relglob:*" > .hgignore
194 $ hg status
217 $ hg status
195 A dir/b.o
218 A dir/b.o
196
219
197 $ cd dir
220 $ cd dir
198 $ hg status .
221 $ hg status .
199 A b.o
222 A b.o
200
223
201 $ hg debugignore
224 $ hg debugignore
202 <includematcher includes='(?:|.*/)[^/]*(?:/|$)'>
225 <includematcher includes='(?:|.*/)[^/]*(?:/|$)'>
203
226
204 $ hg debugignore b.o
227 $ hg debugignore b.o
205 b.o is ignored
228 b.o is ignored
206 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: '*') (glob)
229 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: '*') (glob)
207
230
208 $ cd ..
231 $ cd ..
209
232
210 Check patterns that match only the directory
233 Check patterns that match only the directory
211
234
212 "(fsmonitor !)" below assumes that fsmonitor is enabled with
235 "(fsmonitor !)" below assumes that fsmonitor is enabled with
213 "walk_on_invalidate = false" (default), which doesn't involve
236 "walk_on_invalidate = false" (default), which doesn't involve
214 re-walking whole repository at detection of .hgignore change.
237 re-walking whole repository at detection of .hgignore change.
215
238
216 $ echo "^dir\$" > .hgignore
239 $ echo "^dir\$" > .hgignore
217 $ hg status
240 $ hg status
218 A dir/b.o
241 A dir/b.o
219 ? .hgignore
242 ? .hgignore
220 ? a.c
243 ? a.c
221 ? a.o
244 ? a.o
222 ? dir/c.o (fsmonitor !)
245 ? dir/c.o (fsmonitor !)
223 ? syntax
246 ? syntax
224
247
225 Check recursive glob pattern matches no directories (dir/**/c.o matches dir/c.o)
248 Check recursive glob pattern matches no directories (dir/**/c.o matches dir/c.o)
226
249
227 $ echo "syntax: glob" > .hgignore
250 $ echo "syntax: glob" > .hgignore
228 $ echo "dir/**/c.o" >> .hgignore
251 $ echo "dir/**/c.o" >> .hgignore
229 $ touch dir/c.o
252 $ touch dir/c.o
230 $ mkdir dir/subdir
253 $ mkdir dir/subdir
231 $ touch dir/subdir/c.o
254 $ touch dir/subdir/c.o
232 $ hg status
255 $ hg status
233 A dir/b.o
256 A dir/b.o
234 ? .hgignore
257 ? .hgignore
235 ? a.c
258 ? a.c
236 ? a.o
259 ? a.o
237 ? syntax
260 ? syntax
238 $ hg debugignore a.c
261 $ hg debugignore a.c
239 a.c is not ignored
262 a.c is not ignored
240 $ hg debugignore dir/c.o
263 $ hg debugignore dir/c.o
241 dir/c.o is ignored
264 dir/c.o is ignored
242 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 2: 'dir/**/c.o') (glob)
265 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 2: 'dir/**/c.o') (glob)
243
266
244 Check rooted globs
267 Check rooted globs
245
268
246 $ hg purge --all --config extensions.purge=
269 $ hg purge --all --config extensions.purge=
247 $ echo "syntax: rootglob" > .hgignore
270 $ echo "syntax: rootglob" > .hgignore
248 $ echo "a/*.ext" >> .hgignore
271 $ echo "a/*.ext" >> .hgignore
249 $ for p in a b/a aa; do mkdir -p $p; touch $p/b.ext; done
272 $ for p in a b/a aa; do mkdir -p $p; touch $p/b.ext; done
250 $ hg status -A 'set:**.ext'
273 $ hg status -A 'set:**.ext'
251 ? aa/b.ext
274 ? aa/b.ext
252 ? b/a/b.ext
275 ? b/a/b.ext
253 I a/b.ext
276 I a/b.ext
254
277
255 Check using 'include:' in ignore file
278 Check using 'include:' in ignore file
256
279
257 $ hg purge --all --config extensions.purge=
280 $ hg purge --all --config extensions.purge=
258 $ touch foo.included
281 $ touch foo.included
259
282
260 $ echo ".*.included" > otherignore
283 $ echo ".*.included" > otherignore
261 $ hg status -I "include:otherignore"
284 $ hg status -I "include:otherignore"
262 ? foo.included
285 ? foo.included
263
286
264 $ echo "include:otherignore" >> .hgignore
287 $ echo "include:otherignore" >> .hgignore
265 $ hg status
288 $ hg status
266 A dir/b.o
289 A dir/b.o
267 ? .hgignore
290 ? .hgignore
268 ? otherignore
291 ? otherignore
269
292
270 Check recursive uses of 'include:'
293 Check recursive uses of 'include:'
271
294
272 $ echo "include:nested/ignore" >> otherignore
295 $ echo "include:nested/ignore" >> otherignore
273 $ mkdir nested nested/more
296 $ mkdir nested nested/more
274 $ echo "glob:*ignore" > nested/ignore
297 $ echo "glob:*ignore" > nested/ignore
275 $ echo "rootglob:a" >> nested/ignore
298 $ echo "rootglob:a" >> nested/ignore
276 $ touch a nested/a nested/more/a
299 $ touch a nested/a nested/more/a
277 $ hg status
300 $ hg status
278 A dir/b.o
301 A dir/b.o
279 ? nested/a
302 ? nested/a
280 ? nested/more/a
303 ? nested/more/a
281 $ rm a nested/a nested/more/a
304 $ rm a nested/a nested/more/a
282
305
283 $ cp otherignore goodignore
306 $ cp otherignore goodignore
284 $ echo "include:badignore" >> otherignore
307 $ echo "include:badignore" >> otherignore
285 $ hg status
308 $ hg status
286 skipping unreadable pattern file 'badignore': $ENOENT$
309 skipping unreadable pattern file 'badignore': $ENOENT$
287 A dir/b.o
310 A dir/b.o
288
311
289 $ mv goodignore otherignore
312 $ mv goodignore otherignore
290
313
291 Check using 'include:' while in a non-root directory
314 Check using 'include:' while in a non-root directory
292
315
293 $ cd ..
316 $ cd ..
294 $ hg -R ignorerepo status
317 $ hg -R ignorerepo status
295 A dir/b.o
318 A dir/b.o
296 $ cd ignorerepo
319 $ cd ignorerepo
297
320
298 Check including subincludes
321 Check including subincludes
299
322
300 $ hg revert -q --all
323 $ hg revert -q --all
301 $ hg purge --all --config extensions.purge=
324 $ hg purge --all --config extensions.purge=
302 $ echo ".hgignore" > .hgignore
325 $ echo ".hgignore" > .hgignore
303 $ mkdir dir1 dir2
326 $ mkdir dir1 dir2
304 $ touch dir1/file1 dir1/file2 dir2/file1 dir2/file2
327 $ touch dir1/file1 dir1/file2 dir2/file1 dir2/file2
305 $ echo "subinclude:dir2/.hgignore" >> .hgignore
328 $ echo "subinclude:dir2/.hgignore" >> .hgignore
306 $ echo "glob:file*2" > dir2/.hgignore
329 $ echo "glob:file*2" > dir2/.hgignore
307 $ hg status
330 $ hg status
308 ? dir1/file1
331 ? dir1/file1
309 ? dir1/file2
332 ? dir1/file2
310 ? dir2/file1
333 ? dir2/file1
311
334
312 Check including subincludes with other patterns
335 Check including subincludes with other patterns
313
336
314 $ echo "subinclude:dir1/.hgignore" >> .hgignore
337 $ echo "subinclude:dir1/.hgignore" >> .hgignore
315
338
316 $ mkdir dir1/subdir
339 $ mkdir dir1/subdir
317 $ touch dir1/subdir/file1
340 $ touch dir1/subdir/file1
318 $ echo "rootglob:f?le1" > dir1/.hgignore
341 $ echo "rootglob:f?le1" > dir1/.hgignore
319 $ hg status
342 $ hg status
320 ? dir1/file2
343 ? dir1/file2
321 ? dir1/subdir/file1
344 ? dir1/subdir/file1
322 ? dir2/file1
345 ? dir2/file1
323 $ rm dir1/subdir/file1
346 $ rm dir1/subdir/file1
324
347
325 $ echo "regexp:f.le1" > dir1/.hgignore
348 $ echo "regexp:f.le1" > dir1/.hgignore
326 $ hg status
349 $ hg status
327 ? dir1/file2
350 ? dir1/file2
328 ? dir2/file1
351 ? dir2/file1
329
352
330 Check multiple levels of sub-ignores
353 Check multiple levels of sub-ignores
331
354
332 $ touch dir1/subdir/subfile1 dir1/subdir/subfile3 dir1/subdir/subfile4
355 $ touch dir1/subdir/subfile1 dir1/subdir/subfile3 dir1/subdir/subfile4
333 $ echo "subinclude:subdir/.hgignore" >> dir1/.hgignore
356 $ echo "subinclude:subdir/.hgignore" >> dir1/.hgignore
334 $ echo "glob:subfil*3" >> dir1/subdir/.hgignore
357 $ echo "glob:subfil*3" >> dir1/subdir/.hgignore
335
358
336 $ hg status
359 $ hg status
337 ? dir1/file2
360 ? dir1/file2
338 ? dir1/subdir/subfile4
361 ? dir1/subdir/subfile4
339 ? dir2/file1
362 ? dir2/file1
340
363
341 Check include subignore at the same level
364 Check include subignore at the same level
342
365
343 $ mv dir1/subdir/.hgignore dir1/.hgignoretwo
366 $ mv dir1/subdir/.hgignore dir1/.hgignoretwo
344 $ echo "regexp:f.le1" > dir1/.hgignore
367 $ echo "regexp:f.le1" > dir1/.hgignore
345 $ echo "subinclude:.hgignoretwo" >> dir1/.hgignore
368 $ echo "subinclude:.hgignoretwo" >> dir1/.hgignore
346 $ echo "glob:file*2" > dir1/.hgignoretwo
369 $ echo "glob:file*2" > dir1/.hgignoretwo
347
370
348 $ hg status | grep file2
371 $ hg status | grep file2
349 [1]
372 [1]
350 $ hg debugignore dir1/file2
373 $ hg debugignore dir1/file2
351 dir1/file2 is ignored
374 dir1/file2 is ignored
352 (ignore rule in dir2/.hgignore, line 1: 'file*2')
375 (ignore rule in dir2/.hgignore, line 1: 'file*2')
353
376
354 #if windows
377 #if windows
355
378
356 Windows paths are accepted on input
379 Windows paths are accepted on input
357
380
358 $ rm dir1/.hgignore
381 $ rm dir1/.hgignore
359 $ echo "dir1/file*" >> .hgignore
382 $ echo "dir1/file*" >> .hgignore
360 $ hg debugignore "dir1\file2"
383 $ hg debugignore "dir1\file2"
361 dir1/file2 is ignored
384 dir1/file2 is ignored
362 (ignore rule in $TESTTMP\ignorerepo\.hgignore, line 4: 'dir1/file*')
385 (ignore rule in $TESTTMP\ignorerepo\.hgignore, line 4: 'dir1/file*')
363 $ hg up -qC .
386 $ hg up -qC .
364
387
365 #endif
388 #endif
General Comments 0
You need to be logged in to leave comments. Login now