Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 421
GJ. Avatar asked Dec 29 '10 13:12

GJ.


2 Answers

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.

like image 60
Lasse V. Karlsen Avatar answered Jan 03 '23 19:01

Lasse V. Karlsen


Did you hg init in the subdirectory as well? If so, don't. Below illustrates the issue:

C:\>hg init project
C:\>cd project
C:\project>hg init sub
C:\project>echo >file1
C:\project>echo >sub\file2
C:\project>hg st
? file1

Delete the subfolder's .hg directory to fix it:

C:\project>rd /s/q sub\.hg
C:\project>hg st
? file1
? sub\file2

Unlike Subversion, Mercurial only uses an .hg directory at the root of a project.

like image 31
Mark Tolonen Avatar answered Jan 03 '23 18:01

Mark Tolonen