为了避免团队成员通过直接向特定分支推送代码而破坏或冲突重叠,可以通过使用Bitbucket钩子以及仅将访问权限授予少数特定团队成员来删除此问题。
具体来说,可以使用“pre-receive”钩子来检查提交并仅允许被授权的用户将其推送到特定分支。将以下代码添加到此分支的仓库中,即可实现此目的:
#!/usr/bin/env python import sys import re
DENY_BRANCH = "master" ALLOWED_USER = "alice"
def main(): # Get the data from the incoming push refs = sys.stdin.readlines()
for ref in refs:
# Grab the user and branch from the incoming push
oldrev, newrev, refname = ref.strip().split(" ")
# Check if the branch being pushed to is the "DENY_BRANCH"
if refname.endswith(DENY_BRANCH):
# If the pusher isn't the allowed user, deny the push
if not re.search(ALLOWED_USER, sys.argv[2]):
print "User '%s' is not allowed to push to branch '%s'" % (sys.argv[2], DENY_BRANCH)
sys.exit(1)
if name == "main": main()
此代码将检查提交,如果提交不是由“alice”推送到“master”分支,则拒绝推送,并使用户看到一条相应的错误消息。用户也可以将代码更改为适合他们自己的策略。