diff --git a/Sparkles/Git/Git.Fetcher.cs b/Sparkles/Git/Git.Fetcher.cs index 221a5af0..81bcfd52 100644 --- a/Sparkles/Git/Git.Fetcher.cs +++ b/Sparkles/Git/Git.Fetcher.cs @@ -414,7 +414,7 @@ namespace Sparkles.Git { void InstallGitLFS () { - var git_config_required = new GitCommand (TargetFolder, "config filter.lfs.required true"); + var git_config_required = new GitCommand (TargetFolder, "config filter.lfs.required true"); string GIT_SSH_COMMAND = GitCommand.FormatGitSSHCommand (auth_info); string smudge_command; @@ -427,7 +427,7 @@ namespace Sparkles.Git { clean_command = Path.Combine (Configuration.DefaultConfiguration.BinPath, "git-lfs").Replace ("\\", "/") + " clean %f"; } else { - smudge_command = "env GIT_SSH_COMMAND='" + GIT_SSH_COMMAND + "' git-lfs smudge %f"; + smudge_command = "env GIT_SSH_COMMAND='" + GIT_SSH_COMMAND + "' git-lfs smudge %f"; clean_command = "git-lfs clean %f"; } @@ -440,14 +440,6 @@ namespace Sparkles.Git { git_config_required.StartAndWaitForExit (); git_config_clean.StartAndWaitForExit (); git_config_smudge.StartAndWaitForExit (); - - if (InstallationInfo.OperatingSystem != OS.Windows) { - string pre_push_hook_path = Path.Combine (TargetFolder, ".git", "hooks", "pre-push"); - - // TODO: Use proper API - var chmod = new Command ("chmod", "700 " + pre_push_hook_path); - chmod.StartAndWaitForExit (); - } } } } diff --git a/Sparkles/Git/Git.Repository.cs b/Sparkles/Git/Git.Repository.cs index 58247fc0..5d432fa5 100644 --- a/Sparkles/Git/Git.Repository.cs +++ b/Sparkles/Git/Git.Repository.cs @@ -82,13 +82,7 @@ namespace Sparkles.Git { git_config = new GitCommand (LocalPath, "config core.sshCommand " + GitCommand.FormatGitSSHCommand (auth_info)); git_config.StartAndWaitForExit(); - if (InstallationInfo.OperatingSystem != OS.Windows) { - string pre_push_hook_path = Path.Combine (LocalPath, ".git", "hooks", "pre-push"); - - // TODO: Use proper API - var chmod = new Command ("chmod", "700 " + pre_push_hook_path); - chmod.StartAndWaitForExit (); - } + PrepareGitLFS (); } @@ -221,25 +215,7 @@ namespace Sparkles.Git { if (message != null) Commit (message); - string pre_push_hook_path = Path.Combine (LocalPath, ".git", "hooks", "pre-push"); - string pre_push_hook_content; - - // The pre-push hook may have been changed by Git LFS, overwrite it to use our own configuration - 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 \"$@\""; - - } else { - pre_push_hook_content = - "#!/bin/sh" + Environment.NewLine + - "env GIT_SSH_COMMAND='" + GitCommand.FormatGitSSHCommand (auth_info) + "' " + - "git-lfs pre-push \"$@\""; - } - - Directory.CreateDirectory (Path.GetDirectoryName (pre_push_hook_path)); - File.WriteAllText (pre_push_hook_path, pre_push_hook_content); + PrepareGitLFS (); var git_push = new GitCommand (LocalPath, string.Format ("push --all --progress origin", RemoteUrl), auth_info); git_push.StartInfo.RedirectStandardError = true; @@ -911,6 +887,36 @@ namespace Sparkles.Git { } + // The pre-push hook may have been changed by Git LFS, overwrite it to use our own configuration + 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 \"$@\""; + + } 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 + var chmod = new Command ("chmod", "700 " + pre_push_hook_path); + chmod.StartAndWaitForExit (); + } + + Directory.CreateDirectory (Path.GetDirectoryName (pre_push_hook_path)); + File.WriteAllText (pre_push_hook_path, pre_push_hook_content); + } + + // Git doesn't track empty directories, so this method // fills them all with a hidden empty file. //