public override void OnExecute(CommandEventArgs e) { List<GitOrigin> selected = new List<GitOrigin>(); IFileStatusCache cache = e.GetService<IFileStatusCache>(); switch (e.Command) { case VisualGitCommand.Log: IVisualGitDiffHandler diffHandler = e.GetService<IVisualGitDiffHandler>(); List<GitOrigin> items = new List<GitOrigin>(); foreach (GitItem i in e.Selection.GetSelectedGitItems(false)) { Debug.Assert(i.IsVersioned); if (i.IsAdded) { if (!i.HasCopyableHistory) continue; items.Add(new GitOrigin(diffHandler.GetCopyOrigin(i), i.WorkingCopy.RepositoryRoot)); continue; } items.Add(new GitOrigin(i)); } PerformLog(e.Context, items, null, null); break; case VisualGitCommand.SolutionHistory: IVisualGitSolutionSettings settings = e.GetService<IVisualGitSolutionSettings>(); PerformLog(e.Context, new GitOrigin[] { new GitOrigin(cache[settings.ProjectRoot]) }, null, null); break; case VisualGitCommand.ProjectHistory: IProjectFileMapper mapper = e.GetService<IProjectFileMapper>(); foreach (GitProject p in e.Selection.GetSelectedProjects(false)) { IGitProjectInfo info = mapper.GetProjectInfo(p); if (info != null) selected.Add(new GitOrigin(cache[info.ProjectDirectory])); } PerformLog(e.Context, selected, null, null); break; case VisualGitCommand.DocumentHistory: GitItem docItem = e.Selection.ActiveDocumentItem; Debug.Assert(docItem != null); PerformLog(e.Context, new GitOrigin[] { new GitOrigin(docItem) }, null, null); break; case VisualGitCommand.AnnotateShowLog: IAnnotateSection section = EnumTools.GetSingle(e.Selection.GetSelection<IAnnotateSection>()); if (section == null) return; PerformLog(e.Context, new GitOrigin[] { section.Origin }, section.Revision, null); break; } }
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); } }
public void OnExecute(CommandEventArgs e) { if (_commandService == null) _commandService = e.GetService<IVisualGitCommandService>(); if (_pendingChanges == null) _pendingChanges = e.GetService<PendingChangeManager>(typeof(IPendingChangesManager)); _commandService.TockCommand(e.Command); _pendingChanges.OnTickRefresh(); }
public void OnExecute(CommandEventArgs e) { if (_commandService == null) _commandService = e.GetService<IVisualGitCommandService>(); if (_projectNotifier == null) _projectNotifier = e.GetService<ProjectNotifier>(typeof(IFileStatusMonitor)); _commandService.TockCommand(e.Command); _projectNotifier.HandleEvent(e.Command); }
public override void OnExecute(CommandEventArgs e) { GitItem node = EnumTools.GetFirst(e.Selection.GetSelectedGitItems(false)); IVisualGitCommandService cmd = e.GetService<IVisualGitCommandService>(); switch (e.Command) { case VisualGitCommand.ItemSelectInWorkingCopyExplorer: if (node == null || !node.Exists) return; if (cmd != null) cmd.DirectlyExecCommand(VisualGitCommand.WorkingCopyBrowse, node.FullPath); break; case VisualGitCommand.ItemSelectInSolutionExplorer: if (node == null) return; IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer)); IVsProject project = VsShellUtilities.GetProject(e.Context, node.FullPath) as IVsProject; if (hierWindow != null) { int found; uint id; VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1]; if (project != null && ErrorHandler.Succeeded(project.IsDocumentInProject(node.FullPath, out found, prio, out id)) && found != 0) { hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem); } else if (string.Equals(node.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase)) hierWindow.ExpandItem(e.GetService<IVsUIHierarchy>(typeof(SVsSolution)), VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_SelectItem); // Now try to activate the solution explorer IVsWindowFrame solutionExplorer; Guid solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer); IVsUIShell shell = e.GetService<IVsUIShell>(typeof(SVsUIShell)); if (shell != null) { shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer); if (solutionExplorer != null) solutionExplorer.Show(); } } break; } }
public void OnExecute(CommandEventArgs e) { if (_commandService == null) _commandService = e.GetService<IVisualGitCommandService>(); if (_fileCache == null) _fileCache = e.GetService<FileStatusCache>(typeof(IFileStatusCache)); _commandService.TockCommand(e.Command); if (e.Command == VisualGitCommand.FileCacheFinishTasks) _fileCache.OnCleanup(); else _fileCache.BroadcastChanges(); }
public void OnExecute(CommandEventArgs e) { if (_commandService == null) _commandService = e.GetService<IVisualGitCommandService>(); if (_projectTracker == null) _projectTracker = e.GetService<ProjectTracker>(typeof(IVisualGitProjectDocumentTracker)); if(_sccProvider == null) _sccProvider = e.GetService<VisualGitSccProvider>(typeof(IVisualGitSccService)); _commandService.TockCommand(e.Command); _projectTracker.OnSccCleanup(e); _sccProvider.OnSccCleanup(e); }
public override void OnExecute(CommandEventArgs e) { PathSelectorResult result = ShowDialog(e); if (!result.Succeeded) return; GitRevisionRange revRange = new GitRevisionRange(result.RevisionStart, result.RevisionEnd); IVisualGitTempFileManager tempfiles = e.GetService<IVisualGitTempFileManager>(); string tempFile = tempfiles.GetTempFile(".patch"); IVisualGitSolutionSettings ss = e.GetService<IVisualGitSolutionSettings>(); string slndir = ss.ProjectRoot; string slndirP = slndir + "\\"; GitDiffArgs args = new GitDiffArgs(); args.IgnoreAncestry = true; args.NoDeleted = false; args.Depth = result.Depth; using (MemoryStream stream = new MemoryStream()) { e.Context.GetService<IProgressRunner>().RunModal("Diffing", delegate(object sender, ProgressWorkerArgs ee) { foreach (GitItem item in result.Selection) { GitWorkingCopy wc; if (!string.IsNullOrEmpty(slndir) && item.FullPath.StartsWith(slndirP, StringComparison.OrdinalIgnoreCase)) args.RelativeToPath = slndir; else if ((wc = item.WorkingCopy) != null) args.RelativeToPath = wc.FullPath; else args.RelativeToPath = null; ee.Client.Diff(item.FullPath, revRange, args, stream); } stream.Flush(); stream.Position = 0; }); using (StreamReader sr = new StreamReader(stream)) { File.WriteAllText(tempFile, sr.ReadToEnd(), Encoding.UTF8); VsShellUtilities.OpenDocument(e.Context, tempFile); } } }
public override void OnExecute(CommandEventArgs e) { using (ProjectCommitDialog pcd = new ProjectCommitDialog()) { pcd.Context = e.Context; pcd.LogMessageText = storedLogMessage; pcd.AmendLastCommit = storedAmendCommit; pcd.PreserveWindowPlacement = true; pcd.LoadItems(e.Selection.GetSelectedGitItems(true)); DialogResult dr = pcd.ShowDialog(e.Context); storedLogMessage = pcd.LogMessageText; storedAmendCommit = pcd.AmendLastCommit; if (dr != DialogResult.OK) return; PendingChangeCommitArgs pca = new PendingChangeCommitArgs(); pca.StoreMessageOnError = true; // TODO: Commit it! List<PendingChange> toCommit = new List<PendingChange>(pcd.GetSelection()); pcd.FillArgs(pca); e.GetService<IPendingChangeHandler>().Commit(toCommit, pca); } // not in the finally, because we want to preserve the message for a // non-successful commit storedLogMessage = null; storedAmendCommit = false; }
public override void OnExecute(CommandEventArgs e) { using (ProjectCommitDialog dlg = new ProjectCommitDialog()) { dlg.Context = e.Context; dlg.PreserveWindowPlacement = true; dlg.LoadChanges(GetChanges(e)); dlg.LogMessageText = logMessage ?? ""; DialogResult dr = dlg.ShowDialog(e.Context); logMessage = dlg.LogMessageText; if (dr == DialogResult.OK) { PendingChangeCommitArgs pca = new PendingChangeCommitArgs(); pca.StoreMessageOnError = true; // TODO: Commit it! List<PendingChange> toCommit = new List<PendingChange>(dlg.GetSelection()); dlg.FillArgs(pca); if (e.GetService<IPendingChangeHandler>().Commit(toCommit, pca)) { logMessage = null; } } } }
public override void OnExecute(CommandEventArgs e) { using (CloneDialog dialog = new CloneDialog()) { if (dialog.ShowDialog(e.Context) != DialogResult.OK) return; using (var client = e.GetService<IGitClientPool>().GetNoUIClient()) { } GitCloneArgs args = new GitCloneArgs(); ProgressRunnerArgs pa = new ProgressRunnerArgs(); pa.CreateLog = true; pa.TransportClientArgs = args; string destination = Path.GetFullPath(dialog.Destination); GitException exception = null; e.GetService<IProgressRunner>().RunModal(CommandStrings.CloningRepository, pa, delegate(object sender, ProgressWorkerArgs a) { try { a.Client.Clone(dialog.Remote, dialog.RemoteRef, destination, args); } catch (GitException ex) { exception = ex; } }); if (exception != null) { e.GetService<IVisualGitErrorHandler>().OnWarning(exception); } else { IVsSolution2 sol = e.GetService<IVsSolution2>(typeof(SVsSolution)); sol.OpenSolutionViaDlg(destination, 1); } } }
public override void OnExecute(CommandEventArgs e) { List<GitItem> toResolve = new List<GitItem>(); foreach (GitItem item in e.Selection.GetSelectedGitItems(false)) { if (item.IsCasingConflicted) { toResolve.Add(item); } } try { foreach (GitItem item in toResolve) { string svnPath = GetGitCasing(e, item); string actualPath = GitTools.GetTruePath(item.FullPath); if (svnPath == null || actualPath == null) continue; // not found if (!string.Equals(svnPath, actualPath, StringComparison.OrdinalIgnoreCase)) continue; // More than casing rename string svnName = Path.GetFileName(svnPath); string actualName = Path.GetFileName(actualPath); if (svnName == actualName) continue; // Can't fix directories! IVisualGitOpenDocumentTracker odt = e.GetService<IVisualGitOpenDocumentTracker>(); using (odt.LockDocument(svnPath, DocumentLockType.NoReload)) using (odt.LockDocument(actualPath, DocumentLockType.NoReload)) { try { // Try the actual rename File.Move(actualPath, svnPath); } catch { } try { // And try to fix the project+document system VsShellUtilities.RenameDocument(e.Context, actualPath, svnPath); } catch { } } } } finally { e.GetService<IFileStatusMonitor>().ScheduleGitStatus(GitItem.GetPaths(toResolve)); } }
public override void OnExecute(CommandEventArgs e) { IFileStatusCache cache = e.GetService<IFileStatusCache>(); if (cache == null || e.Selection.SolutionFilename == null) return; GitItem item = cache[e.Selection.SolutionFilename]; HandleUnmanagedOrUnversionedSolution(e, item); }
public override void OnExecute(CommandEventArgs e) { IVisualGitSolutionSettings ss = e.GetService<IVisualGitSolutionSettings>(); IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>(); VisualGitPatchArgs args = new VisualGitPatchArgs(); args.ApplyTo = ss.ProjectRoot; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "Patch files( *.patch)|*.patch|Diff files (*.diff)|*.diff|" + "Text files (*.txt)|*.txt|All files (*.*)|*"; if (ofd.ShowDialog(e.Context.DialogOwner) != DialogResult.OK) return; args.PatchFile = ofd.FileName; } diff.RunPatch(args); }
public override void OnExecute(CommandEventArgs e) { string info; if (e.Argument is string) { // Allow opening from info = (string)e.Argument; } else if (e.Command == VisualGitCommand.WorkingCopyAdd) { using (AddWorkingCopyExplorerRootDialog dlg = new AddWorkingCopyExplorerRootDialog()) { DialogResult dr = dlg.ShowDialog(e.Context); if (dr != DialogResult.OK || string.IsNullOrEmpty(dlg.NewRoot)) return; info = dlg.NewRoot; } } else throw new InvalidOperationException("WorkingCopyBrowse was called without a path"); if (!string.IsNullOrEmpty(info)) { WorkingCopyExplorerControl ctrl = e.Selection.ActiveDialogOrFrameControl as WorkingCopyExplorerControl; if (ctrl == null) { IVisualGitPackage pkg = e.GetService<IVisualGitPackage>(); pkg.ShowToolWindow(VisualGitToolWindow.WorkingCopyExplorer); } ctrl = e.Selection.ActiveDialogOrFrameControl as WorkingCopyExplorerControl; if (ctrl != null) { switch (e.Command) { case VisualGitCommand.WorkingCopyAdd: ctrl.AddRoot(info); break; case VisualGitCommand.WorkingCopyBrowse: ctrl.BrowsePath(e.Context, info); break; } } } }
public override void OnExecute(CommandEventArgs e) { IFileStatusMonitor fsm = e.GetService<IFileStatusMonitor>(); foreach (GitItem i in GetSelection(e)) { if (i.InSolution) continue; if (e.Command == VisualGitCommand.ItemAddToPending || e.Command == VisualGitCommand.DocumentAddToPending) fsm.ScheduleMonitor(i.FullPath); else fsm.StopMonitoring(i.FullPath); } }
public override void OnExecute(CommandEventArgs e) { // Refresh all global states on the selected files // * File Status Cache // * Glyph cache (in VS Projects) // * Pending changes // * Editor dirty state // Don't handle individual windows here, they can just override the refresh handler // See WorkingCopyExplorerControl.OnFrameCreated() for some examples on how to do that IFileStatusMonitor monitor = e.GetService<IFileStatusMonitor>(); monitor.ScheduleGitStatus(e.Selection.GetSelectedFiles(true), true); IVisualGitOpenDocumentTracker dt = e.GetService<IVisualGitOpenDocumentTracker>(); dt.RefreshDirtyState(); IPendingChangesManager pm = e.GetService<IPendingChangesManager>(); pm.Refresh((string)null); // Perform a full incremental refresh on the PC window }
public void OnExecute(CommandEventArgs e) { // All checked in OnUpdate ILogControl logWindow = e.Selection.GetActiveControl<ILogControl>(); GitOrigin origin = EnumTools.GetSingle(logWindow.Origins); IGitLogItem item = EnumTools.GetSingle(e.Selection.GetSelection<IGitLogItem>()); IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>(); VisualGitDiffArgs da = new VisualGitDiffArgs(); da.BaseFile = diff.GetTempFile(origin.Target, item.Revision, true); if (da.BaseFile == null) return; // User cancel da.MineFile = origin.Target.FullPath; da.BaseTitle = string.Format("Base (r{0})", item.Revision); da.MineTitle = "Working"; diff.RunDiff(da); }
public override void OnExecute(CommandEventArgs e) { using (ExportDialog dlg = new ExportDialog(e.Context)) { dlg.OriginPath = EnumTools.GetSingle(e.Selection.GetSelectedGitItems(false)).FullPath; if (dlg.ShowDialog(e.Context) != DialogResult.OK) return; GitDepth depth = dlg.NonRecursive ? GitDepth.Empty : GitDepth.Infinity; e.GetService<IProgressRunner>().RunModal(CommandStrings.Exporting, delegate(object sender, ProgressWorkerArgs wa) { GitExportArgs args = new GitExportArgs(); args.Depth = depth; args.Revision = dlg.Revision; wa.Client.Export(dlg.ExportSource, dlg.LocalPath, args); }); } }
public override void OnExecute(CommandEventArgs e) { List<GitItem> toRevert = new List<GitItem>(); HybridCollection<string> contained = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase); HybridCollection<string> checkedItems = null; foreach (GitItem i in e.Selection.GetSelectedGitItems(false)) { if (contained.Contains(i.FullPath)) continue; contained.Add(i.FullPath); if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty) || i.IsConflicted) toRevert.Add(i); } Predicate<GitItem> initialCheckedFilter = null; if (toRevert.Count > 0) { checkedItems = new HybridCollection<string>(contained, StringComparer.OrdinalIgnoreCase); initialCheckedFilter = delegate(GitItem item) { return checkedItems.Contains(item.FullPath); }; } foreach (GitItem i in e.Selection.GetSelectedGitItems(true)) { if (contained.Contains(i.FullPath)) continue; contained.Add(i.FullPath); if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty)) toRevert.Add(i); } if (e.PromptUser || (!e.DontPrompt && !Shift)) { using (PendingChangeSelector pcs = new PendingChangeSelector()) { pcs.Text = CommandStrings.RevertDialogTitle; pcs.PreserveWindowPlacement = true; pcs.LoadItems(toRevert, null, initialCheckedFilter); if (pcs.ShowDialog(e.Context) != DialogResult.OK) return; toRevert.Clear(); toRevert.AddRange(pcs.GetSelectedItems()); } } IVisualGitOpenDocumentTracker documentTracker = e.GetService<IVisualGitOpenDocumentTracker>(); ICollection<string> revertPaths = GitItem.GetPaths(toRevert); documentTracker.SaveDocuments(revertPaths); // perform the actual revert using (DocumentLock dl = documentTracker.LockDocuments(revertPaths, DocumentLockType.NoReload)) using (dl.MonitorChangesForReload()) { e.GetService<IProgressRunner>().RunModal(CommandStrings.Reverting, delegate(object sender, ProgressWorkerArgs a) { GitRevertItemArgs ra = new GitRevertItemArgs(); ra.Depth = GitDepth.Empty; List<string> toRevertPaths = new List<string>(); foreach (GitItem item in toRevert) { toRevertPaths.Add(item.FullPath); } foreach (GitItem item in toRevert) { try { a.Client.RevertItem(toRevertPaths, ra); } catch (GitNoRepositoryException) { // Ignore path no repository exceptions. } } }); } }
static void Resolve(CommandEventArgs e, GitAccept accept) { HybridCollection<string> paths = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase); foreach (GitItem item in e.Selection.GetSelectedGitItems(true)) { if (!item.IsConflicted) continue; if (!paths.Contains(item.FullPath)) paths.Add(item.FullPath); } IVisualGitOpenDocumentTracker documentTracker = e.GetService<IVisualGitOpenDocumentTracker>(); documentTracker.SaveDocuments(paths); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(paths, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) using (GitClient client = e.GetService<IGitClientPool>().GetNoUIClient()) { GitResolveArgs a = new GitResolveArgs(); a.Depth = GitDepth.Empty; foreach (string p in paths) { client.Resolve(p, accept, a); } } }
static PathSelectorResult ShowDialog(CommandEventArgs e) { PathSelectorInfo info = new PathSelectorInfo("Select items for diffing", e.Selection.GetSelectedGitItems(true)); IUIShell uiShell = e.GetService<IUIShell>(); info.VisibleFilter += delegate { return true; }; info.CheckedFilter += delegate(GitItem item) { return item.IsFile && (item.IsModified || item.IsDocumentDirty); }; info.RevisionStart = GitRevision.Base; info.RevisionEnd = GitRevision.Working; // should we show the path selector? if (!Shift) { return uiShell.ShowPathSelector(info); } return info.DefaultResult; }
public override void OnExecute(CommandEventArgs e) { Dictionary<string, List<string>> add = new Dictionary<string, List<string>>(FileSystemUtil.StringComparer); List<string> refresh = new List<string>(); foreach (GitItem i in e.Selection.GetSelectedGitItems(false)) { if (Skip(i)) continue; refresh.Add(i.FullPath); switch (e.Command) { case VisualGitCommand.ItemIgnoreFile: AddIgnore(add, i.Parent, "/" + i.Name); break; case VisualGitCommand.ItemIgnoreFileType: AddIgnore(add, i.Parent, "/*" + i.Extension); break; case VisualGitCommand.ItemIgnoreFilesInFolder: AddIgnore(add, i.Parent, "/*"); break; case VisualGitCommand.ItemIgnoreFolder: GitItem p = i.Parent; GitItem pp = null; while (null != p && null != (pp = p.Parent) && !pp.IsVersioned) p = pp; if (p != null && pp != null) AddIgnore(add, pp, "/" + p.Name + "/"); break; } } try { VisualGitMessageBox mb = new VisualGitMessageBox(e.Context); foreach (KeyValuePair<string, List<string>> k in add) { if (k.Value.Count == 0) continue; string text; if (k.Value.Count == 1) text = "'" + k.Value[0] + "'"; else { StringBuilder sb = new StringBuilder(); for (int i = 0; i < k.Value.Count; i++) { if (i == 0) sb.AppendFormat("'{0}'", k.Value[i]); else if (i == k.Value.Count - 1) sb.AppendFormat(" and '{0}'", k.Value[i]); else sb.AppendFormat(", '{0}'", k.Value[i]); } text = sb.ToString(); } switch (mb.Show(string.Format(CommandStrings.WouldYouLikeToAddXToTheIgnorePropertyOnY, text, k.Key), CommandStrings.IgnoreCaption, System.Windows.Forms.MessageBoxButtons.YesNoCancel)) { case System.Windows.Forms.DialogResult.Yes: PerformAddIgnores(e, k); break; case System.Windows.Forms.DialogResult.No: continue; default: return; } } } finally { e.GetService<IFileStatusMonitor>().ScheduleGitStatus(refresh); } }
public override void OnExecute(CommandEventArgs e) { GitItem theItem = null; string path; GitRef currentBranch = null; string projectRoot = e.GetService<IVisualGitSolutionSettings>().ProjectRoot; if (e.Command == VisualGitCommand.SolutionSwitchDialog) path = projectRoot; else if (e.Command == VisualGitCommand.SwitchProject) { IProjectFileMapper mapper = e.GetService<IProjectFileMapper>(); path = null; foreach (GitProject item in e.Selection.GetSelectedProjects(true)) { IGitProjectInfo pi = mapper.GetProjectInfo(item); if (pi == null) continue; path = pi.ProjectDirectory; break; } if (string.IsNullOrEmpty(path)) return; } else if (e.Command == VisualGitCommand.LogSwitchToRevision) { IGitLogItem item = EnumTools.GetSingle(e.Selection.GetSelection<IGitLogItem>()); if (item == null) return; path = item.RepositoryRoot; currentBranch = new GitRef(item.Revision); } else { foreach (GitItem item in e.Selection.GetSelectedGitItems(false)) { if (item.IsVersioned) { theItem = item; break; } return; } path = theItem.FullPath; } IFileStatusCache statusCache = e.GetService<IFileStatusCache>(); GitItem pathItem = statusCache[path]; if (currentBranch == null) { using (var client = e.GetService<IGitClientPool>().GetNoUIClient()) { currentBranch = client.GetCurrentBranch(pathItem.FullPath); } if (currentBranch == null) return; // Should never happen on a real workingcopy } GitRef target; bool force = false; if (e.Argument is string) { target = new GitRef((string)e.Argument); } else using (SwitchDialog dlg = new SwitchDialog()) { dlg.GitOrigin = new GitOrigin(pathItem); dlg.Context = e.Context; dlg.LocalPath = GitTools.GetRepositoryRoot(path); dlg.SwitchToBranch = currentBranch; if (dlg.ShowDialog(e.Context) != DialogResult.OK) return; target = dlg.SwitchToBranch; force = dlg.Force; } // Get a list of all documents below the specified paths that are open in editors inside VS HybridCollection<string> lockPaths = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase); IVisualGitOpenDocumentTracker documentTracker = e.GetService<IVisualGitOpenDocumentTracker>(); foreach (string file in documentTracker.GetDocumentsBelow(path)) { if (!lockPaths.Contains(file)) lockPaths.Add(file); } documentTracker.SaveDocuments(lockPaths); // Make sure all files are saved before merging! using (DocumentLock lck = documentTracker.LockDocuments(lockPaths, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { GitSwitchArgs args = new GitSwitchArgs(); GitException exception = null; e.GetService<IProgressRunner>().RunModal( "Changing Current Branch", delegate(object sender, ProgressWorkerArgs a) { args.Force = force; // TODO: Decide whether it is necessary for the switch // command to report conflicts. #if NOT_IMPLEMENTED e.GetService<IConflictHandler>().RegisterConflictHandler(args, a.Synchronizer); #endif try { a.Client.Switch(path, target, args); } catch (GitException ex) { exception = ex; } }); if (exception != null) { e.GetService<IVisualGitErrorHandler>().OnWarning(exception); } } }
public override void OnExecute(CommandEventArgs e) { VisualGitMessageBox mb = new VisualGitMessageBox(e.Context); foreach (GitItem item in e.Selection.GetSelectedGitItems(false)) { if (!item.Exists) continue; try { switch (e.Command) { case VisualGitCommand.ItemOpenVisualStudio: IProjectFileMapper mapper = e.GetService<IProjectFileMapper>(); if (mapper.IsProjectFileOrSolution(item.FullPath)) goto case VisualGitCommand.ItemOpenSolutionExplorer; if (item.IsDirectory) goto case VisualGitCommand.ItemOpenFolder; if (!item.IsFile || !item.Exists) continue; VsShellUtilities.OpenDocument(e.Context, item.FullPath); break; case VisualGitCommand.ItemOpenTextEditor: { IVsUIHierarchy hier; IVsWindowFrame frame; uint id; if (!item.IsFile) continue; VsShellUtilities.OpenDocument(e.Context, item.FullPath, VSConstants.LOGVIEWID_TextView, out hier, out id, out frame); } break; case VisualGitCommand.ItemOpenFolder: if (!item.IsDirectory) System.Diagnostics.Process.Start(Path.GetDirectoryName(item.FullPath)); else System.Diagnostics.Process.Start(item.FullPath); break; case VisualGitCommand.ItemOpenWindows: System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(item.FullPath); psi.Verb = "open"; System.Diagnostics.Process.Start(psi); break; case VisualGitCommand.ItemOpenSolutionExplorer: IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer)); IVsProject project = VsShellUtilities.GetProject(e.Context, item.FullPath) as IVsProject; if (hierWindow != null) { int found; uint id; VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1]; if (project != null && ErrorHandler.Succeeded(project.IsDocumentInProject(item.FullPath, out found, prio, out id)) && found != 0) { hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem); } else if (string.Equals(item.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase)) hierWindow.ExpandItem(e.GetService<IVsUIHierarchy>(typeof(SVsSolution)), VSConstants.VSITEMID_ROOT, EXPANDFLAGS.EXPF_SelectItem); // Now try to activate the solution explorer IVsWindowFrame solutionExplorer; Guid solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer); IVsUIShell shell = e.GetService<IVsUIShell>(typeof(SVsUIShell)); if (shell != null) { shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer); if (solutionExplorer != null) solutionExplorer.Show(); } } break; } } catch (IOException ee) { e.GetService<IVisualGitErrorHandler>().OnWarning(ee); } catch (COMException ee) { e.GetService<IVisualGitErrorHandler>().OnWarning(ee); } catch (InvalidOperationException ee) { e.GetService<IVisualGitErrorHandler>().OnWarning(ee); } catch (System.ComponentModel.Win32Exception ee) { e.GetService<IVisualGitErrorHandler>().OnWarning(ee); } } }
void OnExecuteGet(CommandEventArgs e) { if (ProjectRoot != null) { string repositoryPath; if (GitTools.TryGetRepositoryRoot(ProjectRoot, out repositoryPath)) { using (var client = e.GetService<IGitClientPool>().GetNoUIClient()) { var repositoryBranch = client.GetCurrentBranch(repositoryPath); if (repositoryBranch.Type == GitRefType.Unknown) e.Result = Properties.Resources.NoBranch; else e.Result = repositoryBranch.ShortName; } } } }
public override void OnExecute(CommandEventArgs e) { // TODO: Choose which conflict to edit if we have more than one! GitItem conflict = null; if (e.Command == VisualGitCommand.DocumentConflictEdit) { conflict = e.Selection.ActiveDocumentItem; if (conflict == null || !conflict.IsConflicted) return; } else foreach (GitItem item in e.Selection.GetSelectedGitItems(false)) { if (item.IsConflicted) { conflict = item; break; } } if (conflict == null) return; conflict.MarkDirty(); if (conflict.Status.State != GitStatus.Conflicted) { VisualGitMessageBox mb = new VisualGitMessageBox(e.Context); mb.Show(string.Format(CommandStrings.TheConflictInXIsAlreadyResolved, conflict.FullPath), CommandStrings.EditConflictTitle, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); return; } GitInfoArgs args = new GitInfoArgs(); args.PrepareMerge = true; GitInfoEventArgs conflictInfo = null; bool ok = false; ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal("Retrieving Conflict Information", delegate(object sender, ProgressWorkerArgs a) { ok = a.Client.GetInfo(conflict.FullPath, args, out conflictInfo); }); if (!ok || !r.Succeeded || conflictInfo == null) return; VisualGitMergeArgs da = new VisualGitMergeArgs(); string dir = conflict.Directory; da.BaseFile = Path.Combine(dir, conflictInfo.ConflictOld ?? conflictInfo.ConflictNew); da.TheirsFile = Path.Combine(dir, conflictInfo.ConflictNew ?? conflictInfo.ConflictOld); if (!string.IsNullOrEmpty(conflictInfo.ConflictWork)) da.MineFile = Path.Combine(dir, conflictInfo.ConflictWork); else da.MineFile = conflict.FullPath; da.MergedFile = conflict.FullPath; da.BaseTitle = "Base"; da.TheirsTitle = "Theirs"; da.MineTitle = "Mine"; da.MergedTitle = conflict.Name; da.CleanupFiles = new string[] { conflictInfo.ConflictNew, conflictInfo.ConflictOld, conflictInfo.ConflictWork }; e.GetService<IVisualGitDiffHandler>().RunMerge(da); }
void OnExecuteSet(CommandEventArgs e) { string value = (string)e.Argument; IVisualGitCommandService cs = e.GetService<IVisualGitCommandService>(); if (value == null) cs.PostExecCommand(VisualGitCommand.SolutionSwitchDialog); else cs.PostExecCommand(VisualGitCommand.SolutionSwitchDialog, value); }
static void Resolved(CommandEventArgs e) { using (GitClient client = e.GetService<IGitClientPool>().GetNoUIClient()) { foreach (GitItem item in e.Selection.GetSelectedGitItems(true)) { if (!item.IsConflicted) continue; client.Resolved(item.FullPath); } } }
void ExecuteDiff(CommandEventArgs e, ICollection<GitOrigin> targets, GitRevisionRange range) { if (targets.Count != 1) return; var target = EnumTools.GetSingle(targets); GitTarget diffTarget = target.Target; IVisualGitDiffHandler diff = e.GetService<IVisualGitDiffHandler>(); VisualGitDiffArgs da = new VisualGitDiffArgs(); string[] files = diff.GetTempFiles(diffTarget, range.StartRevision, range.EndRevision, true); if (files == null) return; da.BaseFile = files[0]; da.MineFile = files[1]; da.BaseTitle = diff.GetTitle(diffTarget, range.StartRevision); da.MineTitle = diff.GetTitle(diffTarget, range.EndRevision); da.ReadOnly = true; diff.RunDiff(da); }