Skip to content

dd/issues/2 merge libgit repo #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 50 additions & 48 deletions LibGit2Sharp.Tests/FileHistoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,56 @@ namespace LibGit2Sharp.Tests
{
public class FileHistoryFixture : BaseFixture
{
[Theory]
[InlineData("https://github.com/nulltoken/follow-test.git")]
public void CanDealWithFollowTest(string url)
{
var scd = BuildSelfCleaningDirectory();
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

using (var repo = new Repository(clonedRepoPath))
{
// $ git log --follow --format=oneline so-renamed.txt
// 88f91835062161febb46fb270ef4188f54c09767 Update not-yet-renamed.txt AND rename into so-renamed.txt
// ef7cb6a63e32595fffb092cb1ae9a32310e58850 Add not-yet-renamed.txt
var fileHistoryEntries = repo.Commits.QueryBy("so-renamed.txt").ToList();
Assert.Equal(2, fileHistoryEntries.Count());
Assert.Equal("88f91835062161febb46fb270ef4188f54c09767", fileHistoryEntries[0].Commit.Sha);
Assert.Equal("ef7cb6a63e32595fffb092cb1ae9a32310e58850", fileHistoryEntries[1].Commit.Sha);

// $ git log --follow --format=oneline untouched.txt
// c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
fileHistoryEntries = repo.Commits.QueryBy("untouched.txt").ToList();
Assert.Single(fileHistoryEntries);
Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[0].Commit.Sha);

// $ git log --follow --format=oneline under-test.txt
// 0b5b18f2feb917dee98df1210315b2b2b23c5bec Rename file renamed.txt into under-test.txt
// 49921d463420a892c9547a326632ef6a9ba3b225 Update file renamed.txt
// 70f636e8c64bbc2dfef3735a562bb7e195d8019f Rename file under-test.txt into renamed.txt
// d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d Updated file under test
// 9da10ef7e139c49604a12caa866aae141f38b861 Updated file under test
// 599a5d821fb2c0a25855b4233e26d475c2fbeb34 Updated file under test
// 678b086b44753000567aa64344aa0d8034fa0083 Updated file under test
// 8f7d9520f306771340a7c79faea019ad18e4fa1f Updated file under test
// bd5f8ee279924d33be8ccbde82e7f10b9d9ff237 Updated file under test
// c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
fileHistoryEntries = repo.Commits.QueryBy("under-test.txt").ToList();
Assert.Equal(10, fileHistoryEntries.Count());
Assert.Equal("0b5b18f2feb917dee98df1210315b2b2b23c5bec", fileHistoryEntries[0].Commit.Sha);
Assert.Equal("49921d463420a892c9547a326632ef6a9ba3b225", fileHistoryEntries[1].Commit.Sha);
Assert.Equal("70f636e8c64bbc2dfef3735a562bb7e195d8019f", fileHistoryEntries[2].Commit.Sha);
Assert.Equal("d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d", fileHistoryEntries[3].Commit.Sha);
Assert.Equal("9da10ef7e139c49604a12caa866aae141f38b861", fileHistoryEntries[4].Commit.Sha);
Assert.Equal("599a5d821fb2c0a25855b4233e26d475c2fbeb34", fileHistoryEntries[5].Commit.Sha);
Assert.Equal("678b086b44753000567aa64344aa0d8034fa0083", fileHistoryEntries[6].Commit.Sha);
Assert.Equal("8f7d9520f306771340a7c79faea019ad18e4fa1f", fileHistoryEntries[7].Commit.Sha);
Assert.Equal("bd5f8ee279924d33be8ccbde82e7f10b9d9ff237", fileHistoryEntries[8].Commit.Sha);
Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[9].Commit.Sha);
}
}
//Looks like nulltoken deleted the repo this test was using

//[Theory]
//[InlineData("https://github.com/nulltoken/follow-test.git")]
//public void CanDealWithFollowTest(string url)
//{
// var scd = BuildSelfCleaningDirectory();
// var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

// using (var repo = new Repository(clonedRepoPath))
// {
// // $ git log --follow --format=oneline so-renamed.txt
// // 88f91835062161febb46fb270ef4188f54c09767 Update not-yet-renamed.txt AND rename into so-renamed.txt
// // ef7cb6a63e32595fffb092cb1ae9a32310e58850 Add not-yet-renamed.txt
// var fileHistoryEntries = repo.Commits.QueryBy("so-renamed.txt").ToList();
// Assert.Equal(2, fileHistoryEntries.Count());
// Assert.Equal("88f91835062161febb46fb270ef4188f54c09767", fileHistoryEntries[0].Commit.Sha);
// Assert.Equal("ef7cb6a63e32595fffb092cb1ae9a32310e58850", fileHistoryEntries[1].Commit.Sha);

