Debian Codegraph @

tests/test-hgignore.t

raw
1 #testcases dirstate-v1 dirstate-v2
2
3 #if dirstate-v2
4 $ cat >> $HGRCPATH << EOF
5 > [format]
6 > use-dirstate-v2=1
7 > [storage]
8 > dirstate-v2.slow-path=allow
9 > EOF
10 #endif
11
12 $ hg init ignorerepo
13 $ cd ignorerepo
14
15 debugignore with no hgignore should be deterministic:
16 $ hg debugignore
17 <nevermatcher>
18
19 #if rhg
20 $ rhg_debugignore() {
21 > echo debugignorerhg:
22 > hg debugignorerhg
23 > echo script::hgignore --print-re:
24 > hg script::hgignore --print-re
25 > }
26 $ rhg_debugignore
27 debugignorerhg:
28 skipping unreadable pattern file '.hgignore': $ENOENT$
29 rootfilesin:
30 script::hgignore --print-re:
31 skipping unreadable pattern file '.hgignore': $ENOENT$
32 ^ ^
33 #endif
34
35 Issue562: .hgignore requires newline at end:
36
37 $ touch foo
38 $ touch bar
39 $ touch baz
40 $ cat > makeignore.py <<EOF
41 > f = open(".hgignore", "w")
42 > f.write("ignore\n")
43 > f.write("foo\n")
44 > # No EOL here
45 > f.write("bar")
46 > f.close()
47 > EOF
48
49 $ "$PYTHON" makeignore.py
50
51 Should display baz only:
52
53 $ hg status
54 ? baz
55
56 $ rm foo bar baz .hgignore makeignore.py
57
58 $ touch a.o
59 $ touch a.c
60 $ touch syntax
61 $ mkdir dir
62 $ touch dir/a.o
63 $ touch dir/b.o
64 $ touch dir/c.o
65
66 $ hg add dir/a.o
67 $ hg commit -m 0
68 $ hg add dir/b.o
69
70 $ hg status
71 A dir/b.o
72 ? a.c
73 ? a.o
74 ? dir/c.o
75 ? syntax
76
77 $ echo "*.o" > .hgignore
78 $ hg status
79 abort: $TESTTMP/ignorerepo/.hgignore: invalid pattern (relre): *.o (glob)
80 [255]
81
82 Test relre with flags (issue6759)
83 ---------------------------------
84
85 regexp with flag is the first one
86
87 $ echo 're:(?i)\.O$' > .hgignore
88 $ echo 're:.hgignore' >> .hgignore
89 $ hg status
90 A dir/b.o
91 ? a.c
92 ? syntax
93 $ hg debugignore
94 <includematcher includes='(?i:.*\\.O$)|.*.hgignore'>
95
96 #if rhg
97 $ rhg_debugignore
98 debugignorerhg:
99 (?:\\A[\x00- \x0b-\xf4\x8f\xbf\xbf]*(?:(?:\\.[Oo]\\z)|(?:[\x00- \x0b-\xf4\x8f\xbf\xbf](?:hgignore)))) (esc)
100 script::hgignore --print-re:
101 ^(?:(?i:.*\.O$)|.*.hgignore)
102 #endif
103
104 regex with flag is not the first one
105
106 $ echo 're:.hgignore' > .hgignore
107 $ echo 're:(?i)\.O$' >> .hgignore
108 $ hg status
109 A dir/b.o
110 ? a.c
111 ? syntax
112 $ hg debugignore
113 <includematcher includes='.*.hgignore|(?i:.*\\.O$)'>
114
115 #if rhg
116 $ rhg_debugignore
117 debugignorerhg:
118 (?:\\A[\x00- \x0b-\xf4\x8f\xbf\xbf]*(?:(?:[\x00- \x0b-\xf4\x8f\xbf\xbf](?:hgignore))|(?:\\.[Oo]\\z))) (esc)
119 script::hgignore --print-re:
120 ^(?:.*.hgignore|(?i:.*\.O$))
121 #endif
122
123 flag in a pattern should affect that pattern only
124
125 $ echo 're:(?i)\.O$' > .hgignore
126 $ echo 're:.HGIGNORE' >> .hgignore
127 $ hg status
128 A dir/b.o
129 ? .hgignore
130 ? a.c
131 ? syntax
132 $ hg debugignore
133 <includematcher includes='(?i:.*\\.O$)|.*.HGIGNORE'>
134
135 #if rhg
136 $ rhg_debugignore
137 debugignorerhg:
138 (?:\\A[\x00- \x0b-\xf4\x8f\xbf\xbf]*(?:(?:\\.[Oo]\\z)|(?:[\x00- \x0b-\xf4\x8f\xbf\xbf](?:HGIGNORE)))) (esc)
139 script::hgignore --print-re:
140 ^(?:(?i:.*\.O$)|.*.HGIGNORE)
141 #endif
142
143 $ echo 're:.HGIGNORE' > .hgignore
144 $ echo 're:(?i)\.O$' >> .hgignore
145 $ hg status
146 A dir/b.o
147 ? .hgignore
148 ? a.c
149 ? syntax
150 $ hg debugignore
151 <includematcher includes='.*.HGIGNORE|(?i:.*\\.O$)'>
152
153 #if rhg
154 $ rhg_debugignore
155 debugignorerhg:
156 (?:\\A[\x00- \x0b-\xf4\x8f\xbf\xbf]*(?:(?:[\x00- \x0b-\xf4\x8f\xbf\xbf](?:HGIGNORE))|(?:\\.[Oo]\\z))) (esc)
157 script::hgignore --print-re:
158 ^(?:.*.HGIGNORE|(?i:.*\.O$))
159 #endif
160
161 Check that '^' after flag is properly detected.
162
163 $ echo 're:(?i)^[^a].*\.O$' > .hgignore
164 $ echo 're:.HGIGNORE' >> .hgignore
165 $ hg status
166 A dir/b.o
167 ? .hgignore
168 ? a.c
169 ? a.o
170 ? syntax
171 $ hg debugignore
172 <includematcher includes='(?i:^[^a].*\\.O$)|.*.HGIGNORE'>
173
174 #if rhg
175 $ rhg_debugignore
176 debugignorerhg:
177 (?:\\A(?:(?:\\A[\x00-@B-`b-\xf4\x8f\xbf\xbf][\x00- \x0b-\xf4\x8f\xbf\xbf]*\\.[Oo]\\z)|(?:[\x00- \x0b-\xf4\x8f\xbf\xbf]*[\x00- \x0b-\xf4\x8f\xbf\xbf](?:HGIGNORE)))) (esc)
178 script::hgignore --print-re:
179 ^(?:(?i:^[^a].*\.O$)|.*.HGIGNORE)
180 #endif
181
182 $ echo 're:.HGIGNORE' > .hgignore
183 $ echo 're:(?i)^[^a].*\.O$' >> .hgignore
184 $ hg status
185 A dir/b.o
186 ? .hgignore
187 ? a.c
188 ? a.o
189 ? syntax
190 $ hg debugignore
191 <includematcher includes='.*.HGIGNORE|(?i:^[^a].*\\.O$)'>
192
193 #if rhg
194 $ rhg_debugignore
195 debugignorerhg:
196 (?:\\A(?:(?:[\x00- \x0b-\xf4\x8f\xbf\xbf]*[\x00- \x0b-\xf4\x8f\xbf\xbf](?:HGIGNORE))|(?:\\A[\x00-@B-`b-\xf4\x8f\xbf\xbf][\x00- \x0b-\xf4\x8f\xbf\xbf]*\\.[Oo]\\z))) (esc)
197 script::hgignore --print-re:
198 ^(?:.*.HGIGNORE|(?i:^[^a].*\.O$))
199 #endif
200
201 further testing
202 ---------------
203
204 $ echo 're:^(?!a).*\.o$' > .hgignore
205 $ hg status
206 A dir/b.o
207 ? .hgignore
208 ? a.c
209 ? a.o
210 ? syntax
211 #if rhg
212 $ hg status --config rhg.on-unsupported=abort
213 unsupported feature: Unsupported syntax regex parse error:
214 ^(?!a).*\.o$
215 ^^^
216 error: look-around, including look-ahead and look-behind, is not supported
217 [252]
218 #endif
219
220 Ensure given files are relative to cwd
221
222 $ echo "dir/.*\.o" > .hgignore
223 $ hg status -i
224 I dir/c.o
225
226 $ hg debugignore dir/c.o dir/missing.o
227 dir/c.o is ignored
228 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
229 dir/missing.o is ignored
230 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
231 $ cd dir
232 $ hg debugignore c.o missing.o
233 c.o is ignored
234 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
235 missing.o is ignored
236 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
237
238 For icasefs, inexact matches also work, except for missing files
239
240 #if icasefs
241 $ hg debugignore c.O missing.O
242 c.o is ignored
243 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
244 missing.O is not ignored
245 #endif
246
247 $ cd ..
248
249 $ echo ".*\.o" > .hgignore
250 $ hg status
251 A dir/b.o
252 ? .hgignore
253 ? a.c
254 ? syntax
255
256 Ensure that comments work:
257
258 $ touch 'foo#bar' 'quux#' 'quu0#'
259 #if no-windows
260 $ touch 'baz\' 'baz\wat' 'ba0\#wat' 'ba1\\' 'ba1\\wat' 'quu0\'
261 #endif
262
263 $ cat <<'EOF' >> .hgignore
264 > # full-line comment
265 > # whitespace-only comment line
266 > syntax# pattern, no whitespace, then comment
267 > a.c # pattern, then whitespace, then comment
268 > baz\\# # (escaped) backslash, then comment
269 > ba0\\\#w # (escaped) backslash, escaped comment character, then comment
270 > ba1\\\\# # (escaped) backslashes, then comment
271 > foo\#b # escaped comment character
272 > quux\## escaped comment character at end of name
273 > EOF
274 $ hg status
275 A dir/b.o
276 ? .hgignore
277 ? quu0#
278 ? quu0\ (no-windows !)
279
280 $ cat <<'EOF' > .hgignore
281 > .*\.o
282 > syntax: glob
283 > syntax# pattern, no whitespace, then comment
284 > a.c # pattern, then whitespace, then comment
285 > baz\\#* # (escaped) backslash, then comment
286 > ba0\\\#w* # (escaped) backslash, escaped comment character, then comment
287 > ba1\\\\#* # (escaped) backslashes, then comment
288 > foo\#b* # escaped comment character
289 > quux\## escaped comment character at end of name
290 > quu0[\#]# escaped comment character inside [...]
291 > EOF
292 $ hg status
293 A dir/b.o
294 ? .hgignore
295 ? ba1\\wat (no-windows !)
296 ? baz\wat (no-windows !)
297 ? quu0\ (no-windows !)
298
299 $ rm 'foo#bar' 'quux#' 'quu0#'
300 #if no-windows
301 $ rm 'baz\' 'baz\wat' 'ba0\#wat' 'ba1\\' 'ba1\\wat' 'quu0\'
302 #endif
303
304 Check that '^\.' does not ignore the root directory:
305
306 $ echo "^\." > .hgignore
307 $ hg status
308 A dir/b.o
309 ? a.c
310 ? a.o
311 ? dir/c.o
312 ? syntax
313
314 Test that patterns from ui.ignore options are read:
315
316 $ echo > .hgignore
317 $ cat >> $HGRCPATH << EOF
318 > [ui]
319 > ignore.other = $TESTTMP/ignorerepo/.hg/testhgignore
320 > EOF
321 $ echo "glob:**.o" > .hg/testhgignore
322 $ hg status
323 A dir/b.o
324 ? .hgignore
325 ? a.c
326 ? syntax
327
328 empty out testhgignore
329 $ echo > .hg/testhgignore
330
331 Test relative ignore path (issue4473):
332
333 $ cat >> $HGRCPATH << EOF
334 > [ui]
335 > ignore.relative = .hg/testhgignorerel
336 > EOF
337 $ echo "glob:*.o" > .hg/testhgignorerel
338 $ cd dir
339 $ hg status
340 A dir/b.o
341 ? .hgignore
342 ? a.c
343 ? syntax
344 $ hg debugignore
345 <includematcher includes='.*\\.o(?:/|$)'>
346
347 $ cd ..
348 $ echo > .hg/testhgignorerel
349 $ echo "syntax: glob" > .hgignore
350 $ echo "re:.*\.o" >> .hgignore
351 $ hg status
352 A dir/b.o
353 ? .hgignore
354 ? a.c
355 ? syntax
356
357 $ echo "syntax: invalid" > .hgignore
358 $ hg status
359 $TESTTMP/ignorerepo/.hgignore: ignoring invalid syntax 'invalid'
360 A dir/b.o
361 ? .hgignore
362 ? a.c
363 ? a.o
364 ? dir/c.o
365 ? syntax
366
367 $ echo "syntax: glob" > .hgignore
368 $ echo "*.o" >> .hgignore
369 $ hg status
370 A dir/b.o
371 ? .hgignore
372 ? a.c
373 ? syntax
374
375 $ echo "relglob:syntax*" > .hgignore
376 $ hg status
377 A dir/b.o
378 ? .hgignore
379 ? a.c
380 ? a.o
381 ? dir/c.o
382
383 $ echo "rootglob:dir/b.o" > .hgignore
384 $ hg status
385 A dir/b.o
386 ? .hgignore
387 ? a.c
388 ? a.o
389 ? dir/c.o
390 ? syntax
391 #if rhg
392 $ rhg_debugignore
393 debugignorerhg:
394 (?:\A[a&&b])
395 script::hgignore --print-re:
396 ^(?:dir/b\.o(?:/|$))
397 #endif
398
399 $ echo "relglob:*" > .hgignore
400 $ hg status
401 A dir/b.o
402
403 $ cd dir
404 $ hg status .
405 A b.o
406
407 $ hg debugignore
408 <includematcher includes='.*(?:/|$)'>
409
410 #if rhg
411 $ rhg_debugignore
412 debugignorerhg:
413 (?:\A(?-u:[\x00-\xFF])*?(?:/|\z))
414 script::hgignore --print-re:
415 ^(?:.*(?:/|$))
416 #endif
417
418 $ hg debugignore b.o
419 b.o is ignored
420 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: '*') (glob)
421
422 $ cd ..
423
424 Check patterns that match only the directory
425
426 "(fsmonitor !)" below assumes that fsmonitor is enabled with
427 "walk_on_invalidate = false" (default), which doesn't involve
428 re-walking whole repository at detection of .hgignore change.
429
430 $ echo "^dir\$" > .hgignore
431 $ hg status
432 A dir/b.o
433 ? .hgignore
434 ? a.c
435 ? a.o
436 ? dir/c.o (fsmonitor !)
437 ? syntax
438
439 Check recursive glob pattern matches no directories (dir/**/c.o matches dir/c.o)
440
441 $ echo "syntax: glob" > .hgignore
442 $ echo "dir/**/c.o" >> .hgignore
443 $ touch dir/c.o
444 $ mkdir dir/subdir
445 $ touch dir/subdir/c.o
446 $ hg status
447 A dir/b.o
448 ? .hgignore
449 ? a.c
450 ? a.o
451 ? syntax
452 $ hg debugignore a.c
453 a.c is not ignored
454 $ hg debugignore dir/c.o
455 dir/c.o is ignored
456 (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 2: 'dir/**/c.o') (glob)
457
458 Check rooted globs
459
460 $ hg purge --all --config extensions.purge=
461 $ echo "syntax: rootglob" > .hgignore
462 $ echo "a/*.ext" >> .hgignore
463 $ for p in a b/a aa; do mkdir -p $p; touch $p/b.ext; done
464 $ hg status -A 'set:**.ext'
465 ? aa/b.ext
466 ? b/a/b.ext
467 I a/b.ext
468
469 Check using 'include:' in ignore file
470
471 $ hg purge --all --config extensions.purge=
472 $ touch foo.included
473
474 $ echo ".*.included" > otherignore
475 $ hg status -I "include:otherignore"
476 ? foo.included
477
478 $ echo "include:otherignore" >> .hgignore
479 $ hg status
480 A dir/b.o
481 ? .hgignore
482 ? otherignore
483
484 Check recursive uses of 'include:'
485
486 $ echo "include:nested/ignore" >> otherignore
487 $ mkdir nested nested/more
488 $ echo "glob:*ignore" > nested/ignore
489 $ echo "rootglob:a" >> nested/ignore
490 $ touch a nested/a nested/more/a
491 $ hg status
492 A dir/b.o
493 ? nested/a
494 ? nested/more/a
495 $ rm a nested/a nested/more/a
496
497 $ cp otherignore goodignore
498 $ echo "include:badignore" >> otherignore
499 $ hg status
500 skipping unreadable pattern file 'badignore': $ENOENT$
501 A dir/b.o
502
503 $ mv goodignore otherignore
504
505 Check using 'include:' while in a non-root directory
506
507 $ cd ..
508 $ hg -R ignorerepo status
509 A dir/b.o
510 $ cd ignorerepo
511
512 Check including subincludes
513
514 $ hg revert -q --all
515 $ hg purge --all --config extensions.purge=
516 $ echo ".hgignore" > .hgignore
517 $ mkdir dir1 dir2
518 $ touch dir1/file1 dir1/file2 dir2/file1 dir2/file2
519 $ echo "subinclude:dir2/.hgignore" >> .hgignore
520 $ echo "glob:file*2" > dir2/.hgignore
521 $ hg status
522 ? dir1/file1
523 ? dir1/file2
524 ? dir2/file1
525
526 Check including subincludes with other patterns
527
528 $ echo "subinclude:dir1/.hgignore" >> .hgignore
529
530 $ mkdir dir1/subdir
531 $ touch dir1/subdir/file1
532 $ echo "rootglob:f?le1" > dir1/.hgignore
533 $ hg status
534 ? dir1/file2
535 ? dir1/subdir/file1
536 ? dir2/file1
537 $ rm dir1/subdir/file1
538
539 $ echo "regexp:f.le1" > dir1/.hgignore
540 $ hg status
541 ? dir1/file2
542 ? dir2/file1
543
544 Check multiple levels of sub-ignores
545
546 $ touch dir1/subdir/subfile1 dir1/subdir/subfile3 dir1/subdir/subfile4
547 $ echo "subinclude:subdir/.hgignore" >> dir1/.hgignore
548 $ echo "glob:subfil*3" >> dir1/subdir/.hgignore
549
550 $ hg status
551 ? dir1/file2
552 ? dir1/subdir/subfile4
553 ? dir2/file1
554
555 Check include subignore at the same level
556
557 $ mv dir1/subdir/.hgignore dir1/.hgignoretwo
558 $ echo "regexp:f.le1" > dir1/.hgignore
559 $ echo "subinclude:.hgignoretwo" >> dir1/.hgignore
560 $ echo "glob:file*2" > dir1/.hgignoretwo
561
562 $ hg status | grep file2
563 [1]
564 $ hg debugignore dir1/file2
565 dir1/file2 is ignored
566 (ignore rule in dir2/.hgignore, line 1: 'file*2')
567
568 #if windows
569
570 Windows paths are accepted on input
571
572 $ rm dir1/.hgignore
573 $ echo "dir1/file*" >> .hgignore
574 $ hg debugignore "dir1\file2"
575 dir1/file2 is ignored
576 (ignore rule in $TESTTMP\ignorerepo\.hgignore, line 4: 'dir1/file*')
577 $ hg up -qC .
578
579 #endif
580
581 #if dirstate-v2 rust
582
583 Check the hash of ignore patterns written in the dirstate
584 This is an optimization that is only relevant when using the Rust extensions
585
586 $ cat_filename_and_hash () {
587 > for i in "$@"; do
588 > printf "$i "
589 > cat "$i" | "$TESTDIR"/f --raw-sha1 | sed 's/^raw-sha1=//'
590 > done
591 > }
592 $ hg status > /dev/null
593 $ cat_filename_and_hash .hg/testhgignore .hg/testhgignorerel .hgignore dir2/.hgignore dir1/.hgignore dir1/.hgignoretwo | $TESTDIR/f --sha1
594 sha1=c0beb296395d48ced8e14f39009c4ea6e409bfe6
595 $ hg debugstate --docket | grep ignore
596 ignore pattern hash: c0beb296395d48ced8e14f39009c4ea6e409bfe6
597
598 $ echo rel > .hg/testhgignorerel
599 $ hg status > /dev/null
600 $ cat_filename_and_hash .hg/testhgignore .hg/testhgignorerel .hgignore dir2/.hgignore dir1/.hgignore dir1/.hgignoretwo | $TESTDIR/f --sha1
601 sha1=b8e63d3428ec38abc68baa27631516d5ec46b7fa
602 $ hg debugstate --docket | grep ignore
603 ignore pattern hash: b8e63d3428ec38abc68baa27631516d5ec46b7fa
604 $ cd ..
605
606 Check that the hash depends on the source of the hgignore patterns
607 (otherwise the context is lost and things like subinclude are cached improperly)
608
609 $ hg init ignore-collision
610 $ cd ignore-collision
611 $ echo > .hg/testhgignorerel
612
613 $ mkdir dir1/ dir1/subdir
614 $ touch dir1/subdir/f dir1/subdir/ignored1
615 $ echo 'ignored1' > dir1/.hgignore
616
617 $ mkdir dir2 dir2/subdir
618 $ touch dir2/subdir/f dir2/subdir/ignored2
619 $ echo 'ignored2' > dir2/.hgignore
620 $ echo 'subinclude:dir2/.hgignore' >> .hgignore
621 $ echo 'subinclude:dir1/.hgignore' >> .hgignore
622
623 $ hg commit -Aqm_
624
625 $ > dir1/.hgignore
626 $ echo 'ignored' > dir2/.hgignore
627 $ echo 'ignored1' >> dir2/.hgignore
628 $ hg status
629 M dir1/.hgignore
630 M dir2/.hgignore
631 ? dir1/subdir/ignored1
632
633 #endif