@@ -62,33 +62,37 @@ def _read_backup_message(self) -> str | None:
62
62
with open (self .temp_file , encoding = self .encoding ) as f :
63
63
return f .read ().strip ()
64
64
65
- def _prompt_commit_questions (self ) -> str :
65
+ def _get_message_by_prompt_commit_questions (self ) -> str :
66
66
# Prompt user for the commit message
67
- cz = self .cz
68
- questions = cz .questions ()
67
+ questions = self .cz .questions ()
69
68
for question in (q for q in questions if q ["type" ] == "list" ):
70
69
question ["use_shortcuts" ] = self .config .settings ["use_shortcuts" ]
71
70
try :
72
- answers = questionary .prompt (questions , style = cz .style )
71
+ answers = questionary .prompt (questions , style = self . cz .style )
73
72
except ValueError as err :
74
73
root_err = err .__context__
75
74
if isinstance (root_err , CzException ):
76
- raise CustomError (root_err . __str__ ( ))
75
+ raise CustomError (str ( root_err ))
77
76
raise err
78
77
79
78
if not answers :
80
79
raise NoAnswersError ()
81
80
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 :
86
92
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 } ' "
88
94
)
89
95
90
- return message
91
-
92
96
def manual_edit (self , message : str ) -> str :
93
97
editor = git .get_core_editor ()
94
98
if editor is None :
@@ -113,11 +117,13 @@ def _get_message(self) -> str:
113
117
raise NoCommitBackupError ()
114
118
return m
115
119
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 ())
118
124
):
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 ()
121
127
122
128
def __call__ (self ) -> None :
123
129
extra_args = self .arguments .get ("extra_cli_args" , "" )
0 commit comments