2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
|
|
namespace SourceGit.Commands {
|
|
|
|
|
public class Clone : Command {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private Action<string> _notifyProgress;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
public Clone(string ctx, string path, string url, string localName, string sshKey, string extraArgs, Action<string> ouputHandler) {
|
|
|
|
|
Context = ctx;
|
|
|
|
|
WorkingDirectory = path;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
TraitErrorAsOutput = true;
|
|
|
|
|
|
2023-08-23 05:45:12 -07:00
|
|
|
|
if (string.IsNullOrEmpty(sshKey)) {
|
2023-08-22 23:05:19 -07:00
|
|
|
|
Args = "-c credential.helper=manager ";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
} else {
|
|
|
|
|
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
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;
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_notifyProgress = ouputHandler;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2022-10-19 00:20:58 -07:00
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
protected override void OnReadline(string line) {
|
|
|
|
|
_notifyProgress?.Invoke(line);
|
2022-10-19 00:20:58 -07:00
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|