libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.61k stars 385 forks source link

git-show does not work for initial commits #1201

Open Hritik14 opened 1 year ago

Hritik14 commented 1 year ago

docs at https://www.pygit2.org/recipes/git-show.html suggest to diff against parent to get diff show contents. For initial commits, there are not parents, thus raising IndexError

jorio commented 1 year ago

If the commit has no parents, diff its tree against an empty tree.

if not commit.parents:
    diff = commit.tree.diff_to_tree(swap=True)
Hritik14 commented 1 year ago

@jorio It will be helpful to have this in the documentation as well. Could you please add ?