From f6b413ca8e70e182eafea9522327774cdece4d5b Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 15 Jun 2018 17:42:16 +0100 Subject: [PATCH 01/10] repo git: Use commit message from file to avoid command line conflicts --- Sparkles/Git/GitRepository.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index c2413053..8d7344f3 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -402,11 +402,28 @@ namespace Sparkles.Git { user_email = user_email.AESEncrypt (password); } - git = new GitCommand (LocalPath, - string.Format ("commit --all --message=\"{0}\" --author=\"{1} <{2}>\"", - message, user_name, user_email)); + GitCommand git_commit; + string message_file_path = Path.Combine (LocalPath, ".git", "info", "commit_message"); - git.StartAndReadStandardOutput (); + try { + File.WriteAllText (message_file_path, message); + + // Commit from message stored in temporary file to avoid special character conflicts on the command line + git_commit = new GitCommand (LocalPath, + string.Format ("commit --all --file=\"{0}\" --author=\"{1} <{2}>\"", + message_file_path, user_name, user_email)); + + } catch (IOException e) { + Logger.LogInfo ("Git", Name + " | Could not create commit message file: " + message_file_path, e); + + // If committing with a temporary file fails, use a simple static commit message + git_commit = new GitCommand (LocalPath, + string.Format ("commit --all --message=\"{0}\" --author=\"{1} <{2}>\"", + "Changes by SparkleShare", user_name, user_email)); + } + + git_commit.StartAndReadStandardOutput (); + File.Delete (message_file_path); } From 8ba4bfb5e7dd944b6af647e7b8093c6fa00659f9 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 15 Jun 2018 17:44:12 +0100 Subject: [PATCH 02/10] repo git: Better variable names --- Sparkles/Git/GitRepository.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index 8d7344f3..12117532 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -379,17 +379,17 @@ namespace Sparkles.Git { // Commits the made changes void Commit (string message) { - GitCommand git; + GitCommand git_config; string user_name = base.local_config.User.Name; string user_email = base.local_config.User.Email; if (!this.user_is_set) { - git = new GitCommand (LocalPath, "config user.name \"" + user_name + "\""); - git.StartAndWaitForExit (); + git_config = new GitCommand (LocalPath, "config user.name \"" + user_name + "\""); + git_config.StartAndWaitForExit (); - git = new GitCommand (LocalPath, "config user.email \"" + user_email + "\""); - git.StartAndWaitForExit (); + git_config = new GitCommand (LocalPath, "config user.email \"" + user_email + "\""); + git_config.StartAndWaitForExit (); this.user_is_set = true; } From 0813af349457238f22ff2c6203d1c709b7baa64b Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 15 Jun 2018 17:44:40 +0100 Subject: [PATCH 03/10] repo git: Fix whitespace --- Sparkles/Git/GitRepository.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index 12117532..df2618de 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -511,7 +511,7 @@ namespace Sparkles.Git { // ?? unmerged, new files -> Stage the new files var git_status = new GitCommand (LocalPath, "status --porcelain"); - string output = git_status.StartAndReadStandardOutput (); + string output = git_status.StartAndReadStandardOutput (); string [] lines = output.Split ("\n".ToCharArray ()); bool trigger_conflict_event = false; @@ -1014,7 +1014,7 @@ namespace Sparkles.Git { while (!git_status.StandardOutput.EndOfStream) { string line = git_status.StandardOutput.ReadLine (); - line = line.Trim (); + line = line.Trim (); if (line.EndsWith (".empty") || line.EndsWith (".empty\"")) line = line.Replace (".empty", ""); From 6f173be21b56832e0f8083f72c9347831d0b44fb Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 15 Jun 2018 17:45:34 +0100 Subject: [PATCH 04/10] repo git: Remove no longer needed commit message preparing --- Sparkles/Git/GitRepository.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index df2618de..6862a747 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -205,7 +205,7 @@ namespace Sparkles.Git { return false; } - string message = base.status_message.Replace ("\"", "\\\""); + string message = base.status_message; if (string.IsNullOrEmpty (message)) message = FormatCommitMessage (); @@ -1061,8 +1061,8 @@ namespace Sparkles.Git { foreach (Change change in ParseStatus ()) { if (change.Type == ChangeType.Moved) { - message += "< ‘" + EnsureSpecialChars (change.Path) + "’\n"; - message += "> ‘" + EnsureSpecialChars (change.MovedToPath) + "’\n"; + message += "< ‘" + change.Path + "’\n"; + message += "> ‘" + change.MovedToPath + "’\n"; } else { switch (change.Type) { From 214a383923d8151559635bff6289b80ddeb49b4b Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 15 Jun 2018 22:25:43 +0100 Subject: [PATCH 05/10] repo git: Always make sure LFS pre-push hook is executable --- Sparkles/Git/GitRepository.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index 6862a747..576d5648 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -81,6 +81,12 @@ namespace Sparkles.Git { git_config = new GitCommand (LocalPath, "config core.sshCommand " + GitCommand.FormatGitSSHCommand (auth_info)); git_config.StartAndWaitForExit(); + + 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 (); } From 99b6761acf642da1161d980b504c904956c45456 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 15 Jun 2018 22:28:05 +0100 Subject: [PATCH 06/10] repo git: Only run chmod for pre-push hook on non-Windows --- Sparkles/Git/GitRepository.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index 576d5648..2ea05d2d 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -82,11 +82,13 @@ namespace Sparkles.Git { git_config = new GitCommand (LocalPath, "config core.sshCommand " + GitCommand.FormatGitSSHCommand (auth_info)); git_config.StartAndWaitForExit(); - string pre_push_hook_path = Path.Combine (LocalPath, ".git", "hooks", "pre-push"); + 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 (); + // TODO: Use proper API + var chmod = new Command ("chmod", "700 " + pre_push_hook_path); + chmod.StartAndWaitForExit (); + } } From e37032b5331ed8ceb0fcc537f6d3468acb93f709 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 16 Jun 2018 11:53:46 +0100 Subject: [PATCH 07/10] git: Don't let Git read other global or local configuration --- Sparkles/Git/GitCommand.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sparkles/Git/GitCommand.cs b/Sparkles/Git/GitCommand.cs index 60d498ff..ba314c7d 100644 --- a/Sparkles/Git/GitCommand.cs +++ b/Sparkles/Git/GitCommand.cs @@ -93,6 +93,12 @@ namespace Sparkles.Git { SetEnvironmentVariable ("GIT_SSH_COMMAND", GIT_SSH_COMMAND); SetEnvironmentVariable ("GIT_TERMINAL_PROMPT", "0"); + + // Don't let Git try to read the config options in PREFIX/etc or ~ + SetEnvironmentVariable ("GIT_CONFIG_NOSYSTEM", "1"); + SetEnvironmentVariable ("PREFIX", ""); + SetEnvironmentVariable ("HOME", ""); + SetEnvironmentVariable ("LANG", "en_US"); } From bde443481fb5c14582a6e33a3165bfa2188ea26d Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 16 Jun 2018 12:37:42 +0100 Subject: [PATCH 08/10] git fetcher: Update comment --- Sparkles/Git/GitFetcher.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sparkles/Git/GitFetcher.cs b/Sparkles/Git/GitFetcher.cs index dfbb4534..1199e989 100644 --- a/Sparkles/Git/GitFetcher.cs +++ b/Sparkles/Git/GitFetcher.cs @@ -336,10 +336,10 @@ namespace Sparkles.Git { { string [] settings = { "core.autocrlf input", - "core.quotepath false", // Don't quote "unusual" characters in path names + "core.quotepath false", // For commands to output Unicode characters "as is". e.g. '"h\303\251"' becomes 'hé'. + "core.precomposeunicode true", // Use the same Unicode form on all filesystems "core.ignorecase false", // Be case sensitive explicitly to work on Mac "core.filemode false", // Ignore permission changes - "core.precomposeunicode true", // Use the same Unicode form on all filesystems "core.safecrlf false", "core.excludesfile \"\"", "core.packedGitLimit 128m", // Some memory limiting options From 99e188db8f44fabb85a0b848d2419b101136db51 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 16 Jun 2018 12:41:13 +0100 Subject: [PATCH 09/10] git fetcher: Chmod pre-push hook after clone --- Sparkles/Git/GitFetcher.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sparkles/Git/GitFetcher.cs b/Sparkles/Git/GitFetcher.cs index 1199e989..221a5af0 100644 --- a/Sparkles/Git/GitFetcher.cs +++ b/Sparkles/Git/GitFetcher.cs @@ -440,6 +440,14 @@ 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 (); + } } } } From df6cb3a77d3dd88eae62248abb5bc8645772d343 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 16 Jun 2018 12:45:12 +0100 Subject: [PATCH 10/10] repo git: Remove no longer needed string conversions --- Sparkles/Git/GitRepository.cs | 61 +++-------------------------------- 1 file changed, 5 insertions(+), 56 deletions(-) diff --git a/Sparkles/Git/GitRepository.cs b/Sparkles/Git/GitRepository.cs index 2ea05d2d..58247fc0 100644 --- a/Sparkles/Git/GitRepository.cs +++ b/Sparkles/Git/GitRepository.cs @@ -526,8 +526,7 @@ namespace Sparkles.Git { foreach (string line in lines) { string conflicting_file_path = line.Substring (3); - conflicting_file_path = EnsureSpecialChars (conflicting_file_path); - conflicting_file_path = conflicting_file_path.Trim ("\"".ToCharArray ()); + conflicting_file_path = conflicting_file_path.Trim ("\"".ToCharArray ()); // Remove possible rename indicators string [] separators = {" -> \"", " -> "}; @@ -827,8 +826,7 @@ namespace Sparkles.Git { change_set.User.Name.AESDecrypt (password), change_set.User.Email.AESDecrypt (password)); - } catch (Exception e) { - Console.WriteLine (e.StackTrace); + } catch (Exception) { change_set.User = new User (match.Groups ["name"].Value, match.Groups ["email"].Value); } } @@ -909,59 +907,10 @@ namespace Sparkles.Git { change.IsFolder = true; } - try { - change.Path = EnsureSpecialChars (change.Path); - - if (change.Type == ChangeType.Moved) - change.MovedToPath = EnsureSpecialChars (change.MovedToPath); - - } catch (Exception e) { - Logger.LogInfo ("Local", string.Format ("Error parsing line due to special character: '{0}'", line), e); - return null; - } - return change; } - string EnsureSpecialChars (string path) - { - // The path is quoted if it contains special characters - if (path.StartsWith ("\"")) - path = ResolveSpecialChars (path.Substring (1, path.Length - 2)); - - return path; - } - - - string ResolveSpecialChars (string s) - { - StringBuilder builder = new StringBuilder (s.Length); - List codes = new List (); - - for (int i = 0; i < s.Length; i++) { - while (s [i] == '\\' && - s.Length - i > 3 && - char.IsNumber (s [i + 1]) && - char.IsNumber (s [i + 2]) && - char.IsNumber (s [i + 3])) { - - codes.Add (Convert.ToByte (s.Substring (i + 1, 3), 8)); - i += 4; - } - - if (codes.Count > 0) { - builder.Append (Encoding.UTF8.GetString (codes.ToArray ())); - codes.Clear (); - } - - builder.Append (s [i]); - } - - return builder.ToString (); - } - - // Git doesn't track empty directories, so this method // fills them all with a hidden empty file. // @@ -1035,13 +984,13 @@ namespace Sparkles.Git { change = new Change () { Type = ChangeType.Moved, - Path = EnsureSpecialChars (path), - MovedToPath = EnsureSpecialChars (moved_to_path) + Path = path, + MovedToPath = moved_to_path }; } else { string path = line.Substring (2).Trim ("\" ".ToCharArray ()); - change = new Change () { Path = EnsureSpecialChars (path) }; + change = new Change () { Path = path }; change.Type = ChangeType.Added; if (line.StartsWith ("M")) {