1
1
from __future__ import annotations
2
2
3
- import os
4
3
import warnings
5
4
from logging import getLogger
6
5
7
6
import questionary
8
7
9
- from commitizen import bump , cmd , factory , git , hooks , out
8
+ from commitizen import bump , factory , git , hooks , out
10
9
from commitizen .commands .changelog import Changelog
11
10
from commitizen .config import BaseConfig
12
11
from commitizen .exceptions import (
@@ -286,56 +285,39 @@ def __call__(self) -> None: # noqa: C901
286
285
"The commits found are not eligible to be bumped"
287
286
)
288
287
288
+ files : list [str ] = []
289
289
if self .changelog :
290
+ args = {
291
+ "unreleased_version" : new_tag_version ,
292
+ "template" : self .template ,
293
+ "extras" : self .extras ,
294
+ "incremental" : True ,
295
+ "dry_run" : dry_run ,
296
+ }
290
297
if self .changelog_to_stdout :
291
- changelog_cmd = Changelog (
292
- self .config ,
293
- {
294
- "unreleased_version" : new_tag_version ,
295
- "template" : self .template ,
296
- "extras" : self .extras ,
297
- "incremental" : True ,
298
- "dry_run" : True ,
299
- },
300
- )
298
+ changelog_cmd = Changelog (self .config , {** args , "dry_run" : True })
301
299
try :
302
300
changelog_cmd ()
303
301
except DryRunExit :
304
302
pass
305
- changelog_cmd = Changelog (
306
- self .config ,
307
- {
308
- "unreleased_version" : new_tag_version ,
309
- "incremental" : True ,
310
- "dry_run" : dry_run ,
311
- "template" : self .template ,
312
- "extras" : self .extras ,
313
- "file_name" : self .file_name ,
314
- },
315
- )
303
+
304
+ args ["file_name" ] = self .file_name
305
+ changelog_cmd = Changelog (self .config , args )
316
306
changelog_cmd ()
317
- file_names = []
318
- for file_name in version_files :
319
- drive , tail = os .path .splitdrive (file_name )
320
- path , _ , regex = tail .partition (":" )
321
- path = drive + path if path != "" else drive + regex
322
- file_names .append (path )
323
- git_add_changelog_and_version_files_command = (
324
- f"git add { changelog_cmd .file_name } "
325
- f"{ ' ' .join (name for name in file_names )} "
326
- )
327
- c = cmd .run (git_add_changelog_and_version_files_command )
307
+ files .append (changelog_cmd .file_name )
328
308
329
309
# Do not perform operations over files or git.
330
310
if dry_run :
331
311
raise DryRunExit ()
332
312
333
- bump .update_version_in_files (
334
- str (current_version ),
335
- str (new_version ),
336
- version_files ,
337
- check_consistency = self .check_consistency ,
338
- encoding = self .encoding ,
313
+ files .extend (
314
+ bump .update_version_in_files (
315
+ str (current_version ),
316
+ str (new_version ),
317
+ version_files ,
318
+ check_consistency = self .check_consistency ,
319
+ encoding = self .encoding ,
320
+ )
339
321
)
340
322
341
323
provider .set_version (str (new_version ))
@@ -358,12 +340,13 @@ def __call__(self) -> None: # noqa: C901
358
340
raise ExpectedExit ()
359
341
360
342
# FIXME: check if any changes have been staged
343
+ git .add (* files )
361
344
c = git .commit (message , args = self ._get_commit_args ())
362
345
if self .retry and c .return_code != 0 and self .changelog :
363
346
# Maybe pre-commit reformatted some files? Retry once
364
347
logger .debug ("1st git.commit error: %s" , c .err )
365
348
logger .info ("1st commit attempt failed; retrying once" )
366
- cmd . run ( git_add_changelog_and_version_files_command )
349
+ git . add ( * files )
367
350
c = git .commit (message , args = self ._get_commit_args ())
368
351
if c .return_code != 0 :
369
352
err = c .err .strip () or c .out
0 commit comments