From 083bf2d54603e5196d81f18037487d0deb98971b Mon Sep 17 00:00:00 2001 From: draarivpatel-ui <287273626+draarivpatel-ui@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:48:13 -0600 Subject: [PATCH] fix(customize): resolve info_path from config directory Assisted By: AI --- commitizen/cz/customize/customize.py | 5 ++++- docs/customization/config_file.md | 2 +- tests/test_cz_customize.py | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/commitizen/cz/customize/customize.py b/commitizen/cz/customize/customize.py index 3526048420..b964818d85 100644 --- a/commitizen/cz/customize/customize.py +++ b/commitizen/cz/customize/customize.py @@ -100,5 +100,8 @@ def schema(self) -> str: def info(self) -> str: if info_path := self.custom_settings.get("info_path"): - return Path(info_path).read_text(encoding=self.config.settings["encoding"]) + path = Path(info_path) + if not path.is_absolute() and self.config.path is not None: + path = self.config.path.parent / path + return path.read_text(encoding=self.config.settings["encoding"]) return self.custom_settings.get("info") or "" diff --git a/docs/customization/config_file.md b/docs/customization/config_file.md index 97750e75a7..023129d2a5 100644 --- a/docs/customization/config_file.md +++ b/docs/customization/config_file.md @@ -158,7 +158,7 @@ Example: | `example` | `str` | `""` | (OPTIONAL) Provide an example to help understand the style. Used by `cz example`. | | `schema` | `str` | `""` | (OPTIONAL) Show the schema used. Used by `cz schema`. | | `schema_pattern` | `str` | `""` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. | -| `info_path` | `str` | `""` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Used by `cz info`. If not provided `cz info`, will load `info` instead. | +| `info_path` | `str` | `""` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Relative paths are resolved from the configuration file directory. Used by `cz info`. If not provided `cz info`, will load `info` instead. | | `info` | `str` | `""` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. | | `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`). In JSON and YAML configs, `null` keeps a matched rule from bumping the version. | | `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) | diff --git a/tests/test_cz_customize.py b/tests/test_cz_customize.py index 726177247b..8af3657279 100644 --- a/tests/test_cz_customize.py +++ b/tests/test_cz_customize.py @@ -655,6 +655,24 @@ def test_info_with_info_path(tmp_path, monkeypatch, config_info): assert "Test info" in cz.info() +def test_info_with_info_path_outside_cwd(tmp_path, monkeypatch, config_info): + """Regression test for resolving info_path from the config file directory.""" + # Arrange + config_dir = tmp_path / "project" + config_dir.mkdir() + (config_dir / "info.txt").write_text("Test info") + config_info.path = config_dir / config_info.path.name + work_dir = tmp_path / "subdirectory" + work_dir.mkdir() + monkeypatch.chdir(work_dir) + + # Act + info = CustomizeCommitsCz(config_info).info() + + # Assert + assert "Test info" in info + + def test_info_without_info(config_without_info): cz = CustomizeCommitsCz(config_without_info) assert cz.info() == ""