Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upRepository.diff fails when treeish is "empty" #432
Comments
calling the low level method is faster anyway
|
So git is assuming that every other implementation is going to support the fake empty tree and it doesn't bother writing the actual tree it wants to use to disc? That is quite worrying. |
The representation of Tree as a sequence causes boolean coercion to consider the empty tree to be False, which is nonsensical. Override __nonzero__ for all object types to return True. This fixes libgit2#432.
|
This behaviour has nothing to do with git-core's special handling of the empty tree in some situations, or really with the Git system at all, it's purely an unfortunate decision in Python to consider that an object with a sequence interface is falsy just because the length of that aspect is zero. |
The representation of Tree as a sequence causes boolean coercion to consider the empty tree to be False, which is nonsensical. Override __nonzero__ for all object types to return True. This fixes libgit2#432.
The representation of Tree as a sequence causes boolean coercion to consider the empty tree to be False, which is nonsensical. Override __nonzero__ for all object types to return True. This fixes libgit2#432.
The representation of Tree as a sequence causes boolean coercion to consider the empty tree to be False, which is nonsensical. Override __nonzero__ for all object types to return True. This fixes libgit2#432.
|
I disagree with the solution. It is the code in Regarding the if len == 0 then falsy debate, I have not yet stop to think about it, so I don't |
|
There is by the way at least one more bug, when the input is a reference. |
|
There are more issues with this method, yes. I have a refactored version which should clear away the issue as well. |
|
PR #434 would also fix this, as well as working for references. |
|
@jdavid : Your change does indeed fix my issue. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Repository.diff contains https://github.com/libgit2/pygit2/blob/master/pygit2/repository.py#L390
This causes a subsequent failure when a is pygit2.Commit and len(a.tree) is 0, because a treeish_to_tree(a) evaluates to False in this case. Consequently, a will be the Commit object afterwards.
An example for such a commit is eb02887bc34130647a52f8152c13531d97f5a058 from https://github.com/twbs/bootstrap.git . https://stackoverflow.com/questions/9765453/gits-semi-secret-empty-tree might shed some light on the empty tree.