Skip to content

Indexing a tree by path yields different result with trailing slash #2189

Description

@mburtka

When a slash is included when indexing into a tree to a subtree, the resulting TreeEntry has a path with a duplicated last path part.

using System.Text;
using LibGit2Sharp;

var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

using var repo = new Repository(Repository.Init(path, isBare: true));

var bytes = Encoding.UTF8.GetBytes("Hello, World!");

var blob = repo.ObjectDatabase.CreateBlob(new MemoryStream(bytes));

var td = new TreeDefinition();
td.Add("some/deeply/nested/file", blob, Mode.NonExecutableFile);

var tree = repo.ObjectDatabase.CreateTree(td);

var withSlash = tree["some/deeply/"].Path;
var withoutSlash = tree["some/deeply"].Path;

Console.WriteLine(withSlash);       // some/deeply/deeply
Console.WriteLine(withoutSlash);    // some/deeply

I was seeing this across Linux and Windows, on versions 0.31 and 0.32 and .NET 10 and Framework 4.8

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