diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index afd19580..8619ccc6 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -85,6 +85,8 @@ namespace SparkleLib { CurrentHash = GetCurrentHash (); Domain = GetDomain (RemoteOriginUrl); + if (CurrentHash == null) + CreateInitialCommit (); HasChanged = false; @@ -128,6 +130,9 @@ namespace SparkleLib { // since SparkleShare was stopped AddCommitAndPush (); + if (CurrentHash == null) + CurrentHash = GetCurrentHash (); + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Idling..."); } @@ -409,7 +414,7 @@ namespace SparkleLib { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes..."); - Process.StartInfo.Arguments = "push"; + Process.StartInfo.Arguments = "push origin master"; Process.Start (); Process.WaitForExit (); @@ -466,6 +471,9 @@ namespace SparkleLib { public string GetDomain (string url) { + if (RemoteOriginUrl.Equals ("")) + return ""; + string domain = url.Substring (RemoteOriginUrl.IndexOf ("@") + 1); if (domain.IndexOf (":") > -1) @@ -482,19 +490,25 @@ namespace SparkleLib { public string GetCurrentHash () { - string current_hash; + Process process = new Process () { + EnableRaisingEvents = true + }; - Process process = new Process (); process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; - process.StartInfo.FileName = "git"; - process.StartInfo.WorkingDirectory = LocalPath; - process.StartInfo.Arguments = "rev-list --max-count=1 HEAD"; - process.Start (); + process.StartInfo.UseShellExecute = false; + process.StartInfo.FileName = "git"; + process.StartInfo.WorkingDirectory = LocalPath; + process.StartInfo.Arguments = "rev-list --max-count=1 HEAD"; - current_hash = process.StandardOutput.ReadToEnd ().Trim (); - - return current_hash; + process.Start (); + process.WaitForExit (); + + string current_hash = process.StandardOutput.ReadToEnd ().Trim (); + + if (process.ExitCode != 0) + return null; + else + return current_hash; } @@ -551,6 +565,18 @@ namespace SparkleLib { } + // Create a first commit in case the user has cloned + // an empty repository + private void CreateInitialCommit () + { + + TextWriter writer = new StreamWriter (Path.Combine (LocalPath, "SparkleShare.txt")); + writer.WriteLine (":)"); + writer.Close (); + + } + + // Gets the url of the remote repo, example: "ssh://git@git.gnome.org/project" public string GetRemoteOriginUrl () { diff --git a/SparkleShare/SparkleStatusIcon.cs b/SparkleShare/SparkleStatusIcon.cs index 26bc4791..32ef40a1 100644 --- a/SparkleShare/SparkleStatusIcon.cs +++ b/SparkleShare/SparkleStatusIcon.cs @@ -295,6 +295,9 @@ namespace SparkleShare { public void ShowState () { + if (SyncingReposCount < 0) + SyncingReposCount = 0; + if (SyncingReposCount > 0) SetSyncingState (); else