2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
|
|
namespace SourceGit.Commands {
|
|
|
|
|
public class Fetch : Command {
|
|
|
|
|
public Fetch(string repo, string remote, bool prune, Action<string> outputHandler) {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler = outputHandler;
|
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
TraitErrorAsOutput = true;
|
2021-10-12 02:14:48 -07:00
|
|
|
|
|
|
|
|
|
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
|
|
|
if (!string.IsNullOrEmpty(sshKey)) {
|
2023-08-23 05:45:12 -07:00
|
|
|
|
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
2021-10-12 02:14:48 -07:00
|
|
|
|
} else {
|
2023-08-22 23:05:19 -07:00
|
|
|
|
Args = "-c credential.helper=manager ";
|
2021-10-12 02:14:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Args += "fetch --progress --verbose ";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
if (prune) Args += "--prune ";
|
|
|
|
|
Args += remote;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 22:29:44 -07:00
|
|
|
|
public Fetch(string repo, string remote, string localBranch, string remoteBranch, Action<string> outputHandler) {
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler = outputHandler;
|
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2023-08-17 22:29:44 -07:00
|
|
|
|
TraitErrorAsOutput = true;
|
|
|
|
|
|
|
|
|
|
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
|
|
|
if (!string.IsNullOrEmpty(sshKey)) {
|
2023-08-23 05:45:12 -07:00
|
|
|
|
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
2023-08-17 22:29:44 -07:00
|
|
|
|
} else {
|
2023-08-22 23:05:19 -07:00
|
|
|
|
Args = "-c credential.helper=manager ";
|
2023-08-17 22:29:44 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Args += $"fetch --progress --verbose {remote} {remoteBranch}:{localBranch}";
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
protected override void OnReadline(string line) {
|
|
|
|
|
_outputHandler?.Invoke(line);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
private Action<string> _outputHandler;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|