summaryrefslogtreecommitdiff
path: root/git/index
diff options
context:
space:
mode:
Diffstat (limited to 'git/index')
-rw-r--r--git/index/base.py6
-rw-r--r--git/index/fun.py4
2 files changed, 6 insertions, 4 deletions
diff --git a/git/index/base.py b/git/index/base.py
index 25ac121c..a994e7b6 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -8,7 +8,7 @@ import os
import sys
import subprocess
import glob
-from io import StringIO
+from io import BytesIO
from stat import S_ISLNK
@@ -43,6 +43,7 @@ from git.compat import (
izip,
xrange,
string_types,
+ force_bytes
)
from git.util import (
@@ -562,7 +563,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
st = os.lstat(filepath) # handles non-symlinks as well
stream = None
if S_ISLNK(st.st_mode):
- stream = StringIO(os.readlink(filepath))
+ # in PY3, readlink is string, but we need bytes. In PY2, it's just OS encoded bytes, we assume UTF-8
+ stream = BytesIO(force_bytes(os.readlink(filepath), encoding='utf-8'))
else:
stream = open(filepath, 'rb')
# END handle stream
diff --git a/git/index/fun.py b/git/index/fun.py
index 004f992e..0e49ae8d 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -12,7 +12,7 @@ from stat import (
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
-from io import StringIO
+from io import BytesIO
from git.util import IndexFileSHA1Writer
from git.exc import UnmergedEntriesError
@@ -218,7 +218,7 @@ def write_tree_from_cache(entries, odb, sl, si=0):
# END for each entry
# finally create the tree
- sio = StringIO()
+ sio = BytesIO()
tree_to_stream(tree_items, sio.write)
sio.seek(0)