2 # Copyright (c) 2005 Linus Torvalds
4 USAGE='[-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
13 while case "$#" in 0) break ;; esac
40 rm "$GIT_DIR/refs/tags/$tag_name" && \
41 echo "Deleted tag $tag_name."
56 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
57 die "tag '$name' already exists"
60 git-check-ref-format "tags/$name" ||
61 die "we do not like '$name' as a tag name."
63 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
64 type=$(git-cat-file -t $object) || exit 1
65 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
66 : ${username:=$(expr "$tagger" : '\(.*>\)')}
68 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
70 if [ "$annotate" ]; then
71 if [ -z "$message" ]; then
73 echo "# Write a tag message"
74 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
75 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
77 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
80 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
81 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
83 [ -s "$GIT_DIR"/TAG_FINALMSG ] || {
84 echo >&2 "No tag message?"
88 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
89 "$object" "$type" "$name" "$tagger";
90 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
91 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
92 if [ "$signed" ]; then
93 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
94 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
95 die "failed to sign the tag with GPG."
97 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
100 leading=`expr "refs/tags/$name" : '\(.*\)/'` &&
101 mkdir -p "$GIT_DIR/$leading" &&
102 echo $object > "$GIT_DIR/refs/tags/$name"