// // $ git log --follow --format=oneline untouched.txt
// // c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
// fileHistoryEntries = repo.Commits.QueryBy("untouched.txt").ToList();
// Assert.Single(fileHistoryEntries);
// Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[0].Commit.Sha);

// // $ git log --follow --format=oneline under-test.txt
// // 0b5b18f2feb917dee98df1210315b2b2b23c5bec Rename file renamed.txt into under-test.txt
// // 49921d463420a892c9547a326632ef6a9ba3b225 Update file renamed.txt
// // 70f636e8c64bbc2dfef3735a562bb7e195d8019f Rename file under-test.txt into renamed.txt
// // d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d Updated file under test
// // 9da10ef7e139c49604a12caa866aae141f38b861 Updated file under test
// // 599a5d821fb2c0a25855b4233e26d475c2fbeb34 Updated file under test
// // 678b086b44753000567aa64344aa0d8034fa0083 Updated file under test
// // 8f7d9520f306771340a7c79faea019ad18e4fa1f Updated file under test
// // bd5f8ee279924d33be8ccbde82e7f10b9d9ff237 Updated file under test
// // c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
// fileHistoryEntries = repo.Commits.QueryBy("under-test.txt").ToList();
// Assert.Equal(10, fileHistoryEntries.Count());
// Assert.Equal("0b5b18f2feb917dee98df1210315b2b2b23c5bec", fileHistoryEntries[0].Commit.Sha);
// Assert.Equal("49921d463420a892c9547a326632ef6a9ba3b225", fileHistoryEntries[1].Commit.Sha);
// Assert.Equal("70f636e8c64bbc2dfef3735a562bb7e195d8019f", fileHistoryEntries[2].Commit.Sha);
// Assert.Equal("d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d", fileHistoryEntries[3].Commit.Sha);
// Assert.Equal("9da10ef7e139c49604a12caa866aae141f38b861", fileHistoryEntries[4].Commit.Sha);
// Assert.Equal("599a5d821fb2c0a25855b4233e26d475c2fbeb34", fileHistoryEntries[5].Commit.Sha);
// Assert.Equal("678b086b44753000567aa64344aa0d8034fa0083", fileHistoryEntries[6].Commit.Sha);
// Assert.Equal("8f7d9520f306771340a7c79faea019ad18e4fa1f", fileHistoryEntries[7].Commit.Sha);
// Assert.Equal("bd5f8ee279924d33be8ccbde82e7f10b9d9ff237", fileHistoryEntries[8].Commit.Sha);
// Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[9].Commit.Sha);
// }
//}

[Theory]
[InlineData(null)]
Expand Down
1 change: 0 additions & 1 deletion LibGit2Sharp.Tests/GlobalSettingsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public void CanGetMinimumCompiledInFeatures()
BuiltInFeatures features = GlobalSettings.Version.Features;

Assert.True(features.HasFlag(BuiltInFeatures.Threads));
Assert.True(features.HasFlag(BuiltInFeatures.Https));
}

[Fact]
Expand Down
11 changes: 10 additions & 1 deletion LibGit2Sharp/AmbiguousSpecificationException.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using LibGit2Sharp.Core;
using System;
using System.Runtime.Serialization;

Expand All @@ -7,7 +8,7 @@ namespace LibGit2Sharp
/// The exception that is thrown when the provided specification cannot uniquely identify a reference, an object or a path.
/// </summary>
[Serializable]
public class AmbiguousSpecificationException : LibGit2SharpException
public class AmbiguousSpecificationException : NativeException
{
/// <summary>
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class.
Expand Down Expand Up @@ -50,5 +51,13 @@ public AmbiguousSpecificationException(string message, Exception innerException)
protected AmbiguousSpecificationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }

internal override GitErrorCode ErrorCode
{
get
{
return GitErrorCode.Ambiguous;
}
}
}
}
14 changes: 11 additions & 3 deletions LibGit2Sharp/BareRepositoryException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LibGit2Sharp
/// working directory is performed against a bare repository.
/// </summary>
[Serializable]
public class BareRepositoryException : LibGit2SharpException
public class BareRepositoryException : NativeException
{
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class.
Expand Down Expand Up @@ -52,8 +52,16 @@ protected BareRepositoryException(SerializationInfo info, StreamingContext conte
: base(info, context)
{ }

internal BareRepositoryException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
internal BareRepositoryException(string message, GitErrorCategory category)
: base(message, category)
{ }

internal override GitErrorCode ErrorCode
{
get
{
return GitErrorCode.BareRepo;
}
}
}
}
6 changes: 5 additions & 1 deletion LibGit2Sharp/CertificateX509.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace LibGit2Sharp
/// </summary>
public class CertificateX509 : Certificate
{

/// <summary>
/// For mocking purposes
/// </summary>
Expand All @@ -30,6 +29,11 @@ internal unsafe CertificateX509(git_certificate_x509* cert)
Certificate = new X509Certificate(data);
}

