private void RegisterCommand(ToolbarCommand id, EventHandler callback) { var menuCommandID = new CommandID(PackageConstants.GuidTortoiseGitToolbarCmdSet, (int)id); var menuItem = new OleMenuCommand(callback, menuCommandID); menuItem.Visible = false; _commandService.AddCommand(menuItem); }
public void Ensure_all_tortoisegit_commands_bind_to_event_handlers(ToolbarCommand toolbarCommand) { var command = GetMenuCommand(toolbarCommand); var execHandler = typeof(MenuCommand).GetField("execHandler", BindingFlags.NonPublic | BindingFlags.Instance); Assert.That(execHandler, Is.Not.Null); Assert.That(execHandler.GetValue(command), Is.Not.Null); }
public void Ensure_all_tortoisegit_commands_bind_to_event_handlers(ToolbarCommand toolbarCommand) { var command = GetMenuCommand(toolbarCommand); var execHandler = typeof(MenuCommand).GetField("execHandler", BindingFlags.NonPublic | BindingFlags.Instance); Assert.NotNull(execHandler); Assert.NotNull(execHandler.GetValue(command)); }
private MenuCommand GetMenuCommand(ToolbarCommand toolbarCommand) { _package.SetSite(_serviceProvider); var getServiceMethod = typeof(Package).GetMethod("GetService", BindingFlags.Instance | BindingFlags.NonPublic); var menuCommandId = new CommandID(PackageConstants.GuidTortoiseGitToolbarCmdSet, (int)toolbarCommand); var menuCommandService = getServiceMethod.Invoke(_package, new object[] { typeof(IMenuCommandService) }) as OleMenuCommandService; return(menuCommandService?.FindCommand(menuCommandId)); }
private static void InvokeCommand(ToolbarCommand toolbarCommand) { var menuItemCmd = new CommandID(PackageConstants.GuidTortoiseGitToolbarCmdSet, (int)toolbarCommand); using (var dialogboxPurger = new DialogBoxPurger(NativeMethods.IDOK, 1)) { dialogboxPurger.Start(); ExecuteCommand(menuItemCmd); } }
public void Launch_tortoise_command_with_correct_parameters(ToolbarCommand toolbarCommand) { var solution = GetOpenSolution(); var tortoiseGitLauncherService = Substitute.For<TortoiseGitLauncherService>(_processManagerService, solution); tortoiseGitLauncherService.ExecuteTortoiseProc(toolbarCommand); _processManagerService.Received().GetProcess( GetExpectedCommand(toolbarCommand), GetExpectedParameters(toolbarCommand) ); }
private static void InvokeCommand(ToolbarCommand toolbarCommand) { UIThreadInvoker.Invoke((ThreadInvoker) delegate { var menuItemCmd = new CommandID(PackageConstants.GuidTortoiseGitToolbarCmdSet, (int) toolbarCommand); using (var dialogboxPurger = new DialogBoxPurger(NativeMethods.IDOK, 1)) { dialogboxPurger.Start(); ExecuteCommand(menuItemCmd); } }); }
public void Invoke_all_command_handlers_without_exception(ToolbarCommand toolbarCommand) { try { var uishellMock = UIShellServiceMock.GetUiShellInstance(); _serviceProvider.AddService(typeof(SVsUIShell), uishellMock, true); var tortoiseGitLauncherService = Substitute.For <ITortoiseGitLauncherService>(); _serviceProvider.AddService(typeof(TortoiseGitLauncherService), tortoiseGitLauncherService, true); var command = GetMenuCommand(toolbarCommand); var execHandler = (EventHandler)typeof(MenuCommand).GetField("execHandler", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(command); execHandler.Invoke(null, null); tortoiseGitLauncherService.Received().ExecuteTortoiseProc(toolbarCommand); } finally { _serviceProvider.RemoveService(typeof(SVsUIShell)); } }
public void Invoke_all_command_handlers_without_exception(ToolbarCommand toolbarCommand) { try { var uishellMock = UIShellServiceMock.GetUiShellInstance(); _serviceProvider.AddService(typeof(SVsUIShell), uishellMock, true); var tortoiseGitLauncherService = Substitute.For<ITortoiseGitLauncherService>(); _serviceProvider.AddService(typeof(TortoiseGitLauncherService), tortoiseGitLauncherService, true); var command = GetMenuCommand(toolbarCommand); var execHandler = (EventHandler) typeof(MenuCommand).GetField("execHandler", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(command); TestDelegate commandHandler = () => execHandler.Invoke(null, null); Assert.DoesNotThrow(commandHandler); tortoiseGitLauncherService.Received().ExecuteTortoiseProc(toolbarCommand); } finally { _serviceProvider.RemoveService(typeof(SVsUIShell)); } }
private static string GetExpectedCommand(ToolbarCommand toolbarCommand) { switch (toolbarCommand) { case ToolbarCommand.Commit: case ToolbarCommand.Log: case ToolbarCommand.Pull: case ToolbarCommand.Push: case ToolbarCommand.Resolve: case ToolbarCommand.Switch: case ToolbarCommand.Cleanup: case ToolbarCommand.Fetch: case ToolbarCommand.Revert: case ToolbarCommand.Sync: case ToolbarCommand.Merge: case ToolbarCommand.StashSave: case ToolbarCommand.StashPop: case ToolbarCommand.Rebase: case ToolbarCommand.FileLog: case ToolbarCommand.FileDiff: case ToolbarCommand.FileBlame: return PathConfiguration.GetTortoiseGitPath(); case ToolbarCommand.Bash: case ToolbarCommand.RebaseContinue: return PathConfiguration.GetGitBashPath(); } throw new InvalidOperationException(string.Format("You need to define an expected test process command result for {0}.", toolbarCommand)); }
private static string GetExpectedParameters(ToolbarCommand toolbarCommand) { switch (toolbarCommand) { case ToolbarCommand.Bash: return "--login -i"; case ToolbarCommand.RebaseContinue: return @"--login -i -c 'echo; echo ""Running git rebase --continue""; echo; git rebase --continue; echo; echo ""Please review the output above and press enter to continue.""; read'"; case ToolbarCommand.Commit: return string.Format(@"/command:commit /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Log: return string.Format(@"/command:log /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Pull: return string.Format(@"/command:pull /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Push: return string.Format(@"/command:push /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Switch: return string.Format(@"/command:switch /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Cleanup: return string.Format(@"/command:cleanup /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Fetch: return string.Format(@"/command:fetch /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Revert: return string.Format(@"/command:revert /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Sync: return string.Format(@"/command:sync /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Merge: return string.Format(@"/command:merge /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Resolve: return string.Format(@"/command:resolve /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.StashSave: return string.Format(@"/command:stashsave /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.StashPop: return string.Format(@"/command:stashpop /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.Rebase: return string.Format(@"/command:rebase /path:""{0}""", Environment.CurrentDirectory); case ToolbarCommand.FileBlame: return string.Format(@"/command:blame /path:""{0}"" /line:{1}", TestFilePath, CurrentLine); case ToolbarCommand.FileDiff: return string.Format(@"/command:diff /path:""{0}""", TestFilePath); case ToolbarCommand.FileLog: return string.Format(@"/command:log /path:""{0}""", TestFilePath); } throw new InvalidOperationException(string.Format("You need to define an expected test process parameters result for {0}.", toolbarCommand)); }
public void ExecuteTortoiseProc(ToolbarCommand command) { var solutionPath = PathConfiguration.GetSolutionPath(_solution); var openedFilePath = PathConfiguration.GetOpenedFilePath(_solution); // todo: make the bash/tortoise paths configurable // todo: detect if the solution is a git solution first if (command == ToolbarCommand.Bash && PathConfiguration.GetGitBashPath() == null) { MessageBox.Show( Resources.Resources.TortoiseGitLauncherService_ExecuteTortoiseProc_Could_not_find_Git_Bash_in_the_standard_install_path_, Resources.Resources.TortoiseGitLauncherService_ExecuteTortoiseProc_Git_Bash_not_found, MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); return; } if (command != ToolbarCommand.Bash && solutionPath == null) { MessageBox.Show( Resources.Resources.TortoiseGitLauncherService_SolutionPath_You_need_to_open_a_solution_first, Resources.Resources.TortoiseGitLauncherService_SolutionPath_No_solution_found, MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); return; } if (command != ToolbarCommand.Bash && PathConfiguration.GetTortoiseGitPath() == null) { MessageBox.Show( Resources.Resources.TortoiseGitLauncherService_ExecuteTortoiseProc_Could_not_find_TortoiseGit_in_the_standard_install_path_, Resources.Resources.TortoiseGitLauncherService_ExecuteTortoiseProc_TortoiseGit_not_found, MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); return; } ProcessStartInfo process; switch (command) { case ToolbarCommand.Bash: process = _processManagerService.GetProcess( PathConfiguration.GetGitBashPath(), "--login -i", solutionPath ); break; case ToolbarCommand.RebaseContinue: process = _processManagerService.GetProcess( PathConfiguration.GetGitBashPath(), @"--login -i -c 'echo; echo ""Running git rebase --continue""; echo; git rebase --continue; echo; echo ""Please review the output above and press enter to continue.""; read'", solutionPath ); break; case ToolbarCommand.FileLog: case ToolbarCommand.FileDiff: var commandParam = command.ToString().Replace("File", string.Empty).ToLower(); process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), string.Format(@"/command:{0} /path:""{1}""", commandParam, openedFilePath) ); break; case ToolbarCommand.FileBlame: var line = GetCurrentLine(_solution); process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), string.Format(@"/command:blame /path:""{0}"" /line:{1}", openedFilePath, line) ); break; default: process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), string.Format(@"/command:{0} /path:""{1}""", command.ToString().ToLower(), solutionPath) ); break; } if (process != null) Process.Start(process); }
private MenuCommand GetMenuCommand(ToolbarCommand toolbarCommand) { _package.SetSite(_serviceProvider); var getServiceMethod = typeof(Package).GetMethod("GetService", BindingFlags.Instance | BindingFlags.NonPublic); var menuCommandID = new CommandID(PackageConstants.GuidTortoiseGitToolbarCmdSet, (int)toolbarCommand); var menuCommandService = getServiceMethod.Invoke(_package, new object[] { (typeof(IMenuCommandService)) }) as OleMenuCommandService; return menuCommandService != null ? menuCommandService.FindCommand(menuCommandID) : null; }
public void Ensure_all_tortoisegit_commands_exist(ToolbarCommand toolbarCommand) { var command = GetMenuCommand(toolbarCommand); Assert.That(command, Is.Not.Null, string.Format("Couldn't find command for {0}", toolbarCommand)); }
public void ExecuteTortoiseProc(ToolbarCommand command) { var solutionPath = PathConfiguration.GetSolutionPath(_solution); var openedFilePath = PathConfiguration.GetOpenedFilePath(_solution); // todo: make the bash/tortoise paths configurable // todo: detect if the solution is a git solution first if (command == ToolbarCommand.Bash && PathConfiguration.GetGitBashPath() == null) { MessageBox.Show( Resources.Resources.TortoiseGitLauncherService_ExecuteTortoiseProc_Could_not_find_Git_Bash_in_the_standard_install_path_, Resources.Resources.TortoiseGitLauncherService_ExecuteTortoiseProc_Git_Bash_not_found, MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); return; } if (command != ToolbarCommand.Bash && solutionPath == null) { MessageBox.Show( Resources.Resources.TortoiseGitLauncherService_SolutionPath_You_need_to_open_a_solution_first, Resources.Resources.TortoiseGitLauncherService_SolutionPath_No_solution_found, MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); return; } if (command != ToolbarCommand.Bash && PathConfiguration.GetTortoiseGitPath() == null) { MessageBox.Show( Resources.Resources.TortoiseGitLauncherService_ExecuteTortoiseProc_Could_not_find_TortoiseGit_in_the_standard_install_path_, Resources.Resources.TortoiseGitLauncherService_ExecuteTortoiseProc_TortoiseGit_not_found, MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); return; } ProcessStartInfo process; switch (command) { case ToolbarCommand.Bash: process = _processManagerService.GetProcess( PathConfiguration.GetGitBashPath(), "--login -i", solutionPath ); break; case ToolbarCommand.RebaseContinue: process = _processManagerService.GetProcess( PathConfiguration.GetGitBashPath(), @"--login -i -c 'echo; echo ""Running git rebase --continue""; echo; git rebase --continue; echo; echo ""Please review the output above and press enter to continue.""; read'", solutionPath ); break; case ToolbarCommand.FileLog: case ToolbarCommand.FileDiff: var commandParam = command.ToString().Replace("File", string.Empty).ToLower(); process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), $@"/command:{commandParam} /path:""{openedFilePath}""" ); break; case ToolbarCommand.FileBlame: var line = GetCurrentLine(_solution); process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), $@"/command:blame /path:""{openedFilePath}"" /line:{line}" ); break; case ToolbarCommand.StashList: process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), $@"/command:reflog /path:""{solutionPath}"" /ref:""refs/stash""" ); break; //todo:修改Pull操作 case ToolbarCommand.Pull: process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), $@"/command:pull --progress -v --no-rebase ""origin"" /path:""{solutionPath}""" ); break; case ToolbarCommand.SubModuleAdd: process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), $@"/command:subadd /path:""{solutionPath}""" ); break; case ToolbarCommand.SubModuleUpdate: process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), $@"/command:subupdate --recursive --remote /bkpath:""{solutionPath}"" /path:""{solutionPath}""" ); break; default: process = _processManagerService.GetProcess( PathConfiguration.GetTortoiseGitPath(), $@"/command:{command.ToString().ToLower()} /path:""{solutionPath}""" ); break; } if (process != null) { Process.Start(process); } }
public void Ensure_all_tortoisegit_commands_exist(ToolbarCommand toolbarCommand) { var command = GetMenuCommand(toolbarCommand); Assert.NotNull(command); }