GIT 1.2.0
[git/jnareb-git/bp-gitweb.git] / git-tag.sh
blobc74e1b4151a3d05a5825dc7dcba2dfaf1ad9a0fa
1 #!/bin/sh
2 # Copyright (c) 2005 Linus Torvalds
4 USAGE='[-a | -s | -u <key-id>] [-f | -d] [-m <msg>] <tagname> [<head>]'
5 SUBDIRECTORY_OK='Yes'
6 . git-sh-setup
8 annotate=
9 signed=
10 force=
11 message=
12 username=
13 while case "$#" in 0) break ;; esac
15 case "$1" in
16 -a)
17 annotate=1
19 -s)
20 annotate=1
21 signed=1
23 -f)
24 force=1
26 -m)
27 annotate=1
28 shift
29 message="$1"
31 -u)
32 annotate=1
33 signed=1
34 shift
35 username="$1"
37 -d)
38 shift
39 tag_name="$1"
40 rm "$GIT_DIR/refs/tags/$tag_name" && \
41 echo "Deleted tag $tag_name."
42 exit $?
44 -*)
45 usage
48 break
50 esac
51 shift
52 done
54 name="$1"
55 [ "$name" ] || usage
56 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
57 die "tag '$name' already exists"
59 shift
60 git-check-ref-format "tags/$name" ||
61 die "we do not like '$name' as a tag name."
63 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
64 type=$(git-cat-file -t $object) || exit 1
65 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
66 : ${username:=$(expr "$tagger" : '\(.*>\)')}
68 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
70 if [ "$annotate" ]; then
71 if [ -z "$message" ]; then
72 ( echo "#"
73 echo "# Write a tag message"
74 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
75 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
76 else
77 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
80 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
81 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
83 [ -s "$GIT_DIR"/TAG_FINALMSG ] || {
84 echo >&2 "No tag message?"
85 exit 1
88 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
89 "$object" "$type" "$name" "$tagger";
90 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
91 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
92 if [ "$signed" ]; then
93 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
94 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
95 die "failed to sign the tag with GPG."
97 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
100 leading=`expr "refs/tags/$name" : '\(.*\)/'` &&
101 mkdir -p "$GIT_DIR/$leading" &&
102 echo $object > "$GIT_DIR/refs/tags/$name"