From f6b413ca8e70e182eafea9522327774cdece4d5b Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Fri, 15 Jun 2018 17:42:16 +0100 Subject: [PATCH] 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); }