A SIMPLE .NET Subversion Trigger

This latest post finds me on my continued Subversion kick. Having checked out the wonderful, yet not quite mature enough Mercurial and the possibly wonderful but completely painful windows experience of GIT, i'm sticking with Subversion as my Visual SourceSafe replacement of choice. This week I have mostly been playing with Subversion hooks- an extremely simple and powerful trigger mechanism used when checking items in or out of a subversion database.

For those who do not know, each subversion database contains a 'hooks' folder in which files exist for pre and post commit/lock/property change/unlock events. Harnessing this hooking mechanism is as simple as creating a file and giving it, for instance the filename 'pre-commit'. The true beauty (i'm sure i mentioned this before) is that the extension doesnt matter - you can use an exe, a batch file, a .pl file etc. etc. and, as long as your filename falls into the pre-defined list, your hook is guaranteed to run on the chosen event. Some templates are created as part of the default database creation, and below is an example of a pre-commit.tmpl script for one of my databases.



The beauty of this example is that it explains in no uncertain terms the paramaters taken by the hooking procedure:



# [1] REPOS-PATH (the path to this
repository)
# [2] TXN-NAME (the name of the txn
about to be committed)



Using these parameters, it is easy to create triggers in the flavor of your choice. Below, i created a VB.NET console application which (given the repository path and transaction name) uses the external svnlook command to inspect the comment field passed as part of the transaction. If the user has entered comments less than 5 characters (an arbitrary number) the transaction will fail (a la the exit(1) command and will write an error message back to the calling application.





Here's a screenshot of TortoiseSVN when this trigger fires and my limit of 5 characters had not been reached.












I've been working on something a little more substantial for next time, but I hope this serves as a pretty simple introduction to the joys of subversion triggers!

Comments

Anonymous said…
Nice!

I recommend you this post http://emmersonmiranda.blogspot.com/2007/09/hooks-para-svn-comprobacin-de.html from Emmerson that is a colleague of mine. Despite the entry is wrotten is Spanish, it provide many links to other pre-commit hooks.

I remember that he told me that he wanted a way to disallow a commit if the source has no javadoc o other checks

See you

Popular posts from this blog

Mirth

Excel - Adding an existing Pivot table to the data model

Getting Started with Mirth (Part 1)