sourcegit/src/Commands/Push.cs

57 lines
1.6 KiB
C#
Raw Normal View History

using System;
2021-04-29 05:05:55 -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)
{
WorkingDirectory = repo;
Context = repo;
2021-04-29 05:05:55 -07:00
TraitErrorAsOutput = true;
_outputHandler = onProgress;
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
if (string.IsNullOrEmpty(sshKey))
Args = "-c credential.helper=manager ";
else
UseSSHKey(sshKey);
Args += "push --progress --verbose ";
2021-04-29 05:05:55 -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}";
}
public Push(string repo, string remote, string tag, bool isDelete)
{
WorkingDirectory = repo;
Context = repo;
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
if (string.IsNullOrEmpty(sshKey))
Args = "-c credential.helper=manager ";
else
UseSSHKey(sshKey);
Args += "push ";
if (isDelete)
Args += "--delete ";
2021-04-29 05:05:55 -07:00
Args += $"{remote} refs/tags/{tag}";
}
protected override void OnReadline(string line)
{
_outputHandler?.Invoke(line);
2021-04-29 05:05:55 -07:00
}
private readonly Action<string> _outputHandler = null;
2021-04-29 05:05:55 -07:00
}
}