0

I've been chasing around regular expressions for my .hgignore file, and found several very useful answers on SO (like this) and come up with a regexp I think should work to exclude all files and directories except the ones listed in the negative lookahead.

^(?!(certs/|config/|\.hgignore)).+

It seems to work on RegExr, and follows the pattern from the other SO answer, but the only file shown if I do hg status is the .hgignore itself; nothing in certs or config is seen by Mercurial. (There are certainly files in there that appear if I remove the .hgignore.)

What have I got wrong here?

Community
  • 1
  • 1
Iain Hallam
  • 289
  • 1
  • 13
  • Just curious: It isn't possible in mercurial to define one regex per line? – KingCrunch Jul 22 '11 at 20:58
  • Yes, but I'm trying to get the file to act as a whitelist, rather than its intended purpose as a blacklist of files that should be ignored. As I understand it, using multiple entries would match everything, so mark nothing for versioning. – Iain Hallam Jul 23 '11 at 01:59
  • Same problem... Similar regex(I just use `.*` instead of your `.+`) working in RegexBuddy but not working in mercurial and only `.hgignore` appears in `hg status` – grisevg Sep 01 '11 at 14:52

2 Answers2

2

Whitelists aren't easy because they're seldom necessary. Once you add a file it's tracked and the .hgignore file affects it not at all. That doesn't apply to directories (directories aren't tracking in Mercurial or git), but it does handle files like .hgignore. So just adding it once completely allows you to omit it from your whitelist even if you do try one.

If you really want most thing ignored, just go with this .hgignore file:

.*

And then add the cert and config files as new ones are created (just going out on a limb but one doesn't tend to add new certs and configs files version often). Once they're added they'll be tracked and their changes will show up in hg status as modified when they have been.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • OK. I think Mercurial should allow something like Apache's Order Allow,Deny to change the sense of .hgignore, but there seems little appetite for that, and I'm prepared to go with this for the time being. – Iain Hallam Jul 23 '11 at 17:01
0

Just a guess. Are you using a @"literal string" or a "regular string" You may need to make that \ into a \\

Marty Neal
  • 8,741
  • 3
  • 33
  • 38