# HG changeset patch # User Daniel Dourvaris # Date 2019-02-15 17:54:03 # Node ID d42f7af512ebcde1a8fe258abc3936ab4d40a998 # Parent 3f98c6ee2ea5f3e89b9c11e115562694acda0eef hooks: handle delete branch permission case with branch protection diff --git a/vcsserver/hooks.py b/vcsserver/hooks.py --- a/vcsserver/hooks.py +++ b/vcsserver/hooks.py @@ -511,15 +511,14 @@ def git_pre_receive(unused_repo_path, re type_ = push_ref['type'] new_branch = push_ref['old_rev'] == empty_commit_id - if type_ == 'heads' and not new_branch: + delete_branch = push_ref['new_rev'] == empty_commit_id + if type_ == 'heads' and not (new_branch or delete_branch): old_rev = push_ref['old_rev'] new_rev = push_ref['new_rev'] - cmd = [settings.GIT_EXECUTABLE, 'rev-list', - old_rev, '^{}'.format(new_rev)] + cmd = [settings.GIT_EXECUTABLE, 'rev-list', old_rev, '^{}'.format(new_rev)] stdout, stderr = subprocessio.run_command( cmd, env=os.environ.copy()) - # means we're having some non-reachable objects, this forced push - # was used + # means we're having some non-reachable objects, this forced push was used if stdout: push_ref['pruned_sha'] = stdout.splitlines()