PATCH: Less fragile lookup of gpg key

Subsystems: the rest

4 messages, 3 authors, 2016-06-15 · open the first message on its own page

PATCH: Less fragile lookup of gpg key

From: Grant Olson <hidden>
Date: 2016-06-15 22:48:44

When signing a tag, git will attempt to lookup your gpg key if you don't
provide the key id.  Right now, it's a little fragile.  My gpg key uid
is "Grant T. Olson (Personal Email) [off-list ref]".  My git user
info is "Grant T. Olson [off-list ref]".  Things don't match
because git doesn't have the comment.

However, if I lookup just by email, things work perfectly.

I think doing this would make life much easier for new users, and in the
case that someone has an OpenPGP key without email (e.g. Ubuntu Master
Signing Key) we can safely assume they're an expert and will either add
the key id to their configuration or use -u instead of -s.

Here's a patch that will try to lookup the user by email only if no
signing key is provided.  If there is no email, it will still fall back
to the default generated by git.

From d0fcf1340495045813758f910e8f4d745e28546b Mon Sep 17 00:00:00 2001
From: Grant Olson <redacted>
Date: Sat, 1 May 2010 11:02:18 -0400
Subject: [PATCH] Lookup gpg key by email

---
 builtin/tag.c |    2 +-
 ident.c       |    9 +++++++++
 2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c
index d311491..4eb3cc5 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -165,7 +165,7 @@ static int do_sign(struct strbuf *buffer)
 	int i, j;

 	if (!*signingkey) {
-		if (strlcpy(signingkey, git_committer_info(IDENT_ERROR_ON_NO_NAME),
+		if (strlcpy(signingkey, git_committer_email(),
 				sizeof(signingkey)) > sizeof(signingkey) - 1)
 			return error("committer info too long.");
 		bracket = strchr(signingkey, '>');
diff --git a/ident.c b/ident.c
index 9e24388..0e8b78a 100644
--- a/ident.c
+++ b/ident.c
@@ -260,6 +260,15 @@ const char *git_committer_info(int flag)
 			 flag);
 }

+const char *git_committer_email(void)
+{
+	const char *email = getenv("GIT_COMMITTER_EMAIL");
+	if(!email)
+		email = git_default_email;
+
+	return email;
+}
+
 int user_ident_sufficiently_given(void)
 {
 #ifndef WINDOWS
-- 
1.7.0.4

Re: PATCH: Less fragile lookup of gpg key

From: A Large Angry SCM <hidden>
Date: 2016-06-15 22:48:44

Grant Olson wrote:
When signing a tag, git will attempt to lookup your gpg key if you don't
provide the key id.  Right now, it's a little fragile.  My gpg key uid
is "Grant T. Olson (Personal Email) [off-list ref]".  My git user
info is "Grant T. Olson [off-list ref]".  Things don't match
because git doesn't have the comment.

However, if I lookup just by email, things work perfectly.

I think doing this would make life much easier for new users, and in the
case that someone has an OpenPGP key without email (e.g. Ubuntu Master
Signing Key) we can safely assume they're an expert and will either add
the key id to their configuration or use -u instead of -s.

Here's a patch that will try to lookup the user by email only if no
signing key is provided.  If there is no email, it will still fall back
to the default generated by git.
Why not fall back to just the email if the full lookup fails?

Re: PATCH: Less fragile lookup of gpg key

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:44

A Large Angry SCM [off-list ref] writes:
Grant Olson wrote:
quoted
When signing a tag, git will attempt to lookup your gpg key if you don't
provide the key id.  Right now, it's a little fragile.  My gpg key uid
is "Grant T. Olson (Personal Email) [off-list ref]".  My git user
info is "Grant T. Olson [off-list ref]".  Things don't match
because git doesn't have the comment.

However, if I lookup just by email, things work perfectly.

I think doing this would make life much easier for new users, and in the
case that someone has an OpenPGP key without email (e.g. Ubuntu Master
Signing Key) we can safely assume they're an expert and will either add
the key id to their configuration or use -u instead of -s.

Here's a patch that will try to lookup the user by email only if no
signing key is provided.  If there is no email, it will still fall back
to the default generated by git.
Why not fall back to just the email if the full lookup fails?
Thanks; I like that suggestion a lot better.  Grant's suggestion does not
make the lookup "less fragile", but actually makes it less reliable for
people with the same address with different spellings of name and want to
choose which one to use per project.

Re: PATCH: Less fragile lookup of gpg key

From: Grant Olson <hidden>
Date: 2016-06-15 22:48:44

On 5/1/2010 1:18 PM, Junio C Hamano wrote:
A Large Angry SCM [off-list ref] writes:
quoted
Why not fall back to just the email if the full lookup fails?
Thanks; I like that suggestion a lot better.  Grant's suggestion does not
make the lookup "less fragile", but actually makes it less reliable for
people with the same address with different spellings of name and want to
choose which one to use per project.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Unless I'm mis-understanding you, the does the opposite of that.  It
finds your gpg key based on your git email, ignoring your git name, so
that different spellings of the name between gpg and git become irrelevant.

-- 
Grant

"Can you construct some sort of rudimentary lathe?"
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help