.hgignore syntax for ignoring only files, not directories?
Asked Answered
B

2

11

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]

Bristle answered 26/6, 2009 at 11:30 Comment(0)
H
11

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.

Harmattan answered 30/6, 2009 at 11:47 Comment(2)
Thanks a lot, it confirms my beliefs.Bristle
You could also do it for a subdir and ignore php files like: wpblog/[^/]*\.php$Jungian
S
7

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".

Studhorse answered 16/11, 2009 at 14:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.