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
36 changes: 35 additions & 1 deletion LibGit2Sharp.Tests/ReferenceFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void CanCreateADirectReference()
newRef.CanonicalName.ShouldEqual(name);
newRef.Target.ShouldNotBeNull();
newRef.Target.Sha.ShouldEqual("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
newRef.TargetIdentifier.ShouldEqual(newRef.Target.Sha);
repo.Refs[name].ShouldNotBeNull();
}
}
Expand All @@ -41,6 +42,7 @@ public void CanCreateASymbolicReference()
newRef.ShouldNotBeNull();
newRef.CanonicalName.ShouldEqual(name);
newRef.Target.CanonicalName.ShouldEqual(target);
newRef.TargetIdentifier.ShouldEqual(newRef.Target.CanonicalName);
newRef.ResolveToDirectReference().Target.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345");
repo.Refs[name].ShouldNotBeNull();
}
Expand Down Expand Up @@ -372,7 +374,39 @@ public void UpdatingAReferenceTargetWithBadParametersFails()
}

[Test]
public void CanMoveAReference()
[Ignore("Currently fails because of feature which is not yet implemented in libgit2")]
public void CanMoveAReferenceToADeeperReferenceHierarchy()
{
using (var path = new TemporaryCloneOfTestRepo())
using (var repo = new Repository(path.RepositoryPath))
{
const string newName = "refs/tags/test/deep";

Reference moved = repo.Refs.Move("refs/tags/test", newName);
moved.ShouldNotBeNull();
moved.CanonicalName.ShouldEqual(newName);
}
}

[Test]
[Ignore("Currently fails because of feature which is not yet implemented in libgit2")]
public void CanMoveAReferenceToAUpperReferenceHierarchy()
{
using (var path = new TemporaryCloneOfTestRepo())
using (var repo = new Repository(path.RepositoryPath))
{
const string newName = "refs/heads/o/sole";
const string oldName = newName + "/mio";

repo.Refs.Create(oldName, repo.Head.ResolveToDirectReference().TargetIdentifier);
Reference moved = repo.Refs.Move(oldName, newName);
moved.ShouldNotBeNull();
moved.CanonicalName.ShouldEqual(newName);
}
}

[Test]
public void CanMoveAReferenceToADifferentReferenceHierarchy()
{
using (var path = new TemporaryCloneOfTestRepo())
using (var repo = new Repository(path.RepositoryPath))
Expand Down
165 changes: 79 additions & 86 deletions LibGit2Sharp.Tests/RepositoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,6 @@ public class RepositoryFixture
private const string commitSha = "8496071c1b46c854b31185ea97743be6a8774479";
private const string notFoundSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";

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

[Test]
public void CallingExistsWithNullThrows()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ArgumentNullException>(() => repo.HasObject(null));
}
}

[Test]
public void CanCreateBareRepo()
{
Expand All @@ -42,10 +24,10 @@ public void CanCreateBareRepo()

using (var repo = new Repository(dir))
{
repo.Info.Path.ShouldNotBeNull();
repo.Info.WorkingDirectory.ShouldBeNull();
repo.Info.IsBare.ShouldBeTrue();
repo.Info.IsEmpty.ShouldBeTrue();

AssertInitializedRepository(repo);
}
}
}
Expand All @@ -61,14 +43,30 @@ public void CanCreateStandardRepo()

using (var repo = new Repository(dir))
{
repo.Info.Path.ShouldNotBeNull();
repo.Info.WorkingDirectory.ShouldNotBeNull();
repo.Info.IsBare.ShouldBeFalse();
repo.Info.IsEmpty.ShouldBeTrue();

AssertInitializedRepository(repo);
}
}
}

private static void AssertInitializedRepository(Repository repo)
{
repo.Info.Path.ShouldNotBeNull();
repo.Info.IsEmpty.ShouldBeTrue();
repo.Info.IsHeadDetached.ShouldBeFalse();
repo.Head.TargetIdentifier.ShouldEqual("refs/heads/master");
repo.Head.ResolveToDirectReference().ShouldBeNull();
}

[Test]
public void CreatingRepoWithBadParamsThrows()
{
Assert.Throws<ArgumentException>(() => Repository.Init(string.Empty));
Assert.Throws<ArgumentNullException>(() => Repository.Init(null));
}

[Test]
public void CanLookupACommitByTheNameOfABranch()
{
Expand Down Expand Up @@ -135,128 +133,123 @@ public void CanOpenRepoWithFullPath()
}

[Test]
[Platform(Exclude = "Linux,Unix", Reason = "No need to test windows path separators on non-windows platforms")]
// See http://www.nunit.org/index.php?p=platform&r=2.6 for other platforms that can be excluded/included.
public void CanOpenRepoWithWindowsPathSeparators()
public void LookupObjectByWrongShaReturnsNull()
{
using (new Repository(@".\Resources\testrepo.git"))
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Lookup(notFoundSha).ShouldBeNull();
repo.Lookup<GitObject>(notFoundSha).ShouldBeNull();
}
}

[Test]
public void CanOpenRepository()
public void LookupObjectByWrongTypeReturnsNull()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Info.Path.ShouldNotBeNull();
repo.Info.WorkingDirectory.ShouldBeNull();
repo.Info.IsBare.ShouldBeTrue();
repo.Info.IsEmpty.ShouldBeFalse();
repo.Info.IsHeadDetached.ShouldBeFalse();
repo.Lookup(commitSha).ShouldNotBeNull();
repo.Lookup<Commit>(commitSha).ShouldNotBeNull();
repo.Lookup<TagAnnotation>(commitSha).ShouldBeNull();
}
}

[Test]
public void CanTellIfObjectsExistInRepository()
public void LookupObjectByUnknownReferenceNameReturnsNull()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.HasObject("8496071c1b46c854b31185ea97743be6a8774479").ShouldBeTrue();
repo.HasObject("1385f264afb75a56a5bec74243be9b367ba4ca08").ShouldBeTrue();
repo.HasObject("ce08fe4884650f067bd5703b6a59a8b3b3c99a09").ShouldBeFalse();
repo.HasObject("8496071c1c46c854b31185ea97743be6a8774479").ShouldBeFalse();
repo.Lookup("refs/heads/chopped/off").ShouldBeNull();
repo.Lookup<GitObject>(notFoundSha).ShouldBeNull();
}
}

[Test]
public void CheckForDetachedHeadOnNewRepo()
public void LookingUpWithBadParamsThrows()
{
using (new SelfCleaningDirectory(newRepoPath))
using (var repo = new Repository(Constants.TestRepoPath))
{
var dir = Repository.Init(newRepoPath, true);
Path.IsPathRooted(dir).ShouldBeTrue();
Directory.Exists(dir).ShouldBeTrue();

using (var repo = new Repository(dir))
{
repo.Info.IsEmpty.ShouldBeTrue();
repo.Info.IsHeadDetached.ShouldBeFalse();
}
Assert.Throws<ArgumentException>(() => repo.Lookup(string.Empty));
Assert.Throws<ArgumentException>(() => repo.Lookup<GitObject>(string.Empty));
Assert.Throws<ArgumentNullException>(() => repo.Lookup((string)null));
Assert.Throws<ArgumentNullException>(() => repo.Lookup((ObjectId)null));
Assert.Throws<ArgumentNullException>(() => repo.Lookup<Commit>((string)null));
Assert.Throws<ArgumentNullException>(() => repo.Lookup<Commit>((ObjectId)null));
}
}

[Test]
public void CreateRepoWithEmptyStringThrows()
{
Assert.Throws<ArgumentException>(() => Repository.Init(string.Empty));
}

