-
-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repository.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. |
This should fix issue #432 By the way make the code a little more robust.
@jdavid : Your change does indeed fix my issue. |
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.
The text was updated successfully, but these errors were encountered: