Prechádzať zdrojové kódy

Fix TypeError when handling bytes paths in FileSystemBackend

Fixes #973
Jelmer Vernooij 1 mesiac pred
rodič
commit
bac792ba6a
3 zmenil súbory, kde vykonal 16 pridanie a 0 odobranie
  1. 3 0
      NEWS
  2. 4 0
      dulwich/server.py
  3. 9 0
      tests/test_server.py

+ 3 - 0
NEWS

@@ -3,6 +3,9 @@
  * Support dumb repository access.
    (Jelmer Vernooij, #1097)
 
+ * Fix TypeError when cloning repositories with bytes paths on Windows.
+   (Jelmer Vernooij, #973)
+
  * Support ``depth`` for local clones.
    (Jelmer Vernooij)
 

+ 4 - 0
dulwich/server.py

@@ -201,6 +201,10 @@ class FileSystemBackend(Backend):
 
     def open_repository(self, path):
         logger.debug("opening repository at %s", path)
+        # Ensure path is a string to avoid TypeError when joining with self.root
+        path = os.fspath(path)
+        if isinstance(path, bytes):
+            path = os.fsdecode(path)
         abspath = os.path.abspath(os.path.join(self.root, path)) + os.sep
         normcase_abspath = os.path.normcase(abspath)
         normcase_root = os.path.normcase(self.root)

+ 9 - 0
tests/test_server.py

@@ -1092,6 +1092,15 @@ class FileSystemBackendTests(TestCase):
 
         self.assertRaises(NotGitRepository, lambda: backend.open_repository("/ups"))
 
+    def test_bytes_path(self) -> None:
+        # Test that FileSystemBackend can handle bytes paths (issue #973)
+        repo = self.backend.open_repository(self.path.encode("utf-8"))
+        self.assertTrue(
+            os.path.samefile(
+                os.path.abspath(repo.path), os.path.abspath(self.repo.path)
+            )
+        )
+
 
 class DictBackendTests(TestCase):
     """Tests for DictBackend."""