test-hgignore.t 9.18 KB
Newer Older
1
#testcases dirstate-v1 dirstate-v2
2

3
4
5
6
7
#if dirstate-v2
  $ echo '[format]' >> $HGRCPATH
  $ echo 'exp-dirstate-v2=1' >> $HGRCPATH
#endif

8
9
  $ hg init ignorerepo
  $ cd ignorerepo
Adrian Buehlmann's avatar
Adrian Buehlmann committed
10

11
12
13
14
debugignore with no hgignore should be deterministic:
  $ hg debugignore
  <nevermatcher>

15
Issue562: .hgignore requires newline at end:
Adrian Buehlmann's avatar
Adrian Buehlmann committed
16
17
18
19
20
21
22
23
24
25
26
27
28

  $ touch foo
  $ touch bar
  $ touch baz
  $ cat > makeignore.py <<EOF
  > f = open(".hgignore", "w")
  > f.write("ignore\n")
  > f.write("foo\n")
  > # No EOL here
  > f.write("bar")
  > f.close()
  > EOF

Matt Harbison's avatar
Matt Harbison committed
29
  $ "$PYTHON" makeignore.py
Adrian Buehlmann's avatar
Adrian Buehlmann committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

Should display baz only:

  $ hg status
  ? baz

  $ rm foo bar baz .hgignore makeignore.py

  $ touch a.o
  $ touch a.c
  $ touch syntax
  $ mkdir dir
  $ touch dir/a.o
  $ touch dir/b.o
  $ touch dir/c.o

  $ hg add dir/a.o
  $ hg commit -m 0
  $ hg add dir/b.o

  $ hg status
  A dir/b.o
  ? a.c
  ? a.o
  ? dir/c.o
  ? syntax

  $ echo "*.o" > .hgignore
58
  $ hg status
59
  abort: $TESTTMP/ignorerepo/.hgignore: invalid pattern (relre): *.o (glob)
60
  [255]
Adrian Buehlmann's avatar
Adrian Buehlmann committed
61

62
63
64
65
66
67
68
Ensure given files are relative to cwd

  $ echo "dir/.*\.o" > .hgignore
  $ hg status -i
  I dir/c.o

  $ hg debugignore dir/c.o dir/missing.o
69
  dir/c.o is ignored
70
  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
71
  dir/missing.o is ignored
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
  $ cd dir
  $ hg debugignore c.o missing.o
  c.o is ignored
  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
  missing.o is ignored
  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)

For icasefs, inexact matches also work, except for missing files

#if icasefs
  $ hg debugignore c.O missing.O
  c.o is ignored
  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: 'dir/.*\.o') (glob)
  missing.O is not ignored
#endif

  $ cd ..

Adrian Buehlmann's avatar
Adrian Buehlmann committed
91
  $ echo ".*\.o" > .hgignore
92
  $ hg status
Adrian Buehlmann's avatar
Adrian Buehlmann committed
93
94
95
96
97
  A dir/b.o
  ? .hgignore
  ? a.c
  ? syntax

98
99
Ensure that comments work:

100
  $ touch 'foo#bar' 'quux#' 'quu0#'
101
#if no-windows
102
  $ touch 'baz\' 'baz\wat' 'ba0\#wat' 'ba1\\' 'ba1\\wat' 'quu0\'
103
#endif
104

105
106
107
108
109
  $ cat <<'EOF' >> .hgignore
  > # full-line comment
  >   # whitespace-only comment line
  > syntax# pattern, no whitespace, then comment
  > a.c  # pattern, then whitespace, then comment
110
  > baz\\# # (escaped) backslash, then comment
111
112
  > ba0\\\#w # (escaped) backslash, escaped comment character, then comment
  > ba1\\\\# # (escaped) backslashes, then comment
113
114
115
116
117
118
  > foo\#b # escaped comment character
  > quux\## escaped comment character at end of name
  > EOF
  $ hg status
  A dir/b.o
  ? .hgignore
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
  ? quu0#
  ? quu0\ (no-windows !)

  $ cat <<'EOF' > .hgignore
  > .*\.o
  > syntax: glob
  > syntax# pattern, no whitespace, then comment
  > a.c  # pattern, then whitespace, then comment
  > baz\\#* # (escaped) backslash, then comment
  > ba0\\\#w* # (escaped) backslash, escaped comment character, then comment
  > ba1\\\\#* # (escaped) backslashes, then comment
  > foo\#b* # escaped comment character
  > quux\## escaped comment character at end of name
  > quu0[\#]# escaped comment character inside [...]
  > EOF
  $ hg status
  A dir/b.o
  ? .hgignore
  ? ba1\\wat (no-windows !)
  ? baz\wat (no-windows !)
  ? quu0\ (no-windows !)

  $ rm 'foo#bar' 'quux#' 'quu0#'
142
#if no-windows
143
  $ rm 'baz\' 'baz\wat' 'ba0\#wat' 'ba1\\' 'ba1\\wat' 'quu0\'
144
#endif
145

146
Check that '^\.' does not ignore the root directory:
Adrian Buehlmann's avatar
Adrian Buehlmann committed
147
148
149
150
151
152
153
154
155

  $ echo "^\." > .hgignore
  $ hg status
  A dir/b.o
  ? a.c
  ? a.o
  ? dir/c.o
  ? syntax

156
157
158
159
160
Test that patterns from ui.ignore options are read:

  $ echo > .hgignore
  $ cat >> $HGRCPATH << EOF
  > [ui]
161
  > ignore.other = $TESTTMP/ignorerepo/.hg/testhgignore
162
163
  > EOF
  $ echo "glob:**.o" > .hg/testhgignore
Adrian Buehlmann's avatar
Adrian Buehlmann committed
164
165
166
167
168
169
  $ hg status
  A dir/b.o
  ? .hgignore
  ? a.c
  ? syntax

170
171
empty out testhgignore
  $ echo > .hg/testhgignore
172
173
174
175
176
177
178
179
180

Test relative ignore path (issue4473):

  $ cat >> $HGRCPATH << EOF
  > [ui]
  > ignore.relative = .hg/testhgignorerel
  > EOF
  $ echo "glob:*.o" > .hg/testhgignorerel
  $ cd dir
Adrian Buehlmann's avatar
Adrian Buehlmann committed
181
182
183
184
185
  $ hg status
  A dir/b.o
  ? .hgignore
  ? a.c
  ? syntax
186
  $ hg debugignore
187
  <includematcher includes='.*\\.o(?:/|$)'>
Adrian Buehlmann's avatar
Adrian Buehlmann committed
188

189
190
  $ cd ..
  $ echo > .hg/testhgignorerel
Adrian Buehlmann's avatar
Adrian Buehlmann committed
191
192
193
194
195
196
197
198
199
  $ echo "syntax: glob" > .hgignore
  $ echo "re:.*\.o" >> .hgignore
  $ hg status
  A dir/b.o
  ? .hgignore
  ? a.c
  ? syntax

  $ echo "syntax: invalid" > .hgignore
200
  $ hg status
201
  $TESTTMP/ignorerepo/.hgignore: ignoring invalid syntax 'invalid'
Adrian Buehlmann's avatar
Adrian Buehlmann committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
  A dir/b.o
  ? .hgignore
  ? a.c
  ? a.o
  ? dir/c.o
  ? syntax

  $ echo "syntax: glob" > .hgignore
  $ echo "*.o" >> .hgignore
  $ hg status
  A dir/b.o
  ? .hgignore
  ? a.c
  ? syntax

  $ echo "relglob:syntax*" > .hgignore
  $ hg status
  A dir/b.o
  ? .hgignore
  ? a.c
  ? a.o
  ? dir/c.o

  $ echo "relglob:*" > .hgignore
  $ hg status
  A dir/b.o

  $ cd dir
  $ hg status .
  A b.o

233
  $ hg debugignore
234
  <includematcher includes='.*(?:/|$)'>
kiilerix's avatar
kiilerix committed
235

236
237
  $ hg debugignore b.o
  b.o is ignored
238
  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 1: '*') (glob)
239

kiilerix's avatar
kiilerix committed
240
  $ cd ..
241
242
243

Check patterns that match only the directory

244
245
246
247
"(fsmonitor !)" below assumes that fsmonitor is enabled with
"walk_on_invalidate = false" (default), which doesn't involve
re-walking whole repository at detection of .hgignore change.

248
249
250
251
252
253
  $ echo "^dir\$" > .hgignore
  $ hg status
  A dir/b.o
  ? .hgignore
  ? a.c
  ? a.o
254
  ? dir/c.o (fsmonitor !)
255
  ? syntax
256
257
258
259
260
261
262
263
264
265
266
267
268
269

Check recursive glob pattern matches no directories (dir/**/c.o matches dir/c.o)

  $ echo "syntax: glob" > .hgignore
  $ echo "dir/**/c.o" >> .hgignore
  $ touch dir/c.o
  $ mkdir dir/subdir
  $ touch dir/subdir/c.o
  $ hg status
  A dir/b.o
  ? .hgignore
  ? a.c
  ? a.o
  ? syntax
270
271
272
  $ hg debugignore a.c
  a.c is not ignored
  $ hg debugignore dir/c.o
273
  dir/c.o is ignored
274
  (ignore rule in $TESTTMP/ignorerepo/.hgignore, line 2: 'dir/**/c.o') (glob)
Durham Goode's avatar
Durham Goode committed
275

276
277
278
279
280
281
282
283
284
285
286
Check rooted globs

  $ hg purge --all --config extensions.purge=
  $ echo "syntax: rootglob" > .hgignore
  $ echo "a/*.ext" >> .hgignore
  $ for p in a b/a aa; do mkdir -p $p; touch $p/b.ext; done
  $ hg status -A 'set:**.ext'
  ? aa/b.ext
  ? b/a/b.ext
  I a/b.ext

Durham Goode's avatar
Durham Goode committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
Check using 'include:' in ignore file

  $ hg purge --all --config extensions.purge=
  $ touch foo.included

  $ echo ".*.included" > otherignore
  $ hg status -I "include:otherignore"
  ? foo.included

  $ echo "include:otherignore" >> .hgignore
  $ hg status
  A dir/b.o
  ? .hgignore
  ? otherignore

Check recursive uses of 'include:'

304
  $ echo "include:nested/ignore" >> otherignore
305
  $ mkdir nested nested/more
306
  $ echo "glob:*ignore" > nested/ignore
307
308
  $ echo "rootglob:a" >> nested/ignore
  $ touch a nested/a nested/more/a
Durham Goode's avatar
Durham Goode committed
309
310
  $ hg status
  A dir/b.o
311
312
313
  ? nested/a
  ? nested/more/a
  $ rm a nested/a nested/more/a
314

315
  $ cp otherignore goodignore
316
317
  $ echo "include:badignore" >> otherignore
  $ hg status
318
  skipping unreadable pattern file 'badignore': $ENOENT$
319
  A dir/b.o
320
321
322

  $ mv goodignore otherignore

323
324
325
326
327
328
329
Check using 'include:' while in a non-root directory

  $ cd ..
  $ hg -R ignorerepo status
  A dir/b.o
  $ cd ignorerepo

330
331
332
333
334
335
336
337
338
339
340
341
342
343
Check including subincludes

  $ hg revert -q --all
  $ hg purge --all --config extensions.purge=
  $ echo ".hgignore" > .hgignore
  $ mkdir dir1 dir2
  $ touch dir1/file1 dir1/file2 dir2/file1 dir2/file2
  $ echo "subinclude:dir2/.hgignore" >> .hgignore
  $ echo "glob:file*2" > dir2/.hgignore
  $ hg status
  ? dir1/file1
  ? dir1/file2
  ? dir2/file1

344
Check including subincludes with other patterns
345
346

  $ echo "subinclude:dir1/.hgignore" >> .hgignore
347
348
349
350
351
352
353
354
355
356

  $ mkdir dir1/subdir
  $ touch dir1/subdir/file1
  $ echo "rootglob:f?le1" > dir1/.hgignore
  $ hg status
  ? dir1/file2
  ? dir1/subdir/file1
  ? dir2/file1
  $ rm dir1/subdir/file1

357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
  $ echo "regexp:f.le1" > dir1/.hgignore
  $ hg status
  ? dir1/file2
  ? dir2/file1

Check multiple levels of sub-ignores

  $ touch dir1/subdir/subfile1 dir1/subdir/subfile3 dir1/subdir/subfile4
  $ echo "subinclude:subdir/.hgignore" >> dir1/.hgignore
  $ echo "glob:subfil*3" >> dir1/subdir/.hgignore

  $ hg status
  ? dir1/file2
  ? dir1/subdir/subfile4
  ? dir2/file1

Check include subignore at the same level

  $ mv dir1/subdir/.hgignore dir1/.hgignoretwo
  $ echo "regexp:f.le1" > dir1/.hgignore
  $ echo "subinclude:.hgignoretwo" >> dir1/.hgignore
  $ echo "glob:file*2" > dir1/.hgignoretwo

  $ hg status | grep file2
  [1]
382
  $ hg debugignore dir1/file2
383
  dir1/file2 is ignored
384
  (ignore rule in dir2/.hgignore, line 1: 'file*2')
385
386
387
388
389
390
391
392

#if windows

Windows paths are accepted on input

  $ rm dir1/.hgignore
  $ echo "dir1/file*" >> .hgignore
  $ hg debugignore "dir1\file2"
393
  dir1/file2 is ignored
394
395
396
397
  (ignore rule in $TESTTMP\ignorerepo\.hgignore, line 4: 'dir1/file*')
  $ hg up -qC .

#endif
398

399
#if dirstate-v2 rust
400

401
Check the hash of ignore patterns written in the dirstate
402
This is an optimization that is only relevant when using the Rust extensions
403
404
405
406

  $ hg status > /dev/null
  $ cat .hg/testhgignore .hg/testhgignorerel .hgignore dir2/.hgignore dir1/.hgignore dir1/.hgignoretwo | $TESTDIR/f --sha1
  sha1=6e315b60f15fb5dfa02be00f3e2c8f923051f5ff
407
  $ hg debugdirstateignorepatternshash
408
409
410
411
412
413
  6e315b60f15fb5dfa02be00f3e2c8f923051f5ff

  $ echo rel > .hg/testhgignorerel
  $ hg status > /dev/null
  $ cat .hg/testhgignore .hg/testhgignorerel .hgignore dir2/.hgignore dir1/.hgignore dir1/.hgignoretwo | $TESTDIR/f --sha1
  sha1=dea19cc7119213f24b6b582a4bae7b0cb063e34e
414
  $ hg debugdirstateignorepatternshash
415
416
417
  dea19cc7119213f24b6b582a4bae7b0cb063e34e

#endif