Skip to content

Commit

Permalink
Bug 1572333 - Use a normalized str for GIT_AUTHOR_NAME and GIT_AUTHOR…
Browse files Browse the repository at this point in the history
…_EMAIL in Windows r=glob

Reviewers: glob

Reviewed By: glob

Bug #: 1572333

Differential Revision: https://phabricator.services.mozilla.com/D41149
  • Loading branch information
zalun committed Aug 13, 2019
1 parent 09dbc95 commit aa6770c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
17 changes: 15 additions & 2 deletions moz-phab
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import tempfile
import threading
import time
import traceback
import unicodedata
import urllib2
import urlparse
import uuid
Expand Down Expand Up @@ -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,
},
)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_git.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding=utf-8

import imp
import mock
import os
Expand Down Expand Up @@ -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"
),
)

0 comments on commit aa6770c

Please sign in to comment.