commit: pass --no-divider to interpret-trailers

When git-commit sees any "--trailer" options, it passes the COMMIT_EDITMSG file through git-interpret-trailers. But it does so without passing --no-divider, which means that interpret-trailers will look for a "---" divider to signal the end of the commit message. That behavior doesn't make any sense in this context; we know we have a complete and solitary commit message, not something we have to further parse. And as a result, we'll do the wrong thing if the commit message contains a "---" marker (which otherwise is not syntactically significant), inserting any new trailers at the wrong spot. We can fix this by passing --no-divider. This is the exact situation for which it was added in 1688c9a489 (interpret-trailers: allow suppressing "---" divider, 2018-08-22). As noted in the message for that commit, it just adds the mechanism, and further patches were needed to trigger it from various callers. We did that back then in a few spots, like ffce7f590f (sequencer: ignore "---" divider when parsing trailers, 2018-08-22), but obviously missed this one. Reported-by: <eric.frederich@siemens.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 17, 2023 at 00:26 UTC be3d65434323f7f00a5abed6dbcfe690cde648b8
2 files changed +21 -1
builtin/commit.c
+2 -1
@@ -1043,7 +1043,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
1043 struct child_process run_trailer = CHILD_PROCESS_INIT;
1044
1045 strvec_pushl(&run_trailer.args, "interpret-trailers",
1046 - "--in-place", git_path_commit_editmsg(), NULL);
1046 + "--in-place", "--no-divider",
1047 + git_path_commit_editmsg(), NULL);
1048 strvec_pushv(&run_trailer.args, trailer_args.v);
1049 run_trailer.git_cmd = 1;
1050 if (run_command(&run_trailer))
t/t7502-commit-porcelain.sh
+19
@@ -466,6 +466,25 @@ test_expect_success 'commit --trailer with -c and command' '
466 test_cmp expected actual
467 '
468
469 +test_expect_success 'commit --trailer not confused by --- separator' '
470 + cat >msg <<-\EOF &&
471 + subject
472 +
473 + body with dashes
474 + ---
475 + in it
476 + EOF
477 + git commit --allow-empty --trailer="my-trailer: value" -F msg &&
478 + {
479 + cat msg &&
480 + echo &&
481 + echo "my-trailer: value"
482 + } >expected &&
483 + git cat-file commit HEAD >commit.msg &&
484 + sed -e "1,/^\$/d" commit.msg >actual &&
485 + test_cmp expected actual
486 +'
487 +
488 test_expect_success 'multiple -m' '
489
490 >negative &&