Exemplo n.º 1
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.º 2
0
 public IssueTrackerWatcher(RevisionGrid revisionGrid, DvcsGraph revisions)
 {
     this.revisionGrid             = revisionGrid;
     this.revisions                = revisions;
     IssueStatusImageColumnIndex   = -1;
     IssueStatusMessageColumnIndex = -1;
 }
Exemplo n.º 3
0
 public BuildServerWatcher(RevisionGrid revisionGrid, DvcsGraph revisions)
 {
     this.revisionGrid             = revisionGrid;
     this.revisions                = revisions;
     BuildStatusImageColumnIndex   = -1;
     BuildStatusMessageColumnIndex = -1;
 }
Exemplo n.º 4
0
 public BuildServerWatcher(RevisionGrid revisionGrid, DvcsGraph revisions)
 {
     this.revisionGrid = revisionGrid;
     this.revisions = revisions;
     BuildStatusImageColumnIndex = -1;
     BuildStatusMessageColumnIndex = -1;
 }
Exemplo n.º 5
0
        public void LoadBlame(string guid, string fileName, RevisionGrid revGrid)
        {
            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile      = new StringBuilder();

            _revGrid = revGrid;

            _blame = GitCommandHelpers.Blame(fileName, guid);

            for (int i = 0; i < _blame.Lines.Count; i++)
            {
                GitBlameLine   blameLine   = _blame.Lines[i];
                GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                {
                    blameCommitter.AppendLine(new string(' ', 200));
                }
                else
                {
                    blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime.ToString() + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new char[] { '\r', '\n' }));
                }
                blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
            }

            BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
            BlameFile.ViewText(fileName, blameFile.ToString());
            BlameFile.ScrollPos = scrollpos;

            BlameFile_SelectedLineChanged(null, 0);
        }
Exemplo n.º 6
0
        public FormDiff(GitUICommands aCommands, RevisionGrid revisionGrid, string baseCommitSha,
            string headCommitSha, string baseCommitDisplayStr, string headCommitDisplayStr) : base(aCommands)
        {
            RevisionGrid = revisionGrid;
            _baseCommitDisplayStr = baseCommitDisplayStr;
            _headCommitDisplayStr = headCommitDisplayStr;

            InitializeComponent();
            Translate();

            _toolTipControl.SetToolTip(btnAnotherBaseBranch, anotherBranchTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherHeadBranch, anotherBranchTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherBaseCommit, anotherCommitTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherHeadCommit, anotherCommitTooltip.Text);
            _toolTipControl.SetToolTip(btnSwap, btnSwapTooltip.Text);

            if (!IsUICommandsInitialized)
            {// UICommands is not initialized in translation unit test.
                return;
            }

            _baseRevision = new GitRevision(Module, baseCommitSha);
            _headRevision = new GitRevision(Module, headCommitSha);
            _mergeBase = new GitRevision(Module, Module.GetMergeBase(_baseRevision.Guid, _headRevision.Guid));

            lblBaseCommit.BackColor = AppSettings.DiffRemovedColor;
            lblHeadCommit.BackColor = AppSettings.DiffAddedColor;

            DiffFiles.SelectedIndexChanged += DiffFiles_SelectedIndexChanged;

            DiffFiles.ContextMenuStrip = DiffContextMenu;

            this.Load += (sender, args) => PopulateDiffFiles();
        }
Exemplo n.º 7
0
 public RevisionGridMenuCommands(RevisionGrid revisionGrid)
 {
     _revisionGrid = revisionGrid;
     CreateOrUpdateMenuCommands(); // for translation
     TranslationCategoryName = "RevisionGrid";
     Translate();
 }
