Skip to content

Commit

Permalink
#28, #27, #26
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Aug 26, 2016
1 parent fc19083 commit a4cf575
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 143 deletions.
29 changes: 15 additions & 14 deletions TGit/Commands/ContextMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@
using System;
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;

namespace SamirBoulema.TGit.Commands
{
public class ContextMenuCommands
{
private readonly CommandHelper _commandHelper;
private readonly DTE _dte;
private readonly OptionPageGrid _generalOptions;
private readonly OleMenuCommandService _mcs;

public ContextMenuCommands(CommandHelper commandHelper, DTE dte, OptionPageGrid generalOptions)
public ContextMenuCommands(OleMenuCommandService mcs, DTE dte, OptionPageGrid generalOptions)
{
_commandHelper = commandHelper;
_dte = dte;
_mcs = mcs;
_generalOptions = generalOptions;
}

public void AddCommands()
{
_commandHelper.AddCommand(ShowLogContextCommand, PkgCmdIDList.ShowLogContext);
_commandHelper.AddCommand(DiskBrowserContextCommand, PkgCmdIDList.DiskBrowserContext);
_commandHelper.AddCommand(RepoBrowserContextCommand, PkgCmdIDList.RepoBrowserContext);
CommandHelper.AddCommand(_mcs, ShowLogContextCommand, PkgCmdIDList.ShowLogContext);
CommandHelper.AddCommand(_mcs, DiskBrowserContextCommand, PkgCmdIDList.DiskBrowserContext);
CommandHelper.AddCommand(_mcs, RepoBrowserContextCommand, PkgCmdIDList.RepoBrowserContext);

_commandHelper.AddCommand(BlameContextCommand, PkgCmdIDList.BlameContext);
CommandHelper.AddCommand(_mcs, BlameContextCommand, PkgCmdIDList.BlameContext);

_commandHelper.AddCommand(MergeContextCommand, PkgCmdIDList.MergeContext);
CommandHelper.AddCommand(_mcs, MergeContextCommand, PkgCmdIDList.MergeContext);

_commandHelper.AddCommand(PullContextCommand, PkgCmdIDList.PullContext);
_commandHelper.AddCommand(FetchContextCommand, PkgCmdIDList.FetchContext);
_commandHelper.AddCommand(CommitContextCommand, PkgCmdIDList.CommitContext);
_commandHelper.AddCommand(RevertContextCommand, PkgCmdIDList.RevertContext);
_commandHelper.AddCommand(DiffContextCommand, PkgCmdIDList.DiffContext);
_commandHelper.AddCommand(PrefDiffContextCommand, PkgCmdIDList.PrefDiffContext);
CommandHelper.AddCommand(_mcs, PullContextCommand, PkgCmdIDList.PullContext);
CommandHelper.AddCommand(_mcs, FetchContextCommand, PkgCmdIDList.FetchContext);
CommandHelper.AddCommand(_mcs, CommitContextCommand, PkgCmdIDList.CommitContext);
CommandHelper.AddCommand(_mcs, RevertContextCommand, PkgCmdIDList.RevertContext);
CommandHelper.AddCommand(_mcs, DiffContextCommand, PkgCmdIDList.DiffContext);
CommandHelper.AddCommand(_mcs, PrefDiffContextCommand, PkgCmdIDList.PrefDiffContext);
}

private void ShowLogContextCommand(object sender, EventArgs e)
Expand Down
124 changes: 62 additions & 62 deletions TGit/Commands/GitFlowMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,91 @@
using System;
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;

namespace SamirBoulema.TGit.Commands
{
public class GitFlowMenuCommands
{
private readonly CommandHelper _commandHelper;
private readonly string _gitBin;
private readonly OptionPageGrid _options;
private readonly OleMenuCommandService _mcs;

public GitFlowMenuCommands(CommandHelper commandHelper, OptionPageGrid options)
public GitFlowMenuCommands(OleMenuCommandService mcs, OptionPageGrid options)
{
_commandHelper = commandHelper;
_gitBin = FileHelper.GetMSysGit();
_mcs = mcs;
_options = options;
}

public void AddCommands()
{
//GitFlow Commands
//Start/Finish Feature
var startFeature = _commandHelper.CreateCommand(StartFeatureCommand, PkgCmdIDList.StartFeature);
startFeature.BeforeQueryStatus += _commandHelper.GitFlow_BeforeQueryStatus;
_commandHelper.AddCommand(startFeature);
var startFeature = CommandHelper.CreateCommand(StartFeatureCommand, PkgCmdIDList.StartFeature);
startFeature.BeforeQueryStatus += CommandHelper.GitFlow_BeforeQueryStatus;
CommandHelper.AddCommand(_mcs, startFeature);

var finishFeature = _commandHelper.CreateCommand(FinishFeatureCommand, PkgCmdIDList.FinishFeature);
finishFeature.BeforeQueryStatus += _commandHelper.Feature_BeforeQueryStatus;
_commandHelper.AddCommand(finishFeature);
var finishFeature = CommandHelper.CreateCommand(FinishFeatureCommand, PkgCmdIDList.FinishFeature);
finishFeature.BeforeQueryStatus += CommandHelper.Feature_BeforeQueryStatus;
CommandHelper.AddCommand(_mcs, finishFeature);

//Start/Finish Release
var startRelease = _commandHelper.CreateCommand(StartReleaseCommand, PkgCmdIDList.StartRelease);
startRelease.BeforeQueryStatus += _commandHelper.GitFlow_BeforeQueryStatus;
_commandHelper.AddCommand(startRelease);
var startRelease = CommandHelper.CreateCommand(StartReleaseCommand, PkgCmdIDList.StartRelease);
startRelease.BeforeQueryStatus += CommandHelper.GitFlow_BeforeQueryStatus;
CommandHelper.AddCommand(_mcs, startRelease);

var finishRelease = _commandHelper.CreateCommand(FinishReleaseCommand, PkgCmdIDList.FinishRelease);
finishRelease.BeforeQueryStatus += _commandHelper.Release_BeforeQueryStatus;
_commandHelper.AddCommand(finishRelease);
var finishRelease = CommandHelper.CreateCommand(FinishReleaseCommand, PkgCmdIDList.FinishRelease);
finishRelease.BeforeQueryStatus += CommandHelper.Release_BeforeQueryStatus;
CommandHelper.AddCommand(_mcs, finishRelease);

//Start/Finish Hotfix
var startHotfix = _commandHelper.CreateCommand(StartHotfixCommand, PkgCmdIDList.StartHotfix);
startHotfix.BeforeQueryStatus += _commandHelper.GitFlow_BeforeQueryStatus;
_commandHelper.AddCommand(startHotfix);
var startHotfix = CommandHelper.CreateCommand(StartHotfixCommand, PkgCmdIDList.StartHotfix);
startHotfix.BeforeQueryStatus += CommandHelper.GitFlow_BeforeQueryStatus;
CommandHelper.AddCommand(_mcs, startHotfix);

var finishHotfix = _commandHelper.CreateCommand(FinishHotfixCommand, PkgCmdIDList.FinishHotfix);
finishHotfix.BeforeQueryStatus += _commandHelper.Hotfix_BeforeQueryStatus;
_commandHelper.AddCommand(finishHotfix);
var finishHotfix = CommandHelper.CreateCommand(FinishHotfixCommand, PkgCmdIDList.FinishHotfix);
finishHotfix.BeforeQueryStatus += CommandHelper.Hotfix_BeforeQueryStatus;
CommandHelper.AddCommand(_mcs, finishHotfix);

//Init
var init = _commandHelper.CreateCommand(InitCommand, PkgCmdIDList.Init);
init.BeforeQueryStatus += _commandHelper.GitHubFlow_BeforeQueryStatus;
_commandHelper.AddCommand(init);
var init = CommandHelper.CreateCommand(InitCommand, PkgCmdIDList.Init);
init.BeforeQueryStatus += CommandHelper.GitHubFlow_BeforeQueryStatus;
CommandHelper.AddCommand(_mcs, init);

//GitHubFlow Commands
//Start/Finish Feature
_commandHelper.AddCommand(StartFeatureGitHubCommand, PkgCmdIDList.StartFeatureGitHub);
var finishFeatureGitHub = _commandHelper.CreateCommand(FinishFeatureGitHubCommand, PkgCmdIDList.FinishFeatureGitHub);
finishFeatureGitHub.BeforeQueryStatus += _commandHelper.Feature_BeforeQueryStatus;
_commandHelper.AddCommand(finishFeatureGitHub);
CommandHelper.AddCommand(_mcs, StartFeatureGitHubCommand, PkgCmdIDList.StartFeatureGitHub);
var finishFeatureGitHub = CommandHelper.CreateCommand(FinishFeatureGitHubCommand, PkgCmdIDList.FinishFeatureGitHub);
finishFeatureGitHub.BeforeQueryStatus += CommandHelper.Feature_BeforeQueryStatus;
CommandHelper.AddCommand(_mcs, finishFeatureGitHub);
}

private void InitCommand(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(EnvHelper.SolutionDir)) return;

var flowDialog = new Flow();
if (flowDialog.ShowDialog() == DialogResult.OK)
{
/* 1. Add GitFlow config options
var flowDialog = new FlowDialog();
if (flowDialog.ShowDialog() != DialogResult.OK) return;

/* 1. Add GitFlow config options
* 2. Checkout develop branch (create if it doesn't exist, reset if it does)
* 3. Push develop branch
*/
ProcessHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"config --add gitflow.branch.master {flowDialog.FlowOptions.MasterBranch}") +
FormatCliCommand($"config --add gitflow.branch.develop {flowDialog.FlowOptions.DevelopBranch}") +
FormatCliCommand($"config --add gitflow.prefix.feature {flowDialog.FlowOptions.FeaturePrefix}") +
FormatCliCommand($"config --add gitflow.prefix.release {flowDialog.FlowOptions.ReleasePrefix}") +
FormatCliCommand($"config --add gitflow.prefix.hotfix {flowDialog.FlowOptions.HotfixPrefix}") +
(GitHelper.RemoteBranchExists(flowDialog.FlowOptions.DevelopBranch) ?
"echo." :
FormatCliCommand($"checkout -b {flowDialog.FlowOptions.DevelopBranch}", false)),
"Initializing GitFlow"
ProcessHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"config --add gitflow.branch.master {flowDialog.FlowOptions.MasterBranch}") +
FormatCliCommand($"config --add gitflow.branch.develop {flowDialog.FlowOptions.DevelopBranch}") +
FormatCliCommand($"config --add gitflow.prefix.feature {flowDialog.FlowOptions.FeaturePrefix}") +
FormatCliCommand($"config --add gitflow.prefix.release {flowDialog.FlowOptions.ReleasePrefix}") +
FormatCliCommand($"config --add gitflow.prefix.hotfix {flowDialog.FlowOptions.HotfixPrefix}") +
(GitHelper.RemoteBranchExists(flowDialog.FlowOptions.DevelopBranch) ?
"echo." :
FormatCliCommand($"checkout -b {flowDialog.FlowOptions.DevelopBranch}", false)),
"Initializing GitFlow"
);
}
EnvHelper.GetFlowOptions();
EnvHelper.GetBranchName();
}

