refactor: fix maxOS PATH env

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-14 10:54:09 +08:00
parent c8bee2f6ba
commit c3e1fb93b6
No known key found for this signature in database
4 changed files with 14 additions and 19 deletions

View file

@ -198,10 +198,6 @@ namespace SourceGit.Commands
start.Environment.Add("LC_ALL", "C"); start.Environment.Add("LC_ALL", "C");
} }
// Fix macOS `PATH` env
if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv))
start.Environment.Add("PATH", Native.OS.CustomPathEnv);
// Force using this app as git editor. // Force using this app as git editor.
switch (Editor) switch (Editor)
{ {

View file

@ -17,10 +17,6 @@ namespace SourceGit.Commands
start.CreateNoWindow = true; start.CreateNoWindow = true;
start.WorkingDirectory = repo; start.WorkingDirectory = repo;
// Fix macOS `PATH` env
if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv))
start.Environment.Add("PATH", Native.OS.CustomPathEnv);
try try
{ {
Process.Start(start); Process.Start(start);
@ -44,10 +40,6 @@ namespace SourceGit.Commands
start.StandardErrorEncoding = Encoding.UTF8; start.StandardErrorEncoding = Encoding.UTF8;
start.WorkingDirectory = repo; start.WorkingDirectory = repo;
// Fix macOS `PATH` env
if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv))
start.Environment.Add("PATH", Native.OS.CustomPathEnv);
var proc = new Process() { StartInfo = start }; var proc = new Process() { StartInfo = start };
var builder = new StringBuilder(); var builder = new StringBuilder();

View file

@ -18,9 +18,22 @@ namespace SourceGit.Native
DisableDefaultApplicationMenuItems = true, DisableDefaultApplicationMenuItems = true,
}); });
// Fix `PATH` env on macOS.
var path = Environment.GetEnvironmentVariable("PATH");
if (string.IsNullOrEmpty(path))
path = "/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
else if (!path.Contains("/opt/homebrew/", StringComparison.Ordinal))
path = "/opt/homebrew/bin:/opt/homebrew/sbin:" + path;
var customPathFile = Path.Combine(OS.DataDir, "PATH"); var customPathFile = Path.Combine(OS.DataDir, "PATH");
if (File.Exists(customPathFile)) if (File.Exists(customPathFile))
OS.CustomPathEnv = File.ReadAllText(customPathFile).Trim(); {
var env = File.ReadAllText(customPathFile).Trim();
if (!string.IsNullOrEmpty(env))
path = env;
}
Environment.SetEnvironmentVariable("PATH", path);
} }
public string FindGitExecutable() public string FindGitExecutable()

View file

@ -31,12 +31,6 @@ namespace SourceGit.Native
private set; private set;
} = string.Empty; } = string.Empty;
public static string CustomPathEnv
{
get;
set;
} = string.Empty;
public static string GitExecutable public static string GitExecutable
{ {
get => _gitExecutable; get => _gitExecutable;