Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: draft of the --empty parameter #723

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ def __call__(
"help": "Add additional build-metadata to the version-number",
"default": None,
},
{
"name": ["--allow-no-commit"],
"default": False,
"help": "bump version without eligible commits",
"action": "store_true",
},
],
},
{
Expand Down
11 changes: 10 additions & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def __call__(self) -> None: # noqa: C901
manual_version = self.arguments["manual_version"]
build_metadata = self.arguments["build_metadata"]
increment_mode: str = self.arguments["increment_mode"]
allow_no_commit: bool | None = self.arguments["allow_no_commit"]

if manual_version:
if increment:
Expand Down Expand Up @@ -231,7 +232,11 @@ def __call__(self) -> None: # noqa: C901

# No commits, there is no need to create an empty tag.
# Unless we previously had a prerelease.
if not commits and not current_version.is_prerelease:
if (
not commits
and not current_version.is_prerelease
and not allow_no_commit
):
raise NoCommitsFoundError(
"[NO_COMMITS_FOUND]\n" "No new commits found."
)
Expand All @@ -247,6 +252,10 @@ def __call__(self) -> None: # noqa: C901
"To avoid this error, manually specify the type of increment with `--increment`"
)

# we create an empty PATCH increment for empty tag
if increment is None and allow_no_commit:
increment = "PATCH"

new_version = current_version.bump(
increment,
prerelease=prerelease,
Expand Down
12 changes: 12 additions & 0 deletions docs/commands/bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ You should normally not use this functionality, but if you decide to do, keep in
* Version `1.2.3+a`, and `1.2.3+b` are the same version! Tools should not use the string after `+` for version calculation. This is probably not a guarantee (example in helm) even tho it is in the spec.
* It might be problematic having the metadata in place when doing upgrades depending on what tool you use.

### `--allow-no-commit`

Allow the project version to be bumped even when there's no eligible version. This is most useful when used with `--increment {MAJOR,MINOR,PATCH}` or `[MANUL_VERSION]`

```sh
# bump a minor version even when there's only bug fixes, documentation changes or even no commits
cz bump --incremental MINOR --allow-no-commit

# bump version to 2.0.0 even when there's no breaking changes changes or even no commits
cz bump --allow-no-commit 2.0.0
```

## Avoid raising errors

Some situations from commitizen raise an exit code different than 0.
Expand Down
Loading
Loading