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:
syntax:glob
bin/*
obj/*
4. Save

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

syntax: glob

*.*scc
*.FileListAbsolute.txt
*.aps
*.bak
*.[Cc]ache
*.clw
*.eto
*.exe
*.fb6lck
*.fbl6
*.fbpInf
*.ilk
*.lib
*.log
*.ncb
*.nlb
*.obj
*.orig
*.patch
*.pch
*.pdb
*.plg
*.[Pp]ublish.xml
*.rdl.data
*.sbr
*.scc
*.sig
*.sln.docstates
*.sqlsuo
*.suo
*.svclog
*.tlb
*.tlh
*.tli
*.tmp
*.user
*.vshost.*
*DXCore.Solution
*_i.c
*_p.c
Ankh.Load
Backup*
* - [Cc]opy
CVS/
PrecompiledWeb/
UpgradeLog*.*
[Bb]in/
[Dd]ebug/
[Ee]xternal/
[Oo]bj/
[Pp]ackages/
[Rr]elease/
[Tt]humbs.db
_UpgradeReport_Files
_[Rr]e[Ss]harper.*/
hgignore[.-]*
ignore[.-]*
svnignore[.-]*
lint.db
__MVC_BACKUP

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:

[ui]
ignore = ~/.hgignore

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

Under windows 7+ you can use

[ui]
ignore = %USERPROFILE%/.hgignore

Both of these should work for command line and tortoiseHG.

That is about all there is to it.

Leave a Reply

Your email address will not be published. Required fields are marked *