Skip to content

Commit

Permalink
Update how submodule fetch options are handled
Browse files Browse the repository at this point in the history
  • Loading branch information
bording committed Nov 26, 2023
1 parent 49d39c9 commit 4d3c56e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 35 deletions.
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
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;
}
}
7 changes: 2 additions & 5 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,11 @@ private static void RecursivelyCloneSubmodules(CloneOptions options, string repo

using (Repository repo = new Repository(repoPath))
{
SubmoduleUpdateOptions updateOptions = new SubmoduleUpdateOptions()
var updateOptions = new SubmoduleUpdateOptions()
{
Init = true,
CredentialsProvider = options.FetchOptions.CredentialsProvider,
OnCheckoutProgress = options.OnCheckoutProgress,
OnProgress = options.FetchOptions.OnProgress,
OnTransferProgress = options.FetchOptions.OnTransferProgress,
OnUpdateTips = options.FetchOptions.OnUpdateTips,
FetchOptions = options.FetchOptions
};

string parentRepoWorkDir = repo.Info.WorkingDirectory;
Expand Down
48 changes: 23 additions & 25 deletions LibGit2Sharp/SubmoduleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,43 +74,41 @@ public virtual void Init(string name, bool overwrite)
/// Update specified submodule.
/// <para>
/// This will:
/// 1) Optionally initialize the if it not already initialzed,
/// 1) Optionally initialize the if it not already initialized,
/// 2) clone the sub repository if it has not already been cloned, and
/// 3) checkout the commit ID for the submodule in the sub repository.
/// </para>
/// </summary>
/// <param name="name">The name of the submodule to update.</param>
/// <param name="options">Options controlling submodule udpate behavior and callbacks.</param>
/// <param name="options">Options controlling submodule update behavior and callbacks.</param>
public virtual void Update(string name, SubmoduleUpdateOptions options)
{
options = options ?? new SubmoduleUpdateOptions();
options ??= new SubmoduleUpdateOptions();

using (var handle = Proxy.git_submodule_lookup(repo.Handle, name))
{
if (handle == null)
{
throw new NotFoundException("Submodule lookup failed for '{0}'.",
name);
}
using var handle = Proxy.git_submodule_lookup(repo.Handle, name) ?? throw new NotFoundException("Submodule lookup failed for '{0}'.", name);
using var checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options);
using var fetchOptionsWrapper = new GitFetchOptionsWrapper();

using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
{
var gitCheckoutOptions = checkoutOptionsWrapper.Options;
var gitCheckoutOptions = checkoutOptionsWrapper.Options;

var remoteCallbacks = new RemoteCallbacks(options);
var gitRemoteCallbacks = remoteCallbacks.GenerateCallbacks();
var gitFetchOptions = fetchOptionsWrapper.Options;
gitFetchOptions.ProxyOptions = options.FetchOptions.ProxyOptions.CreateGitProxyOptions();
gitFetchOptions.RemoteCallbacks = new RemoteCallbacks(options.FetchOptions).GenerateCallbacks();

var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions
{
Version = 1,
CheckoutOptions = gitCheckoutOptions,
FetchOptions = new GitFetchOptions { ProxyOptions = options.ProxyOptions.CreateGitProxyOptions(), RemoteCallbacks = gitRemoteCallbacks },
CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE
};

Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts);
}
if (options.FetchOptions != null && options.FetchOptions.CustomHeaders != null)
{
gitFetchOptions.CustomHeaders =
GitStrArrayManaged.BuildFrom(options.FetchOptions.CustomHeaders);
}

var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions
{
Version = 1,
CheckoutOptions = gitCheckoutOptions,
FetchOptions = gitFetchOptions
};

Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts);
}

/// <summary>
Expand Down
7 changes: 6 additions & 1 deletion LibGit2Sharp/SubmoduleUpdateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace LibGit2Sharp
/// <summary>
/// Options controlling Submodule Update behavior and callbacks.
/// </summary>
public sealed class SubmoduleUpdateOptions : FetchOptionsBase, IConvertableToGitCheckoutOpts
public sealed class SubmoduleUpdateOptions : IConvertableToGitCheckoutOpts
{
/// <summary>
/// Initialize the submodule if it is not already initialized.
Expand All @@ -30,6 +30,11 @@ public sealed class SubmoduleUpdateOptions : FetchOptionsBase, IConvertableToGit
/// </summary>
public CheckoutNotifyFlags CheckoutNotifyFlags { get; set; }

/// <summary>
/// Collection of parameters controlling Fetch behavior.
/// </summary>
public FetchOptions FetchOptions { get; internal set; } = new();

CheckoutCallbacks IConvertableToGitCheckoutOpts.GenerateCallbacks()
{
return CheckoutCallbacks.From(OnCheckoutProgress, OnCheckoutNotify);
Expand Down

0 comments on commit 4d3c56e

Please sign in to comment.