Config option and cli command

This commit is contained in:
Cyberboss
2017-10-16 13:26:33 -04:00
parent 1f100b1e3d
commit a2c71ef16f
6 changed files with 110 additions and 24 deletions
+37 -1
View File
@@ -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 "<on|off>";
}
protected override ExitCode Run(IList<string> parameters)
{
switch (parameters[0].ToLower())
{
case "on":
Server.GetComponent<ITGRepository>().SetPushTestmergeCommits(true);
break;
case "off":
Server.GetComponent<ITGRepository>().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
+3
View File
@@ -73,6 +73,9 @@
<setting name="ReattachAPIVersion" serializeAs="String">
<value />
</setting>
<setting name="PushTestmergeCommits" serializeAs="String">
<value>False</value>
</setting>
</TGServerService.Properties.Settings>
</userSettings>
</configuration>
+12
View File
@@ -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;
}
}
}
}
@@ -65,5 +65,8 @@
<Setting Name="ReattachAPIVersion" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="PushTestmergeCommits" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
+41 -23
View File
@@ -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;
}
/// <inheritdoc />
public bool PushTestmergeCommits()
{
return Properties.Settings.Default.PushTestmergeCommits;
}
/// <inheritdoc />
public void SetPushTestmergeCommits(bool newValue)
{
Properties.Settings.Default.PushTestmergeCommits = newValue;
}
}
}
+14
View File
@@ -225,5 +225,19 @@ namespace TGServiceInterface
/// <returns>null on success, error message on failure</returns>
[OperationContract]
string UpdateTGS3Json();
/// <summary>
/// Check if we push a temporary branch to the remote when we make testmerge commits
/// </summary>
/// <returns>true if we push testmerge commits, false otherwise</returns>
[OperationContract]
bool PushTestmergeCommits();
/// <summary>
/// Set if we push a temporary branch to the remote when we make testmerge commits
/// </summary>
/// <param name="newValue">true if we should push testmerge commits, false otherwise</param>
[OperationContract]
void SetPushTestmergeCommits(bool newValue);
}
}