Skip to content

Commit

Permalink
Allow configured email addresses to be pre-quoted as "<...>". (jelmer…
Browse files Browse the repository at this point in the history
…#722)

Allow configured email addresses to be pre-quoted as "<...>".
  • Loading branch information
monnerat authored and jelmer committed Aug 25, 2019
1 parent 6afa2f6 commit dd07fa9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions dulwich/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import sys
import stat
import time
import re

from dulwich.errors import (
NoIndexPresent,
Expand Down Expand Up @@ -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 <email>'"""
Expand Down Expand Up @@ -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">")


Expand Down
2 changes: 1 addition & 1 deletion dulwich/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"<jelmer@apache.org>")
c.write_to_path()
commit_sha = r.do_commit(b'message')
self.assertEqual(
Expand Down

0 comments on commit dd07fa9

Please sign in to comment.