使用 Trac 和 SVN 进行提交后挂钩
所以我在设置时遇到了一些问题。 让我解释。
我的 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()
我在不知道到底出了什么问题? 任何人都可以提供任何帮助吗?
So I am having a few problems with settings this up. Let me explain.
I have three files in my d:\svn\hooks file (D:\ is not windows drive)
post-commit.bat
trac-post-commit-hook.cmd
trac-post-commit-hook
I have setup the post-commit.bat file in d:\svn\hooks file with the following
%~dp0\trac-post-commit-hook.cmd %1 %2
In my trac-post-commit-hook.cmd - I have
@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%"
In my trac-post-commit-hook file - its just the standard script from http://trac.edgewall.org/browser/trunk/contrib/trac-post-commit-hook?rev=920
== Problems ==
When I run post-commit.bat in cmd prompt - it works fine - no errors are generated.
However, when I commit something in the SVN for a test ticket I created in Trac - #1 fixed. - nothing changes on Trac. Nothing updates at all.
When I change the 'trac-post-commit-hook' to 'trac-post-commit-hook.py' and run from d:\svn\hooks\python trac-post-commit-hook.py I get
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()
I am at a loss as to what is actually going wrong ? Can anyone provide any assistance ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想检查此答案,看看它是否可以帮助您解决问题:
如果这没有帮助,您应该尝试记录到文件。 由于使用 SVN 时它工作正常,但使用 Trac 时失败,这可能是一些配置错误。 一旦您能够实际查看错误消息,修复就会更容易。 更改为:
对于初学者,请尝试在 cmd 文件中 这应该将 stdout 和 stderr 消息发送到 \temp\trachook.log 文件。
编辑:抱歉,错过了您已经发布的错误消息。 看起来它没有获得正确的
options.project
,当它应该从-p
选项的TRAC_ENV
设置时,它可能被设置为 None 。将其重命名为 .py 并运行后,您确定正在使用该选项运行它吗? 如果是这样,请尝试更改该文件并在解析参数后记录
options.project
的值。 尝试找出未设置的原因。编辑:顺便说一下,错误行:
我在提交后挂钩的链接中没有看到对此的引用。 你添加这个了吗? 或者链接有误? 另外,该行中存在语法错误:大括号“{”应该是方括号“[”。 但我认为错误实际上发生在 os.path.join 中(options.project 为 None)。 尝试在该行之前添加一行:
并查看输出是什么。
You might want to check this answer to see if it helps you solve your problem:
If that doesn't help, you should try logging to a file. Since it works fine when you use SVN, but fails for Trac, it's probably some config error. Once you can actually view the error message, it will be easier to fix. For starters try changing to:
in your cmd file. This should send both stdout and stderr messages to the \temp\trachook.log file.
EDIT: Sorry, missed the error message you posted already. Looks like it's not getting the right
options.project
and it might be set to None when it should be set fromTRAC_ENV
from the-p
option.Are you sure you're running it with that option after you rename it to .py and run it? If so, try changing that file and logging the value of
options.project
after the arguments have been parsed. Try to track down why it's not being set.EDIT: By the way, the error line:
I don't see a reference to this in the link to the post-commit-hook. Did you add this? Or is the link wrong? Also, there's a syntax error in that line: the curly brace '{' should be a square brace '['. But I think the error actually happens before that, in the os.path.join (options.project is None). Try putting a line before that one:
and see what the output is.
钩子脚本需要传递参数。 要手动测试,您可以运行:
trac-post-commit-hook -p /path/to/environment -r 1001
将 1001 替换为包含命令的修订版本以及 trac 环境的路径。 当您位于 hooks 目录时运行它。
祝你好运!
the hook script requires the parameters to be passed. To test by hand, you can run:
trac-post-commit-hook -p /path/to/environment -r 1001
replace 1001 with a revision that contains a command, and the path with your trac environment. Run it while you are in the hooks directory.
Good luck!