]> git.ipfire.org Git - thirdparty/git.git/blame - git-tag.sh
GIT-VERSION-FILE: check ./version first.
[thirdparty/git.git] / git-tag.sh
CommitLineData
65f0d0ee 1#!/bin/sh
8ac069ac
JH
2# Copyright (c) 2005 Linus Torvalds
3
0bc72abd 4USAGE='-l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg>] <tagname> [<head>]'
806f36d4
FK
5SUBDIRECTORY_OK='Yes'
6. git-sh-setup
d165fa14 7
aabd7693 8message_given=
0fad0fdd 9annotate=
d727782e
LT
10signed=
11force=
c882bc93 12message=
bc162e40 13username=
b867c7c2 14list=
0bc72abd 15verify=
d727782e
LT
16while case "$#" in 0) break ;; esac
17do
18 case "$1" in
0fad0fdd
JH
19 -a)
20 annotate=1
21 ;;
d727782e 22 -s)
0fad0fdd 23 annotate=1
d727782e
LT
24 signed=1
25 ;;
26 -f)
27 force=1
28 ;;
b867c7c2 29 -l)
b867c7c2
JH
30 case "$#" in
31 1)
e6ebb8a3 32 set x . ;;
b867c7c2 33 esac
e6ebb8a3
SE
34 shift
35 git rev-parse --symbolic --tags | sort | grep "$@"
b867c7c2
JH
36 exit $?
37 ;;
c882bc93
CW
38 -m)
39 annotate=1
40 shift
41 message="$1"
aabd7693
HWN
42 if test "$#" = "0"; then
43 die "error: option -m needs an argument"
aabd7693
HWN
44 else
45 message_given=1
46 fi
c882bc93 47 ;;
f79c73ce
JS
48 -F)
49 annotate=1
50 shift
51 if test "$#" = "0"; then
52 die "error: option -F needs an argument"
f79c73ce
JS
53 else
54 message="$(cat "$1")"
55 message_given=1
56 fi
57 ;;
bc162e40
LT
58 -u)
59 annotate=1
60 signed=1
61 shift
62 username="$1"
63 ;;
61f81518
KR
64 -d)
65 shift
453c1e85
JH
66 had_error=0
67 for tag
68 do
69 cur=$(git-show-ref --verify --hash -- "refs/tags/$tag") || {
70 echo >&2 "Seriously, what tag are you talking about?"
71 had_error=1
72 continue
73 }
74 git-update-ref -m 'tag: delete' -d "refs/tags/$tag" "$cur" || {
75 had_error=1
76 continue
77 }
78 echo "Deleted tag $tag."
79 done
80 exit $had_error
61f81518 81 ;;
0bc72abd
SB
82 -v)
83 shift
84 tag_name="$1"
85 tag=$(git-show-ref --verify --hash -- "refs/tags/$tag_name") ||
86 die "Seriously, what tag are you talking about?"
87 git-verify-tag -v "$tag"
88 exit $?
89 ;;
0fad0fdd
JH
90 -*)
91 usage
92 ;;
d727782e
LT
93 *)
94 break
95 ;;
96 esac
97 shift
98done
99
918c05f1 100name="$1"
0fad0fdd 101[ "$name" ] || usage
cede7526 102prev=0000000000000000000000000000000000000000
b431b282 103if git-show-ref --verify --quiet -- "refs/tags/$name"
cede7526
JH
104then
105 test -n "$force" || die "tag '$name' already exists"
106 prev=`git rev-parse "refs/tags/$name"`
0fad0fdd 107fi
d727782e 108shift
03feddd6
JH
109git-check-ref-format "tags/$name" ||
110 die "we do not like '$name' as a tag name."
8ac069ac 111
2ad77e67 112object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
0fc65a45 113type=$(git-cat-file -t $object) || exit 1
c818566d 114tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
d67778ec 115
63460f28
JH
116test -n "$username" ||
117 username=$(git-repo-config user.signingkey) ||
118 username=$(expr "z$tagger" : 'z\(.*>\)')
918c05f1 119
a10aad6a 120trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
0fad0fdd
JH
121
122if [ "$annotate" ]; then
aabd7693 123 if [ -z "$message_given" ]; then
c882bc93
CW
124 ( echo "#"
125 echo "# Write a tag message"
a10aad6a
JH
126 echo "#" ) > "$GIT_DIR"/TAG_EDITMSG
127 ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR"/TAG_EDITMSG || exit
c882bc93 128 else
a10aad6a 129 echo "$message" >"$GIT_DIR"/TAG_EDITMSG
c882bc93 130 fi
d727782e 131
a10aad6a
JH
132 grep -v '^#' <"$GIT_DIR"/TAG_EDITMSG |
133 git-stripspace >"$GIT_DIR"/TAG_FINALMSG
918c05f1 134
aabd7693 135 [ -s "$GIT_DIR"/TAG_FINALMSG -o -n "$message_given" ] || {
bc162e40
LT
136 echo >&2 "No tag message?"
137 exit 1
138 }
918c05f1 139
0dbc4e89
AR
140 ( printf 'object %s\ntype %s\ntag %s\ntagger %s\n\n' \
141 "$object" "$type" "$name" "$tagger";
a10aad6a
JH
142 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
143 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
0fad0fdd 144 if [ "$signed" ]; then
63460f28 145 gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
a10aad6a 146 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
0fad0fdd
JH
147 die "failed to sign the tag with GPG."
148 fi
a10aad6a 149 object=$(git-mktag < "$GIT_DIR"/TAG_TMP)
d727782e 150fi
918c05f1 151
36733704
CC
152git update-ref "refs/tags/$name" "$object" "$prev"
153