Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c0ca27d
fix: workspace member with fixed version key
vemilano Jun 15, 2026
9277972
feat: inheriting workspace members with path, package and version att…
vemilano Jun 19, 2026
8600f81
ci(docspublish): make cli_interactive gif regeneration deterministic …
bearomorphism Jun 21, 2026
8bd1417
ci: make bump preview comment sticky (#2008)
bearomorphism Jun 21, 2026
2394ddb
ci(deps): bump codecov/codecov-action from 6 to 7 (#2013)
dependabot[bot] Jun 21, 2026
2b37564
docs(cli/screenshots): update CLI screenshots
github-actions[bot] Jun 21, 2026
de8a33d
ci(deps): bump peter-evans/find-comment from 3 to 4 (#2020)
dependabot[bot] Jun 22, 2026
5b49851
fix(providers/cargo): don't crash on workspace member with fixed version
bearomorphism May 25, 2026
8e6c95a
bump: version 4.16.3 → 4.16.4
commitizenbot[bot] Jun 22, 2026
1b133ac
docs(cli/screenshots): update CLI screenshots
github-actions[bot] Jun 22, 2026
ee4554d
build(deps): update argcomplete requirement from <3.7,>=1.12.1 to >=1…
dependabot[bot] Jul 1, 2026
6da74da
ci(deps): bump dawidd6/action-homebrew-bump-formula from 7 to 8 (#2022)
dependabot[bot] Jul 3, 2026
93a05d4
ci(deps): bump soupsieve from 2.8.3 to 2.8.4 (#2024)
dependabot[bot] Jul 10, 2026
427b1dc
fix: exclude star-history API from lychee link checker (#2029)
Copilot Jul 16, 2026
84480c3
bump: version 4.16.4 → 4.16.5
commitizenbot[bot] Jul 16, 2026
fa98440
docs(cli/screenshots): update CLI screenshots
github-actions[bot] Jul 16, 2026
fb8b249
ci(deps): bump actions/setup-go from 6 to 7 (#2032)
dependabot[bot] Jul 17, 2026
73dbe61
ci(deps): bump actions/labeler from 6 to 7 (#2034)
dependabot[bot] Jul 22, 2026
c985d57
ci(deps): bump gitpython from 3.1.50 to 3.1.52 (#2035)
dependabot[bot] Jul 22, 2026
5b291b4
ci(deps): bump pymdown-extensions from 10.21.3 to 11.0 (#2037)
dependabot[bot] Jul 28, 2026
617dd0f
ci(deps): bump gitpython from 3.1.52 to 3.1.54 (#2038)
dependabot[bot] Jul 28, 2026
e72bfd0
build(deps-dev): update uv-build requirement from <0.12,>=0.9.17 to >…
dependabot[bot] Jul 29, 2026
a4e410d
fix(bump): use correct type for calling changelog
woile Jul 24, 2026
0c0751a
fix(version): remove next from exclusive group
woile Jul 24, 2026
50f0dcb
fix: robuster agents
woile Jul 24, 2026
7586ec3
feat(cmd/version): add support for `--next USE_GIT_COMMITS`
woile Jul 24, 2026
b4fd8a3
bump: version 4.16.5 → 4.17.0
commitizenbot[bot] Jul 29, 2026
4c3bd92
docs(cli/screenshots): update CLI screenshots
github-actions[bot] Jul 29, 2026
5529ed4
docs: remove star history (#2043)
bearomorphism Jul 29, 2026
51ab90c
docs(tutorial): add Releasing with the SCM Version Provider
woile Jul 29, 2026
3490872
build(deps): bump gitpython from 3.1.54 to 3.1.57 (#2050)
dependabot[bot] Aug 5, 2026
44234a0
build(deps): bump gitpython from 3.1.57 to 3.1.58 (#2058)
dependabot[bot] Aug 10, 2026
85ac073
build(deps): bump pymdown-extensions from 11.0 to 11.0.1 (#2059)
dependabot[bot] Aug 10, 2026
b3b009f
fix(init): use prek when installing hooks if pre-commit is missing
DSeaStar Aug 14, 2026
6931803
fix(init): skip hook question when no installer is present
DSeaStar Aug 14, 2026
0c73c4e
test(init): cover installer missing at install time
DSeaStar Aug 14, 2026
b0f522f
bump: version 4.17.0 → 4.17.1
commitizenbot[bot] Aug 17, 2026
9351e01
docs(cli/screenshots): update CLI screenshots
github-actions[bot] Aug 17, 2026
4ce8164
feat(commit): add a tag(--body-length-limit) and a function for comma…
yjaw Aug 19, 2026
cc45233
bump: version 4.17.1 → 4.18.0
commitizenbot[bot] Aug 19, 2026
6e013c1
docs(cli/screenshots): update CLI screenshots
github-actions[bot] Aug 19, 2026
16117a8
docs(tutorial): fix setup-cz link
bearomorphism Aug 20, 2026
196973f
docs: restore Star History section in README (#2054)
Mubelotix Aug 20, 2026
0bc70e8
ci: restore changelog updates (#2074)
bearomorphism Aug 20, 2026
d5c90a1
ci(links): avoid duplicate broken link reports (#2073)
bearomorphism Aug 21, 2026
7efe21a
fix: workspace member with fixed version key
vemilano Jun 15, 2026
45945bf
feat: inheriting workspace members with path, package and version att…
vemilano Jun 19, 2026
b6da25f
refactor: uv run poe all
vemilano Aug 24, 2026
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
Prev Previous commit
Next Next commit
feat(commit): add a tag(--body-length-limit) and a function for comma…
…nd commit (#1849)
  • Loading branch information
yjaw authored and vemilano committed Aug 24, 2026
commit 4ce8164fd11852c7714b71814225cdf3aaa02a3d
5 changes: 5 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ def __call__(
"type": int,
"help": "Set the length limit of the commit message; 0 for no limit.",
},
{
"name": ["--body-length-limit"],
"type": int,
"help": "Set the length limit of the commit body. Commit message in body will be rewrapped to this length; 0 for no limit.",
},
{
"name": ["--"],
"action": "store_true",
Expand Down
26 changes: 26 additions & 0 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import shutil
import subprocess
import tempfile
import textwrap
from itertools import chain
from pathlib import Path
from typing import TYPE_CHECKING, TypedDict

Expand Down Expand Up @@ -36,6 +38,7 @@ class CommitArgs(TypedDict, total=False):
edit: bool
extra_cli_args: list[str]
message_length_limit: int
body_length_limit: int
no_retry: bool
signoff: bool
write_message_to_file: Path | None
Expand Down Expand Up @@ -82,6 +85,7 @@ def _get_message_by_prompt_commit_questions(self) -> str:

message = self.cz.message(answers)
self._validate_subject_length(message)
message = self._wrap_body(message)
return message

def _validate_subject_length(self, message: str) -> None:
Expand All @@ -100,6 +104,28 @@ def _validate_subject_length(self, message: str) -> None:
f"Length of commit message exceeds limit ({len(subject)}/{message_length_limit}), subject: '{subject}'"
)

def _wrap_body(self, message: str) -> str:
"""
Wrap the body of the commit message to the --body-length-limit length.
"""

body_length_limit = self.arguments.get(
"body_length_limit", self.config.settings["body_length_limit"]
)
# By the contract, body_length_limit is set to 0 for no limit
if not body_length_limit or body_length_limit <= 0:
return message

lines = message.split("\n")
if len(lines) < 3:
return message

# First line is subject, second is blank line, rest are body lines
wrapped_body_lines = chain.from_iterable(
textwrap.wrap(line, width=body_length_limit) for line in lines[2:]
)
return "\n".join(chain(lines[:2], wrapped_body_lines))

def manual_edit(self, message: str) -> str:
editor = git.get_core_editor()
if editor is None:
Expand Down
2 changes: 2 additions & 0 deletions commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Settings(TypedDict, total=False):
legacy_tag_formats: Sequence[str]
major_version_zero: bool
message_length_limit: int
body_length_limit: int
name: str
post_bump_hooks: list[str] | None
pre_bump_hooks: list[str] | None
Expand Down Expand Up @@ -115,6 +116,7 @@ class Settings(TypedDict, total=False):
"extras": {},
"breaking_change_exclamation_in_title": False,
"message_length_limit": 0, # 0 for no limit
"body_length_limit": 0, # 0 for no limit
}

MAJOR = "MAJOR"
Expand Down
67 changes: 67 additions & 0 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,70 @@ def test_commit_command_with_config_message_length_limit(
success_mock.reset_mock()
commands.Commit(config, {"message_length_limit": 0})()
success_mock.assert_called_once()


@pytest.mark.usefixtures("staging_is_clean")
@pytest.mark.parametrize(
("body", "body_length_limit"),
[
pytest.param(
"This is a very long line that exceeds 72 characters and should be automatically wrapped by the system to fit within the limit",
72,
id="wrapping",
),
pytest.param(
"Line1 is shorter than the limit but has newline\nLine2 is shorter than the limit but has newline\nLine3 is shorter than the limit but has newline",
100,
id="preserves_line_breaks",
),
pytest.param(
"This is a very long line that exceeds 72 characters and should NOT be wrapped when body_length_limit is set to 0",
0,
id="disabled",
),
pytest.param(
"",
72,
id="no_body",
),
],
)
def test_commit_command_body_length_limit(
body,
body_length_limit,
config,
success_mock: MockType,
commit_mock,
mocker: MockFixture,
file_regression,
):
"""Parameterized test for body_length_limit feature with file regression."""
mocker.patch(
"questionary.prompt",
return_value={
"prefix": "feat",
"subject": "add feature",
"scope": "",
"is_breaking_change": False,
"body": body,
"footer": "",
},
)

commands.Commit(config, {"body_length_limit": body_length_limit})()
success_mock.assert_called_once()
committed_message = commit_mock.call_args[0][0]
file_regression.check(committed_message, extension=".txt")

lines = committed_message.split("\n")
body_lines = lines[2:] # Skip subject and blank line

if body_length_limit > 0:
for line in body_lines:
assert len(line) <= body_length_limit, (
f"Line exceeds {body_length_limit} chars: '{line}' ({len(line)} chars)"
)
elif body_length_limit == 0:
assert len(body_lines) == 1, (
"Body should not be wrapped when body_length_limit is set to 0"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
feat: add feature

This is a very long line that exceeds 72 characters and should NOT be wrapped when body_length_limit is set to 0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: add feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
feat: add feature

Line1 is shorter than the limit but has newline
Line2 is shorter than the limit but has newline
Line3 is shorter than the limit but has newline
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
feat: add feature

This is a very long line that exceeds 72 characters and should be
automatically wrapped by the system to fit within the limit
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
usage: cz commit [-h] [--retry] [--no-retry] [--dry-run]
[--write-message-to-file FILE_PATH] [-s] [-a] [-e]
[-l MESSAGE_LENGTH_LIMIT] [--]
[-l MESSAGE_LENGTH_LIMIT]
[--body-length-limit BODY_LENGTH_LIMIT] [--]

Create new commit

Expand All @@ -22,4 +23,8 @@ options:
-l MESSAGE_LENGTH_LIMIT, --message-length-limit MESSAGE_LENGTH_LIMIT
Set the length limit of the commit message; 0 for no
limit.
--body-length-limit BODY_LENGTH_LIMIT
Set the length limit of the commit body. Commit
message in body will be rewrapped to this length; 0
for no limit.
-- Positional arguments separator (recommended).
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
usage: cz commit [-h] [--retry] [--no-retry] [--dry-run]
[--write-message-to-file FILE_PATH] [-s] [-a] [-e]
[-l MESSAGE_LENGTH_LIMIT] [--]
[-l MESSAGE_LENGTH_LIMIT]
[--body-length-limit BODY_LENGTH_LIMIT] [--]

Create new commit

Expand All @@ -22,4 +23,8 @@ options:
-l MESSAGE_LENGTH_LIMIT, --message-length-limit MESSAGE_LENGTH_LIMIT
Set the length limit of the commit message; 0 for no
limit.
--body-length-limit BODY_LENGTH_LIMIT
Set the length limit of the commit body. Commit
message in body will be rewrapped to this length; 0
for no limit.
-- Positional arguments separator (recommended).
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
usage: cz commit [-h] [--retry] [--no-retry] [--dry-run]
[--write-message-to-file FILE_PATH] [-s] [-a] [-e]
[-l MESSAGE_LENGTH_LIMIT] [--]
[-l MESSAGE_LENGTH_LIMIT]
[--body-length-limit BODY_LENGTH_LIMIT] [--]

Create new commit

Expand All @@ -22,4 +23,8 @@ options:
-l MESSAGE_LENGTH_LIMIT, --message-length-limit MESSAGE_LENGTH_LIMIT
Set the length limit of the commit message; 0 for no
limit.
--body-length-limit BODY_LENGTH_LIMIT
Set the length limit of the commit body. Commit
message in body will be rewrapped to this length; 0
for no limit.
-- Positional arguments separator (recommended).
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
usage: cz commit [-h] [--retry] [--no-retry] [--dry-run]
[--write-message-to-file FILE_PATH] [-s] [-a] [-e]
[-l MESSAGE_LENGTH_LIMIT] [--]
[-l MESSAGE_LENGTH_LIMIT]
[--body-length-limit BODY_LENGTH_LIMIT] [--]

Create new commit

Expand All @@ -22,4 +23,8 @@ options:
-l, --message-length-limit MESSAGE_LENGTH_LIMIT
Set the length limit of the commit message; 0 for no
limit.
--body-length-limit BODY_LENGTH_LIMIT
Set the length limit of the commit body. Commit
message in body will be rewrapped to this length; 0
for no limit.
-- Positional arguments separator (recommended).
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
usage: cz commit [-h] [--retry] [--no-retry] [--dry-run]
[--write-message-to-file FILE_PATH] [-s] [-a] [-e]
[-l MESSAGE_LENGTH_LIMIT] [--]
[-l MESSAGE_LENGTH_LIMIT]
[--body-length-limit BODY_LENGTH_LIMIT] [--]

Create new commit

Expand All @@ -22,4 +23,8 @@ options:
-l, --message-length-limit MESSAGE_LENGTH_LIMIT
Set the length limit of the commit message; 0 for no
limit.
--body-length-limit BODY_LENGTH_LIMIT
Set the length limit of the commit body. Commit
message in body will be rewrapped to this length; 0
for no limit.
-- Positional arguments separator (recommended).
2 changes: 2 additions & 0 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"extras": {},
"breaking_change_exclamation_in_title": False,
"message_length_limit": 0,
"body_length_limit": 0,
}

_new_settings: dict[str, Any] = {
Expand Down Expand Up @@ -153,6 +154,7 @@
"extras": {},
"breaking_change_exclamation_in_title": False,
"message_length_limit": 0,
"body_length_limit": 0,
}


Expand Down