Mercurial/.hgignore - How do I ignore everything but the contents of a folder?
Asked Answered
P

2

8

I have a NetBeans project and the Mercurial repository is in the project root. I would like it to ignore everything except the contents of the "src" and "test" folders, and .hgignore itself.

I'm not familiar with regular expressions and can't come up with one that will do that.

The ones I tried:

(?!src/.*)

(?!test/.*)

(?!^.hgignore)

(?!src/.|test/.|.hgignore)

These seem to ignore everything, I can't figure out why.

Any advice would be great.

Pi answered 31/3, 2010 at 20:31 Comment(0)
V
8

This seems to work:

syntax: regexp

^(?!src|test|\.hgignore)

This is basically your last attempt, but:

  • It's rooted at the beginning of the string with ^, and
  • It doesn't require a trailing slash for the directory names.

The second point is important since, as the manual says:

For example, say we have an untracked file, file.c, at a/b/file.c inside our repository. Mercurial will ignore file.c if any pattern in .hgignore matches a/b/file.c, a/b or a.

So your pattern must not match src.

Vivisectionist answered 31/3, 2010 at 20:58 Comment(2)
Don't forget to escape the dot.Mobile
Thanks a lot, guys! That really helped, it works like a charm now, and I see where I was going wrong.Pi
M
3
^(?!src\b|test\b|\.hgignore$).*$

should work. It matches any string that does not start with the word src or test, or consists entirely of .hgignore.

It uses a word boundary anchor \b to ensure that files like testtube.txt or srcontrol.txt aren't accidentally matched. However, it will "misfire" on files like src.txt where there is a word boundary other than before the slash.

Mobile answered 31/3, 2010 at 20:56 Comment(1)
How can this be changed so that only certain subdirectories are not ignored? e.g. app/design/frontend/rcDrove

© 2022 - 2024 — McMap. All rights reserved.