How to force comments on Subversion Commit with Perl hook script

If you are using Subversion, you might have come across this issue. Multiple developers working on a set of files and committing them without any comments. If you decide to force comments on every commit, here is a little pre-commit hook script that will do the job.

This script would need to be under /{repository-location}/hooks/. Rename it as pre-commit and give it execution permissions.

#!/usr/bin/perl

# config section
$minchars = 4;
$svnlook = '/usr/bin/svnlook';

#--------------------------------------------
$repos = $ARGV[0];
$txn = $ARGV[1];
$comment = `$svnlook log -t "$txn" "$repos"`;
chomp($comment);

if ( length($comment) == 0 ) {
  print STDERR "A comment is required!";
  exit(1);
  }
elsif ( length($comment) < $minchars ) {
  print STDERR "Comment must be at least $minchars characters.";
  exit(1);
  }

exit(0);

Now if a developer attempts to do a COMMIT without a description he/she will get an error:

Transmitting content files....................svn: Commit failed:
svn: Commit blocked by hook pre-commit (return code 1) with output:
A comment is required!
Advertisements

One thought on “How to force comments on Subversion Commit with Perl hook script

  1. I saw your website while I was surfing around on http://injustfiveminutes.
    wordpress.com/2012/11/15/how-to-force-comments-on-subversion-commit-with-perl-hook-script/.
    Have you got any tips on methods to get registered on http:
    //injustfiveminutes.wordpress.com/2012/11/15/how-to-force-comments-on-subversion-commit-with-perl-hook-script/?

    I’ve been attempting to for quite a while but I never seem to get there. Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s