From 65b2b4b3b6b956ebd55c1e2eb83facbd5f26b1b2 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Wed, 30 Mar 2016 21:43:19 +0100 Subject: [PATCH] Add Git version to logs --- SparkleLib/Git/SparkleGit.cs | 18 ++++++++++++----- SparkleLib/SparkleProcess.cs | 28 +++++++++++++++++++-------- SparkleShare/Mac/SparkleController.cs | 6 +++--- SparkleShare/SparkleControllerBase.cs | 7 ++++--- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/SparkleLib/Git/SparkleGit.cs b/SparkleLib/Git/SparkleGit.cs index cab9141d..16bf5566 100644 --- a/SparkleLib/Git/SparkleGit.cs +++ b/SparkleLib/Git/SparkleGit.cs @@ -19,17 +19,25 @@ namespace SparkleLib.Git { public class SparkleGit : SparkleProcess { - public static string ExecPath; - public static string GitPath; public static string SSHPath; + public static string GitPath; + public static string ExecPath; + + + public static string GitVersion { + get { + string git_version = new SparkleProcess (GitPath, "--version").StartAndReadStandardOutput (); + return git_version.Replace ("git version ", ""); + } + } public SparkleGit (string path, string args) : base (path, args) { - if (string.IsNullOrEmpty (GitPath)) + if (GitPath == null) GitPath = LocateCommand ("git"); - StartInfo.FileName = GitPath; + StartInfo.FileName = GitPath; StartInfo.WorkingDirectory = path; if (string.IsNullOrEmpty (SSHPath)) @@ -41,7 +49,7 @@ namespace SparkleLib.Git { "-o PasswordAuthentication=no " + "-F /dev/null"; // Ignore the environment's SSH config file - if (!string.IsNullOrEmpty (ExecPath)) + if (ExecPath == null) SetEnvironmentVariable ("GIT_EXEC_PATH", ExecPath); SetEnvironmentVariable ("GIT_SSH_COMMAND", GIT_SSH_COMMAND); diff --git a/SparkleLib/SparkleProcess.cs b/SparkleLib/SparkleProcess.cs index 1e67a5f3..cfced2fb 100644 --- a/SparkleLib/SparkleProcess.cs +++ b/SparkleLib/SparkleProcess.cs @@ -23,14 +23,25 @@ namespace SparkleLib { public class SparkleProcess : Process { - public SparkleProcess (string path, string args) { - StartInfo.FileName = path; - StartInfo.Arguments = args; - StartInfo.UseShellExecute = false; + bool write_output; + + + public SparkleProcess (string path, string args) : this (path, args, false) + { + } + + + public SparkleProcess (string path, string args, bool write_output) + { + this.write_output = write_output; + + StartInfo.FileName = path; + StartInfo.Arguments = args; + StartInfo.UseShellExecute = false; StartInfo.RedirectStandardOutput = true; - StartInfo.RedirectStandardError = true; - StartInfo.CreateNoWindow = true; - EnableRaisingEvents = true; + StartInfo.RedirectStandardError = true; + StartInfo.CreateNoWindow = true; + EnableRaisingEvents = true; } @@ -41,7 +52,8 @@ namespace SparkleLib { if (!string.IsNullOrEmpty (StartInfo.WorkingDirectory)) folder = Path.GetFileName (StartInfo.WorkingDirectory) + " | "; - SparkleLogger.LogInfo ("Cmd", folder + Path.GetFileName (StartInfo.FileName) + " " + StartInfo.Arguments); + if (this.write_output) + SparkleLogger.LogInfo ("Cmd", folder + Path.GetFileName (StartInfo.FileName) + " " + StartInfo.Arguments); try { base.Start (); diff --git a/SparkleShare/Mac/SparkleController.cs b/SparkleShare/Mac/SparkleController.cs index 7881f85e..66ef47dd 100755 --- a/SparkleShare/Mac/SparkleController.cs +++ b/SparkleShare/Mac/SparkleController.cs @@ -25,6 +25,7 @@ using MonoMac.Foundation; using MonoMac.AppKit; using SparkleLib; +using SparkleLib.Git; namespace SparkleShare { @@ -41,9 +42,8 @@ namespace SparkleShare { { NSApplication.Init (); - // Let's use the bundled git first - SparkleLib.Git.SparkleGit.GitPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core", "git"); - SparkleLib.Git.SparkleGit.ExecPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core"); + SparkleGit.GitPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core", "git"); + SparkleGit.ExecPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core"); } diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 13966a1f..d31bb85e 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -22,6 +22,7 @@ using System.Linq; using System.Threading; using SparkleLib; +using SparkleLib.Git; namespace SparkleShare { @@ -211,9 +212,9 @@ namespace SparkleShare { public virtual void Initialize () { - SparkleLogger.LogInfo ("Environment", SparkleLib.SparkleBackend.Platform + " (" + Environment.OSVersion + ")"); - // TODO: SparkleLogger.LogInfo ("Environment", "Git version: "); - SparkleLogger.LogInfo ("Environment", "SparkleShare " + SparkleLib.SparkleBackend.Version); + SparkleLogger.LogInfo ("Environment", "SparkleShare " + SparkleBackend.Version); + SparkleLogger.LogInfo ("Environment", "Git " + SparkleGit.GitVersion); + SparkleLogger.LogInfo ("Environment", SparkleBackend.Platform + " (" + Environment.OSVersion + ")"); SparklePlugin.PluginsPath = PluginsPath; InstallProtocolHandler ();