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