Fedora's fedpkg [1] is using GitPython in background, but unfortunately, this usage corrupts the Git repository in a way, that added files [2] always stays in staging and they never get commit. Is there any chance you could help fix this issue?
I have seen this too, but in conjunction with submodules. GitPython writes the index itself, and apparently it doesn't write back the expected format.
A workaround, as described there, is rewriting the index using something like git reset HEAD. The problem certainly occours when using repo.index.add(...), as this one will rewrite the index. As a quick fix, one could forcefully use the git command for this in the downstream source, such as in repo.git.add(...).
Can you point me to code (e.g. bash) that helps me reproducing this, and the original source code of fedpkg ? If I can reproduce it, I can certainly fix it.
$ fedpkg co GitPython --anonymous # --anonymous in case you are not Fedora contributor ;)
$ cd GitPython
$ vim GitPython.spec # and do some editing.
$ fedpkg srpm
$ fedpkg import GitPython-0.3.2-0.7.RC1.fc23.src.rpm
fedpkg [1] is just thin wrapper abouve pyrpkg, so this [2] should be the place where the index is modified after fedpkg import
Thank you - it's about time that bug gets squashed. I will dedicate my time tomorrow, in favour of finishing other work today.
Thanks to the workarounds we have, there are options in case this is not fast enough.
Besides: My apologies - after all, that one could have been fixed earlier.
It turned out that the index is not actually corrupted, which is good news. What happens is that git writes TREE extension data into the index, which causes it to write out the given tree as is next time a git commit is executed. When using git add, this extension data is maintained automatically. However, GitPython doesn't do that ... . Usually this is no problem at all, as you are supposed to use IndexFile.commit(...) along with IndexFile.add(...).
Thanks to a shortcoming in the GitPython API, the index was automatically written out whenever files have been added, without providing control over whether or not extension data will be written along with it.
My fix consists of an additional flag in IndexFile.add(...), which causes extension data not to be written by default, so commits can be safely done via git commit or IndexFile.commit(...).
However, this might introduce new subtle bugs in case someone is relying on extension data to be written. As this can be controlled through the said flag though, a fix is easily done in that case.
How to apply the fix to your codebase
Use GitPython v0.3.7 (due for release this week)
use git add instead of IndexFile.add(...)
use IndexFile.commit(...) instead of git commit
Unfortunately, there is no other way to make it work with older versions of GitPython, as there is yet another bug in IndexFile.write(...) which would cause extension data to written even if that was explicitly disabled. It is fixed in v0.3.7 .
Wow, thanks for fixing this. Hope it will be fixed in Fedora soon (right @pbabinca ? 😉 )
And thanks especially for the video with analysis. Shame I don't have time to watch it (I watched just first 5 minutes). It would be definitely enlightening. BTW the "Session 2" video is private ;)
Hehe, it's only the most-hardcore people who have the time and are willing to watch me do my thing for two hours ... no one will do that, yet it's good to archive the process of fixing issues just in case I will be wondering why the heck I fixed it the way I did :).
The second video just wasn't ready yet - it works now, and youtube probably said it's still being processed when you tried it.
Activity
Byron commented on Mar 2, 2015
I have seen this too, but in conjunction with submodules. GitPython writes the index itself, and apparently it doesn't write back the expected format.
A workaround, as described there, is rewriting the index using something like git reset HEAD. The problem certainly occours when using repo.index.add(...), as this one will rewrite the index. As a quick fix, one could forcefully use the git command for this in the downstream source, such as in repo.git.add(...).
Can you point me to code (e.g. bash) that helps me reproducing this, and the original source code of fedpkg ? If I can reproduce it, I can certainly fix it.
Thank you
voxik commented on Mar 2, 2015
Thank you very much.
This should be the steps:
fedpkg [1] is just thin wrapper abouve pyrpkg, so this [2] should be the place where the index is modified after fedpkg import
[1] https://git.fedorahosted.org/cgit/fedpkg.git/tree/
[2] https://git.fedorahosted.org/cgit/rpkg.git/tree/src/pyrpkg/__init__.py#n1425
Byron commented on Mar 2, 2015
Thank you - it's about time that bug gets squashed. I will dedicate my time tomorrow, in favour of finishing other work today.
Thanks to the workarounds we have, there are options in case this is not fast enough.
Besides: My apologies - after all, that one could have been fixed earlier.
voxik commented on Mar 2, 2015
Thanks a lot. pyrpkg maintainer is now aware about the repo.git.add workaround, so he might apply it as well.
Byron commented on Apr 8, 2015
It turned out that the index is not actually corrupted, which is good news. What happens is that git writes TREE extension data into the index, which causes it to write out the given tree as is next time a git commit is executed. When using git add, this extension data is maintained automatically. However, GitPython doesn't do that ... . Usually this is no problem at all, as you are supposed to use IndexFile.commit(...) along with IndexFile.add(...).
Thanks to a shortcoming in the GitPython API, the index was automatically written out whenever files have been added, without providing control over whether or not extension data will be written along with it.
My fix consists of an additional flag in IndexFile.add(...), which causes extension data not to be written by default, so commits can be safely done via git commit or IndexFile.commit(...).
However, this might introduce new subtle bugs in case someone is relying on extension data to be written. As this can be controlled through the said flag though, a fix is easily done in that case.
How to apply the fix to your codebase
Unfortunately, there is no other way to make it work with older versions of GitPython, as there is yet another bug in IndexFile.write(...) which would cause extension data to written even if that was explicitly disabled. It is fixed in v0.3.7 .
YouTube
The development stream can be watched on youtube
test(index): test for #265
voxik commented on Apr 8, 2015
Wow, thanks for fixing this. Hope it will be fixed in Fedora soon (right @pbabinca ? 😉 )
And thanks especially for the video with analysis. Shame I don't have time to watch it (I watched just first 5 minutes). It would be definitely enlightening. BTW the "Session 2" video is private ;)
Byron commented on Apr 8, 2015
Hehe, it's only the most-hardcore people who have the time and are willing to watch me do my thing for two hours ... no one will do that, yet it's good to archive the process of fixing issues just in case I will be wondering why the heck I fixed it the way I did :).
The second video just wasn't ready yet - it works now, and youtube probably said it's still being processed when you tried it.
reduce git corruption issues