File tree 1 file changed +6
-25
lines changed
1 file changed +6
-25
lines changed Original file line number Diff line number Diff line change @@ -76,38 +76,19 @@ public static async Task<bool> HasSolutionDir()
76
76
/// Start at the solution dir and traverse up to find a .git folder or file
77
77
/// </summary>
78
78
/// <param name="path">Path to start traversing from.</param>
79
- /// <returns>Path to the . git folder or file .</returns>
79
+ /// <returns>Path to the folder of the git repo or worktree .</returns>
80
80
private static async Task < string > FindGitdir ( string path )
81
81
{
82
82
try
83
83
{
84
- var di = new DirectoryInfo ( path ) ;
85
- if ( di . GetDirectories ( ) . Any ( d => d . Name . Equals ( ".git" ) ) )
84
+ var gitPath = Path . Combine ( path , ".git" ) ;
85
+ // A git repo has a .git directory, while a worktree only has a file
86
+ if ( Directory . Exists ( gitPath ) || File . Exists ( gitPath ) )
86
87
{
87
- return di . FullName ;
88
- }
89
-
90
- var gitFilePath = Path . Combine ( path , ".git" ) ;
91
- if ( File . Exists ( gitFilePath ) )
92
- {
93
- var text = File . ReadAllText ( gitFilePath ) ;
94
- var match = Regex . Match ( text , "gitdir:(.*)" ) ;
95
- if ( match . Success )
96
- {
97
- var gitDirPath = match . Groups [ 1 ] . Value . Trim ( ) ;
98
-
99
- if ( Directory . Exists ( gitDirPath ) )
100
- {
101
- return gitDirPath ;
102
- }
103
-
104
- if ( File . Exists ( gitDirPath ) )
105
- {
106
- return File . ReadAllText ( gitDirPath ) ;
107
- }
108
- }
88
+ return path ;
109
89
}
110
90
91
+ var di = new DirectoryInfo ( path ) ;
111
92
if ( di . Parent != null )
112
93
{
113
94
return await FindGitdir ( di . Parent . FullName ) ;
You can’t perform that action at this time.
0 commit comments