libgit2/libgit2sharp — Issue #105: `Branch.IsCurrentRepositoryHead` Throws `NullReferenceException` For Head in New Repo
Author: Haacked
Created: 2012-02-01 06:16:01+00:00
State: open

Ok, this is admittedly an edge case, but I thought I'd bring it up.

If you create a brand new repository, this property:

repo.Head.IsCurrentRepositoryHead

throws a `NullReferenceException` when you evaluate it.

To demonstrate the issue, I updated the test `CanCreateBareRepo` test, [line 15 of RepositoryFixture](https://github.com/libgit2/libgit2sharp/blob/master/LibGit2Sharp.Tests/RepositoryFixture.cs#L15), with two additional asserts.

repo.Head.CanonicalName.ShouldEqual("refs/heads/master");
repo.Head.IsCurrentRepositoryHead.ShouldBeTrue();

That second line throws a `NullReferenceException` when added to the existing unit test.

My guess is that:

repo.Head.IsCurrentRepositoryHead.ShouldBeTrue();

Should probably return true.

Though you could also argue that this is an invalid operation because there are no commits yet so `refs/heads/master` doesn't yet exist. But in that case, I still think an `InvalidOperationException` would be better than `NulReferenceException`. :smiley: