Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prevent Repository.Head.IsCurrentRepositoryHead from throwing a NullR…

…eferenceException when the Repository is empty

Fix issue #105
  • Loading branch information...
commit 839c659c35d8fe42407ef3a749a251eb4daff254 1 parent b765016
@nulltoken nulltoken authored
View
3  LibGit2Sharp.Tests/BranchFixture.cs
@@ -316,10 +316,11 @@ public void CanCheckoutAnArbitraryCommit(string commitPointer)
detachedHead.CanonicalName.ShouldEqual("(no branch)");
detachedHead.Tip.Sha.ShouldEqual(repo.Lookup(commitPointer).Sha);
- detachedHead.IsCurrentRepositoryHead.ShouldBeTrue();
detachedHead.ShouldEqual(repo.Head);
master.IsCurrentRepositoryHead.ShouldBeFalse();
+ detachedHead.IsCurrentRepositoryHead.ShouldBeTrue();
+ repo.Head.IsCurrentRepositoryHead.ShouldBeTrue();
}
}
View
1  LibGit2Sharp.Tests/RepositoryFixture.cs
@@ -99,6 +99,7 @@ private static void AssertInitializedRepository(Repository repo)
headRef.ResolveToDirectReference().ShouldBeNull();
repo.Head.ShouldNotBeNull();
+ repo.Head.IsCurrentRepositoryHead.ShouldBeTrue();
repo.Head.CanonicalName.ShouldEqual(headRef.TargetIdentifier);
repo.Head.Tip.ShouldBeNull();
View
6 LibGit2Sharp/Branch.cs
@@ -111,11 +111,11 @@ public int BehindBy
/// Gets a value indicating whether this instance is current branch (HEAD) in the repository.
/// </summary>
/// <value>
- /// <c>true</c> if this instance is current branch; otherwise, <c>false</c>.
+ /// <c>true</c> if this instance is the current branch; otherwise, <c>false</c>.
/// </value>
- public virtual bool IsCurrentRepositoryHead
+ public bool IsCurrentRepositoryHead
{
- get { return repo.Refs[CanonicalName].ResolveToDirectReference() == repo.Refs["HEAD"].ResolveToDirectReference(); }
+ get { return repo.Head == this; }
}
/// <summary>
View
14 LibGit2Sharp/DetachedHead.cs
@@ -7,20 +7,6 @@ internal DetachedHead(Repository repo, Reference reference)
{
}
- /// <summary>
- /// Gets a value indicating whether this instance is current branch (HEAD) in the repository.
- /// </summary>
- /// <value>
- /// <c>true</c> if this instance is current branch; otherwise, <c>false</c>.
- /// </value>
- public override bool IsCurrentRepositoryHead
- {
- get
- {
- return repo.Head == this;
- }
- }
-
protected override string Shorten(string branchName)
{
return branchName;
Please sign in to comment.
Something went wrong with that request. Please try again.