From dd07fa946b200c3b1cd692a64992bcbae7e20a54 Mon Sep 17 00:00:00 2001 From: monnerat Date: Mon, 26 Aug 2019 00:47:38 +0200 Subject: [PATCH] Allow configured email addresses to be pre-quoted as "<...>". (#722) Allow configured email addresses to be pre-quoted as "<...>". --- dulwich/repo.py | 6 ++++++ dulwich/tests/test_repository.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dulwich/repo.py b/dulwich/repo.py index 9e6fd9e96..aaa066e6b 100644 --- a/dulwich/repo.py +++ b/dulwich/repo.py @@ -34,6 +34,7 @@ import sys import stat import time +import re from dulwich.errors import ( NoIndexPresent, @@ -112,6 +113,8 @@ DEFAULT_REF = b'refs/heads/master' +quoted_email_re = re.compile(br"^\s*<\s*(.*)\s*>\s*$") + class InvalidUserIdentity(Exception): """User identity is not of the format 'user '""" @@ -175,6 +178,9 @@ def get_user_identity(config, kind=None): email = default_email if not isinstance(email, bytes): email = email.encode('utf-8') + m = quoted_email_re.match(email) + if m: + email = m.group(1) return (user + b" <" + email + b">") diff --git a/dulwich/tests/test_repository.py b/dulwich/tests/test_repository.py index c05e6ef86..368f943de 100644 --- a/dulwich/tests/test_repository.py +++ b/dulwich/tests/test_repository.py @@ -882,7 +882,7 @@ def test_commit_config_identity(self): r = self._repo c = r.get_config() c.set((b"user", ), b"name", b"Jelmer") - c.set((b"user", ), b"email", b"jelmer@apache.org") + c.set((b"user", ), b"email", b"") c.write_to_path() commit_sha = r.do_commit(b'message') self.assertEqual(