[repo] Handle cloning empty repos well

This commit is contained in:
Hylke Bons 2010-08-08 20:16:48 +01:00
parent 9513b727e8
commit 6357c95bcb
2 changed files with 40 additions and 11 deletions

View file

@ -85,6 +85,8 @@ namespace SparkleLib {
CurrentHash = GetCurrentHash ();
Domain = GetDomain (RemoteOriginUrl);
if (CurrentHash == null)
CreateInitialCommit ();
HasChanged = false;
@ -128,6 +130,9 @@ namespace SparkleLib {
// since SparkleShare was stopped
AddCommitAndPush ();
if (CurrentHash == null)
CurrentHash = GetCurrentHash ();
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Idling...");
}
@ -409,7 +414,7 @@ namespace SparkleLib {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Pushing changes...");
Process.StartInfo.Arguments = "push";
Process.StartInfo.Arguments = "push origin master";
Process.Start ();
Process.WaitForExit ();
@ -466,6 +471,9 @@ namespace SparkleLib {
public string GetDomain (string url)
{
if (RemoteOriginUrl.Equals (""))
return "";
string domain = url.Substring (RemoteOriginUrl.IndexOf ("@") + 1);
if (domain.IndexOf (":") > -1)
@ -482,19 +490,25 @@ namespace SparkleLib {
public string GetCurrentHash ()
{
string current_hash;
Process process = new Process () {
EnableRaisingEvents = true
};
Process process = new Process ();
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "git";
process.StartInfo.WorkingDirectory = LocalPath;
process.StartInfo.Arguments = "rev-list --max-count=1 HEAD";
process.Start ();
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "git";
process.StartInfo.WorkingDirectory = LocalPath;
process.StartInfo.Arguments = "rev-list --max-count=1 HEAD";
current_hash = process.StandardOutput.ReadToEnd ().Trim ();
return current_hash;
process.Start ();
process.WaitForExit ();
string current_hash = process.StandardOutput.ReadToEnd ().Trim ();
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"
public string GetRemoteOriginUrl ()
{

View file

@ -295,6 +295,9 @@ namespace SparkleShare {
public void ShowState ()
{
if (SyncingReposCount < 0)
SyncingReposCount = 0;
if (SyncingReposCount > 0)
SetSyncingState ();
else