ref-filter: add support for %(contents:lines=X)
In 'tag.c' we can print N lines from the annotation of the tag using the '-n<num>' option. Copy code from 'tag.c' to 'ref-filter' and modify it to support appending of N lines from the annotation of tags to the given strbuf. Implement %(contents:lines=X) where X lines of the given object are obtained. While we're at it, remove unused "contents:<suboption>" atoms from the `valid_atom` array. Add documentation and test for the same. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5b4f28510f
commit
1bb38e5a6a
@ -167,4 +167,56 @@ test_expect_success 'nested alignment with quote formatting' "
|
||||
test_cmp expect actual
|
||||
"
|
||||
|
||||
test_expect_success 'check `%(contents:lines=1)`' '
|
||||
cat >expect <<-\EOF &&
|
||||
master |three
|
||||
side |four
|
||||
odd/spot |three
|
||||
double-tag |Annonated doubly
|
||||
four |four
|
||||
one |one
|
||||
signed-tag |A signed tag message
|
||||
three |three
|
||||
two |two
|
||||
EOF
|
||||
git for-each-ref --format="%(refname:short) |%(contents:lines=1)" >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'check `%(contents:lines=0)`' '
|
||||
cat >expect <<-\EOF &&
|
||||
master |
|
||||
side |
|
||||
odd/spot |
|
||||
double-tag |
|
||||
four |
|
||||
one |
|
||||
signed-tag |
|
||||
three |
|
||||
two |
|
||||
EOF
|
||||
git for-each-ref --format="%(refname:short) |%(contents:lines=0)" >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'check `%(contents:lines=99999)`' '
|
||||
cat >expect <<-\EOF &&
|
||||
master |three
|
||||
side |four
|
||||
odd/spot |three
|
||||
double-tag |Annonated doubly
|
||||
four |four
|
||||
one |one
|
||||
signed-tag |A signed tag message
|
||||
three |three
|
||||
two |two
|
||||
EOF
|
||||
git for-each-ref --format="%(refname:short) |%(contents:lines=99999)" >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success '`%(contents:lines=-1)` should fail' '
|
||||
test_must_fail git for-each-ref --format="%(refname:short) |%(contents:lines=-1)"
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user