Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb60269

Browse files
test(init): add yaml without repos key
1 parent 3eb31ac commit fb60269

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

‎commitizen/commands/init.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ def _read_pre_commit_config(self) -> dict[Any, Any]:
366366

367367
if any("commitizen" in hook["repo"] for hook in repos):
368368
out.write("commitizen already in pre-commit config")
369-
else:
370-
config_data["repos"].append(CZ_HOOK_CONFIG)
369+
return config_data
371370

371+
config_data["repos"].append(CZ_HOOK_CONFIG)
372372
return config_data
373373

374374
def _update_config_file(

‎tests/commands/test_init_command.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ def test_pre_commit_config_without_cz_hook(_, default_choice, tmpdir, config):
213213
check_cz_config(default_choice)
214214
check_pre_commit_config([existing_hook_config, CZ_HOOK_CONFIG])
215215

216+
def test_pre_commit_config_yaml_without_repos(_, default_choice, tmpdir, config):
217+
with tmpdir.as_cwd():
218+
# Write a dictionary YAML content without 'repos' key
219+
p = tmpdir.join(PRE_COMMIT_CONFIG_FILENAME)
220+
p.write(
221+
yaml.safe_dump({"some_other_key": "value"})
222+
) # Dictionary without 'repos' key
223+
224+
commands.Init(config)()
225+
check_cz_config(default_choice)
226+
# Should use DEFAULT_CONFIG since the file content doesn't have 'repos' key
227+
check_pre_commit_config([CZ_HOOK_CONFIG])
228+
216229
def test_cz_hook_exists_in_pre_commit_config(_, default_choice, tmpdir, config):
217230
with tmpdir.as_cwd():
218231
p = tmpdir.join(PRE_COMMIT_CONFIG_FILENAME)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /