sequencer: ignore "---" divider when parsing trailers

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>

Jeff King committed Aug 22, 2018 at 20:50 UTC ffce7f590fabee6f2314ffd891f1fd3629222839
2 files changed +18
sequencer.c
+2
@@ -229,6 +229,8 @@ static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
229 size_t i;
230 int found_sob = 0, found_sob_last = 0;
231
232 + opts.no_divider = 1;
233 +
234 trailer_info_get(&info, sb->buf, &opts);
235
236 if (info.trailer_start == info.trailer_end)
t/t7501-commit.sh
+16
@@ -517,6 +517,22 @@ Myfooter: x" &&
517 test_cmp expected actual
518 '
519
520 +test_expect_success 'signoff not confused by ---' '
521 + cat >expected <<-EOF &&
522 + subject
523 +
524 + body
525 + ---
526 + these dashes confuse the parser!
527 +
528 + Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
529 + EOF
530 + # should be a noop, since we already signed
531 + git commit --allow-empty --signoff -F expected &&
532 + git log -1 --pretty=format:%B >actual &&
533 + test_cmp expected actual
534 +'
535 +
536 test_expect_success 'multiple -m' '
537
538 >negative &&