Skip to content

Commit 32b79b6

Browse files
committed
Proposal for CloneOperation class
1 parent 75f3380 commit 32b79b6

4 files changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.IO;
2+
using LibGit2Sharp.Tests.TestHelpers;
3+
using Xunit;
4+
using Xunit.Extensions;
5+
6+
namespace LibGit2Sharp.Tests
7+
{
8+
public class CloneOperationFixture : BaseFixture
9+
{
10+
[Theory]
11+
[InlineData("http://github.com/libgit2/TestGitRepository")]
12+
[InlineData("https://github.com/libgit2/TestGitRepository")]
13+
[InlineData("git://github.com/nulltoken/TestGitRepository")]
14+
//[InlineData("git@github.com:libgit2/TestGitRepository")]
15+
public void CanClone(string url)
16+
{
17+
var scd = BuildSelfCleaningDirectory();
18+
var cloneop = new CloneOperation(url, scd.RootedDirectoryPath)
19+
{
20+
Bare = false,
21+
Checkout = true,
22+
};
23+
using (var repo = cloneop.Execute())
24+
{
25+
/* TODO
26+
string dir = repo.Info.Path;
27+
Assert.True(Path.IsPathRooted(dir));
28+
Assert.True(Directory.Exists(dir));
29+
30+
Assert.NotNull(repo.Info.WorkingDirectory);
31+
Assert.Equal(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar), repo.Info.Path);
32+
Assert.False(repo.Info.IsBare);
33+
34+
Assert.True(File.Exists(Path.Combine(scd.RootedDirectoryPath, "master.txt")));
35+
*/
36+
}
37+
}
38+
}
39+
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
</Reference>
5858
</ItemGroup>
5959
<ItemGroup>
60+
<Compile Include="CloneOperationFixture.cs" />
6061
<Compile Include="MetaFixture.cs" />
6162
<Compile Include="MockedRepositoryFixture.cs" />
6263
<Compile Include="ConfigurationFixture.cs" />

LibGit2Sharp/CloneOperation.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace LibGit2Sharp
2+
{
3+
public class CloneOperation
4+
{
5+
public delegate void ProgressHandler(string message);
6+
7+
/// <summary>
8+
/// Controls the maximum rate at which the Progress callback can be
9+
/// triggered. Set to 0 (or set Progress to null) to disable.
10+
/// Defaults to 100.
11+
/// </summary>
12+
public uint PollIntervalInMilliseconds { get; set; }
13+
14+
public string SourceUrl { get; private set; }
15+
public string DestinationPath { get; private set; }
16+
public bool Bare { get; set; }
17+
public bool Checkout { get; set; }
18+
19+
public ProgressHandler Progress { get; set; }
20+
21+
public CloneOperation(string sourceUrl, string workdirPath)
22+
{
23+
SourceUrl = sourceUrl;
24+
DestinationPath = workdirPath;
25+
Bare = false;
26+
Checkout = true;
27+
PollIntervalInMilliseconds = 100;
28+
}
29+
30+
/// <summary>
31+
/// Starts a clone operation on a background thread, and polls for
32+
/// progress on this thread.
33+
/// </summary>
34+
/// <returns></returns>
35+
public virtual Repository Execute()
36+
{
37+
// TODO
38+
return Repository.Init(DestinationPath, Bare);
39+
}
40+
}
41+
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<Compile Include="BranchCollectionExtensions.cs" />
6464
<Compile Include="Changes.cs" />
6565
<Compile Include="CheckoutOptions.cs" />
66+
<Compile Include="CloneOperation.cs" />
6667
<Compile Include="Commit.cs" />
6768
<Compile Include="CommitLog.cs" />
6869
<Compile Include="Configuration.cs" />

0 commit comments

Comments
 (0)