We've got VisualSVN set up as our Subversion server on Windows, and we use Ankhsvn + TortoiseSVN on our client workstations.
How can you configure the server to require commit messages to be non-empty?
We've got VisualSVN set up as our Subversion server on Windows, and we use Ankhsvn + TortoiseSVN on our client workstations.
How can you configure the server to require commit messages to be non-empty?
I believe you'll have to setup a pre-commit hook that will check for the message.
Indeed just by googling the first result I got was a perl pre-commit script to do exactly what you intended.
SVN uses a number of hooks to accomplish tasks like this.
You want the pre-commit hook. You can write it yourself in just about any language your platform supports, but there are a number of scripts on the web. Googling "svn precommit hook to require comment" I found a couple that looked like they would fit the bill:
The technical answers to your question have already been given. I'd like to add the social answer, which is: "By establishing commit message standards with your team and getting them to agree (or accept) reasons why one would need expressive commit messages"
I've seen so many commit messages that said "patch", "typo", "fix" or similar that I've lost count.
Really - make it clear to everybody why you'd need them.
Examples for reasons are:
Hope that helps, additionally to the technical answers about precommit hooks.
What VisualSVN offers you to enter as hooks are "Windows NT command scripts", which are basically batch files.
Writing if-then-else in batch files is very ugly and probably very hard to debug.
It will look something like the following (search for pre-commit.bat) (not tested):
SVNLOOK.exe log -t "%2" "%1" | grep.exe "[a-zA-Z0-9]" > nul || GOTO ERROR
GOTO OK
:ERROR
ECHO "Please enter comment and then retry commit!"
exit 1
:OK
exit 0
You need a grep.exe on the path, %1 is the the path to this repository, %2 the name of the txn about to be committed. Also have a look at the pre-commit.tmpl in the hooks directory of your repository.
Good question and good solution! By the way, how can we modify commited files in start commit or pre-comit hook?
Prior to adding commit hooks to my server, I just distributed svnprops to the tortoisesvn clients.
So, as an alternative:
In tortoiseSVN -> Properties property name - add/set tsvn:logminsize appropriately.
This of course is no guarantee on the server as clients/users can opt not to do it, but you can distribute svnprops files if you like. This way users don't have to set their own values - you can provide them to all users.
This also works for things like bugtraq: settings to link issue tracking stuff in the logs.
Use this on Windows:
svnlook log -t "%2" "%1" | c:\tools\grep -c "[a-zA-z0-9]" > nul
if %ERRORLEVEL% NEQ 1 exit 0
echo Please enter a check-in comment 1>&2
exit 1
You'll need a copy of grep, I recommend the gnu tools version.
tried this but no luck:
svnlook log -t "%2" "%1" | c:\tools\grep -c "[a-zA-z0-9]" > nul
if %ERRORLEVEL% NEQ 1 exit 0
echo Please enter a check-in comment 1>&2
exit 1
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
also, how to check for comment length is more important than no comment at all!
Here's a Windows Shell JScript that you can use by specifying the hook as:
%SystemRoot%\System32\CScript.exe //nologo <..path..to..script> %1 %2
It's pretty easy-to-read, so go ahead an experiment.
BTW the reason to do this in JScript is that it does not rely on any other tools (Perl, CygWin, etc) to be installed.
if (WScript.Arguments.Length < 2)
{
WScript.StdErr.WriteLine("Repository Hook Error: Missing parameters. Should be REPOS_PATH then TXN_NAME, e.g. %1 %2 in pre-commit hook");
WScript.Quit(-1);
}
var oShell = new ActiveXObject("WScript.Shell");
var oFSO = new ActiveXObject("Scripting.FileSystemObject");
var preCommitStdOut = oShell.ExpandEnvironmentStrings("%TEMP%\\PRE-COMMIT." + WScript.Arguments(1) + ".stdout");
var preCommitStdErr = oShell.ExpandEnvironmentStrings("%TEMP%\\PRE-COMMIT." + WScript.Arguments(1) + ".stderr");
var commandLine = "%COMSPEC% /C \"C:\\Program Files\\VisualSVN Server\\bin\\SVNLook.exe\" log -t ";
commandLine += WScript.Arguments(1);
commandLine += " ";
commandLine += WScript.Arguments(0);
commandLine += "> " + preCommitStdOut + " 2> " + preCommitStdErr;
// Run Synchronously, don't show a window
// WScript.Echo("About to run: " + commandLine);
var exitCode = oShell.Run(commandLine, 0, true);
var fsOUT = oFSO.GetFile(preCommitStdOut).OpenAsTextStream(1);
var fsERR = oFSO.GetFile(preCommitStdErr).OpenAsTextStream(1);
var stdout = fsOUT && !fsOUT.AtEndOfStream ? fsOUT.ReadAll() : "";
var stderr = fsERR && !fsERR.AtEndOfStream ? fsERR.ReadAll() : "";
if (stderr.length > 0)
{
WScript.StdErr.WriteLine("Error with SVNLook: " + stderr);
WScript.Quit(-2);
}
// To catch naught commiters who write 'blah' as their commit message
if (stdout.length < 5)
{
WScript.StdErr.WriteLine("Please provide a commit message that describes why you've made these changes.");
WScript.Quit(-3);
}
WScript.Quit(0);
This is ours. No extra tools required.
I'm glad you asked this question
pre-commit:
setlocal
set REPOS=%1
set TXN=%2
set SVNLOOK="C:\Program Files\VisualSVN Server\bin\svnlook.exe"
REM Make sure that the log message contains some text.
FOR /F "usebackq delims==" %%g IN (`%SVNLOOK% log -t %TXN% %REPOS% FINDSTR /R /C:......`) DO goto NORMAL_EXIT
:ERROR_TOO_SHORT
echo "Commit note must be at least 6 letters" >&2
goto ERROR_EXIT
:ERROR_EXIT
exit /b 1
REM All checks passed, so allow the commit.
:NORMAL_EXIT
exit 0
Hi I've installed VisualSVN Server 2.1.3 on my computer (XP Pro SP3) and the server is running correctly My Subversion client is TortoiseSVN 1.6.10 However, I'd like to use a pre commit hook to check empty comment in the commit dialog window. But It didn't work at all: here is a snapshot of my server structure: maquette architecture serveur I made right click on "Main"-->"Properties"-->"Hooks"-->"Pre-commit hook"
here is the batch script that I put in the proper window:
setlocal
set REPOS=%1 set TXN=%2
set SVNLOOK="C:\Program Files\VisualSVN Server\bin\svnlook.exe"
REM Faire en sorte que les Developpeurs Bancs de Test laissent un commentaire avant chaque "commit".
FOR /F "usebackq delims==" %%g IN (%SVNLOOK% log -t %TXN% %REPOS% FINDSTR /R /C:......
) DO goto NORMAL_EXIT
:ERROR_TOO_SHORT echo "Un commentaire d'au moins six caracteres est demandé. Merci" >&2 goto ERROR_EXIT
:ERROR_EXIT exit /b 1
REM verification effectuée, livraison en cours.
:NORMAL_EXIT
exit 0
But once in tortoiseSVN, without any comment, the commit is always allowed and files are updated.
What's wrong with my setting up ?
Sources :http://stackoverflow.com/questions/247888/how-to-require-commit-messages-in-visualsvn-server
Cordially Ben