repo git: refactor andf fix Rebase and FormatCommitMessage methods
This commit is contained in:
parent
62c7a797f9
commit
1c8cffd178
|
@ -461,15 +461,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 ();
|
||||||
|
@ -527,9 +533,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,9 +567,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")) {
|
||||||
|
|
||||||
|
@ -581,8 +581,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")) {
|
||||||
|
|
||||||
|
@ -591,24 +589,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)
|
||||||
{
|
{
|
||||||
|
@ -901,70 +886,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> ();
|
|
||||||
List<string> Removed = new List<string> ();
|
|
||||||
string file_name = "";
|
|
||||||
string message = "";
|
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 += "+";
|
||||||
}
|
}
|
||||||
|
|
||||||
int count = 0;
|
string path = line.Substring (3).Trim ("\"".ToCharArray ());
|
||||||
int max_count = 20;
|
message += " ‘" + EnsureSpecialCharacters (path) + "’\n";
|
||||||
|
}
|
||||||
string n = Environment.NewLine;
|
|
||||||
|
|
||||||
foreach (string added in Added) {
|
|
||||||
file_name = added.Trim ("\"".ToCharArray ());
|
|
||||||
message += "+ ‘" + file_name + "’" + n;
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
if (count == max_count)
|
if (count == 10) {
|
||||||
return message + "...";
|
message += "...\n";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string modified in Modified) {
|
git_status.WaitForExit ();
|
||||||
file_name = modified.Trim ("\"".ToCharArray ());
|
message = message.Replace ("\"", "\\\"");
|
||||||
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