Skip to content
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

set remote callback before push #431

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pygit2/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,38 @@ def push(self, spec, signature=None, message=None):
:param Signature signature: signature to use when updating the tips
:param str message: message to use when updating the tips
"""
# Get the default callbacks first
defaultcallbacks = ffi.new('git_remote_callbacks *')
err = C.git_remote_init_callbacks(defaultcallbacks, 1)
check_error(err)

# Build custom callback structure
callbacks = ffi.new('git_remote_callbacks *')
callbacks.version = 1
callbacks.sideband_progress = self._sideband_progress_cb
callbacks.transfer_progress = self._transfer_progress_cb
callbacks.update_tips = self._update_tips_cb
callbacks.credentials = self._credentials_cb
# We need to make sure that this handle stays alive
self._self_handle = ffi.new_handle(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._self_handle needs to be set to None after the push operation completes, next to freeing the push object itself.

callbacks.payload = self._self_handle

err = C.git_remote_set_callbacks(self._remote, callbacks)

try:
check_error(err)
except:
self._self_handle = None
raise


cpush = ffi.new('git_push **')
err = C.git_push_new(cpush, self._remote)
check_error(err)

push = cpush[0]


try:
err = C.git_push_add_refspec(push, to_bytes(spec))
check_error(err)
Expand Down