Repro steps:
Create a new git repository:
mkdir folder
cd folder
git init
Create a repository instance and try to list commits.
var repo = new Repository(@"C:\dev\folder\.git");
foreach (var c in repo.Commits) {
Console.WriteLine(c.Id);
}
Expected:
Empty commit collection
Actual:
Null reference exception
I actually dug a little deeper into why it throws. It seems that this line throws (CommitCollection.StartingAt):
return new CommitCollection(repo) { sortOptions = sortOptions, pushedSha = reference.ResolveToDirectReference().Target.Sha };
ResolveToDirectReference() returns null since the reference is the head which doesn't point to any commits by default.
Repro steps:
Create a new git repository:
Create a repository instance and try to list commits.
Expected:
Empty commit collection
Actual:
Null reference exception
I actually dug a little deeper into why it throws. It seems that this line throws (CommitCollection.StartingAt):
ResolveToDirectReference() returns null since the reference is the head which doesn't point to any commits by default.