repo git: refactor andf fix Rebase and FormatCommitMessage methods
This commit is contained in:
parent
f75bdb5859
commit
e02fbdbc2c
|
@ -432,15 +432,21 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "rebase FETCH_HEAD");
|
SparkleGit git = new SparkleGit (LocalPath, "rebase FETCH_HEAD");
|
||||||
git.StartInfo.RedirectStandardOutput = false;
|
git.StartInfo.RedirectStandardOutput = false;
|
||||||
|
|
||||||
git.Start ();
|
git.Start ();
|
||||||
git.WaitForExit ();
|
git.WaitForExit ();
|
||||||
|
|
||||||
if (git.ExitCode != 0) {
|
if (git.ExitCode != 0) {
|
||||||
SparkleHelpers.DebugInfo ("Git", Name + " | Conflict detected, trying to get out...");
|
SparkleHelpers.DebugInfo ("Git", Name + " | Conflict detected, trying to get out...");
|
||||||
|
|
||||||
while (HasLocalChanges)
|
while (HasLocalChanges) {
|
||||||
ResolveConflict ();
|
ResolveConflict ();
|
||||||
|
Add ();
|
||||||
|
|
||||||
|
git = new SparkleGit (LocalPath, "rebase --continue");
|
||||||
|
git.StartInfo.RedirectStandardOutput = false;
|
||||||
|
git.Start ();
|
||||||
|
git.WaitForExit ();
|
||||||
|
}
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", Name + " | Conflict resolved");
|
SparkleHelpers.DebugInfo ("Git", Name + " | Conflict resolved");
|
||||||
OnConflictResolved ();
|
OnConflictResolved ();
|
||||||
|
@ -498,9 +504,6 @@ namespace SparkleLib.Git {
|
||||||
|
|
||||||
File.SetAttributes (Path.Combine (LocalPath, conflicting_path), FileAttributes.Hidden);
|
File.SetAttributes (Path.Combine (LocalPath, conflicting_path), FileAttributes.Hidden);
|
||||||
|
|
||||||
Add ();
|
|
||||||
RebaseContinue ();
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,9 +538,6 @@ namespace SparkleLib.Git {
|
||||||
git_ours.Start ();
|
git_ours.Start ();
|
||||||
git_ours.WaitForExit ();
|
git_ours.WaitForExit ();
|
||||||
|
|
||||||
Add ();
|
|
||||||
RebaseContinue ();
|
|
||||||
|
|
||||||
// The local version has been modified, but the server version was removed
|
// The local version has been modified, but the server version was removed
|
||||||
} else if (line.StartsWith ("DU")) {
|
} else if (line.StartsWith ("DU")) {
|
||||||
|
|
||||||
|
@ -552,8 +552,6 @@ namespace SparkleLib.Git {
|
||||||
git_add.Start ();
|
git_add.Start ();
|
||||||
git_add.WaitForExit ();
|
git_add.WaitForExit ();
|
||||||
|
|
||||||
RebaseContinue ();
|
|
||||||
|
|
||||||
// The server version has been modified, but the local version was removed
|
// The server version has been modified, but the local version was removed
|
||||||
} else if (line.StartsWith ("UD")) {
|
} else if (line.StartsWith ("UD")) {
|
||||||
|
|
||||||
|
@ -562,24 +560,11 @@ namespace SparkleLib.Git {
|
||||||
SparkleGit git_rebase_skip = new SparkleGit (LocalPath, "rebase --skip");
|
SparkleGit git_rebase_skip = new SparkleGit (LocalPath, "rebase --skip");
|
||||||
git_rebase_skip.Start ();
|
git_rebase_skip.Start ();
|
||||||
git_rebase_skip.WaitForExit ();
|
git_rebase_skip.WaitForExit ();
|
||||||
|
|
||||||
// New local files
|
|
||||||
} else {
|
|
||||||
Add ();
|
|
||||||
RebaseContinue ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void RebaseContinue ()
|
|
||||||
{
|
|
||||||
SparkleGit git = new SparkleGit (LocalPath, "rebase --continue");
|
|
||||||
git.Start ();
|
|
||||||
git.WaitForExit ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Returns a list of the latest change sets
|
// Returns a list of the latest change sets
|
||||||
public override List<SparkleChangeSet> GetChangeSets (int count)
|
public override List<SparkleChangeSet> GetChangeSets (int count)
|
||||||
{
|
{
|
||||||
|
@ -861,70 +846,50 @@ namespace SparkleLib.Git {
|
||||||
// Creates a pretty commit message based on what has changed
|
// Creates a pretty commit message based on what has changed
|
||||||
private string FormatCommitMessage ()
|
private string FormatCommitMessage ()
|
||||||
{
|
{
|
||||||
List<string> Added = new List<string> ();
|
int count = 0;
|
||||||
List<string> Modified = new List<string> ();
|
string message = "";
|
||||||
List<string> Removed = new List<string> ();
|
|
||||||
string file_name = "";
|
|
||||||
string message = "";
|
|
||||||
|
|
||||||
SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain");
|
SparkleGit git_status = new SparkleGit (LocalPath, "status --porcelain");
|
||||||
git_status.Start ();
|
git_status.Start ();
|
||||||
|
|
||||||
// Reading the standard output HAS to go before
|
while (!git_status.StandardOutput.EndOfStream) {
|
||||||
// WaitForExit, or it will hang forever on output > 4096 bytes
|
string line = git_status.StandardOutput.ReadLine ();
|
||||||
string output = git_status.StandardOutput.ReadToEnd ().Trim ("\n".ToCharArray ());
|
|
||||||
git_status.WaitForExit ();
|
|
||||||
|
|
||||||
string [] lines = output.Split ("\n".ToCharArray ());
|
if (line.EndsWith (".empty") || line.EndsWith (".empty\""))
|
||||||
foreach (string line in lines) {
|
|
||||||
if (line.EndsWith (".empty"))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (line.StartsWith ("A"))
|
if (line.StartsWith ("R")) {
|
||||||
Added.Add (line.Substring (3));
|
string path = line.Substring (3, line.IndexOf (" -> ") - 3).Trim ("\"".ToCharArray ());
|
||||||
else if (line.StartsWith ("M"))
|
string moved_to_path = line.Substring (line.IndexOf (" -> ") + 4).Trim ("\"".ToCharArray ());
|
||||||
Modified.Add (line.Substring (3));
|
|
||||||
else if (line.StartsWith ("D"))
|
message += "- ‘" + EnsureSpecialCharacters (path) + "’\n";
|
||||||
Removed.Add (line.Substring (3));
|
message += "+ ‘" + EnsureSpecialCharacters (moved_to_path) + "’\n";
|
||||||
else if (line.StartsWith ("R")) {
|
|
||||||
Removed.Add (line.Substring (3, (line.IndexOf (" -> ") - 3)));
|
} else {
|
||||||
Added.Add (line.Substring (line.IndexOf (" -> ") + 4));
|
if (line.StartsWith ("M")) {
|
||||||
|
message += "/";
|
||||||
|
|
||||||
|
} else if (line.StartsWith ("D")) {
|
||||||
|
message += "-";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
message += "+";
|
||||||
|
}
|
||||||
|
|
||||||
|
string path = line.Substring (3).Trim ("\"".ToCharArray ());
|
||||||
|
message += " ‘" + EnsureSpecialCharacters (path) + "’\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
count++;
|
||||||
|
if (count == 10) {
|
||||||
|
message += "...\n";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = 0;
|
git_status.WaitForExit ();
|
||||||
int max_count = 20;
|
message = message.Replace ("\"", "\\\"");
|
||||||
|
|
||||||
string n = Environment.NewLine;
|
|
||||||
|
|
||||||
foreach (string added in Added) {
|
|
||||||
file_name = added.Trim ("\"".ToCharArray ());
|
|
||||||
message += "+ ‘" + file_name + "’" + n;
|
|
||||||
|
|
||||||
count++;
|
|
||||||
if (count == max_count)
|
|
||||||
return message + "...";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string modified in Modified) {
|
|
||||||
file_name = modified.Trim ("\"".ToCharArray ());
|
|
||||||
message += "/ ‘" + file_name + "’" + n;
|
|
||||||
|
|
||||||
count++;
|
|
||||||
if (count == max_count)
|
|
||||||
return message + "...";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string removed in Removed) {
|
|
||||||
file_name = removed.Trim ("\"".ToCharArray ());
|
|
||||||
message += "- ‘" + file_name + "’" + n;
|
|
||||||
|
|
||||||
count++;
|
|
||||||
if (count == max_count)
|
|
||||||
return message + "..." + n;
|
|
||||||
}
|
|
||||||
|
|
||||||
message = message.Replace ("\"", "");
|
|
||||||
return message.TrimEnd ();
|
return message.TrimEnd ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue