command: Move Git logic out of SSH and derive from SSH command

This commit is contained in:
Hylke Bons 2017-04-15 12:19:30 +01:00
parent 77ed294bfd
commit 73f472e997
4 changed files with 17 additions and 23 deletions

View file

@ -19,7 +19,7 @@ using System.Text.RegularExpressions;
namespace Sparkles.Git {
public class GitCommand : Command {
public class GitCommand : SSHCommand {
public static string ExecPath;
@ -84,7 +84,7 @@ namespace Sparkles.Git {
string GIT_SSH_COMMAND = SSHCommand.SSHCommandPath;
if (auth_info != null)
GIT_SSH_COMMAND = SSHCommand.FormatGitSSHCommand (auth_info);
GIT_SSH_COMMAND = FormatGitSSHCommand (auth_info);
if (ExecPath != null)
SetEnvironmentVariable ("GIT_EXEC_PATH", ExecPath);
@ -208,5 +208,16 @@ namespace Sparkles.Git {
return error;
}
public static string FormatGitSSHCommand (SSHAuthenticationInfo auth_info)
{
return SSHCommandPath + " " +
"-i " + auth_info.PrivateKeyFilePath.Replace ("\\", "/").Replace (" ", "\\ ") + " " +
"-o UserKnownHostsFile=" + auth_info.KnownHostsFilePath.Replace ("\\", "/").Replace (" ", "\\ ") + " " +
"-o IdentitiesOnly=yes" + " " + // Don't fall back to other keys on the system
"-o PasswordAuthentication=no" + " " + // Don't hang on possible password prompts
"-F /dev/null"; // Ignore the system's SSH config file
}
}
}

View file

@ -416,7 +416,7 @@ namespace Sparkles.Git {
{
var git_config_required = new GitCommand (TargetFolder, "config filter.lfs.required true");
string GIT_SSH_COMMAND = SSHCommand.FormatGitSSHCommand (auth_info);
string GIT_SSH_COMMAND = GitCommand.FormatGitSSHCommand (auth_info);
string smudge_command;
string clean_command;

View file

@ -79,7 +79,7 @@ namespace Sparkles.Git {
git_config = new GitCommand (LocalPath, "config remote.origin.url \"" + RemoteUrl + "\"");
git_config.StartAndWaitForExit ();
git_config = new GitCommand (LocalPath, "config core.sshCommand " + SSHCommand.FormatGitSSHCommand (auth_info));
git_config = new GitCommand (LocalPath, "config core.sshCommand " + GitCommand.FormatGitSSHCommand (auth_info));
git_config.StartAndWaitForExit();
}
@ -210,13 +210,13 @@ namespace Sparkles.Git {
if (InstallationInfo.OperatingSystem == OS.Mac || InstallationInfo.OperatingSystem == OS.Windows) {
pre_push_hook_content =
"#!/bin/sh" + Environment.NewLine +
"env GIT_SSH_COMMAND='" + SSHCommand.FormatGitSSHCommand (auth_info) + "' " +
"env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand (auth_info) + "' " +
Path.Combine (Configuration.DefaultConfiguration.BinPath, "git-lfs").Replace ("\\", "/") + " pre-push \"$@\"";
} else {
pre_push_hook_content =
"#!/bin/sh" + Environment.NewLine +
"env GIT_SSH_COMMAND='" + SSHCommand.FormatGitSSHCommand (auth_info) + "' " +
"env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand (auth_info) + "' " +
"git-lfs pre-push \"$@\"";
}

View file

@ -38,23 +38,6 @@ namespace Sparkles {
public SSHCommand(string command, string args, SSHAuthenticationInfo auth_info) :
base (Path.Combine (SSHPath, command), args)
{
string GIT_SSH_COMMAND = SSHPath;
if (auth_info != null)
GIT_SSH_COMMAND = FormatGitSSHCommand (auth_info);
SetEnvironmentVariable ("GIT_SSH_COMMAND", GIT_SSH_COMMAND);
}
public static string FormatGitSSHCommand (SSHAuthenticationInfo auth_info)
{
return SSHCommandPath + " " +
"-i " + auth_info.PrivateKeyFilePath.Replace ("\\" , "/").Replace (" ", "\\ ") + " " +
"-o UserKnownHostsFile=" + auth_info.KnownHostsFilePath.Replace ("\\", "/").Replace (" ", "\\ ") + " " +
"-o IdentitiesOnly=yes" + " " + // Don't fall back to other keys on the system
"-o PasswordAuthentication=no" + " " + // Don't hang on possible password prompts
"-F /dev/null"; // Ignore the system's SSH config file
}
}
}