Skip to content

Commit 3dc5471

Browse files
committed
fix(commit): fix some code and test according to suggestions
1 parent f514bdd commit 3dc5471

8 files changed

+14
-13
lines changed

commitizen/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ def __call__(
167167
{
168168
"name": ["--body-length-limit"],
169169
"type": int,
170-
"default": 0,
171170
"help": "Set the length limit of the commit body. Commit message in body will be rewrapped to this length; 0 for no limit.",
172171
},
173172
{

commitizen/commands/commit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def _validate_subject_length(self, message: str) -> None:
108108

109109
def _wrap_body(self, message: str) -> str:
110110
"""
111-
Wrap the body of the commit message to the specified length.
111+
Wrap the body of the commit message to the --body-length-limit length.
112112
"""
113113

114114
body_length_limit = self.arguments.get(
@@ -122,11 +122,11 @@ def _wrap_body(self, message: str) -> str:
122122
if len(lines) < 3:
123123
return message
124124

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

131131
def manual_edit(self, message: str) -> str:
132132
editor = git.get_core_editor()

tests/commands/test_commit_command.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ def test_commit_command_with_config_message_length_limit(
377377
id="wrapping",
378378
),
379379
pytest.param(
380-
"Line1 that is very long and exceeds the limit\nLine2 that is very long and exceeds the limit\nLine3 that is very long and exceeds the limit",
381-
72,
380+
"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",
381+
100,
382382
id="preserves_line_breaks",
383383
),
384384
pytest.param(
@@ -400,6 +400,7 @@ def test_commit_command_body_length_limit(
400400
success_mock: MockType,
401401
commit_mock,
402402
mocker: MockFixture,
403+
file_regression,
403404
):
404405
"""Parameterized test for body_length_limit feature with file regression."""
405406
mocker.patch(
@@ -417,6 +418,7 @@ def test_commit_command_body_length_limit(
417418
commands.Commit(config, {"body_length_limit": body_length_limit})()
418419
success_mock.assert_called_once()
419420
committed_message = commit_mock.call_args[0][0]
421+
file_regression.check(committed_message, extension=".txt")
420422

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

tests/commands/test_commit_command/test_commit_command_body_length_limit_disabled.txt renamed to tests/commands/test_commit_command/test_commit_command_body_length_limit_disabled_.txt

File renamed without changes.

tests/commands/test_commit_command/test_commit_command_body_length_limit_no_body.txt renamed to tests/commands/test_commit_command/test_commit_command_body_length_limit_no_body_.txt

File renamed without changes.

tests/commands/test_commit_command/test_commit_command_body_length_limit_preserves_line_breaks.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
feat: add feature
2+
3+
Line1 is shorter than the limit but has newline
4+
Line2 is shorter than the limit but has newline
5+
Line3 is shorter than the limit but has newline

tests/commands/test_commit_command/test_commit_command_body_length_limit_wrapping.txt renamed to tests/commands/test_commit_command/test_commit_command_body_length_limit_wrapping_.txt

File renamed without changes.

0 commit comments

Comments
 (0)