views:

3797

answers:

5

I am looking for an expression for the .hgignore file, to ignore all files beneath a specified folder.

eg: I would like to ignore all files and folders beneath bin

Actually any advice on how the expressions are formed would be great

A: 

Nevermind, I got it

syntax: regexp
bin\\*

expressions follow standard perl regular expression syntax.

Xian
Indeed, and your expression means "file or folder ending with bin and followed by 0 or more backslashes"... So it works because the backslash is nullified by the *, but it applies anything with "bin" inside. On Windows, hg replaces \ by / before matching.
PhiLho
+12  A: 

Alternately:

syntax: glob
bin/**
Ry4an
this is much easier I think :)
Xian
Looks like just "bin" (no quotes) works...
PhiLho
+2  A: 

Both of those will also filter out a directory called cabin, which might not be what you want. If you're filtering top-level, you can use:

^/bin/

For bin directories below your root, you can omit the ^. There is no need to specify syntax, regexp is the default.

nullptr
This won't ignore anything. The caret says only things in the repo root but the leading slash catches only dirs not in the repo root.
Ry4an
A: 

to ignore .class files

syntax: regexp
?\.class
damian
Incorrect regex syntax...
PhiLho
+10  A: 

I did some experiments and I found that the regex syntax on Windows applies to the path starting with the current repository, with backslashes transformed to slashes.

So if your repository is in E:\Dev for example, hg status will apply the patterns against foo/bar/file1.c and such. Anchors apply to this path.

So:

  • Glob applies to path elements and is rooted to element parts
  • foo matches any folder (or file) named foo (not to "foobar" nor "barfoo")
  • *foo* matches any folder or file with "foo" in the name
  • foo/bar* matches all files in "foo" folder starting with "bar"


  • Regex is case sensitive, not anchored
  • Of course, backslash regex special characters like . (dot)
  • / matches \ path separator on Windows. \ doesn't match this separator...
  • foo matches all files and folders with "foo" inside
  • foo/ matches only folders ending with "foo"
  • /foo/ matches the folder "foo" somewhere in the path
  • /foo/bar/ matches the folder "bar" in the folder "foo" somewhere in the path
  • ^foo matches file or folder starting by foo at the root of the repository
  • foo$ matches file ending with foo

I hope this will help, I found the HGIGNORE(5) page a bit succinct.

PhiLho