Skip to content

Cannot add empty commit to empty repository #1692

@antoinebj

Description

@antoinebj

I need to unit test an algorithm that only works with the commit graph and metadata, and doesn't care about the contents of the commits.
Therefore to avoid unnecessary distraction, I was trying create a graph of empty commits, starting from an empty in-memory repository.
This issue is not critical because I can just make my initial commit have a dummy blob, but I'm creating this issue anyway because it could be useful to track any divergence between what the official git command and this library can do.

Reproduction steps

var repository = new Repository();
var treeDefinition = new TreeDefinition();
var tree = repository.ObjectDatabase.CreateTree(treeDefinition);

Expected behavior

Create a tree for an empty commit, as is done with the following git command:

git init
git commit --allow-empty --allow-empty-message -m ""

Actual behavior

Getting exception:

LibGit2Sharp.LibGit2SharpException: 'path cannot exist in repository'
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Ensure.cs:line 136
   at LibGit2Sharp.Core.Proxy.git_repository_odb(RepositoryHandle repo) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 2530
   at LibGit2Sharp.ObjectDatabase..ctor(Repository repo) in C:\projects\libgit2sharp\LibGit2Sharp\ObjectDatabase.cs:line 30
   at LibGit2Sharp.Repository.<>c__DisplayClass25_0.<.ctor>b__4() in C:\projects\libgit2sharp\LibGit2Sharp\Repository.cs:line 225
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()

Version of LibGit2Sharp (release number or SHA1)

0.26

Operating system(s) tested; .NET runtime tested

.NET Core 2.2 on Windows 10 1903

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions