Does anybody know how to prevent commits to a Subversion code repository when there is no commit comment entered?
-
15Note that hooks can only prevent accidental commits without comments. Unless you educate your users, they will just commit with something like "fix bug" instead, which has no merit over an empty message. – Thilo Dec 18 '09 at 12:54
-
1I agree with Thilo. If your intention is to prevent mistakes when commiting without comments, the solutions provided here are going to work. If you want this to force your users to provide meaningful comments by forcing them to comment, they're going to write "fix bugs" and "new feature" in all commits. This is a culture issue. – GmonC Dec 18 '09 at 13:03
-
1Agreed, this is most important. – Dec 20 '09 at 12:55
-
1Yes, you cannot force users to write meaningful comments or even understandable. But forcing them to write something instead of just brainlessly sending commits off helps a lot in my experience. And for those who just write "fixed" or such, a chat between people can go a long way. And if this does not help, consider searching for alternatives in the wetware. – jramb Mar 07 '18 at 07:47
6 Answers
You can use a hook (put it into <repository>/hooks
and name it pre-commit.bat
(Windows)):
@echo off
::
:: Stops commits that have empty log messages.
::
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
src: http://www.anujgakhar.com/2008/02/14/how-to-force-comments-on-svn-commit/

- 13,080
- 3
- 33
- 54

- 181,842
- 47
- 306
- 310
-
5+1, though of course this can't force users to use meaningful comments. svn commit -m "foo" foo.h would still work. – Glen Dec 18 '09 at 12:52
-
-
Excellent, does this hook work client-side or serverside? Ideally, I would want this to work serverside to prevent everyone from commiting without commit message. – anaotha Sep 11 '20 at 08:43
Here is a pre-commit hook with @miku's detailed error message for Linux:
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" > /dev/null
GREP_STATUS=$?
if [ $GREP_STATUS -ne 0 ]
then
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
fi
exit 0

- 28,416
- 10
- 82
- 109
Actually, when you create a Subversion repository, its hooks
subdirectory already contains hook samples. Check out the one called pre-commit.tmpl
for details on the hook's parameters. It also contains an example for a hook that you're looking for:
#!/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
You can write your hook in any script or language, as long as it's executable on your Subversion machine.

- 6,401
- 2
- 27
- 34
-
This works for me on Ubuntu with UberSVN. Though I need to point SVNLOOK to `/opt/ubersvn/bin/svnlook` – Nam G VU Aug 15 '11 at 14:21
-
1I also have to `sudo chmod 777 pre-commit` to get it works; otherwise, all commits are refused. – Nam G VU Aug 15 '11 at 14:23
-
2@NamGiVU 777 should not be used lightly, you just had to use 700 or 750 on the file for it to work if the owner is correctly set. – Shadok Feb 16 '12 at 14:26
-
Thanks @Shadok. Though I have no idea on `the owner is correct`. Would be nice if you can point out more – Nam G VU Feb 17 '12 at 02:46
-
2@NamGiVU You should take a day or two to read general documentation on linux because it seems you lack some basic skills (no offense), have a look here for a quick lesson on files onwership and permissions: http://code.google.com/edu/tools101/linux/ownership_permissions.html – Shadok Feb 17 '12 at 10:16
If you are using TortoiseSVN only then you can add TortoiseSVN's property to the root directory:
property name: tsvn:logminsize
value: 1
This will disable OK button in TortoiseSVN commit window then Message is empty.
Please be aware that this property is TortoiseSVN specific it might not work with other SVN client.

- 131
- 2
- 3
Create a pre-commit hook. Here's some instructions on how to do so yourself, or here is an example hook script that will reject anything with a commit message shorter than 10 characters.

- 507,862
- 82
- 626
- 550
-
1
-
1The link to the sample hook script that rejects anything shorter then 10 characters is broken. – tgharold Dec 26 '12 at 14:38
-
2this answer is all a bit "link only". Couldn't you put the contents of the hook example into the answer? – Liam Jun 30 '14 at 09:44
Linux script for more than 15 characters--
#!/bin/bash
REPOS="$1"
TXN="$2"
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
# Comments should have more than 5 characters
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep [a-zA-Z0-9] | wc -c)
if [ "$LOGMSG" -lt 15 ];
then
echo -e "Please provide a meaningful comment when committing changes." 1>&2
exit 1
fi
Source-http://java.dzone.com/articles/useful-subversion-pre-commit

- 606
- 1
- 9
- 24