views:

55

answers:

3

Been fighting with Mercurial's .hgignore for a while under Windows.

I have a folder named Upload which is currently empty. I do want it tracked so I added a .empty file in it which work fine. I want this so that new developers doing an hg clone get the Upload document required for the application.

Thing is I never want the folder to be populated with anything on the source control itself (test uploads from a development machine).

Example: If I add Public/image.jpg it wouldn't be tracked.

Additionally I would like it for sub directory to be tracked. So if developer adds

Upload/users/.empty I would like this to be tracked.

Is this possible with regex voodoo?

+1  A: 

Try putting

Uploads/(?!.empty)

in .hgignore in the root of the repository

rescdsk
Didn't work. I tried adding .hgignore with .* to /Upload and hg st |grep Upload showed Upload/.hgignore and Upload/image.jpg
jfrobishow
Ah, sorry, I was wrong about where you could put hgignore files. Try my edited answer? It works for me now.
rescdsk
Ok that worked for the root Upload directory. Is there anyway I could allow subdirectories? For example I would like Uploads/users/.empty to be tracked and same idea not the rest.
jfrobishow
But I'm having trouble making it recursive so you can have subdirectories... working on that...
rescdsk
I don't think I can do that with just regular expressions. The problem is that I can get it to not ignore Uploads/users/.empty, but it's already ignoring Uploads/users, so that masks the .empty's existence. I guess one possibility is that it could ignore everything except .empty and things that don't have a `.` in the name (folders usually don't have a . in the name), but that's not quite what you want.
rescdsk
Yeah I see what you mean with the regex masking Uploads/users. I suppose we could have it ignore everything with a . in the name, but no it's not exactly it.
jfrobishow
+3  A: 

In mercurial (and unlike in svn and cvs) adding a file overrides the .hgignore file, so you can put this in your .hgignore:

^Uploads/.*

and your Upload/.empty that you added will still be created on update and thus they'll get the directory.

Getting it to ignore files in upload but not not ignore files in subdirectories in Upload could be done with:

^Uploads/[^/]*$

which says: ignore anything that Starts with Uploads and has no further slashes in it.

Really though, you should be creating Uploads with your build/install/configure script when possible, not with the clone/update.

Ry4an
Not sure I understand if I have ^Uploads/.* won't Uploads/.empty be ignored? Good point on the build script...
jfrobishow
It would be ignored *except* you add it manually. That's what I was getting at in that first sentence. You don't need to make your patterns so smart as to exclude your exceptions, just 'hg add' the exception and it overrides .hgignore completely.
Ry4an
Ah I get it now, didn't know that. It's working but I decided to stop fighting the tool anyway and use a configure script as you suggested...
jfrobishow
A: 

Try

^Uploads\b.*/(?!\.empty)[^/]+$

This should match any path starting with Uploads where the text after the last slash (=filename) is anything but .empty.

Tim Pietzcker
Worked for the main directory and masked subdirectories with .empty in it (Uploads/Users/.empty)
jfrobishow
Is that good or not?
Tim Pietzcker
Well what I was trying to do is allow for Uploads\.empty and nothing else inside but other directories (with .empty files in it. A way to preserve a directory structure without tracking files in them.
jfrobishow