Skip to content

Commit cce9977

Browse files
committed
feat(config): look up configuration in git project root
#117
1 parent 5ffc9df commit cce9977

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

commitizen/config/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
from pathlib import Path
44
from typing import Optional
55

6-
from commitizen import defaults
6+
from commitizen import defaults, git, out
77
from .base_config import BaseConfig
88
from .toml_config import TomlConfig
99
from .ini_config import IniConfig
1010

1111

12+
NOT_A_GIT_PROJECT = 10
13+
14+
1215
def load_global_conf() -> Optional[IniConfig]:
1316
home = str(Path.home())
1417
global_cfg = os.path.join(home, ".cz")
@@ -35,8 +38,20 @@ def load_global_conf() -> Optional[IniConfig]:
3538
def read_cfg() -> BaseConfig:
3639
conf = BaseConfig()
3740

41+
git_project_root = git.find_git_project_root()
42+
if not git_project_root:
43+
out.error(
44+
"fatal: not a git repository (or any of the parent directories): .git"
45+
)
46+
raise SystemExit(NOT_A_GIT_PROJECT)
47+
3848
allowed_cfg_files = defaults.config_files
39-
for filename in allowed_cfg_files:
49+
cfg_paths = (
50+
str(path / Path(filename))
51+
for path in [Path("."), git_project_root]
52+
for filename in allowed_cfg_files
53+
)
54+
for filename in cfg_paths:
4055
config_file_exists = os.path.exists(filename)
4156
if not config_file_exists:
4257
continue

0 commit comments

Comments
 (0)