diff --git a/src/Commands/Clone.cs b/src/Commands/Clone.cs index a6bfe11f..9a37aa2e 100644 --- a/src/Commands/Clone.cs +++ b/src/Commands/Clone.cs @@ -14,7 +14,7 @@ namespace SourceGit.Commands { handler = outputHandler; if (!string.IsNullOrEmpty(sshKey)) { - Environment.SetEnvironmentVariable("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); + Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); Args = ""; } else { Args = "-c credential.helper=manager "; diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 34115b4d..2228727f 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -52,6 +52,11 @@ namespace SourceGit.Commands { /// public bool TraitErrorAsOutput { get; set; } = false; + /// + /// 用于设置该进程独有的环境变量 + /// + public Dictionary Envs { get; set; } = new Dictionary(); + /// /// 运行 /// @@ -68,6 +73,8 @@ namespace SourceGit.Commands { if (!string.IsNullOrEmpty(Cwd)) start.WorkingDirectory = Cwd; + foreach (var kv in Envs) start.EnvironmentVariables[kv.Key] = kv.Value; + var progressFilter = new Regex(@"\s\d+%\s"); var errs = new List(); var proc = new Process() { StartInfo = start }; diff --git a/src/Commands/Fetch.cs b/src/Commands/Fetch.cs index c30787c7..f45495fb 100644 --- a/src/Commands/Fetch.cs +++ b/src/Commands/Fetch.cs @@ -16,7 +16,7 @@ namespace SourceGit.Commands { var sshKey = new Config(repo).Get($"remote.{remote}.sshkey"); if (!string.IsNullOrEmpty(sshKey)) { - Environment.SetEnvironmentVariable("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); + Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); Args = ""; } else { Args = "-c credential.helper=manager "; diff --git a/src/Commands/Pull.cs b/src/Commands/Pull.cs index f525a20f..af6bca05 100644 --- a/src/Commands/Pull.cs +++ b/src/Commands/Pull.cs @@ -16,7 +16,7 @@ namespace SourceGit.Commands { var sshKey = new Config(repo).Get($"remote.{remote}.sshkey"); if (!string.IsNullOrEmpty(sshKey)) { - Environment.SetEnvironmentVariable("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); + Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); Args = ""; } else { Args = "-c credential.helper=manager "; diff --git a/src/Commands/Push.cs b/src/Commands/Push.cs index 2742b564..211c7c27 100644 --- a/src/Commands/Push.cs +++ b/src/Commands/Push.cs @@ -14,7 +14,7 @@ namespace SourceGit.Commands { var sshKey = new Config(repo).Get($"remote.{remote}.sshkey"); if (!string.IsNullOrEmpty(sshKey)) { - Environment.SetEnvironmentVariable("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); + Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'"); Args = ""; } else { Args = "-c credential.helper=manager ";