How to force Comments on SVN Commit

On February 14, 2008, in Subversion, by Anuj Gakhar

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.


@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

Tagged with:  

69 Responses to How to force Comments on SVN Commit

  1. sagar says:

    ok ok ..now i got … ok and what about linux..??

  2. sagar says:

    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

  3. Rodolfo says:

    Very Good!!

  4. Hyeok says:

    Thanks!

  5. jean says:

    Wow it works great!
    Don’t forget to rename the file to pre-commit and to make it executables.

    Thanks

  6. cvakumark says:

    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.

  7. cvakumark says:

    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

  8. Santosh Kumar says:

    Hi, your code will work only for a single repository what about if I am having multiple repository that too are generate by code.

Leave a Reply

© 2011 Anuj Gakhar
%d bloggers like this: