Make .hgignore in a Mercurial repository available to all subrepos?

917 views Asked by At

I have a Mercurial repository with several subrepos. Is there a possibility to only define a general .hgignore-File (e.g. to ignore object-files) both in the main repository and, optionally a specialized one in the sub-repositories?

There is not enough information in the manual. Specifying a .hgignore file with

[ui]
ignore = .hgignore

to .hgrc in my home-directory also does not work.

Any ideas?

1

There are 1 answers

3
Joel B Fant On

A .hgignore file in each subrepo would serve as the specialized one for that subrepo. Then you can use the main repo's .hgignore as the main one by including this in each subrepo's hgrc file:

[ui]
ignore.main = \absolute\path\to\mainrepo\.hgignore

The reason why doing ignore = .hgignore didn't work for you in your global .hgrc (and won't in repo hgrc) is that having simply .hgignore is a relative file path and its resolution to an absolute path depends on the current working directory used when invoking hg. Examples:

  • If you're in \repos\main\ and invoke hg st, it will look for \repos\main\.hgignore. Same thing if you invoke hg st -R nested, because the current working directory is still the same.
  • But if you were in \repos\main\nested\ and then invoked hg st, the config would now be looking at \repos\main\nested\.hgignore.

If you want to specify a global .hgignore that is in your home directory, you would need to specify it with a non-relative path (or at least much less relative):

[ui]
ignore = ~\.hgignore