Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search git and git-lfs via locate function #1984

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions SparkleShare/Mac/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
35 changes: 26 additions & 9 deletions Sparkles/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<string> command_paths = new List<string>();
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;
Expand Down
6 changes: 0 additions & 6 deletions Sparkles/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 16 additions & 9 deletions Sparkles/Git/Git.Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)
Expand All @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions Sparkles/Git/Git.Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
15 changes: 4 additions & 11 deletions Sparkles/Git/Git.Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down