如何拥有一个仅在提交到 TRUNK 时才调用的提交后挂钩?
我有一个包含以下目录的存储库:
- 分支
- 标签
- trunk
主干目录包含开发的主线。我为存储库创建了一个提交后挂钩脚本,当用户提交回存储库时,该脚本会更新(主干的)工作副本。
它看起来像这样:
/usr/bin/svn update /path/to/a/working/copy
我刚刚创建了代码的一个分支,因为我即将开始一些重大更改,但注意到当我将更改提交到分支时,它会调用提交后挂钩并更新工作副本(复制的树干)。
有没有办法可以修改我的提交后挂钩脚本或我可以进行的设置,只有在提交到 trunk 目录而不是任何其他目录时才会更新工作副本?
I have a repository that has the following directories:
- branches
- tags
- trunk
The trunk directory contains the main line of development. I have created a post-commit hook script for the repository that updates a working copy (of trunk) when a user commits back to repository.
It looks something like this:
/usr/bin/svn update /path/to/a/working/copy
I've just created a branch of the code as I'm about to start some major changes but noticed that when I commit my changes to branch it calls the post-commit hook and updates the working copy (copy of trunk).
Is there a way I can modify either my post-commit hook script or a setting that I can make that would only update the working copy if the commit was made to the trunk directory and not any other directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您在此文档中看到的,参数被传递给帖子-提交脚本。
提交后挂钩可以是任何类型的任何程序:bash 脚本、C 程序、python 脚本...发生的情况是 shell 使用两个参数启动该程序。
您可以在此处找到有趣的脚本列表。一个好的开始是这个python 脚本,它使用 python svn 库。
请注意,提供的路径与您要签入的文件的路径不同(请参阅保罗的回答)。但是,将此信息与 revnum 一起使用应该可以帮助您获取更改列表,从中您可以确定是否已在主干上完成操作。
As you can see in this documentation, parameters are passed to the post-commit script.
The post-commit hook could be any program of any type : a bash script, a C program, a python script...What happens is that the shell launches this program, with the two parameters.
You can find a list of interesting scripts here. A good beginning would be this python script, which uses the python svn libs.
Please note that the path provided is not the same as the path to the file that you are checking in (see Paul's answer). But using this information with the revnum should help you to get the list of the changes, from which you can determine if operations have been done on trunk or not.
除了 来自 Bishiboosh 的回答,值得注意的是,钩子可以是任何程序。也就是说,如果您愿意,您可以用 C 语言编写程序。传递的参数在中进行了描述文档。
要获得良好的脚本存储库以获取灵感,请查看颠覆工具页面。一般来说,如果您想根据事务的内容进行一些条件处理,并且您确实这样做了,因为您只想处理文件是否在主干中,那么使用 Python 将是最简单的,因为它附带了一堆检查交易的工具。 此脚本是开始寻找灵感的好地方。
请注意,参数的路径与您要签入的文件的路径不同。毕竟您可以在签入中拥有多个文件......您传递的是存储库的位置和修订版本的变化。使用这两条信息,您可以从存储库获取有关更改的信息,并使用该信息来决定是否在提交后挂钩中执行操作。
这是 另一个示例 (在 Perl 中)显式检查签入中文件的路径。这是一个复杂得多的脚本,但很可能重要的部分可以被撕掉并重新使用。
In addition to the answer from Bishiboosh, it is worth noting that the hooks can be any program. That is, if you wanted to, you could write the program in
C
. The parameters that are passed are described in the doc.For a good repository of scripts to get inspiration from, have a look at the subversion tools page. In general, if you want to do some conditional processing based on the contents of the transaction, and you do, since you only want to process if the files are in trunk, then it will be easiest to use Python, since that comes with a bunch of tools to examine the transactions. This script is a good place to start looking for inspiration.
Note, that the path to the parameter, is not the same as the path to the file that you are checking in. You could have multiple files in the checkin after all… What you are passed is the location of the repository, and the revision of the change. Using these two pieces of information you can get the information about the change from the repository, and use that information to decide whether to perform an action or not in the post-commit hook.
Here is another example (in Perl) That explicitly checks the path of the files in the checkin. This is a much more complicated script, but most likely the salient parts can be ripped out and re-used.