如何编写一个svn钩子脚本 [英] how to write a svn hook script
问题描述
我正在尝试为svn编写一个提交后提交钩子脚本,以将存储库导出到Team Foundation Server. (因此,当您提交代码时,该代码的最新版本将被复制到Team Foundation Repo)
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
命令). - 版本库的修订版本.
- The repository path on the server (for the
svnlook
command). - The revision of the repository.
必须通过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屋!