Skip to content

Commit 13f96ea

Browse files
authored
Merge pull request #9 from dotdevelop/dd/issues/2_merge_libgit_repo
dd/issues/2 merge libgit repo
2 parents 3e88e58 + 79bd677 commit 13f96ea

27 files changed

+880
-280
lines changed

LibGit2Sharp.Tests/FileHistoryFixture.cs

Lines changed: 50 additions & 48 deletions
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)]

LibGit2Sharp.Tests/GlobalSettingsFixture.cs

Lines changed: 0 additions & 1 deletion
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]

LibGit2Sharp/AmbiguousSpecificationException.cs

Lines changed: 10 additions & 1 deletion
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
}

LibGit2Sharp/BareRepositoryException.cs

Lines changed: 11 additions & 3 deletions
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
}

LibGit2Sharp/CertificateX509.cs

Lines changed: 5 additions & 1 deletion
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);

LibGit2Sharp/CheckoutConflictException.cs

Lines changed: 11 additions & 3 deletions
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
}

LibGit2Sharp/Core/Ensure.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,20 @@ public static void ArgumentIsExpectedIntPtr(IntPtr argumentValue, IntPtr expecte
114114
}
115115
}
116116

117-
private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCode, GitErrorCategory, LibGit2SharpException>>
117+
private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCategory, LibGit2SharpException>>
118118
GitErrorsToLibGit2SharpExceptions =
119-
new Dictionary<GitErrorCode, Func<string, GitErrorCode, GitErrorCategory, LibGit2SharpException>>
119+
new Dictionary<GitErrorCode, Func<string, GitErrorCategory, LibGit2SharpException>>
120120
{
121-
{ GitErrorCode.User, (m, r, c) => new UserCancelledException(m, r, c) },
122-
{ GitErrorCode.BareRepo, (m, r, c) => new BareRepositoryException(m, r, c) },
123-
{ GitErrorCode.Exists, (m, r, c) => new NameConflictException(m, r, c) },
124-
{ GitErrorCode.InvalidSpecification, (m, r, c) => new InvalidSpecificationException(m, r, c) },
125-
{ GitErrorCode.UnmergedEntries, (m, r, c) => new UnmergedIndexEntriesException(m, r, c) },
126-
{ GitErrorCode.NonFastForward, (m, r, c) => new NonFastForwardException(m, r, c) },
127-
{ GitErrorCode.Conflict, (m, r, c) => new CheckoutConflictException(m, r, c) },
128-
{ GitErrorCode.LockedFile, (m, r, c) => new LockedFileException(m, r, c) },
129-
{ GitErrorCode.NotFound, (m, r, c) => new NotFoundException(m, r, c) },
130-
{ GitErrorCode.Peel, (m, r, c) => new PeelException(m, r, c) },
131-
{ GitErrorCode.Auth, (m, r, c) => new AuthenticationException(m, r, c) },
121+
{ GitErrorCode.User, (m, c) => new UserCancelledException(m, c) },
122+
{ GitErrorCode.BareRepo, (m, c) => new BareRepositoryException(m, c) },
123+
{ GitErrorCode.Exists, (m, c) => new NameConflictException(m, c) },
124+
{ GitErrorCode.InvalidSpecification, (m, c) => new InvalidSpecificationException(m, c) },
125+
{ GitErrorCode.UnmergedEntries, (m, c) => new UnmergedIndexEntriesException(m, c) },
126+
{ GitErrorCode.NonFastForward, (m, c) => new NonFastForwardException(m, c) },
127+
{ GitErrorCode.Conflict, (m, c) => new CheckoutConflictException(m, c) },
128+
{ GitErrorCode.LockedFile, (m, c) => new LockedFileException(m, c) },
129+
{ GitErrorCode.NotFound, (m, c) => new NotFoundException(m, c) },
130+
{ GitErrorCode.Peel, (m, c) => new PeelException(m, c) },
132131
};
133132

134133
private static unsafe void HandleError(int result)
@@ -146,13 +145,13 @@ private static unsafe void HandleError(int result)
146145
errorMessage = LaxUtf8Marshaler.FromNative(error->Message);
147146
}
148147

149-
Func<string, GitErrorCode, GitErrorCategory, LibGit2SharpException> exceptionBuilder;
148+
Func<string, GitErrorCategory, LibGit2SharpException> exceptionBuilder;
150149
if (!GitErrorsToLibGit2SharpExceptions.TryGetValue((GitErrorCode)result, out exceptionBuilder))
151150
{
152-
exceptionBuilder = (m, r, c) => new LibGit2SharpException(m, r, c);
151+
exceptionBuilder = (m, c) => new LibGit2SharpException(m, c);
153152
}
154153

155-
throw exceptionBuilder(errorMessage, (GitErrorCode)result, errorCategory);
154+
throw exceptionBuilder(errorMessage, errorCategory);
156155
}
157156

158157
/// <summary>
@@ -257,7 +256,7 @@ public static void GitObjectIsNotNull(GitObject gitObject, string identifier)
257256
}
258257

259258
var messageFormat = "No valid git object identified by '{0}' exists in the repository.";
260-
259+
261260
if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
262261
{
263262
throw new UnbornBranchException(messageFormat, identifier);

0 commit comments

Comments
 (0)