我需要执行以下操作:
在Perl中编写预提交钩子
挂钩应该检查所有提交的文件中是否存在某些文本,如果找不到该文本,则挂钩将失败
基本上,我需要一个Perl挂钩示例来读取提交的文件。
我真的在寻找一种使用最少代码的优雅解决方案。
笔记:
挂钩应该使用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
}
}
}