From 73f472e997ab81b96f833c5218032ca95ab2ff22 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 15 Apr 2017 12:19:30 +0100 Subject: [PATCH] command: Move Git logic out of SSH and derive from SSH command --- Sparkles/Git/GitCommand.cs | 15 +++++++++++++-- Sparkles/Git/GitFetcher.cs | 2 +- Sparkles/Git/GitRepository.cs | 6 +++--- Sparkles/SSHCommand.cs | 17 ----------------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Sparkles/Git/GitCommand.cs b/Sparkles/Git/GitCommand.cs index 0748dac5..7d259e88 100644 --- a/Sparkles/Git/GitCommand.cs +++ b/Sparkles/Git/GitCommand.cs @@ -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 + } } } diff --git a/Sparkles/Git/GitFetcher.cs b/Sparkles/Git/GitFetcher.cs index 63638be6..9e6a7cb3 100644 --- a/Sparkles/Git/GitFetcher.cs +++ b/Sparkles/Git/GitFetcher.cs @@ -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; diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index 96b3aa10..84f229e8 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -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 \"$@\""; } diff --git a/Sparkles/SSHCommand.cs b/Sparkles/SSHCommand.cs index 324ec4b4..20dcc164 100644 --- a/Sparkles/SSHCommand.cs +++ b/Sparkles/SSHCommand.cs @@ -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 } } }