libgit2 / libgit2/libgit2sharp

gitdir

オープン
#2,157 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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:

  1. Read the content of .git/worktrees/<name>/gitdir
  2. 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Worktree API から始め、Repository.Info.WorkingDirectory と比較します。.git/worktrees//gitdir が checkout パスをどのように識別するかを追跡し、新しいプロパティが C:\repo-core のような実際の worktree ディレクトリを返すことを確認します。完了の条件は、利用者が gitdir ファイルを自分で読み取って解決する必要がなくなることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
csharp, git
領域
backend-api-design, devtools
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
42/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。