OscarRyz
OscarRyz

Reputation: 199333

What should I put in hgignore to avoid mercurial follow the contents of a subdir?

For instance I have a folder

PROJECT/db/

Where a lot of files are created, I want to prevent hg from keeping track of those files but keeping the db folder ?

Upvotes: 3

Views: 1050

Answers (2)

jwsample
jwsample

Reputation: 2411

Empty folders are not inherently supported in mercurial so if you ignore all files in a folder the folder will not be tracked.

From the hg book: http://hgbook.red-bean.com/read/mercurial-in-daily-use.html

Empty directories are rarely useful, and there are unintrusive workarounds that you can use to achieve an appropriate effect. The developers of Mercurial thus felt that the complexity that would be required to manage empty directories was not worth the limited benefit this feature would bring.

If you need an empty directory in your repository, there are a few ways to achieve this. One is to create a directory, then hg add a “hidden” file to that directory. On Unix-like systems, any file name that begins with a period (“.”) is treated as hidden by most commands and GUI tools. This approach is illustrated below.

$ hg init hidden-example
$ cd hidden-example
$ mkdir empty
$ touch empty/.hidden
$ hg add empty/.hidden
$ hg commit -m 'Manage an empty-looking directory'
$ ls empty
$ cd ..
$ hg clone hidden-example tmp
updating working directory
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ ls tmp
empty
$ ls tmp/empty

Another way to tackle a need for an empty directory is to simply create one in your automated build scripts before they will need it.

Edit: I'm assuming you know how to do an hgignore in your repo to ignore the whole directory:
Create a file called .hgignore in your repo root. Put in the follwing text:

syntax: glob
db/

Upvotes: 5

user210733
user210733

Reputation:

As far as I know Mercurial's ignore files are not rooted, hence just list one or more patterns to exclude the content of the DB folder.

Upvotes: 0

Related Questions