SVN 预提交脚本检查 mkdir

发布于 2024-08-13 10:00:52 字数 1699 浏览 8 评论 0原文

我为 SVN 编写了以下预提交脚本,以验证用户是否在文件提交中提交了最少量的信息。但是,当尝试添加/删除目录时,现在失败了。我知道为什么它明显失败,我只是没有意识到每个操作都会调用预提交脚本。如何过滤正在执行的操作?我可以使用 svn log 来做到这一点还是需要使用其他东西?

<?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);  
}
?>

如何测试当前事务中正在执行什么 svn 命令?基本上我只希望验证在 svn commit 上运行,而不是在副本、mkdir 等上运行...

提前致谢!

编辑:我可能应该在原始帖子中进行澄清,我正在使用 TortoiseSVN 的创建文件夹...来执行此操作。也许 TortoiseSVN 正在执行某种提交操作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂归处 2024-08-20 10:00:52

我没有一个很好的答案给你,但是......

也许你可以使用 svnlookchanged --copy-info 来帮助一下。使用它,您可以判断某个项目是否是从某个地方复制的。如果所有项目都被复制,那么可以安全地从 svn copy 指令中假设这一点。同样,如果您检查返回的项目,您应该能够确定它是否也来自添加或删除目录(因为它只是添加或删除的单个目录项目。)

希望它有所帮助......

I don't have a great answer for you, but...

Maybe you can use svnlook changed --copy-info to help a bit. Using that, you can tell if an item was copied from somewhere. If all items are copied, then it may be safe to assume this from an svn copy instruction. Likewise, if you checking the items returned, you should be able to determine if it was from adding or deleting a directory as well (since it will just be a single directory item being added or deleted.)

Hope it helps somewhat...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文