If you are using Subversion, you might have come across this issue. Multiple developers working on a set of files and committing them without any comments. If you decide to force comments on every commit, here is a little pre-commit hook script that will do the job. Just to be clear, a pre-commit script is fired when the user hits the ‘OK’ button on the commit dialog box.
This script would need to be under /{repository-location}/hooks/. There are some template scripts already in there and this one is probably a slight modification of one of those samples in there.
Here it is.
[xml]
@echo off
::
:: Stops commits that have empty log messages.
::
@echo off
setlocal
rem Subversion sends through the path to the repository and transaction id
set REPOS=%1
set TXN=%2
rem check for an empty log message
svnlook log %REPOS% -t %TXN% | findstr . > nul
if %errorlevel% gtr 0 (goto err) else exit 0
:err
echo. 1>&2
echo Your commit has been blocked because you didn’t give any log message 1>&2
echo Please write a log message describing the purpose of your changes and 1>&2
echo then try committing again. — Thank you 1>&2
exit 1
[/xml]
ok ok ..now i got … ok and what about linux..??
hello sir thanks for helping ..such a nice blog..
and in linux where i add this command..?..
my file is
#!/bin/sh
REPOS=”$1″
TXN=”$2″
# Make sure that the log message contains some text.
SVNLOOK=/usr/local/bin/svnlook
$SVNLOOK log -t “$TXN” “$REPOS” | \
grep “[a-zA-Z0-9]” > /dev/null || exit 1
# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
commit-access-control.pl “$REPOS” “$TXN” commit-access-control.cfg || exit 1
# All checks passed, so allow the commit.
exit 0
look at point #6 on this page http://www.howtoforge.com/setting-up-subversion-with-webdav-post-commit-hook-and-multiple-sites-on-jaunty-jackalope-ubuntu-9.04
ok thnx…
but i m using webfaction hosting and its on
Linux 2.6.18-238.12.1.el5PAE i686
..???
so dont know how that script run.?
I would think via SSH ? Not sure if that’s doable in shared hosting or not…contact your host.
Very Good!!
Thanks!
Wow it works great!
Don’t forget to rename the file to pre-commit and to make it executables.
Thanks
Siva
I have copied this shell script for pre-commit.sh to my hooks folder, but when I commint without commit message, it is not throwing error, from where it takes values of $1, $2 in the script. Could you please explian me bit in depth.
Hi Sagar,
i have taken this linux script and placed under hooks folder as pre-commit.sh file and given excute permission. when I commit the file without commit message, it is not throwing error and successfully creating revision in svn. Could you please explain me in depth, from where $1, $2 takes values. Do we need to call this script somewhere. Please help me. i have to setup this restriction to my svn server
Hi, your code will work only for a single repository what about if I am having multiple repository that too are generate by code.
Hi ,
how can add another condition to the above logic if people do not enter with letter DE followed by 3 0r 4 numbers (e.g DE123 or DE1234) in svn log message while doing commit.