File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from pathlib import Path
44from typing import Optional
55
6- from commitizen import defaults
6+ from commitizen import defaults , git , out
77from .base_config import BaseConfig
88from .toml_config import TomlConfig
99from .ini_config import IniConfig
1010
1111
12+ NOT_A_GIT_PROJECT = 10
13+
14+
1215def 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]:
3538def 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
You can’t perform that action at this time.
0 commit comments