Skip to content

Commit 19236db

Browse files
committed
Tweak shallow cloning implementation
1 parent 47b2ee0 commit 19236db

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

LibGit2Sharp/FetchOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public sealed class FetchOptions : FetchOptionsBase
2929
/// <summary>
3030
/// Specifies the depth of the fetch to perform.
3131
/// <para>
32-
/// Default value is 0 (full) fetch.
32+
/// Default value is 0 (full fetch).
3333
/// </para>
3434
/// </summary>
3535
public int Depth { get; set; } = 0;

LibGit2Sharp/Repository.cs

+8-19
Original file line numberDiff line numberDiff line change
@@ -772,46 +772,38 @@ public static string Clone(string sourceUrl, string workdirPath)
772772
/// <param name="workdirPath">Local path to clone into</param>
773773
/// <param name="options"><see cref="CloneOptions"/> controlling clone behavior</param>
774774
/// <returns>The path to the created repository.</returns>
775-
public static string Clone(string sourceUrl, string workdirPath,
776-
CloneOptions options)
775+
public static string Clone(string sourceUrl, string workdirPath, CloneOptions options)
777776
{
778777
Ensure.ArgumentNotNull(sourceUrl, "sourceUrl");
779778
Ensure.ArgumentNotNull(workdirPath, "workdirPath");
780779

781780
options ??= new CloneOptions();
782781

783-
// As default behaviour for GitFetchOptionsWrapper ctor is to create
784-
// a new instance of GitFetchOptions we only populate the Depth field.
785-
var fetchOptions = new GitFetchOptions
786-
{
787-
Depth = options.FetchOptions.Depth,
788-
};
789-
790782
// context variable that contains information on the repository that
791783
// we are cloning.
792784
var context = new RepositoryOperationContext(Path.GetFullPath(workdirPath), sourceUrl);
793785

794786
// Notify caller that we are starting to work with the current repository.
795-
bool continueOperation = OnRepositoryOperationStarting(options.FetchOptions.RepositoryOperationStarting,
796-
context);
787+
bool continueOperation = OnRepositoryOperationStarting(options.FetchOptions.RepositoryOperationStarting, context);
797788

798789
if (!continueOperation)
799790
{
800791
throw new UserCancelledException("Clone cancelled by the user.");
801792
}
802793

803794
using (var checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
804-
using (var fetchOptionsWrapper = new GitFetchOptionsWrapper(fetchOptions))
795+
using (var fetchOptionsWrapper = new GitFetchOptionsWrapper())
805796
{
806797
var gitCheckoutOptions = checkoutOptionsWrapper.Options;
807798

808799
var gitFetchOptions = fetchOptionsWrapper.Options;
800+
gitFetchOptions.Depth = options.FetchOptions.Depth;
809801
gitFetchOptions.ProxyOptions = options.FetchOptions.ProxyOptions.CreateGitProxyOptions();
810802
gitFetchOptions.RemoteCallbacks = new RemoteCallbacks(options.FetchOptions).GenerateCallbacks();
803+
811804
if (options.FetchOptions != null && options.FetchOptions.CustomHeaders != null)
812805
{
813-
gitFetchOptions.CustomHeaders =
814-
GitStrArrayManaged.BuildFrom(options.FetchOptions.CustomHeaders);
806+
gitFetchOptions.CustomHeaders = GitStrArrayManaged.BuildFrom(options.FetchOptions.CustomHeaders);
815807
}
816808

817809
var cloneOpts = new GitCloneOptions
@@ -839,8 +831,7 @@ public static string Clone(string sourceUrl, string workdirPath,
839831
}
840832

841833
// Notify caller that we are done with the current repository.
842-
OnRepositoryOperationCompleted(options.FetchOptions.RepositoryOperationCompleted,
843-
context);
834+
OnRepositoryOperationCompleted(options.FetchOptions.RepositoryOperationCompleted, context);
844835

845836
// Recursively clone submodules if requested.
846837
try
@@ -849,9 +840,7 @@ public static string Clone(string sourceUrl, string workdirPath,
849840
}
850841
catch (Exception ex)
851842
{
852-
throw new RecurseSubmodulesException("The top level repository was cloned, but there was an error cloning its submodules.",
853-
ex,
854-
clonedRepoPath);
843+
throw new RecurseSubmodulesException("The top level repository was cloned, but there was an error cloning its submodules.", ex, clonedRepoPath);
855844
}
856845

857846
return clonedRepoPath;

0 commit comments

Comments
 (0)