Rev 6374: (jelmer) Fix GPG signing key to default to user identity again. (Vincent in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Thu Dec 15 09:58:47 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6374 [merge]
revision-id: pqm at pqm.ubuntu.com-20111215095847-ups4vccjrbfq6tvr
parent: pqm at pqm.ubuntu.com-20111215083155-gfpcyinaaxpbfjyq
parent: v.ladeuil+lp at free.fr-20111215084612-clg6ag882w88g2n1
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-12-15 09:58:47 +0000
message:
  (jelmer) Fix GPG signing key to default to user identity again. (Vincent
   Ladeuil)
modified:
  bzrlib/gpg.py                  gpg.py-20051017065112-8654536d415dacc6
  bzrlib/tests/test_gpg.py       testgpg.py-20051017042228-9276cd40a784c93c
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/gpg.py'
--- a/bzrlib/gpg.py	2011-12-15 07:53:13 +0000
+++ b/bzrlib/gpg.py	2011-12-15 08:36:42 +0000
@@ -27,6 +27,7 @@
 import subprocess
 
 from bzrlib import (
+    config,
     errors,
     trace,
     ui,
@@ -181,8 +182,13 @@
             return False
 
     def _command_line(self):
+        key = self._config_stack.get('gpg_signing_key')
+        if key is None or key == 'default':
+            # 'default' or not setting gpg_signing_key at all means we should
+            # use the user email address
+            key = config.extract_email_address(self._config_stack.get('email'))
         return [self._config_stack.get('gpg_signing_command'), '--clearsign',
-                '-u', self._config_stack.get('gpg_signing_key')]
+                '-u', key]
 
     def sign(self, content):
         if isinstance(content, unicode):

=== modified file 'bzrlib/tests/test_gpg.py'
--- a/bzrlib/tests/test_gpg.py	2011-12-15 07:53:13 +0000
+++ b/bzrlib/tests/test_gpg.py	2011-12-15 08:23:05 +0000
@@ -36,11 +36,13 @@
 
 class FakeConfig(config.Stack):
 
-    def __init__(self):
+    def __init__(self, content=None):
         store = config.IniFileStore()
-        store._load_from_string('''
+        if content is None:
+            content = '''
 gpg_signing_key=amy at example.com
-gpg_signing_command=false''')
+gpg_signing_command=false'''
+        store._load_from_string(content)
         super(FakeConfig, self).__init__([store.get_sections])
 
 
@@ -54,6 +56,23 @@
         self.assertEqual(['false',  '--clearsign', '-u', 'amy at example.com'],
                          self.my_gpg._command_line())
 
+    def test_signing_command_line_from_default(self):
+        # Using 'default' for gpg_signing_key will use the mail part of 'email'
+        my_gpg = gpg.GPGStrategy(FakeConfig('''
+email=Amy <amy at example.com>
+gpg_signing_key=default
+gpg_signing_command=false'''))
+        self.assertEqual(['false',  '--clearsign', '-u', 'amy at example.com'],
+                         my_gpg._command_line())
+
+    def test_signing_command_line_from_email(self):
+        # Not setting gpg_signing_key will use the mail part of 'email'
+        my_gpg = gpg.GPGStrategy(FakeConfig('''
+email=Amy <amy at example.com>
+gpg_signing_command=false'''))
+        self.assertEqual(['false',  '--clearsign', '-u', 'amy at example.com'],
+                         my_gpg._command_line())
+
     def test_checks_return_code(self):
         # This test needs a unix like platform - one with 'false' to run.
         # if you have one, please make this work :)

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-12-14 21:50:54 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-12-15 08:46:12 +0000
@@ -56,6 +56,10 @@
 * Create obsolete_packs directory when repacking if it does not
   exist. (Jonathan Riddell, Jelmer Vernooij, #314314)
 
+* Not setting ``gpg_signing_key`` or setting it to ``default`` will use the
+  user email (obtained from the ``email`` configuration option or its
+  default value). (Vincent Ladeuil, Jelmer Vernooij, #904550)
+
 * Properly ignore '\n' in an option reference since this cannot be part of a
   config option identifier. (Vincent Ladeuil, #902125)
 




More information about the bazaar-commits mailing list