Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/git_commit_guard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<type>\w+)(?:\((?P<scope>[^)]+)\))?!?:\s+(?P<desc>.+)$",
Expand Down Expand Up @@ -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")


Expand Down
11 changes: 11 additions & 0 deletions tests/test_git_commit_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name@example.com>"], r)
assert not r.ok

def test_body_with_trailer_passes(self):
r = Result()
trailer = "Signed-off-by: Name <name@example.com>"
check_body(["fix: add thing", "", "actual body", trailer], r)
assert r.ok


class TestCheckSignedOff:
def test_valid(self):
Expand Down
Loading