mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-21 02:15:00 +00:00
Merge 98f18aa2a8
into c5ad4b837d
This commit is contained in:
commit
5aa85e20aa
3 changed files with 67 additions and 1 deletions
|
@ -167,6 +167,19 @@ namespace SourceGit.Commands
|
|||
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)
|
||||
|
|
45
src/Models/WSL.cs
Normal file
45
src/Models/WSL.cs
Normal file
|
@ -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(':'));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -880,9 +880,17 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
|
||||
public void SetWatcherEnabled(bool enabled)
|
||||
{
|
||||
var wsl = new Models.WSL() { Path = FullPath };
|
||||
if (wsl.IsWSLPath())
|
||||
{
|
||||
_watcher?.MarkBranchDirtyManually();
|
||||
}
|
||||
else
|
||||
{
|
||||
_watcher?.SetEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
public void MarkBranchesDirtyManually()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue