@@ -92,41 +92,36 @@ def manual_edit(self, message: str) -> str:
92
92
os .unlink (file .name )
93
93
return message
94
94
95
- def __call__ (self ):
96
- extra_args : str = self .arguments .get ("extra_cli_args" , "" )
95
+ def _get_message (self ) -> str :
96
+ if self .arguments .get ("retry" ):
97
+ m = self .read_backup_message ()
98
+ if m is None :
99
+ raise NoCommitBackupError ()
100
+ return m
97
101
98
- allow_empty : bool = "--allow-empty" in extra_args
102
+ if self .config .settings .get ("retry_after_failure" ) and not self .arguments .get (
103
+ "no_retry"
104
+ ):
105
+ return self .prompt_commit_questions ()
106
+ return self .read_backup_message () or self .prompt_commit_questions ()
99
107
108
+ def __call__ (self ):
109
+ extra_args : str = self .arguments .get ("extra_cli_args" , "" )
100
110
dry_run : bool = self .arguments .get ("dry_run" )
101
111
write_message_to_file : bool = self .arguments .get ("write_message_to_file" )
102
- manual_edit : bool = self .arguments .get ("edit " )
112
+ signoff : bool = self .arguments .get ("signoff " )
103
113
104
- is_all : bool = self .arguments .get ("all" )
105
- if is_all :
106
- c = git .add ("-u" )
114
+ if self .arguments .get ("all" ):
115
+ git .add ("-u" )
107
116
108
- if git .is_staging_clean () and not (dry_run or allow_empty ):
117
+ if git .is_staging_clean () and not (dry_run or "--allow-empty" in extra_args ):
109
118
raise NothingToCommitError ("No files added to staging!" )
110
119
111
120
if write_message_to_file is not None and write_message_to_file .is_dir ():
112
121
raise NotAllowed (f"{ write_message_to_file } is a directory" )
113
122
114
- retry : bool = self .arguments .get ("retry" )
115
- no_retry : bool = self .arguments .get ("no_retry" )
116
- retry_after_failure : bool = self .config .settings .get ("retry_after_failure" )
117
-
118
- if retry :
119
- m = self .read_backup_message ()
120
- if m is None :
121
- raise NoCommitBackupError ()
122
- elif retry_after_failure and not no_retry :
123
- m = self .read_backup_message ()
124
- if m is None :
125
- m = self .prompt_commit_questions ()
126
- else :
127
- m = self .prompt_commit_questions ()
128
-
129
- if manual_edit :
123
+ m = self ._get_message ()
124
+ if self .arguments .get ("edit" ):
130
125
m = self .manual_edit (m )
131
126
132
127
out .info (f"\n { m } \n " )
@@ -138,19 +133,15 @@ def __call__(self):
138
133
if dry_run :
139
134
raise DryRunExit ()
140
135
141
- always_signoff : bool = self .config .settings ["always_signoff" ]
142
- signoff : bool = self .arguments .get ("signoff" )
143
-
144
136
if signoff :
145
137
out .warn (
146
138
"signoff mechanic is deprecated, please use `cz commit -- -s` instead."
147
139
)
148
140
149
- if always_signoff or signoff :
141
+ if self . config . settings [ " always_signoff" ] or signoff :
150
142
extra_args = f"{ extra_args } -s" .strip ()
151
143
152
144
c = git .commit (m , args = extra_args )
153
-
154
145
if c .return_code != 0 :
155
146
out .error (c .err )
156
147
@@ -160,11 +151,12 @@ def __call__(self):
160
151
161
152
raise CommitError ()
162
153
163
- if "nothing added" in c .out or " no changes added to commit" in c . out :
154
+ if any ( s in c .out for s in ( "nothing added" , " no changes added to commit")) :
164
155
out .error (c .out )
165
- else :
166
- with contextlib .suppress (FileNotFoundError ):
167
- os .remove (self .temp_file )
168
- out .write (c .err )
169
- out .write (c .out )
170
- out .success ("Commit successful!" )
156
+ return
157
+
158
+ with contextlib .suppress (FileNotFoundError ):
159
+ os .remove (self .temp_file )
160
+ out .write (c .err )
161
+ out .write (c .out )
162
+ out .success ("Commit successful!" )
0 commit comments