Skip to content

Commit e177238

Browse files
committed
Merge branch 'hv/ref-filter-trailers-atom-parsing-fix'
The parser for "git for-each-ref --format=..." was too loose when parsing the "%(trailers...)" atom, and forgot that "trailers" and "trailers:<modifiers>" are the only two allowed forms, which has been corrected. * hv/ref-filter-trailers-atom-parsing-fix: ref-filter: 'contents:trailers' show error if `:` is missing t6300: unify %(trailers) and %(contents:trailers) tests
2 parents 63728e4 + 2c22e10 commit e177238

File tree

2 files changed

+23
-41
lines changed

2 files changed

+23
-41
lines changed

ref-filter.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,11 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato
345345
atom->u.contents.option = C_SIG;
346346
else if (!strcmp(arg, "subject"))
347347
atom->u.contents.option = C_SUB;
348-
else if (skip_prefix(arg, "trailers", &arg)) {
349-
skip_prefix(arg, ":", &arg);
350-
if (trailers_atom_parser(format, atom, *arg ? arg : NULL, err))
348+
else if (!strcmp(arg, "trailers")) {
349+
if (trailers_atom_parser(format, atom, NULL, err))
350+
return -1;
351+
} else if (skip_prefix(arg, "trailers:", &arg)) {
352+
if (trailers_atom_parser(format, atom, arg, err))
351353
return -1;
352354
} else if (skip_prefix(arg, "lines=", &arg)) {
353355
atom->u.contents.option = C_LINES;

t/t6300-for-each-ref.sh

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -776,61 +776,40 @@ test_expect_success 'set up trailers for next test' '
776776
'
777777

778778
test_expect_success '%(trailers:unfold) unfolds trailers' '
779-
git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
780779
{
781780
unfold <trailers
782781
echo
783782
} >expect &&
783+
git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
784+
test_cmp expect actual &&
785+
git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
784786
test_cmp expect actual
785787
'
786788

787789
test_expect_success '%(trailers:only) shows only "key: value" trailers' '
788-
git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
789790
{
790791
grep -v patch.description <trailers &&
791792
echo
792793
} >expect &&
794+
git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
795+
test_cmp expect actual &&
796+
git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
793797
test_cmp expect actual
794798
'
795799

796800
test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
797-
git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
798-
git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
799-
test_cmp actual reverse &&
800801
{
801802
grep -v patch.description <trailers | unfold &&
802803
echo
803804
} >expect &&
804-
test_cmp expect actual
805-
'
806-
807-
test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
808-
git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
809-
{
810-
unfold <trailers
811-
echo
812-
} >expect &&
813-
test_cmp expect actual
814-
'
815-
816-
test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' '
817-
git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
818-
{
819-
grep -v patch.description <trailers &&
820-
echo
821-
} >expect &&
822-
test_cmp expect actual
823-
'
824-
825-
test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
805+
git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
806+
test_cmp expect actual &&
807+
git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >actual &&
808+
test_cmp actual actual &&
826809
git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
827-
git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
828-
test_cmp actual reverse &&
829-
{
830-
grep -v patch.description <trailers | unfold &&
831-
echo
832-
} >expect &&
833-
test_cmp expect actual
810+
test_cmp expect actual &&
811+
git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >actual &&
812+
test_cmp actual actual
834813
'
835814

836815
test_expect_success '%(trailers) rejects unknown trailers arguments' '
@@ -839,15 +818,16 @@ test_expect_success '%(trailers) rejects unknown trailers arguments' '
839818
fatal: unknown %(trailers) argument: unsupported
840819
EOF
841820
test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
821+
test_i18ncmp expect actual &&
822+
test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
842823
test_i18ncmp expect actual
843824
'
844825

845-
test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
846-
# error message cannot be checked under i18n
826+
test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
847827
cat >expect <<-EOF &&
848-
fatal: unknown %(trailers) argument: unsupported
828+
fatal: unrecognized %(contents) argument: trailersonly
849829
EOF
850-
test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
830+
test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
851831
test_i18ncmp expect actual
852832
'
853833

0 commit comments

Comments
 (0)