Ejemplo n.º 1
0
        public void OnExecute(CommandEventArgs e)
        {
            if(_skip) // Only show this message once!
                return;

            _skip = true;
            VisualGitMessageBox mb = new VisualGitMessageBox(e.Context);
            mb.Show(string.Format(Resources.UnsupportedWorkingCopyFound, e.Argument));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        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);
                }

            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        static void DoBlame(CommandEventArgs e, GitOrigin item, GitRevision revisionEnd, GitIgnoreSpacing ignoreSpacing)
        {
            GitWriteArgs wa = new GitWriteArgs();
            wa.Revision = revisionEnd;

            GitBlameArgs ba = new GitBlameArgs();
            ba.End = revisionEnd;
            ba.IgnoreSpacing = ignoreSpacing;

            GitTarget target = item.Target;

            IVisualGitTempFileManager tempMgr = e.GetService<IVisualGitTempFileManager>();
            string tempFile = tempMgr.GetTempFileNamed(target.FileName);

            Collection<GitBlameEventArgs> blameResult = null;
            Dictionary<string, string> logMessages = new Dictionary<string, string>();

            bool retry = false;
            ProgressRunnerResult r = e.GetService<IProgressRunner>().RunModal(CommandStrings.Annotating, delegate(object sender, ProgressWorkerArgs ee)
            {
                using (FileStream fs = File.Create(tempFile))
                {
                    ee.Client.Write(target, fs, wa);
                }
                try
                {
                    ee.Client.GetBlame(target, ba, out blameResult);
                }
                catch (GitClientBinaryFileException)
                {
                    retry = true;
                }
            });

            if (retry)
            {
                using (VisualGitMessageBox mb = new VisualGitMessageBox(e.Context))
                {
                    if (DialogResult.Yes == mb.Show(
                                                CommandStrings.AnnotateBinaryFileContinueAnywayText,
                                                CommandStrings.AnnotateBinaryFileContinueAnywayTitle,
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                    {
                        r = e.GetService<IProgressRunner>()
                            .RunModal(CommandStrings.Annotating,
                                      delegate(object sender, ProgressWorkerArgs ee)
                                      {
                                          ee.Client.GetBlame(target, ba, out blameResult);
                                      });
                    }
                }
            }

            if (!r.Succeeded)
                return;

            AnnotateEditorControl annEditor = new AnnotateEditorControl();
            IVisualGitEditorResolver er = e.GetService<IVisualGitEditorResolver>();

            annEditor.Create(e.Context, tempFile);
            annEditor.LoadFile(tempFile);
            annEditor.AddLines(item, blameResult, logMessages);

            // Detect and set the language service
            Guid language;
            if (er.TryGetLanguageService(Path.GetExtension(target.FileName), out language))
            {
                // Extension is mapped -> user
                annEditor.SetLanguageService(language);
            }
            else if (blameResult != null && blameResult.Count > 0 && blameResult[0].Line != null)
            {
                // Extension is not mapped -> Check if this is xml (like project files)
                string line = blameResult[0].Line.Trim();

                if (line.StartsWith("<?xml")
                    || (line.StartsWith("<") && line.Contains("xmlns=\"http://schemas.microsoft.com/developer/msbuild/")))
                {
                    if (er.TryGetLanguageService(".xml", out language))
                    {
                        annEditor.SetLanguageService(language);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void PerformExecuteTag(CommandEventArgs e, GitItem root)
        {
            using (CreateTagDialog dlg = new CreateTagDialog())
            {
                if (e.Command == VisualGitCommand.ProjectTag)
                    dlg.Text = CommandStrings.TagProject;

                while (true)
                {
                    if (DialogResult.OK != dlg.ShowDialog(e.Context))
                        return;

                    bool retry = false;
                    bool ok = false;
                    ProgressRunnerResult rr =
                        e.GetService<IProgressRunner>().RunModal("Creating Tag",
                            delegate(object sender, ProgressWorkerArgs ee)
                            {
                                string tagName = dlg.TagName;

                                if (NameExists(tagName, ee, root))
                                {
                                    DialogResult dr = DialogResult.None;

                                    ee.Synchronizer.Invoke((VisualGitAction)
                                        delegate
                                        {
                                            VisualGitMessageBox mb = new VisualGitMessageBox(ee.Context);
                                            dr = mb.Show(string.Format("The tag '{0}' already exists.", tagName),
                                                "Tag Exists", MessageBoxButtons.RetryCancel);
                                        }, null);

                                    if (dr == DialogResult.Retry)
                                    {
                                        // show dialog again to let user modify the branch URL
                                        retry = true;
                                    }
                                }
                                else
                                {
                                    GitTagArgs args = new GitTagArgs();

                                    if (dlg.AnnotatedTag)
                                    {
                                        args.AnnotatedTag = true;
                                        args.Message = dlg.LogMessage;
                                    }

                                    ok = ee.Client.Tag(
                                        GitTools.GetRepositoryRoot(root.FullPath),
                                        tagName,
                                        args
                                    );
                                }
                            });

                    if (!retry)
                        break;
                }
            }
        }
Ejemplo n.º 7
0
        private void PerformExecuteBranch(CommandEventArgs e, GitItem root)
        {
            using (CreateBranchDialog dlg = new CreateBranchDialog())
            {
                dlg.GitOrigin = new GitOrigin(root);

                if (e.Command == VisualGitCommand.ProjectBranch)
                    dlg.Text = CommandStrings.BranchProject;

                while (true)
                {
                    if (DialogResult.OK != dlg.ShowDialog(e.Context))
                        return;

                    bool retry = false;
                    bool ok = false;
                    string branchName = dlg.BranchName;

                    ProgressRunnerResult rr =
                        e.GetService<IProgressRunner>().RunModal("Creating Branch",
                        delegate(object sender, ProgressWorkerArgs ee)
                        {
                            if (NameExists(branchName, ee, root))
                            {
                                DialogResult dr = DialogResult.None;

                                ee.Synchronizer.Invoke((VisualGitAction)
                                    delegate
                                    {
                                        VisualGitMessageBox mb = new VisualGitMessageBox(ee.Context);
                                        dr = mb.Show(string.Format("The branch '{0}' already exists.", branchName),
                                            "Branch Exists", MessageBoxButtons.RetryCancel);
                                    }, null);

                                if (dr == DialogResult.Retry)
                                {
                                    // show dialog again to let user modify the branch URL
                                    retry = true;
                                }
                            }
                            else
                            {
                                GitBranchArgs args = new GitBranchArgs();

                                args.Force = dlg.Force;
                                args.Revision = dlg.Revision;

                                ok = ee.Client.Branch(
                                    GitTools.GetRepositoryRoot(root.FullPath),
                                    branchName,
                                    args
                                );
                            }
                        });

                    if (rr.Succeeded && ok && dlg.SwitchToBranch)
                    {
                        e.GetService<IVisualGitCommandService>().PostExecCommand(VisualGitCommand.SolutionSwitchDialog, branchName);
                    }

                    if (!retry)
                        break;
                }
            }
        }
Ejemplo n.º 8
0
        static bool HandleUnmanagedOrUnversionedSolution(CommandEventArgs e, GitItem solutionItem)
        {
            IVisualGitSccService scc = e.GetService<IVisualGitSccService>();
            VisualGitMessageBox mb = new VisualGitMessageBox(e.Context);

            bool shouldActivate = false;
            if (!scc.IsActive)
            {
                if (e.State.OtherSccProviderActive)
                    return false; // Can't switch in this case.. Nothing to do

                // VisualGit is not the active provider, we should register as active
                shouldActivate = true;
            }

            if (scc.IsSolutionManaged && solutionItem.IsVersioned)
                return true; // Projects should still be checked

            bool confirmed = false;

            if (solutionItem.IsVersioned)
            { /* File is in Git; just enable */ }
            else
            {
                if (!CheckoutWorkingCopyForSolution(e, ref confirmed))
                    return false;
            }

            if (!confirmed && !e.DontPrompt && !e.IsInAutomation &&
                DialogResult.Yes != mb.Show(string.Format(CommandResources.MarkXAsManaged,
                Path.GetFileName(e.Selection.SolutionFilename)), "", MessageBoxButtons.YesNo))
            {
                return false;
            }

            SetSolutionManaged(shouldActivate, solutionItem, scc);

            return true;
        }
Ejemplo n.º 9
0
        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();
                }
            }
        }