using System;
namespace SourceGit.Commands {
///
/// 克隆
///
public class Clone : Command {
private Action handler = null;
private Action onError = null;
public Clone(string path, string url, string localName, string sshKey, string extraArgs, Action outputHandler, Action errHandler) {
Cwd = path;
TraitErrorAsOutput = true;
handler = outputHandler;
onError = errHandler;
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 ";
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);
}
}
}