Permalink
Browse files

Prevent Repository.Head.IsCurrentRepositoryHead from throwing a NullR…

…eferenceException when the Repository is empty

Fix issue #105
  • Loading branch information...
nulltoken committed Feb 1, 2012
1 parent b765016 commit 839c659c35d8fe42407ef3a749a251eb4daff254
@@ -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();
}
}
@@ -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
@@ -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>
@@ -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;

0 comments on commit 839c659

Please sign in to comment.