From a2c71ef16f6d39a5a73dbfec9050db8efbb75fef Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 16 Oct 2017 13:26:33 -0400 Subject: [PATCH] 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); } }