diff --git a/TGit/Helpers/FileHelper.cs b/TGit/Helpers/FileHelper.cs index 1d1ff60..a7a9b14 100644 --- a/TGit/Helpers/FileHelper.cs +++ b/TGit/Helpers/FileHelper.cs @@ -76,38 +76,19 @@ public static async Task HasSolutionDir() /// Start at the solution dir and traverse up to find a .git folder or file /// /// Path to start traversing from. - /// Path to the .git folder or file. + /// Path to the folder of the git repo or worktree. private static async Task FindGitdir(string path) { try { - var di = new DirectoryInfo(path); - if (di.GetDirectories().Any(d => d.Name.Equals(".git"))) + var gitPath = Path.Combine(path, ".git"); + // A git repo has a .git directory, while a worktree only has a file + if (Directory.Exists(gitPath) || File.Exists(gitPath)) { - return di.FullName; - } - - var gitFilePath = Path.Combine(path, ".git"); - if (File.Exists(gitFilePath)) - { - var text = File.ReadAllText(gitFilePath); - var match = Regex.Match(text, "gitdir:(.*)"); - if (match.Success) - { - var gitDirPath = match.Groups[1].Value.Trim(); - - if (Directory.Exists(gitDirPath)) - { - return gitDirPath; - } - - if (File.Exists(gitDirPath)) - { - return File.ReadAllText(gitDirPath); - } - } + return path; } + var di = new DirectoryInfo(path); if (di.Parent != null) { return await FindGitdir(di.Parent.FullName);