[英]What is the format of the deltas in a subversion respository, and how badly can I blow it up if I change them in a pre-commit hook?
[英]How can I access the commited file from a Subversion pre-commit hook in Perl?
我需要执行以下操作:
用 Perl 编写预提交钩子
Hook 应该检查所有提交的文件是否存在某些文本,如果找不到该文本则失败
基本上,我需要一个 Perl 钩子的例子来读取正在提交的文件。
我真的在寻找一些代码最少的优雅解决方案。
注意:Hook 应该使用svnlook
或其他更好的方式来查找文件。
预提交钩子:
my $repos = shift;
my $txn = shift;
foreach my $line (`$svnlook changed -t $txn "$repos"`)
{
chomp($line);
if ($line !~ /^([AUD_]).\s\s(.+)$/)
{
print STDERR "Can't parse [$line].\n";
exit(1);
}
else
{
my $action = $1;
my $file = $2;
chomp($file);
#If path has trailing slash, then it is a folder and we want to skip folders
if($file =~ /\/$/)
{
next;
}
my $fileContent = `$svnlook cat -t $txn "$repos" "$file"`;
if ($action =~ /[AU]/)
{
my @lines = split(/\n/, $fileContent );
#Check for whatever you need in this file's content
}
}
}
在 Python 中修改这个例子来做你想做的事情应该不会太难。 另请参阅存储库的hooks
子目录以获取一些模板和钩子脚本以及贡献的钩子脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.