How to require commit messages in VisualSVN server?
We've got VisualSVN Server set up as our Subversion server on Windows, and we use Ankhsvn + TortoiseSVN as clients on our workstations.
How can you configure the server to require commit messages to be non-empty?
I'm glad you asked this question. This is our pre-commit hook script written in common Windows Batch. It denies commit if the log message is less than 6 characters. Just put the pre-commit.bat to your hooks directory.
pre-commit.bat
setlocal enabledelayedexpansion
set REPOS=%1
set TXN=%2
set SVNLOOK="%VISUALSVN_SERVER%\bin\svnlook.exe"
SET M=
REM Concatenate all the lines in the commit message
FOR /F "usebackq delims==" %%g IN (`%SVNLOOK% log -t %TXN% %REPOS%`) DO SET M=!M!%%g
REM Make sure M is defined
SET M=0%M%
REM Here the 6 is the length we require
IF NOT "%M:~6,1%"=="" 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
VisualSVN Server 3.9 provides the VisualSVNServerHooks.exe check-logmessage
pre-commit hook that helps you reject commits with empty or short log messages. See the article KB140: Validating commit log messages in VisualSVN Server for instructions.
Besides the built-in VisualSVNServerHooks.exe
, VisualSVN Server and SVN in general uses a number of hooks to accomplish tasks like this.
-
start-commit
— run before commit transaction begins, can be used to do special permission checking -
pre-commit
— run at the end of the transaction, but before commit. Often used to validate things such as a non zero length log message. -
post-commit
— runs after the transaction has been committed. Can be used for sending emails, or backing up repository. -
pre-revprop-change
— runs before a revision property change. Can be used to check permissions. -
post-revprop-change
— runs after a revision property change. Can be used to email or backup these changes.
You need to use 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:
- Perl Script
- Python Script
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:
- Generated Changenotes (well - this'd actually make a nice automatic tool to enforce good messages if I know that they will be (with my name) publically visible - if only for the team)
- License issues: You might need to know the origin of code later, e.g. should you want to change the license to your code (Some organizations even have standards for commit message formatting - well, you could automate the checking for this, but you'd not necessarily get good commit messages with this)
- Interoperability with other tools, e.g. bugtrackers/issue management systems that interface with your version control and extract information from the commit messages.
Hope that helps, additionally to the technical answers about precommit hooks.