Inheritance: GitUI.GitModuleControl
 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);
 }
        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);
                });
            }
        }
        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);
            }
        }
        private void OkClick(object sender, EventArgs e)
        {
            try
            {
                if (RevisionGrid.GetRevisions().Count != 1)
                {
                    MessageBox.Show("Select 1 revision to checkout.", "Checkout");
                    return;
                }

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

                new FormProcess(command).ShowDialog();

                Close();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
 public FormBisect(RevisionGrid revisionGrid)
 {
     InitializeComponent();
     Translate();
     _revisionGrid = revisionGrid;
     UpdateButtonsState();
 }
Exemple #6
0
        public FilterRevisionsHelper(ToolStripTextBox textBox, ToolStripDropDownButton dropDownButton, RevisionGrid revisionGrid, ToolStripLabel label, ToolStripButton showFirstParentButton, Form form)
            : this()
        {
            _NO_TRANSLATE_dropDownButton        = dropDownButton;
            _NO_TRANSLATE_textBox               = textBox;
            _NO_TRANSLATE_revisionGrid          = revisionGrid;
            _NO_TRANSLATE_label                 = label;
            _NO_TRANSLATE_showFirstParentButton = showFirstParentButton;
            _NO_TRANSLATE_form = form;

            _NO_TRANSLATE_dropDownButton.DropDownItems.AddRange(new ToolStripItem[]
            {
                _commitToolStripMenuItem,
                _committerToolStripMenuItem,
                _authorToolStripMenuItem,
                _diffContainsToolStripMenuItem
            });

            _NO_TRANSLATE_showFirstParentButton.Checked = AppSettings.ShowFirstParent;

            _NO_TRANSLATE_label.Click                          += ToolStripLabelClick;
            _NO_TRANSLATE_textBox.Leave                        += ToolStripTextBoxFilterLeave;
            _NO_TRANSLATE_textBox.KeyPress                     += ToolStripTextBoxFilterKeyPress;
            _NO_TRANSLATE_showFirstParentButton.Click          += ToolStripShowFirstParentButtonClick;
            _NO_TRANSLATE_revisionGrid.ShowFirstParentsToggled += RevisionGridShowFirstParentsToggled;
        }
Exemple #7
0
        private void FormBranch_Load(object sender, EventArgs e)
        {
            RevisionGrid.Load();

            BName.Focus();
            AcceptButton = Ok;
        }
Exemple #8
0
 public FormBisect(RevisionGrid revisionGrid)
 {
     InitializeComponent();
     Translate();
     _revisionGrid = revisionGrid;
     UpdateButtonsState();
 }
Exemple #9
0
 public FormBisect(RevisionGrid revisionGrid)
 {
     InitializeComponent();
     Translate();
     Initialize();
     _revisionGrid = revisionGrid;
 }
Exemple #10
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;
        }
        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;
        }
Exemple #12
0
 private void RevisionGridSelectionChanged(object sender, EventArgs e)
 {
     Cursor.Current            = Cursors.WaitCursor;
     DiffFiles.GitItemStatuses = null;
     DiffFiles.SetDiffs(RevisionGrid.GetSelectedRevisions());
     Cursor.Current = Cursors.Default;
 }
Exemple #13
0
 public FormBisect(RevisionGrid revisionGrid)
 {
     InitializeComponent();
     Translate();
     Initialize();
     _revisionGrid = revisionGrid;
 }
        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));
        }
Exemple #15
0
        public FormDiff(GitRevision revision)
        {
            InitializeComponent();
            Translate();


            RevisionGrid.SetSelectedRevision(revision);
        }
Exemple #16
0
        public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
        {
            diffViewer.ViewPatch(() =>
            {
                string selectedPatch = diffViewer.GetSelectedPatch(grid, file);

                return(selectedPatch ?? defaultText);
            });
        }
Exemple #17
0
        public FormDiff(GitModule module, GitRevision revision)
            : base(true)
        {
            InitializeComponent();
            Translate();

            module_ = module;
            RevisionGrid.SetSelectedRevision(revision);
        }
