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