diff --git a/TGit/Commands/GitFlowCommands.cs b/TGit/Commands/GitFlowCommands.cs index 944756a..5cc3c45 100644 --- a/TGit/Commands/GitFlowCommands.cs +++ b/TGit/Commands/GitFlowCommands.cs @@ -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 @@ -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), @@ -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 @@ -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), @@ -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 @@ -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}") + @@ -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 @@ -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}") + @@ -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 @@ -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), @@ -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 @@ -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}") + @@ -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 @@ -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), @@ -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 @@ -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}") + diff --git a/TGit/Helpers/FileHelper.cs b/TGit/Helpers/FileHelper.cs index f7fa23d..2de2571 100644 --- a/TGit/Helpers/FileHelper.cs +++ b/TGit/Helpers/FileHelper.cs @@ -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"); } @@ -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(); } } } diff --git a/TGit/Helpers/GitHelper.cs b/TGit/Helpers/GitHelper.cs index 36df5ae..dcecd20 100644 --- a/TGit/Helpers/GitHelper.cs +++ b/TGit/Helpers/GitHelper.cs @@ -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) @@ -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)) { @@ -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, @@ -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; } @@ -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()} && "; } } } diff --git a/TGit/Helpers/ProcessHelper.cs b/TGit/Helpers/ProcessHelper.cs index dd749af..d4c4aab 100644 --- a/TGit/Helpers/ProcessHelper.cs +++ b/TGit/Helpers/ProcessHelper.cs @@ -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; diff --git a/TGit/source.extension.vsixmanifest b/TGit/source.extension.vsixmanifest index 5d7d799..d38cc07 100644 --- a/TGit/source.extension.vsixmanifest +++ b/TGit/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + TGit Control TortoiseGit from within Visual Studio https://github.com/sboulema/TGit