#!/usr/bin/php
<?php
$svnlook = 'svnlook';
$repos = $argv[1];
$txn = $argv[2];
$change = `$svnlook changed "$repos" -t "$txn"`;
## repos 에 추가 허용할 파일의 확장자
$white_list = array(".java", ".cpp", ".xml");
if ( ($ret = checkHasRestrictedFile($white_list, $change))) {
fwrite(STDERR, "---------------------------------------------------------------------------\n");
fwrite(STDERR, "You commit has been blocked because you are trying to commit a restricted file \n");
fwrite(STDERR, "\"$ret\"\n");
fwrite(STDERR, "---------------------------------------------------------------------------\n");
exit(1);
}
function checkHasRestrictedFile($white_list, $changed)
{
foreach(preg_split("/((\r?\n)|(\r\n?))/", $changed) as $line) {
if ( substr($line,0, 2) == "A ") {
$file_ext = substr(strrchr($line, "/"), 1);
if (strlen($file_ext) > 0) {
$ext = substr(strrchr($file_ext, "."), 0);
if (!in_array($ext, $white_list)) {
return str_replace("A ", "", $line);
}
}
}
}
return null;
}
?> |