Support bytes paths in dulwich.index.
authorJelmer Vernooij <jelmer@jelmer.uk>
Wed, 25 Jul 2018 18:01:57 +0000 (19:01 +0100)
committerJelmer Vernooij <jelmer@jelmer.uk>
Wed, 25 Jul 2018 18:01:57 +0000 (19:01 +0100)
dulwich/index.py

index 20daa5971ea816a4a506f7d8d1fd22689a40a536..f1a49f7e2cfbc4a01404719187cbcba0c91b8e8c 100644 (file)
@@ -590,6 +590,10 @@ def read_submodule_head(path):
     """
     from dulwich.errors import NotGitRepository
     from dulwich.repo import Repo
+    # Repo currently expects a "str", so decode if necessary.
+    # TODO(jelmer): Perhaps move this into Repo() ?
+    if not isinstance(path, str):
+        path = path.decode(sys.getfilesystemencoding())
     try:
         repo = Repo(path)
     except NotGitRepository:
@@ -690,12 +694,13 @@ def index_entry_from_path(path, object_store=None):
         save new blobs in
     :return: An index entry
     """
+    assert isinstance(path, bytes)
     try:
         st = os.lstat(path)
         blob = blob_from_path_and_stat(path, st)
     except EnvironmentError as e:
         if e.errno == errno.EISDIR:
-            if os.path.exists(os.path.join(path, '.git')):
+            if os.path.exists(os.path.join(path, b'.git')):
                 head = read_submodule_head(path)
                 if head is None:
                     return None