[PATCH] commit: fix too generous RFC-2822 footer handling
- From
SZEDER Gábor <szeder@ira.uka.de>
- Date
- Nov 4, 2009, 03:09 UTC
- Message-ID
- <1257304146-15543-1-git-send-email-szeder@ira.uka.de>
- In-Reply-To
- <20091103165951.GA2241@neumann>
Since commit c1e01b0c (commit: More generous accepting of RFC-2822 footer lines, 2009-10-28) RFC-2822-looking lines at the end of the message are considered part of the footer and 'git commit -s -m' doesn't add a newline between that footer and the new S-O-B line. This new behaviour causes problems with subject-only commit messages which happens to look like an RFC-2822 header (e.g. 'git commit -s -m "subsystem: coolest feature ever"'). In such cases there won't be any newline between the subject and the S-O-B line, and the S-O-B line will show up at places where it should not (e.g. in the output of 'git shortlog').
With this patch the newline will be always added if a commit message has only a single line, even if it looks like an RFC-2822 header.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> ---
Maybe something like this? Be careful when reviewing, it's 4AM here...
builtin-commit.c | 8 ++++++++ t/t7501-commit.sh | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c index beddf01..4971156 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -429,6 +429,14 @@ static int ends_rfc2822_footer(struct strbuf *sb) hit = (buf[i] == '\n'); } + for (j = i-1; j > 0; j--) + if (buf[j] == '\n') { + hit = 1; + break; + } + if (!hit) /* one-line message */ + return 0; + while (i < len - 1 && buf[i] == '\n') i++; diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index d2de576..aaeedda 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -215,10 +215,10 @@ test_expect_success 'sign off (1)' ' echo 1 >positive && git add positive && - git commit -s -m "thank you" && + git commit -s -m "subsystem: coolest feature ever" && git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && ( - echo thank you + echo subsystem: coolest feature ever echo git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
-- 1.6.5.2.201.g0f47