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

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?

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

Related

Mercurial: Track repo with .hg dir and work-tree in separate directories

I have often used this approach to dot file management in git, where I create a bare git repo "~/.dotfiles" and us $HOME as a work tree. With the shell alias config I can then add dot files from the home dir quickly (as in config add, config commit
alias config='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
I wonder if a similar setup is possible in mercurial.
You can use a regular repository for that[^bare] and clone it with the share extension. Creating a new home dir as one-liner:
hg --config extensions.share= share $HOME/.dotfiles $HOME
For more information see hg help share. For information how to ignore changes to untracked files, see hg help hgignore.
[^bare]: If it is important for you to have no files in the .dotfiles, just hg update null in ~/.dotfiles. That’s the root of the repository (before anything got added). Mercurial needs no special bare state.

Preventing changesets with files matching .hgignore patterns from being pushed to an hg repo

How can I prevent changesets (from the source repo) with files matching .hgignore patterns (in the head of each respective target branch in the target repo) from being pushed to an hg repo?
It looks like the ACL Extension can deny pushes based on file name globs, but I prefer to keep [acl.deny] in hgrc in sync with .hgignore.
Can the ACL Extension read .hgignore, and use it to specify file selectors for [acl.deny]?
If not, is there any existing script to sync .hgignore patterns to [acl.deny]?
Is there any other way to achieve this (other than manual syncing)?

Find committed files that should have been ignored

How can I list all files in a repository that were committed (explicitly), although they were ignored because of the .hgignore file
.hgignore uses glob syntax
running on Windows
it's not necessary to take any global .hgignore file into account
My idea:
hg manifest > filter using the content of .hgignore > result
You have to learn and use filesets in this case
List files that are in .hgignore but are already tracked:
hg locate "set:hgignore() and not ignored()"

Why does .hgignore appears in my patches?

I use Mercurial Queues to work with patches.
There was no .hgignore initially.
I'm not sure if I first created an MQ patch and then created my .hgignore or the other way round.
(By "creating a patch" I mean hg qnew patch_name -m "...")
Anyway, I made some changes to .hgignore after I created the MQ patch.
When I did hg qrefresh; hg export qtip I got the changed contents of .hgignore also in my patch.
So, tried adding an .hgignore entry to .hgignore itself. But that didn't work. The changes persisted.
So, I tried hg forget .hgignore and this made a bigger mess. It nows shows that I deleted .hgignore in my patch. Like so:
--- a/.hgignore
+++ /dev/null
- all
- the lines of .hgignore
- the lines of .hgignore
How do I resolve this problem?
I just want .hgignore to be part of my local repo and help in not tracking some files.
.hgignore is designed to be tracked by Mercurial (doc). The standard way to ignore files in local clone only is to use ui.ignore setting:
# .hg/hgrc
[ui]
ignore = /path/to/repo/.hg/hgignore
If you have multiple local ignore files then you can write
[ui]
ignore.first = /path/to/repo/.hg/firstignore
ignore.second = /path/to/repo/.hg/secondignore
Additional global ignore files can be configured in this way:
[ui]
ignore.first = /path/to/repo/.hg/firstignore
ignore.second = /path/to/repo/.hg/secondignore
ignore.third = ~/thirdignore
All settings live in hgrc file. More details here:
hgrc file location: doc
ui.ignore setting reference: doc
about .hgignore files: doc
original recipe: Tips And Tricks

For Mercurial (Hg), why the file .hgignore cannot be ignored?

I have these in the proj/.hgignore:
syntax: glob
log/*
*~
*.orig
dump/*
*.hgignore
.hgignore
tmp/*
but for some reason, when I do an hg st or hg com, the file .hgignore still shows up to be modified or to be committed. So the .hgignore cannot be ignored? There might be particulars in my folder that my team didn't want to ignore but I do. So I don't want to commit this file.
Chris has it in the comment: you've probably already added your .hgignore file, and an add overrides the .hgignore. You need to hg forget .hgignore and hg commit and then you'll find your file is ignored.
Thats said, most people put the .hgignore file into the repo for a reason -- so that the next person to clone doesn't accidentally commit all of their log/temporary files.
I think you're looking for this:
https://www.mercurial-scm.org/wiki/TipsAndTricks#Ignore_files_in_local_working_copy_only
The overall .hgignore file is necessary to ignore anything, and so you can't exclude it.