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

Allow the tag signing key to be specified in the config file

I did this: $ git tag -s test-sign gpg: skipped "Andy Parkins <andyparkins@gmail.com>": secret key not available gpg: signing failed: secret key not available failed to sign the tag with GPG. The problem is that I have used the comment field in my key's UID definition. $ gpg --list-keys andy pub 1024D/4F712F6D 2003-08-14 uid Andy Parkins (Google) <andyparkins@gmail.com> So when git-tag looks for "Andy Parkins <andyparkins@gmail.com>"; obviously it's not going to be found. There shouldn't be a requirement that I use the same form of my name in my git repository and my gpg key - I might want to be formal (Andrew) in my gpg key and informal (Andy) in the repository. Further I might have multiple keys in my keyring, and might want to use one that doesn't match up with the address I use in commit messages. This patch adds a configuration entry "user.signingkey" which, if present, will be passed to the "-u" switch for gpg, allowing the tag signing key to be overridden. If the entry is not present, the fallback is the original method, which means existing behaviour will continue untouched. Signed-off-by: Andy Parkins <andyparkins@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Andy Parkins committed Jan 26, 2007 at 14:13 UTC d67778eccdf778f0fc252aaade8a47c23bfebbd6
3 files changed +21 -2
Documentation/config.txt
+7
@@ -469,6 +469,13 @@ user.name::
469 Can be overridden by the 'GIT_AUTHOR_NAME' and 'GIT_COMMITTER_NAME'
470 environment variables. See gitlink:git-commit-tree[1].
471
472 +user.signingkey::
473 + If gitlink:git-tag[1] is not selecting the key you want it to
474 + automatically when creating a signed tag, you can override the
475 + default selection with this variable. This option is passed
476 + unchanged to gpg's --local-user parameter, so you may specify a key
477 + using any method that gpg supports.
478 +
479 whatchanged.difftree::
480 The default gitlink:git-diff-tree[1] arguments to be used
481 for gitlink:git-whatchanged[1].
Documentation/git-tag.txt
+10
@@ -70,6 +70,16 @@ OPTIONS
70 Take the tag message from the given file. Use '-' to
71 read the message from the standard input.
72
73 +CONFIGURATION
74 +-------------
75 +By default, git-tag in sign-with-default mode (-s) will use your
76 +committer identity (of the form "Your Name <your@email.address>") to
77 +find a key. If you want to use a different default key, you can specify
78 +it in the repository configuration as follows:
79 +
80 +[user]
81 + signingkey = <gpg-key-id>
82 +
83 Author
84 ------
85 Written by Linus Torvalds <torvalds@osdl.org>,
git-tag.sh
+4 -2
@@ -112,7 +112,9 @@ git-check-ref-format "tags/$name" ||
112 object=$(git-rev-parse --verify --default HEAD "$@") || exit 1
113 type=$(git-cat-file -t $object) || exit 1
114 tagger=$(git-var GIT_COMMITTER_IDENT) || exit 1
115 -: ${username:=$(expr "z$tagger" : 'z\(.*>\)')}
115 +
116 +keyid=$(git-repo-config user.signingkey) ||
117 + keyid=$(expr "z$tagger" : 'z\(.*>\)')
118
119 trap 'rm -f "$GIT_DIR"/TAG_TMP* "$GIT_DIR"/TAG_FINALMSG "$GIT_DIR"/TAG_EDITMSG' 0
120
@@ -139,7 +141,7 @@ if [ "$annotate" ]; then
141 cat "$GIT_DIR"/TAG_FINALMSG ) >"$GIT_DIR"/TAG_TMP
142 rm -f "$GIT_DIR"/TAG_TMP.asc "$GIT_DIR"/TAG_FINALMSG
143 if [ "$signed" ]; then
142 - gpg -bsa -u "$username" "$GIT_DIR"/TAG_TMP &&
144 + gpg -bsa -u "$keyid" "$GIT_DIR"/TAG_TMP &&
145 cat "$GIT_DIR"/TAG_TMP.asc >>"$GIT_DIR"/TAG_TMP ||
146 die "failed to sign the tag with GPG."
147 fi