[repo] redo commit message formatting
This commit is contained in:
parent
ab60200071
commit
143f991aa3
|
@ -112,6 +112,7 @@ namespace SparkleLib {
|
||||||
Watcher.Changed += new FileSystemEventHandler (OnFileActivity);
|
Watcher.Changed += new FileSystemEventHandler (OnFileActivity);
|
||||||
Watcher.Created += new FileSystemEventHandler (OnFileActivity);
|
Watcher.Created += new FileSystemEventHandler (OnFileActivity);
|
||||||
Watcher.Deleted += new FileSystemEventHandler (OnFileActivity);
|
Watcher.Deleted += new FileSystemEventHandler (OnFileActivity);
|
||||||
|
Watcher.Renamed += new RenamedEventHandler (OnFileActivity);
|
||||||
|
|
||||||
|
|
||||||
// Fetch remote changes every minute
|
// Fetch remote changes every minute
|
||||||
|
@ -221,7 +222,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
WatcherChangeTypes wct = fse_args.ChangeType;
|
WatcherChangeTypes wct = fse_args.ChangeType;
|
||||||
|
|
||||||
if (!ShouldIgnore (fse_args.Name)) {
|
if (!ShouldIgnore (fse_args.FullPath)) {
|
||||||
|
|
||||||
// Only fire the event if the timer has been stopped.
|
// Only fire the event if the timer has been stopped.
|
||||||
// This prevents multiple events from being raised whilst "buffering".
|
// This prevents multiple events from being raised whilst "buffering".
|
||||||
|
@ -264,7 +265,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
string message = FormatCommitMessage ();
|
string message = FormatCommitMessage ();
|
||||||
|
|
||||||
if (!message.Equals ("")) {
|
if (message != null) {
|
||||||
|
|
||||||
Commit (message);
|
Commit (message);
|
||||||
CheckForRemoteChanges ();
|
CheckForRemoteChanges ();
|
||||||
|
@ -313,6 +314,15 @@ namespace SparkleLib {
|
||||||
public void Commit (string message)
|
public void Commit (string message)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Process.StartInfo.Arguments = "status --porcelain";
|
||||||
|
Process.Start ();
|
||||||
|
Process.WaitForExit ();
|
||||||
|
|
||||||
|
if (Process.StandardOutput.ReadToEnd ().TrimEnd ("\n".ToCharArray ()).Equals ("")) {
|
||||||
|
Console.WriteLine ("NO CHANGES!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message);
|
SparkleHelpers.DebugInfo ("Commit", "[" + Name + "] " + message);
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "commit -m \"" + message + "\"";
|
Process.StartInfo.Arguments = "commit -m \"" + message + "\"";
|
||||||
|
@ -527,22 +537,17 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Ignores repos, dotfiles, swap files and the like.
|
// Ignores repos, dotfiles, swap files and the like
|
||||||
private bool ShouldIgnore (string file_name)
|
private bool ShouldIgnore (string file_path)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (file_name [0].Equals (".") ||
|
if (file_path.EndsWith (".lock") ||
|
||||||
file_name.Contains (".lock") ||
|
file_path.Contains (".git") ||
|
||||||
file_name.Contains (".git") ||
|
file_path.Contains ("/.") ||
|
||||||
file_name.Contains ("/.") ||
|
file_path.EndsWith (".swp") ||
|
||||||
Directory.Exists (LocalPath + file_name)) {
|
Directory.Exists (LocalPath + file_path)) {
|
||||||
|
|
||||||
return true; // Yes, ignore it.
|
return true; // Yes, ignore it
|
||||||
|
|
||||||
} else if (file_name.Length > 3 &&
|
|
||||||
file_name.Substring (file_name.Length - 4).Equals (".swp")) {
|
|
||||||
|
|
||||||
return true; // Yes, ignore it.
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -714,90 +719,62 @@ namespace SparkleLib {
|
||||||
private string FormatCommitMessage ()
|
private string FormatCommitMessage ()
|
||||||
{
|
{
|
||||||
|
|
||||||
bool DoneAddCommit = false;
|
Process.StartInfo.Arguments = "status --porcelain";
|
||||||
bool DoneEditCommit = false;
|
|
||||||
bool DoneRenameCommit = false;
|
|
||||||
bool DoneDeleteCommit = false;
|
|
||||||
int FilesAdded = 0;
|
|
||||||
int FilesEdited = 0;
|
|
||||||
int FilesRenamed = 0;
|
|
||||||
int FilesDeleted = 0;
|
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "status";
|
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
string output = Process.StandardOutput.ReadToEnd ();
|
|
||||||
|
|
||||||
foreach (string line in Regex.Split (output, "\n")) {
|
string output = Process.StandardOutput.ReadToEnd ().TrimEnd ();
|
||||||
if (line.IndexOf ("new file:") > -1)
|
string [] lines = Regex.Split (output, "\n");
|
||||||
FilesAdded++;
|
|
||||||
if (line.IndexOf ("modified:") > -1)
|
|
||||||
FilesEdited++;
|
|
||||||
if (line.IndexOf ("renamed:") > -1)
|
|
||||||
FilesRenamed++;
|
|
||||||
if (line.IndexOf ("deleted:") > -1)
|
|
||||||
FilesDeleted++;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (string line in Regex.Split (output, "\n")) {
|
string file_name;
|
||||||
|
string file_action;
|
||||||
|
string message = null;
|
||||||
|
|
||||||
|
foreach (string line in lines) {
|
||||||
|
|
||||||
|
if (line.StartsWith ("A")) {
|
||||||
|
|
||||||
|
file_action = "added";
|
||||||
|
file_name = line.Substring (3);
|
||||||
|
message = file_action + " ‘" + file_name + "’";
|
||||||
|
|
||||||
// Format message for when files are added,
|
|
||||||
// example: "added 'file' and 3 more."
|
|
||||||
if (line.IndexOf ("new file:") > -1 && !DoneAddCommit) {
|
|
||||||
DoneAddCommit = true;
|
|
||||||
if (FilesAdded > 1)
|
|
||||||
return "added ‘" +
|
|
||||||
line.Replace ("#\tnew file:", "").Trim () +
|
|
||||||
"’\nand " + (FilesAdded - 1) + " more.";
|
|
||||||
else
|
|
||||||
return "added ‘" +
|
|
||||||
line.Replace ("#\tnew file:", "").Trim () + "’.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format message for when files are edited,
|
if (line.StartsWith ("M")) {
|
||||||
// example: "edited 'file'."
|
|
||||||
if (line.IndexOf ("modified:") > -1 && !DoneEditCommit) {
|
file_action = "edited";
|
||||||
DoneEditCommit = true;
|
file_name = line.Substring (3);
|
||||||
if (FilesEdited > 1)
|
message = file_action + " ‘" + file_name + "’";
|
||||||
return "edited ‘" +
|
|
||||||
line.Replace ("#\tmodified:", "").Trim () +
|
|
||||||
"’\nand " + (FilesEdited - 1) + " more.";
|
|
||||||
else
|
|
||||||
return "edited ‘" +
|
|
||||||
line.Replace ("#\tmodified:", "").Trim () + "’.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format message for when files are edited,
|
if (line.StartsWith ("D")) {
|
||||||
// example: "deleted 'file'."
|
|
||||||
if (line.IndexOf ("deleted:") > -1 && !DoneDeleteCommit) {
|
file_action = "deleted";
|
||||||
DoneDeleteCommit = true;
|
file_name = line.Substring (3);
|
||||||
if (FilesDeleted > 1)
|
message = file_action + " ‘" + file_name + "’";
|
||||||
return "deleted ‘" +
|
|
||||||
line.Replace ("#\tdeleted:", "").Trim () +
|
|
||||||
"’\nand " + (FilesDeleted - 1) + " more.";
|
|
||||||
else
|
|
||||||
return "deleted ‘" +
|
|
||||||
line.Replace ("#\tdeleted:", "").Trim () + "’.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format message for when files are renamed,
|
if (line.StartsWith ("R")) {
|
||||||
// example: "renamed 'file' to 'new name'."
|
|
||||||
if (line.IndexOf ("renamed:") > -1 && !DoneRenameCommit) {
|
file_action = "renamed";
|
||||||
DoneDeleteCommit = true;
|
message = file_action + " ‘" + line.Substring (3).Replace (" -> ", "’ to\n‘") + "’";
|
||||||
if (FilesRenamed > 1)
|
|
||||||
return "renamed ‘" +
|
}
|
||||||
line.Replace ("#\trenamed:", "").Trim ().Replace
|
|
||||||
(" -> ", "’ to ‘") + "’ and " + (FilesDeleted - 1) +
|
if (line.StartsWith ("C")) {
|
||||||
" more.";
|
|
||||||
else
|
file_action = "copied";
|
||||||
return "renamed ‘" +
|
file_name = line.Substring (3);
|
||||||
line.Replace ("#\trenamed:", "").Trim ().Replace
|
|
||||||
(" -> ", "’ to ‘") + "’.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing happened:
|
if (lines.Length > 1)
|
||||||
return "";
|
message += " and " + (lines.Length - 1) + " more";
|
||||||
|
|
||||||
|
return message;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -338,7 +338,7 @@ namespace SparkleShare {
|
||||||
if (deleted_files.Children.Length > 0) {
|
if (deleted_files.Children.Length > 0) {
|
||||||
|
|
||||||
Label deleted_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
|
Label deleted_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
|
||||||
"Edited" +
|
"Deleted" +
|
||||||
"</small></span>") {
|
"</small></span>") {
|
||||||
UseMarkup=true,
|
UseMarkup=true,
|
||||||
Xalign = 0
|
Xalign = 0
|
||||||
|
|
Loading…
Reference in a new issue