jfrobishow
jfrobishow

Reputation: 2895

Mercurial ignore part of a directory

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?

Upvotes: 0

Views: 541

Answers (3)

Tim Pietzcker
Tim Pietzcker

Reputation: 336468

Try

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

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

Upvotes: 0

Ry4an Brase
Ry4an Brase

Reputation: 78350

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.

Upvotes: 4

rescdsk
rescdsk

Reputation: 8915

Try putting

Uploads/(?!.empty)

in .hgignore in the root of the repository

Upvotes: 1

Related Questions