2 # Copyright (c) 2005 Linus Torvalds
4 . git-sh-setup-script || die "Not a git archive"
7 echo >&2 "Usage: git-tag-script [-a | -s] [-f] tagname"
14 while case "$#" in 0) break ;; esac
39 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
40 die "tag '$name' already exists"
44 object=$(git-rev-parse --verify --revs-only --default HEAD "$@") || exit 1
45 type=$(git-cat-file -t $object) || exit 1
46 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
48 trap 'rm -f .tmp-tag* .tagmsg .editmsg' 0
50 if [ "$annotate" ]; then
52 echo "# Write a tag message"
54 ${VISUAL:-${EDITOR:-vi}} .editmsg || exit
56 grep -v '^#' < .editmsg | git-stripspace > .tagmsg
58 [ -s .tagmsg ] || exit
60 ( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n"; cat .tagmsg ) > .tmp-tag
61 rm -f .tmp-tag.asc .tagmsg
62 if [ "$signed" ]; then
63 me=$(expr "$tagger" : '\(.*>\)') &&
64 gpg -bsa -u "$me" .tmp-tag &&
65 cat .tmp-tag.asc >>.tmp-tag ||
66 die "failed to sign the tag with GPG."
68 object=$(git-mktag < .tmp-tag)
71 mkdir -p "$GIT_DIR/refs/tags"
72 echo $object > "$GIT_DIR/refs/tags/$name"