@@ -62,33 +62,37 @@ def _read_backup_message(self) -> str | None:
6262 with open (self .temp_file , encoding = self .encoding ) as f :
6363 return f .read ().strip ()
6464
65- def _prompt_commit_questions (self ) -> str :
65+ def _get_message_by_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 :
@@ -113,11 +117,13 @@ def _get_message(self) -> str:
113117 raise NoCommitBackupError ()
114118 return m
115119
116- if self .config .settings .get ("retry_after_failure" ) and not self .arguments .get (
117- "no_retry"
120+ if (
121+ self .config .settings .get ("retry_after_failure" )
122+ and not self .arguments .get ("no_retry" )
123+ and (backup_message := self ._read_backup_message ())
118124 ):
119- return self . _read_backup_message () or self . _prompt_commit_questions ()
120- return self ._prompt_commit_questions ()
125+ return backup_message
126+ return self ._get_message_by_prompt_commit_questions ()
121127
122128 def __call__ (self ) -> None :
123129 extra_args = self .arguments .get ("extra_cli_args" , "" )
0 commit comments