diff --git a/moz-phab b/moz-phab index ff804dd..0a25d84 100755 --- a/moz-phab +++ b/moz-phab @@ -36,6 +36,7 @@ import tempfile import threading import time import traceback +import unicodedata import urllib2 import urlparse import uuid @@ -2694,8 +2695,20 @@ class Git(Repository): ["commit-tree", "-p", parent, "-F", message_file, tree_hash], split=False, extra_env={ - "GIT_AUTHOR_NAME": author_name.encode("utf-8"), - "GIT_AUTHOR_EMAIL": author_email.encode("utf-8"), + "GIT_AUTHOR_NAME": ( + unicodedata.normalize("NFKD", author_name).encode( + "ascii", "ignore" + ) + if IS_WINDOWS + else author_name.encode("utf-8") + ), + "GIT_AUTHOR_EMAIL": ( + unicodedata.normalize("NFKD", author_email).encode( + "ascii", "ignore" + ) + if IS_WINDOWS + else author_email.encode("utf-8") + ), "GIT_AUTHOR_DATE": author_date, }, ) diff --git a/tests/test_git.py b/tests/test_git.py index faaa0fd..4b5b70f 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -1,3 +1,5 @@ +# coding=utf-8 + import imp import mock import os @@ -409,3 +411,18 @@ def test_is_cinnabar(m_git_out, git): git._cinnabar_installed = None assert not git.is_cinnabar_installed m_git_out.assert_called_once_with(["--list-cmds=main,others"]) + + +@mock.patch("mozphab.Git.git_out") +def test_unicode_in_windows_env(m_git_out, git, monkeypatch): + utf8 = "ćwikła".decode("utf-8") + asci = "cwika" + monkeypatch.setattr(mozphab, "IS_WINDOWS", True) + git._commit_tree("parent", "tree_hash", "message", utf8, utf8, "date") + m_git_out.assert_called_once_with( + ["commit-tree", "-p", "parent", "-F", mock.ANY, "tree_hash"], + split=False, + extra_env=dict( + GIT_AUTHOR_NAME=asci, GIT_AUTHOR_EMAIL=asci, GIT_AUTHOR_DATE="date" + ), + )