views:

155

answers:

4

I'm using Mercurial and I have a following structure:

files
   test
       demo.jpg
       video.flv
       video.doc

   sport
       demo2.jpg
       picture.jpg
       text.txt
demo3.jpg
demofile3.doc

I want to make a glob filter that only ignore all "jpg" files in all directory that are children of "files" directory

I tried with files/*.jpg but it doesn't work.

Any advice would be appreciated.

A: 

Does it have to be glob syntax? If you use regex syntax, files/.*\.jpg should work.

Tim Pietzcker
+5  A: 
Chris McCauley
+1 - I didn't know about `**`. Very useful tip, thanks.
Tim Pietzcker
Thanks Tim - glad to help!
Chris McCauley
Thanks for the replay but I have one more thing. When I use regexp it ignore the files in other directory that start or has word files in they names. But i want that regexp match only folder files. How can I do that?
Danilo
@Danillo. I'll take a look and get back to you asap.
Chris McCauley
@Daniilo, I've tried reproducing your scenario but it seems to work for me ...touch files/test/demo.jpgtouch anfiles/test/files.doc>hg stat? anfiles/test/files.doc
Chris McCauley
A: 

Chris McCauley thank you. globstars amazing! But isnt working with mercurial! Any ideas?

from .hgignore

syntax: glob
LaTeX/**/*.pdf

(how do I comment instead of answer?)

SpmP
Glad to be of help SpmP, actually I used Danilo's example in Mercurial and it worked fine for me. Is your .hgignore file in the root of your repository?
Chris McCauley
For me it works fine. Once more thanks to Chris save me a lot of efforts
Danilo
I think it did work, I was expecting hg addremove to remove all entries not matched... Anyway it workes. much appreciated!
SpmP
+1  A: 

If you are happy to ignore "all JPG files inside any directory named files", then use

syntax: glob
files/**.jpg

See hg help patterns which explains that ** is a glob operator that spans directory separators. This means that the file

 files/test/demo.jpg

is matched by files/**.jpg.

However, note that glob patterns are not rooted. This means that a file named

 test/files/demo.jpg

will also be ignored since it matches the pattern after you remove the test/ prefix.

You need to use a regular expression if you are concerned with this. In that syntax, the pattern reads

syntax: regex
^files/.*\.jpg

I would normally not worry about rooting the pattern -- I prefer the simplicity of the glob patterns. But it's nice to know that you can root a ignore pattern if you really have to.

Martin Geisler