Sfoglia il codice sorgente

Merge branch 'master' into fix-main

Jelmer Vernooij 3 settimane fa
parent
commit
3a6792685d
2 ha cambiato i file con 12 aggiunte e 2 eliminazioni
  1. 6 2
      dulwich/objects.py
  2. 6 0
      tests/test_object_store.py

+ 6 - 2
dulwich/objects.py

@@ -44,9 +44,9 @@ if sys.version_info >= (3, 11):
 else:
     from typing_extensions import Self
 
-try:
+if sys.version_info >= (3, 10):
     from typing import TypeGuard  # type: ignore
-except ImportError:
+else:
     from typing_extensions import TypeGuard
 
 from . import replace_me
@@ -1313,6 +1313,10 @@ class Tree(ShaFile):
           path: Path to lookup
         Returns: A tuple of (mode, SHA) of the resulting path.
         """
+        # Handle empty path - return the tree itself
+        if not path:
+            return stat.S_IFDIR, self.id
+
         parts = path.split(b"/")
         sha = self.id
         mode: Optional[int] = None

+ 6 - 0
tests/test_object_store.py

@@ -826,6 +826,12 @@ class TreeLookupPathTests(TestCase):
             b"ad/b/j",
         )
 
+    def test_lookup_empty_path(self) -> None:
+        # Empty path should return the tree itself
+        mode, sha = tree_lookup_path(self.get_object, self.tree_id, b"")
+        self.assertEqual(sha, self.tree_id)
+        self.assertEqual(mode, stat.S_IFDIR)
+
 
 class ObjectStoreGraphWalkerTests(TestCase):
     def get_walker(self, heads, parent_map):