@@ -102,8 +102,6 @@ private static async Task<bool> ExecuteAsync(GitCommandArgs gitCommandArgs, Acti
102102 }
103103 }
104104
105-
106-
107105 public static async Task < List < string > > GetWorkTreePathsAsync ( string repositoryPath )
108106 {
109107 List < string > workTreePaths = new List < string > ( ) ;
@@ -113,19 +111,23 @@ public static async Task<List<string>> GetWorkTreePathsAsync(string repositoryPa
113111 Argument = "worktree list --porcelain" ,
114112 } , ( line ) =>
115113 {
116- if ( line . StartsWith ( "worktree" ) )
114+ if ( line . StartsWith ( "worktree " ) )
117115 {
118- string worktreePath = line . Split ( ' ' ) . ElementAtOrDefault ( 1 ) ;
119- string mainRepoPath = Path . GetFullPath ( repositoryPath ) ;
120-
121- if ( ! Path . GetFullPath ( worktreePath ) . Equals ( mainRepoPath , StringComparison . OrdinalIgnoreCase ) )
116+ // everything after "worktree " is the path (can contain spaces)
117+ string rawPath = line . Substring ( "worktree " . Length ) . Trim ( ) ;
118+ if ( ! string . IsNullOrEmpty ( rawPath ) )
122119 {
123- workTreePaths . Add ( worktreePath ) ;
120+ string worktreePath = Path . GetFullPath ( rawPath ) ;
121+ string mainRepoPath = Path . GetFullPath ( repositoryPath ) ;
122+
123+ if ( ! worktreePath . Equals ( mainRepoPath , StringComparison . OrdinalIgnoreCase ) )
124+ {
125+ workTreePaths . Add ( worktreePath ) ;
126+ }
124127 }
125128 }
126129 } ) ;
127- if ( isCompleted ) return workTreePaths ;
128- else return null ;
130+ return isCompleted ? workTreePaths : null ;
129131 }
130132
131133 public static async Task < List < string > > GetBranchesAsync ( string repositoryPath )
@@ -153,7 +155,7 @@ public static async Task<bool> CreateWorkTreeAsync
153155 string force = shouldForceCreate ? "-f " : "" ;
154156 return await ExecuteAsync ( new GitCommandArgs ( )
155157 {
156- Argument = $ "worktree add { force } { workTreePath } { branchName . ToGitCommandExecutableFormat ( ) } ",
158+ Argument = $ "worktree add { force } { SolutionHelper . NormalizePath ( workTreePath ) } { branchName . ToGitCommandExecutableFormat ( ) } ",
157159 WorkingDirectory = repositoryPath
158160 } , ( line ) =>
159161 {
@@ -166,7 +168,7 @@ public static async Task<bool> RemoveWorkTreeAsync(string repositoryPath, string
166168 string force = shouldForceCreate ? "-f " : "" ;
167169 return await ExecuteAsync ( new GitCommandArgs ( )
168170 {
169- Argument = $ "worktree remove { force } { workTreePath } ",
171+ Argument = $ "worktree remove { force } { SolutionHelper . NormalizePath ( workTreePath ) } ",
170172 WorkingDirectory = repositoryPath
171173 } , ( line ) =>
172174 {
@@ -190,13 +192,13 @@ public static async Task<string> GetGitFolderDirectoryAsync(string currentSoluti
190192 {
191193 string commandoutput = "" ;
192194 var isCompleted = await ExecuteAsync ( new GitCommandArgs ( ) { WorkingDirectory = currentSolutionPath , Argument = "rev-parse --git-dir" , } ,
193- ( line ) =>
195+ ( line ) =>
196+ {
197+ if ( ! string . IsNullOrWhiteSpace ( line ) )
194198 {
195- if ( ! string . IsNullOrWhiteSpace ( line ) )
196- {
197- commandoutput = line . Trim ( ) ;
198- }
199- } ) ;
199+ commandoutput = line . Trim ( ) ;
200+ }
201+ } ) ;
200202
201203 if ( isCompleted ) return commandoutput ;
202204 return null ;
0 commit comments