Browse Source

Fix fetching into MemoryRepo

Fixes #1157
Jelmer Vernooij 2 years ago
parent
commit
e83796cd94
3 changed files with 18 additions and 0 deletions
  1. 2 0
      NEWS
  2. 10 0
      dulwich/object_store.py
  3. 6 0
      dulwich/tests/test_repository.py

+ 2 - 0
NEWS

@@ -2,6 +2,8 @@
 
  * Deprecate ``dulwich.objects.parse_commit``.
 
+ * Fix fetching into MemoryRepo. (Jelmer Vernooij, #1157)
+
 0.21.3	2023-02-17
 
  * Add support for ``worktreeconfig`` extension.

+ 10 - 0
dulwich/object_store.py

@@ -1048,6 +1048,16 @@ class MemoryObjectStore(BaseObjectStore):
 
         return f, commit, abort
 
+    def add_pack_data(self, count: int, unpacked_objects: Iterator[UnpackedObject], progress=None) -> None:
+        """Add pack data to this object store.
+
+        Args:
+          count: Number of items to add
+          pack_data: Iterator over pack data tuples
+        """
+        for unpacked_object in unpacked_objects:
+            self.add_object(unpacked_object.sha_file())
+
     def add_thin_pack(self, read_all, read_some, progress=None):
         """Add a new thin pack to this object store.
 

+ 6 - 0
dulwich/tests/test_repository.py

@@ -124,6 +124,12 @@ class MemoryRepoTests(TestCase):
         r.set_description(description)
         self.assertEqual(description, r.get_description())
 
+    def test_pull_into(self):
+        r = MemoryRepo.init_bare([], {})
+        repo = open_repo("a.git")
+        self.addCleanup(tear_down_repo, repo)
+        repo.fetch(r)
+
 
 class RepositoryRootTests(TestCase):
     def mkdtemp(self):