如何从 Perl 中的 Subversion 预提交钩子访问提交的文件? [英] How can I access the commited file from a Subversion pre-commit hook in Perl?
本文介绍了如何从 Perl 中的 Subversion 预提交钩子访问提交的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要执行以下操作:
在 Perl 中编写预提交钩子
Write pre-commit hook in Perl
Hook 应该检查所有提交的文件是否存在某些文本,如果找不到该文本则失败
Hook should check all files being committed for presence of some text, and fail if that text is not found
基本上,我需要一个读取正在提交的文件的 Perl 钩子示例.
我真的在寻找代码最少的优雅解决方案.
I am really looking for some elegant solution with the least amount of code.
注意事项:Hook 应该使用 svnlook
或其他更好的方式来查找文件.
Notes:
Hook should use svnlook
or other better way to find files.
推荐答案
预提交钩子:
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
}
}
}
这篇关于如何从 Perl 中的 Subversion 预提交钩子访问提交的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文