aider icon indicating copy to clipboard operation
aider copied to clipboard

Consider switching from GitPython to another package

Open paul-gauthier opened this issue 2 years ago • 1 comments

GitPython doesn't support git repos with index version newer than v2.

https://github.com/gitpython-developers/GitPython/issues/1075

Newer versions of git can create indexes with v3 and v4:

https://git-scm.com/docs/index-format

You can work around this problem by downgrading the index format of your repo:

git update-index --index-version=2 

But it would be nice if aider used a git package that supported new index formats.

It's worth noting that dulwich currently supports v3 but not v4:

https://github.com/jelmer/dulwich/blob/master/dulwich/index.py#L309C3-L309C3

paul-gauthier avatar Oct 22 '23 22:10 paul-gauthier

  • Related/duplicate issue: #211

I’m not sure if perhaps pygit2 might be another option to support v3+

Edit I checked and it seems like it does indeed support a v3 and v4 index:

(pygit2) louis 🚶 ~/dev/seven $ qp
>>> import pygit2; r = pygit2.Repository("."); len(r.index)
13
>>>
(pygit2) louis 🚶 ~/dev/seven $ git update-index --index-version 3
(pygit2) louis 🚶 ~/dev/seven $ qp
>>> import pygit2; r = pygit2.Repository("."); len(r.index)
13
>>>
(pygit2) louis 🚶 ~/dev/seven $ git update-index --index-version 4
(pygit2) louis 🚶 ~/dev/seven $ qp
>>> import pygit2; r = pygit2.Repository("."); len(r.index)
13

I say assume: I take it the command is doing what it is supposed to. When I use GitPython it reports v2 always

(pygit2) louis 🚶 ~/dev/seven $ git update-index --index-version 2
(pygit2) louis 🚶 ~/dev/seven $ qp
>>> import git; r = git.repo.Repo("."); r.index.version
2
>>>
(pygit2) louis 🚶 ~/dev/seven $ git update-index --index-version 3
(pygit2) louis 🚶 ~/dev/seven $ qp
>>> import git; r = git.repo.Repo("."); r.index.version
2
>>>
(pygit2) louis 🚶 ~/dev/seven $ git update-index --index-version 4
(pygit2) louis 🚶 ~/dev/seven $ qp
>>> import git; r = git.repo.Repo("."); r.index.version
2

According to the format docs it should be a 4-byte integer at positions 5:8. The version is indeed changing each time (but not reliably it seems!):

(pygit2) louis 🚶 ~/dev/seven $ git update-index --index-version 2
(pygit2) louis 🚶 ~/dev/seven $ qp
>>> from pathlib import Path; int.from_bytes(Path('.git/index').read_bytes()[4:8], "big")
2
>>>
(pygit2) louis 🚶 ~/dev/seven $ git update-index --index-version 3
(pygit2) louis 🚶 ~/dev/seven $ qp
>>> from pathlib import Path; int.from_bytes(Path('.git/index').read_bytes()[4:8], "big")
2
>>>
(pygit2) louis 🚶 ~/dev/seven $ git update-index --index-version 4
(pygit2) louis 🚶 ~/dev/seven $ qp
>>> from pathlib import Path; int.from_bytes(Path('.git/index').read_bytes()[4:8], "big")
4

lmmx avatar Jul 29 '24 21:07 lmmx