...
Code Block | ||||
---|---|---|---|---|
| ||||
#!/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; } ?> |
Test
Code Block |
---|
:> svn add q.exe
A q.exe
:> svn commit -m "파일 추가"
Adding my-proj/q.exe
Transmitting file data .svn: Commit failed (details follow):
svn: Commit blocked by pre-commit hook (exit code 1) with output:
---------------------------------------------------------------------------
You commit has been blocked because you are trying to commit a restricted file
"my-proj/q.exe"
--------------------------------------------------------------------------- |
See Also
...