Exemple #18
0
        private void FormFormatPath_Load(object sender, EventArgs e)
        {
            OutputPath.Text = Settings.LastFormatPatchDir;
            string selectedHead = GitCommandHelpers.GetSelectedBranch();

            SelectedBranch.Text = "Current branch: " + selectedHead;

            SaveToDir_CheckedChanged(null, null);
            OutputPath.TextChanged += OutputPath_TextChanged;
            RevisionGrid.Load();
        }
        private void FormFormatPath_Load(object sender, EventArgs e)
        {
            OutputPath.Text = Settings.LastFormatPatchDir;
            string selectedHead = Settings.Module.GetSelectedBranch();

            SelectedBranch.Text = _currentBranchText.Text + " " + selectedHead;

            SaveToDir_CheckedChanged(null, null);
            OutputPath.TextChanged += OutputPath_TextChanged;
            RevisionGrid.Load();
        }
        public FilterBranchHelper(ToolStripComboBox toolStripBranches, ToolStripDropDownButton toolStripDropDownButton2, RevisionGrid RevisionGrid)
            : this()
        {
            this._NO_TRANSLATE_toolStripBranches = toolStripBranches;
            this._NO_TRANSLATE_toolStripDropDownButton2 = toolStripDropDownButton2;
            this._NO_TRANSLATE_RevisionGrid = RevisionGrid;

            this._NO_TRANSLATE_toolStripDropDownButton2.DropDownItems.AddRange(new ToolStripItem[] {
                this.localToolStripMenuItem,
                this.remoteToolStripMenuItem});

            this._NO_TRANSLATE_toolStripBranches.DropDown += this.toolStripBranches_DropDown;
            this._NO_TRANSLATE_toolStripBranches.TextUpdate += this.toolStripBranches_TextUpdate;
            this._NO_TRANSLATE_toolStripBranches.Leave += this.toolStripBranches_Leave;
            this._NO_TRANSLATE_toolStripBranches.KeyUp += this.toolStripBranches_KeyUp;
        }
        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;
            }
        }
Exemple #22
0
        public FilterBranchHelper(ToolStripComboBox toolStripBranches, ToolStripDropDownButton toolStripDropDownButton2, RevisionGrid RevisionGrid)
            : this()
        {
            this._NO_TRANSLATE_toolStripBranches        = toolStripBranches;
            this._NO_TRANSLATE_toolStripDropDownButton2 = toolStripDropDownButton2;
            this._NO_TRANSLATE_RevisionGrid             = RevisionGrid;

            this._NO_TRANSLATE_toolStripDropDownButton2.DropDownItems.AddRange(new ToolStripItem[] {
                this.localToolStripMenuItem,
                this.remoteToolStripMenuItem
            });

            this._NO_TRANSLATE_toolStripBranches.DropDown   += this.toolStripBranches_DropDown;
            this._NO_TRANSLATE_toolStripBranches.TextUpdate += this.toolStripBranches_TextUpdate;
            this._NO_TRANSLATE_toolStripBranches.Leave      += this.toolStripBranches_Leave;
            this._NO_TRANSLATE_toolStripBranches.KeyUp      += this.toolStripBranches_KeyUp;
        }
