2011-05-09 50 views
1

当我提交到存储库中我收到以下错误:为什么我得到这个错误:post-commit钩子失败(退出代码255),没有输出

post-commit hook failed (exit code 255) with no output. 

的后提交代码如下:

@echo off 

setlocal enableextensions 

set REPOS=%1 
set REV=%2 
set TEMPFILE=C:\TEMP\%REV%.txt 
set LOGFILE=D:\svn\logs\mysite\post_commit.log 

set MANTIS_PATH="D:\home\mantis" 

"C:\Program Files\SlikSvn\bin\svnlook" author %REPOS% -r %REV% >> %TEMPFILE% 2>>C:\TEMP\err.txt 
"C:\Program Files\SlikSvn\bin\svnlook" date %REPOS% -r %REV% >> %TEMPFILE% 2>>C:\TEMP\err.txt 
"C:\Program Files\SlikSvn\bin\svnlook" changed %REPOS% -r %REV% >> %TEMPFILE% 2>>C:\TEMP\err.txt 
echo revision:[%REV%] >> %TEMPFILE% 2>>C:\TEMP\err.txt 
"C:\Program Files\SlikSvn\bin\svnlook" log %REPOS% -r %REV% >> %TEMPFILE% 2>>C:\TEMP\err.txt 

date /T >> %LOGFILE% 2>>C:\TEMP\err.txt 
time /T >> %LOGFILE% 2>>C:\TEMP\err.txt 
D:\wamp\bin\php\php5.3.0\php.exe %MANTIS_PATH%\scripts\checkin.php < %TEMPFILE% >> %LOGFILE% 2>>C:\TEMP\err.txt 
  • 正如你可以看到有大量的错误日志记录,但错误日志永远不会被填充(除非我把一个明显的错误,如缺少路径)
  • 无论开发和生活EN vironments是Windows
  • 似乎遇到错误的那一行是最后一行 - PHP被调用。当我拿出这个提交工作没有问题
  • 当我在命令行上手动运行它,它的工作原理并没有显示任何(明显的)错误。据我所知SVN通过足够高privilleges不担心

正如你可能已经做出来的默认用户在系统运行,这是螳螂bug跟踪系统挂接我的SVN签入。有趣的是,正在执行PHP脚本,即将注释添加到错误中并自动关闭问题。它似乎出于某种原因而出错。

我使用TortoiseSVN提交,但使用命令行(SlikSVN)我得到的结果相同:

svn ci -m "this is a test" test.txt 
Sending  test.txt 
Transmitting file data . 
Committed revision 1337. 

Warning: post-commit hook failed (exit code 255) with no output. 

螳螂checkin.php看起来像这样(为便于阅读,删除了一些一般性评论):

#!/usr/bin/php -q 
<?php 

global $g_bypass_headers; 
$g_bypass_headers = 1; 
require_once(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'core.php'); 

# Make sure this script doesn't run via the webserver 
if(php_sapi_name() != 'cli') { 
    echo "checkin.php is not allowed to run through the webserver.\n"; 
    exit(1); 
} 

# Check that the username is set and exists 
$t_username = config_get('source_control_account'); 
if(is_blank($t_username) || (user_get_id_by_name($t_username) === false)) { 
    echo "Invalid source control account ('$t_username').\n"; 
    exit(1); 
} 

if(!defined("STDIN")) { 
    define("STDIN", fopen('php://stdin', 'r')); 
} 

# Detect references to issues + concat all lines to have the comment log. 
$t_commit_regexp = config_get('source_control_regexp'); 
$t_commit_fixed_regexp = config_get('source_control_fixed_regexp'); 

$t_comment = ''; 
$t_issues = array(); 
$t_fixed_issues = array(); 
while(($t_line = fgets(STDIN, 1024))) { 
    $t_comment .= $t_line; 
    if(preg_match_all($t_commit_regexp, $t_line, $t_matches)) { 
     $t_count = count($t_matches[0]); 
     for($i = 0;$i < $t_count;++$i) { 
      $t_issues[] = $t_matches[1][$i]; 
     } 
    } 

    if(preg_match_all($t_commit_fixed_regexp, $t_line, $t_matches)) { 
     $t_count = count($t_matches[0]); 
     for($i = 0;$i < $t_count;++$i) { 
      $t_fixed_issues[] = $t_matches[1][$i]; 
     } 
    } 
} 

# If no issues found, then no work to do. 
if((count($t_issues) == 0) && (count($t_fixed_issues) == 0)) { 
    echo "Comment does not reference any issues.\n"; 
    exit(0); 
} 

# Login as source control user 
if(!auth_attempt_script_login($t_username)) { 
    echo "Unable to login\n"; 
    exit(1); 
} 

# history parameters are reserved for future use. 
$t_history_old_value = ''; 
$t_history_new_value = ''; 

# add note to each bug only once 
$t_issues = array_unique($t_issues); 
$t_fixed_issues = array_unique($t_fixed_issues); 

# Call the custom function to register the checkin on each issue. 

foreach($t_issues as $t_issue_id) { 
    if(!in_array($t_issue_id, $t_fixed_issues)) { 
     helper_call_custom_function('checkin', array($t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, false)); 
    } 
} 

foreach($t_fixed_issues as $t_issue_id) { 
    helper_call_custom_function('checkin', array($t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, true)); 
} 

exit(0); 

回答

1

我通常建议不要使用Subversion挂钩的批处理脚本。有大量免费的,开源的,脚本语言更强大,更易于使用。哎呀,我甚至没有使用BASH作为钩子脚本。

由于钩子脚本只需要在服务器上运行,并且没有其他地方,这一点尤其正确。这意味着你只需要在单一平台上工作。


这就是说,你需要做一些调试。您的挂钩脚本通过svn commit命令行失败。这意味着它不是乌龟相关的问题。这是一个钩子脚本问题。由于这是一个后钩子脚本,尝试在命令行运行脚本本身并传递给它的命令行库和修订:

C> post-commit C:\repos\my_repo 2323 

运作的?

问题是你没有在STDERR上打印任何东西,所以Subversion没有什么可打印的。您正在捕获文件中的STDERR。删除2>>C:\TEMP\err.txt,这样你可以看到错误输出。在Python,BASH和Perl中,我可以捕获STDERR,并将其打印出来,但我不确定如何在批处理脚本中执行此操作。

这将允许您查看错误输出,也许可以帮助您确定脚本失败的位置。它调用你的PHP脚本之前失败了吗?在您的PHP脚本中发生了什么?有没有假设你正在作出哪些不一定有效?

另外,不要只是echo东西在你的PHP钩子。无论钩子成功还是失败,Subversion都不会在STDOUT上打印任何内容。使用fputs(STDERR, 'My Error Message');而不是echoprint。这会将你的错误信息发送到STDERR,如果你的钩子脚本失败,Subversion将把它打印出来。

希望这会有所帮助。

+0

” - 似乎是错误的那一行是最后一行 - 在PHP被调用的时候。当我把它拿出来时,提交没有问题 - 当我在命令行上手动运行它时, t显示任何(明显的)错误。Afaik svn在默认情况下在SYSTEM下运行,足够高以便不必担心“ 以上是我的问题中的重点。是的,我手动尝试,它工作正常。而且,最后一行PHP也是造成这个问题的原因。我把它拿出来,它工作正常,再次把它放回去。 感谢您的其他提示! – LeonardChallis 2011-05-09 15:51:28

0

我也跑过去了。确保您的脚本文件权限设置为可执行。 “

相关问题