diff --git a/TGServerService/Repository.cs b/TGServerService/Repository.cs index 598d148a2b..3f7d730435 100644 --- a/TGServerService/Repository.cs +++ b/TGServerService/Repository.cs @@ -318,6 +318,7 @@ namespace TGServerService }; Commands.Checkout(Repo, sha, Opts); var res = ResetNoLock(null); + UpdateSubmodules(); SendMessage("REPO: Checkout complete!", ChatMessageType.DeveloperInfo); TGServerService.WriteInfo("Repo checked out " + sha, TGServerService.EventID.RepoCheckout); return res; @@ -375,11 +376,12 @@ namespace TGServerService }; fos.OnTransferProgress += HandleTransferProgress; Commands.Fetch(Repo, R.Name, refSpecs, fos, logMessage); - + var originBranch = Repo.Head.TrackedBranch; if (reset) { var error = ResetNoLock(Repo.Head.TrackedBranch); + UpdateSubmodules(); if (error != null) throw new Exception(error); DeletePRList(); @@ -389,6 +391,7 @@ namespace TGServerService var res = MergeBranch(originBranch.FriendlyName); if (res != null) throw new Exception(res); + UpdateSubmodules(); TGServerService.WriteInfo("Repo merge updated to " + originBranch.Tip.Sha, TGServerService.EventID.RepoMergeUpdate); return null; } @@ -401,6 +404,35 @@ namespace TGServerService } } + private void UpdateSubmodules() + { + var suo = new SubmoduleUpdateOptions + { + Init = true + }; + foreach (var I in Repo.Submodules) + try + { + Repo.Submodules.Update(I.Name, suo); + } + catch(Exception e) + { + //workaround for https://github.com/libgit2/libgit2/issues/3820 + //kill off the modules/ folder in .git and try again + try + { + Program.DeleteDirectory(String.Format("{0}/.git/modules/{1}", RepoPath, I.Path)); + } + catch { + throw e; + } + Repo.Submodules.Update(I.Name, suo); + var msg = String.Format("I had to reclone submodule {0}. If this is happening a lot find a better hack or fix https://github.com/libgit2/libgit2/issues/3820!", I.Name); + SendMessage(String.Format("REPO: {0}", msg), ChatMessageType.DeveloperInfo); + TGServerService.WriteWarning(msg, TGServerService.EventID.SubmoduleReclone); + } + } + string CreateBackup() { try @@ -568,6 +600,16 @@ namespace TGServerService //so we'll know if this fails var Result = MergeBranch(LocalBranchName); + if (Result == null) + try + { + UpdateSubmodules(); + } + catch (Exception e) + { + Result = e.ToString(); + } + if (Result == null) { TGServerService.WriteInfo(String.Format("Merged pull request #{0}", PRNumber), TGServerService.EventID.RepoPRMerge); diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index 7cbc5fb224..1f3a5d76ea 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -75,6 +75,7 @@ namespace TGServerService ServerUpdateApplied = 6300, ChatBroadcastFail = 6400, IRCLogModes = 6500, + SubmoduleReclone = 6600, } static TGServerService ActiveService; //So everyone else can write to our eventlog