2

所以我在设置这个时遇到了一些问题。让我解释。

我的 d:\svn\hooks 文件中有三个文件(D:\ 不是 Windows 驱动器)

post-commit.bat
trac-post-commit-hook.cmd
trac-post-commit-hook

我已经在 d:\svn\hooks 文件中设置了 post-commit.bat 文件,其中包含以下内容

%~dp0\trac-post-commit-hook.cmd %1 %2

在我的 trac-post-commit-hook.cmd - 我有

@ECHO OFF
::
:: Trac post-commit-hook script for Windows
::
:: Contributed by markus, modified by cboos.

:: Usage:
::
:: 1) Insert the following line in your post-commit.bat script
::
:: call %~dp0\trac-post-commit-hook.cmd %1 %2
::
:: 2) Check the 'Modify paths' section below, be sure to set at least TRAC_ENV

:: ----------------------------------------------------------
:: Modify paths here:

:: -- this one *must* be set
SET TRAC_ENV=D:\trac\project

:: -- set if Python is not in the system path
SET PYTHON_PATH=D:\trac\Python25

:: -- set to the folder containing trac/ if installed in a non-standard location
SET TRAC_PATH=D:\trac\Python25\Lib\site-packages\trac
:: ----------------------------------------------------------

:: Do not execute hook if trac environment does not exist
IF NOT EXIST %TRAC_ENV% GOTO :EOF

set PATH=%PYTHON_PATH%;%PATH%
set PYTHONPATH=%TRAC_PATH%;%PYTHONPATH%

SET REV=%2

Python "%~dp0\trac-post-commit-hook" -p "%TRAC_ENV%" -r "%REV%" 

在我的 trac-post-commit-hook 文件中 - 它只是来自http://trac.edgewall.org/browser/trunk/contrib/trac-post-commit-hook?rev=920的标准脚本

== 问题 ==

当我在 cmd 提示符下运行 post-commit.bat 时 - 它工作正常 - 不会产生错误。

但是,当我在 SVN 中为我在 Trac 中创建的测试票提交某些内容时 - #1 已修复。- Trac 上没有任何变化。根本没有更新。

当我将 'trac-post-commit-hook' 更改为 'trac-post-commit-hook.py' 并从 d:\svn\hooks\python trac-post-commit-hook.py 运行时,我得到

File "trac-post-commit-hook.py", line 104, in <module>
os.environ{'PYTHON_EGG_CACHE'] = os.path.join(options.project, '.egg-cache')

File "D:\trac\Python25\lib\ntpath.py", line 90, in join
assert len(path) > 0
TypeError: object of type 'NoneType' has no len()

我不知道到底出了什么问题?任何人都可以提供任何帮助吗?

4

2 回答 2

2

您可能需要检查此答案以查看它是否可以帮助您解决问题:

如果这没有帮助,您应该尝试登录到文件。因为当你使用 SVN 时它工作正常,但在 Trac 中失败,这可能是一些配置错误。一旦您可以实际查看错误消息,将更容易修复。对于初学者尝试更改为:

Python "%~dp0\trac-post-commit-hook" -p "%TRAC_ENV%" -r "%REV%" 2>&1 1>>c:\temp\trachook.log

在你的 cmd 文件中。这应该将 stdout 和 stderr 消息发送到 \temp\trachook.log 文件。

编辑:对不起,错过了您已经发布的错误消息。看起来它没有正确options.project,当它应该TRAC_ENV-p选项中设置时,它可能被设置为 None 。

您确定在将其重命名为 .py 并运行它之后使用该选项运行它吗?如果是这样,请尝试更改该文件并记录options.project解析参数后的值。尝试追查为什么它没有被设置。

编辑:顺便说一句,错误行:

File "trac-post-commit-hook.py", line 104, in <module>
os.environ{'PYTHON_EGG_CACHE'] = os.path.join(options.project, '.egg-cache')

我在 post-commit-hook 的链接中没有看到对此的引用。你加了这个吗?还是链接有误?此外,该行中存在语法错误:大括号“{”应该是方括号“[”。但我认为错误实际上发生在此之前,在 os.path.join 中(options.project 为 None)。尝试在该行之前放置一行:

print 'options.project is set to: ', options.project

看看输出是什么。

于 2009-07-11T05:47:00.383 回答
0

钩子脚本需要传递参数。要手动测试,您可以运行:

trac-post-commit-hook -p /path/to/environment -r 1001

将 1001 替换为包含命令的修订版,并将路径替换为您的 trac 环境。在 hooks 目录中运行它。

祝你好运!

于 2009-07-23T14:32:20.223 回答