You can set the post-commit hook, which updates the file:
[hooks] post-commit = sed -i lib/foo/version.rb \ -e "s|\$Date.*\$|\$Date: $(date)\$|" \ -e "s|\$Version.*\$|\$Version: $(hg id -i)\$|"
Then you will probably add the version file to the .hgignore file - it will change after each commit and therefore will always be dirty. You can also add an encoding filter that clears the version file:
[encode] lib/foo/version.rb = sed -e "s|\$Date.*\$|\$Date\$|" \ -e "s|\$Version.*\$|\$Version\$|"
This script will make Mercurial see the file as clean - no matter what date and set of changes it actually contains, Mercurial will see that it contains the unexpanded keywords $Date$ and $Version$ :
$ hg commit -m test
$ hg tip
changeset: 7: df81c9ddc9ad
tag: tip
user: Martin Geisler
date: Wed Apr 06 14:39:26 2011 +0200
summary: test
$ hg status
$ hg cat version.py
date = "$ Date $"
version = "$ Version $"
$ cat version.py
date = "$ Date: Wed Apr 6 14:39:26 CEST 2011 $"
version = "$ Version: df81c9ddc9ad $"
Martin geisler
source share