How to let Mercurial ignore every thing except *.cs file?
Asked Answered
W

3

8

I started a project and added it to Mercurial. But I want to take *.cs file under version control only. So I have to add bin, obj, sln, suo, _resharper folder etc to ignore pattern.

How to let Hg only monitor certain kind of file like white list? How to do that in Subversion?

Wampumpeag answered 27/8, 2009 at 3:10 Comment(2)
Mercurial or Subversion or both?Algonkian
Only Mercurial is ok, both if knowWampumpeag
K
8

Just add the extensions to your .hgignore file as you come across them:

syntax: glob
*.bin
*.obj

and so on. It's not a lot of work, and it documents to the rest of the world exactly what kind of files you consider unimportant for revision control.

You can even setup a global ignore file, please see the ignore entry in the [ui] section.

Trying to turn the .hgignore upside-down by using negative lookahead regular expressions and other voodoo is (in my opinion) not a good idea. It will almost surely not work and will only lead to confusion. This is because hg matches all prefixes of a give path name against the rules in .hgignore. So a file like

a/b/c.cs

will be ignored if any of

a/b/c.cs
a/b
a

is matched by a rule in your .hgignore file. In particular, this means that you cannot use a negative lookahead expression to have a/b/c.cs not-ignored -- the rule will match a/b or a.

Kelle answered 27/8, 2009 at 10:35 Comment(2)
So you're saying that there's no negation operator?Bombshell
Mike: Yes, unfortunately. Please see this issue mercurial.selenic.com/bts/issue712 where you can leave a comment if you're very interested.Kelle
R
1

Regarding the link to a Mercurial issue supplied by Martin Geisler (https://www.mercurial-scm.org/bts/issue712), please note that the issue is not one of technical difficulty, but support:

This is an ancient and recurring feature request, which I turned down well before this bug was created. I've written and supported a couple include/exclude file syntaxes and have decided I would rather say "no, you can't do that" once to 1% of users than "no, you're reading the docs wrong" repeatedly to 20% of users. —Matt Mackall (developer of Mercurial)

Rarefy answered 3/11, 2011 at 20:20 Comment(0)
A
-2

Add a file named .hgignore to your repository with these contents.

syntax: regexp

^\.cs

Subversion doesn't let you use regex to ignore files, only a subset of glob syntax to match file/directory names. I had no idea how to make ignore files not ending in .cs so I searched the web and this webpage says:

svn propset svn:ignore "*[!c][!s]
*.cs?*" .

Use it with caution :)

Edit: Martin Geisler is right and I was mistaken, the regexp syntax is wrong. I apologize. The correct concept is there but not the metacharacters... :(

Algonkian answered 27/8, 2009 at 3:15 Comment(1)
The ^\.cs regexp will make hg ignore a file called .cs in the root directory of the repository. It wont make hg ignore all files not matching *.cs (glob pattern).Kelle

© 2022 - 2024 — McMap. All rights reserved.