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:  

63 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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2011 Anuj Gakhar