Skip to content

Commit

Permalink
Merge pull request #1870 from tyrielv/tree-definition-delete
Browse files Browse the repository at this point in the history
Test and fix for #1869
  • Loading branch information
bording authored Nov 26, 2024
2 parents af85e63 + 2dd7eca commit 3318b73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions LibGit2Sharp.Tests/TreeDefinitionFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,5 +587,23 @@ public void CanAddAnExistingBlobEntryWithAnExistingTree()
Assert.NotNull(td["1/branch_file.txt"]);
}
}

[Fact]
public void CanRemoveADirectoryWithChildren()
{
const string blobSha = "a8233120f6ad708f843d861ce2b7228ec4e3dec6";
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
TreeDefinition td = new TreeDefinition();
var blob = repo.Lookup<Blob>(blobSha);
td.Add("folder/subfolder/file1", blob, Mode.NonExecutableFile);
td.Add("folder/file1", blob, Mode.NonExecutableFile);
td.Remove("folder");
Assert.Null(td["folder"]);
Tree t = repo.ObjectDatabase.CreateTree(td);
Assert.Null(t["folder"]);
}
}
}
}
1 change: 1 addition & 0 deletions LibGit2Sharp/TreeDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public virtual TreeDefinition Remove(string treeEntryPath)
if (segments.Item2 == null)
{
entries.Remove(segments.Item1);
unwrappedTrees.Remove(segments.Item1);
}

if (!unwrappedTrees.ContainsKey(segments.Item1))
Expand Down

0 comments on commit 3318b73

Please sign in to comment.