summaryrefslogtreecommitdiff
path: root/t/t6300-for-each-ref.sh
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2017-10-02 05:25:24 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-10-02 12:15:30 (GMT)
commit7a5edbdb748f58c0ff3f2a459596ad6ddfda0640 (patch)
tree644b598f8b71e6e0c452876b23d8e8cf6a4b6ac4 /t/t6300-for-each-ref.sh
parent67a20a0010224255bbd5bb9fa4f95595c3e1ba7c (diff)
downloadgit-7a5edbdb748f58c0ff3f2a459596ad6ddfda0640.zip
git-7a5edbdb748f58c0ff3f2a459596ad6ddfda0640.tar.gz
git-7a5edbdb748f58c0ff3f2a459596ad6ddfda0640.tar.bz2
ref-filter.c: parse trailers arguments with %(contents) atom
The %(contents) atom takes a contents "field" as its argument. Since "trailers" is one of those fields, extend contents_atom_parser to parse "trailers"'s arguments when used through "%(contents)", like: %(contents:trailers:unfold,only) A caveat: trailers_atom_parser expects NULL when no arguments are given (see: `parse_ref_filter_atom`). This is because string_list_split (given a maxsplit of -1) returns a 1-ary string_list* containing the given string if the delimiter could not be found using `strchr`. To simulate this behavior without teaching trailers_atom_parser to accept strings with length zero, conditionally pass NULL to trailers_atom_parser if the arguments portion of the argument to %(contents) is empty. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t6300-for-each-ref.sh')
-rwxr-xr-xt/t6300-for-each-ref.sh38
1 files changed, 38 insertions, 0 deletions
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 64a0d9e..3bdfa02 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -655,6 +655,35 @@ test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
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' '
+ 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_expect_success '%(trailers) rejects unknown trailers arguments' '
# error message cannot be checked under i18n
cat >expect <<-EOF &&
@@ -664,6 +693,15 @@ test_expect_success '%(trailers) rejects unknown trailers arguments' '
test_i18ncmp expect actual
'
+test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
+ # error message cannot be checked under i18n
+ cat >expect <<-EOF &&
+ fatal: unknown %(trailers) argument: unsupported
+ EOF
+ test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
+ test_i18ncmp expect actual
+'
+
test_expect_success 'basic atom: head contents:trailers' '
git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
sanitize_pgp <actual >actual.clean &&