public override void OnExecute(CommandEventArgs e) { GitPushArgs args = new GitPushArgs(); string repositoryRoot; var repositoryRoots = new HashSet<string>(FileSystemUtil.StringComparer); foreach (var projectRoot in GetAllRoots(e)) { if ( GitTools.TryGetRepositoryRoot(projectRoot.FullPath, out repositoryRoot) && !repositoryRoots.Contains(repositoryRoot) ) repositoryRoots.Add(repositoryRoot); } if (repositoryRoots.Count > 1) { throw new InvalidOperationException("Pushing of multiple repository roots is not supported"); } repositoryRoot = repositoryRoots.Single(); switch (e.Command) { case VisualGitCommand.PendingChangesPushSpecificBranch: case VisualGitCommand.PendingChangesPushSpecificTag: if (!QueryParameters(e, repositoryRoot, args)) return; break; } ProgressRunnerArgs pa = new ProgressRunnerArgs(); pa.CreateLog = true; pa.TransportClientArgs = args; GitException exception = null; e.GetService<IProgressRunner>().RunModal(CommandStrings.PushingSolution, pa, delegate(object sender, ProgressWorkerArgs a) { using (var client = e.GetService<IGitClientPool>().GetNoUIClient()) { try { client.Push(repositoryRoot, args); } catch (GitException ex) { exception = ex; } } }); if (exception != null) { e.GetService<IVisualGitErrorHandler>().OnWarning(exception); } }
private bool QueryParameters(CommandEventArgs e, string repositoryRoot, GitPushArgs args) { using (var dialog = new PushDialog()) { dialog.Args = args; dialog.RepositoryPath = repositoryRoot; switch (e.Command) { case VisualGitCommand.PendingChangesPushSpecificBranch: dialog.Type = PushDialog.PushType.Branch; break; case VisualGitCommand.PendingChangesPushSpecificTag: dialog.Type = PushDialog.PushType.Tag; break; default: throw new NotSupportedException(); } return dialog.ShowDialog(e.Context) == DialogResult.OK; } }