internal CertificateX509(X509Certificate cert)
{
Certificate = cert;
}

internal unsafe IntPtr ToPointers(out IntPtr dataPtr)
{
var certData = Certificate.Export(X509ContentType.Cert);
Expand Down
14 changes: 11 additions & 3 deletions LibGit2Sharp/CheckoutConflictException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LibGit2Sharp
/// in the working directory.
/// </summary>
[Serializable]
public class CheckoutConflictException : LibGit2SharpException
public class CheckoutConflictException : NativeException
{
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class.
Expand Down Expand Up @@ -53,8 +53,16 @@ protected CheckoutConflictException(SerializationInfo info, StreamingContext con
: base(info, context)
{ }

internal CheckoutConflictException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
internal CheckoutConflictException(string message, GitErrorCategory category)
: base(message, category)
{ }

internal override GitErrorCode ErrorCode
{
get
{
return GitErrorCode.Conflict;
}
}
}
}
33 changes: 16 additions & 17 deletions LibGit2Sharp/Core/Ensure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,20 @@ public static void ArgumentIsExpectedIntPtr(IntPtr argumentValue, IntPtr expecte
}
}

private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCode, GitErrorCategory, LibGit2SharpException>>
private static readonly Dictionary<GitErrorCode, Func<string, GitErrorCategory, LibGit2SharpException>>
GitErrorsToLibGit2SharpExceptions =
new Dictionary<GitErrorCode, Func<string, GitErrorCode, GitErrorCategory, LibGit2SharpException>>
new Dictionary<GitErrorCode, Func<string, GitErrorCategory, LibGit2SharpException>>
{
{ GitErrorCode.User, (m, r, c) => new UserCancelledException(m, r, c) },
{ GitErrorCode.BareRepo, (m, r, c) => new BareRepositoryException(m, r, c) },
{ GitErrorCode.Exists, (m, r, c) => new NameConflictException(m, r, c) },
{ GitErrorCode.InvalidSpecification, (m, r, c) => new InvalidSpecificationException(m, r, c) },
{ GitErrorCode.UnmergedEntries, (m, r, c) => new UnmergedIndexEntriesException(m, r, c) },
{ GitErrorCode.NonFastForward, (m, r, c) => new NonFastForwardException(m, r, c) },
{ GitErrorCode.Conflict, (m, r, c) => new CheckoutConflictException(m, r, c) },
{ GitErrorCode.LockedFile, (m, r, c) => new LockedFileException(m, r, c) },
{ GitErrorCode.NotFound, (m, r, c) => new NotFoundException(m, r, c) },
{ GitErrorCode.Peel, (m, r, c) => new PeelException(m, r, c) },
{ GitErrorCode.Auth, (m, r, c) => new AuthenticationException(m, r, c) },
{ GitErrorCode.User, (m, c) => new UserCancelledException(m, c) },
{ GitErrorCode.BareRepo, (m, c) => new BareRepositoryException(m, c) },
{ GitErrorCode.Exists, (m, c) => new NameConflictException(m, c) },
{ GitErrorCode.InvalidSpecification, (m, c) => new InvalidSpecificationException(m, c) },
{ GitErrorCode.UnmergedEntries, (m, c) => new UnmergedIndexEntriesException(m, c) },
{ GitErrorCode.NonFastForward, (m, c) => new NonFastForwardException(m, c) },
{ GitErrorCode.Conflict, (m, c) => new CheckoutConflictException(m, c) },
{ GitErrorCode.LockedFile, (m, c) => new LockedFileException(m, c) },
{ GitErrorCode.NotFound, (m, c) => new NotFoundException(m, c) },
{ GitErrorCode.Peel, (m, c) => new PeelException(m, c) },
};

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

Func<string, GitErrorCode, GitErrorCategory, LibGit2SharpException> exceptionBuilder;
Func<string, GitErrorCategory, LibGit2SharpException> exceptionBuilder;
if (!GitErrorsToLibGit2SharpExceptions.TryGetValue((GitErrorCode)result, out exceptionBuilder))
{
exceptionBuilder = (m, r, c) => new LibGit2SharpException(m, r, c);
exceptionBuilder = (m, c) => new LibGit2SharpException(m, c);
}

throw exceptionBuilder(errorMessage, (GitErrorCode)result, errorCategory);
throw exceptionBuilder(errorMessage, errorCategory);
}

/// <summary>
Expand Down Expand Up @@ -257,7 +256,7 @@ public static void GitObjectIsNotNull(GitObject gitObject, string identifier)
}

var messageFormat = "No valid git object identified by '{0}' exists in the repository.";

if (string.Equals("HEAD", identifier, StringComparison.Ordinal))
{
throw new UnbornBranchException(messageFormat, identifier);
Expand Down
Loading