Skip to content

Commit 0fad0fd

Browse files
author
Junio C Hamano
committed
git-tag-script updates.
This adds -a (annotate only but not sign) option "A Large Angry SCM" <gitzilla@gmail.com> sent to the list, after fixing up the whitespace corruption in the patch, with some of my own fixes. Namely: * A new flag '-a' can be used to create an unsigned tag object; * The '-f' flag logic did not do the right thing; * When creating a signed tag, we did not check for GPG failure as we should; * Try to use the key for the tagger identity when signing the tag. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 154d3d2 commit 0fad0fd

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

git-tag-script

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,30 @@
33

44
. git-sh-setup-script || die "Not a git archive"
55

6+
usage () {
7+
echo >&2 "Usage: git-tag-script [-a | -s] [-f] tagname"
8+
exit 1
9+
}
10+
11+
annotate=
612
signed=
713
force=
814
while case "$#" in 0) break ;; esac
915
do
1016
case "$1" in
17+
-a)
18+
annotate=1
19+
;;
1120
-s)
21+
annotate=1
1222
signed=1
1323
;;
1424
-f)
1525
force=1
1626
;;
27+
-*)
28+
usage
29+
;;
1730
*)
1831
break
1932
;;
@@ -22,16 +35,19 @@ do
2235
done
2336

2437
name="$1"
25-
[ "$name" ] || die "I need a tag-name"
26-
[ -e "$GIT_DIR/refs/tags/$name" ] &&
27-
[ "$force" ] || die "tag '$name' already exists"
38+
[ "$name" ] || usage
39+
if [ -e "$GIT_DIR/refs/tags/$name" -a -z "$force" ]; then
40+
die "tag '$name' already exists"
41+
fi
2842
shift
2943

3044
object=$(git-rev-parse --verify --revs-only --default HEAD "$@") || exit 1
3145
type=$(git-cat-file -t $object) || exit 1
3246
tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
3347

34-
if [ "$signed" ]; then
48+
trap 'rm -f .tmp-tag* .tagmsg .editmsg' 0
49+
50+
if [ "$annotate" ]; then
3551
( echo "#"
3652
echo "# Write a tag message"
3753
echo "#" ) > .editmsg
@@ -43,9 +59,13 @@ if [ "$signed" ]; then
4359

4460
( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n"; cat .tagmsg ) > .tmp-tag
4561
rm -f .tmp-tag.asc .tagmsg
46-
gpg -bsa .tmp-tag && cat .tmp-tag.asc >> .tmp-tag
62+
if [ "$signed" ]; then
63+
me=$(expr "$tagger" : '\(.*>\)') &&
64+
gpg -bsa -u "$me" .tmp-tag &&
65+
cat .tmp-tag.asc >>.tmp-tag ||
66+
die "failed to sign the tag with GPG."
67+
fi
4768
object=$(git-mktag < .tmp-tag)
48-
rm -f .tmp-tag .tmp-tag.sig
4969
fi
5070

5171
mkdir -p "$GIT_DIR/refs/tags"

0 commit comments

Comments
 (0)