GIT 0.99.3
[git/mingw/4msysgit/kblees.git] / git-tag-script
blob4917f99576ef91266a63a12899f16de6589ea226
1 #!/bin/sh
2 # Copyright (c) 2005 Linus Torvalds
4 . git-sh-setup-script || die "Not a git archive"
6 usage () {
7 echo >&2 "Usage: git-tag-script [-a | -s] [-f] tagname"
8 exit 1
11 annotate=
12 signed=
13 force=
14 while case "$#" in 0) break ;; esac
16 case "$1" in
17 -a)
18 annotate=1
20 -s)
21 annotate=1
22 signed=1
24 -f)
25 force=1
27 -*)
28 usage
31 break
33 esac
34 shift
35 done
37 name="$1"
38 [ "$name" ] || usage
39 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
40 die "tag '$name' already exists"
42 shift
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
51 ( echo "#"
52 echo "# Write a tag message"
53 echo "#" ) > .editmsg
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"