Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion commitizen/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def normalize_tag(
version = self.scheme(version) if isinstance(version, str) else version
tag_format = tag_format or self.tag_format

major, minor, patch = version.release
major, minor, patch = (list(version.release) + [0, 0, 0])[:3]
prerelease = version.prerelease or ""

t = Template(tag_format)
Expand Down
22 changes: 11 additions & 11 deletions docs/config/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,24 @@ version_files = [

```json title="setup.json"
{
"name": "magictool",
"version": "1.2.3",
"dependencies": {
"lodash": "1.2.3"
}
"name": "magictool",
"version": "1.2.3",
"dependencies": {
"lodash": "1.2.3"
}
}
```

After running `cz bump 2.0.0`, its content will be updated to:

```diff title="setup.json"
{
"name": "magictool",
- "version": "1.2.3",
+ "version": "2.0.0",
"dependencies": {
"lodash": "1.2.3"
}
"name": "magictool",
- "version": "1.2.3",
+ "version": "2.0.0",
"dependencies": {
"lodash": "1.2.3"
}
}
```

Expand Down
8 changes: 8 additions & 0 deletions docs/config/version_provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Commitizen includes several built-in version providers for common package manage
The default version provider stores and retrieves the version from your Commitizen configuration file (e.g., `pyproject.toml`, `.cz.toml`, etc.).

**Use when:**

- You want to keep version management separate from your package manager
- Your project doesn't use a standard package manager
- You need maximum flexibility in version management
Expand All @@ -35,6 +36,7 @@ version = "0.1.0" # Required when using this provider
Fetches the version from Git tags using `git describe`. This provider **only reads** version information and never writes it back to files. It's designed to work with tools like `setuptools-scm` or other package manager `*-scm` plugins that derive version numbers from Git history.

**Use when:**

- You're using `setuptools-scm` or similar tools
- You want version numbers derived from Git tags
- You don't want Commitizen to modify any files for version management
Expand All @@ -54,6 +56,7 @@ version_provider = "scm"
Manages version in `pyproject.toml` under the `project.version` field, following [PEP 621](https://peps.python.org/pep-0621/) standards.

**Use when:**

- You're using a modern Python project with PEP 621-compliant `pyproject.toml`
- You want version management integrated with your Python project metadata

Expand All @@ -75,6 +78,7 @@ version = "0.1.0" # Managed by Commitizen
Manages version in `pyproject.toml` under the `tool.poetry.version` field, which is used by the [Poetry](https://python-poetry.org/) package manager. This approach is recommended only for users running Poetry versions earlier than 2.0 or relying on Poetry-specific features. For most users on Poetry 2.0 or later, it is recommended to use `pep621` instead. [Read More](https://python-poetry.org/docs/main/managing-dependencies/)

**Use when:**

- You're using Poetry < 2.0 as your Python package manager
- You're using Poetry >= 2.0 as your Python package manager, but don't need poetry-specific features
- You want Commitizen to manage the version that Poetry uses
Expand All @@ -101,6 +105,7 @@ Manages version in both `pyproject.toml` (`project.version`) and `uv.lock` (`pac
Even though uv follows PEP 621 format, `pep621` does not manage the version in `uv.lock`. `uv` is still suggested for uv users.

**Use when:**

- You're using `uv` as your Python package manager
- You want version synchronization between `pyproject.toml` and `uv.lock`

Expand All @@ -115,6 +120,7 @@ version_provider = "uv"
Manages version in both `Cargo.toml` (`package.version`) and `Cargo.lock` (`package.version` for the matching package name). This ensures consistency between your Rust project's manifest and lock file.

**Use when:**

- You're working with a Rust project using Cargo
- You want Commitizen to manage Rust package versions

Expand All @@ -136,6 +142,7 @@ version = "0.1.0" # Managed by Commitizen
Manages version in `package.json` and optionally synchronizes with `package-lock.json` and `npm-shrinkwrap.json` if they exist.

**Use when:**

- You're working with a Node.js/JavaScript project
- You want Commitizen to manage npm package versions

Expand All @@ -158,6 +165,7 @@ version_provider = "npm"
Manages version in `composer.json` under the `version` field, used by PHP's Composer package manager.

**Use when:**

- You're working with a PHP project using Composer
- You want Commitizen to manage Composer package versions

Expand Down
33 changes: 33 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ def test_bump_invalid_manual_version_raises_exception(mocker, manual_version):
"0.1.1",
"0.2.0",
"1.0.0",
"1.2",
"1",
],
)
def test_bump_manual_version(mocker, manual_version):
Expand Down Expand Up @@ -966,6 +968,37 @@ def test_bump_manual_version_disallows_major_version_zero(mocker):
assert expected_error_message in str(excinfo.value)


@pytest.mark.parametrize(
"initial_version, expected_version_after_bump",
[
("1", "1.1.0"),
("1.2", "1.3.0"),
],
)
def test_bump_version_with_less_components_in_config(
tmp_commitizen_project_initial,
mocker: MockFixture,
initial_version,
expected_version_after_bump,
):
tmp_commitizen_project = tmp_commitizen_project_initial(version=initial_version)

testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)

cli.main()

tag_exists = git.tag_exist(expected_version_after_bump)
assert tag_exists is True

for version_file in [
tmp_commitizen_project.join("__version__.py"),
tmp_commitizen_project.join("pyproject.toml"),
]:
with open(version_file) as f:
assert expected_version_after_bump in f.read()


@pytest.mark.parametrize("commit_msg", ("feat: new file", "feat(user): new file"))
def test_bump_with_pre_bump_hooks(
commit_msg, mocker: MockFixture, tmp_commitizen_project
Expand Down