mercurial - Bitbucket: Enforce merge-only by pull request on branch workflow -
our team uses bitbucket hosting our mercurial repository. have single repo cloned our dev vm's upon provisioning them. use typical feature branch -> pull request -> review -> merge feature default
pr workflow.
what we'd like: able restrict things such 1 cannot push default
branch command-line (to avoid accidental commits branch). ie - want enforce way default
modified via pull request.
note forking isn't option due vm setup (we'd have add complexity vm provisioning fork, , set on provisioned vm, , means when accidentally pushes default
they're messing fork).
branch restrictions seem promising, , while can set nobody can push via command line, means single named user or group can actual merge of pr (which don't want, ideally on team can merge, through bitbucket pr).
is possible? suggestions?
so ended solving mercurial hooks. created following file, named prevent_default_push.py
, put in .hg
directory of clone.
# branches prevent being pushed command line. # separate branches spaces restricted_branches = "default".lower().split() def branch_name(repo): return repo[none].branch().lower() def is_restricted(branch): return branch in restricted_branches def prevent_default(ui, repo, *args, **kwargs): if is_restricted(branch_name(repo)): print("preventing push default branch") return true return false def prevent_commit(ui, repo, *args, **kwargs): branch = branch_name(repo) if is_restricted(branch): print("you're on restricted branch (%s), sure want commit? [yn]" % branch) res = raw_input().strip().lower() return res != "y" return false
and edited .hg/hgrc
file use these hooks:
[hooks] pre-push = python:.hg/prevent_default_push.py:prevent_default pre-commit = python:.hg/prevent_default_push.py:prevent_commit
then when trying commit while on default
branch, confirmation prompt, , if try doing push default
it's straight rejected.
example run:
$ hg commit you're on restricted branch (default), sure want commit? [yn] n abort: pre-commit hook failed
where "n" typed.
the plus side of while stuff in .hg
directory isn't under version control (so clone won't it), can incorporate our provisioning mechansims automation of putting these hooks in place on provisioned vm.
Comments
Post a Comment