@@ -19,7 +19,7 @@ class CheckArgs(TypedDict, total=False):
1919 commit_msg : str
2020 rev_range : str
2121 allow_abort : bool
22- message_length_limit : int
22+ message_length_limit : int | None
2323 allowed_prefixes : list [str ]
2424 message : str
2525 use_default_range : bool
@@ -44,13 +44,7 @@ def __init__(self, config: BaseConfig, arguments: CheckArgs, *args: object) -> N
4444 )
4545
4646 self .use_default_range = bool (arguments .get ("use_default_range" ))
47-
48- # Use command line argument if provided, otherwise use config setting
49- cmd_length_limit = arguments .get ("message_length_limit" )
50- if cmd_length_limit is None :
51- self .max_msg_length = config .settings .get ("message_length_limit" , 0 )
52- else :
53- self .max_msg_length = cmd_length_limit
47+ self .max_msg_length = arguments .get ("message_length_limit" , config .settings .get ("message_length_limit" , None ))
5448
5549
5650 # we need to distinguish between None and [], which is a valid value
@@ -97,7 +91,7 @@ def __call__(self) -> None:
9791 invalid_msgs_content = "\n " .join (
9892 f'commit "{ commit .rev } ": "{ commit .message } "'
9993 for commit in commits
100- if not self ._validate_commit_message (commit .message , pattern )
94+ if not self ._validate_commit_message (commit .message , pattern , commit . rev )
10195 )
10296 if invalid_msgs_content :
10397 # TODO: capitalize the first letter of the error message for consistency in v5
@@ -160,21 +154,21 @@ def _filter_comments(msg: str) -> str:
160154 return "\n " .join (lines )
161155
162156 def _validate_commit_message (
163- self , commit_msg : str , pattern : re .Pattern [str ]
157+ self , commit_msg : str , pattern : re .Pattern [str ], commit_hash : str
164158 ) -> bool :
165159 if not commit_msg :
166160 return self .allow_abort
167161
168162 if any (map (commit_msg .startswith , self .allowed_prefixes )):
169163 return True
170164
171- if self .max_msg_length :
165+ if self .max_msg_length is not None :
172166 msg_len = len (commit_msg .partition ("\n " )[0 ].strip ())
173167 if msg_len > self .max_msg_length :
174168 raise CommitMessageLengthExceededError (
175169 f"commit validation: failed!\n "
176170 f"commit message length exceeds the limit.\n "
177- f'commit "": "{ commit_msg } "\n '
171+ f'commit "{ commit_hash } ": "{ commit_msg } "\n '
178172 f"message length limit: { self .max_msg_length } (actual: { msg_len } )"
179173 )
180174
0 commit comments