git-format-patch: the default suffix is now .patch, not .txt
[git/gitweb.git] / git-tag.sh
blobecb9100e4b3a7d1ce0227fde447f675376aaf29a
1 #!/bin/sh
2 # Copyright (c) 2005 Linus Torvalds
4 USAGE='-l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
5 SUBDIRECTORY_OK='Yes'
6 . git-sh-setup
8 message_given=
9 annotate=
10 signed=
11 force=
12 message=
13 username=
14 list=
15 verify=
16 while case "$#" in 0) break ;; esac
18 case "$1" in
19 -a)
20 annotate=1
22 -s)
23 annotate=1
24 signed=1
26 -f)
27 force=1
29 -l)
30 case "$#" in
32 set x . ;;
33 esac
34 shift
35 git rev-parse --symbolic --tags | sort | grep "$@"
36 exit $?
38 -m)
39 annotate=1
40 shift
41 message="$1"
42 if test "$#" = "0"; then
43 die "error: option -m needs an argument"
44 else
45 message_given=1
48 -F)
49 annotate=1
50 shift
51 if test "$#" = "0"; then
52 die "error: option -F needs an argument"
53 else
54 message="$(cat "$1")"
55 message_given=1
58 -u)
59 annotate=1
60 signed=1
61 shift
62 username="$1"
64 -d)
65 shift
66 tag_name="$1"
67 tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
68 die "Seriously, what tag are you talking about?"
69 git-update-ref -m 'tag: delete' -d "refs/tags/$tag_name" "$tag" &&
70 echo "Deleted tag $tag_name."
71 exit $?
73 -v)
74 shift
75 tag_name="$1"
76 tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
77 die "Seriously, what tag are you talking about?"
78 git-verify-tag -v "$tag"
79 exit $?
81 -*)
82 usage
85 break
87 esac
88 shift
89 done
91 name="$1"
92 [ "$name" ] || usage
93 prev=0000000000000000000000000000000000000000
94 if git-show-ref --verify --quiet -- "refs/tags/$name"
95 then
96 test -n "$force" || die "tag '$name' already exists"
97 prev=`git rev-parse "refs/tags/$name"`
99 shift
100 git-check-ref-format "tags/$name" ||
101 die "we do not like '$name' as a tag name."
103 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
104 type=$(git-cat-file -t $object) || exit 1
105 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
106 : ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
108 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
110 if [ "$annotate" ]; then
111 if [ -z "$message_given" ]; then
112 ( echo "#"
113 echo "# Write a tag message"
114 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
115 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
116 else
117 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
120 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
121 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
123 [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
124 echo >&2 "No tag message?"
125 exit 1
128 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
129 "$object" "$type" "$name" "$tagger";
130 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
131 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
132 if [ "$signed" ]; then
133 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
134 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
135 die "failed to sign the tag with GPG."
137 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
140 git update-ref "refs/tags/$name" "$object" "$prev"