Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion commitizen/cz/customize/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
2 changes: 1 addition & 1 deletion docs/customization/config_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cz_customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() == ""
Expand Down
Loading