From 4018bfc19c8f85f289f3038b5b65ba638eaeff2e Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 2 Apr 2016 10:59:36 +0100 Subject: [PATCH] git: Prefer remote SparkleShare branch if it exists --- Sparkles/Git/GitFetcher.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sparkles/Git/GitFetcher.cs b/Sparkles/Git/GitFetcher.cs index 483c4e56..08c34d08 100644 --- a/Sparkles/Git/GitFetcher.cs +++ b/Sparkles/Git/GitFetcher.cs @@ -233,8 +233,18 @@ namespace Sparkles.Git { public override void Complete () { if (!IsFetchedRepoEmpty) { - GitCommand git = new GitCommand (TargetFolder, "checkout --quiet HEAD"); - git.StartAndWaitForExit (); + string branch = "HEAD"; + string prefered_branch = "SparkleShare"; + + // Prefer the "SparkleShare" branch if it exists + var git_show_ref = new GitCommand (TargetFolder, "show-ref --verify --quiet refs/heads/" + prefered_branch); + git_show_ref.StartAndWaitForExit (); + + if (git_show_ref.ExitCode == 0) + branch = prefered_branch; + + var git_checkout = new GitCommand (TargetFolder, "checkout --quiet " + branch); + git_checkout.StartAndWaitForExit (); } base.Complete ();