2 # Copyright (c) 2005 Linus Torvalds
4 . git-sh-setup || die "Not a git archive"
7 echo >&2 "Usage: git-tag [-a | -s] [-f] [-m "tag message"] tagname [head]"
15 while case "$#" in 0) break ;; esac
45 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
46 die "tag '$name' already exists"
49 git-check-ref-format "tags/$name" ||
50 die "we do not like '$name' as a tag name."
52 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
53 type=$(git-cat-file -t $object) || exit 1
54 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
56 trap 'rm -f .tmp-tag* .tagmsg .editmsg' 0
58 if [ "$annotate" ]; then
59 if [ -z "$message" ]; then
61 echo "# Write a tag message"
63 ${VISUAL:-${EDITOR:-vi}} .editmsg || exit
65 echo "$message" > .editmsg
68 grep -v '^#' < .editmsg | git-stripspace > .tagmsg
70 [ -s .tagmsg ] || exit
72 ( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n"; cat .tagmsg ) > .tmp-tag
73 rm -f .tmp-tag.asc .tagmsg
74 if [ "$signed" ]; then
75 me=$(expr "$tagger" : '\(.*>\)') &&
76 gpg -bsa -u "$me" .tmp-tag &&
77 cat .tmp-tag.asc >>.tmp-tag ||
78 die "failed to sign the tag with GPG."
80 object=$(git-mktag < .tmp-tag)
83 mkdir -p "$GIT_DIR/refs/tags"
84 echo $object > "$GIT_DIR/refs/tags/$name"