[Test]
public void CreateRepoWithNullThrows()
[Platform(Exclude = "Linux,Unix", Reason = "No need to test windows path separators on non-windows platforms")]
// See http://www.nunit.org/index.php?p=platform&r=2.6 for other platforms that can be excluded/included.
public void CanOpenRepoWithWindowsPathSeparators()
{
Assert.Throws<ArgumentNullException>(() => Repository.Init(null));
using (new Repository(@".\Resources\testrepo.git"))
{
}
}

[Test]
public void LookupObjectByWrongShaReturnsNull()
public void CanOpenRepository()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Lookup(notFoundSha).ShouldBeNull();
repo.Lookup<GitObject>(notFoundSha).ShouldBeNull();
repo.Info.Path.ShouldNotBeNull();
repo.Info.WorkingDirectory.ShouldBeNull();
repo.Info.IsBare.ShouldBeTrue();
repo.Info.IsEmpty.ShouldBeFalse();
repo.Info.IsHeadDetached.ShouldBeFalse();
}
}

[Test]
public void LookupObjectByWrongTypeReturnsNull()
public void OpenNonExistentRepoThrows()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
repo.Lookup(commitSha).ShouldNotBeNull();
repo.Lookup<Commit>(commitSha).ShouldNotBeNull();
repo.Lookup<TagAnnotation>(commitSha).ShouldBeNull();
}
Assert.Throws<ApplicationException>(() => { new Repository("a_bad_path"); });
}

[Test]
public void LookupWithEmptyStringThrows()
public void OpeningRepositoryWithBadParamsThrows()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ArgumentException>(() => repo.Lookup(string.Empty));
Assert.Throws<ArgumentException>(() => repo.Lookup<GitObject>(string.Empty));
}
Assert.Throws<ArgumentException>(() => new Repository(string.Empty));
Assert.Throws<ArgumentNullException>(() => new Repository(null));
}

[Test]
public void LookupWithNullThrows()
public void CanTellIfObjectsExistInRepository()
{
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ArgumentNullException>(() => repo.Lookup((string) null));
Assert.Throws<ArgumentNullException>(() => repo.Lookup(null));
Assert.Throws<ArgumentNullException>(() => repo.Lookup<Commit>((string) null));
Assert.Throws<ArgumentNullException>(() => repo.Lookup<Commit>((ObjectId) null));
repo.HasObject("8496071c1b46c854b31185ea97743be6a8774479").ShouldBeTrue();
repo.HasObject("1385f264afb75a56a5bec74243be9b367ba4ca08").ShouldBeTrue();
repo.HasObject("ce08fe4884650f067bd5703b6a59a8b3b3c99a09").ShouldBeFalse();
repo.HasObject("8496071c1c46c854b31185ea97743be6a8774479").ShouldBeFalse();
}
}

[Test]
public void OpenNonExistentRepoThrows()
public void CheckingForObjectExistenceWithBadParamsThrows()
{
Assert.Throws<ApplicationException>(() => { new Repository("a_bad_path"); });
using (var repo = new Repository(Constants.TestRepoPath))
{
Assert.Throws<ArgumentException>(() => repo.HasObject(string.Empty));
Assert.Throws<ArgumentNullException>(() => repo.HasObject(null));
}
}

[Test]
public void OpeningRepositoryWithEmptyPathThrows()
public void CheckForDetachedHeadOnNewRepo()
{
Assert.Throws<ArgumentException>(() => new Repository(string.Empty));
}
using (new SelfCleaningDirectory(newRepoPath))
{
var dir = Repository.Init(newRepoPath, true);
Path.IsPathRooted(dir).ShouldBeTrue();
Directory.Exists(dir).ShouldBeTrue();

[Test]
public void OpeningRepositoryWithNullPathThrows()
{
Assert.Throws<ArgumentNullException>(() => new Repository(null));
using (var repo = new Repository(dir))
{
repo.Info.IsEmpty.ShouldBeTrue();
repo.Info.IsHeadDetached.ShouldBeFalse();
}
}
}
}
}
Loading