Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions commitizen/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from commitizen.cz import registry
from commitizen.config import BaseConfig, TomlConfig, IniConfig
from commitizen.git import get_latest_tag_name, get_tag_names
from commitizen.defaults import config_files
from commitizen.defaults import long_term_support_config_files


class Init:
Expand All @@ -17,7 +17,7 @@ def __init__(self, config: BaseConfig, *args):
def __call__(self):
values_to_add = {}

# No config file exist
# No config for commitizen exist
if not self.config.path:
config_path = self._ask_config_path()

Expand All @@ -26,7 +26,7 @@ def __call__(self):
else:
self.config = IniConfig(data="", path=config_path)

self.config.init_empty_config_file()
self.config.init_empty_config_content()

values_to_add["name"] = self._ask_name()
tag = self._ask_tag()
Expand All @@ -41,7 +41,7 @@ def __call__(self):
def _ask_config_path(self) -> str:
name = questionary.select(
"Please choose a supported config file: (default: pyproject.tml)",
choices=config_files,
choices=long_term_support_config_files,
default="pyproject.toml",
style=self.cz.style,
).ask()
Expand Down
4 changes: 2 additions & 2 deletions commitizen/config/toml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def __init__(self, *, data: str, path: str):
self._parse_setting(data)
self.add_path(path)

def init_empty_config_file(self):
with open(self.path, "w") as toml_file:
def init_empty_config_content(self):
with open(self.path, "a") as toml_file:
toml_file.write("[tool.commitizen]")

def set_key(self, key, value):
Expand Down
4 changes: 3 additions & 1 deletion commitizen/defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: str = "cz_conventional_commits"
# TODO: .cz, setup.cfg, .cz.cfg should be removed in 2.0
config_files: list = ["pyproject.toml", ".cz.toml", ".cz", "setup.cfg", ".cz.cfg"]
long_term_support_config_files: list = ["pyproject.toml", ".cz.toml"]
deprcated_config_files: list = [".cz", "setup.cfg", ".cz.cfg"]
config_files: list = long_term_support_config_files + deprcated_config_files

DEFAULT_SETTINGS = {
"name": "cz_conventional_commits",
Expand Down
21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,24 @@ git-cz = "commitizen.cli:main"
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

[tool.coverage]
[tool.coverage.report]
show_missing = true
exclude_lines = [
# Have to re-enable the standard pragma
'pragma: no cover',

# Don't complain about missing debug-only code:
'def __repr__',
'if self\.debug',

# Don't complain if tests don't hit defensive assertion code:
'raise AssertionError',
'raise NotImplementedError',

# Don't complain if non-runnable code isn't run:
'if 0:',
'if __name__ == .__main__.:'
]

15 changes: 13 additions & 2 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,21 @@ def test_read_cfg_when_not_in_a_git_project(tmpdir):


class TestTomlConfig:
def test_init_empty_config_file(self, tmpdir):
def test_init_empty_config_content(self, tmpdir):
path = tmpdir.mkdir("commitizen").join(".cz.toml")
toml_config = config.TomlConfig(data="", path=path)
toml_config.init_empty_config_file()
toml_config.init_empty_config_content()

with open(path, "r") as toml_file:
assert toml_file.read() == "[tool.commitizen]"

def test_init_empty_config_content_with_existing_content(self, tmpdir):
existing_content = "[tool.black]\n" "line-length = 88\n"

path = tmpdir.mkdir("commitizen").join(".cz.toml")
path.write(existing_content)
toml_config = config.TomlConfig(data="", path=path)
toml_config.init_empty_config_content()

with open(path, "r") as toml_file:
assert toml_file.read() == existing_content + "[tool.commitizen]"