Reputation: 29
I am new to svn.Svn repository is in Linux,and developers are working on windows using TSVN client.I implemented a per-commit hook with a proper comment of 32 characters.it is working in Linux.But i tried in TSVN client to commit the code with comment is less than 32 characters it is working.Can any one help me on this.
Here is the code:
$minchars = 10;
$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);
Upvotes: 0
Views: 2811
Reputation: 107040
Try this:
Copy your script to another directory and modify it to use the -r
parameter for the svnlook
command rather than -t
. Then, try it with a commit revision that should have failed.
For example:
$ cd $repo_dir/hooks
$ cp pre-commit $HOME
$ cd
$ vim pre-commit #Change from Transaction to Revision
$ # Revision #123 should have failed
$ ./pre-commit $repo $rev
If the script doesn't produce an error, you can try such things as printing out the comment in quotes to see whether or not it's zero in length, etc. It'll help you find the possible logic error in your script.
You should also use use strict;
and use warnings;
in your Perl scripts because it easily picks up errors you might not realize you have in your script. It's so easy to forget that a particular variable wasn't necessarily set, or that you mistyped a variable. These pragmas will pick up these types of errors which seem to cause about 90% of the problems in Perl:
#! /usr/bin/env perl
use strict;
use warnings;
my $svnlook = "/usr/bin/svnlook";
my $minchars = 10;
my $repos = $ARGV[0];
my $txn = $ARGV[1];
chomp ( my $comment = qx($svnlook log -t $txn $repos) );
if (not $comment) {
die "A comment is required!\n";
}
elsif ( length $comment < $minchars ) {
die "Comment must be at least $minchars characters.\n";
}
exit 0;
You can also use my pre-commit script. It can be used to verify the length and structure of the commit comment. For example, you could require the commit comment to require a defect ID. It also allows you to control who has commit rights in what parts of your repository and also enforce the use of certain properties on certain files. For example, you might want to make sure all shell scripts and Perl scripts have the svn:eol-style
set to either native
or LF
.
It can also allow users to create a tag, but not allow users to make changes in a tag once created. This prevents users from accidentally checking out a tag, making a change, and then committing it.
And, one more thing:
Take a look at a continuous build system such as Jenkins. One of the things I've discovered is that by merely doing continuous builds, developers naturally improve their commit messages without doing any sort of enforcement.
That's because commit messages are now easily visible. Jenkins shows the changes in each build, whether the build itself was successful, test results, etc. It shows the changes and the commit comments. Suddenly, the commit comments become much more useful to the developers themselves, and they simply do better comments.
You can look at an svn log
and see when I implemented Jenkins: Before there were either no commit comments, or such useful things as "reformatted code" or the very helpful "made changes" (both longer than 10 characters). Suddenly the comments are "Fixed BUG-1233. Checked for null pointer before passing it to foo method".
Upvotes: 2