Question

I have two branches in my mercurial repository with the same .hgignore file: dir/

One branch (development) should ignore this directory, while the other (release) should not ignore it. I know I can use hg add dir/somefile despite the entry in the .hgignore file. But now I would like to add the whole directore recursively.

I searched for that and tried

hg add dir    # does not add anything
hg add dir*   # does not add anything
hg add dir/   # does not add anything
hg add dir/*  # only adds the files in dir but not in sub-directories
hg add dir/** # only adds the files in dir but not in sub-directories

But that thas not work recursively. I could use add dir/* dir/*/* dir/*/*/* and so on, but that is annoying. Is there another wildcard I have to use instead or maybe another way to accomplish this?

PS: I would like to avoid to change the .hgignore.

Was it helpful?

Solution

In the meantime, I was able to come up with—what seems to be—a solution:

hg add --dry-run --verbose `hg status --ignored --no-status --exclude **.DS_Store dir/`

This shows a list of files that it would add. If you really want to add them, use the following command:

hg add `hg status --ignored --no-status --exclude **.DS_Store dir/`

Hope this helps someone.

OTHER TIPS

If you have access to find, you can do something like the following:

find docs -exec hg add {} \;

Whenever running commands with find it's always nice to do a dry run first, so I generally stick an echo in front of the command first:

find docs -execechohg add {} \;

If you need to add enough files that performance is a concern, you can use + instead of \;, which will append all matching filenames to the same command instead of running the command once for each filename. For hg add this is not likely to be an issue, but it's important for understanding how find works.

find docs -exec hg add {}+

Unfortunately, .hgignore will ignore anything that is not a full path to a file and is respected even when evaluating patterns. There's a post on StackExchange that contains alternatives that you could use (assuming that you did not want to change .hgignore)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top