Commit 71681bf1 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

git-common: Explicitly specify utf-8 when encoding.

Bug: 1012773
Change-Id: I95006ce78b4473c8fb435162089a787b57c0f835
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1850926
Auto-Submit: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent aeee6a83
...@@ -605,7 +605,7 @@ def mktree(treedict): ...@@ -605,7 +605,7 @@ def mktree(treedict):
""" """
with tempfile.TemporaryFile() as f: with tempfile.TemporaryFile() as f:
for name, (mode, typ, ref) in treedict.items(): for name, (mode, typ, ref) in treedict.items():
f.write(('%s %s %s\t%s\0' % (mode, typ, ref, name)).encode()) f.write(('%s %s %s\t%s\0' % (mode, typ, ref, name)).encode('utf-8'))
f.seek(0) f.seek(0)
return run('mktree', '-z', stdin=f) return run('mktree', '-z', stdin=f)
...@@ -862,7 +862,7 @@ def squash_current_branch(header=None, merge_base=None): ...@@ -862,7 +862,7 @@ def squash_current_branch(header=None, merge_base=None):
# nothing to commit at this point. # nothing to commit at this point.
print('Nothing to commit; squashed branch is empty') print('Nothing to commit; squashed branch is empty')
return False return False
run('commit', '--no-verify', '-a', '-F', '-', indata=log_msg.encode()) run('commit', '--no-verify', '-a', '-F', '-', indata=log_msg.encode('utf-8'))
return True return True
......
#!/usr/bin/env vpython3 #!/usr/bin/env vpython3
# coding=utf-8
# Copyright 2013 The Chromium Authors. All rights reserved. # Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -6,6 +7,7 @@ ...@@ -6,6 +7,7 @@
"""Unit tests for git_common.py""" """Unit tests for git_common.py"""
from __future__ import print_function from __future__ import print_function
from __future__ import unicode_literals
import binascii import binascii
import collections import collections
...@@ -334,7 +336,8 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase, ...@@ -334,7 +336,8 @@ class GitReadOnlyFunctionsTest(git_test_utils.GitRepoReadOnlyTestBase,
] ]
self.assertEqual(ret, [binascii.unhexlify(h) for h in hashes]) self.assertEqual(ret, [binascii.unhexlify(h) for h in hashes])
with self.assertRaisesRegexp(Exception, r"one of \('master', 'bananas'\)"): expected_re = r"one of \(u?'master', u?'bananas'\)"
with self.assertRaisesRegexp(Exception, expected_re):
self.repo.run(self.gc.parse_commitrefs, 'master', 'bananas') self.repo.run(self.gc.parse_commitrefs, 'master', 'bananas')
def testRepoRoot(self): def testRepoRoot(self):
...@@ -399,8 +402,8 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase, ...@@ -399,8 +402,8 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
REPO_SCHEMA = '' REPO_SCHEMA = ''
def _intern_data(self, data): def _intern_data(self, data):
with tempfile.TemporaryFile('w') as f: with tempfile.TemporaryFile('wb') as f:
f.write(data) f.write(data.encode('utf-8'))
f.seek(0) f.seek(0)
return self.repo.run(self.gc.intern_f, f) return self.repo.run(self.gc.intern_f, f)
...@@ -413,10 +416,10 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase, ...@@ -413,10 +416,10 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
def testMkTree(self): def testMkTree(self):
tree = {} tree = {}
for i in 1, 2, 3: for i in 1, 2, 3:
name = 'file%d' % i name = 'file%d' % i
tree[name] = ('100644', 'blob', self._intern_data(name)) tree[name] = ('100644', 'blob', self._intern_data(name))
tree_hash = self.repo.run(self.gc.mktree, tree) tree_hash = self.repo.run(self.gc.mktree, tree)
self.assertEqual('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash) self.assertEqual('b524c02ba0e1cf482f8eb08c3d63e97b8895c89c', tree_hash)
def testConfig(self): def testConfig(self):
self.repo.git('config', '--add', 'happy.derpies', 'food') self.repo.git('config', '--add', 'happy.derpies', 'food')
...@@ -671,9 +674,9 @@ class GitMutableStructuredTest(git_test_utils.GitRepoReadWriteTestBase, ...@@ -671,9 +674,9 @@ class GitMutableStructuredTest(git_test_utils.GitRepoReadWriteTestBase,
self.repo.git('checkout', 'branch_K') self.repo.git('checkout', 'branch_K')
self.assertEqual( self.assertEqual(
True, self.repo.run(self.gc.squash_current_branch, 'cool message')) True, self.repo.run(self.gc.squash_current_branch, 'cool message'))
lines = ['cool message', ''] lines = ['cool message', '']
for l in 'HIJK': for l in 'HIJK':
lines.extend((self.repo[l], l, '')) lines.extend((self.repo[l], l, ''))
lines.pop() lines.pop()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment