summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/index/fun.py5
-rw-r--r--git/test/test_index.py13
2 files changed, 16 insertions, 2 deletions
diff --git a/git/index/fun.py b/git/index/fun.py
index 9ae46861..c1026fd6 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -41,7 +41,8 @@ from gitdb.base import IStream
from gitdb.typ import str_tree_type
from git.compat import (
defenc,
- force_text
+ force_text,
+ force_bytes
)
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
@@ -124,7 +125,7 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
write(entry[4]) # ctime
write(entry[5]) # mtime
path = entry[3]
- path = path.encode(defenc)
+ path = force_bytes(path, encoding=defenc)
plen = len(path) & CE_NAMEMASK # path length
assert plen == len(path), "Path %s too long to fit into index" % entry[3]
flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values
diff --git a/git/test/test_index.py b/git/test/test_index.py
index 2fd53f65..39788575 100644
--- a/git/test/test_index.py
+++ b/git/test/test_index.py
@@ -18,6 +18,7 @@ from git.exc import (
)
from git import (
IndexFile,
+ Repo,
BlobFilter,
UnmergedEntriesError,
Tree,
@@ -45,6 +46,7 @@ from git.index.typ import (
IndexEntry
)
from git.index.fun import hook_path
+from gitdb.test.lib import with_rw_directory
class TestIndex(TestBase):
@@ -780,3 +782,14 @@ class TestIndex(TestBase):
except InvalidGitRepositoryError:
asserted = True
assert asserted, "Adding using a filename is not correctly asserted."
+
+ @with_rw_directory
+ def test_add_utf8P_path(self, rw_dir):
+ # NOTE: fp is not a Unicode object in python 2 (which is the source of the problem)
+ fp = os.path.join(rw_dir, 'ø.txt')
+ with open(fp, 'w') as fs:
+ fs.write('content of ø')
+
+ r = Repo.init(rw_dir)
+ r.index.add([fp])
+ r.index.commit('Added orig and prestable')