Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions GitWorkTree/Helpers/GitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ private static async Task<bool> ExecuteAsync(GitCommandArgs gitCommandArgs, Acti
}
}



public static async Task<List<string>> GetWorkTreePathsAsync(string repositoryPath)
{
List<string> workTreePaths = new List<string>();
Expand All @@ -113,19 +111,23 @@ public static async Task<List<string>> GetWorkTreePathsAsync(string repositoryPa
Argument = "worktree list --porcelain",
}, (line) =>
{
if (line.StartsWith("worktree"))
if (line.StartsWith("worktree "))
{
string worktreePath = line.Split(' ').ElementAtOrDefault(1);
string mainRepoPath = Path.GetFullPath(repositoryPath);

if (!Path.GetFullPath(worktreePath).Equals(mainRepoPath, StringComparison.OrdinalIgnoreCase))
// everything after "worktree " is the path (can contain spaces)
string rawPath = line.Substring("worktree ".Length).Trim();
if (!string.IsNullOrEmpty(rawPath))
{
workTreePaths.Add(worktreePath);
string worktreePath = Path.GetFullPath(rawPath);
string mainRepoPath = Path.GetFullPath(repositoryPath);

if (!worktreePath.Equals(mainRepoPath, StringComparison.OrdinalIgnoreCase))
{
workTreePaths.Add(worktreePath);
}
}
}
});
if (isCompleted) return workTreePaths;
else return null;
return isCompleted ? workTreePaths : null;
}

public static async Task<List<string>> GetBranchesAsync(string repositoryPath)
Expand Down Expand Up @@ -153,7 +155,7 @@ public static async Task<bool> CreateWorkTreeAsync
string force = shouldForceCreate ? "-f " : "";
return await ExecuteAsync(new GitCommandArgs()
{
Argument = $"worktree add {force}{workTreePath} {branchName.ToGitCommandExecutableFormat()}",
Argument = $"worktree add {force}{SolutionHelper.NormalizePath(workTreePath)} {branchName.ToGitCommandExecutableFormat()}",
WorkingDirectory = repositoryPath
}, (line) =>
{
Expand All @@ -166,7 +168,7 @@ public static async Task<bool> RemoveWorkTreeAsync(string repositoryPath, string
string force = shouldForceCreate ? "-f " : "";
return await ExecuteAsync(new GitCommandArgs()
{
Argument = $"worktree remove {force}{workTreePath}",
Argument = $"worktree remove {force}{SolutionHelper.NormalizePath(workTreePath)}",
WorkingDirectory = repositoryPath
}, (line) =>
{
Expand All @@ -190,13 +192,13 @@ public static async Task<string> GetGitFolderDirectoryAsync(string currentSoluti
{
string commandoutput = "";
var isCompleted = await ExecuteAsync(new GitCommandArgs() { WorkingDirectory = currentSolutionPath, Argument = "rev-parse --git-dir", },
(line) =>
(line) =>
{
if (!string.IsNullOrWhiteSpace(line))
{
if (!string.IsNullOrWhiteSpace(line))
{
commandoutput = line.Trim();
}
});
commandoutput = line.Trim();
}
});

if (isCompleted) return commandoutput;
return null;
Expand Down
7 changes: 6 additions & 1 deletion GitWorkTree/Helpers/SolutionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace GitWorkTree.Helpers
{
public static class SolutionHelper
{
static LoggingHelper outputWindow = LoggingHelper.Instance;
public static string NormalizePath(string path) =>
string.IsNullOrWhiteSpace(path) ? "\"\"" :
((path = path.Trim().Trim('"').TrimEnd('\r', '\n'))
.Any(char.IsWhiteSpace) ? $"\"{path}\"" : path);
public static string GetRepositoryPath(string solutionPath)
{
try
Expand Down Expand Up @@ -76,7 +81,7 @@ private static async Task<bool> HandleOpenSolution(string newSolutionPath, bool
private static bool OpenSolutionInNewInstance(string newSolutionPath, string[] solutionFiles)
{
outputWindow?.WriteToOutputWindowAsync($"Opening {newSolutionPath} in new VS instance", true);
System.Diagnostics.Process.Start("devenv.exe", solutionFiles[0]);
System.Diagnostics.Process.Start("devenv.exe", NormalizePath(solutionFiles[0]));
return true;
}

Expand Down