Exemple #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))
            {
                diffViewer.ViewGitItem(file.Name, file.TreeGuid);
            }
            else
            {
                diffViewer.ViewPatch(() =>
                {
                    string selectedPatch = diffViewer.GetSelectedPatch(grid, file);
                    return(selectedPatch ?? defaultText);
                });
            }
        }
        private void Ok_Click(object sender, EventArgs e)
        {
            try
            {
                if (RevisionGrid.GetRevisions().Count != 1)
                {
                    MessageBox.Show(_selectOneRevision.Text, _branchCaption.Text);
                    return;
                }

                new FormProcess(GitCommandHelpers.BranchCmd(BName.Text, RevisionGrid.GetRevisions()[0].Guid, CheckoutAfterCreate.Checked)).ShowDialog();

                Close();
            }
            catch
            {
            }
        }
        public FilterBranchHelper(ToolStripComboBox toolStripBranches, ToolStripDropDownButton toolStripDropDownButton2, RevisionGrid RevisionGrid)
            : this()
        {
            this._NO_TRANSLATE_toolStripBranches = toolStripBranches;
            this._NO_TRANSLATE_toolStripDropDownButton2 = toolStripDropDownButton2;
            this._NO_TRANSLATE_RevisionGrid = RevisionGrid;

            this._NO_TRANSLATE_toolStripDropDownButton2.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.localToolStripMenuItem,
            this.remoteToolStripMenuItem});

            this._NO_TRANSLATE_toolStripBranches.DropDown += new System.EventHandler(this.toolStripBranches_DropDown);
            this._NO_TRANSLATE_toolStripBranches.TextUpdate += new System.EventHandler(this.toolStripBranches_TextUpdate);
            this._NO_TRANSLATE_toolStripBranches.Leave += new System.EventHandler(this.toolStripBranches_Leave);
            this._NO_TRANSLATE_toolStripBranches.KeyUp += new System.Windows.Forms.KeyEventHandler(this.toolStripBranches_KeyUp);

            InitToolStripBranchFilter();
        }
        public FilterBranchHelper(ToolStripComboBox toolStripBranches, ToolStripDropDownButton toolStripDropDownButton2, RevisionGrid revisionGrid)
            : this()
        {
            _NO_TRANSLATE_toolStripBranches = toolStripBranches;
            _NO_TRANSLATE_RevisionGrid      = revisionGrid;

            toolStripDropDownButton2.DropDownItems.AddRange(new ToolStripItem[]
            {
                _localToolStripMenuItem,
                _tagsToolStripMenuItem,
                _remoteToolStripMenuItem
            });

            _NO_TRANSLATE_toolStripBranches.DropDown   += toolStripBranches_DropDown;
            _NO_TRANSLATE_toolStripBranches.TextUpdate += toolStripBranches_TextUpdate;
            _NO_TRANSLATE_toolStripBranches.Leave      += toolStripBranches_Leave;
            _NO_TRANSLATE_toolStripBranches.KeyUp      += toolStripBranches_KeyUp;
        }
        public FilterRevisionsHelper(ToolStripTextBox toolStripTextBoxFilter, ToolStripDropDownButton toolStripDropDownButton1, RevisionGrid RevisionGrid, ToolStripLabel toolStripLabel2, Form form)
            : this()
        {
            this._NO_TRANSLATE_toolStripDropDownButton1 = toolStripDropDownButton1;
            this._NO_TRANSLATE_toolStripTextBoxFilter = toolStripTextBoxFilter;
            this._NO_TRANSLATE_RevisionGrid = RevisionGrid;
            this._NO_TRANSLATE_toolStripLabel2 = toolStripLabel2;
            this._NO_TRANSLATE_form = form;

            this._NO_TRANSLATE_toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] {
                this.commitToolStripMenuItem1,
                this.committerToolStripMenuItem,
                this.authorToolStripMenuItem,
                this.diffContainsToolStripMenuItem});

            this._NO_TRANSLATE_toolStripLabel2.Click += this.ToolStripLabel2Click;
            this._NO_TRANSLATE_toolStripTextBoxFilter.Leave += this.ToolStripTextBoxFilterLeave;
            this._NO_TRANSLATE_toolStripTextBoxFilter.KeyPress += this.ToolStripTextBoxFilterKeyPress;
        }
Exemple #28
0
        private void CherryPick_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            if (RevisionGrid.GetRevisions().Count != 1)
            {
                MessageBox.Show("Select 1 revision to pick.", "Cherry pick");
                return;
            }
            bool   formClosed = false;
            string arguments  = "";
            bool   IsMerge    = GitCommandHelpers.IsMerge(RevisionGrid.GetRevisions()[0].Guid);

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

            if (!formClosed)
            {
                MessageBox.Show("Command executed " + Environment.NewLine + GitCommandHelpers.CherryPick(RevisionGrid.GetRevisions()[0].Guid, AutoCommit.Checked, arguments), "Cherry pick");

                MergeConflictHandler.HandleMergeConflicts();

                RevisionGrid.RefreshRevisions();

                Cursor.Current = Cursors.Default;
            }
        }
Exemple #29
0
        public FilterRevisionsHelper(ToolStripTextBox toolStripTextBoxFilter, ToolStripDropDownButton toolStripDropDownButton1, RevisionGrid RevisionGrid, ToolStripLabel toolStripLabel2, Form form)
            : this()
        {
            this._NO_TRANSLATE_toolStripDropDownButton1 = toolStripDropDownButton1;
            this._NO_TRANSLATE_toolStripTextBoxFilter   = toolStripTextBoxFilter;
            this._NO_TRANSLATE_RevisionGrid             = RevisionGrid;
            this._NO_TRANSLATE_toolStripLabel2          = toolStripLabel2;
            this._NO_TRANSLATE_form = form;

            this._NO_TRANSLATE_toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] {
                this.commitToolStripMenuItem1,
                this.committerToolStripMenuItem,
                this.authorToolStripMenuItem,
                this.diffContainsToolStripMenuItem
            });

            this._NO_TRANSLATE_toolStripLabel2.Click           += this.ToolStripLabel2Click;
            this._NO_TRANSLATE_toolStripTextBoxFilter.Leave    += this.ToolStripTextBoxFilterLeave;
            this._NO_TRANSLATE_toolStripTextBoxFilter.KeyPress += this.ToolStripTextBoxFilterKeyPress;
        }
        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);
                }
            }
        }
Exemple #31
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;
        }
        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);
            }
        }
        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);
                }
            }
        }
        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;
        }
        public FilterRevisionsHelper(ToolStripTextBox textBox, ToolStripDropDownButton dropDownButton, RevisionGrid revisionGrid, ToolStripLabel label, ToolStripButton showFirstParentButton, Form form)
            : this()
        {
            this._NO_TRANSLATE_dropDownButton = dropDownButton;
            this._NO_TRANSLATE_textBox = textBox;
            this._NO_TRANSLATE_revisionGrid = revisionGrid;
            this._NO_TRANSLATE_label = label;
            this._NO_TRANSLATE_showFirstParentButton = showFirstParentButton;
            this._NO_TRANSLATE_form = form;

            this._NO_TRANSLATE_dropDownButton.DropDownItems.AddRange(new ToolStripItem[] {
                this.commitToolStripMenuItem,
                this.committerToolStripMenuItem,
                this.authorToolStripMenuItem,
                this.diffContainsToolStripMenuItem});

            this._NO_TRANSLATE_showFirstParentButton.Checked = AppSettings.ShowFirstParent;

            this._NO_TRANSLATE_label.Click += this.ToolStripLabelClick;
            this._NO_TRANSLATE_textBox.Leave += this.ToolStripTextBoxFilterLeave;
            this._NO_TRANSLATE_textBox.KeyPress += this.ToolStripTextBoxFilterKeyPress;
            this._NO_TRANSLATE_showFirstParentButton.Click += this.ToolStripShowFirstParentButtonClick;
            this._NO_TRANSLATE_revisionGrid.ShowFirstParentsToggled += this.RevisionGridShowFirstParentsToggled;       
        }
Exemple #36
0
 public static string GetSelectedPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file)
 {
     IList<GitRevision> revisions = grid.GetSelectedRevisions();
     return GetSelectedPatch(diffViewer, revisions, file);
 }
        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);
        }
        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;
                                       });
            }
        }
        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();
        }
