Skip to content

Commit 3d72762

Browse files
authored
Merge pull request #1618 from libgit2/ethomson/notls
WIP: Use managed HTTP stack
2 parents dbb17e7 + fd8e277 commit 3d72762

32 files changed

+954
-336
lines changed

Diff for: LibGit2Sharp.Tests/CloneFixture.cs

+59-59
Original file line numberDiff line numberDiff line change
@@ -237,65 +237,65 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
237237
}
238238
}
239239

240-
[SkippableTheory]
241-
[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
242-
[InlineData("[email protected]:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
243-
public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
244-
{
245-
var scd = BuildSelfCleaningDirectory();
246-
247-
InconclusiveIf(
248-
() =>
249-
certType == typeof (CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
250-
"SSH not supported");
251-
252-
bool wasCalled = false;
253-
bool checksHappy = false;
254-
255-
var options = new CloneOptions {
256-
CertificateCheck = (cert, valid, host) => {
257-
wasCalled = true;
258-
259-
Assert.Equal(hostname, host);
260-
Assert.Equal(certType, cert.GetType());
261-
262-
if (certType == typeof(CertificateX509)) {
263-
Assert.True(valid);
264-
var x509 = ((CertificateX509)cert).Certificate;
265-
// we get a string with the different fields instead of a structure, so...
266-
Assert.Contains("CN=github.com,", x509.Subject);
267-
checksHappy = true;
268-
return false;
269-
}
270-
271-
if (certType == typeof(CertificateSsh)) {
272-
var hostkey = (CertificateSsh)cert;
273-
Assert.True(hostkey.HasMD5);
274-
/*
275-
* Once you've connected and thus your ssh has stored the hostkey,
276-
* you can get the hostkey for a host with
277-
*
278-
* ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
279-
*
280-
* though GitHub's hostkey won't change anytime soon.
281-
*/
282-
Assert.Equal("1627aca576282d36631b564debdfa648",
283-
BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
284-
checksHappy = true;
285-
return false;
286-
}
287-
288-
return false;
289-
},
290-
};
291-
292-
Assert.Throws<UserCancelledException>(() =>
293-
Repository.Clone(url, scd.DirectoryPath, options)
294-
);
295-
296-
Assert.True(wasCalled);
297-
Assert.True(checksHappy);
298-
}
240+
//[SkippableTheory]
241+
//[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
242+
//[InlineData("[email protected]:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
243+
//public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
244+
//{
245+
// var scd = BuildSelfCleaningDirectory();
246+
247+
// InconclusiveIf(
248+
// () =>
249+
// certType == typeof (CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
250+
// "SSH not supported");
251+
252+
// bool wasCalled = false;
253+
// bool checksHappy = false;
254+
255+
// var options = new CloneOptions {
256+
// CertificateCheck = (cert, valid, host) => {
257+
// wasCalled = true;
258+
259+
// Assert.Equal(hostname, host);
260+
// Assert.Equal(certType, cert.GetType());
261+
262+
// if (certType == typeof(CertificateX509)) {
263+
// Assert.True(valid);
264+
// var x509 = ((CertificateX509)cert).Certificate;
265+
// // we get a string with the different fields instead of a structure, so...
266+
// Assert.Contains("CN=github.com,", x509.Subject);
267+
// checksHappy = true;
268+
// return false;
269+
// }
270+
271+
// if (certType == typeof(CertificateSsh)) {
272+
// var hostkey = (CertificateSsh)cert;
273+
// Assert.True(hostkey.HasMD5);
274+
// /*
275+
// * Once you've connected and thus your ssh has stored the hostkey,
276+
// * you can get the hostkey for a host with
277+
// *
278+
// * ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
279+
// *
280+
// * though GitHub's hostkey won't change anytime soon.
281+
// */
282+
// Assert.Equal("1627aca576282d36631b564debdfa648",
283+
// BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
284+
// checksHappy = true;
285+
// return false;
286+
// }
287+
288+
// return false;
289+
// },
290+
// };
291+
292+
// Assert.Throws<UserCancelledException>(() =>
293+
// Repository.Clone(url, scd.DirectoryPath, options)
294+
// );
295+
296+
// Assert.True(wasCalled);
297+
// Assert.True(checksHappy);
298+
//}
299299

300300
[Theory]
301301
[InlineData("git://github.com/libgit2/TestGitRepository")]

Diff for: LibGit2Sharp.Tests/FileHistoryFixture.cs

+50-48
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,56 @@ namespace LibGit2Sharp.Tests
1010
{
1111
public class FileHistoryFixture : BaseFixture
1212
{
13-
[Theory]
14-
[InlineData("https://github.com/nulltoken/follow-test.git")]
15-
public void CanDealWithFollowTest(string url)
16-
{
17-
var scd = BuildSelfCleaningDirectory();
18-
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);
19-
20-
using (var repo = new Repository(clonedRepoPath))
21-
{
22-
// $ git log --follow --format=oneline so-renamed.txt
23-
// 88f91835062161febb46fb270ef4188f54c09767 Update not-yet-renamed.txt AND rename into so-renamed.txt
24-
// ef7cb6a63e32595fffb092cb1ae9a32310e58850 Add not-yet-renamed.txt
25-
var fileHistoryEntries = repo.Commits.QueryBy("so-renamed.txt").ToList();
26-
Assert.Equal(2, fileHistoryEntries.Count());
27-
Assert.Equal("88f91835062161febb46fb270ef4188f54c09767", fileHistoryEntries[0].Commit.Sha);
28-
Assert.Equal("ef7cb6a63e32595fffb092cb1ae9a32310e58850", fileHistoryEntries[1].Commit.Sha);
29-
30-
// $ git log --follow --format=oneline untouched.txt
31-
// c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
32-
fileHistoryEntries = repo.Commits.QueryBy("untouched.txt").ToList();
33-
Assert.Single(fileHistoryEntries);
34-
Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[0].Commit.Sha);
35-
36-
// $ git log --follow --format=oneline under-test.txt
37-
// 0b5b18f2feb917dee98df1210315b2b2b23c5bec Rename file renamed.txt into under-test.txt
38-
// 49921d463420a892c9547a326632ef6a9ba3b225 Update file renamed.txt
39-
// 70f636e8c64bbc2dfef3735a562bb7e195d8019f Rename file under-test.txt into renamed.txt
40-
// d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d Updated file under test
41-
// 9da10ef7e139c49604a12caa866aae141f38b861 Updated file under test
42-
// 599a5d821fb2c0a25855b4233e26d475c2fbeb34 Updated file under test
43-
// 678b086b44753000567aa64344aa0d8034fa0083 Updated file under test
44-
// 8f7d9520f306771340a7c79faea019ad18e4fa1f Updated file under test
45-
// bd5f8ee279924d33be8ccbde82e7f10b9d9ff237 Updated file under test
46-
// c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
47-
fileHistoryEntries = repo.Commits.QueryBy("under-test.txt").ToList();
48-
Assert.Equal(10, fileHistoryEntries.Count());
49-
Assert.Equal("0b5b18f2feb917dee98df1210315b2b2b23c5bec", fileHistoryEntries[0].Commit.Sha);
50-
Assert.Equal("49921d463420a892c9547a326632ef6a9ba3b225", fileHistoryEntries[1].Commit.Sha);
51-
Assert.Equal("70f636e8c64bbc2dfef3735a562bb7e195d8019f", fileHistoryEntries[2].Commit.Sha);
52-
Assert.Equal("d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d", fileHistoryEntries[3].Commit.Sha);
53-
Assert.Equal("9da10ef7e139c49604a12caa866aae141f38b861", fileHistoryEntries[4].Commit.Sha);
54-
Assert.Equal("599a5d821fb2c0a25855b4233e26d475c2fbeb34", fileHistoryEntries[5].Commit.Sha);
55-
Assert.Equal("678b086b44753000567aa64344aa0d8034fa0083", fileHistoryEntries[6].Commit.Sha);
56-
Assert.Equal("8f7d9520f306771340a7c79faea019ad18e4fa1f", fileHistoryEntries[7].Commit.Sha);
57-
Assert.Equal("bd5f8ee279924d33be8ccbde82e7f10b9d9ff237", fileHistoryEntries[8].Commit.Sha);
58-
Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[9].Commit.Sha);
59-
}
60-
}
13+
//Looks like nulltoken deleted the repo this test was using
14+
15+
//[Theory]
16+
//[InlineData("https://github.com/nulltoken/follow-test.git")]
17+
//public void CanDealWithFollowTest(string url)
18+
//{
19+
// var scd = BuildSelfCleaningDirectory();
20+
// var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);
21+
22+
// using (var repo = new Repository(clonedRepoPath))
23+
// {
24+
// // $ git log --follow --format=oneline so-renamed.txt
25+
// // 88f91835062161febb46fb270ef4188f54c09767 Update not-yet-renamed.txt AND rename into so-renamed.txt
26+
// // ef7cb6a63e32595fffb092cb1ae9a32310e58850 Add not-yet-renamed.txt
27+
// var fileHistoryEntries = repo.Commits.QueryBy("so-renamed.txt").ToList();
28+
// Assert.Equal(2, fileHistoryEntries.Count());
29+
// Assert.Equal("88f91835062161febb46fb270ef4188f54c09767", fileHistoryEntries[0].Commit.Sha);
30+
// Assert.Equal("ef7cb6a63e32595fffb092cb1ae9a32310e58850", fileHistoryEntries[1].Commit.Sha);
31+
32+
// // $ git log --follow --format=oneline untouched.txt
33+
// // c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
34+
// fileHistoryEntries = repo.Commits.QueryBy("untouched.txt").ToList();
35+
// Assert.Single(fileHistoryEntries);
36+
// Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[0].Commit.Sha);
37+
38+
// // $ git log --follow --format=oneline under-test.txt
39+
// // 0b5b18f2feb917dee98df1210315b2b2b23c5bec Rename file renamed.txt into under-test.txt
40+
// // 49921d463420a892c9547a326632ef6a9ba3b225 Update file renamed.txt
41+
// // 70f636e8c64bbc2dfef3735a562bb7e195d8019f Rename file under-test.txt into renamed.txt
42+
// // d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d Updated file under test
43+
// // 9da10ef7e139c49604a12caa866aae141f38b861 Updated file under test
44+
// // 599a5d821fb2c0a25855b4233e26d475c2fbeb34 Updated file under test
45+
// // 678b086b44753000567aa64344aa0d8034fa0083 Updated file under test
46+
// // 8f7d9520f306771340a7c79faea019ad18e4fa1f Updated file under test
47+
// // bd5f8ee279924d33be8ccbde82e7f10b9d9ff237 Updated file under test
48+
// // c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
49+
// fileHistoryEntries = repo.Commits.QueryBy("under-test.txt").ToList();
50+
// Assert.Equal(10, fileHistoryEntries.Count());
51+
// Assert.Equal("0b5b18f2feb917dee98df1210315b2b2b23c5bec", fileHistoryEntries[0].Commit.Sha);
52+
// Assert.Equal("49921d463420a892c9547a326632ef6a9ba3b225", fileHistoryEntries[1].Commit.Sha);
53+
// Assert.Equal("70f636e8c64bbc2dfef3735a562bb7e195d8019f", fileHistoryEntries[2].Commit.Sha);
54+
// Assert.Equal("d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d", fileHistoryEntries[3].Commit.Sha);
55+
// Assert.Equal("9da10ef7e139c49604a12caa866aae141f38b861", fileHistoryEntries[4].Commit.Sha);
56+
// Assert.Equal("599a5d821fb2c0a25855b4233e26d475c2fbeb34", fileHistoryEntries[5].Commit.Sha);
57+
// Assert.Equal("678b086b44753000567aa64344aa0d8034fa0083", fileHistoryEntries[6].Commit.Sha);
58+
// Assert.Equal("8f7d9520f306771340a7c79faea019ad18e4fa1f", fileHistoryEntries[7].Commit.Sha);
59+
// Assert.Equal("bd5f8ee279924d33be8ccbde82e7f10b9d9ff237", fileHistoryEntries[8].Commit.Sha);
60+
// Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[9].Commit.Sha);
61+
// }
62+
//}
6163

6264
[Theory]
6365
[InlineData(null)]

Diff for: LibGit2Sharp.Tests/GlobalSettingsFixture.cs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public void CanGetMinimumCompiledInFeatures()
1515
BuiltInFeatures features = GlobalSettings.Version.Features;
1616

1717
Assert.True(features.HasFlag(BuiltInFeatures.Threads));
18-
Assert.True(features.HasFlag(BuiltInFeatures.Https));
1918
}
2019

2120
[Fact]

Diff for: LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net46;netcoreapp2.1</TargetFrameworks>
4+
<TargetFrameworks>net472;netcoreapp2.1</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>
88
<ProjectReference Include="..\LibGit2Sharp\LibGit2Sharp.csproj" />
9-
<ProjectReference Include="..\NativeLibraryLoadTestApp\x86\NativeLibraryLoadTestApp.x86.csproj" Condition="'$(TargetFramework)' == 'net46'" ReferenceOutputAssembly="false" OutputItemType="TestAppExe" />
10-
<ProjectReference Include="..\NativeLibraryLoadTestApp\x64\NativeLibraryLoadTestApp.x64.csproj" Condition="'$(TargetFramework)' == 'net46'" ReferenceOutputAssembly="false" OutputItemType="TestAppExe" />
9+
<ProjectReference Include="..\NativeLibraryLoadTestApp\x86\NativeLibraryLoadTestApp.x86.csproj" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" ReferenceOutputAssembly="false" OutputItemType="TestAppExe" />
10+
<ProjectReference Include="..\NativeLibraryLoadTestApp\x64\NativeLibraryLoadTestApp.x64.csproj" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" ReferenceOutputAssembly="false" OutputItemType="TestAppExe" />
1111
</ItemGroup>
1212

1313
<ItemGroup>
@@ -23,7 +23,7 @@
2323

2424
<ItemGroup>
2525
<Compile Include="..\LibGit2Sharp\Core\Platform.cs" Link="TestHelpers\Platform.cs" />
26-
<Compile Remove="desktop\**" Condition="'$(TargetFramework)' != 'net46'" />
26+
<Compile Remove="desktop\**" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
2727
<Content Include="Resources\**\*.*" CopyToOutputDirectory="PreserveNewest" />
2828
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
2929
</ItemGroup>

Diff for: LibGit2Sharp/AmbiguousSpecificationException.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using LibGit2Sharp.Core;
12
using System;
23
using System.Runtime.Serialization;
34

@@ -7,7 +8,7 @@ namespace LibGit2Sharp
78
/// The exception that is thrown when the provided specification cannot uniquely identify a reference, an object or a path.
89
/// </summary>
910
[Serializable]
10-
public class AmbiguousSpecificationException : LibGit2SharpException
11+
public class AmbiguousSpecificationException : NativeException
1112
{
1213
/// <summary>
1314
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class.
@@ -50,5 +51,13 @@ public AmbiguousSpecificationException(string message, Exception innerException)
5051
protected AmbiguousSpecificationException(SerializationInfo info, StreamingContext context)
5152
: base(info, context)
5253
{ }
54+
55+
internal override GitErrorCode ErrorCode
56+
{
57+
get
58+
{
59+
return GitErrorCode.Ambiguous;
60+
}
61+
}
5362
}
5463
}

Diff for: LibGit2Sharp/BareRepositoryException.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace LibGit2Sharp
99
/// working directory is performed against a bare repository.
1010
/// </summary>
1111
[Serializable]
12-
public class BareRepositoryException : LibGit2SharpException
12+
public class BareRepositoryException : NativeException
1313
{
1414
/// <summary>
1515
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class.
@@ -52,8 +52,16 @@ protected BareRepositoryException(SerializationInfo info, StreamingContext conte
5252
: base(info, context)
5353
{ }
5454

55-
internal BareRepositoryException(string message, GitErrorCode code, GitErrorCategory category)
56-
: base(message, code, category)
55+
internal BareRepositoryException(string message, GitErrorCategory category)
56+
: base(message, category)
5757
{ }
58+
59+
internal override GitErrorCode ErrorCode
60+
{
61+
get
62+
{
63+
return GitErrorCode.BareRepo;
64+
}
65+
}
5866
}
5967
}

Diff for: LibGit2Sharp/CertificateX509.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace LibGit2Sharp
1010
/// </summary>
1111
public class CertificateX509 : Certificate
1212
{
13-
1413
/// <summary>
1514
/// For mocking purposes
1615
/// </summary>
@@ -30,6 +29,11 @@ internal unsafe CertificateX509(git_certificate_x509* cert)
3029
Certificate = new X509Certificate(data);
3130
}
3231

32+
internal CertificateX509(X509Certificate cert)
33+
{
34+
Certificate = cert;
35+
}
36+
3337
internal unsafe IntPtr ToPointers(out IntPtr dataPtr)
3438
{
3539
var certData = Certificate.Export(X509ContentType.Cert);

Diff for: LibGit2Sharp/CheckoutConflictException.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace LibGit2Sharp
1010
/// in the working directory.
1111
/// </summary>
1212
[Serializable]
13-
public class CheckoutConflictException : LibGit2SharpException
13+
public class CheckoutConflictException : NativeException
1414
{
1515
/// <summary>
1616
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class.
@@ -53,8 +53,16 @@ protected CheckoutConflictException(SerializationInfo info, StreamingContext con
5353
: base(info, context)
5454
{ }
5555

56-
internal CheckoutConflictException(string message, GitErrorCode code, GitErrorCategory category)
57-
: base(message, code, category)
56+
internal CheckoutConflictException(string message, GitErrorCategory category)
57+
: base(message, category)
5858
{ }
59+
60+
internal override GitErrorCode ErrorCode
61+
{
62+
get
63+
{
64+
return GitErrorCode.Conflict;
65+
}
66+
}
5967
}
6068
}

0 commit comments

Comments
 (0)