Skip to content

Commit

Permalink
#11
Browse files Browse the repository at this point in the history
  • Loading branch information
sboulema committed Aug 9, 2016
2 parents 39d788a + 1c063fe commit 27a738e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 47 deletions.
48 changes: 28 additions & 20 deletions TGit/Commands/GitFlowCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ public void AddCommands()
//GitFlow Commands
//Start/Finish Feature
_commandHelper.AddCommand(StartFeatureCommand, PkgCmdIDList.StartFeature);
OleMenuCommand finishFeature = _commandHelper.CreateCommand(FinishFeatureCommand, PkgCmdIDList.FinishFeature);
var finishFeature = _commandHelper.CreateCommand(FinishFeatureCommand, PkgCmdIDList.FinishFeature);
finishFeature.BeforeQueryStatus += _commandHelper.Feature_BeforeQueryStatus;
_mcs.AddCommand(finishFeature);

//Start/Finish Release
_commandHelper.AddCommand(StartReleaseCommand, PkgCmdIDList.StartRelease);
OleMenuCommand finishRelease = _commandHelper.CreateCommand(FinishReleaseCommand, PkgCmdIDList.FinishRelease);
var finishRelease = _commandHelper.CreateCommand(FinishReleaseCommand, PkgCmdIDList.FinishRelease);
finishRelease.BeforeQueryStatus += _commandHelper.Release_BeforeQueryStatus;
_mcs.AddCommand(finishRelease);

//Start/Finish Hotfix
_commandHelper.AddCommand(StartHotfixCommand, PkgCmdIDList.StartHotfix);
OleMenuCommand finishHotfix = _commandHelper.CreateCommand(FinishHotfixCommand, PkgCmdIDList.FinishHotfix);
var finishHotfix = _commandHelper.CreateCommand(FinishHotfixCommand, PkgCmdIDList.FinishHotfix);
finishHotfix.BeforeQueryStatus += _commandHelper.Hotfix_BeforeQueryStatus;
_mcs.AddCommand(finishHotfix);

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

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

/* 1. Switch to the develop branch
Expand All @@ -71,6 +71,7 @@ private void StartFeatureCommand(object sender, EventArgs e)
_processHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {_options.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"checkout -b {_options.FeatureBranch}/{featureName} {_options.DevelopBranch}", false),
Expand All @@ -80,9 +81,9 @@ private void StartFeatureCommand(object sender, EventArgs e)

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

/* 1. Switch to the master branch
Expand All @@ -92,6 +93,7 @@ private void StartFeatureGitHubCommand(object sender, EventArgs e)
_processHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {_options.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"checkout -b {_options.FeatureBranch}/{featureName} {_options.MasterBranch}", false),
Expand All @@ -101,9 +103,9 @@ private void StartFeatureGitHubCommand(object sender, EventArgs e)

private void FinishFeatureCommand(object sender, EventArgs e)
{
string solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return;
string featureName = _gitHelper.GetCurrentBranchName(true);
var featureName = _gitHelper.GetCurrentBranchName(true);

/* 1. Switch to the develop branch
* 2. Pull latest changes on develop
Expand All @@ -115,6 +117,7 @@ private void FinishFeatureCommand(object sender, EventArgs e)
_processHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {_options.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {_options.FeatureBranch}/{featureName}") +
Expand All @@ -132,9 +135,9 @@ private string FormatCliCommand(string gitCommand, bool appendNextLine = true)

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

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -146,6 +149,7 @@ private void FinishFeatureGitHubCommand(object sender, EventArgs e)
_processHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {_options.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {_options.FeatureBranch}/{featureName}") +
Expand All @@ -157,9 +161,9 @@ private void FinishFeatureGitHubCommand(object sender, EventArgs e)

private void StartReleaseCommand(object sender, EventArgs e)
{
string solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return;
string releaseVersion = Interaction.InputBox("Release Version:", "Start New Release");
var releaseVersion = Interaction.InputBox("Release Version:", "Start New Release");
if (string.IsNullOrEmpty(releaseVersion)) return;

/* 1. Switch to the develop branch
Expand All @@ -169,6 +173,7 @@ private void StartReleaseCommand(object sender, EventArgs e)
_processHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {_options.DevelopBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"checkout -b {_options.ReleaseBranch}/{releaseVersion} {_options.DevelopBranch}", false),
Expand All @@ -178,9 +183,9 @@ private void StartReleaseCommand(object sender, EventArgs e)

private void FinishReleaseCommand(object sender, EventArgs e)
{
string solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return;
string releaseName = _gitHelper.GetCurrentBranchName(true);
var releaseName = _gitHelper.GetCurrentBranchName(true);

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -198,6 +203,7 @@ private void FinishReleaseCommand(object sender, EventArgs e)
_processHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {_options.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {_options.ReleaseBranch}/{releaseName}") +
Expand All @@ -216,9 +222,9 @@ private void FinishReleaseCommand(object sender, EventArgs e)

private void StartHotfixCommand(object sender, EventArgs e)
{
string solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return;
string hotfixVersion = Interaction.InputBox("Hotfix Version:", "Start New Hotfix");
var hotfixVersion = Interaction.InputBox("Hotfix Version:", "Start New Hotfix");
if (string.IsNullOrEmpty(hotfixVersion)) return;

/* 1. Switch to the master branch
Expand All @@ -228,6 +234,7 @@ private void StartHotfixCommand(object sender, EventArgs e)
_processHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {_options.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"checkout -b {_options.HotfixBranch}/{hotfixVersion} {_options.MasterBranch}", false),
Expand All @@ -237,9 +244,9 @@ private void StartHotfixCommand(object sender, EventArgs e)

private void FinishHotfixCommand(object sender, EventArgs e)
{
string solutionDir = _fileHelper.GetSolutionDir();
var solutionDir = _fileHelper.GetSolutionDir();
if (string.IsNullOrEmpty(solutionDir)) return;
string hotfixName = _gitHelper.GetCurrentBranchName(true);
var hotfixName = _gitHelper.GetCurrentBranchName(true);

/* 1. Switch to the master branch
* 2. Pull latest changes on master
Expand All @@ -257,6 +264,7 @@ private void FinishHotfixCommand(object sender, EventArgs e)
_processHelper.StartProcessGui(
"cmd.exe",
$"/c cd \"{solutionDir}\" && " +
_gitHelper.GetSshSetup() +
FormatCliCommand($"checkout {_options.MasterBranch}") +
FormatCliCommand("pull") +
FormatCliCommand($"merge --no-ff {_options.HotfixBranch}/{hotfixName}") +
Expand Down
16 changes: 7 additions & 9 deletions TGit/Helpers/FileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public string GetTortoiseGitProc()
return (string) Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\TortoiseGit", "ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitProc.exe");
}

public string GetMSysGit()
public string GetTortoiseGitPlink()
{
string regPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\TortoiseGit", "MSysGit", null);
return (string)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\TortoiseGit", "ProcPath", @"C:\Program Files\TortoiseGit\bin\TortoiseGitPlink.exe");
}

if (string.IsNullOrEmpty(regPath))
{
return @"C:\Program Files (x86)\Git\bin\git.exe";
}
public string GetMSysGit()
{
var regPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\TortoiseGit", "MSysGit", @"C:\Program Files (x86)\Git\bin\git.exe");
return Path.Combine(regPath, "git.exe");
}

Expand Down Expand Up @@ -100,9 +100,7 @@ public string GetExactPathName(string pathName)
GetExactPathName(di.Parent.FullName),
di.Parent.GetFileSystemInfos(di.Name)[0].Name);
}
else {
return di.Name.ToUpper();
}
return di.Name.ToUpper();
}
}
}
43 changes: 26 additions & 17 deletions TGit/Helpers/GitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ namespace SamirBoulema.TGit.Helpers
{
public class GitHelper
{
private readonly FileHelper fileHelper;
private readonly ProcessHelper processHelper;
private readonly string featureBranch, releaseBranch, hotfixBranch;
private readonly FileHelper _fileHelper;
private readonly ProcessHelper _processHelper;
private readonly string _featureBranch, _releaseBranch, _hotfixBranch;

public GitHelper(FileHelper fileHelper, ProcessHelper processHelper, string featureBranch, string releaseBranch, string hotfixBranch)
{
this.fileHelper = fileHelper;
this.processHelper = processHelper;
this.featureBranch = featureBranch;
this.releaseBranch = releaseBranch;
this.hotfixBranch = hotfixBranch;
_fileHelper = fileHelper;
_processHelper = processHelper;
_featureBranch = featureBranch;
_releaseBranch = releaseBranch;
_hotfixBranch = hotfixBranch;
}

public string GetCommitMessage(string commitMessageTemplate, DTE dte)
Expand Down Expand Up @@ -50,7 +50,7 @@ public string GetCommitMessage(string commitMessageTemplate, DTE dte)

public string GetCurrentBranchName(bool trimPrefix)
{
string solutionDir = fileHelper.GetSolutionDir();
var solutionDir = _fileHelper.GetSolutionDir();

if (string.IsNullOrEmpty(solutionDir))
{
Expand All @@ -65,7 +65,7 @@ public string GetCurrentBranchName(bool trimPrefix)
StartInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c cd \"{solutionDir}\" && {drive} && \"{fileHelper.GetMSysGit()}\" symbolic-ref -q --short HEAD",
Arguments = $"/c cd \"{solutionDir}\" && {drive} && \"{_fileHelper.GetMSysGit()}\" symbolic-ref -q --short HEAD",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand All @@ -83,17 +83,17 @@ public string GetCurrentBranchName(bool trimPrefix)
}
if (branchName != null)
{
if (branchName.StartsWith(featureBranch) && trimPrefix)
if (branchName.StartsWith(_featureBranch) && trimPrefix)
{
return branchName.Substring(featureBranch.Length + 1);
return branchName.Substring(_featureBranch.Length + 1);
}
if (branchName.StartsWith(releaseBranch) && trimPrefix)
if (branchName.StartsWith(_releaseBranch) && trimPrefix)
{
return branchName.Substring(releaseBranch.Length + 1);
return branchName.Substring(_releaseBranch.Length + 1);
}
if (branchName.StartsWith(hotfixBranch) && trimPrefix)
if (branchName.StartsWith(_hotfixBranch) && trimPrefix)
{
return branchName.Substring(hotfixBranch.Length + 1);
return branchName.Substring(_hotfixBranch.Length + 1);
}
return branchName;
}
Expand All @@ -106,7 +106,16 @@ public string GetCurrentBranchName(bool trimPrefix)

public bool BranchExists(string branchName)
{
return processHelper.StartProcessGit($"rev-parse --verify origin/{branchName}", false);
return _processHelper.StartProcessGit($"rev-parse --verify origin/{branchName}", false);
}

public string GetSshSetup()
{
var remoteOriginPuttyKeyfile = _processHelper.StartProcessGitResult("config --get remote.origin.puttykeyfile");
if (string.IsNullOrEmpty(remoteOriginPuttyKeyfile)) return string.Empty;

_processHelper.Start("pageant", remoteOriginPuttyKeyfile);
return $"set GIT_SSH={_fileHelper.GetTortoiseGitPlink()} && ";
}
}
}
5 changes: 5 additions & 0 deletions TGit/Helpers/ProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public void Start(string application)
Process.Start(application);
}

public void Start(string application, string arguments)
{
Process.Start(application, arguments);
}

public void StartProcessGui(string application, string args, string title)
{
var dialogResult = DialogResult.OK;
Expand Down
2 changes: 1 addition & 1 deletion TGit/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="2eb0e74d-a27d-4c41-bca4-7e9e9befaa18" Version="3.4" Language="en-US" Publisher="Samir L. Boulema" />
<Identity Id="2eb0e74d-a27d-4c41-bca4-7e9e9befaa18" Version="3.5" Language="en-US" Publisher="Samir L. Boulema" />
<DisplayName>TGit</DisplayName>
<Description xml:space="preserve">Control TortoiseGit from within Visual Studio</Description>
<MoreInfo>https://github.com/sboulema/TGit</MoreInfo>
Expand Down

0 comments on commit 27a738e

Please sign in to comment.