libgit2 / libgit2/libgit2sharp
Indexing a tree by path yields different result with trailing slash
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.5k
- Forks
- 925
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the discrepancy using the provided TreeDefinition and tree indexer example, comparing the paths returned for "some/deeply/" and "some/deeply". Trace the TreeEntry path construction for indexed subtrees and add a regression test covering both inputs. Done means trailing-slash indexing returns the same non-duplicated path as the equivalent path without the slash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, git
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100