2021-04-29 05:05:55 -07:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace SourceGit.Commands {
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 克隆
|
|
|
|
/// </summary>
|
|
|
|
public class Clone : Command {
|
|
|
|
private Action<string> handler = null;
|
2022-10-19 00:20:58 -07:00
|
|
|
private Action<string> onError = null;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
2022-10-19 00:20:58 -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;
|
2022-10-19 00:20:58 -07:00
|
|
|
onError = errHandler;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
2021-10-12 02:14:48 -07:00
|
|
|
if (!string.IsNullOrEmpty(sshKey)) {
|
2021-10-12 02:26:39 -07:00
|
|
|
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
2021-10-12 02:14:48 -07:00
|
|
|
Args = "";
|
|
|
|
} else {
|
2023-08-22 23:05:19 -07:00
|
|
|
Args = "-c credential.helper=manager ";
|
2021-10-12 02:14:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2022-10-19 00:20:58 -07:00
|
|
|
|
|
|
|
public override void OnException(string message) {
|
|
|
|
onError?.Invoke(message);
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
|
|
|
}
|