diff --git a/SparkleLib/Git/SparkleFetcherGit.cs b/SparkleLib/Git/SparkleFetcherGit.cs index 58735308..94755d02 100755 --- a/SparkleLib/Git/SparkleFetcherGit.cs +++ b/SparkleLib/Git/SparkleFetcherGit.cs @@ -42,12 +42,14 @@ namespace SparkleLib.Git { SparkleGit git = new SparkleGit (TargetFolder, "branch -a"); git.StartAndWaitForExit (); - string [] branches = git.StartAndReadStandardOutput ().Split (Environment.NewLine.ToCharArray ()); - // TODO double check env.newline ^ - - foreach (string branch in branches) { - if (branch.StartsWith (" remotes/origin/salt-")) { - this.cached_salt = branch.Substring (22); + string [] branches = git.StartAndReadStandardOutput ().Split ("\n".ToCharArray ()); + Regex salt_regex = new Regex ("remotes/origin/salt-(.+)"); + + foreach (string branch in branches) { + Match salt_match = salt_regex.Match (branch); + + if (salt_match.Success) { + this.cached_salt = salt_match.Groups [1].Value; break; } } @@ -57,7 +59,7 @@ namespace SparkleLib.Git { this.cached_salt = GenerateCryptoSalt (); string salt_file_path = new string [] { TargetFolder, ".git", "salt" }.Combine (); - // Temporarily store the salt in a file, so the Repo can + // Temporarily store the salt in a file, so the Repo object can // push it to a branch on the host later File.WriteAllText (salt_file_path, this.cached_salt); } @@ -180,6 +182,9 @@ namespace SparkleLib.Git { this.git.WaitForExit (); if (this.git.ExitCode == 0) { + SparkleGit git_fetch = new SparkleGit (TargetFolder, "fetch --all"); + git_fetch.StartAndWaitForExit (); + while (percentage < 100) { percentage += 25; @@ -231,9 +236,11 @@ namespace SparkleLib.Git { string n = Environment.NewLine; + string salt = this.crypto_salt; + config += "[filter \"crypto\"]" + n + - "\tsmudge = openssl enc -d -aes-256-cbc -base64 -S " + this.crypto_salt + " -pass file:.git/password" + n + - "\tclean = openssl enc -e -aes-256-cbc -base64 -S " + this.crypto_salt + " -pass file:.git/password" + n; + "\tsmudge = openssl enc -d -aes-256-cbc -base64 -S " + salt + " -pass file:.git/password" + n + + "\tclean = openssl enc -e -aes-256-cbc -base64 -S " + salt + " -pass file:.git/password" + n; File.WriteAllText (repo_config_file_path, config); diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 53782fe5..16f65aa5 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -28,7 +28,7 @@ namespace SparkleLib.Git { public class SparkleRepo : SparkleRepoBase { - private bool user_is_set; + private bool user_is_set; private bool use_git_bin; private bool is_encrypted; @@ -185,22 +185,6 @@ namespace SparkleLib.Git { string message = FormatCommitMessage (); Commit (message); - - string salt_file_path = new string [] { LocalPath, ".git", "salt" }.Combine (); - - // If the repo is encrypted, create a branch to - // store the in and push it to the host - if (File.Exists (salt_file_path)) { - string salt = File.ReadAllText (salt_file_path).Trim (); - - SparkleGit git_salt = new SparkleGit (LocalPath, "branch salt-" + salt); - git_salt.StartAndWaitForExit (); - - git_salt = new SparkleGit (LocalPath, "push origin salt-" + salt); - git_salt.StartAndWaitForExit (); - - File.Delete (salt_file_path); - } } SparkleGit git; @@ -268,6 +252,23 @@ namespace SparkleLib.Git { if (git.ExitCode == 0) { ClearCache (); + + string salt_file_path = new string [] { LocalPath, ".git", "salt" }.Combine (); + + // If the repo is encrypted, create a branch to + // store the in and push it to the host + if (File.Exists (salt_file_path)) { + string salt = File.ReadAllText (salt_file_path).Trim (); + + SparkleGit git_salt = new SparkleGit (LocalPath, "branch salt-" + salt); + git_salt.StartAndWaitForExit (); + + git_salt = new SparkleGit (LocalPath, "push origin salt-" + salt); + git_salt.StartAndWaitForExit (); + + File.Delete (salt_file_path); + } + return true; } else { @@ -337,11 +338,11 @@ namespace SparkleLib.Git { Rebase (); string identifier_file_path = Path.Combine (LocalPath, ".sparkleshare"); - File.SetAttributes (identifier_file_path, FileAttributes.Hidden); + File.SetAttributes (identifier_file_path, FileAttributes.Hidden); ClearCache (); - return true; + return true; } else { Error = ErrorStatus.HostUnreachable; @@ -391,18 +392,18 @@ namespace SparkleLib.Git { // Commits the made changes private void Commit (string message) - { - SparkleGit git; + { + SparkleGit git; - if (!this.user_is_set) { - git = new SparkleGit (LocalPath, "config user.name \"" + base.local_config.User.Name + "\""); - git.StartAndWaitForExit (); + if (!this.user_is_set) { + git = new SparkleGit (LocalPath, "config user.name \"" + base.local_config.User.Name + "\""); + git.StartAndWaitForExit (); - git = new SparkleGit (LocalPath, "config user.email \"" + base.local_config.User.Email + "\""); - git.StartAndWaitForExit (); + git = new SparkleGit (LocalPath, "config user.email \"" + base.local_config.User.Email + "\""); + git.StartAndWaitForExit (); - this.user_is_set = true; - } + this.user_is_set = true; + } git = new SparkleGit (LocalPath, "commit --all --message=\"" + message + "\" " + "--author=\"" + base.local_config.User.Name + " <" + base.local_config.User.Email + ">\"");