sourcegit/src/Commands/Clone.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2021-04-29 05:05:55 -07:00
using System;
namespace SourceGit.Commands {
/// <summary>
/// 克隆
/// </summary>
public class Clone : Command {
private Action<string> handler = null;
private Action<string> onError = null;
2021-04-29 05:05:55 -07:00
public Clone(string path, string url, string localName, string sshKey, string extraArgs, Action<string> outputHandler, Action<string> errHandler) {
2021-04-29 05:05:55 -07:00
Cwd = path;
TraitErrorAsOutput = true;
handler = outputHandler;
onError = errHandler;
2021-04-29 05:05:55 -07:00
if (!string.IsNullOrEmpty(sshKey)) {
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
Args = "";
} else {
Args = "-c credential.helper=manager ";
}
Args += "clone --progress --verbose --recurse-submodules ";
2021-04-29 05:05:55 -07:00
if (!string.IsNullOrEmpty(extraArgs)) Args += $"{extraArgs} ";
Args += $"{url} ";
if (!string.IsNullOrEmpty(localName)) Args += localName;
}
public override void OnReadline(string line) {
handler?.Invoke(line);
}
public override void OnException(string message) {
onError?.Invoke(message);
}
2021-04-29 05:05:55 -07:00
}
}