如何锁定 SVN 主干(除了来自分支的合并)?
我想阻止开发人员直接在主干上工作。
我的目标是强制所有开发人员离开主干并在自己的分支上工作,直到 CI 测试通过。然后,他们必须从主干合并到分支(以获取最新更改),运行并通过测试,然后再合并回主干。
这种 SVN 使用方式有什么规则吗?
I'd like to prevent developers working directly on the trunk.
I'm aiming to enforce all developers off the trunk and to work on there own branches until CI tests are cleared. They then have to merge from the trunk to their branch (to pick up latest changes), run and pass tests before they merge back to the trunk.
Is there any rules for this style of SVN usage?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
限制主干提交给机器人。该机器人可以进行无冲突合并并提交到主干。我就是这么做的;它被称为 mergebot (麻省理工学院许可)。它是一个守护进程和一个 Trac 插件,提供了一种按票拥有一个分支的方法。文档很薄弱,在极端情况下也存在问题,但它大多数情况下都可以工作。
Limit trunk commits to a bot. That bot can do the conflict-free merge and commit to trunk. I've done just that; it's called mergebot (MIT licensed). It's a daemon and a Trac plugin to provide a way to have a branch per-ticket. Docs are thin, there are issues in corner cases, but it mostly just works.
要仅允许合并到主干中,您可以使用预提交挂钩来尝试区分合并与普通提交并拒绝后者。您可以通过检查提交是否更改任何路径上的“svn:mergeinfo”属性来判断提交是否是合并。 此邮件列表线程有两个检查钩子的示例合并信息。这些示例实际上试图在特定路径上强制执行其不存在,但是如果您反转逻辑,则可以创建一个仅接受合并的钩子。
开发人员仍然有可能在合并时故意插入其他更改,并且不可能合理地检测到这一点。这样的预提交挂钩将温和地提醒开发人员,他们可能想要签入分支而不是主干,但只有当他们不故意试图绕过策略时,它才有效。
更可靠的解决方案是将对主干的写访问权限限制为您信任的少数用户,他们会做正确的事情。然后,这些用户在每种情况下都必须执行最后的“合并回主干”步骤。如果开发人员已经从主干合并到他们自己的分支,那么最终的合并回来是微不足道的,因此不会对您信任的用户造成很大的负担。事实上,每当开发人员将其分支标记为“准备合并”时,最终的合并甚至可以通过自动化流程来完成。我已经看到过这种自动合并过程的内部实现,但我不知道有任何公开可用的内容。
To allow only merges into the trunk, you could use a pre-commit hook that tries to distinguish merges from ordinary commits and rejects the latter. You can tell whether a commit is a merge by checking if it changes the "svn:mergeinfo" property on any path. This mailing list thread has two examples of hooks that check for mergeinfo. The examples are actually trying to enforce its absence on specific paths, but if you reverse the logic, you can make a hook that accepts only merges.
It would still be possible for a developer to deliberately slip in other changes along with the merge, and it's not reasonably possible to detect that. Such a pre-commit hook will work as a gentle reminder to the developers that they probably meant to check in to a branch and not the trunk, but it only works as long as they're not deliberately trying to sneak around the policy.
A more ironclad solution would be to limit write access to the trunk to a small number of users whom you trust to do the right thing. Those users will then have to do the final "merge back to the trunk" step in every case. If the developers have already merged from the trunk to their own branch, then this final merge back is trivial to do, so would not be a great burden on your trusted users. In fact, the final merge back can even be done by an automated process whenever developers flag their branch as "ready to merge". I've seen in-house implementations of such an automatic merge process, but I don't know of anything publicly available.
你不能那样做。他们要么可以写入目录,要么不能。
但是,您也许可以编写一个预提交挂钩来检测他们是否正在尝试执行此操作,如果是这种情况则中止。
You cannot do that. Either they can write to a directory or they can't.
However, you might be able to write a pre-commit hook that detects if they're trying to do this and abort if that's the case.
让您的开发人员在主干上工作,但“直到他们满意为止”才提交更改,这会简单得多。您的开发人员可以更轻松地使用其他开发人员所做的提交更改来更新他们的代码。
您描述的设置更适合开发人员,他们在合并更改之前必须获得经理或用户的明确授权。您还必须手动管理从一名开发人员到需要这些更改的其他开发人员的分支更改。 (分支到分支合并)。
我拒绝我组中的 Cobol 开发人员访问 SVN 主干。我通过编写自己的 Eclipse 插件来实现这一点,该插件会自动创建分支并执行合并回主干。
It would be a lot simpler to have your developers work on the trunk, but not commit changes "until they are happy". Your developers can more easily update their code with the committed changes made by the other developers.
The setup you describe is more for developers that have to get express authorization from a manager or a user before they merge their changes. You also have to manually manage the branch changes from one developer to the other developers that need those changes for their change. (Branch to branch merging).
I deny access to the Cobol developers in my group access to SVN trunk. I did it by writing my own Eclipse plug-in that automatically creates branches and performs the merge back to trunk.
无论如何,我都不是 SVN 专家,Daniel 的回答是有道理的,所以我可能需要 SVN/WebDAV 专家来告诉我为什么这不起作用:
此页面记录了各种 SVN 命令使用的 WebDAV 方法。看来您可以“锁定”
commit
、rm
、copy
、mv
和mkdir
通过拒绝用户使用MKACTIVITY
方法的权限。这仍然允许diff
、merge
、checkout
、ls
、cat
等 。那么您需要做的就是在 Apache 配置中设置指令。我还没有对此进行测试,但它看起来像这样:
或
指令 与 trunk 目录对应的您应该能够将其嵌套在存储库的主
指令中。这一切都假设您使用 HTTPS 访问您的存储库。I'm not an SVN expert by any means, and Daniel's answer makes sense, so I might need an SVN/WebDAV expert to tell me why this wouldn't work:
This page documents the WebDAV methods used by various SVN commands. And it appears that you could "lock"
commit
,rm
,copy
,mv
, andmkdir
by denying a user permission to use theMKACTIVITY
method. This would still allowdiff
,merge
,checkout
,ls
,cat
, etc.So then all you would need to do is set up, in your Apache config, a
<Limit>
or a<LimitExcept>
directive inside of a<Location>
directive corresponding to the trunk directory. I haven't tested this out, but it would look something like:And you should be able to nest that inside of your repository's main
<Location>
directive. This is all assuming you're using HTTPS to access your repository.您必须设置一个提交钩子来处理这种情况。但我不确定你是否真的可以将对主干的提交与对主干的合并分开(可能基于 svn:mergeinfo 更改)...但我建议向开发人员描述对此的需求,而不是强制它...顺便说一下,提交脚本必须被编写和测试,如果你向开发人员解释这一点,我认为这是不需要的。
You have to setup a commit hook which handles this situation. But I'm not sure if you really can separate a commit to trunk from a merge to the trunk (May be based on svn:mergeinfo change)...but i would recommend to describe the need for that to the developers instead forcing it...and by the way the commit script must be written and tested and that's an effort which i think is not really needed if you explain that to devs.
使用 SVN 权限限制他们对
/trunk
的访问。允许他们读,但不允许写。分配一个可以写入/trunk
的“架构师”角色。当分支准备就绪时,开发人员必须向架构师报告,架构师将手动通过测试,然后合并到/trunk
。Restrict their access to
/trunk
with SVN permissions. Allow them to read, but dis-allow to write. Assign one "architect" role who can write to/trunk
. Developers will have to report to the architect when a branch is ready, the architect will pass tests manually, and then will merge into/trunk
.