From de760328c5766b7fc6b77d487039c7238bc1801b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nerijus=20Bend=C5=BEi=C5=ABnas?= Date: Tue, 21 Apr 2026 08:20:22 +0300 Subject: [PATCH] fix: body check must not count git trailers as body content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commits signed with -s (or any other footer) get a Signed-off-by trailer appended, which was being treated as body content, causing the body check to pass even when no real body was written. Trailers matching the git trailer format (Token: value) are now excluded from the body presence check. Signed-off-by: Nerijus Bendžiūnas --- src/git_commit_guard/__init__.py | 4 +++- tests/test_git_commit_guard.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/git_commit_guard/__init__.py b/src/git_commit_guard/__init__.py index 08d906a..4aa5c11 100644 --- a/src/git_commit_guard/__init__.py +++ b/src/git_commit_guard/__init__.py @@ -27,6 +27,7 @@ ) _NON_IMPERATIVE_SUFFIX_RE = re.compile(r"(?:ing|ed)$") +_TRAILER_RE = re.compile(r"^[\w-]+:\s+\S") SUBJECT_RE = re.compile( r"^(?P\w+)(?:\((?P[^)]+)\))?!?:\s+(?P.+)$", @@ -173,7 +174,8 @@ def check_body(lines, result): return if lines[1].strip(): result.error("missing blank line between subject and body") - if not any(ln.strip() for ln in lines[2:]): + 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") diff --git a/tests/test_git_commit_guard.py b/tests/test_git_commit_guard.py index 56c7dfd..1e6846d 100644 --- a/tests/test_git_commit_guard.py +++ b/tests/test_git_commit_guard.py @@ -200,6 +200,17 @@ def test_multiline_body(self): check_body(["fix: add thing", "", "line one", "line two"], r) assert r.ok + def test_trailer_only_is_not_body(self): + r = Result() + check_body(["fix: add thing", "", "Signed-off-by: Name "], r) + assert not r.ok + + def test_body_with_trailer_passes(self): + r = Result() + trailer = "Signed-off-by: Name " + check_body(["fix: add thing", "", "actual body", trailer], r) + assert r.ok + class TestCheckSignedOff: def test_valid(self):