Label Cloud

Thursday, November 22, 2007

Subversion pre-commit hooks

I am using a wonderful source control product Subversion. More information is available on http://subversion.tigris.org

A great future of subversion is an ability to run a server script before the check-in is committed . The script has the ability to rollback the check-in. We are using this functionality to enforce comments for every check-in.

To create a script, place any executable file into a hooks folder in the repository. You can start with a pre-commit.tmpl template file that is located there already. The template is a perl script that accomplishes exactly that functionality.

Our subversion runs on a windows system, so we converted the perl script into a batch file

"c:\Program Files\Subversion\bin\svnlook.exe" log -t %2 %1 | FindStr [a-zA-Z0-9]
IF %ERRORLEVEL% EQU 0 GOTO OK
echo "Commit Comments are Required" >&2
exit 1
:OK
exit 0

Place the code into a pre-commit.bat batch file in the hooks directory.

Technorati Tags: ,,,


Share/Save/Bookmark

8 comments:

Anonymous said...

Exactly what I am looking for. Thanks!

Anonymous said...

Wonderful! I was battling with a script using grep, but this one worked first try.

Thank you!

mcraig88 said...

Worked for me too! Thanks for posting. Not enough examples of Win based scripts out there.

Anonymous said...

You hero! Nice to see something simple.

big.bald.dave said...

Thank you, good sir.

Anonymous said...

Thanks for this. This should knock my lazy colleagues into shape!

Anonymous said...

Sweet! I'd been looking for a way to use findstr in this manner without resorting to temp files. Thanks a bunch!

Never Been Kissed said...

Hi,

Thanks for the great script. It works sweet :)

Can you also guide on pre-commit script to enforce svn:needs-lock is set on all files

Directory of Computers/Tech Blogs