Dulwich.io dulwich / 935aa67
Fix index.changes_from_tree against an empty tree. index.changes_from_tree(object_store, None) should work. Modify that function so the 'tree' argument can be None to signify an empty tree. Signed-off-by: Jelmer Vernooij <jelmer@samba.org> kwatters authored 7 years ago Jelmer Vernooij committed 6 years ago
2 changed file(s) with 20 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
354354 :param names: Iterable of names in the working copy
355355 :param lookup_entry: Function to lookup an entry in the working copy
356356 :param object_store: Object store to use for retrieving tree contents
357 :param tree: SHA1 of the root tree
357 :param tree: SHA1 of the root tree, or None for an empty tree
358358 :param want_unchanged: Whether unchanged files should be reported
359359 :return: Iterator over tuples with (oldpath, newpath), (oldmode, newmode),
360360 (oldsha, newsha)
361361 """
362362 other_names = set(names)
363 for (name, mode, sha) in object_store.iter_tree_contents(tree):
364 try:
365 (other_sha, other_mode) = lookup_entry(name)
366 except KeyError:
367 # Was removed
368 yield ((name, None), (mode, None), (sha, None))
369 else:
370 other_names.remove(name)
371 if (want_unchanged or other_sha != sha or other_mode != mode):
372 yield ((name, name), (mode, other_mode), (sha, other_sha))
363
364 if tree is not None:
365 for (name, mode, sha) in object_store.iter_tree_contents(tree):
366 try:
367 (other_sha, other_mode) = lookup_entry(name)
368 except KeyError:
369 # Was removed
370 yield ((name, None), (mode, None), (sha, None))
371 else:
372 other_names.remove(name)
373 if (want_unchanged or other_sha != sha or other_mode != mode):
374 yield ((name, name), (mode, other_mode), (sha, other_sha))
373375
374376 # Mention added files
375377 for name in other_names:
7575 self.assertEqual(0, len(i))
7676 self.assertFalse(os.path.exists(i._filename))
7777
78 def test_against_empty_tree(self):
79 i = self.get_simple_index("index")
80 changes = list(i.changes_from_tree(MemoryObjectStore(), None))
81 self.assertEqual(1, len(changes))
82 (oldname, newname), (oldmode, newmode), (oldsha, newsha) = changes[0]
83 self.assertEqual('bla', newname)
84 self.assertEqual('e69de29bb2d1d6434b8b29ae775ad8c2e48c5391', newsha)
7885
7986 class SimpleIndexWriterTestCase(IndexTestCase):
8087