Exemplo n.º 8
0
        public void LoadBlame(GitRevision revision, List <string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding, int?initialLine = null, bool force = false)
        {
            //refresh only when something changed
            string guid = revision.Guid;

            if (!force && guid.Equals(_blameHash) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
            {
                return;
            }

            if (controlToMask != null)
            {
                controlToMask.Mask();
            }

            var scrollpos = BlameFile.ScrollPos;

            int line = initialLine.GetValueOrDefault(0);

            if (_clickedBlameLine.CommitGuid == guid)
            {
                line = _clickedBlameLine.OriginLineNumber;
            }
            _revGrid  = revGrid;
            _fileName = fileName;
            _encoding = encoding;

            blameLoader.Load(() => _blame = Module.Blame(fileName, guid, encoding),
                             () => ProcessBlame(revision, children, controlToMask, line, scrollpos));
        }
Exemplo n.º 9
0
        public static bool RunScript(IWin32Window owner, GitModule aModule, string script, RevisionGrid revisionGrid)
        {
            if (string.IsNullOrEmpty(script))
                return false;

            ScriptInfo scriptInfo = ScriptManager.GetScript(script);

            if (scriptInfo == null)
            {
                MessageBox.Show(owner, "Cannot find script: " + script, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            if (string.IsNullOrEmpty(scriptInfo.Command))
                return false;

            string argument = scriptInfo.Arguments;
            foreach (string option in Options)
            {
                if (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                    continue;
                if (!option.StartsWith("{s"))
                    continue;
                if (revisionGrid != null)
                    continue;
                MessageBox.Show(owner,
                    string.Format("Option {0} is only supported when started from revision grid.", option),
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            return RunScript(owner, aModule, scriptInfo, revisionGrid);
        }
Exemplo n.º 10
0
 private void RevisionGridSelectionChanged(object sender, EventArgs e)
 {
     using (WaitCursorScope.Enter())
     {
         DiffFiles.SetDiffs(RevisionGrid.GetSelectedRevisions());
     }
 }
Exemplo n.º 11
0
        public FormDiff(GitUICommands aCommands, RevisionGrid revisionGrid, string baseCommitSha,
                        string headCommitSha, string baseCommitDisplayStr, string headCommitDisplayStr) : base(aCommands)
        {
            RevisionGrid          = revisionGrid;
            _baseCommitDisplayStr = baseCommitDisplayStr;
            _headCommitDisplayStr = headCommitDisplayStr;

            InitializeComponent();
            Translate();

            _toolTipControl.SetToolTip(btnAnotherBaseBranch, anotherBranchTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherHeadBranch, anotherBranchTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherBaseCommit, anotherCommitTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherHeadCommit, anotherCommitTooltip.Text);
            _toolTipControl.SetToolTip(btnSwap, btnSwapTooltip.Text);

            if (!IsUICommandsInitialized)
            {// UICommands is not initialized in translation unit test.
                return;
            }

            _baseRevision = new GitRevision(baseCommitSha);
            _headRevision = new GitRevision(headCommitSha);
            _mergeBase    = new GitRevision(Module.GetMergeBase(_baseRevision.Guid, _headRevision.Guid));

            lblBaseCommit.BackColor = AppSettings.DiffRemovedColor;
            lblHeadCommit.BackColor = AppSettings.DiffAddedColor;

            DiffFiles.SelectedIndexChanged += DiffFiles_SelectedIndexChanged;

            DiffFiles.ContextMenuStrip = DiffContextMenu;

            this.Load += (sender, args) => PopulateDiffFiles();
            this.DiffText.ExtraDiffArgumentsChanged += DiffTextOnExtraDiffArgumentsChanged;
        }
Exemplo n.º 12
0
        public void LoadBlame(string guid, string fileName, RevisionGrid revGrid)
        {
            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile = new StringBuilder();
            _revGrid = revGrid;

            _blame = GitCommandHelpers.Blame(fileName, guid);

            for (int i = 0; i < _blame.Lines.Count; i++ )
            {
                GitBlameLine blameLine = _blame.Lines[i];
                GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                if (i > 0 && _blame.Lines[i-1].CommitGuid == blameLine.CommitGuid)
                {
                    blameCommitter.AppendLine(new string(' ', 200));
                } else
                {
                    blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime.ToString() + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new char[] { '\r', '\n' }));
                }
                if (blameLine.LineText == null )
                    blameFile.AppendLine("");
                else
                    blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
            }

            BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
            BlameFile.ViewText(fileName, blameFile.ToString());
            BlameFile.ScrollPos = scrollpos;

            BlameFile_SelectedLineChanged(null, 0);
        }
Exemplo n.º 13
0
        public static void RunScript(string script, RevisionGrid RevisionGrid)
        {
            if (string.IsNullOrEmpty(script))
                return;

            ScriptInfo scriptInfo = ScriptManager.GetScript(script);

            if (scriptInfo == null)
            {
                MessageBox.Show("Cannot find script: " + script, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrEmpty(scriptInfo.Command))
                return;

            string argument = scriptInfo.Arguments;
            foreach (string option in Options)
            {
                if (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                    continue;
                if (!option.StartsWith("{s"))
                    continue;
                if (RevisionGrid != null)
                    continue;
                MessageBox.Show(
                    string.Format("Option {0} is only supported when started from revision grid.", option),
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            RunScript(scriptInfo, RevisionGrid);
        }
 public RevisionGridMenuCommands(RevisionGrid revisionGrid)
 {
     _revisionGrid = revisionGrid;
     CreateOrUpdateMenuCommands(); // for translation
     TranslationCategoryName = "RevisionGrid";
     Translate();
 }
Exemplo n.º 15
0
        public void LoadBlame(GitRevision revision, IReadOnlyList <string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding, int?initialLine = null, bool force = false)
        {
            string guid = revision.Guid;

            // refresh only when something changed
            if (!force && guid == _blameHash && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
            {
                return;
            }

            controlToMask?.Mask();

            var scrollpos = BlameFile.ScrollPos;

            var line = _clickedBlameLine != null && _clickedBlameLine.Commit.ObjectId == guid
                ? _clickedBlameLine.OriginLineNumber
                : initialLine ?? 0;

            _revGrid  = revGrid;
            _fileName = fileName;
            _encoding = encoding;

            _blameLoader.LoadAsync(() => _blame = Module.Blame(fileName, guid, encoding),
                                   () => ProcessBlame(revision, children, controlToMask, line, scrollpos));
        }
Exemplo n.º 16
0
        private static GitRevision CalculateSelectedRevision(RevisionGrid RevisionGrid, List <GitHead> selectedRemoteBranches,
                                                             List <string> selectedRemotes, List <GitHead> selectedLocalBranches,
                                                             List <GitHead> selectedBranches, List <GitHead> selectedTags)
        {
            GitRevision 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);
                    }
                }
            }
            return(selectedRevision);
        }
Exemplo n.º 17
0
        private static GitRevision CalculateSelectedRevision(RevisionGrid revisionGrid, List <IGitRef> selectedRemoteBranches,
                                                             List <string> selectedRemotes, List <IGitRef> selectedLocalBranches,
                                                             List <IGitRef> selectedBranches, List <IGitRef> selectedTags)
        {
            GitRevision selectedRevision = revisionGrid.LatestSelectedRevision;

            foreach (GitRef head in selectedRevision.Refs)
            {
                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);
                    }
                }
            }
            return(selectedRevision);
        }
Exemplo n.º 18
0
 public BuildServerWatcher(RevisionGrid revisionGrid, DvcsGraph revisions)
 {
     _revisionGrid                 = revisionGrid;
     _revisions                    = revisions;
     _repoNameExtractor            = new RepoNameExtractor(() => Module);
     BuildStatusImageColumnIndex   = -1;
     BuildStatusMessageColumnIndex = -1;
 }
Exemplo n.º 19
0
        public FormBrowseMenuCommands(FormBrowse formBrowse, RevisionGrid revisionGrid)
        {
            TranslationCategoryName = "FormBrowse";
            Translate();

            _formBrowse  = formBrowse;
            RevisionGrid = revisionGrid;
        }
        public FormBrowseMenuCommands(FormBrowse formBrowse, RevisionGrid revisionGrid)
        {
            TranslationCategoryName = "FormBrowse";
            Translate();

            _formBrowse = formBrowse;
            RevisionGrid = revisionGrid;
        }
Exemplo n.º 21
0
 private void ViewSelectedFileDiff()
 {
     using (WaitCursorScope.Enter())
     {
         var revisions   = RevisionGrid.GetSelectedRevisions();
         var selectedRev = revisions.FirstOrDefault();
         var firstId     = revisions.Skip(1).LastOrDefault()?.ObjectId ?? selectedRev?.FirstParentGuid;
         diffViewer.ViewChangesAsync(firstId, selectedRev, DiffFiles.SelectedItem);
     }
 }
Exemplo n.º 22
0
        public void LoadBlame(string guid, string fileName, RevisionGrid revGrid = null)
        {
            var scrollpos = BlameFile.ScrollPos;

            _revGrid = revGrid;
            Blame = Settings.Module.Blame(fileName, guid);

            LoadBlame_SetupBlameCommitter();
            LoadBlame_SetupBlameFile(fileName, scrollpos);
            commitInfo.SetRevision(guid);
        }
Exemplo n.º 23
0
        private void FormFormatPath_Load(object sender, EventArgs e)
        {
            OutputPath.Text = AppSettings.LastFormatPatchDir;
            string selectedHead = Module.GetSelectedBranch();

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

            SaveToDir_CheckedChanged(null, null);
            OutputPath.TextChanged += OutputPath_TextChanged;
            RevisionGrid.Load();
        }
Exemplo n.º 24
0
        private void ViewSelectedFileDiff()
        {
            if (DiffFiles.SelectedItem == null)
            {
                diffViewer.ViewPatch("");
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            diffViewer.ViewChanges(RevisionGrid.GetSelectedRevisions(), DiffFiles.SelectedItem, String.Empty);
            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 25
0
        public void LoadBlame(GitRevision revision, List<string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            //refresh only when something changed
            if (revision.Equals(CommitInfo.Revision) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
                return;

            if (controlToMask != null)
                controlToMask.Mask();

            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile = new StringBuilder();
            _revGrid = revGrid;
            _fileName = fileName;
            _encoding = encoding;
            string guid = revision.Guid;

            blameLoader.Load(() =>
            {
                _blame = Module.Blame(fileName, guid, encoding);
            },
            () =>
            {

                for (int i = 0; i < _blame.Lines.Count; i++)
                {
                    GitBlameLine blameLine = _blame.Lines[i];
                    GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                    if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                    {
                        blameCommitter.AppendLine(new string(' ', 200));
                    }
                    else
                    {
                        blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new[] { '\r', '\n' }));
                    }
                    if (blameLine.LineText == null)
                        blameFile.AppendLine("");
                    else
                        blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
                }

                BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
                BlameFile.ViewText(fileName, blameFile.ToString());
                BlameFile.ScrollPos = scrollpos;

                CommitInfo.SetRevisionWithChildren(revision, children);

                if (controlToMask != null)
                    controlToMask.UnMask();
            });
        }
Exemplo n.º 26
0
        private void ViewSelectedFileDiff()
        {
            if (DiffFiles.SelectedItem == null)
            {
                diffViewer.ViewPatch("");
                return;
            }

            using (WaitCursorScope.Enter())
            {
                diffViewer.ViewChangesAsync(RevisionGrid.GetSelectedRevisions(), DiffFiles.SelectedItem, string.Empty);
            }
        }
Exemplo n.º 27
0
        /// <summary>Tries to run scripts identified by a <paramref name="command"/> 
        /// and returns true if any executed.</summary>
        public static bool ExecuteScriptCommand(IWin32Window owner, GitModule aModule, int command, RevisionGrid revisionGrid = null)
        {
            var curScripts = ScriptManager.GetScripts();
            bool anyScriptExecuted = false;

            foreach (ScriptInfo s in curScripts)
            {
                if (s.HotkeyCommandIdentifier == command)
                {
                    RunScript(owner, aModule, s.Name, revisionGrid);
                    anyScriptExecuted = true;
                }
            }
            return anyScriptExecuted;
        }
Exemplo n.º 28
0
        private static GitRevision GetCurrentRevision(RevisionGrid RevisionGrid, List <GitHead> currentTags, List <GitHead> currentLocalBranches,
                                                      List <GitHead> currentRemoteBranches, List <GitHead> currentBranches,
                                                      GitRevision currentRevision, string option)
        {
            if (option.StartsWith("{c") && currentRevision == null)
            {
                IList <GitHead> heads;

                if (RevisionGrid == null)
                {
                    heads = new List <GitHead>();
                    string currentRevisionGuid = Settings.Module.GetCurrentCheckout();
                    foreach (GitHead head in Settings.Module.GetHeads(true, true))
                    {
                        if (head.Guid == currentRevisionGuid)
                        {
                            heads.Add(head);
                        }
                    }
                }
                else
                {
                    currentRevision = RevisionGrid.GetCurrentRevision();
                    heads           = currentRevision.Heads;
                }

                foreach (GitHead head in 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);
                        }
                    }
                }
            }
            return(currentRevision);
        }
