Skip to content

Commit 6404168

Browse files
committed
Merge pull request #200 from dbaxa/0.3-with-unicode-fixes
0.3 with unicode fixes
2 parents 27c577d + c390e22 commit 6404168

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

‎.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "gitdb"]
22
path = git/ext/gitdb
3-
url = http://github.com/gitpython-developers/gitdb.git
3+
url = https://github.com/gitpython-developers/gitdb.git

‎git/cmd.py

+4
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,16 @@ def transform_kwargs(self, split_single_char_options=False, **kwargs):
410410
@classmethod
411411
def __unpack_args(cls, arg_list):
412412
if not isinstance(arg_list, (list,tuple)):
413+
if isinstance(arg_list, unicode):
414+
return [arg_list.encode('utf-8')]
413415
return [ str(arg_list) ]
414416

415417
outlist = list()
416418
for arg in arg_list:
417419
if isinstance(arg_list, (list, tuple)):
418420
outlist.extend(cls.__unpack_args( arg ))
421+
elif isinstance(arg_list, unicode):
422+
outlist.append(arg_list.encode('utf-8'))
419423
# END recursion
420424
else:
421425
outlist.append(str(arg))

‎git/repo/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def commit(self, rev=None):
376376
if rev is None:
377377
return self.head.commit
378378
else:
379-
return self.rev_parse(str(rev)+"^0")
379+
return self.rev_parse(unicode(rev)+"^0")
380380

381381
def iter_trees(self, *args, **kwargs):
382382
""":return: Iterator yielding Tree objects
@@ -399,7 +399,7 @@ def tree(self, rev=None):
399399
if rev is None:
400400
return self.head.commit.tree
401401
else:
402-
return self.rev_parse(str(rev)+"^{tree}")
402+
return self.rev_parse(unicode(rev)+"^{tree}")
403403

404404
def iter_commits(self, rev=None, paths='', **kwargs):
405405
"""A list of Commit objects representing the history of a given ref/commit

‎git/test/test_git.py

+20-11
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

77
import os, sys
8-
from git.test.lib import ( TestBase,
9-
patch,
8+
from git.test.lib import (
9+
TestBase,
10+
patch,
1011
raises,
1112
assert_equal,
1213
assert_true,
@@ -16,7 +17,7 @@
1617
GitCommandError )
1718

1819
class TestGit(TestBase):
19-
20+
2021
@classmethod
2122
def setUp(cls):
2223
super(TestGit, cls).setUp()
@@ -29,6 +30,14 @@ def test_call_process_calls_execute(self, git):
2930
assert_true(git.called)
3031
assert_equal(git.call_args, ((['git', 'version'],), {}))
3132

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+
3241
@raises(GitCommandError)
3342
def test_it_raises_errors(self):
3443
self.git.this_does_not_exist()
@@ -58,7 +67,7 @@ def test_it_ignores_false_kwargs(self, git):
5867
# this_should_not_be_ignored=False implies it *should* be ignored
5968
output = self.git.version(pass_this_kwarg=False)
6069
assert_true("pass_this_kwarg" not in git.call_args[1])
61-
70+
6271
def test_persistent_cat_file_command(self):
6372
# read header only
6473
import subprocess as sp
@@ -67,37 +76,37 @@ def test_persistent_cat_file_command(self):
6776
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
6877
g.stdin.flush()
6978
obj_info = g.stdout.readline()
70-
79+
7180
# read header + data
7281
g = self.git.cat_file(batch=True, istream=sp.PIPE,as_process=True)
7382
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
7483
g.stdin.flush()
7584
obj_info_two = g.stdout.readline()
7685
assert obj_info == obj_info_two
77-
86+
7887
# read data - have to read it in one large chunk
7988
size = int(obj_info.split()[2])
8089
data = g.stdout.read(size)
8190
terminating_newline = g.stdout.read(1)
82-
91+
8392
# now we should be able to read a new object
8493
g.stdin.write("b2339455342180c7cc1e9bba3e9f181f7baa5167\n")
8594
g.stdin.flush()
8695
assert g.stdout.readline() == obj_info
87-
88-
96+
97+
8998
# same can be achived using the respective command functions
9099
hexsha, typename, size = self.git.get_object_header(hexsha)
91100
hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha)
92101
assert typename == typename_two and size == size_two
93-
102+
94103
def test_version(self):
95104
v = self.git.version_info
96105
assert isinstance(v, tuple)
97106
for n in v:
98107
assert isinstance(n, int)
99108
#END verify number types
100-
109+
101110
def test_cmd_override(self):
102111
prev_cmd = self.git.GIT_PYTHON_GIT_EXECUTABLE
103112
try:

0 commit comments

Comments
 (0)