Wednesday, April 26, 2006

Checking file contents using Subversion Hooks

I found lots of examples of verifying checkin comments using Subversion commit hooks but nothing which showed me how to validate the contents of the file.

In my case I want to make sure that I'm not checking in any unit test files that have classes decorated with [CurrentFixture]. FYI I use MbUnit for my unit tests.

Using perl or shell scripts would be relatively easy but I wanted to do things the batch file way. Not sure why. Something repressed from my childhood no doubt.

I'm "sure" there's an easier way even using batch files but here's what I came up with. In the hooks directory in your Subversion repository edit the pre-commit.bat file like so:

set REPOS=%1
set TXN=%2
set FIXQUOTES=c:\util\FixQuotes
set PROJECTROOT=G:\Projects\VolMan

for /F "usebackq tokens=2" %%f in (`svnlook changed -t "%TXN%" "%REPOS%"`) do (
for /F "usebackq" %%x in (`%FIXQUOTES% %%f`) do (
for /F "usebackq" %%g in (`findstr /LM "[CurrentFixture]" %PROJECTROOT%\%%x`) do (
if not x%%g==x (
echo Cannot check in a file containing a class decorated with [CurrentFixture] 1>&2
exit 1
)
)
)
)


* - the output of svnlook has forward slashes '/' instead of the dos-friendly backslashes '\' which caused findstr to puke. I needed to create a cheeseball little app FixQuotes to flip all forward slashes to backslashes. Here's where perl/shell script would've made things trivial.

It's sooo yucky to hardcode the path to FixQuotes and the root of the project too. But c'est la vie.

If anyone has an easier way pleeease tell me.

[Listening to: Staple - The Day the Blind Revolted]

del.icio.us killed my blog!

Ever since I "found" del.icio.us I have had nothing to blog about. Well, that and my never before heights of laziness.

All of my old "ditto" blog entries ended up just getting tagged instead of blogged about. Not that there's really anyone who reads this (at least yet [fingers crossed]).

I have however recently dusted off my compiler and fired up my last project. Naturally it has nothing to do with Hookup as I'm pretty sure that Windows Workflow Foundation has put an end to my aspirations.

No, I'm heading along a much more reasonable path to world domination (I'd settle for domination of my basement mind you.)

I'm writing a simple app to maintain volunteer information for a race since I know a bit about that.

Hopefully this lasts.

Damn you del.icio.us

[Listening to (via Pandora): Pantera - It Makes Them Disappear]