Skip to content

fix(gix-object): detect trailers when they are the sole body content#2514

Merged
Sebastian Thiel (Byron) merged 4 commits intoGitoxideLabs:mainfrom
mtsgrd:fix/body-ref-trailer-as-sole-body-content
Apr 14, 2026
Merged

fix(gix-object): detect trailers when they are the sole body content#2514
Sebastian Thiel (Byron) merged 4 commits intoGitoxideLabs:mainfrom
mtsgrd:fix/body-ref-trailer-as-sole-body-content

Conversation

@mtsgrd
Copy link
Copy Markdown
Contributor

Problem

BodyRef::from_bytes searched for \n\n within the body to find the trailer block. But MessageRef::from_bytes already consumed the first \n\n when splitting the title from the body — so for a message like:

Fix the thing

Signed-off-by: Alice <alice@example.com>

the body bytes arriving at BodyRef::from_bytes are just "Signed-off-by: Alice <alice@example.com>" with no inner \n\n. The result was zero trailers, diverging from git interpret-trailers --parse:

$ printf 'Fix the thing\n\nSigned-off-by: Alice <alice@example.com>\n' | git interpret-trailers --parse
Signed-off-by: Alice <alice@example.com>

This is the common case in practice: a subject line followed directly by trailers with no other body text (Gerrit Change-Id, GitHub Co-authored-by, etc.).

Fix

When no \n\n is found within the body and the first non-empty line parses as a valid Token: value trailer, treat the entire body as the trailer block (with an empty body_without_trailer). Non-trailer body text followed by a trailer on the same paragraph without a blank-line separator is correctly left unchanged — a blank line is still required to delimit the trailer block from preceding prose.

Tests added

  • trailer_as_sole_body_content — single trailer, no preceding body text
  • multiple_trailers_as_sole_body_content — multiple trailers, no preceding body text
  • body_text_then_trailer_without_blank_line_is_not_a_trailer — guard: body text + trailer in same paragraph (no \n\n) is not a trailer block
  • trailer_as_sole_body_content_via_message_ref — end-to-end through the public MessageRef API

🤖 Generated with Claude Code

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad6948e289

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread gix-object/src/commit/message/body.rs Outdated
@mtsgrd Mattias Granlund (mtsgrd) force-pushed the fix/body-ref-trailer-as-sole-body-content branch from ad6948e to da52490 Compare April 13, 2026 23:24
`BodyRef::from_bytes` searched for `\n\n` *within the body* to find the
trailer block separator. However, `MessageRef::from_bytes` already
consumed the first `\n\n` when splitting the title from the body — so
for a message like:

    Fix the thing

    Signed-off-by: Alice <alice@example.com>

the body bytes arriving at `BodyRef::from_bytes` are just
`"Signed-off-by: Alice <alice@example.com>"` with no further `\n\n`,
causing zero trailers to be returned and diverging from the behaviour
of `git interpret-trailers --parse`.

Fix: when no `\n\n` is found within the body *and* the first
non-empty line parses as a valid `Token: value` trailer, treat the
entire body as the trailer block (with an empty `body_without_trailer`).
Non-trailer body text followed by a trailer on the same paragraph
(without a blank-line separator) is correctly left unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mtsgrd Mattias Granlund (mtsgrd) force-pushed the fix/body-ref-trailer-as-sole-body-content branch from da52490 to c7908d1 Compare April 13, 2026 23:45
- minor edits while lookinag through the code
Codex (codex) and others added 2 commits April 14, 2026 13:13
Also add more tests for more complete compliance with `git interpret-trailers`.
Note that the new behaviour is more conforming, which means that trailer
blocks must be parseable in full to be be recognised.

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
@Byron Sebastian Thiel (Byron) force-pushed the fix/body-ref-trailer-as-sole-body-content branch from 3222835 to 58f7595 Compare April 14, 2026 05:23
@Byron
Copy link
Copy Markdown
Member

Thanks so much to get this started!

I ended up having Codex implement a compliant version of this, along with support for continuations/multi-line (those are folded into a single line).

@Byron Sebastian Thiel (Byron) merged commit c261237 into GitoxideLabs:main Apr 14, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants