Skip to content

Listing commits for an empty repository throws a null reference exception #30

Description

@davidfowl

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions