Skip to content

Commit

Permalink
Fix 'status' in newly initialized trees.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Feb 21, 2016
1 parent cf6b56c commit 3004c89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Support missing empty line after headers in Git commits and tags.
(Nicolas Dandrimont, #413)

* Fix `dulwich.porcelain.status` when used in empty trees.
(Jelmer Vernooij, #415)

0.12.0 2015-12-13

IMPROVEMENTS
Expand Down
7 changes: 6 additions & 1 deletion dulwich/porcelain.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,12 @@ def get_tree_changes(repo):
'delete': [],
'modify': [],
}
for change in index.changes_from_tree(r.object_store, r[b'HEAD'].tree):
try:
tree_id = r[b'HEAD'].tree
except KeyError:
tree_id = None

for change in index.changes_from_tree(r.object_store, tree_id):
if not change[0][0]:
tracked_changes['add'].append(change[0][1])
elif not change[0][1]:
Expand Down
7 changes: 7 additions & 0 deletions dulwich/tests/test_porcelain.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ def test_simple(self):

class StatusTests(PorcelainTestCase):

def test_empty(self):
results = porcelain.status(self.repo)
self.assertEquals(
{'add': [], 'delete': [], 'modify': []},
results.staged)
self.assertEquals([], results.unstaged)

def test_status(self):
"""Integration test for `status` functionality."""

Expand Down

0 comments on commit 3004c89

Please sign in to comment.