Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix index.changes_from_tree against a repository with no initial commit. #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions dulwich/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,22 +354,24 @@ def changes_from_tree(names, lookup_entry, object_store, tree,
:param names: Iterable of names in the working copy
:param lookup_entry: Function to lookup an entry in the working copy
:param object_store: Object store to use for retrieving tree contents
:param tree: SHA1 of the root tree
:param tree: SHA1 of the root tree, or None for an empty tree
:param want_unchanged: Whether unchanged files should be reported
:return: Iterator over tuples with (oldpath, newpath), (oldmode, newmode),
(oldsha, newsha)
"""
other_names = set(names)
for (name, mode, sha) in object_store.iter_tree_contents(tree):
try:
(other_sha, other_mode) = lookup_entry(name)
except KeyError:
# Was removed
yield ((name, None), (mode, None), (sha, None))
else:
other_names.remove(name)
if (want_unchanged or other_sha != sha or other_mode != mode):
yield ((name, name), (mode, other_mode), (sha, other_sha))

if tree is not None:
for (name, mode, sha) in object_store.iter_tree_contents(tree):
try:
(other_sha, other_mode) = lookup_entry(name)
except KeyError:
# Was removed
yield ((name, None), (mode, None), (sha, None))
else:
other_names.remove(name)
if (want_unchanged or other_sha != sha or other_mode != mode):
yield ((name, name), (mode, other_mode), (sha, other_sha))

# Mention added files
for name in other_names:
Expand Down
7 changes: 7 additions & 0 deletions dulwich/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def test_empty(self):
self.assertEqual(0, len(i))
self.assertFalse(os.path.exists(i._filename))

def test_against_empty_tree(self):
i = self.get_simple_index("index")
changes = list(i.changes_from_tree(MemoryObjectStore(), None))
self.assertEqual(1, len(changes))
(oldname, newname), (oldmode, newmode), (oldsha, newsha) = changes[0]
self.assertEqual('bla', newname)
self.assertEqual('e69de29bb2d1d6434b8b29ae775ad8c2e48c5391', newsha)

class SimpleIndexWriterTestCase(IndexTestCase):

Expand Down