22
33import warnings
44from logging import getLogger
5- from typing import TYPE_CHECKING , cast
5+ from typing import TYPE_CHECKING
66
77import questionary
88
99from commitizen import bump , factory , git , hooks , out
1010from commitizen .changelog_formats import get_changelog_format
1111from commitizen .commands .changelog import Changelog
12+ from commitizen .config .settings import ChainSettings
1213from commitizen .defaults import Settings
1314from commitizen .exceptions import (
1415 BumpCommitFailedError ,
@@ -70,37 +71,11 @@ def __init__(self, config: BaseConfig, arguments: BumpArgs) -> None:
7071
7172 self .config : BaseConfig = config
7273 self .arguments = arguments
73- self .bump_settings = cast (
74- "BumpArgs" ,
75- {
76- ** config .settings ,
77- ** {
78- k : v
79- for k in (
80- "annotated_tag_message" ,
81- "annotated_tag" ,
82- "bump_message" ,
83- "file_name" ,
84- "gpg_sign" ,
85- "increment_mode" ,
86- "increment" ,
87- "major_version_zero" ,
88- "prerelease_offset" ,
89- "prerelease" ,
90- "tag_format" ,
91- "template" ,
92- )
93- if (v := arguments .get (k )) is not None
94- },
95- },
96- )
74+ self .settings = ChainSettings (config .settings , arguments ).load_settings ()
9775 self .cz = factory .committer_factory (self .config )
9876 self .changelog_flag = arguments ["changelog" ]
9977 self .changelog_to_stdout = arguments ["changelog_to_stdout" ]
10078 self .git_output_to_stderr = arguments ["git_output_to_stderr" ]
101- self .no_verify = arguments ["no_verify" ]
102- self .check_consistency = arguments ["check_consistency" ]
103- self .retry = arguments ["retry" ]
10479 self .pre_bump_hooks = self .config .settings ["pre_bump_hooks" ]
10580 self .post_bump_hooks = self .config .settings ["post_bump_hooks" ]
10681 deprecated_version_type = arguments .get ("version_type" )
@@ -148,7 +123,7 @@ def _find_increment(self, commits: list[git.GitCommit]) -> Increment | None:
148123 # self.cz.bump_map = defaults.bump_map_major_version_zero
149124 bump_map = (
150125 self .cz .bump_map_major_version_zero
151- if self .bump_settings ["major_version_zero" ]
126+ if self .settings ["major_version_zero" ]
152127 else self .cz .bump_map
153128 )
154129 bump_pattern = self .cz .bump_pattern
@@ -230,7 +205,7 @@ def _resolve_increment_and_new_version(
230205 return increment , current_version .bump (
231206 increment ,
232207 prerelease = self .arguments ["prerelease" ],
233- prerelease_offset = self .bump_settings ["prerelease_offset" ],
208+ prerelease_offset = self .settings ["prerelease_offset" ],
234209 devrelease = self .arguments ["devrelease" ],
235210 is_local_version = self .arguments ["local_version" ],
236211 build_metadata = self .arguments ["build_metadata" ],
@@ -262,7 +237,7 @@ def __call__(self) -> None:
262237 )
263238 )
264239
265- rules = TagRules .from_settings (cast ( "Settings" , self .bump_settings ) )
240+ rules = TagRules .from_settings (self .settings )
266241 current_tag = rules .find_tag_for (git .get_tags (), current_version )
267242 current_tag_version = (
268243 current_tag .name if current_tag else rules .normalize_tag (current_version )
@@ -285,7 +260,7 @@ def __call__(self) -> None:
285260 raise DryRunExit ()
286261
287262 message = bump .create_commit_message (
288- current_version , new_version , self .bump_settings ["bump_message" ]
263+ current_version , new_version , self .settings ["bump_message" ]
289264 )
290265 # Report found information
291266 information = f"{ message } \n tag to create: { new_tag_version } \n "
@@ -342,8 +317,8 @@ def __call__(self) -> None:
342317 bump .update_version_in_files (
343318 str (current_version ),
344319 str (new_version ),
345- self .bump_settings ["version_files" ],
346- check_consistency = self .check_consistency ,
320+ self .settings ["version_files" ],
321+ check_consistency = self .arguments [ " check_consistency" ] ,
347322 encoding = self .config .settings ["encoding" ],
348323 )
349324 )
@@ -372,7 +347,7 @@ def __call__(self) -> None:
372347 # FIXME: check if any changes have been staged
373348 git .add (* updated_files )
374349 c = git .commit (message , args = self ._get_commit_args ())
375- if self .retry and c .return_code != 0 and self .changelog_flag :
350+ if self .arguments [ " retry" ] and c .return_code != 0 and self .changelog_flag :
376351 # Maybe pre-commit reformatted some files? Retry once
377352 logger .debug ("1st git.commit error: %s" , c .err )
378353 logger .info ("1st commit attempt failed; retrying once" )
@@ -391,18 +366,18 @@ def __call__(self) -> None:
391366 new_tag_version ,
392367 signed = any (
393368 (
394- self .bump_settings .get ("gpg_sign" ),
395- self .config .settings .get ("gpg_sign" ),
369+ self .settings .get ("gpg_sign" ),
370+ self .config .settings .get ("gpg_sign" ), # TODO: remove this
396371 )
397372 ),
398373 annotated = any (
399374 (
400- self .bump_settings .get ("annotated_tag" ),
401- self .config .settings .get ("annotated_tag" ),
402- self .bump_settings .get ("annotated_tag_message" ),
375+ self .settings .get ("annotated_tag" ),
376+ self .config .settings .get ("annotated_tag" ), # TODO: remove this
377+ self .settings .get ("annotated_tag_message" ),
403378 )
404379 ),
405- msg = self .bump_settings .get ("annotated_tag_message" , None ),
380+ msg = self .settings .get ("annotated_tag_message" , None ), # type: ignore[arg-type]
406381 # TODO: also get from self.config.settings?
407382 )
408383 if c .return_code != 0 :
@@ -432,6 +407,6 @@ def __call__(self) -> None:
432407
433408 def _get_commit_args (self ) -> str :
434409 commit_args = ["-a" ]
435- if self .no_verify :
410+ if self .arguments [ " no_verify" ] :
436411 commit_args .append ("--no-verify" )
437412 return " " .join (commit_args )
0 commit comments