ignoring folders in mercurial
Asked Answered
M

4

33

Caveat: I try all the posibilities listed here: How can I ignore everything under a folder in Mercurial.
None works as I hope.

I want to ignore every thing under the folder test. But not ignore srcProject\test\TestManager

I try

syntax: glob
test/**

And it ignores test and srcProject\test\TestManager

With:

syntax: regexp
^/test/

It's the same thing.

Also with:

syntax: regexp
test\\*

I have install TortoiseHG 0.4rc2 with Mercurial-626cb86a6523+tortoisehg, Python-2.5.1, PyGTK-2.10.6, GTK-2.10.11 in Windows

Milkmaid answered 21/11, 2008 at 20:37 Comment(0)
H
46

Try it without the slash after the caret in the regexp version.

^test/

Here's a test:

~$ mkdir hg-folder-ignore
~$ cd hg-folder-ignore
~/hg-folder-ignore$ echo '^test/' > .hgignore
~/hg-folder-ignore$ hg init
~/hg-folder-ignore$ mkdir test
~/hg-folder-ignore$ touch test/ignoreme
~/hg-folder-ignore$ mkdir -p srcProject/test/TestManager
~/hg-folder-ignore$ touch srcProject/test/TestManager/dont-ignore
~/hg-folder-ignore$ hg stat
? .hgignore
? srcProject/test/TestManager/dont-ignore

Notice that ignoreme isn't showing up and dont-ignore is.

Haleyhalf answered 24/11, 2008 at 4:10 Comment(2)
@JaKXz yes, this works in all versions of Mercurial. What you've got in your .hgignore didn't come through. Make sure your ignore file is being interpreted as a regex instead of a glob, and don't count on ignore to ignore files you've already hg added. Ignoring only affects how unadded files are listed/treated.Haleyhalf
et al. The solution I found is to use this: syntax: regexp ^SourceFolder\bin ^SourceFolder\gen and for a file named .classpath: ^SourceFolder\.classpathRies
L
4

You can use zero-width negative look-ahead and look-behind assertions to specify that you want to ignore test only when it's not preceded by srcProject and not followed by TestManager:

syntax: regexp
(?<!srcProject\\)test\\(?!TestManager)

Mercurial uses Python regular expressions, so you can find more info on zero-width assertions in the Python docs: https://docs.python.org/library/re.html#regular-expression-syntax

Longmire answered 21/11, 2008 at 22:23 Comment(1)
Way more complicated than it needs to be to solve a simple problem. Ry4an's solution accomplishes the same in a much simpler manner.Kunlun
B
4

Both cases worked for me (on linux and windows):

syntax: regexp
^backup/     #root folder
nbproject/   #any folder

or

syntax: glob
./backup/*   #root folder
nbproject/*  #any folder

However, it wasn't before I added a link to .hgignore file to .hgrc file in my repo:

[ui]
ignore = .hg/.hgignore

Also worth mentioning that mercurial ignores files that it is not currently tracking, which are those added before you configured it to ignore them. So, don't be put off by hg status saying some filed are M (modified) or ! (missing) in the folders that you have just added to the ignore list!

Balustrade answered 7/6, 2010 at 10:27 Comment(1)
.hgignore is normally in the root directory of the repository, not under .hg.Tansy
O
0

Create .hgignore file under root directory of the repository

Now add the following contents in the file .

syntax: glob

bin/**

*.DS_Store

This will remove the bin directory and all the *.DS_Store files from the repository

Orelie answered 25/11, 2015 at 3:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.