pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/libgit2/libgit2sharp/commit/47b2ee01f00d5eaf94b31d4914cf8960ee62e344

fa.css" /> Adds Depth to FetchOptions allowing for shallow cloning (#2070) · libgit2/libgit2sharp@47b2ee0 · GitHub
Skip to content

Commit 47b2ee0

Browse files
Adds Depth to FetchOptions allowing for shallow cloning (#2070)
* Added Depth as a fetch option * Map Depth from FetchOptions to GitFetchOptions * Added tests for shallow cloning
1 parent 5162c68 commit 47b2ee0

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ public void CanClone(string url)
3535
}
3636
}
3737

38+
[Theory]
39+
[InlineData("https://github.com/libgit2/TestGitRepository",1)]
40+
[InlineData("https://github.com/libgit2/TestGitRepository",5)]
41+
[InlineData("https://github.com/libgit2/TestGitRepository",7)]
42+
public void CanCloneShallow(string url, int depth)
43+
{
44+
var scd = BuildSelfCleaningDirectory();
45+
46+
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions
47+
{
48+
FetchOptions =
49+
{
50+
Depth = depth,
51+
},
52+
});
53+
54+
using (var repo = new Repository(clonedRepoPath))
55+
{
56+
var commitsFirstParentOnly = repo.Commits.QueryBy(new CommitFilter
57+
{
58+
FirstParentOnly = true,
59+
});
60+
61+
Assert.Equal(depth, commitsFirstParentOnly.Count());
62+
Assert.Equal("49322bb17d3acc9146f98c97d078513228bbf3c0", repo.Head.Tip.Id.ToString());
63+
}
64+
}
65+
3866
[Theory]
3967
[InlineData("br2", "a4a7dce85cf63874e984719f4fdd239f5145052f")]
4068
[InlineData("packed", "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")]

LibGit2Sharp/FetchOptions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public sealed class FetchOptions : FetchOptionsBase
2626
//github.com/ </summary>
2727
public bool? Prune { get; set; }
2828

29+
//github.com/ <summary>
30+
//github.com/ Specifies the depth of the fetch to perform.
31+
//github.com/ <para>
32+
//github.com/ Default value is 0 (full) fetch.
33+
//github.com/ </para>
34+
//github.com/ </summary>
35+
public int Depth { get; set; } = 0;
36+
2937
//github.com/ <summary>
3038
//github.com/ Get/Set the custom headers.
3139
//github.com/

LibGit2Sharp/Repository.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,13 @@ public static string Clone(string sourceUrl, string workdirPath,
780780

781781
options ??= new CloneOptions();
782782

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+
783790
// context variable that contains information on the repository that
784791
// we are cloning.
785792
var context = new RepositoryOperationContext(Path.GetFullPath(workdirPath), sourceUrl);
@@ -794,7 +801,7 @@ public static string Clone(string sourceUrl, string workdirPath,
794801
}
795802

796803
using (var checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
797-
using (var fetchOptionsWrapper = new GitFetchOptionsWrapper())
804+
using (var fetchOptionsWrapper = new GitFetchOptionsWrapper(fetchOptions))
798805
{
799806
var gitCheckoutOptions = checkoutOptionsWrapper.Options;
800807

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy