2 # Copyright (c) 2005 Linus Torvalds
4 . git-sh-setup || die
"Not a git archive"
7 echo >&2 "Usage: git-tag [-a | -s | -u <key-id>] [-f] [-m <msg>] <tagname>"
16 while case "$#" in 0) break ;; esac
52 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
53 die
"tag '$name' already exists"
57 object
=$
(git-rev-parse
--verify --default HEAD
"$@") ||
exit 1
58 type=$
(git-cat-file
-t $object) ||
exit 1
59 tagger
=$
(git-var GIT_COMMITTER_IDENT
) ||
exit 1
60 : ${username:=$(expr "$tagger" : '\(.*>\)')}
62 trap 'rm -f .tmp-tag* .tagmsg .editmsg' 0
64 if [ "$annotate" ]; then
65 if [ -z "$message" ]; then
67 echo "# Write a tag message"
69 ${VISUAL:-${EDITOR:-vi}} .editmsg ||
exit
71 echo "$message" > .editmsg
74 grep -v '^#' < .editmsg | git-stripspace
> .tagmsg
77 echo >&2 "No tag message?"
81 ( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n"; cat .tagmsg
) > .tmp-tag
82 rm -f .tmp-tag.asc .tagmsg
83 if [ "$signed" ]; then
84 gpg
-bsa -u "$username" .tmp-tag
&&
85 cat .tmp-tag.asc
>>.tmp-tag ||
86 die
"failed to sign the tag with GPG."
88 object
=$
(git-mktag
< .tmp-tag
)
91 mkdir
-p "$GIT_DIR/refs/tags"
92 echo $object > "$GIT_DIR/refs/tags/$name"