Exemplo n.º 29
0
        private void ViewSelectedFileDiff()
        {
            if (DiffFiles.SelectedItem == null)
            {
                diffViewer.Clear();
                return;
            }

            using (WaitCursorScope.Enter())
            {
                var revisions   = RevisionGrid.GetSelectedRevisions();
                var selectedRev = revisions.FirstOrDefault();
                var firstId     = revisions.Skip(1).LastOrDefault()?.ObjectId;
                diffViewer.ViewChangesAsync(firstId, selectedRev, DiffFiles.SelectedItem, string.Empty);
            }
        }
Exemplo n.º 30
0
        public void LoadBlame(GitRevision revision, List<string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            //refresh only when something changed
            if (revision.Equals(CommitInfo.Revision) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
                return;

            if (controlToMask != null)
                controlToMask.Mask();

            var scrollpos = BlameFile.ScrollPos;

            _revGrid = revGrid;
            _fileName = fileName;
            _encoding = encoding;
            string guid = revision.Guid;

            blameLoader.Load(() => _blame = Module.Blame(fileName, guid, encoding),
                () => ProcessBlame(revision, children, controlToMask, scrollpos));
        }
Exemplo n.º 31
0
        public static void RunScript(string script, RevisionGrid RevisionGrid)
        {
            if (string.IsNullOrEmpty(script))
            {
                return;
            }

            ScriptInfo scriptInfo = ScriptManager.GetScript(script);

            if (scriptInfo == null)
            {
                MessageBox.Show("Cannot find script: " + script, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrEmpty(scriptInfo.Command))
            {
                return;
            }

            string argument = scriptInfo.Arguments;

            foreach (string option in Options)
            {
                if (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                {
                    continue;
                }
                if (!option.StartsWith("{s"))
                {
                    continue;
                }
                if (RevisionGrid != null)
                {
                    continue;
                }
                MessageBox.Show(
                    string.Format("Option {0} is only supported when started from revision grid.", option),
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            RunScript(scriptInfo, RevisionGrid);
        }
Exemplo n.º 32
0
        private static GitRevision GetCurrentRevision(GitModule module, RevisionGrid revisionGrid, List <IGitRef> currentTags, List <IGitRef> currentLocalBranches,
                                                      List <IGitRef> currentRemoteBranches, List <IGitRef> currentBranches,
                                                      GitRevision currentRevision)
        {
            if (currentRevision == null)
            {
                IList <IGitRef> refs;

                if (revisionGrid == null)
                {
                    string currentRevisionGuid = module.GetCurrentCheckout();
                    refs = module.GetRefs(true, true).Where(gitRef => gitRef.Guid == currentRevisionGuid).ToList();
                }
                else
                {
                    currentRevision = revisionGrid.GetCurrentRevision();
                    refs            = currentRevision.Refs;
                }

                foreach (IGitRef gitRef in refs)
                {
                    if (gitRef.IsTag)
                    {
                        currentTags.Add(gitRef);
                    }
                    else if (gitRef.IsHead || gitRef.IsRemote)
                    {
                        currentBranches.Add(gitRef);
                        if (gitRef.IsRemote)
                        {
                            currentRemoteBranches.Add(gitRef);
                        }
                        else
                        {
                            currentLocalBranches.Add(gitRef);
                        }
                    }
                }
            }

            return(currentRevision);
        }
Exemplo n.º 33
0
        public FormDiff(GitUICommands commands, RevisionGrid revisionGrid, string baseCommitSha,
                        string headCommitSha, string baseCommitDisplayStr, string headCommitDisplayStr) : base(commands)
        {
            _revisionGrid         = revisionGrid;
            _baseCommitDisplayStr = baseCommitDisplayStr;
            _headCommitDisplayStr = headCommitDisplayStr;

            InitializeComponent();
            Translate();

            _toolTipControl.SetToolTip(btnAnotherBaseBranch, _anotherBranchTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherHeadBranch, _anotherBranchTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherBaseCommit, _anotherCommitTooltip.Text);
            _toolTipControl.SetToolTip(btnAnotherHeadCommit, _anotherCommitTooltip.Text);
            _toolTipControl.SetToolTip(btnSwap, _btnSwapTooltip.Text);

            if (!IsUICommandsInitialized)
            {
                // UICommands is not initialized in translation unit test.
                return;
            }

            _baseRevision                      = new GitRevision(baseCommitSha);
            _headRevision                      = new GitRevision(headCommitSha);
            _mergeBase                         = new GitRevision(Module.GetMergeBase(_baseRevision.Guid, _headRevision.Guid));
            _fullPathResolver                  = new FullPathResolver(() => Module.WorkingDir);
            _findFilePredicateProvider         = new FindFilePredicateProvider();
            _revisionTester                    = new GitRevisionTester(_fullPathResolver);
            _revisionDiffContextMenuController = new FileStatusListContextMenuController();

            lblBaseCommit.BackColor = AppSettings.DiffRemovedColor;
            lblHeadCommit.BackColor = AppSettings.DiffAddedColor;

            DiffFiles.SelectedIndexChanged += DiffFiles_SelectedIndexChanged;

            DiffFiles.ContextMenuStrip = DiffContextMenu;

            Load += (sender, args) => PopulateDiffFiles();
            DiffText.ExtraDiffArgumentsChanged += DiffTextOnExtraDiffArgumentsChanged;
        }
Exemplo n.º 34
0
        public void LoadBlame(string guid, string fileName, RevisionGrid revGrid)
        {
            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile      = new StringBuilder();

            _revGrid = revGrid;

            _blame = Settings.Module.Blame(fileName, guid);

            for (int i = 0; i < _blame.Lines.Count; i++)
            {
                GitBlameLine   blameLine   = _blame.Lines[i];
                GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                {
                    blameCommitter.AppendLine(new string(' ', 200));
                }
                else
                {
                    blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new[] { '\r', '\n' }));
                }
                if (blameLine.LineText == null)
                {
                    blameFile.AppendLine("");
                }
                else
                {
                    blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
                }
            }

            BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
            BlameFile.ViewText(fileName, blameFile.ToString());
            BlameFile.ScrollPos = scrollpos;

            commitInfo.SetRevision(guid);
        }
Exemplo n.º 35
0
        public void LoadBlame(GitRevision revision, List<string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            //refresh only when something changed
            string guid = revision.Guid;
            if (guid.Equals(_blameHash) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
                return;

            if (controlToMask != null)
                controlToMask.Mask();

            var scrollpos = BlameFile.ScrollPos;

            int line = 0;
            if (_clickedBlameLine.CommitGuid == guid)
                line = _clickedBlameLine.OriginLineNumber;
            _revGrid = revGrid;
            _fileName = fileName;
            _encoding = encoding;

            blameLoader.Load(() => _blame = Module.Blame(fileName, guid, encoding),
                () => ProcessBlame(revision, children, controlToMask, line, scrollpos));
        }
Exemplo n.º 36
0
        public FormDiff(GitUICommands aCommands, RevisionGrid revisionGrid, string leftCommitSha,
                        string rightCommitSha, string leftDisplayStr, string rightDisplayStr) : base(aCommands)
        {
            RevisionGrid     = revisionGrid;
            _leftDisplayStr  = leftDisplayStr;
            _rightDisplayStr = rightDisplayStr;

            InitializeComponent();
            Translate();

            _leftRevision  = new GitRevision(Module, leftCommitSha);
            _rightRevision = new GitRevision(Module, rightCommitSha);
            _mergeBase     = new GitRevision(Module, Module.GetMergeBase(_leftRevision.Guid, _rightRevision.Guid));

            lblLeftCommit.BackColor  = AppSettings.DiffRemovedColor;
            lblRightCommit.BackColor = AppSettings.DiffAddedColor;

            DiffFiles.SelectedIndexChanged += DiffFiles_SelectedIndexChanged;

            DiffFiles.ContextMenuStrip = DiffContextMenu;

            this.Load += (sender, args) => PopulateDiffFiles();
        }
Exemplo n.º 37
0
        public void LoadBlame(GitRevision revision, List <string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            //refresh only when something changed
            if (revision.Equals(CommitInfo.Revision) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
            {
                return;
            }

            if (controlToMask != null)
            {
                controlToMask.Mask();
            }

            var scrollpos = BlameFile.ScrollPos;

            _revGrid  = revGrid;
            _fileName = fileName;
            _encoding = encoding;
            string guid = revision.Guid;

            blameLoader.Load(() => _blame = Module.Blame(fileName, guid, encoding),
                             () => ProcessBlame(revision, children, controlToMask, scrollpos));
        }
Exemplo n.º 38
0
        internal static void RunScript(ScriptInfo scriptInfo, RevisionGrid RevisionGrid)
        {
            string command = scriptInfo.Command;
            string argument = scriptInfo.Arguments;

            command = OverrideCommandWhenNecessary(command);

            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 (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                    continue;
                if (!option.StartsWith("{s") || selectedRevision != null)
                {
                    currentRevision = GetCurrentRevision(RevisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision, option);
                }
                else
                {
                    selectedRevision = CalculateSelectedRevision(RevisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags);
                }

                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;
                    case "{cDefaultRemote}":
                        if (currentBranches.Count == 1)
                            argument = argument.Replace(option,
                                                        Settings.Module.GetSetting(string.Format("branch.{0}.remote",
                                                                                                 currentBranches[0].Name)));
                        else if (currentBranches.Count != 0)
                            argument = argument.Replace(option,
                                                        Settings.Module.GetSetting(string.Format("branch.{0}.remote",
                                                                                                 askToSpecify(
                                                                                                     currentBranches,
                                                                                                     "Current Revision Branch"))));
                        else
                            argument = argument.Replace(option, "");
                        break;
                    case "{UserInput}":
                        SimplePrompt Prompt = new SimplePrompt();
                        Prompt.ShowDialog();
                        argument = argument.Replace(option, Prompt.UserInput);
                        break;
                }
            }

            new FormProcess(command, argument).ShowDialog();
        }
Exemplo n.º 39
0
        internal static bool RunScript(IWin32Window owner, GitModule aModule, ScriptInfo scriptInfo, RevisionGrid revisionGrid)
        {
            string originalCommand = scriptInfo.Command;
            string argument = scriptInfo.Arguments;

            string command = OverrideCommandWhenNecessary(originalCommand);
            var allSelectedRevisions = new List<GitRevision>();

            GitRevision selectedRevision = null;
            GitRevision currentRevision = null;

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

            foreach (string option in Options)
            {
                if (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                    continue;
                if (option.StartsWith("{c") && currentRevision == null)
                {
                    currentRevision = GetCurrentRevision(aModule, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision);

                    if (currentLocalBranches.Count == 1)
                        currentRemote = aModule.GetSetting(string.Format("branch.{0}.remote", currentLocalBranches[0].Name));
                    else
                    {
                        currentRemote = aModule.GetCurrentRemote();
                        if (string.IsNullOrEmpty(currentRemote))
                            currentRemote = aModule.GetSetting(string.Format("branch.{0}.remote",
                                askToSpecify(currentLocalBranches, "Current Revision Branch")));
                    }
                }
                else if (option.StartsWith("{s") && selectedRevision == null && revisionGrid != null)
                {
                    allSelectedRevisions = revisionGrid.GetSelectedRevisions();
                    allSelectedRevisions.Reverse(); // Put first clicked revisions first
                    selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags);
                }

                string remote;
                string url;
                switch (option)
                {
                    case "{sHashes}":
                        argument = argument.Replace(option,
                            string.Join(" ", allSelectedRevisions.Select(revision => revision.Guid).ToArray()));
                        break;
                    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 == 0)
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        if (selectedRemotes.Count == 1)
                            remote = selectedRemotes[0];
                        else
                            remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                        argument = argument.Replace(option, remote);
                        break;
                    case "{sRemoteUrl}":
                        if (selectedRemotes.Count == 0)
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        if (selectedRemotes.Count == 1)
                            remote = selectedRemotes[0];
                        else
                            remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                        url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote));
                        argument = argument.Replace(option, url);
                        break;
                    case "{sRemotePathFromUrl}":
                        if (selectedRemotes.Count == 0)
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        if (selectedRemotes.Count == 1)
                            remote = selectedRemotes[0];
                        else
                            remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                        url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote));
                        argument = argument.Replace(option, GetRemotePath(url));
                        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;
                    case "{cDefaultRemote}":
                        if (string.IsNullOrEmpty(currentRemote))
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        argument = argument.Replace(option, currentRemote);
                        break;
                    case "{cDefaultRemoteUrl}":
                        if (string.IsNullOrEmpty(currentRemote))
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote));
                        argument = argument.Replace(option, url);
                        break;
                    case "{cDefaultRemotePathFromUrl}":
                        if (string.IsNullOrEmpty(currentRemote))
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote));
                        argument = argument.Replace(option, GetRemotePath(url));
                        break;
                    case "{UserInput}":
                        using (SimplePrompt Prompt = new SimplePrompt())
                        {
                            Prompt.ShowDialog();
                            argument = argument.Replace(option, Prompt.UserInput);
                        }
                        break;
                    case "{WorkingDir}":
                        argument = argument.Replace(option, aModule.WorkingDir);
                        break;
                }
            }
            command = ExpandCommandVariables(command,aModule);

            if (!scriptInfo.RunInBackground)
                FormProcess.ShowDialog(owner, command, argument, aModule.WorkingDir, null, true);
            else
            {
                if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase))
                    Process.Start(argument);
                else
                    aModule.RunExternalCmdDetached(command, argument);
            }
            return !scriptInfo.RunInBackground;
        }
