From 1f100b1e3d92b07aa3318c16a42d9e7b1a5f6e83 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 12 Oct 2017 14:41:06 -0400 Subject: [PATCH 01/11] Ability to publish testmerge commits --- TGServerService/Compiler.cs | 2 +- TGServerService/Repository.cs | 32 ++++++++++++++++++++++++++------ TGServerService/ServerService.cs | 1 + 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/TGServerService/Compiler.cs b/TGServerService/Compiler.cs index 49ccfffa8f..1ec5dbd916 100644 --- a/TGServerService/Compiler.cs +++ b/TGServerService/Compiler.cs @@ -352,7 +352,7 @@ namespace TGServerService resurrectee = GetStagingDir(); var Config = new RepoConfig(false); - var deleteExcludeList = new List(); + var deleteExcludeList = new List { InterfaceDLLName }; deleteExcludeList.AddRange(Config.StaticDirectoryPaths); deleteExcludeList.AddRange(Config.DLLPaths); Program.DeleteDirectory(resurrectee, true, deleteExcludeList); diff --git a/TGServerService/Repository.cs b/TGServerService/Repository.cs index 2b6bf6a3b5..19c2111da1 100644 --- a/TGServerService/Repository.cs +++ b/TGServerService/Repository.cs @@ -14,6 +14,7 @@ namespace TGServerService partial class TGStationServer : ITGRepository, IDisposable { const string RepoPath = "Repository"; + const string RemoteTempBranchName = "___TGS3TempBranch"; const string RepoTGS3SettingsPath = RepoPath + "/TGS3.json"; const string CachedTGS3SettingsPath = "TGS3.json"; const string RepoErrorUpToDate = "Already up to date!"; @@ -745,19 +746,14 @@ namespace TGServerService File.WriteAllText(PRJobFile, rawdata); } - //public api public string MergePullRequest(int PRNumber) - { - return MergePullRequestImpl(PRNumber, false); - } - string MergePullRequestImpl(int PRNumber, bool impliedUpdate) { lock (RepoLock) { var result = LoadRepo(); if (result != null) return result; - SendMessage(String.Format("REPO: {1}erging PR #{0}...", PRNumber, impliedUpdate ? "Test m" : "M"), ChatMessageType.DeveloperInfo); + SendMessage(String.Format("REPO: Merging PR #{0}...", PRNumber), ChatMessageType.DeveloperInfo); result = ResetNoLock(null); if (result != null) return result; @@ -845,6 +841,30 @@ namespace TGServerService TGServerService.WriteError("Failed to update PR list", TGServerService.EventID.RepoPRListError); return "PR Merged, JSON update failed: " + e.ToString(); } + + if (SSHAuth()) + { + try + { + //now try and push the commit to the remote so they can be referenced + var NewB = Repo.CreateBranch(RemoteTempBranchName).CanonicalName; + + var options = new PushOptions() + { + CredentialsProvider = GenerateGitCredentials + }; + var targetRemote = Repo.Network.Remotes[SSHPushRemote]; + Repo.Network.Push(targetRemote, NewB, options); //push the branch + Repo.Network.Push(targetRemote, null, NewB, options); //delete the branch + Repo.Branches.Remove(NewB); + TGServerService.WriteInfo("Pushed reference commit: " + Repo.Head.Tip.Sha, TGServerService.EventID.ReferencePush); + } + catch (Exception e) + { + TGServerService.WriteWarning(String.Format("Failed to push reference commit: {0}. Error: {1}", Repo.Head.Tip.Sha, e.ToString()), TGServerService.EventID.ReferencePush); + } + } + } return Result; } diff --git a/TGServerService/ServerService.cs b/TGServerService/ServerService.cs index f277dfd2f9..c2adb435bc 100644 --- a/TGServerService/ServerService.cs +++ b/TGServerService/ServerService.cs @@ -85,6 +85,7 @@ namespace TGServerService StaticRead = 7300, StaticWrite = 7400, StaticDelete = 7500, + ReferencePush = 7600, } static TGServerService ActiveService; //So everyone else can write to our eventlog From a2c71ef16f6d39a5a73dbfec9050db8efbb75fef Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 16 Oct 2017 13:26:33 -0400 Subject: [PATCH 02/11] Config option and cli command --- TGCommandLine/RepoCommands.cs | 38 ++++++++++- TGServerService/App.config | 3 + .../Properties/Settings.Designer.cs | 12 ++++ TGServerService/Properties/Settings.settings | 3 + TGServerService/Repository.cs | 64 ++++++++++++------- TGServiceInterface/Repository.cs | 14 ++++ 6 files changed, 110 insertions(+), 24 deletions(-) diff --git a/TGCommandLine/RepoCommands.cs b/TGCommandLine/RepoCommands.cs index 1ad2101a4e..c76e6431c5 100644 --- a/TGCommandLine/RepoCommands.cs +++ b/TGCommandLine/RepoCommands.cs @@ -9,7 +9,7 @@ namespace TGCommandLine public RepoCommand() { Keyword = "repo"; - Children = new Command[] { new RepoSetupCommand(), new RepoUpdateCommand(), new RepoGenChangelogCommand(), new RepoPushChangelogCommand(), new RepoPythonPathCommand(), new RepoSetEmailCommand(), new RepoSetNameCommand(), new RepoMergePRCommand(), new RepoListPRsCommand(), new RepoStatusCommand(), new RepoListBackupsCommand(), new RepoCheckoutCommand(), new RepoResetCommand(), new RepoUpdateJsonCommand() }; + Children = new Command[] { new RepoSetupCommand(), new RepoUpdateCommand(), new RepoGenChangelogCommand(), new RepoPushChangelogCommand(), new RepoPythonPathCommand(), new RepoSetEmailCommand(), new RepoSetNameCommand(), new RepoMergePRCommand(), new RepoListPRsCommand(), new RepoStatusCommand(), new RepoListBackupsCommand(), new RepoCheckoutCommand(), new RepoResetCommand(), new RepoUpdateJsonCommand(), new RepoSetPushTestmergeCommitsCommand() }; } public override string GetHelpText() { @@ -17,6 +17,41 @@ namespace TGCommandLine } } + class RepoSetPushTestmergeCommitsCommand : Command + { + public RepoSetPushTestmergeCommitsCommand() + { + Keyword = "push-testmerges"; + RequiredParameters = 1; + } + public override string GetHelpText() + { + return "Set if a temporary branch is to the remote when we make testmerge commits and then delete it"; + } + + public override string GetArgumentString() + { + return ""; + } + + protected override ExitCode Run(IList parameters) + { + switch (parameters[0].ToLower()) + { + case "on": + Server.GetComponent().SetPushTestmergeCommits(true); + break; + case "off": + Server.GetComponent().SetPushTestmergeCommits(false); + break; + default: + OutputProc("Invalid option!"); + return ExitCode.BadCommand; + } + return ExitCode.Normal; + } + } + class RepoUpdateJsonCommand : Command { public RepoUpdateJsonCommand() @@ -97,6 +132,7 @@ namespace TGCommandLine OutputProc("Remote: " + remote + " (" + remotehead + ")"); OutputProc("Branch: " + branch); OutputProc("HEAD: " + head); + OutputProc("Push testmerge commits: " + (Repo.PushTestmergeCommits() ? "ON" : "OFF")); OutputProc(String.Format("Committer Identity: {0} ({1})", Repo.GetCommitterName(), Repo.GetCommitterEmail())); } else diff --git a/TGServerService/App.config b/TGServerService/App.config index 6b4ecc1601..b0894c51a4 100644 --- a/TGServerService/App.config +++ b/TGServerService/App.config @@ -73,6 +73,9 @@ + + False + diff --git a/TGServerService/Properties/Settings.Designer.cs b/TGServerService/Properties/Settings.Designer.cs index 7a76d2a5ae..630f47980d 100644 --- a/TGServerService/Properties/Settings.Designer.cs +++ b/TGServerService/Properties/Settings.Designer.cs @@ -274,5 +274,17 @@ namespace TGServerService.Properties { this["ReattachAPIVersion"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool PushTestmergeCommits { + get { + return ((bool)(this["PushTestmergeCommits"])); + } + set { + this["PushTestmergeCommits"] = value; + } + } } } diff --git a/TGServerService/Properties/Settings.settings b/TGServerService/Properties/Settings.settings index 5618f8cd97..c8afebdedd 100644 --- a/TGServerService/Properties/Settings.settings +++ b/TGServerService/Properties/Settings.settings @@ -65,5 +65,8 @@ + + False + \ No newline at end of file diff --git a/TGServerService/Repository.cs b/TGServerService/Repository.cs index 19c2111da1..68dfba3809 100644 --- a/TGServerService/Repository.cs +++ b/TGServerService/Repository.cs @@ -555,6 +555,32 @@ namespace TGServerService return null; } + void PushTestmergeCommit() + { + if (Properties.Settings.Default.PushTestmergeCommits && SSHAuth()) + { + try + { + //now try and push the commit to the remote so they can be referenced + var NewB = Repo.CreateBranch(RemoteTempBranchName).CanonicalName; + + var options = new PushOptions() + { + CredentialsProvider = GenerateGitCredentials + }; + var targetRemote = Repo.Network.Remotes[SSHPushRemote]; + Repo.Network.Push(targetRemote, NewB, options); //push the branch + Repo.Network.Push(targetRemote, null, NewB, options); //delete the branch + Repo.Branches.Remove(NewB); + TGServerService.WriteInfo("Pushed reference commit: " + Repo.Head.Tip.Sha, TGServerService.EventID.ReferencePush); + } + catch (Exception e) + { + TGServerService.WriteWarning(String.Format("Failed to push reference commit: {0}. Error: {1}", Repo.Head.Tip.Sha, e.ToString()), TGServerService.EventID.ReferencePush); + } + } + } + //public api public string Update(bool reset) { @@ -585,6 +611,8 @@ namespace TGServerService return error; } res = MergeBranch(originBranch.FriendlyName); + if (!LocalIsRemote()) //might be fast forward + PushTestmergeCommit(); if (res != null) throw new Exception(res); UpdateSubmodules(); @@ -842,29 +870,7 @@ namespace TGServerService return "PR Merged, JSON update failed: " + e.ToString(); } - if (SSHAuth()) - { - try - { - //now try and push the commit to the remote so they can be referenced - var NewB = Repo.CreateBranch(RemoteTempBranchName).CanonicalName; - - var options = new PushOptions() - { - CredentialsProvider = GenerateGitCredentials - }; - var targetRemote = Repo.Network.Remotes[SSHPushRemote]; - Repo.Network.Push(targetRemote, NewB, options); //push the branch - Repo.Network.Push(targetRemote, null, NewB, options); //delete the branch - Repo.Branches.Remove(NewB); - TGServerService.WriteInfo("Pushed reference commit: " + Repo.Head.Tip.Sha, TGServerService.EventID.ReferencePush); - } - catch (Exception e) - { - TGServerService.WriteWarning(String.Format("Failed to push reference commit: {0}. Error: {1}", Repo.Head.Tip.Sha, e.ToString()), TGServerService.EventID.ReferencePush); - } - } - + PushTestmergeCommit(); } return Result; } @@ -1212,5 +1218,17 @@ namespace TGServerService { return Properties.Settings.Default.PythonPath; } + + /// + public bool PushTestmergeCommits() + { + return Properties.Settings.Default.PushTestmergeCommits; + } + + /// + public void SetPushTestmergeCommits(bool newValue) + { + Properties.Settings.Default.PushTestmergeCommits = newValue; + } } } diff --git a/TGServiceInterface/Repository.cs b/TGServiceInterface/Repository.cs index da0ef9d8c5..bb0f1afff1 100644 --- a/TGServiceInterface/Repository.cs +++ b/TGServiceInterface/Repository.cs @@ -225,5 +225,19 @@ namespace TGServiceInterface /// null on success, error message on failure [OperationContract] string UpdateTGS3Json(); + + /// + /// Check if we push a temporary branch to the remote when we make testmerge commits + /// + /// true if we push testmerge commits, false otherwise + [OperationContract] + bool PushTestmergeCommits(); + + /// + /// Set if we push a temporary branch to the remote when we make testmerge commits + /// + /// true if we should push testmerge commits, false otherwise + [OperationContract] + void SetPushTestmergeCommits(bool newValue); } } From 250d6799ad8be5c1f9ecd408423c0e373d0a701c Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 17 Oct 2017 16:11:23 -0400 Subject: [PATCH 03/11] Control panel checkbox on Repo tab --- TGControlPanel/Main.Designer.cs | 17 +++++++++++++++++ TGControlPanel/RepoPage.cs | 4 ++++ TGInstallerWrapper/TGInstallerWrapper.csproj | 1 - 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/TGControlPanel/Main.Designer.cs b/TGControlPanel/Main.Designer.cs index 3f787f03be..4ce2b177a5 100644 --- a/TGControlPanel/Main.Designer.cs +++ b/TGControlPanel/Main.Designer.cs @@ -158,6 +158,7 @@ this.StaticFileCreateButton = new System.Windows.Forms.Button(); this.label6 = new System.Windows.Forms.Label(); this.StaticFileListBox = new System.Windows.Forms.ListBox(); + this.SyncCommitsCheckBox = new System.Windows.Forms.CheckBox(); this.ChatPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.ChatPortSelector)).BeginInit(); this.ChatProviderSelectorPanel.SuspendLayout(); @@ -1319,6 +1320,7 @@ // RepoPanel // this.RepoPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(39)))), ((int)(((byte)(40)))), ((int)(((byte)(34))))); + this.RepoPanel.Controls.Add(this.SyncCommitsCheckBox); this.RepoPanel.Controls.Add(this.TGSJsonUpdate); this.RepoPanel.Controls.Add(this.RepoRefreshButton); this.RepoPanel.Controls.Add(this.BackupTagsList); @@ -1799,6 +1801,20 @@ this.StaticFileListBox.TabIndex = 0; this.StaticFileListBox.SelectedIndexChanged += new System.EventHandler(this.StaticFileListBox_SelectedIndexChanged); // + // SyncCommitsCheckBox + // + this.SyncCommitsCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.SyncCommitsCheckBox.AutoSize = true; + this.SyncCommitsCheckBox.Font = new System.Drawing.Font("Verdana", 12F); + this.SyncCommitsCheckBox.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(242))))); + this.SyncCommitsCheckBox.Location = new System.Drawing.Point(574, 16); + this.SyncCommitsCheckBox.Name = "SyncCommitsCheckBox"; + this.SyncCommitsCheckBox.Size = new System.Drawing.Size(142, 22); + this.SyncCommitsCheckBox.TabIndex = 46; + this.SyncCommitsCheckBox.Text = "Sync Commits"; + this.SyncCommitsCheckBox.UseVisualStyleBackColor = true; + this.SyncCommitsCheckBox.Visible = false; + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -1966,5 +1982,6 @@ private System.Windows.Forms.NumericUpDown AutoUpdateInterval; private System.Windows.Forms.CheckBox AutoUpdateCheckbox; private System.Windows.Forms.Label AutoUpdateMLabel; + private System.Windows.Forms.CheckBox SyncCommitsCheckBox; } } diff --git a/TGControlPanel/RepoPage.cs b/TGControlPanel/RepoPage.cs index 15983de0ec..2546e1d93a 100644 --- a/TGControlPanel/RepoPage.cs +++ b/TGControlPanel/RepoPage.cs @@ -87,7 +87,9 @@ namespace TGControlPanel PythonPathLabel.Visible = true; PythonPathText.Visible = true; RepoRefreshButton.Visible = true; + SyncCommitsCheckBox.Visible = true; PythonPathText.Text = Repo.PythonPath(); + SyncCommitsCheckBox.Checked = Repo.PushTestmergeCommits(); if (!Repo.Exists()) { @@ -240,6 +242,7 @@ namespace TGControlPanel if (ra != RepoAction.Wait && RepoBusyCheck()) return; + SyncCommitsCheckBox.Visible = false; CurrentRevisionLabel.Visible = false; CurrentRevisionTitle.Visible = false; TestMergeListLabel.Visible = false; @@ -301,6 +304,7 @@ namespace TGControlPanel if (!Reclone) { + Repo.SetPushTestmergeCommits(SyncCommitsCheckBox.Checked); var branch = Repo.GetBranch(out error); if(branch == null) { diff --git a/TGInstallerWrapper/TGInstallerWrapper.csproj b/TGInstallerWrapper/TGInstallerWrapper.csproj index 7e1bf4045e..4a7e9bf37d 100644 --- a/TGInstallerWrapper/TGInstallerWrapper.csproj +++ b/TGInstallerWrapper/TGInstallerWrapper.csproj @@ -80,7 +80,6 @@ - From 668c8e509f3cf0c6991b950f73b4e2f3ab74f4ab Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 6 Nov 2017 10:32:38 -0500 Subject: [PATCH 04/11] Improve testmerge publish API documentation --- TGServiceInterface/Components/Repository.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TGServiceInterface/Components/Repository.cs b/TGServiceInterface/Components/Repository.cs index 5a64167aad..d722304328 100644 --- a/TGServiceInterface/Components/Repository.cs +++ b/TGServiceInterface/Components/Repository.cs @@ -179,14 +179,14 @@ namespace TGServiceInterface.Components /// /// Check if we push a temporary branch to the remote when we make testmerge commits /// - /// true if we push testmerge commits, false otherwise + /// if we publish testmerge commits to the remote, otherwise [OperationContract] bool PushTestmergeCommits(); /// /// Set if we push a temporary branch to the remote when we make testmerge commits /// - /// true if we should push testmerge commits, false otherwise + /// if we testmerge commits should be published to the remote, otherwise [OperationContract] void SetPushTestmergeCommits(bool newValue); } From 58f14b6dcd807ebe4c14a96ff08b24d305f970ae Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 6 Nov 2017 10:44:18 -0500 Subject: [PATCH 05/11] Fixes "Sync Commits" checkbox being always visible --- TGControlPanel/ControlPanel/ServerPage.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/TGControlPanel/ControlPanel/ServerPage.cs b/TGControlPanel/ControlPanel/ServerPage.cs index 9491b8db2a..895f3d87ac 100644 --- a/TGControlPanel/ControlPanel/ServerPage.cs +++ b/TGControlPanel/ControlPanel/ServerPage.cs @@ -93,6 +93,7 @@ namespace TGControlPanel WorldAnnounceField.Visible = RepoExists; WorldAnnounceButton.Visible = RepoExists; WorldAnnounceLabel.Visible = RepoExists; + SyncCommitsCheckBox.Visible = RepoExists; if (updatingFields) return; From 146a8f00d2f4288b3d98b82c261dd87101e5e741 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 6 Nov 2017 11:12:52 -0500 Subject: [PATCH 06/11] Actually get reference pushing working --- TGServerService/ServerInstance/Repository.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/TGServerService/ServerInstance/Repository.cs b/TGServerService/ServerInstance/Repository.cs index ecaf06020f..b3b92005d5 100644 --- a/TGServerService/ServerInstance/Repository.cs +++ b/TGServerService/ServerInstance/Repository.cs @@ -571,10 +571,11 @@ namespace TGServerService { if (Config.PushTestmergeCommits && SSHAuth()) { + string NewB = null; try { //now try and push the commit to the remote so they can be referenced - var NewB = Repo.CreateBranch(RemoteTempBranchName).CanonicalName; + NewB = Repo.CreateBranch(RemoteTempBranchName).CanonicalName; var options = new PushOptions() { @@ -582,14 +583,20 @@ namespace TGServerService }; var targetRemote = Repo.Network.Remotes[SSHPushRemote]; Repo.Network.Push(targetRemote, NewB, options); //push the branch - Repo.Network.Push(targetRemote, null, NewB, options); //delete the branch Repo.Branches.Remove(NewB); + NewB = null; + Repo.Network.Push(targetRemote, String.Format(":{0}", NewB), options); //delete the branch WriteInfo("Pushed reference commit: " + Repo.Head.Tip.Sha, EventID.ReferencePush); } catch (Exception e) { WriteWarning(String.Format("Failed to push reference commit: {0}. Error: {1}", Repo.Head.Tip.Sha, e.ToString()), EventID.ReferencePush); } + finally + { + if (NewB != null) + Repo.Branches.Remove(NewB); + } } } From 601cccf4d9efc273983d3a6d5bbe45f9a159ef6a Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 6 Nov 2017 11:25:54 -0500 Subject: [PATCH 07/11] MergeBranch now takes a message parameter. Testmerge commits indicate which PR# they were from --- TGServerService/ServerInstance/Repository.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/TGServerService/ServerInstance/Repository.cs b/TGServerService/ServerInstance/Repository.cs index b3b92005d5..6ae37a3a31 100644 --- a/TGServerService/ServerInstance/Repository.cs +++ b/TGServerService/ServerInstance/Repository.cs @@ -546,14 +546,21 @@ namespace TGServerService /// Merges given into the current branch /// /// The sha/branch/tag to merge + /// The commit message for the merge commit /// on success, error message on failure - string MergeBranch(string committish) + string MergeBranch(string committish, string mergeMessage) { var mo = new MergeOptions() { OnCheckoutProgress = HandleCheckoutProgress }; - var Result = Repo.Merge(committish, MakeSig()); + if (mergeMessage != null) + { + mo.CommitOnSuccess = false; + mo.FastForwardStrategy = FastForwardStrategy.NoFastForward; + } + var sig = MakeSig(); + var Result = Repo.Merge(committish, sig, mo); currentProgress = -1; switch (Result.Status) { @@ -564,6 +571,8 @@ namespace TGServerService case MergeStatus.UpToDate: return RepoErrorUpToDate; } + if(mergeMessage != null) + Repo.Commit(mergeMessage, sig, sig); return null; } @@ -644,7 +653,7 @@ namespace TGServerService WriteInfo("Repo hard updated to " + originBranch.Tip.Sha, EventID.RepoHardUpdate); return error; } - res = MergeBranch(originBranch.FriendlyName); + res = MergeBranch(originBranch.FriendlyName, "Merge origin into current testmerge"); if (!LocalIsRemote()) //might be fast forward PushTestmergeCommit(); if (res != null) @@ -883,7 +892,7 @@ namespace TGServerService } //so we'll know if this fails - var Result = MergeBranch(LocalBranchName); + var Result = MergeBranch(LocalBranchName, String.Format("Testmerge commit for pull request #{0}", PRNumber)); if (Result == null) try From a7f4c22c52f7a949cb5be5614edb679bbce90db8 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 6 Nov 2017 11:27:57 -0500 Subject: [PATCH 08/11] Better failure handling for reference commit pushing --- TGServerService/ServerInstance/Repository.cs | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/TGServerService/ServerInstance/Repository.cs b/TGServerService/ServerInstance/Repository.cs index 6ae37a3a31..1a1d1b4ca2 100644 --- a/TGServerService/ServerInstance/Repository.cs +++ b/TGServerService/ServerInstance/Repository.cs @@ -581,16 +581,15 @@ namespace TGServerService if (Config.PushTestmergeCommits && SSHAuth()) { string NewB = null; + var targetRemote = Repo.Network.Remotes[SSHPushRemote]; + var options = new PushOptions() + { + CredentialsProvider = GenerateGitCredentials + }; try { //now try and push the commit to the remote so they can be referenced NewB = Repo.CreateBranch(RemoteTempBranchName).CanonicalName; - - var options = new PushOptions() - { - CredentialsProvider = GenerateGitCredentials - }; - var targetRemote = Repo.Network.Remotes[SSHPushRemote]; Repo.Network.Push(targetRemote, NewB, options); //push the branch Repo.Branches.Remove(NewB); NewB = null; @@ -604,7 +603,19 @@ namespace TGServerService finally { if (NewB != null) - Repo.Branches.Remove(NewB); + { + //Try to delete the branches regardless + try + { + Repo.Branches.Remove(NewB); + } + catch { } + try + { + Repo.Network.Push(targetRemote, String.Format(":{0}", NewB), options); + } + catch { } + } } } } From c9d85bab1e1e1d7cc84576d23f60687b17f9b99e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 6 Nov 2017 11:38:41 -0500 Subject: [PATCH 09/11] Fix reference push errors --- TGServerService/ServerInstance/Repository.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TGServerService/ServerInstance/Repository.cs b/TGServerService/ServerInstance/Repository.cs index 1a1d1b4ca2..682b239346 100644 --- a/TGServerService/ServerInstance/Repository.cs +++ b/TGServerService/ServerInstance/Repository.cs @@ -592,8 +592,11 @@ namespace TGServerService NewB = Repo.CreateBranch(RemoteTempBranchName).CanonicalName; Repo.Network.Push(targetRemote, NewB, options); //push the branch Repo.Branches.Remove(NewB); + var removalString = String.Format(":{0}", NewB); NewB = null; - Repo.Network.Push(targetRemote, String.Format(":{0}", NewB), options); //delete the branch + //we need to delay the second operation a LOT otherwise we get ssh errors + Thread.Sleep(10000); + Repo.Network.Push(targetRemote, removalString, options); //delete the branch WriteInfo("Pushed reference commit: " + Repo.Head.Tip.Sha, EventID.ReferencePush); } catch (Exception e) From 377f5872c121ac82422381a28531bfb95245f9c5 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 6 Nov 2017 15:13:35 -0500 Subject: [PATCH 10/11] Test for command line PushTestmergeCommits functions --- TGCommandLine/Properties/AssemblyInfo.cs | 4 ++ .../Repository/RepositoryCommandTest.cs | 22 ++++++++ .../TestRepoSetPushTestmergeCommitsCommand.cs | 53 +++++++++++++++++++ .../Repository/TestRepoStatusCommand.cs | 46 ++++++++++++++++ TGServiceTests/OutputProcOverriderTest.cs | 26 +++++++++ TGServiceTests/TGServiceTests.csproj | 15 ++++++ TGServiceTests/TempDirectoryRequiredTest.cs | 2 +- TGServiceTests/packages.config | 2 + 8 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 TGServiceTests/CommandLine/Commands/Repository/RepositoryCommandTest.cs create mode 100644 TGServiceTests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs create mode 100644 TGServiceTests/CommandLine/Commands/Repository/TestRepoStatusCommand.cs create mode 100644 TGServiceTests/OutputProcOverriderTest.cs diff --git a/TGCommandLine/Properties/AssemblyInfo.cs b/TGCommandLine/Properties/AssemblyInfo.cs index 4b2ae228ae..27af13774e 100644 --- a/TGCommandLine/Properties/AssemblyInfo.cs +++ b/TGCommandLine/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -14,3 +15,6 @@ using System.Runtime.InteropServices; // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("9ad1f086-a83e-4d14-a844-58a9471106b6")] + +//allow the unit tester to peek inside us +[assembly: InternalsVisibleTo("TGServiceTests", AllInternalsVisible = true)] diff --git a/TGServiceTests/CommandLine/Commands/Repository/RepositoryCommandTest.cs b/TGServiceTests/CommandLine/Commands/Repository/RepositoryCommandTest.cs new file mode 100644 index 0000000000..48e3355c1a --- /dev/null +++ b/TGServiceTests/CommandLine/Commands/Repository/RepositoryCommandTest.cs @@ -0,0 +1,22 @@ +using Moq; +using TGServiceInterface; +using TGServiceInterface.Components; +using TGServiceTests; + +namespace TGCommandLine.Commands.Repository.Tests +{ + public abstract class RepositoryCommandTest : OutputProcOverriderTest + { + /// + /// Creates a mock that returns a specific when that component is requested + /// + /// The the resulting should return + /// A mock + protected IInterface MockInterfaceToRepo(ITGRepository repo) + { + var mock = new Mock(); + mock.Setup(foo => foo.GetComponent()).Returns(repo); + return mock.Object; + } + } +} diff --git a/TGServiceTests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs b/TGServiceTests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs new file mode 100644 index 0000000000..9810387d9c --- /dev/null +++ b/TGServiceTests/CommandLine/Commands/Repository/TestRepoSetPushTestmergeCommitsCommand.cs @@ -0,0 +1,53 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System.Collections.Generic; +using TGServiceInterface; +using TGServiceInterface.Components; + +namespace TGCommandLine.Commands.Repository.Tests +{ + /// + /// Tests for + /// + [TestClass] + public class TestRepoSetPushTestmergeCommitsCommand : RepositoryCommandTest + { + /// + /// Ensure it can be turned on + /// + [TestMethod] + public void TestTurnOn() + { + var ran = false; + var repo = new Mock(); + repo.Setup(foo => foo.SetPushTestmergeCommits(true)).Callback(() => { ran = true; }); + ConsoleCommand.Interface = MockInterfaceToRepo(repo.Object); + Assert.AreEqual(new RepoSetPushTestmergeCommitsCommand().DoRun(new List { "on" }), Command.ExitCode.Normal); + Assert.IsTrue(ran); + } + + /// + /// Ensure that it can be turned off + /// + [TestMethod] + public void TestTurnOff() + { + + var ran = false; + var repo = new Mock(); + repo.Setup(foo => foo.SetPushTestmergeCommits(false)).Callback(() => { ran = true; }); + ConsoleCommand.Interface = MockInterfaceToRepo(repo.Object); + Assert.AreEqual(new RepoSetPushTestmergeCommitsCommand().DoRun(new List { "off" }), Command.ExitCode.Normal); + Assert.IsTrue(ran); + } + + /// + /// Ensure that is returned for gibberish parameters + /// + [TestMethod] + public void TestGibberishParam() + { + Assert.AreEqual(new RepoSetPushTestmergeCommitsCommand().DoRun(new List { "gibberish" }), Command.ExitCode.BadCommand); + } + } +} diff --git a/TGServiceTests/CommandLine/Commands/Repository/TestRepoStatusCommand.cs b/TGServiceTests/CommandLine/Commands/Repository/TestRepoStatusCommand.cs new file mode 100644 index 0000000000..10b4656086 --- /dev/null +++ b/TGServiceTests/CommandLine/Commands/Repository/TestRepoStatusCommand.cs @@ -0,0 +1,46 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System.Collections.Generic; +using TGServiceInterface; +using TGServiceInterface.Components; + +namespace TGCommandLine.Commands.Repository.Tests +{ + /// + /// Tests for + /// + [TestClass] + public class TestRepoStatusCommand : RepositoryCommandTest + { + /// + /// Set the default returns for the mock to be + /// + /// A of with default return values + Mock GetDefaultMock() + { + var mock = new Mock(); + mock.SetReturnsDefault(null); + return mock; + } + + /// + /// Tests the results of + /// + [TestMethod] + public void TestPushTestmergeCommits() + { + var ran = false; + var mock = GetDefaultMock(); + mock.Setup(foo => foo.PushTestmergeCommits()).Returns(false).Callback(() => ran = true); + ConsoleCommand.Interface = MockInterfaceToRepo(mock.Object); + Assert.AreEqual(new RepoStatusCommand().DoRun(new List { }), Command.ExitCode.Normal); + Assert.IsTrue(ran); + + ran = false; + mock.Setup(foo => foo.PushTestmergeCommits()).Returns(true).Callback(() => ran = true); + ConsoleCommand.Interface = MockInterfaceToRepo(mock.Object); + Assert.AreEqual(new RepoStatusCommand().DoRun(new List { }), Command.ExitCode.Normal); + Assert.IsTrue(ran); + } + } +} diff --git a/TGServiceTests/OutputProcOverriderTest.cs b/TGServiceTests/OutputProcOverriderTest.cs new file mode 100644 index 0000000000..d118f07faf --- /dev/null +++ b/TGServiceTests/OutputProcOverriderTest.cs @@ -0,0 +1,26 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TGServiceInterface; + +namespace TGServiceTests +{ + /// + /// For tests that need to override + /// + public abstract class OutputProcOverriderTest + { + /// + /// Set to + /// + [TestInitialize] + public void Setup() + { + Command.OutputProcVar.Value = OutputProc; + } + + /// + /// Whe + /// + /// + protected virtual void OutputProc(string message) { } + } +} diff --git a/TGServiceTests/TGServiceTests.csproj b/TGServiceTests/TGServiceTests.csproj index 23dccc15c1..e8ad0a9acc 100644 --- a/TGServiceTests/TGServiceTests.csproj +++ b/TGServiceTests/TGServiceTests.csproj @@ -38,19 +38,30 @@ 4 + + ..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll + ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll ..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + ..\packages\Moq.4.7.145\lib\net45\Moq.dll + + + + + + Component @@ -65,6 +76,10 @@ + + {89191f69-b18e-4b59-b72e-e12f9b6811a0} + TGCommandLine + {f32eda25-0855-411c-af5e-f0d042917e2d} TGServerService diff --git a/TGServiceTests/TempDirectoryRequiredTest.cs b/TGServiceTests/TempDirectoryRequiredTest.cs index a4ef44cf09..dbf6aa4553 100644 --- a/TGServiceTests/TempDirectoryRequiredTest.cs +++ b/TGServiceTests/TempDirectoryRequiredTest.cs @@ -6,7 +6,7 @@ namespace TGServiceTests /// /// To be the parent of test classes that required a temporary directory /// - public class TempDirectoryRequiredTest + public abstract class TempDirectoryRequiredTest { /// /// The path to the temporary directory diff --git a/TGServiceTests/packages.config b/TGServiceTests/packages.config index d8c1b9099c..968620fd09 100644 --- a/TGServiceTests/packages.config +++ b/TGServiceTests/packages.config @@ -1,5 +1,7 @@  + + \ No newline at end of file From ab62382caa14ed8f01f2376ba3d963a91375bc0a Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 7 Nov 2017 12:55:39 -0500 Subject: [PATCH 11/11] As many tests as we can without the rewrite --- TGServerService/InstanceConfig.cs | 2 +- TGServiceTests/Service/TestServerInstance.cs | 29 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/TGServerService/InstanceConfig.cs b/TGServerService/InstanceConfig.cs index 69c6cf2ae7..a7afc8ab5f 100644 --- a/TGServerService/InstanceConfig.cs +++ b/TGServerService/InstanceConfig.cs @@ -7,7 +7,7 @@ namespace TGServerService /// /// Configuration settings for a /// - interface IInstanceConfig + public interface IInstanceConfig { /// /// The directory this is for diff --git a/TGServiceTests/Service/TestServerInstance.cs b/TGServiceTests/Service/TestServerInstance.cs index 27b79b6c4b..e8c8629549 100644 --- a/TGServiceTests/Service/TestServerInstance.cs +++ b/TGServiceTests/Service/TestServerInstance.cs @@ -1,4 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; using TGServiceTests; namespace TGServerService.Tests @@ -17,5 +18,33 @@ namespace TGServerService.Tests { new ServerInstance(new InstanceConfig(TempPath), 1).Dispose(); } + + /// + /// Test the return value of + /// + [TestMethod] + public void TestPushTestMergeCommits() + { + var ic = new InstanceConfig(TempPath) { PushTestmergeCommits = false }; + using (var si = new ServerInstance(ic, 1)) + { + Assert.IsFalse(si.PushTestmergeCommits()); + ic.PushTestmergeCommits = true; + Assert.IsTrue(si.PushTestmergeCommits()); + } + } + + [TestMethod] + public void TestSetPushTestMergeCommits() + { + var ic = new InstanceConfig(TempPath) { PushTestmergeCommits = false }; + using (var si = new ServerInstance(ic, 1)) + { + si.SetPushTestmergeCommits(true); + Assert.IsTrue(ic.PushTestmergeCommits); + si.SetPushTestmergeCommits(false); + Assert.IsFalse(ic.PushTestmergeCommits); + } + } } }