libgit2 / libgit2/libgit2sharp
gitdir
还没有人认领这个 Issue。
- 主要语言
- C#
- 星标
- 3.5k
- 派生
- 925
- PR 合并指标
- 30 天内没有已合并 PR
描述
Problem Description
The Worktree API in LibGit2Sharp does not expose any property to retrieve the actual working directory path associated with a worktree (i.e., the folder where the code is checked out).
Currently, the Worktree object only provides:
Name→ the name of the worktree (e.g., "core")GitDirectory→ the path.git/worktrees/<name>, which does not correspond to the working directory
Due to this limitation, consumers must manually:
- Read the content of
.git/worktrees/<name>/gitdir - Use
Directory.GetParent()to resolve the real worktree folder path
This approach is both fragile and undocumented.
Expected Behavior
Expose a property like Worktree.WorkingDirectory (similar to Repository.Info.WorkingDirectory) that returns the actual working directory path of the worktree (e.g., C:\repo-core).
Example Workaround
var worktreePaths = new List<string>();
var gitDir = Path.Combine(repoPath, ".git", "worktrees");
foreach (var folder in Directory.GetDirectories(gitDir))
{
var gitdirFile = Path.Combine(folder, "gitdir");
if (File.Exists(gitdirFile))
{
var gitdirPath = File.ReadAllText(gitdirFile).Trim();
var worktreePath = Directory.GetParent(gitdirPath)?.FullName;
if (!string.IsNullOrEmpty(worktreePath))
worktreePaths.Add(worktreePath);
}
}
This code reads the .git/worktrees/<name>/gitdir file and manually resolves the worktree’s root folder. A native API would make this more reliable and developer-friendly.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Worktree API 开始,并将其与 Repository.Info.WorkingDirectory 进行比较。跟踪 .git/worktrees//gitdir 如何标识 checkout 路径,然后验证新属性返回的确实是 worktree 目录,例如 C:\repo-core。完成的标准是消费者不再需要自行读取并解析 gitdir 文件。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- csharp, git
- 领域
- backend-api-design, devtools
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 42/100