views:

263

answers:

3

I'm looking for a way to modify my .hgignore file to ignore all "Properties/AssemblyInfo.cs" files except those in either the "Test/" or the "Tests/" subfolders.

I tried using the negative look-behind expression (?<!Test)/Properties/AssemblyInfo\.cs$, but I didn't find a way to "un-ignore" in both folders "Test/" and "Tests/".

A: 

Normally you'd just do Tests?, but since depending on the regexp engine, dynamic look-behinds aren't allowed, you can simply use two branches:

(?<!Test|Tests)/Properties/AssemblyInfo\.cs$

reko_t
I already tried that, doesn't work. Mercurial says "invalid pattern". Doesn't this have to do with the look-behind expression having to be of a fixed length?
jco
Somehow I assumed that PCRE was used, in PCRE different branches can be of different width.
reko_t
+1  A: 

Python doesn't support variable-length lookbehind.

But \b(?<!Test)(?<!Tests)/Properties/AssemblyInfo\.cs$ should work.

Tim Pietzcker
Sweet, this works like a charm. But what's the purpose of 'r'? Is that like the '@' of C# for instance?
jco
Yes it is, but I just removed this bit again since you don't need this in the .hgignore file, only in a native Python string. Got a little carried away there :)
Tim Pietzcker
+1  A: 

Just to get this out there for any future searchers: Regex contortions like this are only necessary if you expect a lot more exception files to be added to the working directory in the future.

If you just want to make the current ones exceptions, you can just hg add them. Unlike svn and cvs, in mercurial you can add an ignored file and it overrides the .hgignore -- future changes will be automatically tracked.

It's not unheard of to have .* in your .hgignore file and then hg add the files you want tracked.

In this case, The more traditional mercurial way to do this would be a .hgignore file like this:

/Properties/AssemblyInfo\.cs

followed by:

$ hg add Test/Properties/AssemblyInfo.cs
$ hg add Tests/Properties/AssemblyInfo.cs

If you have hundreds of Test and Tests you can add them with a find, but if you create new ones every day then the regex is definitely the way to go.

Ry4an