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 Push : Command
|
|
|
|
|
{
|
|
|
|
|
public Push(string repo, string local, string remote, string remoteBranch, bool withTags, bool force, bool track, Action<string> onProgress)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
TraitErrorAsOutput = true;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler = onProgress;
|
2021-10-12 02:14:48 -07:00
|
|
|
|
|
|
|
|
|
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
2024-07-08 07:07:00 -07:00
|
|
|
|
if (string.IsNullOrEmpty(sshKey))
|
2023-08-22 23:05:19 -07:00
|
|
|
|
Args = "-c credential.helper=manager ";
|
2024-07-08 07:07:00 -07:00
|
|
|
|
else
|
|
|
|
|
UseSSHKey(sshKey);
|
2021-10-12 02:14:48 -07:00
|
|
|
|
|
|
|
|
|
Args += "push --progress --verbose ";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (withTags)
|
|
|
|
|
Args += "--tags ";
|
|
|
|
|
if (track)
|
|
|
|
|
Args += "-u ";
|
|
|
|
|
if (force)
|
|
|
|
|
Args += "--force-with-lease ";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
|
|
|
|
Args += $"{remote} {local}:{remoteBranch}";
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Push(string repo, string remote, string tag, bool isDelete)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-11-14 20:21:34 -08:00
|
|
|
|
|
|
|
|
|
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
2024-07-08 07:07:00 -07:00
|
|
|
|
if (string.IsNullOrEmpty(sshKey))
|
2023-08-22 23:05:19 -07:00
|
|
|
|
Args = "-c credential.helper=manager ";
|
2024-07-08 07:07:00 -07:00
|
|
|
|
else
|
|
|
|
|
UseSSHKey(sshKey);
|
2021-11-14 20:21:34 -08:00
|
|
|
|
|
|
|
|
|
Args += "push ";
|
2024-03-31 01:54:29 -07:00
|
|
|
|
if (isDelete)
|
|
|
|
|
Args += "--delete ";
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args += $"{remote} refs/tags/{tag}";
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
protected override void OnReadline(string line)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_outputHandler?.Invoke(line);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Action<string> _outputHandler = null;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|