libgit2/pygit2

Passing checkout_branch to pygit2.clone_repository() triggers a fatal error

djmattyg007 opened this issue · 4 comments

Whenever I try and clone any repository with something like the following command:

repo = pygit2.clone_repository(url="file:///srv/samba/files/programming/cli/modman-test", path="/tmp/modman")

The entire contents of the repo are staged for deletion.

I tried to get around this by passing 'checkout_branch="master"' to the clone_repository() function (as this fixes the issue just fine when I run 'git checkout master' from my shell), but that triggers a fatal error.

Which error? Which is the active branch in the source repository?

The active branch is master. This is line of code I'm trying to run:

repo = pygit2.clone_repository(url="file:///srv/samba/files/programming/cli/modman-test", path="/tmp/modman", checkout_branch="master")

And this is the full error I get:

Traceback (most recent call last):
File "modman.py", line 8, in <module>
repo = git.clone_repository(url="file:///srv/samba/files/programming/cli/modman-test", path="/tmp/modman", checkout_branch="master")
File "/usr/lib/python3.4/site-packages/pygit2/__init__.py", line 156, in clone_repository
checkout_branch_ref = ffi.new('char []', branch)
File "/usr/lib/python3.4/site-packages/cffi/api.py", line 225, in new
return self._backend.newp(cdecl, init)
TypeError: initializer for ctype 'char[]' must be a bytes or list or tuple, not str

I've just discovered that the "test_clone_checkout_branch" test in the repository test suite is commented out because it's broken, which probably explains why this use case isn't working for me.

I feel like the documentation should be updated to reflect this until it is fixed, as it can be quite frustrating for someone who doesn't know.

The test is commented out for a different reason, explained in the comment block. As you can see from the error message, the issue here is down to a type mismatch, which looks like a missing to_bytes() when setting up the struct.