@@ -63,33 +63,37 @@ def _read_backup_message(self) -> str | None:
6363 ) as f :
6464 return f .read ().strip ()
6565
66- def _prompt_commit_questions (self ) -> str :
66+ def _get_message_by_prompt_commit_questions (self ) -> str :
6767 # Prompt user for the commit message
68- cz = self .cz
69- questions = cz .questions ()
68+ questions = self .cz .questions ()
7069 for question in (q for q in questions if q ["type" ] == "list" ):
7170 question ["use_shortcuts" ] = self .config .settings ["use_shortcuts" ]
7271 try :
73- answers = questionary .prompt (questions , style = cz .style )
72+ answers = questionary .prompt (questions , style = self . cz .style )
7473 except ValueError as err :
7574 root_err = err .__context__
7675 if isinstance (root_err , CzException ):
77- raise CustomError (root_err . __str__ ( ))
76+ raise CustomError (str ( root_err ))
7877 raise err
7978
8079 if not answers :
8180 raise NoAnswersError ()
8281
83- message = cz .message (answers )
84- message_len = len (message .partition ("\n " )[0 ].strip ())
85- message_length_limit = self .arguments .get ("message_length_limit" , 0 )
86- if 0 < message_length_limit < message_len :
82+ message = self .cz .message (answers )
83+ self ._validate_subject_length (message )
84+ return message
85+
86+ def _validate_subject_length (self , message : str ) -> None :
87+ # By the contract, message_length_limit is set to 0 for no limit
88+ subject = message .partition ("\n " )[0 ].strip ()
89+ limit = self .arguments .get ("message_length_limit" , 0 )
90+ if limit == 0 :
91+ return
92+ if len (subject ) > limit :
8793 raise CommitMessageLengthExceededError (
88- f"Length of commit message exceeds limit ({ message_len } /{ message_length_limit } ) "
94+ f"Length of commit message exceeds limit ({ len ( subject ) } /{ limit } ), subject: ' { subject } ' "
8995 )
9096
91- return message
92-
9397 def manual_edit (self , message : str ) -> str :
9498 editor = git .get_core_editor ()
9599 if editor is None :
@@ -114,11 +118,13 @@ def _get_message(self) -> str:
114118 raise NoCommitBackupError ()
115119 return commit_message
116120
117- if self .config .settings .get ("retry_after_failure" ) and not self .arguments .get (
118- "no_retry"
121+ if (
122+ self .config .settings .get ("retry_after_failure" )
123+ and not self .arguments .get ("no_retry" )
124+ and (backup_message := self ._read_backup_message ())
119125 ):
120- return self . _read_backup_message () or self . _prompt_commit_questions ()
121- return self ._prompt_commit_questions ()
126+ return backup_message
127+ return self ._get_message_by_prompt_commit_questions ()
122128
123129 def __call__ (self ) -> None :
124130 extra_args = self .arguments .get ("extra_cli_args" , "" )
0 commit comments