Skip to content

Commit 9260df5

Browse files
committed
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.
1 parent e437b7e commit 9260df5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pre_commit_hooks/no_commit_to_branch.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@ def main(argv: Sequence[str] | None = None) -> int:
3737
'may be specified multiple times'
3838
),
3939
)
40+
parser.add_argument(
41+
'-m', '--message', default='',
42+
help=(
43+
'What message to display if the the check fails'
44+
),
45+
)
4046
args = parser.parse_args(argv)
4147

4248
protected = frozenset(args.branch or ('master', 'main'))
4349
patterns = frozenset(args.pattern or ())
44-
return int(is_on_branch(protected, patterns))
50+
result = int(is_on_branch(protected, patterns))
51+
if result:
52+
print(args.message)
53+
return result
4554

4655

4756
if __name__ == '__main__':

0 commit comments

Comments
 (0)