Skip to content

Commit e626291

Browse files
committed
feat(commit): validate non-negative message_length_limit
1 parent 5e5778b commit e626291

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

commitizen/commands/commit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
CommitMessageLengthExceededError,
1919
CustomError,
2020
DryRunExit,
21+
InvalidCommandArgumentError,
2122
NoAnswersError,
2223
NoCommitBackupError,
2324
NotAGitProjectError,
@@ -60,6 +61,10 @@ def __init__(self, config: BaseConfig, arguments: CommitArgs) -> None:
6061
if message_length_limit is not None
6162
else config.settings["message_length_limit"]
6263
)
64+
if self.message_length_limit < 0:
65+
raise InvalidCommandArgumentError(
66+
"message_length_limit must be a non-negative integer"
67+
)
6368

6469
def _read_backup_message(self) -> str | None:
6570
# Check the commit backup file exists
@@ -93,7 +98,7 @@ def _get_message_by_prompt_commit_questions(self) -> str:
9398

9499
def _validate_subject_length(self, message: str) -> None:
95100
# By the contract, message_length_limit is set to 0 for no limit
96-
if self.message_length_limit <= 0:
101+
if self.message_length_limit == 0:
97102
return
98103

99104
subject = message.partition("\n")[0].strip()

0 commit comments

Comments
 (0)