コード例 #1
0
        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);
        }
コード例 #2
0
        private void HandleConflictWithExternalMergeTool(GitConflictEventArgs e)
        {
            IVisualGitDiffHandler handler = GetService<IVisualGitDiffHandler>();
            if (handler == null)
            {
                HandleConflictWithDialog(e);
            }
            else
            {
                VisualGitMergeArgs ama = new VisualGitMergeArgs();
                // Ensure paths are in valid format or the DiffToolMonitor constructor
                // throws argument exception validatig the file path to be monitored.
                ama.BaseFile = GitTools.GetNormalizedFullPath(e.BaseFile);
                ama.TheirsFile = GitTools.GetNormalizedFullPath(e.TheirFile);
                ama.MineFile = GitTools.GetNormalizedFullPath(e.MyFile);
                ama.MergedFile = GitTools.GetNormalizedFullPath(e.MergedFile);
                ama.Mode = DiffMode.PreferExternal;
                ama.BaseTitle = "Base";
                ama.TheirsTitle = "Theirs";
                ama.MineTitle = "Mine";
                ama.MergedTitle = new System.IO.FileInfo(e.Path).Name;
                bool merged = handler.RunMerge(ama);
                if (merged)
                {
                    IUIService ui = Context.GetService<IUIService>();
                    string message = "Did you resolve all of the conflicts in the file?\n\nAnswering yes marks this file as resolved, no will keep it as conflicted.";
                    string caption = "Resolve Conflict";
                    DialogResult result = ui.ShowMessage(message, caption, MessageBoxButtons.YesNoCancel);
                    e.Cancel = result == DialogResult.Cancel;

                    if(!e.Cancel)
                        merged = result == DialogResult.Yes;
                }
                if (!merged)
                {
                    //Restore original merged file.
                    HandleConflictWithDialog(e);
                }
                else
                {
                    e.Choice = GitAccept.Merged;
                }
            }
        }
コード例 #3
0
ファイル: VisualGitDiff.cs プロジェクト: pvginkel/VisualGit
            public DiffToolMonitor(IVisualGitServiceProvider context, string monitor, bool monitorDir, VisualGitMergeArgs args)
                : base(context)
            {
                if (string.IsNullOrEmpty(monitor))
                    throw new ArgumentNullException("monitor");
                else if (!GitItem.IsValidPath(monitor))
                    throw new ArgumentOutOfRangeException("monitor");

                _monitorDir = monitorDir;
                _args = args;
                _toMonitor = monitor;

                IVsFileChangeEx fx = context.GetService<IVsFileChangeEx>(typeof(SVsFileChangeEx));

                _cookie = 0;
                if (fx == null)
                { }
                else if (!_monitorDir)
                {
                    if (!ErrorHandler.Succeeded(fx.AdviseFileChange(monitor,
                            (uint)(_VSFILECHANGEFLAGS.VSFILECHG_Time | _VSFILECHANGEFLAGS.VSFILECHG_Size
                            | _VSFILECHANGEFLAGS.VSFILECHG_Add | _VSFILECHANGEFLAGS.VSFILECHG_Del
                            | _VSFILECHANGEFLAGS.VSFILECHG_Attr),
                            this,
                            out _cookie)))
                    {
                        _cookie = 0;
                    }
                }
                else
                {
                    if (!ErrorHandler.Succeeded(fx.AdviseDirChange(monitor, 1, this, out _cookie)))
                    {
                        _cookie = 0;
                    }
                }
            }
コード例 #4
0
ファイル: VisualGitDiff.cs プロジェクト: pvginkel/VisualGit
            public Replacer(VisualGitDiff context, VisualGitDiffToolArgs args, DiffToolMode toolMode)
            {
                if (context == null)
                    throw new ArgumentNullException("context");
                else if (args == null)
                    throw new ArgumentNullException("args");

                _context = context;
                _toolArgs = args;
                _diffArgs = args as VisualGitDiffArgs;
                _mergeArgs = args as VisualGitMergeArgs;
                _patchArgs = args as VisualGitPatchArgs;
                _toolMode = toolMode;
            }
コード例 #5
0
ファイル: VisualGitDiff.cs プロジェクト: pvginkel/VisualGit
        public bool RunMerge(VisualGitMergeArgs args)
        {
            if (args == null)
                throw new ArgumentNullException("args");
            else if (!args.Validate())
                throw new ArgumentException("Arguments not filled correctly", "args");

            string diffApp = this.GetMergePath(args.Mode);

            if (string.IsNullOrEmpty(diffApp))
            {
                new VisualGitMessageBox(Context).Show("Please specify a merge tool in Tools -> Options -> SourceControl -> Git", "VisualGit - No visual merge tool is available");

                return false;
            }

            string program;
            string arguments;
            if (!Substitute(diffApp, args, DiffToolMode.Merge, out program, out arguments))
            {
                new VisualGitMessageBox(Context).Show(string.Format("Can't find merge program '{0}'", program));
                return false;
            }

            Process p = new Process();
            p.StartInfo = new ProcessStartInfo(program, arguments);

            string mergedFile = args.MergedFile;

            DiffToolMonitor monitor = null;
            if (!string.IsNullOrEmpty(mergedFile))
            {
                monitor = new DiffToolMonitor(Context, mergedFile, false, args);

                p.EnableRaisingEvents = true;
                monitor.Register(p);
            }

            bool started = false;
            try
            {
                return started = p.Start();
            }
            finally
            {
                if (!started)
                {
                    if (monitor != null)
                        monitor.Dispose();
                }
            }
        }