libgit2sharp icon indicating copy to clipboard operation
libgit2sharp copied to clipboard

TreeDefinition item recursive remove not working

Open SS1823 opened this issue 2 years ago • 2 comments

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", "[email protected]", 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)

SS1823 avatar Aug 30 '23 11:08 SS1823

I noticed the code does not remove entries from unwrappedTrees dictionary, just from entries maybe that's the issue here

SS1823 avatar Aug 30 '23 11:08 SS1823

Duplicate of #1869

tyrielv avatar Jan 04 '24 20:01 tyrielv