views:

385

answers:

8

Possible Duplicates:
Any svn:hook script that enforce commit with comments?
Creating a Required Comment Hook for Tortoise SVN

I often see a slew of commits, but no notes referencing the tickets... And so I end up going back and reviewing the diff manually. Not necessarily bad, but it would be nice to have notes. Any ideas?

+2  A: 

Sure, but how are you going to enforce non-gibberish, meaningful and contextualized commit messages?

Better to just punch your irresponsible coworkers when you notice a lame/empty commit. Or the verbal equivalent of punch. Just make sure they feel bad, it's deserved.

kch
It's true that a pre-commit script will not stop people from typing "updated project" in the box, but I've seen the commit messages go from 90% empty to 90% reasonable messages here after implementing one. You have to do less punching if you have a pre-commit script.
Wim Coenen
Cattleprods on order for just this purpose.
Jim T
+4  A: 

You can define a pre-commit hook script which rejects all commits with an empty or too short log message.

Here is a post on how to do it.

Nadia Alramli
+1  A: 

I have used a pre-commit hook script to ensure that a commit comment always refers to an issue number in the issue tracking system. For example, a comment such as

fixes frobulator when the moon is full (bug 1234)

would be accepted because it contains a bug number. Even with this arrangement, you still have to trust the developer to insert a meaningful comment and bug number.

Greg Hewgill
1.6 now includes reg-ex matching of bug numbers and can raise a warning if no bug number is found (won't reject it, but better than nothing).
Jim T
+1  A: 

Our pre-commit hookscript (windows batch):

@echo off & setlocal ENABLEEXTENSIONS

set SVNLOOK="E:\Subversion\Program\Subversion 1.5.0\bin\svnlook.exe"

set REPOS=%1%
set TXN=%2%
set LOGFILE=%REPOS%\hooks\log-%TXN%.txt
set GREP=E:\UnxUtils\usr\local\wbin\grep.exe

%SVNLOOK% log -t "%TXN%" "%REPOS%" >%LOGFILE%

set "first="
for /f "delims=" %%a in ('more ^< "%LOGFILE%"') do (
  if not defined first set first=%%a
)

del %LOGFILE%

if not defined first ( echo "Please supply a commit comment" >&2 & exit 1 )





REM Check for invalid windows characters in the path
echo Checking >%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | find "\" >>%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | find ":" >>%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | find "*" >>%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | find "?" >>%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | find """" >>%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | find "^>" >>%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | find "^<" >>%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | find "^|" >>%LOGFILE%

set "first="
for /f "delims=" %%a in ('more +1 ^< "%LOGFILE%"') do (
  if not defined first set first=%%a
)

del %LOGFILE%

if defined first ( echo "Please do not use filename characters which are invalid in  windows. - Found %first%" >&2 & exit 1 )






REM Tagblock - prevent changes to tag directories
echo Checking >%LOGFILE%
%SVNLOOK% changed -t "%TXN%" "%REPOS%" | %GREP% "^U.*\/tags\/.*" | %GREP% -v -f "%REPOS%\conf\tag-block-exceptions.txt" >>%LOGFILE%

set "first="
for /f "delims=" %%a in ('more +1 ^< "%LOGFILE%"') do (
  if not defined first set first=%%a
)

del %LOGFILE%


if defined first ( 
    echo "%first% -- Error: Modifications to tag directories are blocked. To allow these modifications add the path to %REPOS%\conf\tag-block-exceptions.txt" >&2 
    exit 1 )
Jim T
+5  A: 

Not TortoiseSVN, but Subversion itself - a setting on the server. You can set up a pre-commit hook that enforces a commit comment. There are also pre-commit hooks that will verify the presence of a reference to an issue tracking system like Jira if you want to go one step further.

David M
TortoiseSVN has the tsvn:logminsize property. If you set that property to e.g. 10, then the OK button will stay disabled until at least 10 chars are entered as a commit message.
Stefan
A: 

TortoiseSVN is a client, you might want to force comments on the subversion server. Or you can tell them to comment their commits.

Bertrand Marron
That is the same link I originally bookmarked when I built my script, the only issue I had is that it requires a direct path for the call function.
Nate Bross
+1  A: 

You need to use a pre-commit hook which is a server setting, I have written one for VisualSVN which is basically a batch file -- similar scripts are available for non-windows based SVN Servers.

@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
call "C:\program files\visualsvn server\bin\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
Nate Bross
+1  A: 

You can force a commit comment easily enough, but what you'll end up with is a million commits that say "debugging" or "testing".

If your developers don't see the value in adding commit messages forcing them to type something is not going to change that.

What's worse is when Eclipse users have SVN/CVS integrated such that it remembers their last commit message - and they end up committing a completely unrelated file with the message from their last task/project.

Anon