views:

645

answers:

2

Is it possible, while using glob syntax for an .hgignore file, to recursively ignore certain files and folders, except one?

Assuming that you have:

a/
a/b
a/c
a/d

Something like:

syntax globe:
a
^a/b

This should ideally ignore c and d and keep b.

I know this has been discussed in other SO questions, but it seems they're all using regex mode for the syntax.

+2  A: 

The glob syntax is transformed to regex in match.py. It seems that this is the syntax you are looking for:

syntax:glob

a/*[!b]
Otto Allmendinger
This works fin in this example, but apparently not with nested subfolders (in my real repo, I need to skip something like a/*[!b/sub/subsub]). I tried to escape the slashes in several modes, but it didn't help. Any suggestion?
Roberto Aloi
Accepted as best answer so far :)
Roberto Aloi
+2  A: 

If you want to ignore all but one, just add that one. Adding a file overrides ignoring it, which differs from subversion or cvs, but is incredibly handy.

Ry4an
I would prefer to avoid this procedure. It's error prone and I usually forget adding files to hg after creating a lot of them :)
Roberto Aloi
@Roberto Aloi than all executables and other generated stuff would clutter your commits. I'd rather add new files, than removing all unneeded stuff every time.
Joschua