Chi*_*ago 5 svn perl pre-commit-hook
我需要做以下事情:
在Perl中编写预提交钩子
Hook应该检查所有提交的文件是否存在某些文本,如果找不到该文本则会失败
基本上,我需要一个Perl钩子的例子来读取被提交的文件.
我真的在寻找一些代码最少的优雅解决方案.
注意:Hook应该使用svnlook
或其他更好的方式来查找文件.
Chi*_*ago 11
预提交钩子:
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
}
}
}
Run Code Online (Sandbox Code Playgroud)