2021-04-29 05:05:55 -07:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace SourceGit.Commands {
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 克隆
|
|
|
|
/// </summary>
|
|
|
|
public class Clone : Command {
|
|
|
|
private Action<string> handler = null;
|
|
|
|
|
2021-10-12 02:14:48 -07:00
|
|
|
public Clone(string path, string url, string localName, string sshKey, string extraArgs, Action<string> outputHandler) {
|
2021-04-29 05:05:55 -07:00
|
|
|
Cwd = path;
|
|
|
|
TraitErrorAsOutput = true;
|
|
|
|
handler = outputHandler;
|
|
|
|
|
2021-10-12 02:14:48 -07:00
|
|
|
if (!string.IsNullOrEmpty(sshKey)) {
|
|
|
|
Environment.SetEnvironmentVariable("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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|