GetSelectedRevisions() public method

public GetSelectedRevisions ( ) : List
return List
Exemplo n.º 1
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
                return null;

            if (revisions[0].Guid == GitRevision.UncommittedWorkingDirGuid) //working dir changes
            {
                if (file.IsTracked)
                    return Settings.Module.GetCurrentChanges(file.Name, file.OldName, false, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);
                return FileReader.ReadFileContent(Settings.WorkingDir + file.Name, diffViewer.Encoding);
            }
            if (revisions[0].Guid == GitRevision.IndexGuid) //index
            {
                return Settings.Module.GetCurrentChanges(file.Name, file.OldName, true, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);
            }
            var secondRevision = revisions.Count == 2 ? revisions[1].Guid : revisions[0].Guid + "^";

            PatchApply.Patch patch = Settings.Module.GetSingleDiff(revisions[0].Guid, secondRevision, file.Name, file.OldName,
                                                    diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
                return null;

            if (file.IsSubmodule)
                return GitCommandHelpers.ProcessSubmodulePatch(patch.Text);

            return patch.Text;
        }
Exemplo n.º 2
0
        public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 1 && (revisions[0].ParentGuids == null || revisions[0].ParentGuids.Length == 0))
            {
                if (file.TreeGuid.IsNullOrEmpty())
                {
                    diffViewer.ViewGitItemRevision(file.Name, revisions[0].Guid);
                }
                else if (!file.IsSubmodule)
                {
                    diffViewer.ViewGitItem(file.Name, file.TreeGuid);
                }
                else
                {
                    diffViewer.ViewText(file.Name,
                                        GitCommandHelpers.GetSubmoduleText(grid.Module, file.Name, file.TreeGuid));
                }
            }
            else
            {
                diffViewer.ViewPatch(() =>
                {
                    string selectedPatch = diffViewer.GetSelectedPatch(grid, file);
                    return(selectedPatch ?? defaultText);
                });
            }
        }
