Add proxy options by bording · Pull Request #2065 · libgit2/libgit2sharp · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
108 changes: 56 additions & 52 deletions LibGit2Sharp.Tests/CloneFixture.cs
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/SubmoduleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using Xunit.Extensions;

namespace LibGit2Sharp.Tests
{
Expand Down Expand Up @@ -240,9 +239,10 @@ public void CanUpdateSubmodule()
OnCheckoutProgress = (x, y, z) => checkoutProgressCalled = true,
OnCheckoutNotify = (x, y) => { checkoutNotifyCalled = true; return true; },
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated,
OnUpdateTips = (x, y, z) => { updateTipsCalled = true; return true; },
};

options.FetchOptions.OnUpdateTips = (x, y, z) => { updateTipsCalled = true; return true; };

repo.Submodules.Init(submodule.Name, false);
repo.Submodules.Update(submodule.Name, options);

Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp/CloneOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LibGit2Sharp
/// <summary>
/// Options to define clone behaviour
/// </summary>
public sealed class CloneOptions : FetchOptionsBase, IConvertableToGitCheckoutOpts
public sealed class CloneOptions : IConvertableToGitCheckoutOpts
{
/// <summary>
/// Creates default <see cref="CloneOptions"/> for a non-bare clone
Expand Down Expand Up @@ -46,7 +46,7 @@ public CloneOptions()
/// <summary>
/// Gets or sets the fetch options.
/// </summary>
public FetchOptions FetchOptions { get; set; }
public FetchOptions FetchOptions { get; } = new();

#region IConvertableToGitCheckoutOpts

Expand Down
3 changes: 1 addition & 2 deletions LibGit2Sharp/Commands/Fetch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using LibGit2Sharp;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;

Expand Down Expand Up @@ -75,7 +74,7 @@ public static void Fetch(Repository repository, string remote, IEnumerable<strin
fetchOptions.CustomHeaders = GitStrArrayManaged.BuildFrom(options.CustomHeaders);
}

fetchOptions.ProxyOptions = new GitProxyOptions { Version = 1 };
fetchOptions.ProxyOptions = options.ProxyOptions.CreateGitProxyOptions();

Proxy.git_remote_fetch(remoteHandle, refspecs, fetchOptions, logMessage);
}
Expand Down
9 changes: 5 additions & 4 deletions LibGit2Sharp/Core/GitFetchOptionsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace LibGit2Sharp.Core
{
/// <summary>
/// Git fetch options wrapper. Disposable wrapper for GitFetchOptions
/// <summary>
/// Git fetch options wrapper. Disposable wrapper for GitFetchOptions
/// </summary>
internal class GitFetchOptionsWrapper : IDisposable
{
public GitFetchOptionsWrapper() : this(new GitFetchOptions()) { }

public GitFetchOptionsWrapper(GitFetchOptions fetchOptions)
{
this.Options = fetchOptions;
Options = fetchOptions;
}

public GitFetchOptions Options { get; private set; }
Expand All @@ -23,7 +23,8 @@ protected virtual void Dispose(bool disposing)
if (disposedValue)
return;

this.Options.CustomHeaders.Dispose();
Options.CustomHeaders.Dispose();
EncodingMarshaler.Cleanup(Options.ProxyOptions.Url);
disposedValue = true;
}

Expand Down
6 changes: 3 additions & 3 deletions LibGit2Sharp/Core/GitProxyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ internal struct GitProxyOptions
public uint Version;
public GitProxyType Type;
public IntPtr Url;
public IntPtr CredentialsCb;
public IntPtr CertificateCheck;
public IntPtr CbPayload;
public NativeMethods.git_cred_acquire_cb Credentials;
public NativeMethods.git_transport_certificate_check_cb CertificateCheck;
public IntPtr Payload;
}
}
32 changes: 32 additions & 0 deletions LibGit2Sharp/Core/GitProxyOptionsWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;

namespace LibGit2Sharp.Core
{
internal class GitProxyOptionsWrapper : IDisposable
{
public GitProxyOptionsWrapper() : this(new GitProxyOptions()) { }

public GitProxyOptionsWrapper(GitProxyOptions fetchOptions)
{
Options = fetchOptions;
}

public GitProxyOptions Options { get; private set; }

private bool disposedValue = false;

protected virtual void Dispose(bool disposing)
{
if (disposedValue)
return;

EncodingMarshaler.Cleanup(Options.Url);
disposedValue = true;
}

public void Dispose()
{
Dispose(true);
}
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/Core/GitPushOptionsWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected virtual void Dispose(bool disposing)
return;

this.Options.CustomHeaders.Dispose();
EncodingMarshaler.Cleanup(Options.ProxyOptions.Url);
disposedValue = true;
}

Expand Down
2 changes: 0 additions & 2 deletions LibGit2Sharp/Core/GitSubmoduleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ internal struct GitSubmoduleUpdateOptions

public GitFetchOptions FetchOptions;

public CheckoutStrategy CloneCheckoutStrategy;

public int AllowFetch;
}
}
8 changes: 4 additions & 4 deletions LibGit2Sharp/FetchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public sealed class FetchOptions : FetchOptionsBase

/// <summary>
/// Get/Set the custom headers.
///
/// <para>
/// This allows you to set custom headers (e.g. X-Forwarded-For,
///
/// <para>
/// This allows you to set custom headers (e.g. X-Forwarded-For,
/// X-Request-Id, etc),
/// </para>
/// </summary>
/// <remarks>
/// Libgit2 sets some headers for HTTP requests (User-Agent, Host,
/// Libgit2 sets some headers for HTTP requests (User-Agent, Host,
/// Accept, Content-Type, Transfer-Encoding, Content-Length, Accept) that
/// cannot be overriden.
/// </remarks>
Expand Down
7 changes: 6 additions & 1 deletion LibGit2Sharp/FetchOptionsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal FetchOptionsBase()

/// <summary>
/// This handler will be called to let the user make a decision on whether to allow
/// the connection to preoceed based on the certificate presented by the server.
/// the connection to proceed based on the certificate presented by the server.
/// </summary>
public CertificateCheckHandler CertificateCheck { get; set; }

Expand All @@ -48,5 +48,10 @@ internal FetchOptionsBase()
/// Completed operating on the current repository.
/// </summary>
public RepositoryOperationCompleted RepositoryOperationCompleted { get; set; }

/// <summary>
/// Options for connecting through a proxy.
/// </summary>
public ProxyOptions ProxyOptions { get; } = new();
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Loading