如何配置Mercurial服务器,以便在其关闭后限制对指定分支的提交?我只希望存储库管理员能够重新打开分支。
https://www.mercurial-scm.org/wiki/PruningDeadBranches说关闭的变更集可以通过“变更集的额外字段中的close=1”来标识。不清楚如何使用Mercurial API读取变更集的额外字段。
发布于 2010-10-19 01:24:26
有一个ACL扩展与Mercurial一起发布。您应该能够通过拒绝提交给除管理员之外的所有分支来指定冻结的分支。我不确定命名分支是否可以利用此功能。
配置acls:
[acl.deny.branches]
frozen-branch = *
[acl.allow.branches]
branch_name = admin
发布于 2010-10-19 02:46:18
服务器不能限制提交,但它可以拒绝接受违反约束的推送。这里有一个钩子,你可以把它放在服务器上,以拒绝在关闭的分支上有任何变更集的任何推送:
#!/bin/sh
for thenode in $(hg log -r $HG_NODE:tip --template '{node}\n') ; do
if hg branches --closed | grep -q "^$(hg id --branch -r $thenode).*\(closed\)" ; then
echo Commits to closed branches are not allowed -- bad changeset $thenode
exit 1
fi
done
你可以像这样安装这个钩子:
[hooks]
prechangegroup = /path/to/that.sh
几乎可以肯定的是,有一种方法可以通过您引用的API使用内部python钩子来实现,但shell钩子也能很好地工作。
发布于 2012-09-18 02:12:10
下面是一个进程内钩子,它应该拒绝关闭分支上的其他变更集。
from mercurial import context, ui
def run(ui, repo, node, **kwargs):
ctx = repo[node]
for rev in xrange(ctx.rev(), len(repo)):
ctx = context.changectx(repo, rev)
parent1 = ctx.parents()[0]
if parent1 != None and parent1.extra().get('close'):
ui.warn("Commit to closed branch is forbidden!\n")
return True
return False
该钩子可以使用以下hgrc条目以pretxncommit模式(在本地提交事务期间选中)或pretxnchangegroup模式(在从外部存储库添加变更集时选中)运行:
[hooks]
pretxncommit.forbid_commit_closed_branch = python:/path/to/forbid_commit_closed_branch.py:run
pretxnchangegroup.forbid_commit_closed_branch = python:/path/to/forbid_commit_closed_branch.py:run
不确定此挂钩是否适用于2.2之前的Mercurial版本。
https://stackoverflow.com/questions/3961548
复制相似问题