Exemplo n.º 3
0
        private void RevisionGridSelectionChanged(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current            = Cursors.WaitCursor;
                DiffFiles.GitItemStatuses = null;
                var revisions = RevisionGrid.GetSelectedRevisions();

                if (revisions.Count == 1)
                {
                    DiffFiles.GitItemStatuses =
                        Settings.Module.GetDiffFiles(
                            revisions[0].Guid,
                            revisions[0].ParentGuids[0]);
                }

                if (revisions.Count == 2)
                {
                    DiffFiles.GitItemStatuses =
                        Settings.Module.GetDiffFiles(
                            revisions[0].Guid,
                            revisions[1].Guid);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 4
0
 private void RevisionGridSelectionChanged(object sender, EventArgs e)
 {
     Cursor.Current            = Cursors.WaitCursor;
     DiffFiles.GitItemStatuses = null;
     DiffFiles.SetDiffs(RevisionGrid.GetSelectedRevisions());
     Cursor.Current = Cursors.Default;
 }
Exemplo n.º 5
0
        private void OkClick(object sender, EventArgs e)
        {
            try
            {
                if (RevisionGrid.GetSelectedRevisions().Count != 1)
                {
                    MessageBox.Show(this, _noRevisionSelectedMsgBox.Text, _noRevisionSelectedMsgBoxCaption.Text);
                    return;
                }

                var command = "checkout \"" + RevisionGrid.GetSelectedRevisions()[0].Guid + "\"";
                if (Force.Checked)
                {
                    command += " --force";
                }

                new FormProcess(command).ShowDialog(this);

                Close();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Exemplo n.º 6
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();
            string firstRevision          = revisions.Count > 0 ? revisions[0].Guid : null;
            string secondRevision         = revisions.Count == 2 ? revisions[1].Guid : null;

            return(GetSelectedPatch(diffViewer, firstRevision, secondRevision, file));
        }
Exemplo n.º 7
0
        private void Start_Click(object sender, EventArgs e)
        {
            FormProcess.ShowDialog(this, GitCommandHelpers.StartBisectCmd());
            UpdateButtonsState();

            IList <GitRevision> revisions = _revisionGrid.GetSelectedRevisions();

            if (revisions.Count > 1)
            {
                if (MessageBox.Show(this, _bisectStart.Text, Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    BisectRange(revisions.First().Guid, revisions.Last().Guid);
                    Close();
                }
            }
        }
Exemplo n.º 8
0
        private void CherryPick_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            if (RevisionGrid.GetSelectedRevisions().Count != 1)
            {
                MessageBox.Show(this, _noRevisionSelectedMsgBox.Text, _noRevisionSelectedMsgBoxCaption.Text);
                return;
            }
            bool          formClosed = false;
            List <string> arguments  = new List <string>();
            bool          IsMerge    = Settings.Module.IsMerge(RevisionGrid.GetSelectedRevisions()[0].Guid);

            if (IsMerge && !autoParent.Checked)
            {
                GitRevision[] ParentsRevisions = Settings.Module.GetParents(RevisionGrid.GetSelectedRevisions()[0].Guid);
                var           choose           = new FormCherryPickMerge(ParentsRevisions);
                choose.ShowDialog(this);
                if (choose.OkClicked)
                {
                    arguments.Add("-m " + (choose.ParentsList.SelectedItems[0].Index + 1));
                }
                else
                {
                    formClosed = true;
                }
            }
            else if (IsMerge)
            {
                arguments.Add("-m 1");
            }

            if (checkAddReference.Checked)
            {
                arguments.Add("-x");
            }

            if (!formClosed)
            {
                MessageBox.Show(this, _cmdExecutedMsgBox.Text + " " + Environment.NewLine + Settings.Module.CherryPick(RevisionGrid.GetSelectedRevisions()[0].Guid, AutoCommit.Checked, string.Join(" ", arguments.ToArray())), _cmdExecutedMsgBoxCaption.Text);

                MergeConflictHandler.HandleMergeConflicts(this);

                RevisionGrid.RefreshRevisions();

                Cursor.Current = Cursors.Default;
            }
        }
Exemplo n.º 9
0
        public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 1 && (revisions[0].ParentGuids == null || revisions[0].ParentGuids.Length == 0))
            {
                diffViewer.ViewGitItem(file.Name, file.TreeGuid);
            }
            else
            {
                diffViewer.ViewPatch(() =>
                {
                    string selectedPatch = diffViewer.GetSelectedPatch(grid, file);
                    return(selectedPatch ?? defaultText);
                });
            }
        }
Exemplo n.º 10
0
        private void Ok_Click(object sender, EventArgs e)
        {
            try
            {
                if (RevisionGrid.GetSelectedRevisions().Count != 1)
                {
                    MessageBox.Show(this, _selectOneRevision.Text, _branchCaption.Text);
                    return;
                }

                string cmd = GitCommandHelpers.BranchCmd(BName.Text, RevisionGrid.GetSelectedRevisions()[0].Guid, CheckoutAfterCreate.Checked);
                FormProcess.ShowDialog(this, cmd);

                Close();
            }
            catch
            {
            }
        }
Exemplo n.º 11
0
        public static void OpenWithDifftool(this RevisionGrid grid, string fileName, string oldFileName, GitUI.RevisionDiffKind diffKind, bool isTracked = true)
        {
            // Note: Order in revisions is that first clicked is last in array

            string error = RevisionDiffInfoProvider.Get(grid.GetSelectedRevisions(), diffKind,
                                                        out var extraDiffArgs, out var firstRevision, out var secondRevision);

            if (!string.IsNullOrEmpty(error))
            {
                MessageBox.Show(grid, error);
            }
            else
            {
                string output = grid.Module.OpenWithDifftool(fileName, oldFileName, firstRevision, secondRevision, extraDiffArgs, isTracked);
                if (!string.IsNullOrEmpty(output))
                {
                    MessageBox.Show(grid, output);
                }
            }
        }
Exemplo n.º 12
0
        private void ViewSelectedFileDiff()
        {
            Cursor.Current = Cursors.WaitCursor;

            if (DiffFiles.SelectedItem == null)
            {
                return;
            }

            Patch selectedPatch;

            var revisions = RevisionGrid.GetSelectedRevisions();

            if (revisions.Count == 2)
            {
                selectedPatch =
                    Settings.Module
                    .GetSingleDiff(
                        revisions[0].Guid,
                        revisions[1].Guid,
                        DiffFiles.SelectedItem.Name,
                        DiffFiles.SelectedItem.OldName,
                        diffViewer.GetExtraDiffArguments());
            }
            else
            {
                var revision = revisions[0];
                selectedPatch =
                    Settings.Module
                    .GetSingleDiff(
                        revision.Guid,
                        revision.ParentGuids[0],
                        DiffFiles.SelectedItem.Name,
                        DiffFiles.SelectedItem.OldName,
                        diffViewer.GetExtraDiffArguments());
            }

            diffViewer.ViewPatch(selectedPatch != null ? selectedPatch.Text : "");
            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 13
0
        private void OkClick(object sender, EventArgs e)
        {
            try
            {
                if (RevisionGrid.GetSelectedRevisions().Count != 1)
                {
                    MessageBox.Show(this, _noRevisionSelectedMsgBox.Text, _noRevisionSelectedMsgBoxCaption.Text);
                    return;
                }

                string command = GitCommandHelpers.CheckoutCmd(RevisionGrid.GetSelectedRevisions()[0].Guid,
                                                               Force.Checked ? LocalChangesAction.Reset : 0);

                FormProcess.ShowDialog(this, command);

                Close();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
Exemplo n.º 14
0
        public static void OpenWithDifftool(this RevisionGrid grid, string fileName, string oldFileName, DiffWithRevisionKind diffKind)
        {
            //Note: Order in revisions is that first clicked is last in array
            string extraDiffArgs;
            string firstRevision;
            string secondRevision;

            string error = DiffKindRevision.Get(grid.GetSelectedRevisions(), diffKind, out extraDiffArgs, out firstRevision, out secondRevision);

            if (!string.IsNullOrEmpty(error))
            {
                MessageBox.Show(grid, error);
            }
            else
            {
                string output = grid.Module.OpenWithDifftool(fileName, oldFileName, firstRevision, secondRevision, extraDiffArgs);
                if (!string.IsNullOrEmpty(output))
                {
                    MessageBox.Show(grid, output);
                }
            }
        }
Exemplo n.º 15
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
                return null;

            string firstRevision = revisions[0].Guid;
            var secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
            {
                firstRevision = secondRevision;
                secondRevision = revisions[0].Guid;
            }

            if (IsItemUntracked(file, firstRevision, secondRevision))
            {
                var fullPath = Path.Combine(grid.Module.WorkingDir, file.Name);
                if (Directory.Exists(fullPath) && GitModule.ValidWorkingDir(fullPath))
                    return GitCommandHelpers.GetSubmoduleText(grid.Module, file.Name.TrimEnd('/'), "");
                return FileReader.ReadFileContent(fullPath, diffViewer.Encoding);
            }

            if (file.IsSubmodule && file.SubmoduleStatus != null)
                return GitCommandHelpers.ProcessSubmoduleStatus(grid.Module, file.SubmoduleStatus);

            PatchApply.Patch patch = GetItemPatch(grid.Module, file, firstRevision, secondRevision,
                diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);

            if (patch == null)
                return string.Empty;

            if (file.IsSubmodule)
                return GitCommandHelpers.ProcessSubmodulePatch(grid.Module, patch);
            return patch.Text;
        }
Exemplo n.º 16
0
        public static void OpenWithDifftool(this RevisionGrid grid, string fileName, string oldFileName, DiffWithRevisionKind diffKind, string parentGuid)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0 || revisions.Count > 2)
            {
                return;
            }

            string output;

            if (diffKind == DiffWithRevisionKind.DiffAB)
            {
                string firstRevision  = revisions[0].Guid;
                var    secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

                //to simplify if-ology
                if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
                {
                    firstRevision  = secondRevision;
                    secondRevision = revisions[0].Guid;
                }

                string extraDiffArgs = "-M -C";

                if (GitRevision.IsArtificial(firstRevision))
                {
                    bool staged = firstRevision == GitRevision.IndexGuid;
                    if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                    {
                        firstRevision = string.Empty;
                    }
                    else
                    {
                        firstRevision = secondRevision;
                    }
                    secondRevision = string.Empty;
                    if (staged) //rev1 vs index
                    {
                        extraDiffArgs = string.Join(" ", extraDiffArgs, "--cached");
                    }
                }
                else if (secondRevision == null)
                {
                    secondRevision = parentGuid ?? firstRevision + "^";
                }

                output = grid.Module.OpenWithDifftool(fileName, oldFileName, firstRevision, secondRevision, extraDiffArgs);
            }
            else
            {
                string revisionToCmp;
                if (revisions.Count == 1)
                {
                    GitRevision revision = revisions[0];
                    if (diffKind == DiffWithRevisionKind.DiffALocal)
                    {
                        revisionToCmp = parentGuid ?? revision.FirstParentGuid ?? revision.Guid + '^';
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffBLocal)
                    {
                        revisionToCmp = revision.Guid;
                    }
                    else
                    {
                        revisionToCmp = null;
                    }
                }
                else
                {
                    switch (diffKind)
                    {
                    case DiffWithRevisionKind.DiffALocal:
                        revisionToCmp = revisions[1].Guid;
                        break;

                    case DiffWithRevisionKind.DiffBLocal:
                        revisionToCmp = revisions[0].Guid;
                        break;

                    case DiffWithRevisionKind.DiffAParentLocal:
                        revisionToCmp = revisions[1].FirstParentGuid ?? revisions[1].Guid + '^';
                        break;

                    case DiffWithRevisionKind.DiffBParentLocal:
                        revisionToCmp = revisions[0].FirstParentGuid ?? revisions[0].Guid + '^';
                        break;

                    default:
                        revisionToCmp = null;
                        break;
                    }
                }

                if (revisionToCmp == null)
                {
                    return;
                }

                output = grid.Module.OpenWithDifftool(fileName, null, revisionToCmp);
            }

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(grid, output);
            }
        }
Exemplo n.º 17
0
        public static void OpenWithDifftool(this RevisionGrid grid, string fileName, string oldFileName, DiffWithRevisionKind diffKind)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0 || revisions.Count > 2)
            {
                return;
            }

            string output;

            if (diffKind == DiffWithRevisionKind.DiffAB)
            {
                string firstRevision  = revisions[0].Guid;
                var    secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

                //to simplify if-ology
                if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
                {
                    firstRevision  = secondRevision;
                    secondRevision = revisions[0].Guid;
                }

                string extraDiffArgs = "-M -C";

                if (firstRevision == GitRevision.UnstagedGuid) //working dir changes
                {
                    if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                    {
                        firstRevision  = string.Empty;
                        secondRevision = string.Empty;
                    }
                    else
                    {
                        // rev2 vs working dir changes
                        firstRevision  = secondRevision;
                        secondRevision = string.Empty;
                    }
                }
                if (firstRevision == GitRevision.IndexGuid) //index
                {
                    if (secondRevision == null)
                    {
                        firstRevision  = string.Empty;
                        secondRevision = string.Empty;
                        extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
                    }
                    else //rev1 vs index
                    {
                        firstRevision  = secondRevision;
                        secondRevision = string.Empty;
                        extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
                    }
                }

                Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision, secondRevision));

                if (secondRevision == null)
                {
                    secondRevision = firstRevision + "^";
                }

                output = grid.Module.OpenWithDifftool(fileName, oldFileName, firstRevision, secondRevision, extraDiffArgs);
            }
            else
            {
                string revisionToCmp;
                if (revisions.Count == 1)
                {
                    GitRevision revision = revisions[0];
                    if (diffKind == DiffWithRevisionKind.DiffALocal)
                    {
                        revisionToCmp = revision.ParentGuids.Length == 0 ? null : revision.ParentGuids[0];
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffBLocal)
                    {
                        revisionToCmp = revision.Guid;
                    }
                    else
                    {
                        revisionToCmp = null;
                    }
                }
                else
                {
                    if (diffKind == DiffWithRevisionKind.DiffALocal)
                    {
                        revisionToCmp = revisions[0].Guid;
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffBLocal)
                    {
                        revisionToCmp = revisions[1].Guid;
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffAParentLocal)
                    {
                        revisionToCmp = revisions[0].ParentGuids.Length == 0 ? null : revisions[0].ParentGuids[0];
                    }
                    else if (diffKind == DiffWithRevisionKind.DiffBLocal)
                    {
                        revisionToCmp = revisions[1].ParentGuids.Length == 0 ? null : revisions[1].ParentGuids[0];
                    }
                    else
                    {
                        revisionToCmp = null;
                    }
                }

                if (revisionToCmp == null)
                {
                    return;
                }

                output = grid.Module.OpenWithDifftool(fileName, revisionToCmp);
            }

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(grid, output);
            }
        }
Exemplo n.º 18
0
        public static void OpenWithDifftool(this RevisionGrid grid, string fileName, DiffWithRevisionKind diffKind)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
            {
                return;
            }

            string output;

            if (diffKind == DiffWithRevisionKind.DiffBaseLocal)
            {
                if (revisions[0].ParentGuids.Length == 0)
                {
                    return;
                }
                output = GitModule.Current.OpenWithDifftool(fileName, revisions[0].ParentGuids[0]);
            }
            else if (diffKind == DiffWithRevisionKind.DiffRemoteLocal)
            {
                output = GitModule.Current.OpenWithDifftool(fileName, revisions[0].Guid);
            }
            else
            {
                string firstRevision  = revisions[0].Guid;
                var    secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

                //to simplify if-ology
                if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UncommittedWorkingDirGuid)
                {
                    firstRevision  = secondRevision;
                    secondRevision = revisions[0].Guid;
                }

                string extraDiffArgs = null;

                if (firstRevision == GitRevision.UncommittedWorkingDirGuid) //working dir changes
                {
                    if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                    {
                        firstRevision  = string.Empty;
                        secondRevision = string.Empty;
                    }
                    else
                    {
                        // rev2 vs working dir changes
                        firstRevision  = secondRevision;
                        secondRevision = string.Empty;
                    }
                }
                if (firstRevision == GitRevision.IndexGuid) //index
                {
                    if (secondRevision == null)
                    {
                        firstRevision  = string.Empty;
                        secondRevision = string.Empty;
                        extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
                    }
                    else //rev1 vs index
                    {
                        firstRevision  = secondRevision;
                        secondRevision = string.Empty;
                        extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
                    }
                }

                Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision, secondRevision));

                if (secondRevision == null)
                {
                    secondRevision = firstRevision + "^";
                }

                output = GitModule.Current.OpenWithDifftool(fileName, firstRevision, secondRevision, extraDiffArgs);
            }

            if (!string.IsNullOrEmpty(output))
            {
                MessageBox.Show(grid, output);
            }
        }
Exemplo n.º 19
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
            {
                return(null);
            }

            string firstRevision  = revisions[0].Guid;
            var    secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UncommittedWorkingDirGuid)
            {
                firstRevision  = secondRevision;
                secondRevision = revisions[0].Guid;
            }

            string extraDiffArgs = null;

            if (firstRevision == GitRevision.UncommittedWorkingDirGuid) //working dir changes
            {
                if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                {
                    if (file.IsTracked)
                    {
                        return(ProcessDiffText(GitModule.Current.GetCurrentChanges(file.Name, file.OldName, false,
                                                                                   diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule));
                    }

                    return(FileReader.ReadFileContent(GitModule.CurrentWorkingDir + file.Name, diffViewer.Encoding));
                }
                else
                {
                    firstRevision  = secondRevision;
                    secondRevision = string.Empty;
                }
            }
            if (firstRevision == GitRevision.IndexGuid) //index
            {
                if (secondRevision == null)
                {
                    return(ProcessDiffText(GitModule.Current.GetCurrentChanges(file.Name, file.OldName, true,
                                                                               diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule));
                }

                //rev1 vs index
                firstRevision  = secondRevision;
                secondRevision = string.Empty;
                extraDiffArgs  = string.Join(" ", extraDiffArgs, "--cached");
            }

            Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision, secondRevision));

            if (secondRevision == null)
            {
                secondRevision = firstRevision + "^";
            }

            PatchApply.Patch patch = GitModule.Current.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName,
                                                                     string.Join(" ", diffViewer.GetExtraDiffArguments(), extraDiffArgs), diffViewer.Encoding);

            if (patch == null)
            {
                return(string.Empty);
            }

            return(ProcessDiffText(patch.Text, file.IsSubmodule));
        }
Exemplo n.º 20
0
        public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 1 && (revisions[0].ParentGuids == null || revisions[0].ParentGuids.Length == 0))
            {
                diffViewer.ViewGitItem(file.Name, file.TreeGuid);
            }
            else
            diffViewer.ViewPatch(() =>
                                   {
                                       string selectedPatch = diffViewer.GetSelectedPatch(grid, file);

                                       return selectedPatch ?? defaultText;
                                   });
        }
Exemplo n.º 21
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
                return null;

            string firstRevision = revisions[0].Guid;
            var secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UnstagedGuid)
            {
                firstRevision = secondRevision;
                secondRevision = revisions[0].Guid;
            }

            string extraDiffArgs = null;

            if (firstRevision == GitRevision.UnstagedGuid) //working dir changes
            {
                if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                {
                    if (file.IsTracked)
                    {
                        return ProcessDiffText(grid.Module, grid.Module.GetCurrentChanges(file.Name, file.OldName, false,
                            diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule);
                    }

                    var fullPath = Path.Combine(grid.Module.WorkingDir, file.Name);
                    if (Directory.Exists(fullPath) && GitModule.ValidWorkingDir(fullPath))
                        return GitCommandHelpers.GetSubmoduleText(grid.Module, file.Name.TrimEnd('/'), "");
                    return FileReader.ReadFileContent(fullPath, diffViewer.Encoding);
                }
                else
                {
                    firstRevision = secondRevision;
                    secondRevision = string.Empty;
                }
            }
            if (firstRevision == GitRevision.IndexGuid) //index
            {
                if (secondRevision == null)
                {
                    return ProcessDiffText(grid.Module, grid.Module.GetCurrentChanges(file.Name, file.OldName, true,
                        diffViewer.GetExtraDiffArguments(), diffViewer.Encoding), file.IsSubmodule);
                }

                //rev1 vs index
                firstRevision = secondRevision;
                secondRevision = string.Empty;
                extraDiffArgs = string.Join(" ", extraDiffArgs, "--cached");
            }

            Debug.Assert(!GitRevision.IsArtificial(firstRevision), string.Join(" ", firstRevision,secondRevision));

            if (secondRevision == null)
                secondRevision = firstRevision + "^";

            PatchApply.Patch patch = grid.Module.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName,
                                                    string.Join(" ", diffViewer.GetExtraDiffArguments(), extraDiffArgs), diffViewer.Encoding);

            if (patch == null)
                return string.Empty;

            return ProcessDiffText(grid.Module, patch.Text, file.IsSubmodule);
        }
Exemplo n.º 22
0
        private void FormatPatch_Click(object sender, EventArgs e)
        {
            if (SaveToDir.Checked && string.IsNullOrEmpty(OutputPath.Text))
            {
                MessageBox.Show(this, _noOutputPathEnteredText.Text);
                return;
            }

            if (!SaveToDir.Checked && string.IsNullOrEmpty(MailAddress.Text))
            {
                MessageBox.Show(this, _noEmailEnteredText.Text);
                return;
            }

            if (!SaveToDir.Checked && string.IsNullOrEmpty(MailSubject.Text))
            {
                MessageBox.Show(this, _noSubjectEnteredText.Text);
                return;
            }

            if (!SaveToDir.Checked && string.IsNullOrEmpty(Settings.Smtp))
            {
                MessageBox.Show(this, _wrongSmtpSettingsText.Text);
                return;
            }

            string savePatchesToDir = OutputPath.Text;

            if (!SaveToDir.Checked)
            {
                savePatchesToDir = Settings.Module.WorkingDirGitDir() + "\\PatchesToMail";
                if (Directory.Exists(savePatchesToDir))
                {
                    foreach (string file in Directory.GetFiles(savePatchesToDir, "*.patch"))
                    {
                        File.Delete(file);
                    }
                }
                else
                {
                    Directory.CreateDirectory(savePatchesToDir);
                }
            }

            string rev1   = "";
            string rev2   = "";
            string result = "";

            if (RevisionGrid.GetSelectedRevisions().Count > 0)
            {
                if (RevisionGrid.GetSelectedRevisions().Count == 1)
                {
                    rev1   = RevisionGrid.GetSelectedRevisions()[0].ParentGuids[0];
                    rev2   = RevisionGrid.GetSelectedRevisions()[0].Guid;
                    result = Settings.Module.FormatPatch(rev1, rev2, savePatchesToDir);
                }

                if (RevisionGrid.GetSelectedRevisions().Count == 2)
                {
                    rev1   = RevisionGrid.GetSelectedRevisions()[0].ParentGuids[0];
                    rev2   = RevisionGrid.GetSelectedRevisions()[1].Guid;
                    result = Settings.Module.FormatPatch(rev1, rev2, savePatchesToDir);
                }

                if (RevisionGrid.GetSelectedRevisions().Count > 2)
                {
                    int n = 0;
                    foreach (GitRevision revision in RevisionGrid.GetSelectedRevisions())
                    {
                        n++;
                        rev1    = revision.ParentGuids[0];
                        rev2    = revision.Guid;
                        result += Settings.Module.FormatPatch(rev1, rev2, savePatchesToDir, n);
                    }
                }
            }
            else
            if (string.IsNullOrEmpty(rev1) || string.IsNullOrEmpty(rev2))
            {
                MessageBox.Show(this, _twoRevisionsNeededText.Text, _twoRevisionsNeededCaption.Text);
                return;
            }

            if (!SaveToDir.Checked)
            {
                if (SendMail(savePatchesToDir))
                {
                    result += _sendMailResult.Text + " " + MailAddress.Text;
                }
                else
                {
                    result += _sendMailResultFailed.Text;
                }


                //Clean up
                if (Directory.Exists(savePatchesToDir))
                {
                    foreach (string file in Directory.GetFiles(savePatchesToDir, "*.patch"))
                    {
                        File.Delete(file);
                    }
                }
            }

            MessageBox.Show(this, result, _patchResultCaption.Text);
            Close();
        }
Exemplo n.º 23
0
        public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 1 && (revisions[0].ParentGuids == null || revisions[0].ParentGuids.Length == 0))
            {
                if (file.TreeGuid.IsNullOrEmpty())
                    diffViewer.ViewGitItemRevision(file.Name, revisions[0].Guid);
                else if (!file.IsSubmodule)
                    diffViewer.ViewGitItem(file.Name, file.TreeGuid);
                else
                    diffViewer.ViewText(file.Name,
                        GitCommandHelpers.GetSubmoduleText(grid.Module, file.Name, file.TreeGuid));
            }
            else
            {
                diffViewer.ViewPatch(() =>
                                       {
                                           string selectedPatch = diffViewer.GetSelectedPatch(grid, file);
                                           return selectedPatch ?? defaultText;
                                       });
            }
        }
Exemplo n.º 24
0
 public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
 {
     IList<GitRevision> revisions = grid.GetSelectedRevisions();
     ViewPatch(diffViewer, revisions, file, defaultText);
 }
Exemplo n.º 25
0
 public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
 {
     IList<GitRevision> revisions = grid.GetSelectedRevisions();
     string firstRevision = revisions.Count > 0 ? revisions[0].Guid : null;
     string secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;
     return GetSelectedPatch(diffViewer, firstRevision, secondRevision, file);
 }
Exemplo n.º 26
0
 public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
 {
     IList<GitRevision> revisions = grid.GetSelectedRevisions();
     return GetSelectedPatch(diffViewer, revisions, file);
 }
Exemplo n.º 27
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList<GitRevision> revisions = grid.GetSelectedRevisions();

            if (revisions.Count == 0)
                return null;

            string firstRevision = revisions[0].Guid;
            var secondRevision = revisions.Count == 2 ? revisions[1].Guid : null;

            //to simplify if-ology
            if (GitRevision.IsArtificial(secondRevision) && firstRevision != GitRevision.UncommittedWorkingDirGuid)
            {
                firstRevision = secondRevision;
                secondRevision = revisions[0].Guid;
            }

            string extraDiffArgs = null;

            if (firstRevision == GitRevision.UncommittedWorkingDirGuid) //working dir changes
            {
                if (secondRevision == null || secondRevision == GitRevision.IndexGuid)
                {
                    if (file.IsTracked)
                        return Settings.Module.GetCurrentChanges(file.Name, file.OldName, false, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);
                    return FileReader.ReadFileContent(Settings.WorkingDir + file.Name, diffViewer.Encoding);
                }
                else
                {
                    firstRevision = secondRevision;
                    secondRevision = string.Empty;
                }
            }
            if (firstRevision == GitRevision.IndexGuid) //index
            {
                if (secondRevision == null)
                    return Settings.Module.GetCurrentChanges(file.Name, file.OldName, true, diffViewer.GetExtraDiffArguments(), diffViewer.Encoding);
                else //rev1 vs index
                {
                    firstRevision = secondRevision;
                    secondRevision = string.Empty;
                    extraDiffArgs = extraDiffArgs.Join(" ", "--cached");
                }
            }

            Debug.Assert(!GitRevision.IsArtificial(firstRevision), firstRevision.Join(" ", secondRevision));

            if (secondRevision == null)
                secondRevision = firstRevision + "^";

            PatchApply.Patch patch = Settings.Module.GetSingleDiff(firstRevision, secondRevision, file.Name, file.OldName,
                                                    diffViewer.GetExtraDiffArguments().Join(" ", extraDiffArgs), diffViewer.Encoding);

            if (patch == null)
                return string.Empty;

            if (file.IsSubmodule)
                return GitCommandHelpers.ProcessSubmodulePatch(patch.Text);

            return patch.Text;
        }
Exemplo n.º 28
0
        public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
        {
            IList <GitRevision> revisions = grid.GetSelectedRevisions();

            return(GetSelectedPatch(diffViewer, revisions, file));
        }