libgit2 / libgit2/libgit2sharp

TreeDefinition item recursive remove not working

Open
#2,057 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
3.5k
Forks
925
PR merge metrics
No merged PRs in 30d

Description

Reproduction steps

Compile & run

using LibGit2Sharp;

Repository.Init(args[0]);
var repo = new Repository(args[0]);

TreeDefinition current = new();
current.Add("sample/stays/to/a/file", repo.ObjectDatabase.CreateBlob("stays".ToStream()), Mode.NonExecutableFile);
current.Add("sample/removed/to/a/file", repo.ObjectDatabase.CreateBlob("removed".ToStream()), Mode.NonExecutableFile);
current.Remove("sample/removed");

var tree = repo.ObjectDatabase.CreateTree(current);
var sig = new Signature("John Doe", "jd@example.com", DateTimeOffset.UtcNow);
var commit = repo.ObjectDatabase.CreateCommit(sig, sig, "Test", tree, new Commit[] { }, false);
var branch = repo.Branches.Add("main", commit, true);
repo.Refs.UpdateTarget(repo.Refs.Head, branch.Reference);
static class Ext
{
    public static Stream ToStream(this string data)
    {
        MemoryStream stream = new();
        StreamWriter writer = new(stream);
        writer.Write(data);
        writer.Flush();
        stream.Position = 0;
        return stream;
    }
}
Expected behavior

sample/removed path is not in repo

Actual behavior

sample/removed is there with the file

Version of LibGit2Sharp (release number or SHA1)

2.7.2

Operating system(s) tested; .NET runtime tested

linux (.net7) & windows (.net7)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TreeDefinition.Remove("sample/removed") call in the provided reproduction, then inspect how ObjectDatabase.CreateTree(current) processes recursive paths. Run the reproduction on LibGit2Sharp 2.7.2 and verify that the resulting tree does not contain sample/removed or its file.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.