2 # Copyright (c) 2005 Linus Torvalds
4 USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
17 while case "$#" in 0) break ;; esac
32 -*) LINES=1 # no argument
35 LINES=$(expr "$1" : '\([0-9]*\)')
36 [ -z "$LINES" ] && LINES=1 # 1 line is default when -n is used
43 PATTERN="$1" # select tags by shell pattern, not re
44 git rev-parse --symbolic --tags | sort |
51 [ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
52 OBJTYPE=$(git cat-file -t "$TAG")
54 tag) ANNOTATION=$(git cat-file tag "$TAG" |
56 -e '/^-----BEGIN PGP SIGNATURE-----$/Q' )
57 printf "%-15s %s\n" "$TAG" "$ANNOTATION" |
70 if test "$#" = "0"; then
71 die "error: option -m needs an argument"
79 if test "$#" = "0"; then
80 die "error: option -F needs an argument"
97 cur=$(git-show-ref --verify --hash -- "refs/tags/$tag") || {
98 echo >&2 "Seriously, what tag are you talking about?"
102 git-update-ref -m 'tag: delete' -d "refs/tags/$tag" "$cur" || {
106 echo "Deleted tag $tag."
113 tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
114 die "Seriously, what tag are you talking about?"
115 git-verify-tag -v "$tag"
128 [ -n "$list" ] && exit 0
132 prev=0000000000000000000000000000000000000000
133 if git-show-ref --verify --quiet -- "refs/tags/$name"
135 test -n "$force" || die "tag '$name' already exists"
136 prev=`git rev-parse "refs/tags/$name"`
139 git-check-ref-format "tags/$name" ||
140 die "we do not like '$name' as a tag name."
142 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
143 type=$(git-cat-file -t $object) || exit 1
144 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
146 test -n "$username" ||
147 username=$(git-repo-config user.signingkey) ||
148 username=$(expr "z$tagger" : 'z\(.*>\)')
150 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
152 if [ "$annotate" ]; then
153 if [ -z "$message_given" ]; then
155 echo "# Write a tag message"
156 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
157 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
159 printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG
162 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
163 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
165 [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
166 echo >&2 "No tag message?"
170 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
171 "$object" "$type" "$name" "$tagger";
172 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
173 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
174 if [ "$signed" ]; then
175 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
176 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
177 die "failed to sign the tag with GPG."
179 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
182 git update-ref "refs/tags/$name" "$object" "$prev"