Exemplo n.º 40
0
        internal static void RunScript(ScriptInfo scriptInfo, RevisionGrid RevisionGrid)
        {
            string command  = scriptInfo.Command;
            string argument = scriptInfo.Arguments;

            command = OverrideCommandWhenNecessary(command);

            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 (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                {
                    continue;
                }
                if (!option.StartsWith("{s") || selectedRevision != null)
                {
                    currentRevision = GetCurrentRevision(RevisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision, option);
                }
                else
                {
                    selectedRevision = CalculateSelectedRevision(RevisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags);
                }

                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;

                case "{cDefaultRemote}":
                    if (currentBranches.Count == 1)
                    {
                        argument = argument.Replace(option,
                                                    Settings.Module.GetSetting(string.Format("branch.{0}.remote",
                                                                                             currentBranches[0].Name)));
                    }
                    else if (currentBranches.Count != 0)
                    {
                        argument = argument.Replace(option,
                                                    Settings.Module.GetSetting(string.Format("branch.{0}.remote",
                                                                                             askToSpecify(
                                                                                                 currentBranches,
                                                                                                 "Current Revision Branch"))));
                    }
                    else
                    {
                        argument = argument.Replace(option, "");
                    }
                    break;

                case "{UserInput}":
                    SimplePrompt Prompt = new SimplePrompt();
                    Prompt.ShowDialog();
                    argument = argument.Replace(option, Prompt.UserInput);
                    break;
                }
            }

            new FormProcess(command, argument).ShowDialog();
        }
Exemplo n.º 41
0
        private static GitRevision GetCurrentRevision(GitModule aModule, RevisionGrid RevisionGrid, List<GitRef> currentTags, List<GitRef> currentLocalBranches,
                                                      List<GitRef> currentRemoteBranches, List<GitRef> currentBranches,
                                                      GitRevision currentRevision)
        {
            if (currentRevision == null)
            {
                IList<GitRef> refs;

                if (RevisionGrid == null)
                {
                    string currentRevisionGuid = aModule.GetCurrentCheckout();
                    refs = aModule.GetRefs(true, true).Where(gitRef => gitRef.Guid == currentRevisionGuid).ToList();
                }
                else
                {
                    currentRevision = RevisionGrid.GetCurrentRevision();
                    refs = currentRevision.Refs;
                }

                foreach (GitRef gitRef in refs)
                {
                    if (gitRef.IsTag)
                        currentTags.Add(gitRef);
                    else if (gitRef.IsHead || gitRef.IsRemote)
                    {
                        currentBranches.Add(gitRef);
                        if (gitRef.IsRemote)
                            currentRemoteBranches.Add(gitRef);
                        else
                            currentLocalBranches.Add(gitRef);
                    }
                }
            }
            return currentRevision;
        }
Exemplo n.º 42
0
        internal static void RunScript(IWin32Window owner, GitModule aModule, ScriptInfo scriptInfo, RevisionGrid revisionGrid)
        {
            string command = scriptInfo.Command;
            string argument = scriptInfo.Arguments;

            command = OverrideCommandWhenNecessary(command);

            GitRevision selectedRevision = null;
            GitRevision currentRevision = null;

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

            foreach (string option in Options)
            {
                if (string.IsNullOrEmpty(argument) || !argument.Contains(option))
                    continue;
                if (!option.StartsWith("{s") || selectedRevision != null)
                {
                    currentRevision = GetCurrentRevision(aModule, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision, option);

                    if (currentLocalBranches.Count == 1)
                        currentRemote = aModule.GetSetting(string.Format("branch.{0}.remote", currentLocalBranches[0].Name));
                    else
                    {
                        currentRemote = aModule.GetCurrentRemote();
                        if (string.IsNullOrEmpty(currentRemote))
                            currentRemote = aModule.GetSetting(string.Format("branch.{0}.remote",
                                askToSpecify(currentLocalBranches, "Current Revision Branch")));
                    }
                }
                else
                {
                    selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags);
                }

                string remote;
                string url;
                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 == 0)
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        if (selectedRemotes.Count == 1)
                            remote = selectedRemotes[0];
                        else
                            remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                        argument = argument.Replace(option, remote);
                        break;
                    case "{sRemoteUrl}":
                        if (selectedRemotes.Count == 0)
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        if (selectedRemotes.Count == 1)
                            remote = selectedRemotes[0];
                        else
                            remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                        url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote));
                        argument = argument.Replace(option, url);
                        break;
                    case "{sRemotePathFromUrl}":
                        if (selectedRemotes.Count == 0)
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        if (selectedRemotes.Count == 1)
                            remote = selectedRemotes[0];
                        else
                            remote = askToSpecify(selectedRemotes, "Selected Revision Remote");
                        url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote));
                        argument = argument.Replace(option, GetRemotePath(url));
                        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;
                    case "{cDefaultRemote}":
                        if (string.IsNullOrEmpty(currentRemote))
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        argument = argument.Replace(option, currentRemote);
                        break;
                    case "{cDefaultRemoteUrl}":
                        if (string.IsNullOrEmpty(currentRemote))
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote));
                        argument = argument.Replace(option, url);
                        break;
                    case "{cDefaultRemotePathFromUrl}":
                        if (string.IsNullOrEmpty(currentRemote))
                        {
                            argument = argument.Replace(option, "");
                            break;
                        }
                        url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote));
                        argument = argument.Replace(option, GetRemotePath(url));
                        break;
                    case "{UserInput}":
                        using (SimplePrompt Prompt = new SimplePrompt())
                        {
                            Prompt.ShowDialog();
                            argument = argument.Replace(option, Prompt.UserInput);
                        }
                        break;
                }
            }

            if (scriptInfo.ShowProgress)
                FormProcess.ShowDialog(owner, command, argument, aModule.WorkingDir, null, true);
            else
                aModule.RunExternalCmdDetached(command, argument);
        }
