diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index 6fe5bfe6..95250794 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -303,7 +303,7 @@ namespace SparkleLib { string remote_hash = git.StandardOutput.ReadToEnd (); if (!remote_hash.StartsWith (_CurrentHash)) { - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found."); + SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Remote changes found." + _CurrentHash + " " + remote_hash); Fetch (); Watcher.EnableRaisingEvents = false; @@ -400,10 +400,8 @@ namespace SparkleLib { CommitEndedUpEmpty (this, args); } } finally { - RemoteTimer.Start (); LocalTimer.Start (); - } } @@ -447,13 +445,19 @@ namespace SparkleLib { private string GetCurrentHash () { + // Remove stale rebase-apply files because it + // makes the method return the wrong hashes. + string rebase_apply_file = SparkleHelpers.CombineMore (LocalPath, ".git", "rebase-apply"); + if (File.Exists (rebase_apply_file)) + File.Delete (rebase_apply_file); + SparkleGit git = new SparkleGit (LocalPath, "log -1 --format=%H"); git.Start (); git.WaitForExit (); string output = git.StandardOutput.ReadToEnd (); string hash = output.Trim (); - + Console.WriteLine (hash+"!!!!!!!!!!!!!!!!"); return hash; } @@ -575,42 +579,27 @@ namespace SparkleLib { SparkleGit git = new SparkleGit (LocalPath, "rebase -v FETCH_HEAD"); git.Exited += delegate { -/* if (Status.MergeConflict.Count > 0) { + if (git.ExitCode != 0) { SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict detected..."); - foreach (string problem_file_name in Status.MergeConflict) { - SparkleGit git_ours = new SparkleGit (LocalPath, - "checkout --ours " + problem_file_name); - git_ours.Start (); - git_ours.WaitForExit (); - - string timestamp = DateTime.Now.ToString ("H:mm d MMM"); - string new_file_name = problem_file_name + " (" + UserName + ", " + timestamp + ")"; + while (AnyDifferences) { + ResolveConflict (); + Add (); - File.Move (problem_file_name, new_file_name); - - SparkleGit git_theirs = new SparkleGit (LocalPath, - "checkout --theirs " + problem_file_name); - git_theirs.Start (); - git_theirs.WaitForExit (); - - SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected"); - - if (ConflictDetected != null) - ConflictDetected (this, args); + SparkleGit git_continue = new SparkleGit (LocalPath, "rebase --continue"); + git_continue.Start (); + git_continue.WaitForExit (); } - Add (); - - SparkleGit git_continue = new SparkleGit (LocalPath, "rebase --continue"); - git_continue.Start (); - git_continue.WaitForExit (); - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Conflict resolved."); -*/ - _CurrentHash = GetCurrentHash (); -// Push (); -// } + + SparkleEventArgs args = new SparkleEventArgs ("ConflictDetected"); + if (ConflictDetected != null) + ConflictDetected (this, args); + } + + _CurrentHash = GetCurrentHash (); + Push (); }; git.Start (); @@ -625,6 +614,44 @@ namespace SparkleLib { } + private void ResolveConflict () + { + SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain"); + git_status.Start (); + git_status.WaitForExit (); + + string output = git_status.StandardOutput.ReadToEnd ().TrimEnd (); + string [] lines = output.Split ("\n".ToCharArray ()); + + // We're going to recover the two original versions of + // each conflicting path, and put a timestamp on our versions + foreach (string line in lines) { + if (line.StartsWith ("UU")) { + string conflicting_path = line.Substring (3); + + File.Delete (conflicting_path); + + // Recover our version + SparkleGit git_ours = new SparkleGit (LocalPath, + "checkout --ours " + conflicting_path); + git_ours.Start (); + git_ours.WaitForExit (); + + // Append a timestamp to our version + string timestamp = DateTime.Now.ToString ("HH:mm d MMM"); + string our_path = conflicting_path + " (" + UserName + ", " + timestamp + ")"; + File.Move (conflicting_path, our_path); + + // Recover the server's version + SparkleGit git_theirs = new SparkleGit (LocalPath, + "checkout --theirs " + conflicting_path); + git_theirs.Start (); + git_theirs.WaitForExit (); + } + } + } + + // Pushes the changes to the remote repo public void Push () { @@ -811,7 +838,7 @@ namespace SparkleLib { List commits = new List (); - SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw --date=iso"); + SparkleGit git_log = new SparkleGit (LocalPath, "log -" + count + " --raw -M --date=iso"); Console.OutputEncoding = System.Text.Encoding.Unicode; git_log.Start (); @@ -883,6 +910,7 @@ namespace SparkleLib { string change_type = entry_line [37].ToString (); string file_path = entry_line.Substring (39); + string to_file_path; if (change_type.Equals ("A")) { commit.Added.Add (file_path); @@ -890,6 +918,13 @@ namespace SparkleLib { commit.Edited.Add (file_path); } else if (change_type.Equals ("D")) { commit.Deleted.Add (file_path); + } else if (change_type.Equals ("R")) { + int tab_pos = entry_line.LastIndexOf ("\t"); + file_path = entry_line.Substring (42, tab_pos - 42); + to_file_path = entry_line.Substring (tab_pos + 1); + + commit.MovedFrom.Add (file_path); + commit.MovedTo.Add (to_file_path); } } } diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index c30a2e9b..347f4c31 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -379,29 +379,53 @@ namespace SparkleShare { } - if (change_set.Deleted.Count > 0) { - - event_entry += "
Deleted
"; - - foreach (string file_path in change_set.Deleted) { - - string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, - name, file_path); - - if (File.Exists (absolute_file_path)) { - - event_entry += "
" + file_path + "
"; - - } else { - - event_entry += "
" + file_path + "
"; - - } - - } - - } - + if (change_set.Deleted.Count > 0) { + + event_entry += "
Deleted
"; + + foreach (string file_path in change_set.Deleted) { + + string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, + name, file_path); + + if (File.Exists (absolute_file_path)) { + + event_entry += "
" + file_path + "
"; + + } else { + + event_entry += "
" + file_path + "
"; + + } + + } + + } + + if (change_set.MovedFrom.Count > 0) { + event_entry += "
Moved
"; + + int i = 0; + foreach (string file_path in change_set.MovedFrom) { + string to_file_path = change_set.MovedTo [i]; + string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, + name, file_path); + string absolute_to_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, + name, to_file_path); + + if (File.Exists (absolute_file_path)) + event_entry += "
" + file_path + "
"; + else + event_entry += "
" + file_path + "
"; + + if (File.Exists (absolute_to_file_path)) + event_entry += "" + to_file_path + "
"; + else + event_entry += to_file_path + ""; + + i++; + } + } } event_entry += ""; diff --git a/data/html/event-log.html b/data/html/event-log.html index 0f6877a9..158ea70f 100644 --- a/data/html/event-log.html +++ b/data/html/event-log.html @@ -18,9 +18,13 @@ } small { - font-size: ; - color: ; - } + font-size: ; + color: ; + } + + .moved-arrow { + color: ; + } .day-entry-header { font-size: ;