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