Exemplo n.º 43
0
        public static void RunScript(string script, RevisionGrid RevisionGrid)
        {
            if (string.IsNullOrEmpty(script))
            {
                return;
            }

            ScriptInfo scriptInfo = ScriptManager.GetScript(script);
            string     command;
            string     argument;

            if (scriptInfo == null)
            {
                MessageBox.Show("Cannot find script: " + script, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                command  = scriptInfo.Command;
                argument = scriptInfo.Arguments;
            }


            if (string.IsNullOrEmpty(command))
            {
                return;
            }

            //Make sure we are able to run git, even if git is not in the path
            if (command.Equals("git", System.StringComparison.CurrentCultureIgnoreCase) ||
                command.Equals("{git}", System.StringComparison.CurrentCultureIgnoreCase))
            {
                command = Settings.GitCommand;
            }

            if (command.Equals("gitextensions", System.StringComparison.CurrentCultureIgnoreCase) ||
                command.Equals("{gitextensions}", System.StringComparison.CurrentCultureIgnoreCase) ||
                command.Equals("gitex", System.StringComparison.CurrentCultureIgnoreCase) ||
                command.Equals("{gitex}", System.StringComparison.CurrentCultureIgnoreCase))
            {
                command = Settings.GetGitExtensionsFullPath();
            }

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

            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 (!string.IsNullOrEmpty(argument) && argument.Contains(option))
                {
                    if (option.StartsWith("{s") && selectedRevision == null)
                    {
                        if (RevisionGrid == null)
                        {
                            MessageBox.Show(string.Format("Option {0} is only supported when started from revision grid.", option), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        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)
                    {
                        IList <GitHead> heads;

                        if (RevisionGrid == null)
                        {
                            heads = new List <GitHead>();
                            string currentRevisionGuid = Settings.Module.GetCurrentCheckout();
                            foreach (GitHead head in Settings.Module.GetHeads(true, true))
                            {
                                if (head.Guid == currentRevisionGuid)
                                {
                                    heads.Add(head);
                                }
                            }
                        }
                        else
                        {
                            currentRevision = RevisionGrid.GetCurrentRevision();
                            heads           = currentRevision.Heads;
                        }

                        foreach (GitHead head in 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;

                    case "{cDefaultRemote}":
                        if (currentBranches.Count == 1)
                        {
                            argument = argument.Replace(option, Settings.Module.GetSetting(string.Format("branch.{0}.remote", currentBranches[0].Name)));
                        }
                        else if (currentBranches.Count != 0)
                        {
                            argument = argument.Replace(option, Settings.Module.GetSetting(string.Format("branch.{0}.remote",
                                                                                                         askToSpecify(currentBranches, "Current Revision Branch"))));
                        }
                        else
                        {
                            argument = argument.Replace(option, "");
                        }
                        break;

                    case "{UserInput}":
                        SimplePrompt Prompt = new SimplePrompt();
                        Prompt.ShowDialog();
                        argument = argument.Replace(option, Prompt.UserInput);
                        break;

                    default:
                        break;
                    }
                }
            }

            new FormProcess(command, argument).ShowDialog();
        }
Exemplo n.º 44
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(MailTo.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(AppSettings.SmtpServer))
            {
                MessageBox.Show(this, _wrongSmtpSettingsText.Text);
                return;
            }

            string savePatchesToDir = OutputPath.Text;

            if (!SaveToDir.Checked)
            {
                savePatchesToDir = Path.Combine(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 = "";

            var revisions = RevisionGrid.GetSelectedRevisions();

            if (revisions.Count > 0)
            {
                if (revisions.Count == 1)
                {
                    var parents = revisions[0].ParentIds;
                    rev1   = parents?.Count > 0 ? parents[0].ToString() : "";
                    rev2   = revisions[0].Guid;
                    result = Module.FormatPatch(rev1, rev2, savePatchesToDir);
                }
                else if (revisions.Count == 2)
                {
                    var parents = revisions[0].ParentIds;
                    rev1   = parents?.Count > 0 ? parents[0].ToString() : "";
                    rev2   = revisions[1].Guid;
                    result = Module.FormatPatch(rev1, rev2, savePatchesToDir);
                }
                else
                {
                    int n = 0;
                    foreach (GitRevision revision in revisions)
                    {
                        n++;
                        var parents = revision.ParentIds;
                        rev1    = parents?.Count > 0 ? parents[0].ToString() : "";
                        rev2    = revision.Guid;
                        result += Module.FormatPatch(rev1, rev2, savePatchesToDir, n);
                    }
                }
            }
            else
            {
                MessageBox.Show(this, _revisionsNeededText.Text, _revisionsNeededCaption.Text);
                return;
            }

            if (!SaveToDir.Checked)
            {
                result += Environment.NewLine + Environment.NewLine;
                if (SendMail(savePatchesToDir))
                {
                    result += _sendMailResult.Text + " " + MailTo.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.º 45
0
        private static GitRevision CalculateSelectedRevision(RevisionGrid RevisionGrid, List<GitHead> selectedRemoteBranches,
                                                             List<string> selectedRemotes, List<GitHead> selectedLocalBranches,
                                                             List<GitHead> selectedBranches, List<GitHead> selectedTags)
        {
            GitRevision 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);
                }
            }
            return selectedRevision;
        }
Exemplo n.º 46
0
 private void FormDiffLoad(object sender, EventArgs e)
 {
     RevisionGrid.Load();
 }
Exemplo n.º 47
0
 public FormBisect(RevisionGrid revisionGrid)
     : this(revisionGrid.UICommands)
 {
     _revisionGrid = revisionGrid;
     UpdateButtonsState();
 }
Exemplo n.º 48
0
        private static GitRevision GetCurrentRevision(RevisionGrid RevisionGrid, List<GitHead> currentTags, List<GitHead> currentLocalBranches,
                                                      List<GitHead> currentRemoteBranches, List<GitHead> currentBranches,
                                                      GitRevision currentRevision, string option)
        {
            if (option.StartsWith("{c") && currentRevision == null)
            {
                IList<GitHead> heads;

                if (RevisionGrid == null)
                {
                    heads = new List<GitHead>();
                    string currentRevisionGuid = Settings.Module.GetCurrentCheckout();
                    foreach (GitHead head in Settings.Module.GetHeads(true, true))
                    {
                        if (head.Guid == currentRevisionGuid)
                            heads.Add(head);
                    }
                }
                else
                {
                    currentRevision = RevisionGrid.GetCurrentRevision();
                    heads = currentRevision.Heads;
                }

                foreach (GitHead head in 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);
                    }
                }
            }
            return currentRevision;
        }
Exemplo n.º 49
0
 public void Bind(RevisionGrid revisionGrid, RevisionFileTree revisionFileTree)
 {
     _revisionGrid     = revisionGrid;
     _revisionFileTree = revisionFileTree;
 }
Exemplo n.º 50
0
        public static void RunScript(string script, RevisionGrid RevisionGrid)
        {
            if (string.IsNullOrEmpty(script))
                return;

            ScriptInfo scriptInfo = ScriptManager.GetScript(script);
            string command;
            string argument;

            if (scriptInfo == null)
            {
                MessageBox.Show("Cannot find script: " + script, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                command = scriptInfo.Command;
                argument = scriptInfo.Arguments;
            }

            if (string.IsNullOrEmpty(command))
                return;

            //Make sure we are able to run git, even if git is not in the path
            if (command.Equals("git", System.StringComparison.CurrentCultureIgnoreCase) ||
                command.Equals("{git}", System.StringComparison.CurrentCultureIgnoreCase))
                command = Settings.GitCommand;

            if (command.Equals("gitextensions", System.StringComparison.CurrentCultureIgnoreCase) ||
                command.Equals("{gitextensions}", System.StringComparison.CurrentCultureIgnoreCase) ||
                command.Equals("gitex", System.StringComparison.CurrentCultureIgnoreCase) ||
                command.Equals("{gitex}", System.StringComparison.CurrentCultureIgnoreCase))
                command = Settings.GetGitExtensionsFullPath();

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

            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 (!string.IsNullOrEmpty(argument) && argument.Contains(option))
                {
                    if (option.StartsWith("{s") && selectedRevision == null)
                    {
                        if (RevisionGrid == null)
                        {
                            MessageBox.Show("Option " + option + " is only supported when started from revision grid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        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)
                    {
                        IList<GitHead> heads;

                        if (RevisionGrid == null)
                        {
                            heads = new List<GitHead>();
                            string currentRevisionGuid = GitCommandHelpers.GetCurrentCheckout();
                            foreach (GitHead head in GitCommandHelpers.GetHeads(true, true))
                            {
                                if (head.Guid == currentRevisionGuid)
                                    heads.Add(head);
                            }
                        }
                        else
                        {
                            currentRevision = RevisionGrid.GetCurrentRevision();
                            heads = currentRevision.Heads;
                        }

                        foreach (GitHead head in 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;
                        case "{cDefaultRemote}":
                            if (currentBranches.Count == 1)
                                argument = argument.Replace(option, GitCommandHelpers.GetSetting(string.Format("branch.{0}.remote", currentBranches[0].Name)));
                            else if (currentBranches.Count != 0)
                                argument = argument.Replace(option, GitCommandHelpers.GetSetting(string.Format("branch.{0}.remote",
                                                            askToSpecify(currentBranches, "Current Revision Branch"))));
                            else
                                argument = argument.Replace(option, "");
                            break;
                        case "{UserInput}":
                            SimplePrompt Prompt = new SimplePrompt();
                            Prompt.ShowDialog();
                            argument = argument.Replace(option, Prompt.UserInput);
                            break;
                        default:
                            break;
                    }
                }
            }

            new FormProcess(command, argument).ShowDialog();
        }