
How a commit hook is invokedĪs with most things Subversion, it’s pretty simple. For example, the Thumbs.db file really shouldn’t exist in your repository and you may want to enforce its exclusion. Another common use case is to prohibit certain file patterns. “Appropriate” may simply mean characters must exist or it could lay out some rules for what constitutes an acceptable pattern. If the hook program writes data to stderr, it will be marshalled back to the client.īy far the most common use case for pre-commit hooks is ensuring a revision is accompanied by an appropriate comment. If the program returns a non-zero exit value, the commit is aborted and the transaction is removed. The repository passes two arguments to this program: the path to the repository, and the name of the transaction being committed. Typically, this hook is used to protect against commits that are disallowed due to content or location (for example, your site might require that all commits to a certain branch include a ticket number from the bug tracker, or that the incoming log message is non-empty). This is run when the transaction is complete, but before it is committed. Let’s look a bit more into what the SVN book has to say about the pre-commit hook: There are half a dozen other hook events relating to different server events but we’ll ignore them for the purpose of this post. Valid transaction lifecycle events include start-commit (before a transaction is created), pre-commit (the transaction is complete but not committed) and post-commit (the transaction is committed and a new revision has been created). About commit hooksĪ common SVN practice, and a good use case for writing a bit of code, is to create event hooks which fire at certain points in the transaction lifecycle of a commit to a repository.

#Subversion pre commit hook code#
Having said that, there’s nothing specific to this particular SVN distribution so the concepts and code snippets should be equally relevant to any others. NET realm so hopefully this will make someone’s life a little easier.Īs with the previous blog post, all the info in this post relates to a Visual SVN Server instance of Subversion. There are a heap of examples out there in Python and Perl but not much in the. This is a great way of quickly and easily giving users a self-service mechanism for managing their own repositories in a controlled, secure fashion.Ĭontinuing the theme of customising SVN to do your bidding I thought I’d share some info on commit hooks. NET to perform common management tasks in SVN such as provisioning a repository or managing permissions. A while back I wrote about Creating your own custom Subversion management layer which involved rolling your own UI in.
