@@ -111,16 +111,6 @@ def is_npm_package(self) -> bool:
111111 def is_php_composer (self ) -> bool :
112112 return os .path .isfile ("composer.json" )
113113
114- @property
115- def latest_tag (self ) -> str | None :
116- return get_latest_tag_name ()
117-
118- def tags (self ) -> list | None :
119- """Not a property, only use if necessary"""
120- if self .latest_tag is None :
121- return None
122- return get_tag_names ()
123-
124114 @property
125115 def is_pre_commit_installed (self ) -> bool :
126116 return bool (shutil .which ("pre-commit" ))
@@ -142,8 +132,8 @@ def __call__(self) -> None:
142132
143133 out .info ("Welcome to commitizen!\n " )
144134 out .line (
145- "Answer the questions to configure your project.\n "
146- "For further configuration visit:\n "
135+ "Answer the following questions to configure your project.\n "
136+ "For further configuration, visit:\n "
147137 "\n "
148138 "https://commitizen-tools.github.io/commitizen/config/"
149139 "\n "
@@ -170,21 +160,6 @@ def __call__(self) -> None:
170160 self .config = JsonConfig (data = "{}" , path = config_path )
171161 elif "yaml" in config_path :
172162 self .config = YAMLConfig (data = "" , path = config_path )
173- values_to_add : dict [str , Any ] = {}
174- values_to_add ["name" ] = cz_name
175- values_to_add ["tag_format" ] = tag_format
176- values_to_add ["version_scheme" ] = version_scheme
177-
178- if version_provider == "commitizen" :
179- values_to_add ["version" ] = version .public
180- else :
181- values_to_add ["version_provider" ] = version_provider
182-
183- if update_changelog_on_bump :
184- values_to_add ["update_changelog_on_bump" ] = update_changelog_on_bump
185-
186- if major_version_zero :
187- values_to_add ["major_version_zero" ] = major_version_zero
188163
189164 # Collect hook data
190165 hook_types = questionary .checkbox (
@@ -202,7 +177,18 @@ def __call__(self) -> None:
202177
203178 # Create and initialize config
204179 self .config .init_empty_config_content ()
205- self ._update_config_file (values_to_add )
180+
181+ self .config .set_key ("name" , cz_name )
182+ self .config .set_key ("tag_format" , tag_format )
183+ self .config .set_key ("version_scheme" , version_scheme )
184+ if version_provider == "commitizen" :
185+ self .config .set_key ("version" , version .public )
186+ else :
187+ self .config .set_key ("version_provider" , version_provider )
188+ if update_changelog_on_bump :
189+ self .config .set_key ("update_changelog_on_bump" , update_changelog_on_bump )
190+ if major_version_zero :
191+ self .config .set_key ("major_version_zero" , major_version_zero )
206192
207193 out .write ("\n You can bump the version running:\n " )
208194 out .info ("\t cz bump\n " )
@@ -231,31 +217,32 @@ def _ask_name(self) -> str:
231217 return name
232218
233219 def _ask_tag (self ) -> str :
234- latest_tag = self . project_info . latest_tag
220+ latest_tag = get_latest_tag_name ()
235221 if not latest_tag :
236222 out .error ("No Existing Tag. Set tag to v0.0.1" )
237223 return "0.0.1"
238224
239- is_correct_tag = questionary .confirm (
225+ if questionary .confirm (
240226 f"Is { latest_tag } the latest tag?" , style = self .cz .style , default = False
227+ ).unsafe_ask ():
228+ return latest_tag
229+
230+ existing_tags = get_tag_names ()
231+ if not existing_tags :
232+ out .error ("No Existing Tag. Set tag to v0.0.1" )
233+ return "0.0.1"
234+
235+ answer : str = questionary .select (
236+ "Please choose the latest tag: " ,
237+ # The latest tag is most likely with the largest number.
238+ # Thus, listing the existing_tags in reverse order makes more sense.
239+ choices = sorted (existing_tags , reverse = True ),
240+ style = self .cz .style ,
241241 ).unsafe_ask ()
242- if not is_correct_tag :
243- tags = self .project_info .tags ()
244- if not tags :
245- out .error ("No Existing Tag. Set tag to v0.0.1" )
246- return "0.0.1"
247-
248- # the latest tag is most likely with the largest number. Thus list the tags in reverse order makes more sense
249- sorted_tags = sorted (tags , reverse = True )
250- latest_tag = questionary .select (
251- "Please choose the latest tag: " ,
252- choices = sorted_tags ,
253- style = self .cz .style ,
254- ).unsafe_ask ()
255-
256- if not latest_tag :
257- raise NoAnswersError ("Tag is required!" )
258- return latest_tag
242+
243+ if not answer :
244+ raise NoAnswersError ("Tag is required!" )
245+ return answer
259246
260247 def _ask_tag_format (self , latest_tag : str ) -> str :
261248 if latest_tag .startswith ("v" ):
@@ -360,7 +347,7 @@ def _get_config_data(self) -> dict[str, Any]:
360347 "rev" : f"v{ __version__ } " ,
361348 "hooks" : [
362349 {"id" : "commitizen" },
363- {"id" : "commitizen-branch" , "stages" : ["push" ]},
350+ {"id" : "commitizen-branch" , "stages" : ["pre- push" ]},
364351 ],
365352 }
366353
@@ -396,7 +383,3 @@ def _install_pre_commit_hook(self, hook_types: list[str] | None = None) -> None:
396383 hook_types = ["commit-msg" , "pre-push" ]
397384 self ._exec_install_pre_commit_hook (hook_types )
398385 out .write ("commitizen pre-commit hook is now installed in your '.git'\n " )
399-
400- def _update_config_file (self , values : dict [str , Any ]) -> None :
401- for key , value in values .items ():
402- self .config .set_key (key , value )
0 commit comments