Requiring Comments for Subversion Commits

14 Apr

One of the cool things about DreamHost is that it offers a free Subversion repository with its hosting package.  While it provides a convenient interface to set up a project repository, some things need to be configured manually.

When I checked in some code for today, I forgot to enter a comment for the commit.  There were no pre-commit hooks in place so the commit went through as it normally would.  This is undesired if I want to go back and revisit a specific change in the future by viewing the commit comments.

How do I make sure this doesn’t happen again?  There are a handful of sites online that offer solutions for this situation.  One that provided the most direct answer was from Word Aligned.  To add a pre-commit hook to block checkins containing empty comments, use the pre-commit script template file contained in the hooks directory of the Subversion repository.  Assuming you have access to the repository server:

1) Go to the hooks directory for your repository:


2) Copy the existing precommit-tmpl file to a file pre-commit

cp pre-commit.tmpl pre-commit

3) Make the new file executable

chmod +x pre-commit

One caveat is I commented out the following lines in the pre-commit script since I did not need to fine-tune access control for the time being (nor are the required files present by default in the hooks directory):

# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
"$REPOS"/hooks/ "$REPOS" $TXN \

That’s all there was to it for my situation.  See the Word Aligned article for details on testing the hook script and this person’s blog post for information on setting up

Leave a comment

Posted by on April 14, 2012 in How Tos


Tags: , , ,

Leave a Reply

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