SVN Commit Hooks / Subversion Tags on IgorExchange
Fri, 09/25/2009 - 10:26 am
I know this is fairly off-topic (it has more to do with Igor Exchange than
with Igor itself), but I am quite confident that it will interest more than
one on the list.
Could somebody post the pre/post commit hooks they use in Subversion? I
would like to add/modify the first couple of lines in my versioned
procedures, and seeing that some packages on Igor Exchange already do this,
I thought I would just ask here before diving into the Subversion book.
Thank you in advance,
On IgorExchange, we use a pretty complicated set of pre and post
commit hook scripts to do several things:
1. Reject the commit if the log message is empty.
2. Send an email to me with information about every commit so that I
can monitor things and find problems earlier.
3. Enforce access control, making sure that the user has the
permission to commit code to the project it's being committed to.
4. Enforce branch and tag naming conventions so that releases work properly.
The hook scripts used on the site are quite complicated and written in
PHP. However there are sample scripts, written in Python, provided by
the Subversion authors that do #1 and #2 above. They are at
. Scroll down to the
pre-commit and post-commit sections.
If what you are looking for is to have things like the revision
number, date, committer username, etc. inserted in text files that are
committed (usually at the top of the file), you don't need hook
scripts. Instead, you just need to use Subversion properties. See
for general information about properties and how to set them with
subversion. The property you need is the svn:keywords property. See
for specific information on that keyword. Note that you have to both
set the svn:keyword property on the file and also include the keyword
anchor text in the file itself.
One caveat with doing this--when Igor opens text files, such as
procedure files, for editing it locks them. This means that you won't
be able to commit changes to any file that has the svn:keywords
property set and which includes the anchor text, because as Subversion
tries to commit the file it must modify it, and Igor's lock will
prevent that from happening.