Skip to content

Commit 3cb206d

Browse files
committed
fix: handle missing HEAD commit in IndexFile.diff(None) for new repos
1 parent 356e549 commit 3cb206d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

git/index/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,4 +1568,9 @@ def diff(
15681568
raise ValueError("other must be None, Diffable.INDEX, a Tree or Commit, was %r" % other)
15691569

15701570
# Diff against working copy - can be handled by superclass natively.
1571-
return super().diff(other, paths, create_patch, **kwargs)
1571+
try:
1572+
self.repo.head.commit
1573+
return super().diff(other, paths, create_patch, **kwargs)
1574+
except ValueError:
1575+
# No commits yet - diff against null tree instead
1576+
return self.diff(git_diff.NULL_TREE, paths, create_patch, **kwargs)

0 commit comments

Comments
 (0)