mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-11 13:44:17 +00:00
Make optional argument use an immutable set for the default value
in no-commit-to-branch. Make other sets immutable to satisfy type-checking and be consistent
This commit is contained in:
parent
6568414fc5
commit
a7af812449
1 changed files with 6 additions and 6 deletions
|
|
@ -2,16 +2,16 @@ from __future__ import print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
import re
|
||||||
|
from typing import FrozenSet
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
from typing import Set
|
|
||||||
|
|
||||||
from pre_commit_hooks.util import CalledProcessError
|
from pre_commit_hooks.util import CalledProcessError
|
||||||
from pre_commit_hooks.util import cmd_output
|
from pre_commit_hooks.util import cmd_output
|
||||||
|
|
||||||
|
|
||||||
def is_on_branch(protected, patterns=set()):
|
def is_on_branch(protected, patterns=frozenset()):
|
||||||
# type: (Set[str], Set[str]) -> bool
|
# type: (FrozenSet[str], FrozenSet[str]) -> bool
|
||||||
try:
|
try:
|
||||||
ref_name = cmd_output('git', 'symbolic-ref', 'HEAD')
|
ref_name = cmd_output('git', 'symbolic-ref', 'HEAD')
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
|
|
@ -33,13 +33,13 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||||
'-p', '--pattern', action='append',
|
'-p', '--pattern', action='append',
|
||||||
help=(
|
help=(
|
||||||
'regex pattern for branch name to disallow commits to, '
|
'regex pattern for branch name to disallow commits to, '
|
||||||
'May be specified multiple times'
|
'may be specified multiple times'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
protected = set(args.branch or ('master',))
|
protected = frozenset(args.branch or ('master',))
|
||||||
patterns = set(args.pattern or ())
|
patterns = frozenset(args.pattern or ())
|
||||||
return int(is_on_branch(protected, patterns))
|
return int(is_on_branch(protected, patterns))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue