Add Git version to logs

This commit is contained in:
Hylke Bons 2016-03-30 21:43:19 +01:00
parent 5ff930300f
commit 65b2b4b3b6
4 changed files with 40 additions and 19 deletions

View file

@ -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);

View file

@ -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 ();

View file

@ -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");
}

View file

@ -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 ();