libgit2 / libgit2/libgit2sharp

gitdir

Đang mở
#2,157 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
C#
Star
3.5k
Fork
925
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với Worktree API và so sánh nó với Repository.Info.WorkingDirectory. Theo dõi cách .git/worktrees//gitdir xác định đường dẫn checkout, sau đó xác minh rằng thuộc tính mới trả về đúng thư mục worktree thực tế, chẳng hạn như C:\repo-core. Hoàn tất khi các bên sử dụng không còn cần tự đọc và phân giải tệp gitdir.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp, git
Lĩnh vực
backend-api-design, devtools
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.