This repository was archived by the owner on Feb 3, 2023. It is now read-only.
forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCloneFixture.cs
More file actions
139 lines (123 loc) · 5.47 KB
/
Copy pathCloneFixture.cs
File metadata and controls
139 lines (123 loc) · 5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;
using System.IO;
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
public class CloneFixture : BaseFixture
{
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
[InlineData("git://github.com/libgit2/TestGitRepository")]
//[InlineData("git@github.com:libgit2/TestGitRepository")]
public void CanClone(string url)
{
var scd = BuildSelfCleaningDirectory();
using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath))
{
string dir = repo.Info.Path;
Assert.True(Path.IsPathRooted(dir));
Assert.True(Directory.Exists(dir));
Assert.NotNull(repo.Info.WorkingDirectory);
Assert.Equal(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar), repo.Info.Path);
Assert.False(repo.Info.IsBare);
Assert.True(File.Exists(Path.Combine(scd.RootedDirectoryPath, "master.txt")));
Assert.Equal(repo.Head.Name, "master");
Assert.Equal(repo.Head.Tip.Id.ToString(), "49322bb17d3acc9146f98c97d078513228bbf3c0");
}
}
private void AssertLocalClone(string path)
{
var scd = BuildSelfCleaningDirectory();
using (Repository clonedRepo = Repository.Clone(path, scd.RootedDirectoryPath))
using (var originalRepo = new Repository(BareTestRepoPath))
{
Assert.NotEqual(originalRepo.Info.Path, clonedRepo.Info.Path);
Assert.Equal(originalRepo.Head, clonedRepo.Head);
Assert.Equal(originalRepo.Branches.Count(), clonedRepo.Branches.Count(b => b.IsRemote));
Assert.Equal(1, clonedRepo.Branches.Count(b => !b.IsRemote));
Assert.Equal(originalRepo.Tags.Count(), clonedRepo.Tags.Count());
Assert.Equal(1, clonedRepo.Network.Remotes.Count());
}
}
[Fact]
public void CanCloneALocalRepositoryFromALocalUri()
{
var uri = new Uri(BareTestRepoPath);
AssertLocalClone(uri.AbsoluteUri);
}
[Fact]
public void CanCloneALocalRepositoryFromAStandardPath()
{
AssertLocalClone(BareTestRepoPath);
}
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
[InlineData("git://github.com/libgit2/TestGitRepository")]
//[InlineData("git@github.com:libgit2/TestGitRepository")]
public void CanCloneBarely(string url)
{
var scd = BuildSelfCleaningDirectory();
using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath, bare: true))
{
string dir = repo.Info.Path;
Assert.True(Path.IsPathRooted(dir));
Assert.True(Directory.Exists(dir));
Assert.Null(repo.Info.WorkingDirectory);
Assert.Equal(scd.RootedDirectoryPath + Path.DirectorySeparatorChar, repo.Info.Path);
Assert.True(repo.Info.IsBare);
}
}
[Theory]
[InlineData("git://github.com/libgit2/TestGitRepository")]
public void WontCheckoutIfAskedNotTo(string url)
{
var scd = BuildSelfCleaningDirectory();
using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath, checkout: false))
{
Assert.False(File.Exists(Path.Combine(scd.RootedDirectoryPath, "master.txt")));
}
}
[Theory]
[InlineData("git://github.com/libgit2/TestGitRepository")]
public void CallsProgressCallbacks(string url)
{
bool transferWasCalled = false;
bool checkoutWasCalled = false;
var scd = BuildSelfCleaningDirectory();
using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath,
onTransferProgress: (_) => { transferWasCalled = true; return 0; },
onCheckoutProgress: (a, b, c) => checkoutWasCalled = true))
{
Assert.True(transferWasCalled);
Assert.True(checkoutWasCalled);
}
}
[SkippableFact]
public void CanCloneWithCredentials()
{
InconclusiveIf(() => string.IsNullOrEmpty(Constants.PrivateRepoUrl),
"Populate Constants.PrivateRepo* to run this test");
var scd = BuildSelfCleaningDirectory();
using (Repository repo = Repository.Clone(
Constants.PrivateRepoUrl, scd.RootedDirectoryPath,
credentials: new Credentials
{
Username = Constants.PrivateRepoUsername,
Password = Constants.PrivateRepoPassword
}))
{
string dir = repo.Info.Path;
Assert.True(Path.IsPathRooted(dir));
Assert.True(Directory.Exists(dir));
Assert.NotNull(repo.Info.WorkingDirectory);
Assert.Equal(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar), repo.Info.Path);
Assert.False(repo.Info.IsBare);
}
}
}
}