Skip to content

Commit 1ba8a7c

Browse files
committed
Merge branch 'jk/trailers-use-config' into next
"git interpret-trailers" always treated '#' as the comment character, regardless of core.commentChar setting, which has been corrected. * jk/trailers-use-config: interpret-trailers: load default config
2 parents ba3fcc1 + 29c83fc commit 1ba8a7c

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)