Skip to content

Commit 2c22e10

Browse files
harry-hovgitster
authored andcommitted
ref-filter: 'contents:trailers' show error if : is missing
The 'contents' atom does not show any error if used with 'trailers' atom and colon is missing before trailers arguments. e.g %(contents:trailersonly) works, while it shouldn't. It is definitely not an expected behavior. Let's fix this bug. Mentored-by: Christian Couder <[email protected]> Mentored-by: Heba Waly <[email protected]> Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Hariom Verma <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a8e0f50 commit 2c22e10

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

ref-filter.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,11 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato
342342
atom->u.contents.option = C_SIG;
343343
else if (!strcmp(arg, "subject"))
344344
atom->u.contents.option = C_SUB;
345-
else if (skip_prefix(arg, "trailers", &arg)) {
346-
skip_prefix(arg, ":", &arg);
347-
if (trailers_atom_parser(format, atom, *arg ? arg : NULL, err))
345+
else if (!strcmp(arg, "trailers")) {
346+
if (trailers_atom_parser(format, atom, NULL, err))
347+
return -1;
348+
} else if (skip_prefix(arg, "trailers:", &arg)) {
349+
if (trailers_atom_parser(format, atom, arg, err))
348350
return -1;
349351
} else if (skip_prefix(arg, "lines=", &arg)) {
350352
atom->u.contents.option = C_LINES;

t/t6300-for-each-ref.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,14 @@ test_expect_success '%(trailers) rejects unknown trailers arguments' '
785785
test_i18ncmp expect actual
786786
'
787787

788+
test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
789+
cat >expect <<-EOF &&
790+
fatal: unrecognized %(contents) argument: trailersonly
791+
EOF
792+
test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
793+
test_i18ncmp expect actual
794+
'
795+
788796
test_expect_success 'basic atom: head contents:trailers' '
789797
git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
790798
sanitize_pgp <actual >actual.clean &&

0 commit comments

Comments
 (0)