如何编写 svn 钩子脚本 [英] how to write a svn hook script
问题描述
我正在尝试为 svn 编写提交后挂钩脚本以将存储库导出到团队基础服务器.(因此,当您提交代码时,该代码的最新版本会被复制到团队基础存储库)
I'm trying to write a post commit hook script for svn to export repository to team foundation server. (So when you commit a code, that latest version of the code gets copied to team foundation repo )
我使用的唯一语言是 C++ 和 C,而且我从未编写过脚本.任何人都可以给我一步一步的指导吗?使用哪种语言,阅读什么等等......可能还有一些示例代码??
Only language I use is C++ and C and I have never written a script. Can anybody give me step by step instruction for this? which language to use, what to read etc... along with some example code possibly ??
可以用c++写一个钩子脚本吗?或者我应该学习如何使用 python 或 ruby 等.
Is it possible to write a hook script with c++? or should I learn how to use python or ruby etc..
推荐答案
如果愿意,您可以使用 C 或 C++ 编写钩子.大多数人使用 Perl 或 Python.
You can write your hook using C or C++ if you like. Most people use Perl or Python.
主要的是 svnlook
应该用在你的钩子脚本中,而不是 svn
.svnlook 比 svn
更快更安全.事实上,在预提交脚本中,您必须使用 svnlook
,因为您没有存储库修订版.
The main thing is that svnlook
should be used in your hook script and not svn
. svnlook is faster and safer than svn
. In fact, in pre-commit scripts, you have to use svnlook
since you don't have a repository revision.
以下是有关 post-commit
挂钩的一些注意事项:
Here are some things to keep in mind about your post-commit
hook:
- 您不能更改修订版本,也不要尝试提交更改.你的提交后钩子最终会调用自己.如果您希望您的开发人员遵循某些参数,您需要有一个
pre-commit
钩子,如果开发人员做得不对,它就会失败. - 当 Subversion 调用您的
post-commit
挂钩时,PATH
环境变量已被删除.如果您需要访问其他命令或文件,则必须自己提供完整路径. - Subversion 会从命令行向您传递某些参数.不是实际的命令行,但这意味着您可以在
ARGV
中找到这些参数.将传递给您两个参数:
- You cannot change a revision, and don't try to commit changes. Your post-commit hook will end up calling itself. If you want your developers to follow certain parameters, you need to have a
pre-commit
hook that fails if the developers don't do it right. - When Subversion calls your
post-commit
hook, thePATH
environment variable has been deleted. If you need to access another command or a file, you'll have to provide the full path yourself. - Subversion will pass you certain parameters from the command line. Not an actual command line, but it means you can find these parameters in
ARGV
. Two parameters will be passed to you:
- 服务器上的存储库路径(用于
svnlook
命令). - 存储库的修订版.
您必须通过 svnlook
(您可以通过 system
命令运行它.但是,由于您实际上是用 C 和 C++ 编写的东西,您可能能够使用内置的 Subversion API).
Everything else you must deduce though svnlook
(which you can run via the system
command. However, since you're actually writing things in C and C++, you might be able to use the built in Subversion API).
另一种可能性:使用像 Jenkins 这样的持续构建系统来为您完成繁重的工作.您可能会发现通过 Jenkins 工作更容易,而不必担心提交后挂钩如何完成此任务.Jenkins 的优点之一是,当出现问题时,您不会将失败的提交后消息发送回用户(可能没有错).取而代之的是,您可以获取所发生情况的完整日志,并提醒真正能够解决问题的人员.
Another possibility: Use a continuous build system like Jenkins to do the dirty work for you. You might find it easier to work through Jenkins instead of worrying how a post-commit hook might accomplish this task. One of the advantages of Jenkins is that when things go wrong, you're not sending back failed post-commit messages to the user (who is probably not at fault). Instead, you cat get a complete log of what happened, and alert the person who can actually fix the issue.
这是一个示例用 Perl 写的.不知道对你有没有用.
Here's a sample of one I wrote which is in Perl. Don't know if it'll do you any good.
这篇关于如何编写 svn 钩子脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!