Skip to content

Commit 6abd0fb

Browse files
committed
Merge branch 'mm/tag'
* mm/tag: Teach git-tag about showing tag annotations.
2 parents 11f68d9 + 980ea5c commit 6abd0fb

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

Documentation/git-tag.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ SYNOPSIS
1111
[verse]
1212
'git-tag' [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] <name> [<head>]
1313
'git-tag' -d <name>...
14-
'git-tag' -l [<pattern>]
14+
'git-tag' [-n [<num>]] -l [<pattern>]
1515
'git-tag' -v <name>
1616

1717
DESCRIPTION
@@ -38,8 +38,8 @@ GnuPG key for signing.
3838

3939
`-v <tag>` verifies the gpg signature of the tag.
4040

41-
`-l <pattern>` lists tags that match the given pattern (or all
42-
if no pattern is given).
41+
`-l <pattern>` lists tags with names that match the given pattern
42+
(or all if no pattern is given).
4343

4444
OPTIONS
4545
-------
@@ -61,8 +61,13 @@ OPTIONS
6161
-v::
6262
Verify the gpg signature of given the tag
6363

64+
-n <num>::
65+
<num> specifies how many lines from the annotation, if any,
66+
are printed when using -l.
67+
The default is not to print any annotation lines.
68+
6469
-l <pattern>::
65-
List tags that match the given pattern (or all if no pattern is given).
70+
List tags with names that match the given pattern (or all if no pattern is given).
6671

6772
-m <msg>::
6873
Use the given tag message (instead of prompting)

git-tag.sh

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22
# Copyright (c) 2005 Linus Torvalds
33

4-
USAGE='-l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
4+
USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
55
SUBDIRECTORY_OK='Yes'
66
. git-sh-setup
77

@@ -13,6 +13,7 @@ message=
1313
username=
1414
list=
1515
verify=
16+
LINES=0
1617
while case "$#" in 0) break ;; esac
1718
do
1819
case "$1" in
@@ -26,14 +27,41 @@ do
2627
-f)
2728
force=1
2829
;;
29-
-l)
30-
case "$#" in
31-
1)
32-
set x . ;;
30+
-n)
31+
case $2 in
32+
-*) LINES=1 # no argument
33+
;;
34+
*) shift
35+
LINES=$(expr "$1" : '\([0-9]*\)')
36+
[ -z "$LINES" ] && LINES=1 # 1 line is default when -n is used
37+
;;
3338
esac
39+
;;
40+
-l)
41+
list=1
3442
shift
35-
git rev-parse --symbolic --tags | sort | grep "$@"
36-
exit $?
43+
PATTERN="$1" # select tags by shell pattern, not re
44+
git rev-parse --symbolic --tags | sort |
45+
while read TAG
46+
do
47+
case "$TAG" in
48+
*$PATTERN*) ;;
49+
*) continue ;;
50+
esac
51+
[ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
52+
OBJTYPE=$(git cat-file -t "$TAG")
53+
case $OBJTYPE in
54+
tag) ANNOTATION=$(git cat-file tag "$TAG" |
55+
sed -e '1,/^$/d' \
56+
-e '/^-----BEGIN PGP SIGNATURE-----$/Q' )
57+
printf "%-15s %s\n" "$TAG" "$ANNOTATION" |
58+
sed -e '2,$s/^/ /' \
59+
-e "${LINES}q"
60+
;;
61+
*) echo "$TAG"
62+
;;
63+
esac
64+
done
3765
;;
3866
-m)
3967
annotate=1
@@ -97,6 +125,8 @@ do
97125
shift
98126
done
99127

128+
[ -n "$list" ] && exit 0
129+
100130
name="$1"
101131
[ "$name" ] || usage
102132
prev=0000000000000000000000000000000000000000

0 commit comments

Comments
 (0)