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: Anthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
diff --git a/git_common.py b/git_common.py
index e022ff3..24c178c 100644
--- a/git_common.py
+++ b/git_common.py
@@ -605,7 +605,7 @@
"""
with tempfile.TemporaryFile() as f:
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)
return run('mktree', '-z', stdin=f)
@@ -862,7 +862,7 @@
# nothing to commit at this point.
print('Nothing to commit; squashed branch is empty')
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
diff --git a/tests/git_common_test.py b/tests/git_common_test.py
index 30ce8cd..e042463 100755
--- a/tests/git_common_test.py
+++ b/tests/git_common_test.py
@@ -1,4 +1,5 @@
#!/usr/bin/env vpython3
+# coding=utf-8
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -6,6 +7,7 @@
"""Unit tests for git_common.py"""
from __future__ import print_function
+from __future__ import unicode_literals
import binascii
import collections
@@ -334,7 +336,8 @@
]
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')
def testRepoRoot(self):
@@ -399,8 +402,8 @@
REPO_SCHEMA = ''
def _intern_data(self, data):
- with tempfile.TemporaryFile('w') as f:
- f.write(data)
+ with tempfile.TemporaryFile('wb') as f:
+ f.write(data.encode('utf-8'))
f.seek(0)
return self.repo.run(self.gc.intern_f, f)
@@ -413,10 +416,10 @@
def testMkTree(self):
tree = {}
for i in 1, 2, 3:
- name = 'file%d' % i
+ name = '✔ file%d' % i
tree[name] = ('100644', 'blob', self._intern_data(name))
tree_hash = self.repo.run(self.gc.mktree, tree)
- self.assertEqual('37b61866d6e061c4ba478e7eb525be7b5752737d', tree_hash)
+ self.assertEqual('b524c02ba0e1cf482f8eb08c3d63e97b8895c89c', tree_hash)
def testConfig(self):
self.repo.git('config', '--add', 'happy.derpies', 'food')
@@ -671,9 +674,9 @@
self.repo.git('checkout', 'branch_K')
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':
lines.extend((self.repo[l], l, ''))
lines.pop()