我尝试手动添加规则,但是这很耗时,因为有很多人加入团队。
更新:
答案 0 :(得分:0)
组织所有者和对组织拥有的存储库具有管理员权限的人可以强制执行分支机构限制,以便只有某些用户或团队才能推送到受保护的分支机构。
有关更多信息,请在see这里
答案 1 :(得分:0)
我不会评论这是否是一个好主意。 足以说我曾经让我创建以下 update 钩子以应用于规范的仓库(,但是请注意,Github不允许自定义更新钩子,你在那里不走运):
#!/usr/bin/env python
import os
import re
import sys
from pathlib import Path
from subprocess import check_output
branch = sys.argv[1]
old_commit = sys.argv[2]
new_commit = sys.argv[3]
zero = "0000000000000000000000000000000000000000"
branch_pattern = 'feature/.+'
def get_author(commit):
return str(check_output(['git', '--no-pager', 'show', '-s', "--format='%an'", commit]).strip(), 'utf-8')
def allow(message=None):
if message:
print(message)
exit(0)
def deny(message=None):
if message:
print(message)
exit(1)
# if this isn't a feature branch bail
if not re.match(branch_pattern, branch):
allow()
# if the update is a delete bail
if new_commit == zero:
allow("update: deleting branch '%s': OK" % branch)
# if this is the first commit on the branch bail
if old_commit == zero:
allow("update: creating branch '%s': OK" % branch)
branch_log = Path('.git', 'logs', 'refs', 'heads').joinpath(*branch.split(os.path.sep))
with open(branch_log, 'r') as log:
first_commit = log.readline(81).split(sep=' ', maxsplit=1)[1]
branch_author = get_author(first_commit)
new_commit_author = get_author(new_commit)
print("update: branch = '%s'; branch author = %s; commit author = %s" % (branch, branch_author, new_commit_author))
if new_commit_author == branch_author:
allow("update: commit author == branch author: OK")
else:
deny(
"update: branch author != commit author: REJECTED\n"
"update: create a branch for your changes from the tip of %s and request a pull instead"
% branch
)