libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.58k stars 382 forks source link

Fix Submodule.open() if parent repo is instance of Repository subclass #1295

Closed jorio closed 1 month ago

jorio commented 1 month ago

Submodule.open() fails if the submodule was created from a subclass of Repository.

For example:

class CustomRepoClass(pygit2.Repository):
    pass
r = CustomRepoClass("some-repo")
s = r.submodules["submodule-name"].open()

# Traceback (most recent call last):
#   (...snip...)
#   File "pygit2/submodules.py", line 60, in open
#     return self._repo._from_c(crepo[0], True)
#   File "pygit2/repository.py", line 1551, in _from_c
#     super(cls, repo)._from_c(bytes(ffi.buffer(cptr)[:]), owned)
#   File "pygit2/repository.py", line 1549, in _from_c
#     cptr[0] = ptr
# TypeError: initializer for ctype 'struct git_repository *' must be a cdata pointer, not bytes

This PR fixes this issue.