Skip to content

Push negotiation callback #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2025
Merged

Push negotiation callback #1396

merged 2 commits into from
Aug 5, 2025

Conversation

jorio
Copy link
Contributor

@jorio jorio commented Aug 4, 2025

This PR does two things:

  • Expose libgit2's git_remote_callbacks.push_negotiation to Python code (via RemoteCallbacks).
  • Add a new connect argument to Remote.ls_remotes(). This lets you tell ls_remote to skip its default connection step, which is harmful if calling ls_remotes from RemoteCallbacks.push_negotiation.

Some background info:

My use case is to implement an equivalent of git push --force-with-lease. To achieve this, I need push_negotiation which is called right before the transfer actually begins.

My negotiation callback uses Remote.ls_remotes to determine whether the repo has stale information about the remote branch to force-push to, in which case the push should be rejected.

However, Remote.ls_remotes currently forces a new connection to the remote. This invalidates the existing connection that was set up by the push - causing the push fail. So, this PR also lets you tell ls_remotes to not override the current connection (by passing connect=False).

jorio added 2 commits August 4, 2025 17:14
Remote.ls_remotes() used to force a new connection to the remote. This can be harmful if a connection was already set up for other purposes, e.g. when calling ls_remotes from RemoteCallbacks.push_negotiation.

This new argument `ls_remotes(..., connect)` lets you bypass the automatic connection.
@jdavid jdavid merged commit d7b67e4 into libgit2:master Aug 5, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants