sparkles: Add Git LFS support

This commit is contained in:
Hylke Bons 2016-05-29 20:14:40 -07:00 committed by Hylke Bons
parent 6e16361c8f
commit bfdb72194c
3 changed files with 55 additions and 15 deletions

View file

@ -24,6 +24,13 @@ using Timers = System.Timers;
namespace Sparkles { namespace Sparkles {
public enum RepositoryStorageType {
Plain,
Encrypted,
LargeFiles,
LargeFilesEncrypted
}
public enum SyncStatus { public enum SyncStatus {
Idle, Idle,
Paused, Paused,
@ -32,7 +39,6 @@ namespace Sparkles {
Error Error
} }
public enum ErrorStatus { public enum ErrorStatus {
None, None,
HostUnreachable, HostUnreachable,
@ -63,6 +69,8 @@ namespace Sparkles {
public abstract List<ChangeSet> GetChangeSets (); public abstract List<ChangeSet> GetChangeSets ();
public abstract List<ChangeSet> GetChangeSets (string path); public abstract List<ChangeSet> GetChangeSets (string path);
protected RepositoryStorageType StorageType = RepositoryStorageType.Plain;
public static bool UseCustomWatcher = false; public static bool UseCustomWatcher = false;

View file

@ -184,6 +184,7 @@ namespace Sparkles.Git {
InstallExcludeRules (); InstallExcludeRules ();
InstallAttributeRules (); InstallAttributeRules ();
InstallGitLFS (); InstallGitLFS ();
EnableGitLFS (); // TODO
return true; return true;
} }
@ -360,8 +361,18 @@ namespace Sparkles.Git {
void InstallGitLFS () void InstallGitLFS ()
{ {
var git_lfs = new GitCommand (TargetFolder, "lfs install --local"); var git_config_required = new GitCommand (TargetFolder, "config filter.lfs.required true");
git_lfs.StartAndWaitForExit (); var git_config_clean = new GitCommand (TargetFolder, "config filter.lfs.clean 'git-lfs clean %f'");
string GIT_SSH_COMMAND = GitCommand.FormatGitSSHCommand (auth_info);
string smudge_command = "env GIT_SSH_COMMAND='" + GIT_SSH_COMMAND + "' git-lfs smudge %f";
var git_config_smudge = new GitCommand (TargetFolder,
"config filter.lfs.smudge \"" + smudge_command + "\"");
git_config_required.StartAndWaitForExit ();
git_config_clean.StartAndWaitForExit ();
git_config_smudge.StartAndWaitForExit ();
} }

View file

@ -89,11 +89,14 @@ namespace Sparkles.Git {
{ {
this.auth_info = auth_info; this.auth_info = auth_info;
var git = new GitCommand (LocalPath, "config core.ignorecase false"); if (RemoteUrl.Host == "github.com") // TODO
git.StartAndWaitForExit (); StorageType = RepositoryStorageType.LargeFiles;
git = new GitCommand (LocalPath, "config remote.origin.url \"" + RemoteUrl + "\""); var git_config = new GitCommand (LocalPath, "config core.ignorecase false");
git.StartAndWaitForExit (); git_config.StartAndWaitForExit ();
git_config = new GitCommand (LocalPath, "config remote.origin.url \"" + RemoteUrl + "\"");
git_config.StartAndWaitForExit ();
string password_file_path = Path.Combine (LocalPath, ".git", "password"); string password_file_path = Path.Combine (LocalPath, ".git", "password");
@ -198,7 +201,7 @@ namespace Sparkles.Git {
Logger.LogInfo ("Git", Name + " | Remote " + remote_revision + " is already in our history"); Logger.LogInfo ("Git", Name + " | Remote " + remote_revision + " is already in our history");
return false; return false;
} }
} }
Logger.LogInfo ("Git", Name + " | No remote changes, local+remote: " + current_revision); Logger.LogInfo ("Git", Name + " | No remote changes, local+remote: " + current_revision);
return false; return false;
@ -221,14 +224,27 @@ namespace Sparkles.Git {
if (message != null) if (message != null)
Commit (message); Commit (message);
var git = new GitCommand (LocalPath, "push --progress \"" + RemoteUrl + "\" " + this.branch, auth_info); string pre_push_hook_path = Path.Combine (LocalPath, ".git", "hooks", "pre-push");
git.StartInfo.RedirectStandardError = true;
git.Start (); // We start "git lfs push" manually, so remove the
// hook automatically created by the clean/smudge filters
if (File.Exists (pre_push_hook_path))
File.Delete (pre_push_hook_path);
if (StorageType == RepositoryStorageType.LargeFiles) {
// TODO: Progress reporting, error handling
var git_lfs_push = new GitCommand (LocalPath, "lfs push origin " + branch, auth_info);
git_lfs_push.StartAndWaitForExit ();
}
var git_push = new GitCommand (LocalPath, "push --progress \"" + RemoteUrl + "\" " + this.branch, auth_info);
git_push.StartInfo.RedirectStandardError = true;
git_push.Start ();
double percentage = 1.0; double percentage = 1.0;
while (!git.StandardError.EndOfStream) { while (!git_push.StandardError.EndOfStream) {
string line = git.StandardError.ReadLine (); string line = git_push.StandardError.ReadLine ();
Match match = this.progress_regex.Match (line); Match match = this.progress_regex.Match (line);
double speed = 0.0; double speed = 0.0;
double number = 0.0; double number = 0.0;
@ -279,10 +295,10 @@ namespace Sparkles.Git {
} }
} }
git.WaitForExit (); git_push.WaitForExit ();
UpdateSizes (); UpdateSizes ();
if (git.ExitCode == 0) if (git_push.ExitCode == 0)
return true; return true;
Error = ErrorStatus.HostUnreachable; Error = ErrorStatus.HostUnreachable;
@ -292,6 +308,11 @@ namespace Sparkles.Git {
public override bool SyncDown () public override bool SyncDown ()
{ {
if (StorageType == RepositoryStorageType.LargeFiles) {
var git_lfs_pull = new GitCommand (LocalPath, "lfs pull", auth_info);
git_lfs_pull.StartAndWaitForExit ();
}
var git = new GitCommand (LocalPath, "fetch --progress \"" + RemoteUrl + "\" " + this.branch, auth_info); var git = new GitCommand (LocalPath, "fetch --progress \"" + RemoteUrl + "\" " + this.branch, auth_info);
git.StartInfo.RedirectStandardError = true; git.StartInfo.RedirectStandardError = true;