Excluding files in Mercurial – Kiln for use with Visual Studio

After working in environments where there was source control and task tracking for so long there was just no way I could start building applications or writing code without having such systems in place. So the first thing I did when I started working in my current position was look at Task/bug tracking software and source control software. In the end I decided on Fogbugz & Kiln by Fog Creek Software. I went this direction as I like the fact that we could have them host everything and it was easy to support different development enviroments. If I was only developing with .net I think I would have likely gone with locally hosted Team Foundation Server.

Anyway I’m now doing some .net dev work and thought I would mention a few things I’ve found related to excluding files with Mercurial.

Too exclude files you create a .hgignore file. This should be linked in your mercurial.ini file. More about that later though.

First off windows is a bit of a pain and dislikes files that start with a a period ‘.’ so to create the file you may need to do something along the lines of the following:

1. cd to/my/repo
2. notepad .hgignore Notepad.exe opens and asks if you want to create the file. Say yes.
3. Add something to it:
4. Save

I would suggest you use the follow in your .htignore file it covers C#, C++ and Visual Studio development:

syntax: glob

* - [Cc]opy

Finally to make this file work with all your repositories you should link it in the [ui] section of your mercurial.ini file. This file is located in your user profile folder.

How do I configure Mercurial to use environment variables in mercurial.ini

To do this I modify the [ui] section of my Mercurial.ini (in my home path) to include:

ignore = ~/.hgignore

This appears to work for all version of windows and elsewhere.

Under windows 7+ you can use

ignore = %USERPROFILE%/.hgignore

Both of these should work for command line and tortoiseHG.

That is about all there is to it.