Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
23bb357
Update libgit2 binaries to f02f4b5
nulltoken May 14, 2011
a6abf7d
Improve error handling mechanism
nulltoken May 14, 2011
a375658
Reduce public API exposure
nulltoken May 15, 2011
3db11df
Refactor SelfCleaningDirectory and TemporaryCloneOfTestRepo test helpers
nulltoken May 15, 2011
ec29248
Update backlog
nulltoken May 15, 2011
9202e91
Fix some issues pinpointed by Code Analysis
nulltoken May 15, 2011
02f414c
Improve documentation and tests related to initialization and opening…
nulltoken May 16, 2011
b81a2d1
Add UnknownSha to test helper Constants
nulltoken May 17, 2011
6cdd301
Fix default CommitCollection sorting behavior
nulltoken May 17, 2011
3e2535d
Update backlog
nulltoken May 17, 2011
2a52952
Add a corrupted branch to the test repository
nulltoken May 18, 2011
1047733
Fix creation of reference to prevent it from choking on corrupted ones
nulltoken May 18, 2011
5ea4866
Add some documentation
nulltoken May 19, 2011
6b8b8a2
Refactor SafeHandles
nulltoken May 19, 2011
4e90db8
Add RevWalkerSafeHandle to ensure proper release of non managed resou…
nulltoken May 19, 2011
548b8d9
Unify the behavior of CommitEnumerator
nulltoken May 19, 2011
4322bd7
Enforce CommitEnumerator immutability
nulltoken May 19, 2011
65de100
Fix Repository.Info.IsEmpty
nulltoken May 19, 2011
cf9dbed
Convert CommitCollection.StartingAt() overloads as extension methods
nulltoken May 19, 2011
8720df7
Enforce CommitCollection test coverage
nulltoken May 19, 2011
2785f53
Ensure a CommitCollection can not be built from an unknown sha or a c…
nulltoken May 19, 2011
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
Binary file modified Lib/git2.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LibGit2Sharp.Tests
[TestFixture]
public class BranchFixture
{
private readonly List<string> expectedBranches = new List<string> {"packed-test", "packed", "br2", "master", "test"};
private readonly List<string> expectedBranches = new List<string> {"packed-test", "packed", "br2", "master", "test", "deadbeef"};

[Test]
public void CanCheckoutAnExistingBranch()
Expand Down Expand Up @@ -76,7 +76,7 @@ public void CanListAllBranches()
Assert.Contains(r.Name, expectedBranches);
}

repo.Branches.Count().ShouldEqual(5);
repo.Branches.Count().ShouldEqual(6);
}
}

Expand Down
40 changes: 38 additions & 2 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ public void CanCountCommits()
}
}

[Test]
public void CanCorrectlyCountCommitsWhenSwitchingToAnotherBranch()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Branches.Checkout("test");
repo.Commits.Count.ShouldEqual(2);
repo.Commits.First().Id.Sha.ShouldEqual("e90810b8df3e80c413d903f631643c716887138d");

repo.Branches.Checkout("master");
repo.Commits.Count.ShouldEqual(7);
repo.Commits.First().Id.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345");
}
}

[Test]
public void CanEnumerateCommits()
{
Expand All @@ -37,6 +52,15 @@ public void CanEnumerateCommits()
count.ShouldEqual(7);
}

[Test]
public void DefaultOrderingWhenEnumeratingCommitsIsTimeBased()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Commits.SortedBy.ShouldEqual(GitSortOptions.Time);
}
}

[Test]
public void CanEnumerateCommitsFromSha()
{
Expand All @@ -52,6 +76,18 @@ public void CanEnumerateCommitsFromSha()
count.ShouldEqual(6);
}

[Test]
public void BuildingACommitCollectionFromUnknownShaOrInvalidReferenceThrows()
{
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"]));
}
}

[Test]
public void CanEnumerateCommitsWithReverseTimeSorting()
{
Expand All @@ -74,7 +110,7 @@ public void CanEnumerateCommitsWithReverseTopoSorting()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
var commits = repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f").SortBy(GitSortOptions.Topo | GitSortOptions.Reverse).ToList();
var commits = repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f").SortBy(GitSortOptions.Topological | GitSortOptions.Reverse).ToList();
foreach (var commit in commits)
{
commit.ShouldNotBeNull();
Expand Down Expand Up @@ -108,7 +144,7 @@ public void CanEnumerateCommitsWithTopoSorting()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
var commits = repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f").SortBy(GitSortOptions.Topo).ToList();
var commits = repo.Commits.StartingAt("a4a7dce85cf63874e984719f4fdd239f5145052f").SortBy(GitSortOptions.Topological).ToList();
foreach (var commit in commits)
{
commit.ShouldNotBeNull();
Expand Down
1 change: 1 addition & 0 deletions LibGit2Sharp.Tests/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public static class Constants
public const string TestRepoPath = "./Resources/testrepo.git";
public const string TestRepoWithWorkingDirPath = "./Resources/testrepo_wd/.git";
public const string TemporaryReposPath = "TestRepos";
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh, deadbeef!

}
}
8 changes: 3 additions & 5 deletions LibGit2Sharp.Tests/IndexFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,14 @@ public void CanStageANewFileWithAFullPath()
[Test]
public void StagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows()
{
string tempPath = new DirectoryInfo("./temp").FullName;

using (new SelfCleaningDirectory(tempPath))
using (var scd = new SelfCleaningDirectory())
using (var path = new TemporaryCloneOfTestRepo(Constants.TestRepoWithWorkingDirPath))
using (var repo = new Repository(path.RepositoryPath))
{
Directory.CreateDirectory(tempPath);
var di = Directory.CreateDirectory(scd.DirectoryPath);

const string filename = "unit_test.txt";
string fullPath = Path.Combine(tempPath, filename);
string fullPath = Path.Combine(di.FullName, filename);
File.WriteAllText(fullPath, "some contents");

Assert.Throws<ArgumentException>(() => repo.Index.Stage(fullPath));
Expand Down
5 changes: 3 additions & 2 deletions LibGit2Sharp.Tests/ReferenceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace LibGit2Sharp.Tests
[TestFixture]
public class ReferenceFixture
{
private readonly List<string> expectedRefs = new List<string> {"refs/heads/packed-test", "refs/heads/packed", "refs/heads/br2", "refs/heads/master", "refs/heads/test", "refs/tags/test", "refs/tags/e90810b", "refs/tags/lw"};
private readonly List<string> expectedRefs = new List<string> { "refs/heads/packed-test", "refs/heads/packed", "refs/heads/br2", "refs/heads/master", "refs/heads/test",
"refs/heads/deadbeef", "refs/tags/test", "refs/tags/e90810b", "refs/tags/lw" };

[Test]
public void CanCreateADirectReference()
Expand Down Expand Up @@ -211,7 +212,7 @@ public void CanListAllReferences()
Assert.Contains(r.CanonicalName, expectedRefs);
}

repo.Refs.Count().ShouldEqual(8);
repo.Refs.Count().ShouldEqual(9);
}
}

Expand Down
23 changes: 11 additions & 12 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ namespace LibGit2Sharp.Tests
[TestFixture]
public class RepositoryFixture
{
private const string newRepoPath = "new_repo";

private const string commitSha = "8496071c1b46c854b31185ea97743be6a8774479";
private const string notFoundSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";

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

using (var repo = new Repository(dir))
{
repo.Info.WorkingDirectory.ShouldBeNull();
repo.Info.Path.ShouldEqual(scd.RootedDirectoryPath + @"\");
repo.Info.IsBare.ShouldBeTrue();

AssertInitializedRepository(repo);
Expand All @@ -35,15 +33,16 @@ public void CanCreateBareRepo()
[Test]
public void CanCreateStandardRepo()
{
using (new SelfCleaningDirectory(newRepoPath))
using (var scd = new SelfCleaningDirectory())
{
var dir = Repository.Init(newRepoPath);
var dir = Repository.Init(scd.DirectoryPath);
Path.IsPathRooted(dir).ShouldBeTrue();
Directory.Exists(dir).ShouldBeTrue();

using (var repo = new Repository(dir))
{
repo.Info.WorkingDirectory.ShouldNotBeNull();
repo.Info.Path.ShouldEqual(Path.Combine(scd.RootedDirectoryPath, ".git" + @"\"));
repo.Info.IsBare.ShouldBeFalse();

AssertInitializedRepository(repo);
Expand Down Expand Up @@ -137,8 +136,8 @@ public void LookupObjectByWrongShaReturnsNull()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Lookup(notFoundSha).ShouldBeNull();
repo.Lookup<GitObject>(notFoundSha).ShouldBeNull();
repo.Lookup(Constants.UnknownSha).ShouldBeNull();
repo.Lookup<GitObject>(Constants.UnknownSha).ShouldBeNull();
}
}

Expand All @@ -159,7 +158,7 @@ public void LookupObjectByUnknownReferenceNameReturnsNull()
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Lookup("refs/heads/chopped/off").ShouldBeNull();
repo.Lookup<GitObject>(notFoundSha).ShouldBeNull();
repo.Lookup<GitObject>(Constants.UnknownSha).ShouldBeNull();
}
}

Expand Down Expand Up @@ -238,9 +237,9 @@ public void CheckingForObjectExistenceWithBadParamsThrows()
[Test]
public void CheckForDetachedHeadOnNewRepo()
{
using (new SelfCleaningDirectory(newRepoPath))
using (var scd = new SelfCleaningDirectory())
{
var dir = Repository.Init(newRepoPath, true);
var dir = Repository.Init(scd.DirectoryPath, true);
Path.IsPathRooted(dir).ShouldBeTrue();
Directory.Exists(dir).ShouldBeTrue();

Expand Down
19 changes: 8 additions & 11 deletions LibGit2Sharp.Tests/TagFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ namespace LibGit2Sharp.Tests
[TestFixture]
public class TagFixture
{
private const string newRepoPath = "new_repo";

private readonly List<string> expectedTags = new List<string> {"test", "e90810b", "lw"};

private static readonly Signature signatureTim = new Signature("Tim Clem", "timothy.clem@gmail.com", DateTimeOffset.UtcNow);
private static readonly Signature signatureNtk = new Signature("nulltoken", "emeric.fermas@gmail.com", Epoch.ToDateTimeOffset(1300557894, 60));
private const string tagTestSha = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
private const string commitE90810BSha = "e90810b8df3e80c413d903f631643c716887138d";
private const string tagE90810BSha = "7b4384978d2493e851f9cca7858815fac9b10980";
const string invalidTargetId = "deadbeef1b46c854b31185ea97743be6a8774479";

[Test]
public void CanCreateALightWeightTagFromSha()
Expand Down Expand Up @@ -159,9 +156,9 @@ public void CreatingAnAnnotatedTagIsDeterministic()
[Description("Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L32)")]
public void CreatingATagInAEmptyRepositoryThrows()
{
using (new SelfCleaningDirectory(newRepoPath))
using (var scd = new SelfCleaningDirectory())
{
var dir = Repository.Init(newRepoPath);
var dir = Repository.Init(scd.DirectoryPath);

using (var repo = new Repository(dir))
{
Expand All @@ -174,9 +171,9 @@ public void CreatingATagInAEmptyRepositoryThrows()
[Description("Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L37)")]
public void CreatingATagForHeadInAEmptyRepositoryThrows()
{
using (new SelfCleaningDirectory(newRepoPath))
using (var scd = new SelfCleaningDirectory())
{
var dir = Repository.Init(newRepoPath);
var dir = Repository.Init(scd.DirectoryPath);

using (var repo = new Repository(dir))
{
Expand All @@ -203,7 +200,7 @@ public void CreatingATagForAnUnknowObjectIdShouldFail()
using (var path = new TemporaryCloneOfTestRepo())
using (var repo = new Repository(path.RepositoryPath))
{
Assert.Throws<ApplicationException>(() => repo.ApplyTag("mytagnorev", invalidTargetId));
Assert.Throws<ApplicationException>(() => repo.ApplyTag("mytagnorev", Constants.UnknownSha));
}
}

Expand Down Expand Up @@ -399,7 +396,7 @@ public void CreateTagWithNotExistingTargetThrows()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ApplicationException>(() => repo.Tags.Create("test_tag", invalidTargetId, signatureTim, "message"));
Assert.Throws<ApplicationException>(() => repo.Tags.Create("test_tag", Constants.UnknownSha, signatureTim, "message"));
}
}

Expand Down Expand Up @@ -520,9 +517,9 @@ public void CanListTags()
[Description("Ported from cgit (https://github.com/git/git/blob/1c08bf50cfcf924094eca56c2486a90e2bf1e6e2/t/t7004-tag.sh#L24)")]
public void CanListAllTagsInAEmptyRepository()
{
using (new SelfCleaningDirectory(newRepoPath))
using (var scd = new SelfCleaningDirectory())
{
var dir = Repository.Init(newRepoPath);
var dir = Repository.Init(scd.DirectoryPath);

using (var repo = new Repository(dir))
{
Expand Down
23 changes: 15 additions & 8 deletions LibGit2Sharp.Tests/TestHelpers/SelfCleaningDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace LibGit2Sharp.Tests.TestHelpers
{
public class SelfCleaningDirectory : IDisposable
{
private readonly string path;
public SelfCleaningDirectory() : this(BuildTempPath())
{
}

public SelfCleaningDirectory(string path)
{
Expand All @@ -14,26 +16,31 @@ public SelfCleaningDirectory(string path)
throw new InvalidOperationException("Directory '{0}' already exists.");
}

this.path = path;
DirectoryPath = path;
RootedDirectoryPath = Path.GetFullPath(path);
}

protected string DirectoryPath
{
get { return path; }
}

public string DirectoryPath { get; private set; }
public string RootedDirectoryPath { get; private set; }

#region IDisposable Members

public void Dispose()
{
if (!Directory.Exists(path))
if (!Directory.Exists(DirectoryPath))
{
throw new InvalidOperationException("Directory '{0}' doesn't exist any longer.");
}

DirectoryHelper.DeleteDirectory(path);
DirectoryHelper.DeleteDirectory(DirectoryPath);
}

#endregion

protected static string BuildTempPath()
{
return Path.Combine(Constants.TemporaryReposPath, Guid.NewGuid().ToString().Substring(0, 8));
}
}
}
13 changes: 3 additions & 10 deletions LibGit2Sharp.Tests/TestHelpers/TemporaryCloneOfTestRepo.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
using System;
using System.IO;
using System.IO;

namespace LibGit2Sharp.Tests.TestHelpers
{
public class TemporaryCloneOfTestRepo : SelfCleaningDirectory
{
public TemporaryCloneOfTestRepo(string path = Constants.TestRepoPath)
: base(BuildTempPath())
public TemporaryCloneOfTestRepo(string sourceDirectoryPath = Constants.TestRepoPath)
{
var source = new DirectoryInfo(path);
var source = new DirectoryInfo(sourceDirectoryPath);
var tempRepository = new DirectoryInfo(Path.Combine(DirectoryPath, source.Name));

RepositoryPath = tempRepository.FullName;
DirectoryHelper.CopyFilesRecursively(source, tempRepository);
}

public string RepositoryPath { get; private set; }

private static string BuildTempPath()
{
return Path.Combine(Constants.TemporaryReposPath, Guid.NewGuid().ToString().Substring(0, 8));
}
}
}
Loading