8000 Update how submodule fetch options are handled · enriqueraso/libgit2sharp@01a6ccb · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 01a6ccb

Browse files
committed
Update how submodule fetch options are handled
1 parent c6ef24d commit 01a6ccb

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

LibGit2Sharp.Tests/SubmoduleFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using LibGit2Sharp.Tests.TestHelpers;
55
using Xunit;
6-
using Xunit.Extensions;
76

87
namespace LibGit2Sharp.Tests
98
{
@@ -240,9 +239,10 @@ public void CanUpdateSubmodule()
240239
OnCheckoutProgress = (x, y, z) => checkoutProgressCalled = true,
241240
OnCheckoutNotify = (x, y) => { checkoutNotifyCalled = true; return true; },
242241
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated,
243-
OnUpdateTips = (x, y, z) => { updateTipsCalled = true; return true; },
244242
};
245243

244+
options.FetchOptions.OnUpdateTips = (x, y, z) => { updateTipsCalled = true; return true; };
245+
246246
repo.Submodules.Init(submodule.Name, false);
247247
repo.Submodules.Update(submodule.Name, options);
248248

LibGit2Sharp/Core/GitSubmoduleOptions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ internal struct GitSubmoduleUpdateOptions
1111

1212
public GitFetchOptions FetchOptions;
1313

14-
public CheckoutStrategy CloneCheckoutStrategy;
15-
1614
public int AllowFetch;
1715
}
1816
}

LibGit2Sharp/Repository.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,14 +865,11 @@ private static void RecursivelyCloneSubmodules(CloneOptions options, string repo
865865

866866
using (Repository repo = new Repository(repoPath))
867867
{
868-
SubmoduleUpdateOptions updateOptions = new SubmoduleUpdateOptions()
868+
var updateOptions = new SubmoduleUpdateOptions()
869869
{
870870
Init = true,
871-
CredentialsProvider = options.FetchOptions.CredentialsProvider,
872871
OnCheckoutProgress = options.OnCheckoutProgress,
873-
OnProgress = options.FetchOptions.OnProgress,
874-
OnTransferProgress = options.FetchOptions.OnTransferProgress,
875-
OnUpdateTips = options.FetchOptions.OnUpdateTips,
872+
FetchOptions = options.FetchOptions
876873
};
877874

878875
string parentRepoWorkDir = repo.Info.WorkingDirectory;

LibGit2Sharp/SubmoduleCollection.cs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,43 +74,41 @@ public virtual void Init(string name, bool overwrite)
7474
/// Update specified submodule.
7575
/// <para>
7676
/// This will:
77-
/// 1) Optionally initialize the if it not already initialzed,
77+
/// 1) Optionally initialize the if it not already initialized,
7878
/// 2) clone the sub repository if it has not already been cloned, and
7979
/// 3) checkout the commit ID for the submodule in the sub repository.
8080
/// </para>
8181
/// </summary>
8282
/// <param name="name">The name of the submodule to update.</param>
83-
/// <param name="options">Options controlling submodule udpate behavior and callbacks.</param>
83+
/// <param name="options">Options controlling submodule update behavior and callbacks.</param>
8484
public virtual void Update(string name, SubmoduleUpdateOptions options)
8585
{
86-
options = options ?? new SubmoduleUpdateOptions();
86+
options ??= new SubmoduleUpdateOptions();
8787

88-
using (var handle = Proxy.git_submodule_lookup(repo.Handle, name))
89-
{
90-
if (handle == null)
91-
{
92-
throw new NotFoundException("Submodule lookup failed for '{0}'.",
93-
name);
94-
}
88+
using var handle = Proxy.git_submodule_lookup(repo.Handle, name) ?? throw new NotFoundException("Submodule lookup failed for '{0}'.", name);
89+
using var checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options);
90+
using var fetchOptionsWrapper = new GitFetchOptionsWrapper();
9591

96-
using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
97-
{
98-
var gitCheckoutOptions = checkoutOptionsWrapper.Options;
92+
var gitCheckoutOptions = checkoutOptionsWrapper.Options;
9993

100-
var remoteCallbacks = new RemoteCallbacks(options);
101-
var gitRemoteCallbacks = remoteCallbacks.GenerateCallbacks();
94+
var gitFetchOptions = fetchOptionsWrapper.Options;
95+
gitFetchOptions.ProxyOptions = options.FetchOptions.ProxyOptions.CreateGitProxyOptions();
96+
gitFetchOptions.RemoteCallbacks = new RemoteCallbacks(options.FetchOptions).GenerateCallbacks();
10297

103-
var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions
104-
{
105-
Version = 1,
106-
CheckoutOptions = gitCheckoutOptions,
107-
FetchOptions = new GitFetchOptions { ProxyOptions = options.ProxyOptions.CreateGitProxyOptions(), RemoteCallbacks = gitRemoteCallbacks },
108-
CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE
109-
};
110-
111-
Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts);
112-
}
98+
if (options.FetchOptions != null && options.FetchOptions.CustomHeaders != null)
99+
{
100+
gitFetchOptions.CustomHeaders =
101+
GitStrArrayManaged.BuildFrom(options.FetchOptions.CustomHeaders);
113102
}
103+
104+
var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions
105+
{
106+
Version = 1,
107+
CheckoutOptions = gitCheckoutOptions,
108+
FetchOptions = gitFetchOptions
109+
};
110+
111+
Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts);
114112
}
115113

116114
/// <summary>

LibGit2Sharp/SubmoduleUpdateOptions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace LibGit2Sharp
66
/// <summary>
77
/// Options controlling Submodule Update behavior and callbacks.
88
/// </summary>
9-
public sealed class SubmoduleUpdateOptions : FetchOptionsBase, IConvertableToGitCheckoutOpts
9+
public sealed class SubmoduleUpdateOptions : IConvertableToGitCheckoutOpts
1010
{
1111
/// <summary>
1212
/// Initialize the submodule if it is not already initialized.
@@ -30,6 +30,11 @@ public sealed class SubmoduleUpdateOptions : FetchOptionsBase, IConvertableToGit
3030
/// </summary>
3131
public CheckoutNotifyFlags CheckoutNotifyFlags { get; set; }
3232

33+
/// <summary>
34+
/// Collection of parameters controlling Fetch behavior.
35+
/// </summary>
36+
public FetchOptions FetchOptions { get; internal set; } = new();
37+
3338
CheckoutCallbacks IConvertableToGitCheckoutOpts.GenerateCallbacks()
3439
{
3540
return CheckoutCallbacks.From(OnCheckoutProgress, OnCheckoutNotify);

0 commit comments

Comments
 (0)
0