@@ -23,6 +23,33 @@ def __init__(self, config: dict, arguments: dict):
23
23
self .arguments = arguments
24
24
self .temp_file : str = os .path .join (tempfile .gettempdir (), "cz.commit.backup" )
25
25
26
+ def read_backup_message (self ) -> str :
27
+ # Check the commit backup file exists
28
+ if not os .path .isfile (self .temp_file ):
29
+ out .error ("No commit backup found" )
30
+ raise SystemExit (NO_COMMIT_BACKUP )
31
+
32
+ # Read commit message from backup
33
+ with open (self .temp_file , "r" ) as f :
34
+ return f .read ().strip ()
35
+
36
+ def prompt_commit_questions (self ) -> str :
37
+ # Prompt user for the commit message
38
+ cz = self .cz
39
+ questions = cz .questions ()
40
+ try :
41
+ answers = questionary .prompt (questions , style = cz .style )
42
+ except ValueError as err :
43
+ root_err = err .__context__
44
+ if isinstance (root_err , CzException ):
45
+ out .error (root_err .__str__ ())
46
+ raise SystemExit (CUSTOM_ERROR )
47
+ raise err
48
+
49
+ if not answers :
50
+ raise SystemExit (NO_ANSWERS )
51
+ return cz .message (answers )
52
+
26
53
def __call__ (self ):
27
54
if git .is_staging_clean ():
28
55
out .write ("No files added to staging!" )
@@ -31,30 +58,9 @@ def __call__(self):
31
58
retry : bool = self .arguments .get ("retry" )
32
59
33
60
if retry :
34
- # Check the commit backup file exists
35
- if not os .path .isfile (self .temp_file ):
36
- out .error ("No commit backup found" )
37
- raise SystemExit (NO_COMMIT_BACKUP )
38
-
39
- # Read commit message from backup
40
- with open (self .temp_file , "r" ) as f :
41
- m = f .read ().strip ()
61
+ m = self .read_backup_message ()
42
62
else :
43
- # Prompt user for the commit message
44
- cz = self .cz
45
- questions = cz .questions ()
46
- try :
47
- answers = questionary .prompt (questions , style = cz .style )
48
- except ValueError as err :
49
- root_err = err .__context__
50
- if isinstance (root_err , CzException ):
51
- out .error (root_err .__str__ ())
52
- raise SystemExit (CUSTOM_ERROR )
53
- raise err
54
-
55
- if not answers :
56
- raise SystemExit (NO_ANSWERS )
57
- m = cz .message (answers )
63
+ m = self .prompt_commit_questions ()
58
64
59
65
out .info (f"\n { m } \n " )
60
66
c = git .commit (m )
0 commit comments