11from __future__ import annotations
22
3- import os
43import warnings
54from logging import getLogger
65
76import questionary
87
9- from commitizen import bump , cmd , factory , git , hooks , out
8+ from commitizen import bump , factory , git , hooks , out
109from commitizen .commands .changelog import Changelog
1110from commitizen .config import BaseConfig
1211from commitizen .exceptions import (
@@ -286,56 +285,39 @@ def __call__(self) -> None: # noqa: C901
286285 "The commits found are not eligible to be bumped"
287286 )
288287
288+ files : list [str ] = []
289289 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+ }
290297 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 })
301299 try :
302300 changelog_cmd ()
303301 except DryRunExit :
304302 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 )
316306 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 )
328308
329309 # Do not perform operations over files or git.
330310 if dry_run :
331311 raise DryRunExit ()
332312
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+ )
339321 )
340322
341323 provider .set_version (str (new_version ))
@@ -358,12 +340,13 @@ def __call__(self) -> None: # noqa: C901
358340 raise ExpectedExit ()
359341
360342 # FIXME: check if any changes have been staged
343+ git .add (* files )
361344 c = git .commit (message , args = self ._get_commit_args ())
362345 if self .retry and c .return_code != 0 and self .changelog :
363346 # Maybe pre-commit reformatted some files? Retry once
364347 logger .debug ("1st git.commit error: %s" , c .err )
365348 logger .info ("1st commit attempt failed; retrying once" )
366- cmd . run ( git_add_changelog_and_version_files_command )
349+ git . add ( * files )
367350 c = git .commit (message , args = self ._get_commit_args ())
368351 if c .return_code != 0 :
369352 err = c .err .strip () or c .out
0 commit comments