mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 12:15:00 +00:00
feature<SSH>: supports using ssh private key to access remote git repository
This commit is contained in:
parent
306292147f
commit
75a46ceb74
11 changed files with 200 additions and 18 deletions
|
@ -8,12 +8,20 @@ namespace SourceGit.Commands {
|
|||
public class Clone : Command {
|
||||
private Action<string> handler = null;
|
||||
|
||||
public Clone(string path, string url, string localName, string extraArgs, Action<string> outputHandler) {
|
||||
public Clone(string path, string url, string localName, string sshKey, string extraArgs, Action<string> outputHandler) {
|
||||
Cwd = path;
|
||||
TraitErrorAsOutput = true;
|
||||
Args = "-c credential.helper=manager clone --progress --verbose --recurse-submodules ";
|
||||
handler = outputHandler;
|
||||
|
||||
if (!string.IsNullOrEmpty(sshKey)) {
|
||||
Environment.SetEnvironmentVariable("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
||||
Args = "";
|
||||
} else {
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
|
||||
Args += "clone --progress --verbose --recurse-submodules ";
|
||||
|
||||
if (!string.IsNullOrEmpty(extraArgs)) Args += $"{extraArgs} ";
|
||||
Args += $"{url} ";
|
||||
if (!string.IsNullOrEmpty(localName)) Args += localName;
|
||||
|
|
|
@ -13,7 +13,16 @@ namespace SourceGit.Commands {
|
|||
public Fetch(string repo, string remote, bool prune, Action<string> outputHandler) {
|
||||
Cwd = repo;
|
||||
TraitErrorAsOutput = true;
|
||||
Args = "-c credential.helper=manager fetch --progress --verbose ";
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey)) {
|
||||
Environment.SetEnvironmentVariable("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
||||
Args = "";
|
||||
} else {
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
|
||||
Args += "fetch --progress --verbose ";
|
||||
if (prune) Args += "--prune ";
|
||||
Args += remote;
|
||||
handler = outputHandler;
|
||||
|
|
|
@ -11,10 +11,19 @@ namespace SourceGit.Commands {
|
|||
|
||||
public Pull(string repo, string remote, string branch, bool useRebase, bool autoStash, Action<string> onProgress) {
|
||||
Cwd = repo;
|
||||
Args = "-c credential.helper=manager pull --verbose --progress --tags ";
|
||||
TraitErrorAsOutput = true;
|
||||
handler = onProgress;
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey)) {
|
||||
Environment.SetEnvironmentVariable("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
||||
Args = "";
|
||||
} else {
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
|
||||
Args += "pull --verbose --progress --tags ";
|
||||
|
||||
if (useRebase) Args += "--rebase ";
|
||||
if (autoStash) {
|
||||
if (useRebase) Args += "--autostash ";
|
||||
|
|
|
@ -11,7 +11,16 @@ namespace SourceGit.Commands {
|
|||
Cwd = repo;
|
||||
TraitErrorAsOutput = true;
|
||||
handler = onProgress;
|
||||
Args = "-c credential.helper=manager push --progress --verbose ";
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey)) {
|
||||
Environment.SetEnvironmentVariable("GIT_SSH_COMMAND", $"ssh -i '{sshKey}'");
|
||||
Args = "";
|
||||
} else {
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
|
||||
Args += "push --progress --verbose ";
|
||||
|
||||
if (withTags) Args += "--tags ";
|
||||
if (track) Args += "-u ";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue