From b5eead3e37cc63fc12f4d46d20159a960b48892e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 08 2018 09:17:10 +0000 Subject: Add a way to block non fast-forwardable commits on all branches Fixes https://pagure.io/pagure/issue/1988 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/hooks/files/pagure_force_commit_hook.py b/pagure/hooks/files/pagure_force_commit_hook.py index 5b1b18c..7aef071 100755 --- a/pagure/hooks/files/pagure_force_commit_hook.py +++ b/pagure/hooks/files/pagure_force_commit_hook.py @@ -46,16 +46,11 @@ def run_as_pre_receive_hook(): plugin = pagure.lib.plugins.get_plugin('Block non fast-forward pushes') plugin.db_object() # Get the list of branches - branches = [ + branches = [] + if repo.pagure_force_commit_hook: branch.strip() for branch in repo.pagure_force_commit_hook.branches.split(',') - if repo.pagure_force_commit_hook] - - # Remove empty branches - branches = [ - branch.strip() - for branch in branches - if branch] + if branch.strip()] for line in sys.stdin: if _config.get('HOOK_DEBUG', False): @@ -63,7 +58,7 @@ def run_as_pre_receive_hook(): (oldrev, newrev, refname) = line.strip().split(' ', 2) refname = refname.replace('refs/heads/', '') - if refname in branches: + if refname in branches or branches == ['*']: if _config.get('HOOK_DEBUG', False): print(' -- Old rev') print(oldrev) diff --git a/pagure/hooks/pagure_force_commit.py b/pagure/hooks/pagure_force_commit.py index 5ec8fe1..d389405 100644 --- a/pagure/hooks/pagure_force_commit.py +++ b/pagure/hooks/pagure_force_commit.py @@ -70,7 +70,9 @@ class PagureForceCommitHook(BaseHook): name = 'Block non fast-forward pushes' description = 'Using this hook you can block any non-fast-forward '\ - 'commit forced pushed to one or more branches' + 'commit forced pushed to one or more branches.\n'\ + 'You can specify one or more branch names (sperated them using '\ + 'commas) or block all the branches by specifying: ``*``' form = PagureForceCommitForm db_object = PagureForceCommitTable backref = 'pagure_force_commit_hook'