Skip to content

Commit 29c83fc

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d0ac38 commit 29c83fc

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed

builtin/interpret-trailers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "parse-options.h"
1111
#include "string-list.h"
1212
#include "trailer.h"
13+
#include "config.h"
1314

1415
static const char * const git_interpret_trailers_usage[] = {
1516
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)
112113
OPT_END()
113114
};
114115

116+
git_config(git_default_config, NULL);
117+
115118
argc = parse_options(argc, argv, prefix, options,
116119
git_interpret_trailers_usage, 0);
117120

t/t7513-interpret-trailers.sh

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -538,33 +538,50 @@ test_expect_success 'with 2 files arguments' '
538538
test_cmp expected actual
539539
'
540540

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
568585

569586
test_expect_success 'with message that has an old style conflict block' '
570587
cat basic_message >message_with_comments &&

0 commit comments

Comments
 (0)