How to get mercurial to notice files added into subdirectories? (hg st, hg add)

GJ. picture GJ. · Dec 29, 2010 · Viewed 10.3k times · Source

If I add a new file into my project's root, it appears with a ? status in hg st, and gets added with hg add.

However, if I add a new file into a subdirectory, it doesn't appear in hg st at all, and only gets added if I explicitly add the file (not even if I add the file's containing directory).

How can I get mercurial to notice files in subdirectories, in a similar way to how subversion notices them?

Thanks

Answer

Lasse V. Karlsen picture Lasse V. Karlsen · Dec 29, 2010

Well, plain hg add without any extra arguments adds files in sub-directories as well, it basically adds all files with status unknown to be tracked.

However, if you specify a simple mask, it only operates on your current working directory (ie. the working directory of the hg command, not the working directory associated with the repository), so if you're currently situated in the sub-directory, it will add those files, if you're in the root directory, it will add those files instead.

In other words, this:

hg add test*

Only operates on files in the directory you're currently situated.

You can override that behavior by specifying a mask that tells hg to operate on sub-directories:

hg add **/test*

This says "add all files that match 'test*' in the current directory and all sub-directories.

If you remove one of the asterixes, you only operate on sub-directories of the current working directory.

It would help if you posted what specific commands you executed, and the output, if any, and the output of hg st before and after.