Exemple #40
0
        public RunScript(string script, RevisionGrid RevisionGrid)
        {
            string[] scriptInfo = Settings.GetScript(script);
            string command;
            string argument;

            if (scriptInfo == null)
            {
                command = "cmd";
                argument = "echo \'Cannot find script: " + script + "\'";
            }
            else
            {
                command = scriptInfo[1];
                argument = scriptInfo[2];
            }

            string[] options =
                {
                    "{sTag}",
                    "{sBranch}",
                    "{sLocalBranch}",
                    "{sRemoteBranch}",
                    "{sRemote}",
                    "{sHash}",
                    "{sMessage}",
                    "{sAuthor}",
                    "{sCommitter}",
                    "{sAuthorDate}",
                    "{sCommitDate}",
                    "{cTag}",
                    "{cBranch}",
                    "{cLocalBranch}",
                    "{cRemoteBranch}",
                    "{cHash}",
                    "{cMessage}",
                    "{cAuthor}",
                    "{cCommitter}",
                    "{cAuthorDate}",
                    "{cCommitDate}"
                };

            GitRevision selectedRevision = null;
            GitRevision currentRevision = null;

            var selectedLocalBranches = new List<GitHead>();
            var selectedRemoteBranches = new List<GitHead>();
            var selectedRemotes = new List<string>();
            var selectedBranches = new List<GitHead>();
            var selectedTags = new List<GitHead>();
            var currentLocalBranches = new List<GitHead>();
            var currentRemoteBranches = new List<GitHead>();
            var currentBranches = new List<GitHead>();
            var currentTags = new List<GitHead>();

            foreach (string option in options)
            {
                if (argument.Contains(option))
                {
                    if (option.StartsWith("{s") && selectedRevision == null)
                    {
                        selectedRevision = RevisionGrid.GetRevision(RevisionGrid.LastRow);
                        foreach (GitHead head in selectedRevision.Heads)
                        {
                            if (head.IsTag)
                                selectedTags.Add(head);

                            else if (head.IsHead || head.IsRemote)
                            {
                                selectedBranches.Add(head);
                                if (head.IsRemote)
                                {
                                    selectedRemoteBranches.Add(head);
                                    if (!selectedRemotes.Contains(head.Remote))
                                        selectedRemotes.Add(head.Remote);
                                }
                                else
                                    selectedLocalBranches.Add(head);
                            }
                        }
                    }
                    else if (option.StartsWith("{c") && currentRevision == null)
                    {
                        currentRevision = RevisionGrid.GetCurrentRevision();

                        foreach (GitHead head in currentRevision.Heads)
                        {
                            if (head.IsTag)
                                currentTags.Add(head);
                            else if (head.IsHead || head.IsRemote)
                            {
                                currentBranches.Add(head);
                                if (head.IsRemote)
                                    currentRemoteBranches.Add(head);
                                else
                                    currentLocalBranches.Add(head);
                            }
                        }
                    }

                    switch (option)
                    {
                        case "{sTag}":
                            if (selectedTags.Count == 1)
                                argument = argument.Replace(option, selectedTags[0].Name);
                            else if (selectedTags.Count != 0)
                                argument = argument.Replace(option, askToSpecify(selectedTags, "Selected Revision Tag"));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{sBranch}":
                            if (selectedBranches.Count == 1)
                                argument = argument.Replace(option, selectedBranches[0].Name);
                            else if (selectedBranches.Count != 0)
                                argument = argument.Replace(option,
                                                            askToSpecify(selectedBranches, "Selected Revision Branch"));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{sLocalBranch}":
                            if (selectedLocalBranches.Count == 1)
                                argument = argument.Replace(option, selectedLocalBranches[0].Name);
                            else if (selectedLocalBranches.Count != 0)
                                argument = argument.Replace(option,
                                                            askToSpecify(selectedLocalBranches,
                                                                         "Selected Revision Local Branch"));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{sRemoteBranch}":
                            if (selectedRemoteBranches.Count == 1)
                                argument = argument.Replace(option, selectedRemoteBranches[0].Name);
                            else if (selectedRemoteBranches.Count != 0)
                                argument = argument.Replace(option,
                                                            askToSpecify(selectedRemoteBranches,
                                                                         "Selected Revision Remote Branch"));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{sRemote}":
                            if (selectedRemotes.Count == 1)
                                argument = argument.Replace(option, selectedRemotes[0]);
                            else if (selectedRemotes.Count != 0)
                            {
                                argument = argument.Replace(option,
                                                            askToSpecify(selectedRemotes, "Selected Revision Remote"));
                            }
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{sHash}":
                            argument = argument.Replace(option, selectedRevision.Guid);
                            break;
                        case "{sMessage}":
                            argument = argument.Replace(option, selectedRevision.Message);
                            break;
                        case "{sAuthor}":
                            argument = argument.Replace(option, selectedRevision.Author);
                            break;
                        case "{sCommitter}":
                            argument = argument.Replace(option, selectedRevision.Committer);
                            break;
                        case "{sAuthorDate}":
                            argument = argument.Replace(option, selectedRevision.AuthorDate.ToString());
                            break;
                        case "{sCommitDate}":
                            argument = argument.Replace(option, selectedRevision.CommitDate.ToString());
                            break;
                        case "{cTag}":
                            if (currentTags.Count == 1)
                                argument = argument.Replace(option, currentTags[0].Name);
                            else if (currentTags.Count != 0)
                                argument = argument.Replace(option, askToSpecify(currentTags, "Current Revision Tag"));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{cBranch}":
                            if (currentBranches.Count == 1)
                                argument = argument.Replace(option, currentBranches[0].Name);
                            else if (currentBranches.Count != 0)
                                argument = argument.Replace(option,
                                                            askToSpecify(currentBranches, "Current Revision Branch"));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{cLocalBranch}":
                            if (currentLocalBranches.Count == 1)
                                argument = argument.Replace(option, currentLocalBranches[0].Name);
                            else if (currentLocalBranches.Count != 0)
                                argument = argument.Replace(option,
                                                            askToSpecify(currentLocalBranches,
                                                                         "Current Revision Local Branch"));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{cRemoteBranch}":
                            if (currentRemoteBranches.Count == 1)
                                argument = argument.Replace(option, currentRemoteBranches[0].Name);
                            else if (currentRemoteBranches.Count != 0)
                                argument = argument.Replace(option,
                                                            askToSpecify(currentRemoteBranches,
                                                                         "Current Revision Remote Branch"));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{cHash}":
                            argument = argument.Replace(option, currentRevision.Guid);
                            break;
                        case "{cMessage}":
                            argument = argument.Replace(option, currentRevision.Message);
                            break;
                        case "{cAuthor}":
                            argument = argument.Replace(option, currentRevision.Author);
                            break;
                        case "{cCommitter}":
                            argument = argument.Replace(option, currentRevision.Committer);
                            break;
                        case "{cAuthorDate}":
                            argument = argument.Replace(option, currentRevision.AuthorDate.ToString());
                            break;
                        case "{cCommitDate}":
                            argument = argument.Replace(option, currentRevision.CommitDate.ToString());
                            break;
                        default:
                            break;
                    }
                }
            }

            new FormProcess(command, argument).ShowDialog();
        }
        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);
            }
        }
Exemple #42
0
 public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
 {
     IList<GitRevision> revisions = grid.GetSelectedRevisions();
     ViewPatch(diffViewer, revisions, file, defaultText);
 }
        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;
                                   });
        }
Exemple #44
0
        private void FormDiffLoad(object sender, EventArgs e)
        {
            RevisionGrid.Load();

            RestorePosition("diff");
        }
        public static void ViewPatch(this FileViewer diffViewer, RevisionGrid grid, GitItemStatus file, string defaultText)
        {
            diffViewer.ViewPatch(() =>
                                   {
                                       string selectedPatch = diffViewer.GetSelectedPatch(grid, file);

                                       return selectedPatch ?? defaultText;
                                   });
        }
Exemple #46
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);
            }
        }
        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;
        }
 public FormBisect(RevisionGrid revisionGrid)
     : this(revisionGrid.UICommands)
 {
     _revisionGrid = revisionGrid;
     UpdateButtonsState();
 }