Skip to content

Commit a24a41e

Browse files
drafnelgitster
authored andcommitted
git-commit: only append a newline to -m mesg if necessary
Currently, git will append two newlines to every message supplied via the -m switch. The purpose of this is to allow -m to be supplied multiple times and have each supplied string become a paragraph in the resulting commit message. Normally, this does not cause a problem since any trailing newlines will be removed by the cleanup operation. If cleanup=verbatim for example, then the trailing newlines will not be removed and will survive into the resulting commit message. Instead, let's ensure that the string supplied to -m is newline terminated, but only append a second newline when appending additional messages. Fixes the test in t7502. Signed-off-by: Brandon Casey <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b012c8 commit a24a41e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

builtin/commit.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
124124
if (unset)
125125
strbuf_setlen(buf, 0);
126126
else {
127+
if (buf->len)
128+
strbuf_addch(buf, '\n');
127129
strbuf_addstr(buf, arg);
128-
strbuf_addstr(buf, "\n\n");
130+
strbuf_complete_line(buf);
129131
}
130132
return 0;
131133
}

t/t7502-commit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ test_expect_success 'cleanup commit messages (verbatim option,-F)' '
204204
205205
'
206206

207-
test_expect_failure 'cleanup commit messages (verbatim option,-m)' '
207+
test_expect_success 'cleanup commit messages (verbatim option,-m)' '
208208
209209
echo >>negative &&
210210
git commit --cleanup=verbatim -m "$mesg_with_comment_and_newlines" -a &&

0 commit comments

Comments
 (0)