Example #1
0
        /// <summary>
        /// Creates a unified diff comparing the selected saved file to itself in the HEAD commit.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private static void WorkingHeadCodeWinCallback(object sender, EventArgs e)
        {
            try
            {
                string unifiedDiff = "";
                var    git         = new Git2Sharp();

                var path = dte.ActiveDocument.Path + dte.ActiveDocument.Name;

                var    txtDoc  = (TextDocument)dte.ActiveDocument.Object("TextDocument");
                var    editPnt = txtDoc.StartPoint.CreateEditPoint();
                string docText = editPnt.GetText(txtDoc.EndPoint);

                string diff = git.Diff(path, docText);
                if (diff != "")
                {
                    unifiedDiff += diff;
                }
                else
                {
                    unifiedDiff += $"{path} - no changes found.";
                }

                NewVSDiffDocument(unifiedDiff);
            }
            catch (Exception)
            {
            }
        }
Example #2
0
        /// <summary>
        /// Creates a unified diff comparing the selected saved file to itself in the HEAD commit.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private static void SavedHeadCodeWinCallback(object sender, EventArgs e)
        {
            try
            {
                string unifiedDiff = "";
                var    git         = new Git2Sharp();

                var path = dte.ActiveDocument.Path + dte.ActiveDocument.Name;

                string diff = git.Diff(path);
                if (diff != "")
                {
                    unifiedDiff += diff;
                }
                else
                {
                    unifiedDiff += $"{path} - no changes found.";
                }

                NewVSDiffDocument(unifiedDiff);
            }
            catch (Exception)
            {
            }
        }
Example #3
0
        /// <summary>
        /// Creates a unified diff comparing the selected saved file to itself in the HEAD commit.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private static void SavedHeadSolutionCallback(object sender, EventArgs e)
        {
            try
            {
                var    myCommand   = (OleMenuCommand)sender;
                string unifiedDiff = "";
                var    git         = new Git2Sharp();

                // Get unified diff(s)
                List <string> paths = new List <string>();

                if (myCommand.CommandID.ID == CmdID_SavedHeadSourceChanges)
                {
                    paths = SelectedSCCFilePaths();
                }
                else if (myCommand.CommandID.ID == CmdID_SavedHeadSolution)
                {
                    paths = SelectedItemFilePaths(dte);
                }

                // todo fix this ugly mess below
                int index = 0;
                foreach (string path in paths)
                {
                    if (index > 0)
                    {
                        unifiedDiff += Environment.NewLine + Environment.NewLine;
                    }

                    if (dte.SourceControl.IsItemUnderSCC(path))
                    {
                        string diff = git.Diff(path);
                        if (diff != "")
                        {
                            unifiedDiff += diff;
                        }
                        else
                        {
                            unifiedDiff += $"{path} - no changes found.";
                        }
                    }
                    else
                    {
                        unifiedDiff += $"{path} - file is not under source control.";
                    }

                    index++;
                }

                NewVSDiffDocument(unifiedDiff);
            }
            catch (Exception)
            {
            }
        }
Example #4
0
        /// <summary>
        /// Creates a unified diff comparing the selected unsaved modified file to itself in the HEAD commit.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private static void WorkingHeadSolutionCallback(object sender, EventArgs e)
        {
            try
            {
                string unifiedDiff = "";
                var    git         = new Git2Sharp();

                var selected = dte.SelectedItems.Item(1).ProjectItem;
                var path     = selected.Properties.Item("FullPath").Value.ToString();

                if (selected.IsOpen)
                {
                    var    txtDoc  = (TextDocument)selected.Document.Object("TextDocument");
                    var    editPnt = txtDoc.StartPoint.CreateEditPoint();
                    string docText = editPnt.GetText(txtDoc.EndPoint);

                    if (dte.SourceControl.IsItemUnderSCC(path))
                    {
                        string diff = git.Diff(path, docText);
                        if (diff != "")
                        {
                            unifiedDiff += diff;
                        }
                        else
                        {
                            unifiedDiff += $"{path} - no changes found.";
                        }
                    }
                    else
                    {
                        unifiedDiff += $"{path} - file is not under source control.";
                    }

                    NewVSDiffDocument(unifiedDiff);
                }
            }
            catch (Exception)
            {
            }
        }