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); } } }
private void ReleaseExternalWrites() { Dictionary<string, DocumentLock> modified; lock (_externallyChanged) { if (_externallyChanged.Count == 0) return; modified = new Dictionary<string, DocumentLock>(_externallyChanged, StringComparer.OrdinalIgnoreCase); _externallyChanged.Clear(); } try { foreach (KeyValuePair<string, DocumentLock> file in modified) { ScheduleGitStatus(file.Key); GitItem item = Cache[file.Key]; if (item.IsConflicted) { VisualGitMessageBox mb = new VisualGitMessageBox(Context); DialogResult dr = mb.Show(string.Format(Resources.YourMergeToolSavedXWouldYouLikeItMarkedAsResolved, file.Key), Resources.MergeCompleted, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); switch (dr) { case DialogResult.Yes: using (GitClient c = Context.GetService<IGitClientPool>().GetNoUIClient()) { GitResolveArgs ra = new GitResolveArgs(); ra.ThrowOnError = false; c.Resolve(file.Key, GitAccept.Merged, ra); } goto case DialogResult.No; case DialogResult.No: if (!item.IsModified) { // Reload? } break; default: // Let VS handle the file return; // No reload } } if (!item.IsDocumentDirty) { if (file.Value != null) file.Value.Reload(file.Key); } } } catch (Exception ex) { IVisualGitErrorHandler eh = GetService<IVisualGitErrorHandler>(); if (eh != null && eh.IsEnabled(ex)) eh.OnError(ex); else throw; } finally { foreach (DocumentLock dl in modified.Values) { if (dl != null) dl.Dispose(); } } }