pretty, ref-filter: format %(trailers) with no_divider option
In both of these cases we know that we are feeding the trailer-parsing code a pure commit message. We should tell it so, which avoids false positives for a commit message that contains a "---" line. 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
e5fba5d55886eaf48aeeb158dd4d30c2fc0294c9
4 files changed
+51
pretty.c
+3
@@ -1304,6 +1304,9 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1304
1305
if (skip_prefix(placeholder, "(trailers", &arg)) {
1306
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
1307
+
1308
+ opts.no_divider = 1;
1309
+
1310
if (*arg == ':') {
1311
arg++;
1312
for (;;) {
ref-filter.c
+2
@@ -223,6 +223,8 @@ static int trailers_atom_parser(const struct ref_format *format, struct used_ato
223
struct string_list params = STRING_LIST_INIT_DUP;
224
int i;
225
226
+ atom->u.contents.trailer_opts.no_divider = 1;
227
+
228
if (arg) {
229
string_list_split(¶ms, arg, ',', -1);
230
for (i = 0; i < params.nr; i++) {
t/t4205-log-pretty-formats.sh
+23
@@ -598,4 +598,27 @@ test_expect_success ':only and :unfold work together' '
598
test_cmp expect actual
599
'
600
601
+test_expect_success 'trailer parsing not fooled by --- line' '
602
+ git commit --allow-empty -F - <<-\EOF &&
603
+ this is the subject
604
+
605
+ This is the body. The message has a "---" line which would confuse a
606
+ message+patch parser. But here we know we have only a commit message,
607
+ so we get it right.
608
+
609
+ trailer: wrong
610
+ ---
611
+ This is more body.
612
+
613
+ trailer: right
614
+ EOF
615
+
616
+ {
617
+ echo "trailer: right" &&
618
+ echo
619
+ } >expect &&
620
+ git log --no-walk --format="%(trailers)" >actual &&
621
+ test_cmp expect actual
622
+'
623
+
624
test_done
t/t6300-for-each-ref.sh
+23
@@ -715,6 +715,29 @@ test_expect_success 'basic atom: head contents:trailers' '
715
test_cmp expect actual.clean
716
'
717
718
+test_expect_success 'trailer parsing not fooled by --- line' '
719
+ git commit --allow-empty -F - <<-\EOF &&
720
+ this is the subject
721
+
722
+ This is the body. The message has a "---" line which would confuse a
723
+ message+patch parser. But here we know we have only a commit message,
724
+ so we get it right.
725
+
726
+ trailer: wrong
727
+ ---
728
+ This is more body.
729
+
730
+ trailer: right
731
+ EOF
732
+
733
+ {
734
+ echo "trailer: right" &&
735
+ echo
736
+ } >expect &&
737
+ git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
738
+ test_cmp expect actual
739
+'
740
+
741
test_expect_success 'Add symbolic ref for the following tests' '
742
git symbolic-ref refs/heads/sym refs/heads/master
743
'