mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 11:16:53 +00:00
Add wildcard matching to no-commit-to-branch hook so that commits can
be blocked on, for example, all release branches with 'release/*'
This commit is contained in:
parent
aa9c202b9b
commit
d6847c4827
3 changed files with 19 additions and 4 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import fnmatch
|
||||
from typing import Optional
|
||||
from typing import Sequence
|
||||
from typing import Set
|
||||
|
|
@ -11,11 +12,12 @@ from pre_commit_hooks.util import cmd_output
|
|||
|
||||
def is_on_branch(protected): # type: (Set[str]) -> bool
|
||||
try:
|
||||
branch = cmd_output('git', 'symbolic-ref', 'HEAD')
|
||||
ref_name = cmd_output('git', 'symbolic-ref', 'HEAD')
|
||||
except CalledProcessError:
|
||||
return False
|
||||
chunks = branch.strip().split('/')
|
||||
return '/'.join(chunks[2:]) in protected
|
||||
chunks = ref_name.strip().split('/')
|
||||
branch_name = '/'.join(chunks[2:])
|
||||
return any(fnmatch.fnmatch(branch_name, s) for s in protected)
|
||||
|
||||
|
||||
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue