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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h3>Checks</h3>
</tr>
<tr>
<td><code>body</code></td>
<td>Body is present after a blank line</td>
<td>Blank line separates subject from body, and body is non-empty</td>
</tr>
<tr>
<td><code>signed-off</code></td>
Expand Down
6 changes: 5 additions & 1 deletion src/git_commit_guard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_git_commit_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading