@@ -64,31 +64,35 @@ def _read_backup_message(self) -> str | None:
6464
6565 def _prompt_commit_questions (self ) -> str :
6666 # Prompt user for the commit message
67- cz = self .cz
68- questions = cz .questions ()
67+ questions = self .cz .questions ()
6968 for question in (q for q in questions if q ["type" ] == "list" ):
7069 question ["use_shortcuts" ] = self .config .settings ["use_shortcuts" ]
7170 try :
72- answers = questionary .prompt (questions , style = cz .style )
71+ answers = questionary .prompt (questions , style = self . cz .style )
7372 except ValueError as err :
7473 root_err = err .__context__
7574 if isinstance (root_err , CzException ):
76- raise CustomError (root_err . __str__ ( ))
75+ raise CustomError (str ( root_err ))
7776 raise err
7877
7978 if not answers :
8079 raise NoAnswersError ()
8180
82- message = cz .message (answers )
83- message_len = len (message .partition ("\n " )[0 ].strip ())
84- message_length_limit = self .arguments .get ("message_length_limit" , 0 )
85- if 0 < message_length_limit < message_len :
81+ message = self .cz .message (answers )
82+ self ._validate_subject_length (message )
83+ return message
84+ 85+ def _validate_subject_length (self , message : str ) -> None :
86+ # By the contract, message_length_limit is set to 0 for no limit
87+ subject = message .partition ("\n " )[0 ].strip ()
88+ limit = self .arguments .get ("message_length_limit" , 0 )
89+ if limit == 0 :
90+ return
91+ if len (subject ) > limit :
8692 raise CommitMessageLengthExceededError (
87- f"Length of commit message exceeds limit ({ message_len } /{ message_length_limit } ) "
93+ f"Length of commit message exceeds limit ({ len ( subject ) } /{ limit } ), subject: ' { subject } ' "
8894 )
8995
90- return message
91- 9296 def manual_edit (self , message : str ) -> str :
9397 editor = git .get_core_editor ()
9498 if editor is None :
0 commit comments