@matheusbsbs / matheus-bagliano / commits / bc162e40ea
Fork 0

Allow "-u" flag to tag signing

The current "git tag -s" thing always uses the tagger name as the signing user key, which is very irritating, since my key is under my email address, but the tagger key obviously contains the actual machine name too. Now, I could just use "GIT_COMMITTER_EMAIL" and force it to be my real email, but I actually think that it's nice to see which machine I use for my work. So rather than force my tagger ID to have to match the gpg key name, just support the "-u" flag to "git tag" instead. It implicitly enables signing, since it doesn't make any sense without it. Thus: git tag -u <gpg-key-name> <tag-name> [<tagged-object>] will use the named gpg key for signing. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Oct 6, 2005 at 14:10 UTC bc162e40ea6dc3208e3bda76301d6409607ed3ff
2 files changed +29 -11
Documentation/git-tag.txt
+15 -7
@@ -10,19 +10,27 @@ git-tag - Create a tag object signed with GPG
10
11 SYNOPSIS
12 --------
13 -'git-tag' [-s | -a] [-f] <name>
13 +'git-tag' [-a | -s | -u <key-id>] [-f] [-m <msg>] <name>
14
15 DESCRIPTION
16 -----------
17 -Adds a "tag" reference in .git/refs/tags/
17 +Adds a 'tag' reference in .git/refs/tags/
18
19 -Unless "-f" is given, the tag must not yet exist in ".git/refs/tags"
19 +Unless `-f` is given, the tag must not yet exist in
20 +`.git/refs/tags/` directory.
21
21 -If "-s" or "-a" is passed, the user will be prompted for a tag message.
22 -and a tag object is created. Otherwise just the SHA1 object
23 -name of the commit object is written.
22 +If one of `-a`, `-s`, or `-u <key-id>` is passed, the command
23 +creates a 'tag' object, and requires the tag message. Unless
24 +`-m <msg>` is given, an editor is started for the user to type
25 +in the tag message.
26
25 -A GnuPG signed tag object will be created when "-s" is used.
27 +Otherwise just the SHA1 object name of the commit object is
28 +written (i.e. an lightweight tag).
29 +
30 +A GnuPG signed tag object will be created when `-s` or `-u
31 +<key-id>` is used. When `-u <key-id>` is not used, the
32 +committer identity for the current user is used to find the
33 +GnuPG key for signing.
34
35
36 Author
git-tag.sh
+14 -4
@@ -4,7 +4,7 @@
4 . git-sh-setup || die "Not a git archive"
5
6 usage () {
7 - echo >&2 "Usage: git-tag [-a | -s] [-f] [-m "tag message"] tagname"
7 + echo >&2 "Usage: git-tag [-a | -s | -u <key-id>] [-f] [-m <msg>] <tagname>"
8 exit 1
9 }
10
@@ -12,6 +12,7 @@ annotate=
12 signed=
13 force=
14 message=
15 +username=
16 while case "$#" in 0) break ;; esac
17 do
18 case "$1" in
@@ -30,6 +31,12 @@ do
31 shift
32 message="$1"
33 ;;
34 + -u)
35 + annotate=1
36 + signed=1
37 + shift
38 + username="$1"
39 + ;;
40 -*)
41 usage
42 ;;
@@ -50,6 +57,7 @@ shift
57 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
58 type=$(git-cat-file -t $object) || exit 1
59 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
60 +: ${username:=$(expr "$tagger" : '\(.*>\)')}
61
62 trap 'rm -f .tmp-tag* .tagmsg .editmsg' 0
63
@@ -65,13 +73,15 @@ if [ "$annotate" ]; then
73
74 grep -v '^#' < .editmsg | git-stripspace > .tagmsg
75
68 - [ -s .tagmsg ] || exit
76 + [ -s .tagmsg ] || {
77 + echo >&2 "No tag message?"
78 + exit 1
79 + }
80
81 ( echo -e "object $object\ntype $type\ntag $name\ntagger $tagger\n"; cat .tagmsg ) > .tmp-tag
82 rm -f .tmp-tag.asc .tagmsg
83 if [ "$signed" ]; then
73 - me=$(expr "$tagger" : '\(.*>\)') &&
74 - gpg -bsa -u "$me" .tmp-tag &&
84 + gpg -bsa -u "$username" .tmp-tag &&
85 cat .tmp-tag.asc >>.tmp-tag ||
86 die "failed to sign the tag with GPG."
87 fi