2021-04-29 05:05:55 -07:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace SourceGit.Commands {
|
|
|
|
/// <summary>
|
|
|
|
/// 推送
|
|
|
|
/// </summary>
|
|
|
|
public class Push : Command {
|
|
|
|
private Action<string> handler = null;
|
|
|
|
|
|
|
|
public Push(string repo, string local, string remote, string remoteBranch, bool withTags, bool force, bool track, Action<string> onProgress) {
|
|
|
|
Cwd = repo;
|
|
|
|
TraitErrorAsOutput = true;
|
|
|
|
handler = onProgress;
|
2021-10-12 02:14:48 -07:00
|
|
|
|
|
|
|
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
|
|
if (!string.IsNullOrEmpty(sshKey)) {
|
2021-10-12 02:26:39 -07:00
|
|
|
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
2021-10-12 02:14:48 -07:00
|
|
|
Args = "";
|
|
|
|
} else {
|
2023-08-22 23:05:19 -07:00
|
|
|
Args = "-c credential.helper=manager ";
|
2021-10-12 02:14:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ";
|
|
|
|
|
|
|
|
Args += $"{remote} {local}:{remoteBranch}";
|
|
|
|
}
|
|
|
|
|
|
|
|
public Push(string repo, string remote, string branch) {
|
|
|
|
Cwd = repo;
|
2021-11-14 20:21:34 -08:00
|
|
|
|
|
|
|
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
|
|
if (!string.IsNullOrEmpty(sshKey)) {
|
|
|
|
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
|
|
|
Args = "";
|
|
|
|
} else {
|
2023-08-22 23:05:19 -07:00
|
|
|
Args = "-c credential.helper=manager ";
|
2021-11-14 20:21:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Args += $"push {remote} --delete {branch}";
|
2021-04-29 05:05:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public Push(string repo, string remote, string tag, bool isDelete) {
|
|
|
|
Cwd = repo;
|
2021-11-14 20:21:34 -08:00
|
|
|
|
|
|
|
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
|
|
|
if (!string.IsNullOrEmpty(sshKey)) {
|
|
|
|
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
|
|
|
Args = "";
|
|
|
|
} else {
|
2023-08-22 23:05:19 -07:00
|
|
|
Args = "-c credential.helper=manager ";
|
2021-11-14 20:21:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Args += "push ";
|
2021-04-29 05:05:55 -07:00
|
|
|
if (isDelete) Args += "--delete ";
|
|
|
|
Args += $"{remote} refs/tags/{tag}";
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnReadline(string line) {
|
|
|
|
handler?.Invoke(line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|