diff --git a/SparkleShare/Mac/Controller.cs b/SparkleShare/Mac/Controller.cs index db7510baf..fe4e7d52f 100644 --- a/SparkleShare/Mac/Controller.cs +++ b/SparkleShare/Mac/Controller.cs @@ -42,15 +42,7 @@ public Controller (Configuration config) { NSApplication.Init (); - GitCommand.GitPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core", "git"); - GitCommand.ExecPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core"); - - bool overwite = true; - - File.Copy ( - Path.Combine (GitCommand.ExecPath, "git-lfs"), - Path.Combine (Config.BinPath, "git-lfs"), - overwite); + Command.SetSearchPath(Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core")); NSWorkspace.Notifications.ObserveDidWake((object sender, NSNotificationEventArgs e) => { Console.Write ("Detected wake from sleep, checking for updates\n"); diff --git a/Sparkles/Command.cs b/Sparkles/Command.cs index b49bc0ec4..eeeb29f29 100644 --- a/Sparkles/Command.cs +++ b/Sparkles/Command.cs @@ -18,13 +18,25 @@ using System; using System.Diagnostics; using System.IO; +using System.Reflection; +using System.Collections.Generic; namespace Sparkles { public class Command : Process { bool write_output; + static string[] extended_search_path; + public static void SetSearchPath(string[] pathes) + { + extended_search_path = pathes; + } + + public static void SetSearchPath(string path) + { + SetSearchPath(new string[] { path}); + } public Command (string path, string args) : this (path, args, write_output: true) { @@ -116,17 +128,22 @@ public void SetEnvironmentVariable (string variable, string content) protected static string LocateCommand (string name) { - string [] possible_command_paths = { - Environment.GetFolderPath (Environment.SpecialFolder.Personal) + "/bin/" + name, - InstallationInfo.Directory + "/bin/" + name, - "/usr/local/bin/" + name, - "/usr/bin/" + name, - "/opt/local/bin/" + name + string[] possible_command_paths = { + Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.Personal), "bin"), + Path.Combine(InstallationInfo.Directory, "bin"), + "/usr/local/bin/", + "/usr/bin/", + "/opt/local/bin/" }; - foreach (string path in possible_command_paths) { - if (File.Exists (path)) - return path; + List command_paths = new List(); + command_paths.AddRange(extended_search_path); + command_paths.AddRange(possible_command_paths); + + foreach (string path in command_paths) { + if (File.Exists(Path.Combine (path, name))) { + return Path.Combine (path, name); + } } return name; diff --git a/Sparkles/Configuration.cs b/Sparkles/Configuration.cs index 83f5bb359..037b9331c 100644 --- a/Sparkles/Configuration.cs +++ b/Sparkles/Configuration.cs @@ -42,7 +42,6 @@ public class Configuration : XmlDocument { public readonly string DirectoryPath; public readonly string FilePath; public readonly string TmpPath; - public readonly string BinPath; public string AvatarProvider; public readonly string LogFilePath; @@ -73,11 +72,6 @@ public Configuration (string config_path, string config_file_name) FilePath = Path.Combine (config_path, config_file_name); DirectoryPath = config_path; - BinPath = Path.Combine (config_path, "bin"); - - if (!Directory.Exists (BinPath)) - Directory.CreateDirectory (BinPath); - string logs_path = Path.Combine (config_path, "logs"); int i = 1; diff --git a/Sparkles/Git/Git.Command.cs b/Sparkles/Git/Git.Command.cs index ffec4f603..6cf7c9b92 100644 --- a/Sparkles/Git/Git.Command.cs +++ b/Sparkles/Git/Git.Command.cs @@ -27,11 +27,12 @@ public class GitCommand : SSHCommand { static string git_path; - + static string git_lfs_path; + public static string GitPath { get { if (git_path == null) - git_path = LocateCommand ("git"); + git_path = LocateCommand ("git").Replace("\\", "/"); return git_path; } @@ -41,12 +42,21 @@ public static string GitPath { } } + public static string GitLfsPath { + get { + if (git_lfs_path == null) + git_lfs_path = LocateCommand ("git-lfs").Replace("\\","/"); + return git_lfs_path; + } + + set { + git_lfs_path = value; + } + } + public static string GitVersion { get { - if (GitPath == null) - GitPath = LocateCommand ("git"); - var git_version = new Command (GitPath, "--version", false); if (ExecPath != null) @@ -60,10 +70,7 @@ public static string GitVersion { public static string GitLFSVersion { get { - if (GitPath == null) - GitPath = LocateCommand ("git"); - - var git_lfs_version = new Command (GitPath, "lfs version", false); + var git_lfs_version = new Command (GitLfsPath, "version", false); if (ExecPath != null) git_lfs_version.SetEnvironmentVariable ("GIT_EXEC_PATH", ExecPath); diff --git a/Sparkles/Git/Git.Fetcher.cs b/Sparkles/Git/Git.Fetcher.cs index 052638f6a..84ebd3e93 100644 --- a/Sparkles/Git/Git.Fetcher.cs +++ b/Sparkles/Git/Git.Fetcher.cs @@ -427,16 +427,10 @@ void InstallGitLFS () string smudge_command; string clean_command; - if (InstallationInfo.OperatingSystem == OS.macOS || InstallationInfo.OperatingSystem == OS.Windows) { - smudge_command = "env GIT_SSH_COMMAND='" + GIT_SSH_COMMAND + "' " + - Path.Combine (Configuration.DefaultConfiguration.BinPath, "git-lfs").Replace ("\\", "/") + " smudge %f"; - clean_command = Path.Combine (Configuration.DefaultConfiguration.BinPath, "git-lfs").Replace ("\\", "/") + " clean %f"; + smudge_command = "env GIT_SSH_COMMAND='" + GIT_SSH_COMMAND.Replace("\"", "\\\"") + "' '" + GitCommand.GitLfsPath + "' smudge %f"; + clean_command = "'" + GitCommand.GitLfsPath + "' clean %f"; - } else { - smudge_command = "env GIT_SSH_COMMAND='" + GIT_SSH_COMMAND + "' git-lfs smudge %f"; - clean_command = "git-lfs clean %f"; - } var git_config_smudge = new GitCommand (TargetFolder, string.Format ("config filter.lfs.smudge \"{0}\"", smudge_command)); diff --git a/Sparkles/Git/Git.Repository.cs b/Sparkles/Git/Git.Repository.cs index ac19964cf..5ba7ddde5 100644 --- a/Sparkles/Git/Git.Repository.cs +++ b/Sparkles/Git/Git.Repository.cs @@ -893,18 +893,11 @@ void PrepareGitLFS () string pre_push_hook_path = Path.Combine (LocalPath, ".git", "hooks", "pre-push"); string pre_push_hook_content; - if (InstallationInfo.OperatingSystem == OS.macOS || InstallationInfo.OperatingSystem == OS.Windows) { - pre_push_hook_content = - "#!/bin/sh" + Environment.NewLine + - "env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand (auth_info) + "' " + - Path.Combine (Configuration.DefaultConfiguration.BinPath, "git-lfs").Replace ("\\", "/") + " pre-push \"$@\""; + pre_push_hook_content = + "#!/bin/sh" + Environment.NewLine + + "env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand (auth_info) + "' " + "'"+ + GitCommand.GitLfsPath + "' pre-push \"$@\""; - } else { - pre_push_hook_content = - "#!/bin/sh" + Environment.NewLine + - "env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand (auth_info) + "' " + - "git-lfs pre-push \"$@\""; - } if (InstallationInfo.OperatingSystem != OS.Windows) { // TODO: Use proper API