interpret-trailers: load default config

The interpret-trailers program does not do the usual loading of config via git_default_config(), and thus does not respect many of the usual options. In particular, we will not load core.commentChar, even though the underlying trailer code uses its value. This can be seen in the accompanying test, where setting core.commentChar to anything besides "#" results in a failure to treat the comments correctly. Reported-by: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 18, 2019 at 23:37 UTC 29c83fc23f140c6d06e13916f40e6830616cfa29
2 files changed +47 -27
builtin/interpret-trailers.c
+3
@@ -10,6 +10,7 @@
10 #include "parse-options.h"
11 #include "string-list.h"
12 #include "trailer.h"
13 +#include "config.h"
14
15 static const char * const git_interpret_trailers_usage[] = {
16 N_("git interpret-trailers [--in-place] [--trim-empty] [(--trailer <token>[(=|:)<value>])...] [<file>...]"),
@@ -112,6 +113,8 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
113 OPT_END()
114 };
115
116 + git_config(git_default_config, NULL);
117 +
118 argc = parse_options(argc, argv, prefix, options,
119 git_interpret_trailers_usage, 0);
120
t/t7513-interpret-trailers.sh
+44 -27
@@ -538,33 +538,50 @@ test_expect_success 'with 2 files arguments' '
538 test_cmp expected actual
539 '
540
541 -test_expect_success 'with message that has comments' '
542 - cat basic_message >message_with_comments &&
543 - sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF &&
544 - # comment
545 -
546 - # other comment
547 - Cc: Z
548 - # yet another comment
549 - Reviewed-by: Johan
550 - Reviewed-by: Z
551 - # last comment
552 -
553 - EOF
554 - cat basic_patch >>message_with_comments &&
555 - cat basic_message >expected &&
556 - cat >>expected <<-\EOF &&
557 - # comment
558 -
559 - Reviewed-by: Johan
560 - Cc: Peff
561 - # last comment
562 -
563 - EOF
564 - cat basic_patch >>expected &&
565 - git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual &&
566 - test_cmp expected actual
567 -'
541 +# Cover multiple comment characters with the same test input.
542 +for char in "#" ";"
543 +do
544 + case "$char" in
545 + "#")
546 + # This is the default, so let's explicitly _not_
547 + # set any config to make sure it behaves as we expect.
548 + ;;
549 + *)
550 + config="-c core.commentChar=$char"
551 + ;;
552 + esac
553 +
554 + test_expect_success "with message that has comments ($char)" '
555 + cat basic_message >message_with_comments &&
556 + sed -e "s/ Z\$/ /" \
557 + -e "s/#/$char/g" >>message_with_comments <<-EOF &&
558 + # comment
559 +
560 + # other comment
561 + Cc: Z
562 + # yet another comment
563 + Reviewed-by: Johan
564 + Reviewed-by: Z
565 + # last comment
566 +
567 + EOF
568 + cat basic_patch >>message_with_comments &&
569 + cat basic_message >expected &&
570 + sed -e "s/#/$char/g" >>expected <<-\EOF &&
571 + # comment
572 +
573 + Reviewed-by: Johan
574 + Cc: Peff
575 + # last comment
576 +
577 + EOF
578 + cat basic_patch >>expected &&
579 + git $config interpret-trailers \
580 + --trim-empty --trailer "Cc: Peff" \
581 + message_with_comments >actual &&
582 + test_cmp expected actual
583 + '
584 +done
585
586 test_expect_success 'with message that has an old style conflict block' '
587 cat basic_message >message_with_comments &&