sequencer: ignore "---" divider when parsing trailers
authorJeff King <peff@peff.net>
Thu, 23 Aug 2018 00:50:37 +0000 (20:50 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 23 Aug 2018 17:08:51 +0000 (10:08 -0700)
When the sequencer code appends a signoff or cherry-pick
origin, it uses the default trailer-parsing options, which
treat "---" as the end of the commit message. As a result,
it may be fooled by a commit message that contains that
string and fail to find the existing trailer block. Even
more confusing, the actual append code does not know about
"---", and always appends to the end of the string. This can
lead to bizarre results. E.g., appending a signoff to a
commit message like this:

subject

body
---
these dashes confuse the parser!

Signed-off-by: A
results in output with a final block like:

Signed-off-by: A
Signed-off-by: A
The parser thinks the final line of the message is "body",
and ignores everything else, claiming there are no trailers.
So we output an extra newline separator (wrong) and add a
duplicate signoff (also wrong).

Since we know we are feeding a pure commit message, we can
simply tell the parser to ignore the "---" divider.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sequencer.c
t/t7501-commit.sh
index 849208eb40c3eb122d23e61a9d48eba4178f8e03..51ef7245b14cf1625385be872815fda11e2dc191 100644 (file)
@@ -229,6 +229,8 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
        size_t i;
        int found_sob = 0, found_sob_last = 0;
 
+       opts.no_divider = 1;
+
        trailer_info_get(&info, sb->buf, &opts);
 
        if (info.trailer_start == info.trailer_end)
index 9dbbd01fc07724e378a864e3fe735269665a9bc3..025d65b51770b06c2ce05a540bb862783ce261af 100755 (executable)
@@ -517,6 +517,22 @@ Myfooter: x" &&
        test_cmp expected actual
 '
 
+test_expect_success 'signoff not confused by ---' '
+       cat >expected <<-EOF &&
+               subject
+
+               body
+               ---
+               these dashes confuse the parser!
+
+               Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
+       EOF
+       # should be a noop, since we already signed
+       git commit --allow-empty --signoff -F expected &&
+       git log -1 --pretty=format:%B >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'multiple -m' '
 
        >negative &&