TreeDefinition.Remove fails to remove unwrapped trees.
You are opening a bug report against the LibGit2Sharp project: we use GitHub Issues for tracking bug reports and feature requests. If you have a question about an API or usage, please ask on StackOverflow: http://stackoverflow.com/questions/tagged/libgit2sharp.
Otherwise, to report a bug, please fill out the reproduction steps (below) and delete these introductory paragraphs. Thanks!
Reproduction steps
var dir = Path.GetTempPath() + Path.GetRandomFileName();
Repository.Init(dir);
Repository r = new Repository(dir);
Blob empty = r.ObjectDatabase.CreateBlob(new MemoryStream());
var td = new TreeDefinition();
td.Add("a/b/c", empty, Mode.NonExecutableFile);
td.Remove("a");
bool presentInTreeDefinition = td["a"] != null;
Tree t = r.ObjectDatabase.CreateTree(td);
bool presentInTree = t["a"] != null;
Expected behavior
Both presentInTreeDefinition and presentInTree should be false.
Actual behavior
presentInTreeDefinition is false, but presentInTree is true.
Version of LibGit2Sharp (release number or SHA1)
0.26.2
Operating system(s) tested; .NET runtime tested
Windows 10, .NET Core 3.1
https://github.com/libgit2/libgit2sharp/blob/df3b22a754ef56da8d7e3c330ce2d783c2b7982e/LibGit2Sharp/TreeDefinition.cs#L96 The tree entry is removed here, but the private field unwrapped tree is not removed unless it already has no subentries. When the tree is built from the definition, the still-present unwrapped tree reintroduces what should have been removed.