@@ -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
@@ -42,12 +42,7 @@ def __init__(self, config: BaseConfig, arguments: CheckArgs, *args: object) -> N
4242 arguments .get ("allow_abort" , config .settings ["allow_abort" ])
4343 )
4444
45- # Use command line argument if provided, otherwise use config setting
46- cmd_length_limit = arguments .get ("message_length_limit" )
47- if cmd_length_limit is None :
48- self .max_msg_length = config .settings .get ("message_length_limit" , 0 )
49- else :
50- self .max_msg_length = cmd_length_limit
45+ self .max_msg_length = arguments .get ("message_length_limit" , config .settings .get ("message_length_limit" , None ))
5146
5247 # we need to distinguish between None and [], which is a valid value
5348 allowed_prefixes = arguments .get ("allowed_prefixes" )
@@ -90,7 +85,7 @@ def __call__(self) -> None:
9085 invalid_msgs_content = "\n " .join (
9186 f'commit "{ commit .rev } ": "{ commit .message } "'
9287 for commit in commits
93- if not self ._validate_commit_message (commit .message , pattern )
88+ if not self ._validate_commit_message (commit .message , pattern , commit . rev )
9489 )
9590 if invalid_msgs_content :
9691 # TODO: capitalize the first letter of the error message for consistency in v5
@@ -150,21 +145,21 @@ def _filter_comments(msg: str) -> str:
150145 return "\n " .join (lines )
151146
152147 def _validate_commit_message (
153- self , commit_msg : str , pattern : re .Pattern [str ]
148+ self , commit_msg : str , pattern : re .Pattern [str ], commit_hash : str
154149 ) -> bool :
155150 if not commit_msg :
156151 return self .allow_abort
157152
158153 if any (map (commit_msg .startswith , self .allowed_prefixes )):
159154 return True
160155
161- if self .max_msg_length :
156+ if self .max_msg_length is not None :
162157 msg_len = len (commit_msg .partition ("\n " )[0 ].strip ())
163158 if msg_len > self .max_msg_length :
164159 raise CommitMessageLengthExceededError (
165160 f"commit validation: failed!\n "
166161 f"commit message length exceeds the limit.\n "
167- f'commit "": "{ commit_msg } "\n '
162+ f'commit "{ commit_hash } ": "{ commit_msg } "\n '
168163 f"message length limit: { self .max_msg_length } (actual: { msg_len } )"
169164 )
170165
0 commit comments