private void StartFeatureCommand(object sender, EventArgs e)
Expand Down Expand Up @@ -139,7 +139,7 @@ private void FinishFeatureCommand(object sender, EventArgs e)
if (string.IsNullOrEmpty(EnvHelper.SolutionDir)) return;
var featureBranch = GitHelper.GetCurrentBranchName(false);
var featureName = GitHelper.GetCurrentBranchName(true);
var flowOptions = GitHelper.GetFlowOptions();
EnvHelper.GetFlowOptions();

/* 1. Switch to the develop branch
* 2. Pull latest changes on develop
Expand All @@ -152,18 +152,18 @@ private void FinishFeatureCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"checkout {flowOptions.DevelopBranch}") +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {featureBranch}") +
FormatCliCommand($"push origin {flowOptions.DevelopBranch}", false),
FormatCliCommand($"push origin {EnvHelper.FlowOptions.DevelopBranch}", false),
$"Finishing feature {featureName}",
featureBranch, null, _options
);
}

private string FormatCliCommand(string gitCommand, bool appendNextLine = true)
{
return $"echo ^> {Path.GetFileNameWithoutExtension(_gitBin)} {gitCommand} && \"{_gitBin}\" {gitCommand}{(appendNextLine ? " && " : string.Empty)}";
return $"echo ^> {Path.GetFileNameWithoutExtension(EnvHelper.Git)} {gitCommand} && \"{EnvHelper.Git}\" {gitCommand}{(appendNextLine ? " && " : string.Empty)}";
}

private void FinishFeatureGitHubCommand(object sender, EventArgs e)
Expand Down Expand Up @@ -219,7 +219,7 @@ private void FinishReleaseCommand(object sender, EventArgs e)
if (string.IsNullOrEmpty(EnvHelper.SolutionDir)) return;
var releaseBranch = GitHelper.GetCurrentBranchName(false);
var releaseName = GitHelper.GetCurrentBranchName(true);
var flowOptions = GitHelper.GetFlowOptions();
EnvHelper.GetFlowOptions();

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -238,15 +238,15 @@ private void FinishReleaseCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"checkout {flowOptions.MasterBranch}") +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {releaseBranch}") +
FormatCliCommand($"tag {releaseName}") +
FormatCliCommand($"checkout {flowOptions.DevelopBranch}") +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {releaseBranch}") +
FormatCliCommand($"push origin {flowOptions.DevelopBranch}") +
FormatCliCommand($"push origin {flowOptions.MasterBranch}") +
FormatCliCommand($"push origin {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand($"push origin {EnvHelper.FlowOptions.MasterBranch}") +
FormatCliCommand($"push origin {releaseName}", false),
$"Finishing release {releaseName}",
releaseBranch, null, _options
Expand Down Expand Up @@ -281,7 +281,7 @@ private void FinishHotfixCommand(object sender, EventArgs e)
if (string.IsNullOrEmpty(EnvHelper.SolutionDir)) return;
var hotfixBranch = GitHelper.GetCurrentBranchName(false);
var hotfixName = GitHelper.GetCurrentBranchName(true);
var flowOptions = GitHelper.GetFlowOptions();
EnvHelper.GetFlowOptions();

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -300,15 +300,15 @@ private void FinishHotfixCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{EnvHelper.SolutionDir}\" && " +
GitHelper.GetSshSetup() +
FormatCliCommand($"checkout {flowOptions.MasterBranch}") +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {hotfixBranch}") +
FormatCliCommand($"tag {hotfixName}") +
FormatCliCommand($"checkout {flowOptions.DevelopBranch}") +
FormatCliCommand($"checkout {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {hotfixBranch}") +
FormatCliCommand($"push origin {flowOptions.DevelopBranch}") +
FormatCliCommand($"push origin {flowOptions.MasterBranch}") +
FormatCliCommand($"push origin {EnvHelper.FlowOptions.DevelopBranch}") +
FormatCliCommand($"push origin {EnvHelper.FlowOptions.MasterBranch}") +
FormatCliCommand($"push origin {hotfixName}", false),
$"Finishing hotfix {hotfixName}",
hotfixBranch, null, _options
Expand Down
Loading

0 comments on commit a4cf575

Please sign in to comment.