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
This commit is contained in:
Junio C Hamano 2020-08-31 15:49:47 -07:00
Родитель 63728e4814 2c22e102f8
Коммит e17723842b
2 изменённых файлов: 26 добавлений и 44 удалений

Просмотреть файл

@ -345,9 +345,11 @@ static int contents_atom_parser(const struct ref_format *format, struct used_ato
atom->u.contents.option = C_SIG;
else if (!strcmp(arg, "subject"))
atom->u.contents.option = C_SUB;
else if (skip_prefix(arg, "trailers", &arg)) {
skip_prefix(arg, ":", &arg);
if (trailers_atom_parser(format, atom, *arg ? arg : NULL, err))
else if (!strcmp(arg, "trailers")) {
if (trailers_atom_parser(format, atom, NULL, err))
return -1;
} else if (skip_prefix(arg, "trailers:", &arg)) {
if (trailers_atom_parser(format, atom, arg, err))
return -1;
} else if (skip_prefix(arg, "lines=", &arg)) {
atom->u.contents.option = C_LINES;

Просмотреть файл

@ -776,61 +776,40 @@ test_expect_success 'set up trailers for next test' '
'
test_expect_success '%(trailers:unfold) unfolds trailers' '
git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
{
unfold <trailers
echo
} >expect &&
git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
test_cmp expect actual &&
git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
test_cmp expect actual
'
test_expect_success '%(trailers:only) shows only "key: value" trailers' '
git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
{
grep -v patch.description <trailers &&
echo
} >expect &&
git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
test_cmp expect actual &&
git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
test_cmp expect actual
'
test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
{
grep -v patch.description <trailers | unfold &&
echo
} >expect &&
git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
test_cmp actual reverse &&
{
grep -v patch.description <trailers | unfold &&
echo
} >expect &&
test_cmp expect actual
'
test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
{
unfold <trailers
echo
} >expect &&
test_cmp expect actual
'
test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' '
git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
{
grep -v patch.description <trailers &&
echo
} >expect &&
test_cmp expect actual
'
test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
test_cmp expect actual &&
git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >actual &&
test_cmp actual actual &&
git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
test_cmp actual reverse &&
{
grep -v patch.description <trailers | unfold &&
echo
} >expect &&
test_cmp expect actual
test_cmp expect actual &&
git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >actual &&
test_cmp actual actual
'
test_expect_success '%(trailers) rejects unknown trailers arguments' '
@ -839,15 +818,16 @@ test_expect_success '%(trailers) rejects unknown trailers arguments' '
fatal: unknown %(trailers) argument: unsupported
EOF
test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
test_i18ncmp expect actual &&
test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
test_i18ncmp expect actual
'
test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
# error message cannot be checked under i18n
test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
cat >expect <<-EOF &&
fatal: unknown %(trailers) argument: unsupported
fatal: unrecognized %(contents) argument: trailersonly
EOF
test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
test_i18ncmp expect actual
'