2 # Copyright (c) 2005 Linus Torvalds
4 USAGE='[-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
39 LINES=$(expr "$1" : '\([0-9]*\)')
40 [ -z "$LINES" ] && LINES=1 # 1 line is default when -n is used
52 PATTERN="$1" # select tags by shell pattern, not re
56 git rev-parse --symbolic --tags | sort |
63 [ "$LINES" -le 0 ] && { echo "$TAG"; continue ;}
64 OBJTYPE=$(git cat-file -t "$TAG")
67 ANNOTATION=$(git cat-file tag "$TAG" |
70 /^-----BEGIN PGP SIGNATURE-----\$/q
75 printf "%-15s %s\n" "$TAG" "$ANNOTATION"
86 if test "$#" = "0"; then
87 die "error: option -m needs an argument"
97 if test "$#" = "0"; then
98 die "error: option -F needs an argument"
100 message="$(cat "$1")"
109 if test "$#" = "0"; then
110 die "error: option -u needs an argument"
121 cur=$(git show-ref --verify --hash -- "refs/tags/$tag") || {
122 echo >&2 "Seriously, what tag are you talking about?"
126 git update-ref -m 'tag: delete' -d "refs/tags/$tag" "$cur" || {
130 echo "Deleted tag $tag."
137 tag=$(git show-ref --verify --hash -- "refs/tags/$tag_name") ||
138 die "Seriously, what tag are you talking about?"
139 git-verify-tag -v "$tag"
151 [ -n "$list" ] && exit 0
155 prev=0000000000000000000000000000000000000000
156 if git show-ref --verify --quiet -- "refs/tags/$name"
158 test -n "$force" || die "tag '$name' already exists"
159 prev=`git rev-parse "refs/tags/$name"`
162 git check-ref-format "tags/$name" ||
163 die "we do not like '$name' as a tag name."
165 object=$(git rev-parse --verify --default HEAD "$@") || exit 1
166 type=$(git cat-file -t $object) || exit 1
167 tagger=$(git var GIT_COMMITTER_IDENT) || exit 1
169 test -n "$username" ||
170 username=$(git config user.signingkey) ||
171 username=$(expr "z$tagger" : 'z\(.*>\)')
173 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
175 if [ "$annotate" ]; then
176 if [ -z "$message_given" ]; then
178 echo "# Write a tag message"
179 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
180 git_editor "$GIT_DIR"/TAG_EDITMSG || exit
182 printf '%s\n' "$message" >"$GIT_DIR"/TAG_EDITMSG
185 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
186 git stripspace >"$GIT_DIR"/TAG_FINALMSG
188 [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
189 echo >&2 "No tag message?"
193 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
194 "$object" "$type" "$name" "$tagger";
195 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
196 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
197 if [ "$signed" ]; then
198 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
199 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
200 die "failed to sign the tag with GPG."
202 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
205 git update-ref "refs/tags/$name" "$object" "$prev"