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