fix(changelog): restore cwd-relative resolution for --file-name CLI arg#1987
Open
bearomorphism wants to merge 2 commits intocommitizen-tools:masterfrom
Open
fix(changelog): restore cwd-relative resolution for --file-name CLI arg#1987bearomorphism wants to merge 2 commits intocommitizen-tools:masterfrom
bearomorphism wants to merge 2 commits intocommitizen-tools:masterfrom
Conversation
Closes commitizen-tools#1331 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When --file-name is passed on the command line, the path should be interpreted relative to the current working directory, as is standard for CLI tools. When changelog_file is read from the configuration file it should be anchored to the config file's directory so the result is stable regardless of where cz is invoked. PR commitizen-tools#1391 / v4.6.3 inadvertently applied the config-dir anchor to BOTH sources, breaking setups where users specify a cwd-relative path via --file-name (e.g. from a Sphinx docs subdirectory). Changes: - commitizen/commands/changelog.py: distinguish args-provided file_name (cwd-relative) from config-provided changelog_file (config-dir-relative) - commitizen/commands/bump.py: only forward file_name to Changelog when it was explicitly supplied via CLI; otherwise let Changelog perform its own config lookup so the anchor logic is applied correctly - tests/test_changelog.py: replace the PR-commitizen-tools#1391 test with a parametrised regression test covering all four combinations - docs/commands/changelog.md: document the two resolution strategies Fixes commitizen-tools#1411 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restores pre-v4.6.3 behavior for cz changelog --file-name by making CLI-provided paths resolve relative to the current working directory, while preserving config-provided changelog_file resolution relative to the config file directory. It also introduces a new cz dump-config command with docs/tests.
Changes:
- Fix changelog output path resolution by distinguishing CLI
--file-namevs configchangelog_filesources. - Adjust
cz bump --changelogto only forwardfile_nametoChangelogwhen explicitly provided via CLI. - Add a new
cz dump-configcommand, along with documentation and tests.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
commitizen/commands/changelog.py |
Implements source-aware path resolution for changelog output filename. |
commitizen/commands/bump.py |
Ensures Bump only forwards CLI --file-name, letting Changelog resolve config-relative paths. |
tests/test_changelog.py |
Updates/extends tests to validate the new filename resolution behavior. |
docs/commands/changelog.md |
Documents the CLI-vs-config relative path behavior. |
commitizen/commands/dump_config.py |
Adds the DumpConfig command implementation. |
commitizen/commands/__init__.py |
Exposes DumpConfig in the commands package. |
commitizen/cli.py |
Registers the new dump-config subcommand and help text. |
tests/commands/test_dump_config_command.py |
Adds tests for dump-config output formats. |
tests/commands/test_common_command.py |
Includes dump-config in the common --help regression tests. |
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_10_dump_config_.txt |
Adds help output snapshot for dump-config (Py 3.10). |
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_11_dump_config_.txt |
Adds help output snapshot for dump-config (Py 3.11). |
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_12_dump_config_.txt |
Adds help output snapshot for dump-config (Py 3.12). |
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_13_dump_config_.txt |
Adds help output snapshot for dump-config (Py 3.13). |
tests/commands/test_common_command/test_command_shows_description_when_use_help_option_py_3_14_dump_config_.txt |
Adds help output snapshot for dump-config (Py 3.14). |
docs/commands/dump_config.md |
Adds documentation for the new dump-config command. |
mkdocs.yml |
Adds the new dump-config docs page to navigation and plugin config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+39
to
+46
| {"tool": {"commitizen": settings}}, | ||
| default_flow_style=False, | ||
| allow_unicode=True, | ||
| ) | ||
| ) | ||
| else: | ||
| out.write( | ||
| json.dumps({"tool": {"commitizen": settings}}, indent=2, default=str) |
Comment on lines
+200
to
+213
| { | ||
| "name": "dump-config", | ||
| "description": "Output the current commitizen configuration", | ||
| "help": "Output the current commitizen configuration.", | ||
| "func": commands.DumpConfig, | ||
| "arguments": [ | ||
| { | ||
| "name": ["--format", "-f"], | ||
| "choices": ["toml", "yaml", "json"], | ||
| "default": "toml", | ||
| "help": "Output format (default: toml).", | ||
| } | ||
| ], | ||
| }, |
Comment on lines
+33
to
+44
| assert "tool" in data | ||
| assert "commitizen" in data["tool"] | ||
| assert data["tool"]["commitizen"]["name"] == "cz_conventional_commits" | ||
|
|
||
|
|
||
| def test_dump_config_json(config, capsys): | ||
| DumpConfig(config, {"format": "json"})() | ||
| out, _ = capsys.readouterr() | ||
| data = json.loads(out) | ||
| assert "tool" in data | ||
| assert "commitizen" in data["tool"] | ||
| assert data["tool"]["commitizen"]["name"] == "cz_conventional_commits" |
Comment on lines
+1
to
+16
| # dump-config | ||
|
|
||
| Output the current commitizen configuration (defaults merged with any project overrides) so you can paste it directly into a configuration file as a starting point. | ||
|
|
||
| ## Usage | ||
|
|
||
| ``` | ||
| cz dump-config [--format {toml,yaml,json}] | ||
| ``` | ||
|
|
||
| ## Options | ||
|
|
||
| | Option | Description | | ||
| |---|---| | ||
| | `--format`, `-f` | Output format: `toml` (default), `yaml`, or `json` | | ||
|
|
30 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Why
Fixes #1411 — relative paths work differently with newer versions.
The user reported that after upgrading to v4.6.3, the following command stopped working as expected:
# run from a Sphinx docs subdirectory cz -n cz_customize changelog --file-name=changelog/fileBefore v4.6.3: the file was created at
<cwd>/changelog/file(relative to the directory whereczwas invoked — standard CLI behaviour).After v4.6.3: the file is created at
<project_root>/changelog/file(relative to the config file's directory), ignoringcwd.What changed
--file-nameCLI argchangelog_fileconfig settingPR #1391 (v4.6.3) fixed a real bug —
cz bump --changelogfrom a subdirectory was writing the changelog relative to the subdirectory instead of the project root. However, it applied the config-dir anchor to both sources: the config-filechangelog_filesetting AND the CLI--file-nameargument. This over-correction broke existing setups that relied on--file-namebeing cwd-relative.How it works
commitizen/commands/changelog.py: The__init__method now distinguishes between the two sources:arguments.get("file_name")(CLI arg) → used as-is, relative to cwdconfig.settings.get("changelog_file")(config setting) → resolved relative toconfig.path.parentcommitizen/commands/bump.py: WhenBumpinvokesChangelog, it previously always forwardedfile_name(even when the value came from config). It now only forwardsfile_nameif it was explicitly provided via CLI (--file-name). Without a forwardedfile_name,Changelogfalls through to its own config lookup and applies the correct config-dir anchor.Backward compatibility
--file-namebeing resolved relative to cwd: behaviour restored to pre-v4.6.3.changelog_filein config being resolved relative to the config dir: no change, the PR fix: cz bump subdir #1391 behaviour is preserved.cz bump --changelogwithout--file-namefrom a subdirectory: no change, the changelog still goes to the project root (the PR fix: cz bump subdir #1391 fix is preserved).Checklist
Was generative AI tooling used to co-author this PR?
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsExpected Behavior
cz changelog --file-name=changelog/CHANGES.mdrun from any working directory should write the changelog to<cwd>/changelog/CHANGES.md.changelog_file = "CHANGELOG.md"inpyproject.tomlshould write the changelog to<project_root>/CHANGELOG.md, regardless of the working directory.Steps to Test This Pull Request
Additional Context