8000 Merge pull request #175 from craigez/feature/handle_utf8 · gitpython-developers/GitPython@7519415 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7519415

Browse files
committed
Merge pull request #175 from craigez/feature/handle_utf8
Handling unicode arguments
2 parents 22a2103 + 8fa25b1 commit 7519415

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

git/cmd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,16 @@ def transform_kwargs(self, **kwargs):
426426
@classmethod
427427
def __unpack_args(cls, arg_list):
428428
if not isinstance(arg_list, (list,tuple)):
429+
if isinstance(arg_list, unicode):
430+
return [arg_list.encode('utf-8')]
429431
return [ str(arg_list) ]
430432

431433
outlist = list()
432434
for arg in arg_list:
433435
if isinstance(arg_list, (list, tuple)):
434436
outlist.extend(cls.__unpack_args( arg ))
437+
elif isinstance(arg_list, unicode):
438+
outlist.append(arg_list.encode('utf-8'))
435439
# END recursion
436440
else:
437441
outlist.append(str(arg))

git/test/test_cmd.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import os, sys
88
from git.test.lib import (
9-
TestBase,
10-
patch,
9+
TestBase,
10+
patch,
1111
raises,
1212
assert_equal,
1313
assert_true,
@@ -17,7 +17,7 @@
1717
from git import Git, GitCommandError
1818

1919
class TestGit(TestBase):
20-
20+
2121
@classmethod
2222
def setUp(cls):
2323
super(TestGit, cls).setUp()
@@ -30,6 +30,14 @@ def test_call_process_calls_execute(self, git):
3030
assert_true(git.called)
3131
assert_equal(git.call_args, ((['git', 'version'],), {}))
3232

33+
def test_call_unpack_args_unicode(self):
34+
args = Git._Git__unpack_args(u'Unicode' + unichr(40960))
35+
assert_equal(args, ['Unicode\xea\x80\x80'])
36+
37+
def test_call_unpack_args(self):
38+
args = Git._Git__unpack_args(['git', 'log', '--', u'Unicode' + unichr(40960)])
39+
assert_equal(args, ['git', 'log', '--', 'Unicode\xea\x80\x80'])
40+
3341
@raises(GitCommandError)
3442
def test_it_raises_errors(self):
3543
self.git.this_does_not_exist()
@@ -59,7 +67,7 @@ def test_it_ignores_false_kwargs(self, git):
5967
# this_should_not_be_ignored=False implies it *should* be ignored
6068
output = self.git.version(pass_this_kwarg=False)
6169
assert_true("pass_this_kwarg" not in git.call_args[1])
62-
70+
6371
def test_persistent_cat_file_command(self):
6472
# read header only
6573
import subprocess as sp
@@ -68,37 +76,37 @@ def test_persistent_cat_file_command(self):
6876
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
6977
g.stdin.flush()
7078
obj_info = g.stdout.readline()
71-
79+
7280
# read header + data
7381
g = self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True)
7482
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
7583
g.stdin.flush()
7684
obj_info_two = g.stdout.readline()
7785
assert obj_info == obj_info_two
78-
86+
7987
# read data - have to read it in one large chunk
8088
size = int(obj_info.split()[2])
8189
data = g.stdout.read(size)
8290
terminating_newline = g.stdout.read(1)
83-
91+
8492
# now we should be able to read a new object
8593
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
8694
g.stdin.flush()
8795
assert g.stdout.readline() == obj_info
88-
89-
96+
97+
9098
# same can be achived using the respective command functions
9199
hexsha, typename, size = self.git.get_object_header(hexsha)
92100
hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
93101
assert typename == typename_two and size == size_two
94-
102+
95103
def test_version(self):
96104
v = self.git.version_info
97105
assert isinstance(v, tuple)
98106
for n in v:
99107
assert isinstance(n, int)
100108
#END verify number types
101-
109+
102110
def test_cmd_override(self):
103111
prev_cmd = self.git.GIT_PYTHON_GIT_EXECUTABLE
104112
try:
@@ -108,7 +116,7 @@ def test_cmd_override(self):
108116
finally:
109117
type(self.git).GIT_PYTHON_GIT_EXECUTABLE = prev_cmd
110118
#END undo adjustment
111-
119+
112120
def test_output_strip(self):
113121
import subprocess as sp
114122
hexsha = "b2339455342180c7cc1e9bba3e9f181f7baa5167"

0 commit comments

Comments
 (0)
0