Skip to content

Commit

Permalink
Support BZR_EMAIL variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Mar 26, 2020
1 parent e88b83f commit 3014386
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions breezy/config.py
Expand Up @@ -556,12 +556,12 @@ def username(self):
Something similar to 'Martin Pool <mbp@sourcefrog.net>'
$BRZ_EMAIL can be set to override this, then
$BRZ_EMAIL or $BZR_EMAIL can be set to override this, then
the concrete policy type is checked, and finally
$EMAIL is examined.
If no username can be found, NoWhoami exception is raised.
"""
v = os.environ.get('BRZ_EMAIL')
v = os.environ.get('BRZ_EMAIL') or os.environ.get('BZR_EMAIL')
if v:
if not PY3:
v = v.decode(osutils.get_user_encoding())
Expand Down Expand Up @@ -2546,7 +2546,7 @@ def get_help(self, key=None):
Option('editor',
help='The command called to launch an editor to enter a message.'))
option_registry.register(
Option('email', override_from_env=['BRZ_EMAIL'],
Option('email', override_from_env=['BRZ_EMAIL', 'BZR_EMAIL'],
default=bedding.default_email, help='The users identity'))
option_registry.register(
Option('gpg_signing_key',
Expand Down
17 changes: 16 additions & 1 deletion breezy/tests/test_config.py
Expand Up @@ -1484,6 +1484,13 @@ def test_BRZ_EMAIL_OVERRIDES(self):
self.assertEqual("Robert Collins <robertc@example.org>",
my_config.username())

def test_BRZ_EMAIL_OVERRIDES(self):
self.overrideEnv('BZR_EMAIL', "Robert Collins <robertc@example.org>")
branch = FakeBranch()
my_config = config.BranchConfig(branch)
self.assertEqual("Robert Collins <robertc@example.org>",
my_config.username())

def test_get_user_option_global(self):
my_config = self.get_branch_config(global_config=sample_config_text)
self.assertEqual('something',
Expand Down Expand Up @@ -4648,8 +4655,16 @@ class EmailOptionTests(tests.TestCase):

def test_default_email_uses_BRZ_EMAIL(self):
conf = config.MemoryStack(b'email=jelmer@debian.org')
# BRZ_EMAIL takes precedence over EMAIL
# BRZ_EMAIL takes precedence over BZR_EMAIL and EMAIL
self.overrideEnv('BRZ_EMAIL', 'jelmer@samba.org')
self.overrideEnv('BZR_EMAIL', 'jelmer@jelmer.uk')
self.overrideEnv('EMAIL', 'jelmer@apache.org')
self.assertEqual('jelmer@samba.org', conf.get('email'))

def test_default_email_uses_BZR_EMAIL(self):
conf = config.MemoryStack(b'email=jelmer@debian.org')
# BZR_EMAIL takes precedence over EMAIL
self.overrideEnv('BZR_EMAIL', 'jelmer@samba.org')
self.overrideEnv('EMAIL', 'jelmer@apache.org')
self.assertEqual('jelmer@samba.org', conf.get('email'))

Expand Down

0 comments on commit 3014386

Please sign in to comment.