防止推送添加到关闭分支的提交

发布于 2024-09-28 03:55:03 字数 378 浏览 5 评论 0原文

如何配置 Mercurial 服务器以在指定分支关闭后限制提交?我只希望存储库管理员能够重新打开分支。

https://www.mercurial-scm.org/wiki/PruningDeadBranches 表示已关闭变更集可以通过“变更集的额外字段中的 close=1”来标识。目前尚不清楚如何使用 Mercurial API 读取变更集的额外字段。

How can I configure a Mercurial server to restrict commits to a named branch once it has been closed? I only want the repository administrator to have the ability to reopen the branch.

https://www.mercurial-scm.org/wiki/PruningDeadBranches says that closed changesets can be identified by "close=1 in the changeset's extra field". It's not clear how to read a changeset's extra field using the Mercurial API.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你爱我像她 2024-10-05 03:55:03

有一个 ACL 扩展与 Mercurial 一起分发。
您应该能够通过拒绝提交除管理员之外的每个分支来指定冻结分支。我不确定指定分支机构是否可以利用此设施。

配置 acl:

[acl.deny.branches] 
frozen-branch = *

[acl.allow.branches]
branch_name = admin

There is an ACL extension that is distributed along with Mercurial.
You should be able to specify the frozen branches by denying commit to every one except the administrator. I am not sure if named branches can leverage this facility.

Configuring acls:

[acl.deny.branches] 
frozen-branch = *

[acl.allow.branches]
branch_name = admin
朱染 2024-10-05 03:55:03

服务器无法限制提交,但它可以拒绝接受违反约束的推送。您可以在服务器上放置一个钩子,以拒绝任何在关闭分支上有任何变更集的推送:

#!/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 hooks 也效果很好。

A server can't restrict commits, but it can refuse to accept pushes that violate constraints. Here's a hook you can put on a server to reject any pushes that have any changesets that are on a closed branch:

#!/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

You'd install that hook like this:

[hooks]
prechangegroup = /path/to/that.sh

There's almost certainly a way to do it using in-python hooks with the API you referenced, but shell hooks work out pretty well too.

狠疯拽 2024-10-05 03:55:03

这是一个进程内挂钩,它应该拒绝关闭分支上的其他变更集。

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

该钩子可以在 pretxncommit 模式(在本地提交事务期间检查)或 pretxnchangegroup 模式(在从外部存储库添加变更集时检查)运行,并具有以下 hgrc 条目:

[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 版本。

Here's an in-process hook that should reject additional changesets on a closed branch.

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

The hook can run in pretxncommit mode (checked during a local commit transaction) or pretxnchangegroup mode (checked when changesets added from external repo) with the following hgrc entries:

[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

Not sure if this hook will work with Mercurial versions prior to 2.2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文