I wrote the following pre-commit script for SVN to validate that a user has submitted the minimum amount of information on a file commit. However, when trying to add/delete a directory, now it is failing. I know why it's failing obviously, I just didn't realize the pre-commit script was called on every action. How do I filter for the action being performed? Can I do that with svn log or do I need to use something else?
<?php
define('SVNLOOK', "\"C:\Program Files\CollabNet\Subversion Server\svnlook.exe\"");
define('NOTEXT', 1000);
define('NOPATTERNMATCH', 1001);
define('ERRORPROCESSING', 9999);
$repo_path = $argv[1];
$transaction = $argv[2];
$tracking_regex_pattern = "/\b(?:bug|issue|ter)\s*[#]{0,1}(\d+)\b/i";
exec(SVNLOOK . " log $repo_path -t$transaction", $revisions);
//loop through transaction message line by line for validation
$validation_passed = (bool) false;
$has_text = (bool) false;
foreach($revisions as $change_line){
$change_line = trim($change_line);
if (!empty($change_line)){
$has_text = true;
if (preg_match($tracking_regex_pattern, $change_line)) {
$validation_passed = true;
}
}
}
if(!$validation_passed){
switch($has_text) {
case true:
throwError(NOPATTERNMATCH, $revisions);
break;
case false:
throwError(NOTEXT, $revisions);
break;
default:
throwError(ERRORPROCESSING, $revisions);
break;
}
}else{
exit(0);
}
function throwError($error_code, $revisions){
$fp = fopen('php://stderr', 'w');
fwrite($fp, "********** (Error Code: $error_code) **********\n");
foreach($revisions as $change_line) {
fwrite($fp, $change_line."\n");
}
fclose($fp);
exit($error_code);
}
?>
How do I test for what svn command is being exectued in the current transaction? Basically I only want the validation to run on a svn commit and not a copy, mkdir, etc...
Thanks in advance!!!
EDIT: I probably should have clarified with the original post, I am using TortoiseSVN's Create Folder... to do this. Maybe TortoiseSVN is doing some kind of commit operation?