mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-31 18:46:53 +00:00
Allow display of custom message when no-commit-to-branch fails
This change should make the failures of no-commit-to-branch easier for people that might encounter it as maintainers can provide information about allowed branch names. Current behavior just gives an opaque error that is not very useful for people that do not have a lot of knowledge about the project they are contributing to.
This commit is contained in:
parent
e437b7ed51
commit
c03c3986cd
2 changed files with 11 additions and 1 deletions
|
|
@ -37,11 +37,20 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|||
'may be specified multiple times'
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
'-m', '--message', default='',
|
||||
help=(
|
||||
'What message to display if the the check fails'
|
||||
),
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
protected = frozenset(args.branch or ('master', 'main'))
|
||||
patterns = frozenset(args.pattern or ())
|
||||
return int(is_on_branch(protected, patterns))
|
||||
result = int(is_on_branch(protected, patterns))
|
||||
if result:
|
||||
print(args.message)
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue