@@ -27,6 +27,7 @@ internal RemoteCallbacks(PushOptions pushOptions)
2727 PushTransferProgress = pushOptions . OnPushTransferProgress ;
2828 PackBuilderProgress = pushOptions . OnPackBuilderProgress ;
2929 CredentialsProvider = pushOptions . CredentialsProvider ;
30+ PushStatusError = pushOptions . OnPushStatusError ;
3031 }
3132
3233 internal RemoteCallbacks ( FetchOptionsBase fetchOptions )
@@ -54,6 +55,12 @@ internal RemoteCallbacks(FetchOptionsBase fetchOptions)
5455 /// </summary>
5556 private readonly UpdateTipsHandler UpdateTips ;
5657
58+ /// <summary>
59+ /// PushStatusError callback. It will be called when the libgit2 push_update_reference returns a non null status message,
60+ /// which means that the update was rejected by the remote server.
61+ /// </summary>
62+ private readonly PushStatusErrorHandler PushStatusError ;
63+
5764 /// <summary>
5865 /// Managed delegate to be called in response to a git_transfer_progress_callback callback from libgit2.
5966 /// This will in turn call the user provided delegate.
@@ -91,6 +98,11 @@ internal GitRemoteCallbacks GenerateCallbacks()
9198 callbacks . update_tips = GitUpdateTipsHandler ;
9299 }
93100
101+ if ( PushStatusError != null )
102+ {
103+ callbacks . push_update_reference = GitPushUpdateReference ;
104+ }
105+
94106 if ( CredentialsProvider != null )
95107 {
96108 callbacks . acquire_credentials = GitCredentialHandler ;
@@ -164,6 +176,30 @@ private int GitUpdateTipsHandler(IntPtr str, ref GitOid oldId, ref GitOid newId,
164176 return Proxy . ConvertResultToCancelFlag ( shouldContinue ) ;
165177 }
166178
179+ /// <summary>
180+ /// The delegate with the signature that matches the native push_update_reference function's signature
181+ /// </summary>
182+ /// <param name="str">IntPtr to string, the name of the reference</param>
183+ /// <param name="status">IntPtr to string, the update status message</param>
184+ /// <param name="data">IntPtr to optional payload passed back to the callback.</param>
185+ /// <returns>0 on success; a negative value to abort the process.</returns>
186+ private int GitPushUpdateReference ( IntPtr str , IntPtr status , IntPtr data )
187+ {
188+ PushStatusErrorHandler onPushError = PushStatusError ;
189+
190+ if ( onPushError != null )
191+ {
192+ string reference = LaxUtf8Marshaler . FromNative ( str ) ;
193+ string message = LaxUtf8Marshaler . FromNative ( status ) ;
194+ if ( message != null )
195+ {
196+ onPushError ( new PushStatusError ( reference , message ) ) ;
197+ }
198+ }
199+
200+ return Proxy . ConvertResultToCancelFlag ( true ) ;
201+ }
202+
167203 /// <summary>
168204 /// The delegate with the signature that matches the native git_transfer_progress_callback function's signature.
169205 /// </summary>
0 commit comments