Skip to content
Draft
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
13 changes: 13 additions & 0 deletions src/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ private ProcessStartInfo CreateGitStartInfo()
start.Environment.Add("LANG", "C");
start.Environment.Add("LC_ALL", "C");
}
else if (OperatingSystem.IsWindows())
{
// Use WSL git for WSL paths on Windows
var wsl = new Models.WSL() { Path = WorkingDirectory };
if (wsl.IsWSLPath())
{
start.FileName = "wsl";
start.Arguments = $"git {start.Arguments}";

wsl.SetEnvironmentForProcess(start);
selfExecFile = start.Environment["SSH_ASKPASS"];
}
}

// Force using this app as git editor.
switch (Editor)
Expand Down
45 changes: 45 additions & 0 deletions src/Models/WSL.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Diagnostics;
using System.Text;

namespace SourceGit.Models
{
public class WSL
{
public string Path { get; set; } = "";

public bool IsWSLPath()
{
return OperatingSystem.IsWindows() && !string.IsNullOrEmpty(Path) &&
(Path.StartsWith("//wsl.localhost/", StringComparison.OrdinalIgnoreCase) ||
Path.StartsWith("//wsl$/", StringComparison.OrdinalIgnoreCase));
}

public void SetEnvironmentForProcess(ProcessStartInfo start)
{
start.Environment.Add("LANG", "C");
start.Environment.Add("LC_ALL", "C");

if (start.Environment.TryGetValue("SSH_ASKPASS", out var askPassPath) && !string.IsNullOrEmpty(askPassPath) && System.IO.Path.IsPathRooted(askPassPath))
{
// Convert Windows path to WSL path
var driveLetter = askPassPath[0].ToString();
start.Environment["SSH_ASKPASS"] = askPassPath
.Replace($"{driveLetter}:\\", $"/mnt/{driveLetter.ToLowerInvariant()}/")
.Replace('\\', '/');
}

var wslEnvirionment = new[] { "SSH_ASKPASS", "SSH_ASKPASS_REQUIRE", "SOURCEGIT_LAUNCH_AS_ASKPASS", "GIT_SSH_COMMAND", "LANG", "LC_ALL" };
var wslEnvBuilder = new StringBuilder();

foreach (string env in wslEnvirionment)
{
if (start.Environment.ContainsKey(env))
wslEnvBuilder.Append($"{env}:");
}

// Forward environment variables for WSL
start.Environment.Add("WSLENV", wslEnvBuilder.ToString().TrimEnd(':'));
}
}
}
10 changes: 9 additions & 1 deletion src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,15 @@ public void StartSearchCommits()

public void SetWatcherEnabled(bool enabled)
{
_watcher?.SetEnabled(enabled);
var wsl = new Models.WSL() { Path = FullPath };
if (wsl.IsWSLPath())
{
_watcher?.MarkBranchDirtyManually();
}
else
{
_watcher?.SetEnabled(enabled);
}
}

public void MarkBranchesDirtyManually()
Expand Down