8000 Wire up the push_update_reference_callback to fire the PushStatusErro… · GiTechLab/libgit2sharp@c6532ce · GitHub
[go: up one dir, main page]

Skip to content

Commit c6532ce

Browse files
committed
Wire up the push_update_reference_callback to fire the PushStatusError callback if the returned status is not NULL and the update was rejected by the remote server.
1 parent 4d816d9 commit c6532ce

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

LibGit2Sharp/Core/GitRemoteCallbacks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal struct GitRemoteCallbacks
2727

2828
internal NativeMethods.git_push_transfer_progress push_transfer_progress;
2929

30-
internal IntPtr push_update_reference;
30+
internal NativeMethods.push_update_reference_callback push_update_reference;
3131

3232
internal IntPtr payload;
3333
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,12 @@ internal delegate int remote_update_tips_callback(
11081108
ref GitOid newId,
11091109
IntPtr data);
11101110

1111+
internal delegate int push_update_reference_callback(
1112+
IntPtr refName,
1113+
IntPtr status,
1114+
IntPtr data
1115+
);
1116+
11111117
[DllImport(libgit2)]
11121118
internal static extern int git_repository_discover(
11131119
GitBuf buf,

LibGit2Sharp/RemoteCallbacks.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
0