pygit2 icon indicating copy to clipboard operation
pygit2 copied to clipboard

git-show does not work for initial commits

Open Hritik14 opened this issue 2 years ago • 2 comments

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

Hritik14 avatar Mar 24 '23 11:03 Hritik14

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)

jorio avatar Mar 26 '23 11:03 jorio

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

Hritik14 avatar Apr 03 '23 13:04 Hritik14