libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.17k stars 886 forks source link

Commit indexer is not working for repository root #1516

Open rsabirov opened 6 years ago

rsabirov commented 6 years ago

I am creating Virtual File system for my application. As input I am getting file paths or directory paths. I found that app works perfectly for any paths except for root.

Technically speaking I cannot get TreeEntry for repo root directory.

            Commit commit = GetCommit(commitHash);

            // this works
            var file = commit["foo.txt"];
            var dir1 = commit["var/logs"];
            var dir2 = commit["var"];

            // this doesn't work
            ver rootDir = commit["/"]; // returns null
carlosmn commented 6 years ago

This is expected. There is no entry for / a couple of reasons. One being that the root tree isn't contained in anything. Another is that the paths are relative to the root tree, and / isn't an allowed path in a Git tree anyway.

You get to the commit's tree via Commit.Tree.

rsabirov commented 6 years ago

Thank you for explanation @carlosmn, but it's still little bit strange as it works in file systems.

ethomson commented 6 years ago

Don't you think that it would be a little bit strange if / did work but it was the only / prefixed path? That would defy my expectations.

You could make an argument that commit[""] should work, but I don't think commit["/"] is at all consistent.

rsabirov commented 6 years ago

Let me clarify, I am not expecting that it will be commit["/"]. It can be commit[""] or commit["."], it doesn't matter. The problem is that there is no way to get TreeEnty for root at all.

From my point of view there is no difference between root folder and any other folder.

ethomson commented 6 years ago

Thanks for the update. This seems rather reasonable.