简体   繁体   English

SVN预提交钩子

[英]SVN Pre-Commit hook

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. 我是svn.Svn存储库在Linux中的新手,开发人员正在使用TSVN客户端工作。我实现了一个带有32个字符的正确注释的per-commit钩子。它在Linux中工作。但是我尝试在TSVN客户端中使用提交带注释的代码少于32个字符它正在工作。任何人都可以帮助我。

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);

Try this: 尝试这个:

Copy your script to another directory and modify it to use the -r parameter for the svnlook command rather than -t . 将脚本复制到另一个目录并修改它以使用svnlook命令的-r参数而不是-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; 你也应该使用use strict; and use warnings; use warnings; in your Perl scripts because it easily picks up errors you might not realize you have in your script. 在你的Perl脚本中,因为它很容易找到你可能没有意识到你的脚本中的错误。 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: 这些pragma会发现这些类型的错误,这些错误似乎导致Perl中大约90%的问题:

#! /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. 例如,您可以要求提交注释以要求缺陷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 . 例如,您可能希望确保所有shell脚本和Perl脚本都将svn:eol-style设置为nativeLF

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 . 看一下像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. Jenkins显示每个构建中的更改,构建本身是否成功,测试结果等。它显示更改和提交注释。 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). 您可以查看一个svn log ,看看我何时实现了Jenkins:在没有提交注释之前,或者“ 重新格式化的代码 ”或非常有用的“ 更改 ”(两个都超过10个字符)之类的有用的东西。 Suddenly the comments are " Fixed BUG-1233. Checked for null pointer before passing it to foo method ". 突然,评论是“ 固定BUG-1233。在将其传递给foo方法之前检查空指针 ”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM