private static bool ResolveConflicts(ITfsTemporaryWorkspace tempWorkspace, ref bool finished) { bool hadConflicts = false; while (tempWorkspace.Conflicts.Count != 0) { hadConflicts = true; int oldConflictsCount = tempWorkspace.Conflicts.Count; SimpleLogger.Checkpoint("PerformMerge: Resolving conflict ({0} remaining)", oldConflictsCount); //Repository.Instance.TfsUIInteractionProvider.ResolveConflictsInternally(tempWorkspace); //return false; Repository.Instance.TfsUIInteractionProvider.ResolveConflictsPerTF(tempWorkspace.MappedFolder); SimpleLogger.Checkpoint("PerformMerge: Finished resolving conflict ({0} remaining)", oldConflictsCount); tempWorkspace.RefreshConflicts(); if (tempWorkspace.Conflicts.Count == oldConflictsCount) { MessageBoxViewModel mbvm = new MessageBoxViewModel("Cancel merge?", "There are conflicts remaining to be resolved. Really cancel the merge?", MessageBoxViewModel.MessageBoxButtons.None); var yesButton = new MessageBoxViewModel.MessageBoxButton("_Yes"); mbvm.ConfirmButtons.Add(yesButton); mbvm.ConfirmButtons.Add(new MessageBoxViewModel.MessageBoxButton("_No")); Repository.Instance.ViewManager.ShowModal(mbvm); if (yesButton.IsChecked) { finished = false; break; } } } return(hadConflicts); }
public bool ResolveConflictsInternally(ITfsTemporaryWorkspace workspace) { try { var MicrosoftVisualStudioTeamFoundationVersionControlControlsDll = AppDomain.CurrentDomain.GetAssemblies().Where(ass => ass.GetName().Name == "Microsoft.TeamFoundation.VersionControl.Controls").FirstOrDefault(); if (MicrosoftVisualStudioTeamFoundationVersionControlControlsDll == null) { return(false); } var resolveConflictsManagerType = MicrosoftVisualStudioTeamFoundationVersionControlControlsDll.GetTypes().Where(type => type.Name == "ResolveConflictsManager" && type.Namespace == "Microsoft.VisualStudio.TeamFoundation.VersionControl").FirstOrDefault(); if (resolveConflictsManagerType == null) { return(false); } dynamic mgr = Activator.CreateInstance(resolveConflictsManagerType); mgr.Initialize(); mgr.ResolveConflicts((Workspace)workspace.TfsWorkspace, new string[] { workspace.MappedFolder }, true, false); mgr.Dispose(); return(true); } catch (Exception ex) { SimpleLogger.Log(ex, true); return(false); } }
void EmbeddedCheckInSummaryViewModel_Finished(object sender, ViewModelFinishedEventArgs e) { if (!EmbeddedCheckInSummaryViewModel.Cancelled) { CommitMerge(EmbeddedCheckInSummaryViewModel); } _temporaryWorkspace.UndoAllPendingChanges(); _temporaryWorkspace = null; EmbeddedCheckInSummaryViewModel.Finished -= EmbeddedCheckInSummaryViewModel_Finished; EmbeddedCheckInSummaryViewModel = null; }
bool PerformMerge(ChangesetListElement item, TrackProgressParameters externalProgress = null) { SimpleLogger.Checkpoint("PerformMerge: Starting"); bool returnValue = false; bool undoPendingChanges = true; if (item == null) { return(false); } SimpleLogger.Checkpoint("PerformMerge: Getting temporary workspace"); var tempWorkspace = Repository.Instance.TfsBridgeProvider.GetTemporaryWorkspace(MergeSource, MergeTarget); SimpleLogger.Checkpoint("PerformMerge: Undoing pending changes in temporary workspace"); tempWorkspace.UndoAllPendingChanges(); try { var mergeChangeset = TfsItemCache.GetChangesetFromCache(item.SourceCheckinId).TfsChangeset; bool finished = false; try { finished = Repository.Instance.BackgroundTaskManager.RunWithCancelDialog( (progressParams) => { tempWorkspace.Merge( MergeTarget, PathFilter, new ITfsChangeset[] { mergeChangeset }.AsEnumerable(), progressParams.TrackProgress); }, String.Format("Merging changeset #{0} ...", item.SourceCheckinId), externalProgress); } catch (AggregateException ex) { bool otherExceptions = false; foreach (var iex in ex.InnerExceptions) { if (iex is LocalPathTooLongException) { DisplayPathTooLongHelp(); } else { SimpleLogger.Log(ex, false, false); otherExceptions = true; } } if (otherExceptions) { SimpleLogger.Log(ex, true); } } catch (LocalPathTooLongException) { DisplayPathTooLongHelp(); return(false); } catch (Exception ex) { SimpleLogger.Log(ex); return(false); } if (!finished) { return(false); } SimpleLogger.Checkpoint("PerformMerge: Building check-in summary"); var checkInSummary = new CheckInSummaryViewModel(); SimpleLogger.Checkpoint("PerformMerge: Refreshing conflicts"); tempWorkspace.RefreshConflicts(); SimpleLogger.Checkpoint("PerformMerge: Refreshing pending changes"); tempWorkspace.RefreshPendingChanges(); checkInSummary.SourceBranch = MergeSource; checkInSummary.TargetBranch = MergeTarget; checkInSummary.Changes = tempWorkspace.PendingChanges .Select( change => new CheckInSummaryViewModel.PendingChangeWithConflict( change, tempWorkspace.Conflicts.Where(conflict => conflict.ServerPath == change.ServerPath).FirstOrDefault())) .ToList(); // Automerging but conflicts? if (externalProgress != null && tempWorkspace.Conflicts.Count != 0) { return(false); } bool hadConflicts = ResolveConflicts(tempWorkspace, ref finished); if (finished) { SimpleLogger.Checkpoint("PerformMerge: Finished"); if (!item.OriginalChangesetLoaded) { FindOriginalChangeset(item.SourceCheckinId); } checkInSummary.TemporaryWorkspace = tempWorkspace; var originalCsWrapper = item.OriginalChangesetLoaded ? TfsItemCache.GetChangesetFromCache(item.OriginalChangesetId) : null; var originalCs = originalCsWrapper != null ? originalCsWrapper.TfsChangeset : null; checkInSummary.OriginalChangesets = new ITfsChangeset[] { originalCs ?? mergeChangeset }.ToList(); checkInSummary.SourceChangesets = new ITfsChangeset[] { mergeChangeset }.ToList(); checkInSummary.AssociatedWorkItems = item.SourceChangeset.RelatedWorkItems; checkInSummary.CheckInComment = BuildCheckInComment( item.SourceChangeset, mergeChangeset); if (hadConflicts || (externalProgress == null && AutoMergeDirectly == false)) { SimpleLogger.Checkpoint("PerformMerge: Showing check-in dialog"); if (Repository.Instance.Settings.FetchSettings <bool>(Constants.Settings.PerformNonModalMergeKey)) { undoPendingChanges = false; EmbeddedCheckInSummaryViewModel = checkInSummary; _temporaryWorkspace = tempWorkspace; EmbeddedCheckInSummaryViewModel.Finished += EmbeddedCheckInSummaryViewModel_Finished; } else { Repository.Instance.ViewManager.ShowModal(checkInSummary); } if (!checkInSummary.Cancelled) { CommitMerge(checkInSummary); } } else { SimpleLogger.Checkpoint("PerformMerge: Check-in automatically cancelled"); checkInSummary.Cancelled = false; CommitMerge(checkInSummary, externalProgress); } returnValue = !hadConflicts; } else { SimpleLogger.Checkpoint("PerformMerge: Not finished"); } } finally { if (undoPendingChanges) { SimpleLogger.Checkpoint("PerformMerge: Undoing pending changes"); tempWorkspace.UndoAllPendingChanges(); } else { SimpleLogger.Checkpoint("PerformMerge: NOT undoing pending changes"); } } SimpleLogger.Checkpoint("PerformMerge: Returning"); return(returnValue); }
public bool ResolveConflictsInternally(ITfsTemporaryWorkspace workspace) { return(true); }