[repo] Handle cloning empty repos well
This commit is contained in:
parent
fbc87d7449
commit
2946c9d49b
|
@ -85,6 +85,8 @@ namespace SparkleLib {
|
||||||
CurrentHash = GetCurrentHash ();
|
CurrentHash = GetCurrentHash ();
|
||||||
Domain = GetDomain (RemoteOriginUrl);
|
Domain = GetDomain (RemoteOriginUrl);
|
||||||
|
|
||||||
|
if (CurrentHash == null)
|
||||||
|
CreateInitialCommit ();
|
||||||
|
|
||||||
HasChanged = false;
|
HasChanged = false;
|
||||||
|
|
||||||
|
@ -128,6 +130,9 @@ namespace SparkleLib {
|
||||||
// since SparkleShare was stopped
|
// since SparkleShare was stopped
|
||||||
AddCommitAndPush ();
|
AddCommitAndPush ();
|
||||||
|
|
||||||
|
if (CurrentHash == null)
|
||||||
|
CurrentHash = GetCurrentHash ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Idling...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Idling...");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -409,7 +414,7 @@ namespace SparkleLib {
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
|
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
|
||||||
|
|
||||||
Process.StartInfo.Arguments = "push";
|
Process.StartInfo.Arguments = "push origin master";
|
||||||
Process.Start ();
|
Process.Start ();
|
||||||
Process.WaitForExit ();
|
Process.WaitForExit ();
|
||||||
|
|
||||||
|
@ -466,6 +471,9 @@ namespace SparkleLib {
|
||||||
public string GetDomain (string url)
|
public string GetDomain (string url)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (RemoteOriginUrl.Equals (""))
|
||||||
|
return "";
|
||||||
|
|
||||||
string domain = url.Substring (RemoteOriginUrl.IndexOf ("@") + 1);
|
string domain = url.Substring (RemoteOriginUrl.IndexOf ("@") + 1);
|
||||||
|
|
||||||
if (domain.IndexOf (":") > -1)
|
if (domain.IndexOf (":") > -1)
|
||||||
|
@ -482,19 +490,25 @@ namespace SparkleLib {
|
||||||
public string GetCurrentHash ()
|
public string GetCurrentHash ()
|
||||||
{
|
{
|
||||||
|
|
||||||
string current_hash;
|
Process process = new Process () {
|
||||||
|
EnableRaisingEvents = true
|
||||||
|
};
|
||||||
|
|
||||||
Process process = new Process ();
|
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
process.StartInfo.UseShellExecute = false;
|
process.StartInfo.UseShellExecute = false;
|
||||||
process.StartInfo.FileName = "git";
|
process.StartInfo.FileName = "git";
|
||||||
process.StartInfo.WorkingDirectory = LocalPath;
|
process.StartInfo.WorkingDirectory = LocalPath;
|
||||||
process.StartInfo.Arguments = "rev-list --max-count=1 HEAD";
|
process.StartInfo.Arguments = "rev-list --max-count=1 HEAD";
|
||||||
|
|
||||||
process.Start ();
|
process.Start ();
|
||||||
|
process.WaitForExit ();
|
||||||
|
|
||||||
current_hash = process.StandardOutput.ReadToEnd ().Trim ();
|
string current_hash = process.StandardOutput.ReadToEnd ().Trim ();
|
||||||
|
|
||||||
return current_hash;
|
if (process.ExitCode != 0)
|
||||||
|
return null;
|
||||||
|
else
|
||||||
|
return current_hash;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,6 +565,18 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Create a first commit in case the user has cloned
|
||||||
|
// an empty repository
|
||||||
|
private void CreateInitialCommit ()
|
||||||
|
{
|
||||||
|
|
||||||
|
TextWriter writer = new StreamWriter (Path.Combine (LocalPath, "SparkleShare.txt"));
|
||||||
|
writer.WriteLine (":)");
|
||||||
|
writer.Close ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Gets the url of the remote repo, example: "ssh://git@git.gnome.org/project"
|
// Gets the url of the remote repo, example: "ssh://git@git.gnome.org/project"
|
||||||
public string GetRemoteOriginUrl ()
|
public string GetRemoteOriginUrl ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -295,6 +295,9 @@ namespace SparkleShare {
|
||||||
public void ShowState ()
|
public void ShowState ()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (SyncingReposCount < 0)
|
||||||
|
SyncingReposCount = 0;
|
||||||
|
|
||||||
if (SyncingReposCount > 0)
|
if (SyncingReposCount > 0)
|
||||||
SetSyncingState ();
|
SetSyncingState ();
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue