Test commit
[cogito/jonas.git] / cg-tag-show
blob18530b639bdc305488a3410e406e87ced3cd902f
1 #!/usr/bin/env bash
3 # Show information about given tag(s)
4 # Copyright (c) Petr Baudis 2006
6 # This command shows detailed information about specified tag(s).
8 # Testsuite: TODO
10 USAGE="cg-tag-show TAGNAME..."
11 _git_wc_unneeded=1
13 . "${COGITO_LIB}"cg-Xlib || exit 1
16 verify_tag()
18 local tag="$1" sha1="$2"
19 local tagfile="$(mktemp -t gittag.XXXXXX)"
21 git-cat-file tag "$1" >"$tagfile" || return 1
22 cat "$tagfile" | sed '/^-----BEGIN PGP SIGNATURE-----/Q' |
23 gpg --verify "$tagfile" - || return 1
24 rm -f "$tagfile"
25 return 0
28 header_end()
30 local tag="$1" sha1="$2" verify="$3"
32 if [ "$verify" ]; then
33 if verify_tag "$tag" "$sha1"; then
34 echo "Signature: Ok"
35 else
36 echo "Signature: NOT VERIFIED"
38 else
39 echo "Signature: None"
43 cat_tag()
45 local tag="$1" sha1="$2" verify="$3" object= state=1 date=
46 while IFS=$'\n' read -r line; do
47 if [ ! "$line" -a "$state" = 1 ]; then
48 header_end "$tag" "$sha1" "$verify"
49 echo
50 state=2
51 continue
54 if [ "$state" = 1 ]; then
55 data="${line#* }"
56 case "${line%% *}" in
57 object) object="$data";;
58 type)
59 echo "Object: $object ($data)";;
60 tag)
61 if [ "$data" != "$tag" ]; then
62 echo "Real tag name: $data"
63 fi;;
64 tagger)
65 # We want wordsplitting in the $date here, to get
66 # TZ as separate argument.
67 date=(${data#*> })
68 showdate ${date[*]}; date="$_showdate"
69 echo "Tagger: ${data%%> *}> $date";;
71 echo " $line";; # print unknown headers as-they-are
72 esac
73 elif [ "$state" = 2 ]; then
74 if [ x"$line" = x"-----BEGIN PGP SIGNATURE-----" ]; then
75 # FIXME: Extra newline was printed just before
76 break
78 echo " $line"
80 done
81 if [ "$state" = 1 ]; then
82 header_end "$tag" "$sha1" "$verify"
86 show_tag()
88 local tag="$1"
89 local sha1
90 if ! sha1="$(get_ref "refs/tags/$tag")"; then
91 echo "No such tag: $tag" >&2
92 echo >&2
93 return 1
95 local type="$(git-cat-file -t "$sha1" 2>/dev/null)"
96 if [ ! "$type" ]; then
97 echo "Broken tag: $tag" >&2
98 echo >&2
99 return 1
102 echo -n "Tag: $tag"
103 if [ "$type" != "tag" ]; then
104 echo " (direct)"
105 echo "Object: $sha1 ($type)"
106 return 0
108 echo
110 local verify=
111 if git-cat-file tag "$sha1" | grep -q '^-----BEGIN PGP SIGNATURE-----'; then
112 verify=1
114 git-cat-file tag "$sha1" | cat_tag "$tag" "$sha1" "$verify"
115 if [ ${PIPESTATUS[0]} -ne 0 -o ${PIPESTATUS[1]} -ne 0 ]; then
116 return 1
118 return 0
122 [ "${ARGS[0]}" ] || usage
124 first=1
125 ret=0
126 for tag in "${ARGS[@]}"; do
127 if [ "$first" ]; then
128 first=
129 else
130 echo
132 if ! show_tag "$tag"; then
133 ret=1
134 first=1
136 done
137 exit $ret