views:

2022

answers:

2

Hello,

I have a problem which I can't seem to understand. I'm using TortoiseHg (version 0.7.5) on windows but on linux I have the same problem. Here it is:

My .hgignore file:

syntax: regexp
^[^\\/]+$

What I'm trying to achieve is to add to the ignore list the files which are in the root of the hg repository.

For example if I have like this:

.hg
+mydir1
+mydir2
-myfile1
-myfile2
-anotherfile1
-anotherfile2 
.hgignore

I want myfile1(2) and anotherfile1(2) to be ignored (names are only for the purpose of this example - they don't have a simple rule that can be put in the hgignore file easily)

Is there something I'm missing because I'm pretty sure that regexp is good (I even tested it)? Ideas?

Is there a simpler way to achieve this? [to add to the ignore list files that are in the root of the mercurial repository]

Thank you,

Iulian

+5  A: 

I relayed this question in #mercurial on irc.freenode.net and the response was that you cannot distinguish between files and directories -- the directory is matched without the slash that you're searching for in your regexp.

However, if you can assume that your directories will never contain a full-stop ".", but your files will, then something like this seems to work:

^[^/]*\..*$

I tested it in a repository like this:

% hg status -ui
? a.txt
? bbb
? foo/x.txt
? foo/yyy

Adding the .hgignore file gives:

% hg status -ui
? bbb
? foo/x.txt
? foo/yyy
I .hgignore
I a.txt

which indicates that the a.txt file is correctly ignored in your root directory, but x.txt in the foo subdirectory is not. You can also see that a file named just bbb in the root directory is not ignored. But maybe you can add such files yourself to the .hgignore file.

If you happen to have a directory like bar.baz in your root directory, then this directory and all files within will be ignored. I hope this helps a bit.

Martin Geisler
Thanks a lot, it confirms my beliefs.
Iulian Şerbănoiu
+2  A: 

Here is a dirty trick:

Create an empty file ".hidden" in your directory, than add to .hgignore:

^mydir/(?!\.hidden).+$

This will ignore all files in the directory except ".hidden".

t0ster