Skip to content

Commit

Permalink
#21, #22
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Aug 19, 2016
1 parent 21f682b commit 6f98a18
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 137 deletions.
8 changes: 3 additions & 5 deletions TGit/Commands/ContextMenuCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ public class ContextMenuCommands
{
private readonly ProcessHelper _processHelper;
private readonly CommandHelper _commandHelper;
private readonly FileHelper _fileHelper;
private readonly GitHelper _gitHelper;
private readonly DTE _dte;
private readonly OptionPageGrid _generalOptions;

public ContextMenuCommands(ProcessHelper processHelper, CommandHelper commandHelper, GitHelper gitHelper, FileHelper fileHelper,
public ContextMenuCommands(ProcessHelper processHelper, CommandHelper commandHelper, GitHelper gitHelper,
DTE dte, OptionPageGrid generalOptions)
{
_processHelper = processHelper;
_commandHelper = commandHelper;
_gitHelper = gitHelper;
_fileHelper = fileHelper;
_dte = dte;
_generalOptions = generalOptions;
}
Expand Down Expand Up @@ -120,14 +118,14 @@ private void PrefDiffContextCommand(object sender, EventArgs e)
if (string.IsNullOrEmpty(currentFilePath)) return;
_dte.ActiveDocument.Save();

var revisions = _processHelper.GitResult(Path.GetDirectoryName(currentFilePath), $"log -2 --pretty=format:%h {_fileHelper.GetExactFileName(currentFilePath)}");
var revisions = _processHelper.GitResult(Path.GetDirectoryName(currentFilePath), $"log -2 --pretty=format:%h {FileHelper.GetExactFileName(currentFilePath)}");
if (!revisions.Contains(","))
{
MessageBox.Show("Could not determine the last committed revision!", "TGit", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
_processHelper.StartTortoiseGitProc($"/command:diff /path:\"{_fileHelper.GetExactPathName(currentFilePath)}\" /startrev:{revisions.Split(',')[0]} /endrev:{revisions.Split(',')[1]}");
_processHelper.StartTortoiseGitProc($"/command:diff /path:\"{FileHelper.GetExactPathName(currentFilePath)}\" /startrev:{revisions.Split(',')[0]} /endrev:{revisions.Split(',')[1]}");
}
}
}
Expand Down
67 changes: 32 additions & 35 deletions TGit/Commands/GitFlowCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Windows.Forms;
using EnvDTE;
using Microsoft.VisualStudio.Shell;

namespace SamirBoulema.TGit.Commands
Expand All @@ -11,19 +12,22 @@ public class GitFlowCommands
{
private readonly ProcessHelper _processHelper;
private readonly CommandHelper _commandHelper;
private readonly FileHelper _fileHelper;
private readonly GitHelper _gitHelper;
private readonly string _gitBin;
private readonly OleMenuCommandService _mcs;
private readonly DTE _dte;
private readonly OptionPageGrid _options;

public GitFlowCommands(ProcessHelper processHelper, CommandHelper commandHelper, GitHelper gitHelper, FileHelper fileHelper, OleMenuCommandService mcs)
public GitFlowCommands(ProcessHelper processHelper, CommandHelper commandHelper, GitHelper gitHelper,
OleMenuCommandService mcs, DTE dte, OptionPageGrid options)
{
_processHelper = processHelper;
_commandHelper = commandHelper;
_gitHelper = gitHelper;
_fileHelper = fileHelper;
_gitBin = fileHelper.GetMSysGit();
_gitBin = FileHelper.GetMSysGit();
_mcs = mcs;
_dte = dte;
_options = options;
}

public void AddCommands()
Expand Down Expand Up @@ -71,7 +75,7 @@ public void AddCommands()

private void InitCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;

var flowDialog = new Flow();
Expand Down Expand Up @@ -100,7 +104,7 @@ private void InitCommand(object sender, EventArgs e)

private void StartFeatureCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;
var featureName = Interaction.InputBox("Feature Name:", "Start New Feature");
if (string.IsNullOrEmpty(featureName)) return;
Expand All @@ -124,13 +128,11 @@ private void StartFeatureCommand(object sender, EventArgs e)

private void StartFeatureGitHubCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;
var featureName = Interaction.InputBox("Feature Name:", "Start New Feature");
if (string.IsNullOrEmpty(featureName)) return;

var flowOptions = _gitHelper.GetFlowOptions();

/* 1. Switch to the master branch
* 2. Pull latest changes on master
* 3. Create and switch to a new branch
Expand All @@ -139,16 +141,16 @@ private void StartFeatureGitHubCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {flowOptions.MasterBranch}") +
FormatCliCommand("checkout master") +
FormatCliCommand("pull") +
FormatCliCommand($"checkout -b {flowOptions.FeaturePrefix}{featureName} {flowOptions.MasterBranch}", false),
FormatCliCommand($"checkout -b {featureName} master", false),
$"Starting feature {featureName}"
);
}

private void FinishFeatureCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;
var featureBranch = _gitHelper.GetCurrentBranchName(false);
var featureName = _gitHelper.GetCurrentBranchName(true);
Expand All @@ -168,10 +170,9 @@ private void FinishFeatureCommand(object sender, EventArgs e)
FormatCliCommand($"checkout {flowOptions.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {featureBranch}") +
FormatCliCommand($"push origin {flowOptions.DevelopBranch}") +
FormatCliCommand($"branch -d {featureBranch}") +
(_gitHelper.RemoteBranchExists(featureBranch) ? FormatCliCommand($"push origin --delete {featureBranch}", false) : "echo."),
$"Finishing feature {featureName}"
FormatCliCommand($"push origin {flowOptions.DevelopBranch}", false),
$"Finishing feature {featureName}",
featureBranch, null, _options
);
}

Expand All @@ -182,11 +183,10 @@ private string FormatCliCommand(string gitCommand, bool appendNextLine = true)

private void FinishFeatureGitHubCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;
var featureBranch = _gitHelper.GetCurrentBranchName(false);
var featureName = _gitHelper.GetCurrentBranchName(true);
var flowOptions = _gitHelper.GetFlowOptions();

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -199,18 +199,17 @@ private void FinishFeatureGitHubCommand(object sender, EventArgs e)
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {flowOptions.MasterBranch}") +
FormatCliCommand("checkout master") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {featureBranch}") +
FormatCliCommand($"push origin {flowOptions.MasterBranch}") +
FormatCliCommand($"branch -d {featureBranch}") +
(_gitHelper.RemoteBranchExists(featureBranch) ? FormatCliCommand($"push origin --delete {featureBranch}", false) : "echo."),
$"Finishing feature {featureName}");
FormatCliCommand("push origin master", false),
$"Finishing feature {featureName}",
featureBranch, null, _options);
}

private void StartReleaseCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;
var releaseVersion = Interaction.InputBox("Release Version:", "Start New Release");
if (string.IsNullOrEmpty(releaseVersion)) return;
Expand All @@ -234,7 +233,7 @@ private void StartReleaseCommand(object sender, EventArgs e)

private void FinishReleaseCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;
var releaseBranch = _gitHelper.GetCurrentBranchName(false);
var releaseName = _gitHelper.GetCurrentBranchName(true);
Expand Down Expand Up @@ -266,16 +265,15 @@ private void FinishReleaseCommand(object sender, EventArgs e)
FormatCliCommand($"merge --no-ff {releaseBranch}") +
FormatCliCommand($"push origin {flowOptions.DevelopBranch}") +
FormatCliCommand($"push origin {flowOptions.MasterBranch}") +
FormatCliCommand($"push origin {releaseName}") +
FormatCliCommand($"branch -d {releaseBranch}") +
(_gitHelper.RemoteBranchExists(releaseBranch) ? FormatCliCommand($"push origin --delete {releaseBranch}", false) : "echo."),
$"Finishing release {releaseName}"
FormatCliCommand($"push origin {releaseName}", false),
$"Finishing release {releaseName}",
releaseBranch, null, _options
);
}

private void StartHotfixCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;
var hotfixVersion = Interaction.InputBox("Hotfix Version:", "Start New Hotfix");
if (string.IsNullOrEmpty(hotfixVersion)) return;
Expand All @@ -299,7 +297,7 @@ private void StartHotfixCommand(object sender, EventArgs e)

private void FinishHotfixCommand(object sender, EventArgs e)
{
var solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = FileHelper.GetSolutionDir(_dte);
if (string.IsNullOrEmpty(solutionDir)) return;
var hotfixBranch = _gitHelper.GetCurrentBranchName(false);
var hotfixName = _gitHelper.GetCurrentBranchName(true);
Expand Down Expand Up @@ -331,10 +329,9 @@ private void FinishHotfixCommand(object sender, EventArgs e)
FormatCliCommand($"merge --no-ff {hotfixBranch}") +
FormatCliCommand($"push origin {flowOptions.DevelopBranch}") +
FormatCliCommand($"push origin {flowOptions.MasterBranch}") +
FormatCliCommand($"push origin {hotfixName}") +
FormatCliCommand($"branch -d {hotfixBranch}") +
(_gitHelper.RemoteBranchExists(hotfixBranch) ? FormatCliCommand($"push origin --delete {hotfixBranch}", false) : "echo."),
$"Finishing hotfix {hotfixName}"
FormatCliCommand($"push origin {hotfixName}", false),
$"Finishing hotfix {hotfixName}",
hotfixBranch, null, _options
);
}
}
Expand Down
Loading

0 comments on commit 6f98a18

Please sign in to comment.