@@ -27,6 +27,7 @@ internal RemoteCallbacks(PushOptions pushOptions)
27
27
PushTransferProgress = pushOptions . OnPushTransferProgress ;
28
28
PackBuilderProgress = pushOptions . OnPackBuilderProgress ;
29
29
CredentialsProvider = pushOptions . CredentialsProvider ;
30
+ PushStatusError = pushOptions . OnPushStatusError ;
30
31
}
31
32
32
33
internal RemoteCallbacks ( FetchOptionsBase fetchOptions )
@@ -54,6 +55,12 @@ internal RemoteCallbacks(FetchOptionsBase fetchOptions)
54
55
/// </summary>
55
56
private readonly UpdateTipsHandler UpdateTips ;
56
57
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
+
57
64
/// <summary>
58
65
/// Managed delegate to be called in response to a git_transfer_progress_callback callback from libgit2.
59
66
/// This will in turn call the user provided delegate.
@@ -91,6 +98,11 @@ internal GitRemoteCallbacks GenerateCallbacks()
91
98
callbacks . update_tips = GitUpdateTipsHandler ;
92
99
}
93
100
101
+ if ( PushStatusError != null )
102
+ {
103
+ callbacks . push_update_reference = GitPushUpdateReference ;
104
+ }
105
+
94
106
if ( CredentialsProvider != null )
95
107
{
96
108
callbacks . acquire_credentials = GitCredentialHandler ;
@@ -164,6 +176,30 @@ private int GitUpdateTipsHandler(IntPtr str, ref GitOid oldId, ref GitOid newId,
164
176
return Proxy . ConvertResultToCancelFlag ( shouldContinue ) ;
165
177
}
166
178
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
+
167
203
/// <summary>
168
204
/// The delegate with the signature that matches the native git_transfer_progress_callback function's signature.
169
205
/// </summary>
0 commit comments