@@ -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,12 +44,7 @@ def __init__(self, config: BaseConfig, arguments: CheckArgs, *args: object) -> N
4444 )
4545 self .use_default_range = bool (arguments .get ("use_default_range" ))
4646
47- # Use command line argument if provided, otherwise use config setting
48- cmd_length_limit = arguments .get ("message_length_limit" )
49- if cmd_length_limit is None :
50- self .max_msg_length = config .settings .get ("message_length_limit" , 0 )
51- else :
52- self .max_msg_length = cmd_length_limit
47+ self .max_msg_length = arguments .get ("message_length_limit" , config .settings .get ("message_length_limit" , None ))
5348
5449 # we need to distinguish between None and [], which is a valid value
5550 allowed_prefixes = arguments .get ("allowed_prefixes" )
@@ -95,7 +90,7 @@ def __call__(self) -> None:
9590 invalid_msgs_content = "\n " .join (
9691 f'commit "{ commit .rev } ": "{ commit .message } "'
9792 for commit in commits
98- if not self ._validate_commit_message (commit .message , pattern )
93+ if not self ._validate_commit_message (commit .message , pattern , commit . rev )
9994 )
10095 if invalid_msgs_content :
10196 # TODO: capitalize the first letter of the error message for consistency in v5
@@ -158,21 +153,21 @@ def _filter_comments(msg: str) -> str:
158153 return "\n " .join (lines )
159154
160155 def _validate_commit_message (
161- self , commit_msg : str , pattern : re .Pattern [str ]
156+ self , commit_msg : str , pattern : re .Pattern [str ], commit_hash : str
162157 ) -> bool :
163158 if not commit_msg :
164159 return self .allow_abort
165160
166161 if any (map (commit_msg .startswith , self .allowed_prefixes )):
167162 return True
168163
169- if self .max_msg_length :
164+ if self .max_msg_length is not None :
170165 msg_len = len (commit_msg .partition ("\n " )[0 ].strip ())
171166 if msg_len > self .max_msg_length :
172167 raise CommitMessageLengthExceededError (
173168 f"commit validation: failed!\n "
174169 f"commit message length exceeds the limit.\n "
175- f'commit "": "{ commit_msg } "\n '
170+ f'commit "{ commit_hash } ": "{ commit_msg } "\n '
176171 f"message length limit: { self .max_msg_length } (actual: { msg_len } )"
177172 )
178173
0 commit comments