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