mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 12:45:00 +00:00
feature: support git.core.askpass (#239)
This commit is contained in:
parent
8fa19ecd0c
commit
cbe4c36525
14 changed files with 211 additions and 60 deletions
|
@ -52,14 +52,10 @@
|
|||
cmd.Context = repo;
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey))
|
||||
{
|
||||
cmd.Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(sshKey))
|
||||
cmd.Args = "-c credential.helper=manager ";
|
||||
}
|
||||
else
|
||||
cmd.UseSSHKey(sshKey);
|
||||
|
||||
cmd.Args += $"push {remote} --delete {name}";
|
||||
return cmd.Exec();
|
||||
|
|
|
@ -13,13 +13,9 @@ namespace SourceGit.Commands
|
|||
TraitErrorAsOutput = true;
|
||||
|
||||
if (string.IsNullOrEmpty(sshKey))
|
||||
{
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
else
|
||||
{
|
||||
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
||||
}
|
||||
UseSSHKey(sshKey);
|
||||
|
||||
Args += "clone --progress --verbose --recurse-submodules ";
|
||||
|
||||
|
|
|
@ -28,6 +28,15 @@ namespace SourceGit.Commands
|
|||
public string Args { get; set; } = string.Empty;
|
||||
public bool RaiseError { get; set; } = true;
|
||||
public bool TraitErrorAsOutput { get; set; } = false;
|
||||
public Dictionary<string, string> Envs { get; set; } = new Dictionary<string, string>();
|
||||
|
||||
public void UseSSHKey(string key)
|
||||
{
|
||||
Envs.Add("DISPLAY", "required");
|
||||
Envs.Add("SSH_ASKPASS", Process.GetCurrentProcess().MainModule.FileName);
|
||||
Envs.Add("SSH_ASKPASS_REQUIRE", "prefer");
|
||||
Envs.Add("GIT_SSH_COMMAND", $"ssh -i '{key}'");
|
||||
}
|
||||
|
||||
public bool Exec()
|
||||
{
|
||||
|
@ -41,6 +50,10 @@ namespace SourceGit.Commands
|
|||
start.StandardOutputEncoding = Encoding.UTF8;
|
||||
start.StandardErrorEncoding = Encoding.UTF8;
|
||||
|
||||
// User environment overrides.
|
||||
foreach (var kv in Envs)
|
||||
start.Environment.Add(kv.Key, kv.Value);
|
||||
|
||||
// Force using en_US.UTF-8 locale to avoid GCM crash
|
||||
if (OperatingSystem.IsLinux())
|
||||
start.Environment.Add("LANG", "en_US.UTF-8");
|
||||
|
@ -94,7 +107,7 @@ namespace SourceGit.Commands
|
|||
return;
|
||||
if (e.Data.StartsWith("Filtering content:", StringComparison.Ordinal))
|
||||
return;
|
||||
if (_progressRegex().IsMatch(e.Data))
|
||||
if (REG_PROGRESS().IsMatch(e.Data))
|
||||
return;
|
||||
errs.Add(e.Data);
|
||||
};
|
||||
|
@ -185,6 +198,9 @@ namespace SourceGit.Commands
|
|||
protected virtual void OnReadline(string line) { }
|
||||
|
||||
[GeneratedRegex(@"\d+%")]
|
||||
private static partial Regex _progressRegex();
|
||||
private static partial Regex REG_PROGRESS();
|
||||
|
||||
[GeneratedRegex(@"Enter\s+passphrase\s*for\s*key\s*['""]([^'""]+)['""]\:\s*", RegexOptions.IgnoreCase)]
|
||||
private static partial Regex REG_ASKPASS();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,14 +15,10 @@ namespace SourceGit.Commands
|
|||
TraitErrorAsOutput = true;
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey))
|
||||
{
|
||||
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(sshKey))
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
else
|
||||
UseSSHKey(sshKey);
|
||||
|
||||
Args += "fetch --progress --verbose ";
|
||||
if (prune)
|
||||
|
@ -46,14 +42,10 @@ namespace SourceGit.Commands
|
|||
TraitErrorAsOutput = true;
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey))
|
||||
{
|
||||
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(sshKey))
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
else
|
||||
UseSSHKey(sshKey);
|
||||
|
||||
Args += $"fetch --progress --verbose {remote} {remoteBranch}:{localBranch}";
|
||||
}
|
||||
|
|
|
@ -12,14 +12,10 @@ namespace SourceGit.Commands
|
|||
TraitErrorAsOutput = true;
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey))
|
||||
{
|
||||
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(sshKey))
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
else
|
||||
UseSSHKey(sshKey);
|
||||
|
||||
Args += "pull --verbose --progress --tags ";
|
||||
if (useRebase)
|
||||
|
|
|
@ -12,14 +12,10 @@ namespace SourceGit.Commands
|
|||
_outputHandler = onProgress;
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey))
|
||||
{
|
||||
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(sshKey))
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
else
|
||||
UseSSHKey(sshKey);
|
||||
|
||||
Args += "push --progress --verbose ";
|
||||
|
||||
|
@ -39,14 +35,10 @@ namespace SourceGit.Commands
|
|||
Context = repo;
|
||||
|
||||
var sshKey = new Config(repo).Get($"remote.{remote}.sshkey");
|
||||
if (!string.IsNullOrEmpty(sshKey))
|
||||
{
|
||||
Args = $"-c core.sshCommand=\"ssh -i '{sshKey}'\" ";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(sshKey))
|
||||
Args = "-c credential.helper=manager ";
|
||||
}
|
||||
else
|
||||
UseSSHKey(sshKey);
|
||||
|
||||
Args += "push ";
|
||||
if (isDelete)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue