Skip to content
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# LibGit2Sharp releases

## v0.2.0

- [Fix] Fix Repository.Info.IsEmpty
- [Fix] Fix default CommitCollection sorting behavior
- [Fix] Fix creation of reference to prevent it from choking on corrupted ones
- [Fix] Fix interop issue in a IIS hosted application
- [Upd] Update CommitCollection API to query commits
- [Upd] Update CommitCollection API to query commits
- [Upd] Update libgit2 binaries to 4191d52

## v0.1.1

- [Fix] Fix NuGet packaging
Expand Down
52 changes: 26 additions & 26 deletions CI-build.msbuild
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<Project DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\Lib\MSBuild.Community.Tasks\MSBuild.Community.Tasks.dll" TaskName="NUnit" />
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\Lib\MSBuild.ExtensionPack\MSBuild.ExtensionPack.dll" TaskName="Folder"/>

<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\Lib\MSBuild.Community.Tasks\MSBuild.Community.Tasks.dll" TaskName="NUnit" />
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\Lib\MSBuild.ExtensionPack\MSBuild.ExtensionPack.dll" TaskName="Folder"/>

<LibObjDir>$(MSBuildProjectDirectory)\LibGit2Sharp\obj\</LibObjDir>
<TestsObjDir>$(MSBuildProjectDirectory)\LibGit2Sharp.Tests\obj\</TestsObjDir>
<OutputDir>$(MSBuildProjectDirectory)\build\</OutputDir>
</PropertyGroup>

<Target Name="Clean">
<Folder TaskAction="RemoveContent" Path="$(LibObjDir)" Condition="Exists('$(LibObjDir)')" />
<Folder TaskAction="RemoveContent" Path="$(TestsObjDir)" Condition="Exists('$(TestsObjDir)')" />
<Folder TaskAction="RemoveContent" Path="$(OutputDir)" Condition="Exists('$(OutputDir)')" />
<PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>

<RemoveDir Directories="$(LibObjDir)" Condition="Exists('$(LibObjDir)')" />
<RemoveDir Directories="$(TestsObjDir)" Condition="Exists('$(TestsObjDir)')" />
<RemoveDir Directories="$(OutputDir)" Condition="Exists('$(OutputDir)')" />
</Target>

<Target Name="Build" DependsOnTargets="Clean">
<MSBuild
<LibObjDir>$(MSBuildProjectDirectory)\LibGit2Sharp\obj\</LibObjDir>
<TestsObjDir>$(MSBuildProjectDirectory)\LibGit2Sharp.Tests\obj\</TestsObjDir>
<OutputDir>$(MSBuildProjectDirectory)\build\</OutputDir>
</PropertyGroup>

<Target Name="Clean">
<Folder TaskAction="RemoveContent" Path="$(LibObjDir)" Condition="Exists('$(LibObjDir)')" />
<Folder TaskAction="RemoveContent" Path="$(TestsObjDir)" Condition="Exists('$(TestsObjDir)')" />
<Folder TaskAction="RemoveContent" Path="$(OutputDir)" Condition="Exists('$(OutputDir)')" />

<RemoveDir Directories="$(LibObjDir)" Condition="Exists('$(LibObjDir)')" />
<RemoveDir Directories="$(TestsObjDir)" Condition="Exists('$(TestsObjDir)')" />
<RemoveDir Directories="$(OutputDir)" Condition="Exists('$(OutputDir)')" />
</Target>

<Target Name="Build" DependsOnTargets="Clean">
<MSBuild
Projects="LibGit2Sharp.sln"
Targets="Build"
Properties="Configuration=$(Configuration);TrackFileAccess=false;OutDir=$(OutputDir)" />
</Target>
<Target Name="Test" DependsOnTargets="Build">
<NUnit Assemblies="$(OutputDir)LibGit2Sharp.Tests.dll"
</Target>

<Target Name="Test" DependsOnTargets="Build">
<NUnit Assemblies="$(OutputDir)LibGit2Sharp.Tests.dll"
ToolPath="$(MSBuildProjectDirectory)\Lib\NUnit\"
OutputXmlFile="$(OutputDir)Test-result.xml" />
</Target>
</Target>
</Project>
Binary file added Lib/git2-0.dll
Binary file not shown.
Binary file removed Lib/git2.dll
Binary file not shown.
65 changes: 29 additions & 36 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void CanCountCommits()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Commits.Count.ShouldEqual(7);
repo.Commits.Count().ShouldEqual(7);
}
}

Expand All @@ -28,11 +28,11 @@ public void CanCorrectlyCountCommitsWhenSwitchingToAnotherBranch()
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Branches.Checkout("test");
repo.Commits.Count.ShouldEqual(2);
repo.Commits.Count().ShouldEqual(2);
repo.Commits.First().Id.Sha.ShouldEqual("e90810b8df3e80c413d903f631643c716887138d");

repo.Branches.Checkout("master");
repo.Commits.Count.ShouldEqual(7);
repo.Commits.Count().ShouldEqual(7);
repo.Commits.First().Id.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345");
}
}
Expand Down Expand Up @@ -67,7 +67,7 @@ public void CanEnumerateCommitsFromSha()
int count = 0;
using (var repo = new Repository(Constants.TestRepoPath))
{
foreach (var commit in repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f"))
foreach (var commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f" }))
{
commit.ShouldNotBeNull();
count++;
Expand All @@ -77,14 +77,25 @@ public void CanEnumerateCommitsFromSha()
}

[Test]
public void BuildingACommitCollectionFromUnknownShaOrInvalidReferenceThrows()
public void QueryingTheCommitHistoryWithUnknownShaOrInvalidReferenceThrows()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ArgumentException>(() => repo.Commits.StartingAt(Constants.UnknownSha));
Assert.Throws<ArgumentException>(() => repo.Commits.StartingAt("refs/heads/deadbeef"));
Assert.Throws<ArgumentException>(() => repo.Commits.StartingAt(repo.Branches["deadbeef"]));
Assert.Throws<ArgumentException>(() => repo.Commits.StartingAt(repo.Refs["refs/heads/deadbeef"]));
Assert.Throws<InvalidOperationException>(() => repo.Commits.QueryBy(new Filter { Since = Constants.UnknownSha}));
Assert.Throws<InvalidOperationException>(() => repo.Commits.QueryBy(new Filter { Since = "refs/heads/deadbeef"}));
Assert.Throws<InvalidOperationException>(() => repo.Commits.QueryBy(new Filter { Since = repo.Branches["deadbeef"]}));
Assert.Throws<InvalidOperationException>(() => repo.Commits.QueryBy(new Filter { Since = repo.Refs["refs/heads/deadbeef"] }));
}
}

[Test]
public void QueryingTheCommitHistoryWithBadParamsThrows()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ArgumentException>(() => repo.Commits.QueryBy(new Filter { Since = string.Empty }));
Assert.Throws<ArgumentNullException>(() => repo.Commits.QueryBy(new Filter { Since = null }));
Assert.Throws<ArgumentNullException>(() => repo.Commits.QueryBy(null));
}
}

Expand All @@ -95,7 +106,7 @@ public void CanEnumerateCommitsWithReverseTimeSorting()
int count = 0;
using (var repo = new Repository(Constants.TestRepoPath))
{
foreach (var commit in repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f").SortBy(GitSortOptions.Time | GitSortOptions.Reverse))
foreach (var commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time | GitSortOptions.Reverse }))
{
commit.ShouldNotBeNull();
commit.Sha.StartsWith(expectedShas[count]);
Expand All @@ -110,7 +121,7 @@ public void CanEnumerateCommitsWithReverseTopoSorting()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
var commits = repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f").SortBy(GitSortOptions.Topological | GitSortOptions.Reverse).ToList();
var commits = repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time | GitSortOptions.Reverse }).ToList();
foreach (var commit in commits)
{
commit.ShouldNotBeNull();
Expand All @@ -129,7 +140,7 @@ public void CanEnumerateCommitsWithTimeSorting()
int count = 0;
using (var repo = new Repository(Constants.TestRepoPath))
{
foreach (var commit in repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f").SortBy(GitSortOptions.Time))
foreach (var commit in repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Time }))
{
commit.ShouldNotBeNull();
commit.Sha.StartsWith(expectedShas[count]);
Expand All @@ -144,7 +155,7 @@ public void CanEnumerateCommitsWithTopoSorting()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
var commits = repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f").SortBy(GitSortOptions.Topological).ToList();
var commits = repo.Commits.QueryBy(new Filter { Since = "a4a7dce85cf63874e984719f4fdd239f5145052f", SortBy = GitSortOptions.Topological }).ToList();
foreach (var commit in commits)
{
commit.ShouldNotBeNull();
Expand All @@ -158,14 +169,14 @@ public void CanEnumerateCommitsWithTopoSorting()
}

[Test]
public void CanLookupCommitAlt()
public void CanEnumerateUsingTwoCommitsAsBoundaries()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
var commit = repo.Commits[sha];
commit.Message.ShouldEqual("testing\n");
commit.MessageShort.ShouldEqual("testing");
commit.Sha.ShouldEqual(sha);
var commits = repo.Commits.QueryBy(new Filter { Since = "refs/heads/br2", Until = "refs/heads/packed-test" });

IEnumerable<string> abbrevShas = commits.Select(c => c.Id.Sha.Substring(0, 7)).ToArray();
CollectionAssert.AreEquivalent(new[] { "a4a7dce", "c47800c", "9fd738e" }, abbrevShas);
}
}

Expand Down Expand Up @@ -220,23 +231,5 @@ public void CanReadCommitWithMultipleParents()
commit.Parents.Count().ShouldEqual(2);
}
}

[Test]
public void PushingEmptyShaThrows()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ArgumentException>(() => repo.Commits.StartingAt(string.Empty));
}
}

[Test]
public void PushingNullShaThrows()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ArgumentNullException>(() => repo.Commits.StartingAt((string) null));
}
}
}
}
23 changes: 6 additions & 17 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using NUnit.Framework;

Expand Down Expand Up @@ -57,6 +58,11 @@ private static void AssertInitializedRepository(Repository repo)
repo.Info.IsHeadDetached.ShouldBeFalse();
repo.Head.TargetIdentifier.ShouldEqual("refs/heads/master");
repo.Head.ResolveToDirectReference().ShouldBeNull();

repo.Commits.Count().ShouldEqual(0);
repo.Commits.QueryBy(new Filter { Since = repo.Head }).Count().ShouldEqual(0);
repo.Commits.QueryBy(new Filter { Since = "HEAD" }).Count().ShouldEqual(0);
repo.Commits.QueryBy(new Filter { Since = "refs/heads/master" }).Count().ShouldEqual(0);
}

[Test]
Expand Down Expand Up @@ -233,22 +239,5 @@ public void CheckingForObjectExistenceWithBadParamsThrows()
Assert.Throws<ArgumentNullException>(() => repo.HasObject(null));
}
}

[Test]
public void CheckForDetachedHeadOnNewRepo()
{
using (var scd = new SelfCleaningDirectory())
{
var dir = Repository.Init(scd.DirectoryPath, true);
Path.IsPathRooted(dir).ShouldBeTrue();
Directory.Exists(dir).ShouldBeTrue();

using (var repo = new Repository(dir))
{
repo.Info.IsEmpty.ShouldBeTrue();
repo.Info.IsHeadDetached.ShouldBeFalse();
}
}
}
}
}
13 changes: 11 additions & 2 deletions LibGit2Sharp/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public bool IsCurrentRepositoryHead
/// <summary>
/// Gets the commits on this branch. (Starts walking from the References's target).
/// </summary>
public CommitCollection Commits
public ICommitCollection Commits
{
get { return repo.Commits.StartingAt(this); }
get { return repo.Commits.QueryBy(new Filter{Since = this}); }
}

#region IEquatable<Branch> Members
Expand Down Expand Up @@ -149,5 +149,14 @@ private static string ShortenName(string branchName)
{
return !Equals(left, right);
}

/// <summary>
/// Returns the <see cref="CanonicalName"/>, a <see cref="String"/> representation of the current <see cref="Branch"/>.
/// </summary>
/// <returns>The <see cref="CanonicalName"/> that represents the current <see cref="Branch"/>.</returns>
public override string ToString()
{
return CanonicalName;
}
}
}
4 changes: 2 additions & 2 deletions LibGit2Sharp/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ internal static Commit BuildFromPtr(IntPtr obj, ObjectId id, Repository repo)

return new Commit(id, treeId, repo)
{
Message = NativeMethods.git_commit_message(obj),
MessageShort = NativeMethods.git_commit_message_short(obj),
Message = NativeMethods.git_commit_message(obj).MarshallAsString(),
MessageShort = NativeMethods.git_commit_message_short(obj).MarshallAsString(),
Author = new Signature(NativeMethods.git_commit_author(obj)),
Committer = new Signature(NativeMethods.git_commit_committer(obj)),
};
Expand Down
Loading