用libgit2.sharp构建跟踪文件的目录树
不知道我在这里是否在正确的轨道上。
我一直在尝试通过递归构建字典info对象来构建在Winforms中的文件夹结构树,并通过一些黑客忽略了我忽略的文件和文件夹。
但是我发现有一个git命令基本上为我完成了这一切。 git ls -tree -r -t -name -hame -head
我可以用libgit2实现这一点吗?
谢谢!
编辑(添加解决方法),
所以现在我正在这样做
var info = new ProcessStartInfo("git", "ls-tree -r -t --name-only head")
{
CreateNoWindow = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = "<repo workdir>",
};
var list = new List<TreeNode>();
using (var sr = Process.Start(info)?.StandardOutput)
{
string? line;
while ((line = sr?.ReadLine()) != null)
{
if (line != null)
list.Add(new TreeNode(line));
}
}
treeView.Nodes.Clear();
var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Nodes.AddRange(list.ToArray());
not sure if I am on the right track here.
I have been trying to build a folder structure tree in Winforms by recursively building a DictionaryInfo object and with some hacking ignoring files and folders I ignored and not tracked by git.
But I found that there is a git command that basically does all this for me. git ls-tree -r -t --name-only head
Can I achieve this with libgit2?
Thanks!
Edit (Add workaround)
So right now I am doing this
var info = new ProcessStartInfo("git", "ls-tree -r -t --name-only head")
{
CreateNoWindow = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = "<repo workdir>",
};
var list = new List<TreeNode>();
using (var sr = Process.Start(info)?.StandardOutput)
{
string? line;
while ((line = sr?.ReadLine()) != null)
{
if (line != null)
list.Add(new TreeNode(line));
}
}
treeView.Nodes.Clear();
var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Nodes.AddRange(list.ToArray());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Libgit2Sharp Wiki页面上有一个示例,它提供了一个起点,可以通过索引中的所有条目进行迭代: https://github.com/libgit2/libgit2sharp/wiki/wiki/git-ls-files-files#libgit2sharp
对于您的情况条目。
There is an example on the LibGit2Sharp wiki page that provides a starting point to iterate through all entries in the index: https://github.com/libgit2/libgit2sharp/wiki/git-ls-files#libgit2sharp
For your case, I think you will want to remove the block checking the stage level of the entry.