cz-path
Commitizen plugin that prefixes commit messages with the common path or prefix of staged files.
Installation
pip install cz-path
The package depends on Commitizen, so you get the cz command when you install cz-path.
Usage
Configure Commitizen
Point Commitizen at this plugin by setting name to cz_path in your configuration file (see
below). To use this plugin for a single run without changing the config file, pass -n cz_path or
--name cz_path to cz.
Create a commit
-
Use a Git repository. Run
czfrom the repository root. The plugin opens the Git index in the current directory, so running it elsewhere will not see your project. -
Stage your changes with
git add. The plugin looks at the staged diff againstHEADto suggest a path prefix. If nothing is staged, Commitizen fails with a message that no staged files were found. -
Start Commitizen to write the message and create the commit:
cz commitShort form:
cz c. -
Answer the prompts:
- Prefix — pick the suggested path prefix (if shown), or
project, or(empty)for no prefix. - Commit title — the rest of the subject line. The full message is
<prefix>: <title>.
- Prefix — pick the suggested path prefix (if shown), or
Message format
Commits follow <prefix>: <title>, for example module/component: short description of the change.
The pattern is a prefix (which may be empty), then a colon and space, then the title.
By default, src/ is stripped from the computed prefix. Set remove_path_prefixes to [] to turn
that off, or add other path segments (such as a top-level package name) to strip. You do not need to
include a trailing / in each entry.
pyproject.toml
[tool.commitizen]
name = "cz_path"
remove_path_prefixes = ["src", "module_name"]
.cz.json
{
"commitizen": {
"name": "cz_path",
"remove_path_prefixes": ["src", "module_name"]
}
}
Scenarios
| Staged files | Path prefix | String prefix |
|---|---|---|
src/a.c, src/b.c |
src |
src/ |
src/a1.c, src/a2.c |
src |
src/a |
a.c, b.c |
(no option) | (no option) |
If no prefix is found amongst the staged files, only the choices project and empty will be given.