]> git.ipfire.org Git - thirdparty/git.git/commit
interpret-trailers: handle message without trailing newline
authorBrian Lyles <brianmlyles@gmail.com>
Fri, 6 Sep 2024 14:50:08 +0000 (09:50 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Sep 2024 16:21:44 +0000 (09:21 -0700)
commitc02414a99796487a2124e4dbb17c3a88c8606404
tree83af73811fe72f1a9b0f0df1a875319a5096a31b
parent39bf06adf96da25b87c9aa7d35a32ef3683eb4a4
interpret-trailers: handle message without trailing newline

When git-interpret-trailers is used to add a trailer to a message that
does not end in a trailing newline, the new trailer is added on the line
immediately following the message instead of as a trailer block
separated from the message by a blank line.

For example, if a message's text was exactly "The subject" with no
trailing newline present, `git interpret-trailers --trailer
my-trailer=true` will result in the following malformed commit message:

    The subject
    my-trailer: true

While it is generally expected that a commit message should end with a
newline character, git-interpret-trailers should not be returning an
invalid message in this case.

Use `strbuf_complete_line` to ensure that the message ends with a
newline character when reading the input.

Signed-off-by: Brian Lyles <brianmlyles@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/interpret-trailers.c
t/t7513-interpret-trailers.sh