Skip to content

Commit 1d4a4d6

Browse files
committed
fix(config): handle empty config file
1 parent f726ef4 commit 1d4a4d6

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

commitizen/config/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,19 @@ def read_cfg() -> dict:
4444
data: str = f.read()
4545

4646
if "toml" in filename:
47-
conf = TomlConfig(data=data, path=filename)
47+
_conf = TomlConfig(data=data, path=filename)
4848
else:
4949
warnings.warn(
5050
".cz, setup.cfg, and .cz.cfg will be deprecated "
5151
"in next major version. \n"
5252
'Please use "pyproject.toml", ".cz.toml" instead'
5353
)
54-
conf = IniConfig(data=data, path=filename)
54+
_conf = IniConfig(data=data, path=filename)
5555

56-
if not conf:
56+
if _conf.is_empty_config:
5757
continue
5858
else:
59+
conf = _conf
5960
break
6061

6162
if not conf.path:

commitizen/config/ini_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class IniConfig(BaseConfig):
1818

1919
def __init__(self, *, data: str, path: str):
2020
super(IniConfig, self).__init__()
21+
self.is_empty_config = False
2122
self._parse_setting(data)
2223
self._path = path
2324

@@ -65,4 +66,4 @@ def _parse_setting(self, data: str) -> dict:
6566

6667
self._settings.update(_data)
6768
except KeyError:
68-
pass
69+
self.is_empty_config = True

commitizen/config/toml_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class TomlConfig(BaseConfig):
77
def __init__(self, *, data: str, path: str):
88
super(TomlConfig, self).__init__()
9+
self.is_empty_config = False
910
self._parse_setting(data)
1011
self._path = path
1112

@@ -35,4 +36,4 @@ def _parse_setting(self, data: str) -> dict:
3536
try:
3637
self._settings.update(doc["tool"]["commitizen"])
3738
except exceptions.NonExistentKey:
38-
pass
39+
self.is_empty_config = True

tests/test_conf.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ def test_load_conf(config_files_manager, configure_supported_files):
106106
assert cfg.settings == _settings
107107

108108

109-
@pytest.mark.skip(
110-
msg="Empty config is broken due to refactor. Will fix it in next commit"
111-
)
112109
def test_conf_is_loaded_with_empty_pyproject_but_ok_cz(
113110
empty_pyproject_ok_cz, configure_supported_files
114111
):

0 commit comments

Comments
 (0)