Subversion hook to verify unit testing?
Ever since last year, we’ve setup subversion to require comments are added before a file can be committed to our SVN repositories. Even just small comments on file commits is helpful.
But what I REALLY want is a subversion hook that requires a file is unit tested before it can be submitted to the repository. Think of the power of that. In fact let me say that again…
Before you can commit a file, you HAVE TO TEST IT LOCALLY.
That’s one of the things I’ve been working on with my inline CFML debugger. So far it’s pretty simple, I’ve added an attribute to the cffunction tags in my unit tests called TestApproved which can either be 1 or 0. So when you run a unit test the inline debug gives you a form to approve the test. If the test itself doesn’t throw an error you have decide if the results of the code are correct. Then you just approve.
I just got that working yesterday, this week I’ll play with the SVN pre-commit hook. I think that’s what I want. Basically I’m just going to have the pre-commit hook search for those TestApproved attributes. I’m going to make it fudgeable on purpose.
Has anyone out there ever done a pre-commit hook with subversion?

Hey, no specific help to you on this, but we are in a similar spot with a different kind of post commit hook. We have had some success, but its still not right so I feel your pain.
Any Subversion pros out there that can do a little freelance work on the side??
Comment by Eric Hoffman — October 22, 2008 @ 12:00 am
Yeah I’ve got a pretty sweet post-commit hook working where it automatically does an svn update on a staging server. So when someone commits to the repository it automatically shows up on the central server for others to look at.
I’ve been researching this pre-commit hook concept. I think I have a pretty good understanding of it. I’m considering using cURL to call a .cfm page so I can do the heavy lifting with CF instead of batch file bullshit.
Comment by Steve Nelson — October 23, 2008 @ 12:00 am
Thats the post commit hook I am trying to write. Any chance of letting me see how you got yours to work?
Pretty ingenious running a cURL call. Hmm.
We just moved to Collabnet Sourceforge Enterprise 5, which bundles subversion…its on a wmware image on a windows box. Adds a little layer of intracacy for me. At some point they will migrate it to a full linux box and run it natively. With no linux admins in house though, thats why we went VMWare image until we get one on contract.
Anyhow, these hooks are pretty powerful, so was very interested in seeing how others use it…and your idea for validation purposes is sweet.
Comment by Eric Hoffman — October 23, 2008 @ 12:00 am
Dan Switzer did a great blog post on a post-commit hook. Take a look:
http://blog.pengoworks.com/index.cfm/2008/2/5/SVN-postcommit-for-Windows
Comment by Steve Nelson — October 25, 2008 @ 12:00 am
While Subversion hooks are pretty powerful, Subversion really needs a *policy* system. I tried to write a post-commit hook that automatically applies svn:needs-lock to binary files (determined by a regex against file extension), and I ended up having to check out the revision, apply the property locally, then check it back in – all INSIDE the post-commit hook. There’s some dicey synchronization going on there, I can tell you that!
Of course, the official position is "educate your users" to apply locks, and use a pre-commit hook to verify that they’ve done so. Um, you want me to explain the concept and the UI of commit locks to my sales guys and project managers? And force them to do something that could be automated? (The only practical alternative is to pass around a bunch of pre-commit hooks for *Tortoise*, but what happens when one of them is working remotely?)
A proper policy-based system would clear up a lot of the problems people have with pre- and post-commit hooks.
Comment by Oluseyi — November 4, 2008 @ 12:00 am