libgit2 / pygit2

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

Push options support within pygit2 #1126

Closed kuwv closed 3 months ago

kuwv commented 2 years ago

I am trying to determine how to use git_push_options with a remote push. I'm unable to find any documentation, tests or working examples.

My goal is to implement something similar to git using the following: git push --push-option somevar=someval

What I have gleaned from the remote.py context manager is that I probably need to pass libgit2 custom_headers parameter. But, I'm not sure if I'm missing something or just off base.


class CustomRemoteCallbacks(RemoteCallbacks):
    """Provide callback with push options."""

    def __init__(
        self,
        credentials: Optional[Credentials] = None,
        certificate: Optional[Certificate] = None,
        **kwargs: Any,
    ) -> None:
        """Initialize remote callback with custom headers."""
        super().__init__(credentials=credentials, certificate=certificate)
        self.custom_headers = [f"{k}={v}" for k, v in kwargs.items()]
kuwv commented 2 years ago

I guess I'll try to solve this.

kuwv commented 2 years ago

While taking a closer look at this I believe that push_options have no way of being set: https://github.com/libgit2/pygit2/blob/master/pygit2/callbacks.py#L267

As it seems they are just reset with a new pointer: https://github.com/libgit2/pygit2/blob/master/pygit2/callbacks.py#L271

@jdavid can you confirm that this is correct or if I am mistaken?