fix: preserve empty-body commits in release bump parsing

Do not strip the raw git-log record before splitting on the field
separator, because commits with empty bodies lose their delimiter and get
dropped entirely. Add a deterministic unit test for empty-body parsing.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
JerrettDavis 2026-04-16 23:46:06 -05:00
parent 8872b8be3b
commit 799e1c3a30
2 changed files with 16 additions and 7 deletions

View file

@ -249,10 +249,9 @@ def list_release_commits(root: Path, previous_tag: str) -> list[CommitInfo]:
commits: list[CommitInfo] = []
for raw_entry in result.stdout.split(RECORD_SEP):
entry = raw_entry.strip()
if not entry or FIELD_SEP not in entry:
if not raw_entry or FIELD_SEP not in raw_entry:
continue
subject, body = entry.split(FIELD_SEP, 1)
subject, body = raw_entry.split(FIELD_SEP, 1)
commits.append(CommitInfo(subject=subject.strip(), body=body.strip()))
return commits

View file

@ -4,6 +4,7 @@ import os
import subprocess
import sys
from pathlib import Path
from unittest.mock import Mock
import pytest
@ -137,12 +138,21 @@ def test_determine_bump_level_prefers_major_over_minor_and_patch() -> None:
assert determine_bump_level(commits) == "major"
def test_list_release_commits_returns_first_parent_range() -> None:
def test_list_release_commits_parses_empty_body_entries(
monkeypatch: pytest.MonkeyPatch,
) -> None:
run = Mock()
run.return_value = Mock(
stdout="feat: add capability\x1f\x1efix: patch bug\x1fbody text\x1e",
)
monkeypatch.setattr("headroom.release_version.subprocess.run", run)
commits = list_release_commits(ROOT, "")
assert commits
assert isinstance(commits[0], CommitInfo)
assert commits[0].subject
assert commits == [
CommitInfo(subject="feat: add capability", body=""),
CommitInfo(subject="fix: patch bug", body="body text"),
]
def test_release_version_script_runs_directly_without_importing_headroom_package(