1

特定のユーザーが変更セットをリポジトリのデフォルト ブランチにプッシュできないように制限したいと考えています。可能であれば、どのようにしますか?

4

2 に答える 2

4

ACL 拡張機能が機能するはずです。ただし、次の考慮事項を考慮する必要があります。

  • 拡張機能は、サーバー リポジトリで有効にする必要があります。つまり、hgrc提供される各リポジトリのファイルには、ACL 設定が定義されている必要があります。

    [extensions]
    acl =
    
    [hooks]
    pretxnchangegroup.acl = python:hgext.acl.hook
    
    [acl]
    sources = serve
    
    [acl.deny.branches]
    default = user1, user2, user3
    
  • プッシュが拒否されたこれらのユーザーは、システムユーザーです。つまり、ユーザー名は、あなたの場合、Web サーバーによって提供される資格情報から取得されます。コミット メタデータのフィールドとは関係ありません。Author:

  • 完全なchagegroupのみを許可または拒否できます。拒否されたユーザーの 1 人が、単一のコミットを含むコミットのグループをデフォルト ブランチにプッシュすると、プッシュ全体が拒否されます (他のコミットが許可されていても)。ユーザーがデフォルト ブランチと頻繁にマージする傾向がある場合、これはそれほど奇妙ではありません。

独自のpretxnchangegroupフックを作成することもできますが、ACL 拡張機能よりも優れた機能はありません。

于 2012-04-13T09:17:58.487 に答える
0

現在の回答は、プッシュした瞬間にチェックされます(チェックは、acl コードから作成したサーバー側です)。必要なのは、ローカル リポジトリへのコミットのチェックです。そのためには、「pretxncommit」フックを作成する必要があります (さまざまなイベントに作用する複数の種類のフックがあることに注意してください)。

以下をせよ:

A success Git branching modelによると、master に直接コミットする必要はなく、マージのみを行う必要があります。これを強制するために、mercurial にコールバック フックを追加して、コミットをチェックし、それらが直接マスターにある場合は許可しないようにすることができます。これを行うには、プロジェクトの .hg/hgrc に次のコード行を追加します。

[hooks]
pretxncommit.nocommittomasterhook = python:%USERPROFILE%\hgnocommittomaster.py:nocommittomaster

Windows のホーム ディレクトリにhgnocommittomaster.py、コンテンツを含むファイル ' ' を作成します (元の例):

from mercurial.node import bin, nullid
from mercurial import util

# Documentation is here: https://www.mercurial-scm.org/wiki/MercurialApi
# Script based on: https://www.mercurial-scm.org/wiki/HookExamples

def nocommittomaster(ui, repo, node, **kwargs):
    n = bin(node)
    start = repo.changelog.rev(n)
    end = len(repo.changelog)
    failed = False
    for rev in xrange(start, end):
        n = repo.changelog.node(rev)
        ctx = repo[n]
        p = ctx.parents()
        if ctx.branch()  == 'master' and len(p) == 1:
            if p[0].branch() != 'master':
                # commit that creates the branch, allowed
                continue
            if len(ctx.files()) == 0 and len(ctx.tags()) == 1:  # will not hit?, '.hgtags' always changed?
                continue    # Only a tag is added; allowed.
            elif len(ctx.files()) == 1 and len(ctx.tags()) == 1:
                if ctx.files()[0] == '.hgtags':
                    continue    # Only a tag is added; allowed.
            ui.warn(' - changeset rev=%d (%s) on stable branch and is not a merge !\n' % (rev,ctx))
            failed = True
    if failed:
        ui.warn('* Please strip the offending changeset(s)\n'
                '* and re-do them, if needed, on another branch!\n')
        return True

この投稿は、 Mercurial pre commit hookおよびMercurial Pre-Commit Hook: How to hook to python program in current directory?に触発されました。

于 2018-11-08T15:35:16.180 に答える