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!
1 comment

Popular posts from this blog

Getting Started with Mirth (Part 2)

Mirth

Visual Studio 2012–Debug in Chrome Incognito Mode