summaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
Diffstat (limited to 'git')
-rw-r--r--git/objects/commit.py25
-rw-r--r--git/test/test_base.py11
2 files changed, 20 insertions, 16 deletions
diff --git a/git/objects/commit.py b/git/objects/commit.py
index 79d460ad..5ad7902b 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -373,40 +373,33 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
def _serialize(self, stream):
write = stream.write
- write("tree %s\n" % self.tree)
+ write(("tree %s\n" % self.tree).encode('ascii'))
for p in self.parents:
- write("parent %s\n" % p)
+ write(("parent %s\n" % p).encode('ascii'))
a = self.author
aname = a.name
- if isinstance(aname, text_type):
- aname = aname.encode(self.encoding)
- # END handle unicode in name
-
c = self.committer
fmt = "%s %s <%s> %s %s\n"
- write(fmt % ("author", aname, a.email,
+ write((fmt % ("author", aname, a.email,
self.authored_date,
- altz_to_utctz_str(self.author_tz_offset)))
+ altz_to_utctz_str(self.author_tz_offset))).encode(self.encoding))
# encode committer
aname = c.name
- if isinstance(aname, text_type):
- aname = aname.encode(self.encoding)
- # END handle unicode in name
- write(fmt % ("committer", aname, c.email,
+ write((fmt % ("committer", aname, c.email,
self.committed_date,
- altz_to_utctz_str(self.committer_tz_offset)))
+ altz_to_utctz_str(self.committer_tz_offset))).encode(self.encoding))
if self.encoding != self.default_encoding:
- write("encoding %s\n" % self.encoding)
+ write(("encoding %s\n" % self.encoding).encode('ascii'))
if self.gpgsig:
write("gpgsig")
for sigline in self.gpgsig.rstrip("\n").split("\n"):
- write(" " + sigline + "\n")
+ write((" " + sigline + "\n").encode('ascii'))
- write("\n")
+ write(b"\n")
# write plain bytes, be sure its encoded according to our encoding
if isinstance(self.message, text_type):
diff --git a/git/test/test_base.py b/git/test/test_base.py
index a14d4680..edacbd80 100644
--- a/git/test/test_base.py
+++ b/git/test/test_base.py
@@ -1,3 +1,4 @@
+#-*-coding:utf-8-*-
# test_base.py
# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
#
@@ -106,3 +107,13 @@ class TestBase(TestBase):
assert not rw_repo.config_reader("repository").getboolean("core", "bare")
assert rw_remote_repo.config_reader("repository").getboolean("core", "bare")
assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib'))
+
+ @with_rw_repo('0.1.6')
+ def test_add_unicode(self, rw_repo):
+ filename = u"שלום.txt"
+
+ file_path = os.path.join(rw_repo.working_dir, filename)
+ open(file_path, "wb").write('something')
+
+ rw_repo.git.add(rw_repo.working_dir)
+ rw_repo.index.commit('message')