From 3490c2603afc5371e894526b0963844fb9eabae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nerijus=20Bend=C5=BEi=C5=ABnas?= Date: Tue, 28 Apr 2026 06:05:46 +0300 Subject: [PATCH] fix!: detect missing blank line separator in body check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A two-line message (subject + body, no blank line) was hitting the len < 3 guard and reporting "missing body" instead of "missing blank line between subject and body". The body was present; only the separator was wrong. BREAKING CHANGE: the body check now emits "missing blank line between subject and body" instead of "missing body" when a non-blank second line immediately follows the subject. Scripts or CI steps that match on the exact error message string will need updating. Signed-off-by: Nerijus Bendžiūnas --- README.md | 2 +- docs/index.html | 2 +- src/git_commit_guard/__init__.py | 6 +++++- tests/test_git_commit_guard.py | 6 ++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ae2e8c1..a0365be 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Available checks: * `subject` - Format matches `type(scope): description`, valid type, lowercase start, no trailing period, max 72 chars * `imperative` - First word is an imperative verb (for example `add` not `added`) -* `body` - Body is present after a blank line +* `body` - Blank line separates subject from body, and body is non-empty * `signed-off` - `Signed-off-by:` trailer exists * `signature` - Verify GPG or SSH signature diff --git a/docs/index.html b/docs/index.html index 6403f1c..9ae46fd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -369,7 +369,7 @@

Checks

body - Body is present after a blank line + Blank line separates subject from body, and body is non-empty signed-off diff --git a/src/git_commit_guard/__init__.py b/src/git_commit_guard/__init__.py index 7d4474e..171e4f2 100644 --- a/src/git_commit_guard/__init__.py +++ b/src/git_commit_guard/__init__.py @@ -220,11 +220,15 @@ def check_imperative(desc, result): def check_body(lines, result): - if len(lines) < 3: # noqa: PLR2004 + if len(lines) == 1: result.error("missing body", check=Check.BODY) return if lines[1].strip(): result.error("missing blank line between subject and body", check=Check.BODY) + return + if len(lines) == 2: # noqa: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + result.error("missing body", check=Check.BODY) + return body_lines = [ln for ln in lines[2:] if not _TRAILER_RE.match(ln)] if not any(ln.strip() for ln in body_lines): result.error("missing body", check=Check.BODY) diff --git a/tests/test_git_commit_guard.py b/tests/test_git_commit_guard.py index 45c0c17..7044b59 100644 --- a/tests/test_git_commit_guard.py +++ b/tests/test_git_commit_guard.py @@ -237,6 +237,12 @@ def test_missing_blank_line(self): check_body(["fix: add thing", "body text", "more"], r) assert not r.ok + def test_missing_blank_line_two_lines(self): + r = Result() + check_body(["fix: add thing", "body text"], r) + assert not r.ok + assert any("blank line" in msg for _, _, msg in r.errors) + def test_blank_body_content(self): r = Result() check_body(["fix: add thing", "", " "], r)