@@ -13,23 +13,17 @@ def _resolve_config_candidates() -> list[BaseConfig]:
1313 git_project_root = git .find_git_project_root ()
1414 cfg_search_paths = [Path ("." )]
1515
16- if git_project_root and not cfg_search_paths [0 ].samefile ( git_project_root ):
16+ if git_project_root and cfg_search_paths [0 ].resolve () != git_project_root . resolve ( ):
1717 cfg_search_paths .append (git_project_root )
1818
19- # The following algorithm is ugly, but we need to ensure that the order of the candidates are preserved before v5.
20- # Also, the number of possible config files is limited, so the complexity is not a problem.
2119 candidates : list [BaseConfig ] = []
2220 for dir in cfg_search_paths :
2321 for filename in defaults .CONFIG_FILES :
2422 out_path = dir / Path (filename )
25- if (
26- out_path .exists ()
27- and not any (
28- out_path .samefile (candidate .path ) for candidate in candidates
29- )
30- and not (conf := _create_config_from_path (out_path )).is_empty_config
31- ):
32- candidates .append (conf )
23+ if out_path .is_file ():
24+ conf = _create_config_from_path (out_path )
25+ if conf .contains_commitizen_section ():
26+ candidates .append (conf )
3327 return candidates
3428
3529
@@ -43,10 +37,10 @@ def _create_config_from_path(path: Path) -> BaseConfig:
4337def read_cfg (filepath : str | None = None ) -> BaseConfig :
4438 if filepath is not None :
4539 conf_path = Path (filepath )
46- if not conf_path .exists ():
40+ if not conf_path .is_file ():
4741 raise ConfigFileNotFound ()
4842 conf = _create_config_from_path (conf_path )
49- if conf .is_empty_config :
43+ if not conf .contains_commitizen_section () :
5044 raise ConfigFileIsEmpty ()
5145 return conf
5246
0 commit comments