Add some more events to SparkleRepo
This commit is contained in:
parent
4dcd9fc99b
commit
3191ea70e0
|
@ -49,6 +49,15 @@ namespace SparkleShare {
|
||||||
public delegate void AddedEventHandler (object o, SparkleEventArgs args);
|
public delegate void AddedEventHandler (object o, SparkleEventArgs args);
|
||||||
public event AddedEventHandler Added;
|
public event AddedEventHandler Added;
|
||||||
|
|
||||||
|
public delegate void CommitedEventHandler (object o, SparkleEventArgs args);
|
||||||
|
public event CommitedEventHandler Commited;
|
||||||
|
|
||||||
|
public delegate void PushedEventHandler (object o, SparkleEventArgs args);
|
||||||
|
public event PushedEventHandler Pushed;
|
||||||
|
|
||||||
|
public delegate void FetchedEventHandler (object o, SparkleEventArgs args);
|
||||||
|
public event FetchedEventHandler Fetched;
|
||||||
|
|
||||||
|
|
||||||
public static string _ (string s)
|
public static string _ (string s)
|
||||||
{
|
{
|
||||||
|
@ -74,6 +83,7 @@ namespace SparkleShare {
|
||||||
CurrentHash = GetCurrentHash ();
|
CurrentHash = GetCurrentHash ();
|
||||||
Domain = GetDomain (RemoteOriginUrl);
|
Domain = GetDomain (RemoteOriginUrl);
|
||||||
|
|
||||||
|
|
||||||
// Watch the repository's folder
|
// Watch the repository's folder
|
||||||
Watcher = new FileSystemWatcher (LocalPath) {
|
Watcher = new FileSystemWatcher (LocalPath) {
|
||||||
IncludeSubdirectories = true,
|
IncludeSubdirectories = true,
|
||||||
|
@ -85,6 +95,7 @@ namespace SparkleShare {
|
||||||
Watcher.Created += new FileSystemEventHandler (OnFileActivity);
|
Watcher.Created += new FileSystemEventHandler (OnFileActivity);
|
||||||
Watcher.Deleted += new FileSystemEventHandler (OnFileActivity);
|
Watcher.Deleted += new FileSystemEventHandler (OnFileActivity);
|
||||||
|
|
||||||
|
|
||||||
// Fetch remote changes every 20 seconds
|
// Fetch remote changes every 20 seconds
|
||||||
FetchTimer = new Timer () {
|
FetchTimer = new Timer () {
|
||||||
Interval = 20000
|
Interval = 20000
|
||||||
|
@ -94,6 +105,7 @@ namespace SparkleShare {
|
||||||
Fetch ();
|
Fetch ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Keep a buffer that checks if there are changes and
|
// Keep a buffer that checks if there are changes and
|
||||||
// whether they have settled
|
// whether they have settled
|
||||||
BufferTimer = new Timer () {
|
BufferTimer = new Timer () {
|
||||||
|
@ -104,9 +116,11 @@ namespace SparkleShare {
|
||||||
CheckForChanges ();
|
CheckForChanges ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
FetchTimer.Start ();
|
FetchTimer.Start ();
|
||||||
BufferTimer.Start ();
|
BufferTimer.Start ();
|
||||||
|
|
||||||
|
|
||||||
// Add everything that changed
|
// Add everything that changed
|
||||||
// since SparkleShare was stopped
|
// since SparkleShare was stopped
|
||||||
AddCommitAndPush ();
|
AddCommitAndPush ();
|
||||||
|
@ -116,112 +130,6 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string GetDomain (string url)
|
|
||||||
{
|
|
||||||
|
|
||||||
string domain;
|
|
||||||
|
|
||||||
domain = url.Substring (RemoteOriginUrl.IndexOf ("@") + 1);
|
|
||||||
if (domain.IndexOf (":") > -1)
|
|
||||||
domain = domain.Substring (0, domain.IndexOf (":"));
|
|
||||||
else
|
|
||||||
domain = domain.Substring (0, domain.IndexOf ("/"));
|
|
||||||
|
|
||||||
return domain;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Gets hash of the current commit
|
|
||||||
public string GetCurrentHash ()
|
|
||||||
{
|
|
||||||
|
|
||||||
string current_hash;
|
|
||||||
|
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
|
||||||
process.StartInfo.UseShellExecute = false;
|
|
||||||
process.StartInfo.FileName = "git";
|
|
||||||
process.StartInfo.Arguments = "rev-list --max-count=1 HEAD";
|
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
current_hash = process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
return current_hash;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Gets the user's name, example: "User Name"
|
|
||||||
public string GetUserName ()
|
|
||||||
{
|
|
||||||
|
|
||||||
string user_name;
|
|
||||||
|
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
|
||||||
process.StartInfo.UseShellExecute = false;
|
|
||||||
process.StartInfo.FileName = "git";
|
|
||||||
process.StartInfo.Arguments = "config --get user.name";
|
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
user_name = process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
if (user_name.Equals ("")) {
|
|
||||||
|
|
||||||
UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName);
|
|
||||||
|
|
||||||
if (unix_user_info.RealName.Equals (""))
|
|
||||||
user_name = "???";
|
|
||||||
else
|
|
||||||
user_name = unix_user_info.RealName;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return user_name;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Gets the user's email, example: "person@gnome.org"
|
|
||||||
public string GetUserEmail ()
|
|
||||||
{
|
|
||||||
|
|
||||||
string user_email;
|
|
||||||
|
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.UseShellExecute = false;
|
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
|
||||||
process.StartInfo.FileName = "git";
|
|
||||||
process.StartInfo.Arguments = "config --get user.email";
|
|
||||||
process.Start ();
|
|
||||||
user_email = process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
return user_email;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Gets the url of the remote repo, example: "ssh://git@git.gnome.org/project"
|
|
||||||
public string GetRemoteOriginUrl ()
|
|
||||||
{
|
|
||||||
|
|
||||||
string remote_origin_url;
|
|
||||||
|
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.UseShellExecute = false;
|
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
|
||||||
process.StartInfo.FileName = "git";
|
|
||||||
process.StartInfo.Arguments = "config --get remote.origin.url";
|
|
||||||
process.Start ();
|
|
||||||
|
|
||||||
remote_origin_url = process.StandardOutput.ReadToEnd ().Trim ();
|
|
||||||
|
|
||||||
return remote_origin_url;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void CheckForChanges ()
|
private void CheckForChanges ()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -316,7 +224,8 @@ namespace SparkleShare {
|
||||||
// SparkleUI.NotificationIcon.SetSyncingState ();
|
// SparkleUI.NotificationIcon.SetSyncingState ();
|
||||||
// SparkleUI.NotificationIcon.SetIdleState ();
|
// SparkleUI.NotificationIcon.SetIdleState ();
|
||||||
|
|
||||||
SparkleEventArgs args = new SparkleEventArgs ("add test");
|
SparkleEventArgs args = new SparkleEventArgs ("Added");
|
||||||
|
|
||||||
if (Added != null)
|
if (Added != null)
|
||||||
Added (this, args);
|
Added (this, args);
|
||||||
|
|
||||||
|
@ -333,6 +242,11 @@ namespace SparkleShare {
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
|
|
||||||
|
SparkleEventArgs args = new SparkleEventArgs ("Commited");
|
||||||
|
|
||||||
|
if (Commited != null)
|
||||||
|
Commited (this, args);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -356,6 +270,11 @@ namespace SparkleShare {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
|
||||||
|
|
||||||
|
SparkleEventArgs args = new SparkleEventArgs ("Fetched");
|
||||||
|
|
||||||
|
if (Fetched != null)
|
||||||
|
Fetched (this, args);
|
||||||
|
|
||||||
if (!Output.Contains ("up to date"))
|
if (!Output.Contains ("up to date"))
|
||||||
Rebase ();
|
Rebase ();
|
||||||
|
|
||||||
|
@ -369,6 +288,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Merges the fetched changes
|
// Merges the fetched changes
|
||||||
public void Rebase ()
|
public void Rebase ()
|
||||||
{
|
{
|
||||||
|
@ -495,6 +415,7 @@ namespace SparkleShare {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Pushes the changes to the remote repo
|
// Pushes the changes to the remote repo
|
||||||
public void Push ()
|
public void Push ()
|
||||||
{
|
{
|
||||||
|
@ -507,6 +428,11 @@ namespace SparkleShare {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes pushed.");
|
||||||
|
|
||||||
|
SparkleEventArgs args = new SparkleEventArgs ("Pushed");
|
||||||
|
|
||||||
|
if (Pushed != null)
|
||||||
|
Pushed (this, args);
|
||||||
|
|
||||||
// SparkleUI.NotificationIcon.SetIdleState ();
|
// SparkleUI.NotificationIcon.SetIdleState ();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -537,6 +463,112 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string GetDomain (string url)
|
||||||
|
{
|
||||||
|
|
||||||
|
string domain;
|
||||||
|
|
||||||
|
domain = url.Substring (RemoteOriginUrl.IndexOf ("@") + 1);
|
||||||
|
if (domain.IndexOf (":") > -1)
|
||||||
|
domain = domain.Substring (0, domain.IndexOf (":"));
|
||||||
|
else
|
||||||
|
domain = domain.Substring (0, domain.IndexOf ("/"));
|
||||||
|
|
||||||
|
return domain;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets hash of the current commit
|
||||||
|
public string GetCurrentHash ()
|
||||||
|
{
|
||||||
|
|
||||||
|
string current_hash;
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.Arguments = "rev-list --max-count=1 HEAD";
|
||||||
|
process.Start ();
|
||||||
|
|
||||||
|
current_hash = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
|
return current_hash;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the user's name, example: "User Name"
|
||||||
|
public string GetUserName ()
|
||||||
|
{
|
||||||
|
|
||||||
|
string user_name;
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.Arguments = "config --get user.name";
|
||||||
|
process.Start ();
|
||||||
|
|
||||||
|
user_name = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
|
if (user_name.Equals ("")) {
|
||||||
|
|
||||||
|
UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName);
|
||||||
|
|
||||||
|
if (unix_user_info.RealName.Equals (""))
|
||||||
|
user_name = "???";
|
||||||
|
else
|
||||||
|
user_name = unix_user_info.RealName;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return user_name;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the user's email, example: "person@gnome.org"
|
||||||
|
public string GetUserEmail ()
|
||||||
|
{
|
||||||
|
|
||||||
|
string user_email;
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.Arguments = "config --get user.email";
|
||||||
|
process.Start ();
|
||||||
|
user_email = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
|
return user_email;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Gets the url of the remote repo, example: "ssh://git@git.gnome.org/project"
|
||||||
|
public string GetRemoteOriginUrl ()
|
||||||
|
{
|
||||||
|
|
||||||
|
string remote_origin_url;
|
||||||
|
|
||||||
|
Process process = new Process ();
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
process.StartInfo.FileName = "git";
|
||||||
|
process.StartInfo.Arguments = "config --get remote.origin.url";
|
||||||
|
process.Start ();
|
||||||
|
|
||||||
|
remote_origin_url = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
|
return remote_origin_url;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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 ()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue