Make "git rev-list" be a builtin
[debian-git.git] / git-tag.sh
bloba0afa25821b5438f41abfed3a2f27bd22767c3d6
1 #!/bin/sh
2 # Copyright (c) 2005 Linus Torvalds
4 USAGE='-l [<pattern>] | [-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 list=
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 -l)
28 case "$#" in
30 set x . ;;
31 esac
32 shift
33 git rev-parse --symbolic --tags | sort | grep "$@"
34 exit $?
36 -m)
37 annotate=1
38 shift
39 message="$1"
41 -u)
42 annotate=1
43 signed=1
44 shift
45 username="$1"
47 -d)
48 shift
49 tag_name="$1"
50 rm "$GIT_DIR/refs/tags/$tag_name" && \
51 echo "Deleted tag $tag_name."
52 exit $?
54 -*)
55 usage
58 break
60 esac
61 shift
62 done
64 name="$1"
65 [ "$name" ] || usage
66 if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
67 die "tag '$name' already exists"
69 shift
70 git-check-ref-format "tags/$name" ||
71 die "we do not like '$name' as a tag name."
73 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
74 type=$(git-cat-file -t $object) || exit 1
75 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
76 : ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
78 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
80 if [ "$annotate" ]; then
81 if [ -z "$message" ]; then
82 ( echo "#"
83 echo "# Write a tag message"
84 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
85 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
86 else
87 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
90 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
91 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
93 [ -s "$GIT_DIR"/TAG_FINALMSG ] || {
94 echo >&2 "No tag message?"
95 exit 1
98 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
99 "$object" "$type" "$name" "$tagger";
100 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
101 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
102 if [ "$signed" ]; then
103 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
104 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
105 die "failed to sign the tag with GPG."
107 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
110 leading=`expr "refs/tags/$name" : '\(.*\)/'` &&
111 mkdir -p "$GIT_DIR/$leading" &&
112 echo $object > "$GIT_DIR/refs/tags/$name"