private void revisionGrid_SelectionChanged(object sender, EventArgs e) { var revisions = revisionGrid.GetSelectedRevisions(); if (1 != revisions.Count) { return; } SelectedRevision = revisions[0]; flowLayoutPanelParents.Visible = SelectedRevision.HasParent; if (!flowLayoutPanelParents.Visible) { return; } _parents = SelectedRevision.ParentGuids.ToDictionary(p => GitRevision.ToShortSha(p), p => p); linkLabelParent.Text = _parents.Keys.ElementAt(0); linkLabelParent2.Visible = _parents.Count > 1; if (linkLabelParent2.Visible) { linkLabelParent2.Text = _parents.Keys.ElementAt(1); } }
/// <summary> /// shows a message box if commitHash is invalid /// </summary> public void SetSelectedCommitHash(string commitHash) { string oldCommitHash = SelectedCommitHash; SelectedCommitHash = Module.RevParse(commitHash); if (SelectedCommitHash.IsNullOrEmpty() && !commitHash.IsNullOrWhiteSpace()) { SelectedCommitHash = oldCommitHash; MessageBox.Show("The given commit hash is not valid for this repository and was therefore discarded."); } var isArtificialCommitForEmptyRepo = SelectedCommitHash == "HEAD"; if (SelectedCommitHash.IsNullOrEmpty() || isArtificialCommitForEmptyRepo) { textBoxCommitHash.Text = ""; lbCommits.Text = ""; } else { textBoxCommitHash.Text = GitRevision.ToShortSha(SelectedCommitHash); Task.Factory.StartNew(() => Module.GetCommitCountString(Module.GetCurrentCheckout(), SelectedCommitHash)) .ContinueWith(t => lbCommits.Text = t.Result, TaskScheduler.FromCurrentSynchronizationContext()); } }
public void Render_should_render_commit_parents() { var author = "John Doe (Acme Inc) <*****@*****.**>"; var committer = author; var authorDate = DateTime.Parse("2017-06-17T16:38:40+03"); var commitDate = authorDate; var data = new CommitData("8ea78df688ec4719a9756c1199a515d1", Guid.NewGuid().ToString("N"), _parentHashes.AsReadOnly(), author, authorDate, committer, commitDate, ""); _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author); _dateFormatter.FormatDateAsRelativeLocal(authorDate).Returns("6 months ago (06/17/2017 23:38:40)"); var result = _renderer.Render(data, false); result.Should().Be($"Author: John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}Date: 6 months ago (06/17/2017 23:38:40){Environment.NewLine}Commit hash: 8ea78df688ec4719a9756c1199a515d1{Environment.NewLine}" + $"Parent(s): {GitRevision.ToShortSha(_parentHashes[0])} {GitRevision.ToShortSha(_parentHashes[1])} {GitRevision.ToShortSha(_parentHashes[2])}"); _labelFormatter.Received(1).FormatLabel(Strings.GetAuthorText(), Arg.Any <int>()); _labelFormatter.Received(1).FormatLabel(Strings.GetDateText(), Arg.Any <int>()); _labelFormatter.Received(1).FormatLabel(Strings.GetCommitHashText(), Arg.Any <int>()); _labelFormatter.DidNotReceive().FormatLabel(Strings.GetAuthorDateText(), Arg.Any <int>()); _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitterText(), Arg.Any <int>()); _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitDateText(), Arg.Any <int>()); }
public void Render_should_render_commit_children() { var author = "John Doe (Acme Inc) <*****@*****.**>"; var committer = author; var authorDate = DateTime.Parse("2017-06-17T16:38:40+03"); var commitDate = authorDate; var data = new CommitData( ObjectId.Parse("7fa3109989e0523aeacb178995a2a3aa6c302a2c"), ObjectId.Random(), new ReadOnlyCollection <string>(new List <string>()), author, authorDate, committer, commitDate, ""); data.ChildrenGuids = _childrenHashes; _linkFactory.CreateLink(author, Arg.Any <string>()).Returns(x => author); _dateFormatter.FormatDateAsRelativeLocal(authorDate).Returns("6 months ago (06/17/2017 23:38:40)"); var result = _renderer.Render(data, false); result.Should().Be($"Author: John Doe (Acme Inc) <*****@*****.**>{Environment.NewLine}Date: 6 months ago (06/17/2017 23:38:40){Environment.NewLine}Commit hash: 7fa3109989e0523aeacb178995a2a3aa6c302a2c{Environment.NewLine}" + $"Children: {GitRevision.ToShortSha(_childrenHashes[0])} " + $"{GitRevision.ToShortSha(_childrenHashes[1])} " + $"{GitRevision.ToShortSha(_childrenHashes[2])}"); _labelFormatter.Received(1).FormatLabel(Strings.GetAuthorText(), Arg.Any <int>()); _labelFormatter.Received(1).FormatLabel(Strings.GetDateText(), Arg.Any <int>()); _labelFormatter.Received(1).FormatLabel(Strings.GetCommitHashText(), Arg.Any <int>()); _labelFormatter.DidNotReceive().FormatLabel(Strings.GetAuthorDateText(), Arg.Any <int>()); _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitterText(), Arg.Any <int>()); _labelFormatter.DidNotReceive().FormatLabel(Strings.GetCommitDateText(), Arg.Any <int>()); }
/// <summary> /// shows a message box if commitHash is invalid /// </summary> public void SetSelectedCommitHash(string commitHash) { string oldCommitHash = SelectedCommitHash; SelectedCommitHash = Module.RevParse(commitHash); if (SelectedCommitHash.IsNullOrEmpty() && !commitHash.IsNullOrWhiteSpace()) { SelectedCommitHash = oldCommitHash; MessageBox.Show("The given commit hash is not valid for this repository and was therefore discarded."); } var isArtificialCommitForEmptyRepo = SelectedCommitHash == "HEAD"; if (SelectedCommitHash.IsNullOrEmpty() || isArtificialCommitForEmptyRepo) { textBoxCommitHash.Text = ""; lbCommits.Text = ""; } else { textBoxCommitHash.Text = GitRevision.ToShortSha(SelectedCommitHash); ThreadHelper.JoinableTaskFactory.RunAsync( async() => { await TaskScheduler.Default.SwitchTo(alwaysYield: true); var text = Module.GetCommitCountString(Module.GetCurrentCheckout(), SelectedCommitHash); await this.SwitchToMainThreadAsync(); lbCommits.Text = text; }); } }
public string CreateCommitLink(string guid, string linkText = null, bool preserveGuidInLinkText = false) { if (linkText == null) { if (GitRevision.UnstagedGuid == guid) { linkText = Strings.GetCurrentUnstagedChanges(); } else if (GitRevision.IndexGuid == guid) { linkText = Strings.GetCurrentIndex(); } else { if (preserveGuidInLinkText) { linkText = guid; } else { linkText = GitRevision.ToShortSha(guid); } } } return(AddLink(linkText, "gitext://gotocommit/" + guid)); }
private string RenderHashCollection(IEnumerable <string> hashes, bool showRevisionsAsLinks) { string commitsString; if (showRevisionsAsLinks) { commitsString = hashes.Select(g => _linkFactory.CreateCommitLink(g)).Join(" "); } else { commitsString = hashes.Select(guid => GitRevision.ToShortSha(guid)).Join(" "); } return(commitsString); }
public FormCommitDiff(GitUICommands aCommands, string revisionGuid) : this(aCommands) { // We cannot use the GitRevision from revision grid. When a filtered commit list // is shown (file history/normal filter) the parent guids are not the 'real' parents, // but the parents in the filtered list. GitRevision revision = Module.GetRevision(revisionGuid); if (revision != null) { DiffFiles.SetDiffs(revision); Text = "Diff - " + GitRevision.ToShortSha(revision.Guid) + " - " + revision.AuthorDate + " - " + revision.Author + " - " + Module.WorkingDir;; } }
public void Render_with_tabs_no_links() { var expectedHeader = "Author: <a href='mailto:[email protected]'>John Doe (Acme Inc) <[email protected]></a>"+ Environment.NewLine + "Author date: 3 days ago ("+ LocalizationHelpers.GetFullDateString(_data.AuthorDate) + ")" + Environment.NewLine + "Committer: <a href='mailto:[email protected]'>Jane Doe <[email protected]></a>"+ Environment.NewLine + "Commit date: 2 days ago ("+ LocalizationHelpers.GetFullDateString(_data.CommitDate) + ")" + Environment.NewLine + "Commit hash: "+ _data.Guid + Environment.NewLine + "Children: "+ GitRevision.ToShortSha(_data.ChildrenGuids[0]) + " " + GitRevision.ToShortSha(_data.ChildrenGuids[1]) + " " + GitRevision.ToShortSha(_data.ChildrenGuids[2]) + Environment.NewLine + "Parent(s): "+ GitRevision.ToShortSha(_data.ParentGuids[0]) + " " + GitRevision.ToShortSha(_data.ParentGuids[1]); var result = _rendererTabs.Render(_data, false); result.Should().Be(expectedHeader); }
public FormDiff(GitUICommands commands, bool firstParentIsValid, string baseCommitSha, string headCommitSha, string baseCommitDisplayStr, string headCommitDisplayStr) : base(commands) { _baseCommitDisplayStr = baseCommitDisplayStr; _headCommitDisplayStr = headCommitDisplayStr; _firstParentIsValid = firstParentIsValid; 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)); ckCompareToMergeBase.Text += $" ({GitRevision.ToShortSha(_mergeBase.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; }
private void revisionGrid_SelectionChanged(object sender, EventArgs e) { var revisions = revisionGrid.GetSelectedRevisions(); if (revisions.Count != 1) { return; } SelectedRevision = revisions[0]; flowLayoutPanelParents.Visible = SelectedRevision.HasParent; if (!flowLayoutPanelParents.Visible) { return; } var parents = SelectedRevision.ParentGuids; if (parents == null || parents.Count == 0) { return; } linkLabelParent.Tag = parents[0]; linkLabelParent.Text = GitRevision.ToShortSha(parents[0]); if (parents.Count > 1) { linkLabelParent2.Visible = true; linkLabelParent2.Tag = parents[1]; linkLabelParent2.Text = GitRevision.ToShortSha(parents[1]); } else { linkLabelParent2.Visible = false; } }
public void SetRevision(string revisionGuid, string fileToSelect) { // We cannot use the GitRevision from revision grid. When a filtered commit list // is shown (file history/normal filter) the parent guids are not the 'real' parents, // but the parents in the filtered list. GitRevision revision = Module.GetRevision(revisionGuid); if (revision != null) { DiffFiles.SetDiffs(new[] { revision }); if (fileToSelect != null) { var itemToSelect = DiffFiles.AllItems.FirstOrDefault(i => i.Name == fileToSelect); if (itemToSelect != null) { DiffFiles.SelectedItem = itemToSelect; } } commitInfo.Revision = revision; Text = "Diff - " + GitRevision.ToShortSha(revision.Guid) + " - " + revision.AuthorDate + " - " + revision.Author + " - " + Module.WorkingDir; } }
private DialogResult OkClick() { // Ok button set as the "AcceptButton" for the form // if the user hits [Enter] at any point, we need to trigger txtCustomBranchName Leave event Ok.Focus(); GitCheckoutBranchCmd cmd = new GitCheckoutBranchCmd(Branches.Text.Trim(), Remotebranch.Checked); if (Remotebranch.Checked) { if (rbCreateBranchWithCustomName.Checked) { cmd.NewBranchName = txtCustomBranchName.Text.Trim(); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create; if (cmd.NewBranchName.IsNullOrWhiteSpace()) { MessageBox.Show(_customBranchNameIsEmpty.Text, Text); DialogResult = DialogResult.None; return(DialogResult.None); } if (!Module.CheckBranchFormat(cmd.NewBranchName)) { MessageBox.Show(string.Format(_customBranchNameIsNotValid.Text, cmd.NewBranchName), Text); DialogResult = DialogResult.None; return(DialogResult.None); } } else if (rbResetBranch.Checked) { IGitRef localBranchRef = GetLocalBranchRef(_localBranchName); IGitRef remoteBranchRef = GetRemoteBranchRef(cmd.BranchName); if (localBranchRef != null && remoteBranchRef != null) { string mergeBaseGuid = Module.GetMergeBase(localBranchRef.Guid, remoteBranchRef.Guid); bool isResetFastForward = localBranchRef.Guid.Equals(mergeBaseGuid); if (!isResetFastForward) { string mergeBaseText = mergeBaseGuid.IsNullOrWhiteSpace() ? "merge base" : GitRevision.ToShortSha(mergeBaseGuid); string warningMessage = string.Format(_resetNonFastForwardBranch.Text, _localBranchName, mergeBaseText); if (MessageBox.Show(this, warningMessage, _resetCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { DialogResult = DialogResult.None; return(DialogResult.None); } } } cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset; cmd.NewBranchName = _localBranchName; } else { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.DontCreate; cmd.NewBranchName = null; } } LocalChangesAction changes = ChangesMode; if (changes != LocalChangesAction.Reset && chkSetLocalChangesActionAsDefault.Checked) { AppSettings.CheckoutBranchAction = changes; } if ((Visible || AppSettings.UseDefaultCheckoutBranchAction) && HasUncommittedChanges) { cmd.LocalChanges = changes; } else { cmd.LocalChanges = LocalChangesAction.DontChange; } IWin32Window owner = Visible ? this : Owner; bool stash = false; if (changes == LocalChangesAction.Stash) { if (_isDirtyDir == null && Visible) { _isDirtyDir = Module.IsDirtyDir(); } stash = _isDirtyDir == true; if (stash) { UICommands.StashSave(owner, AppSettings.IncludeUntrackedFilesInAutoStash); } } var originalHash = Module.GetCurrentCheckout(); ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout); if (UICommands.StartCommandLineProcessDialog(cmd, owner)) { if (stash) { bool?messageBoxResult = AppSettings.AutoPopStashAfterCheckoutBranch; if (messageBoxResult == null) { DialogResult res = cTaskDialog.MessageBox( this, _applyShashedItemsAgainCaption.Text, "", _applyShashedItemsAgain.Text, "", "", _dontShowAgain.Text, eTaskDialogButtons.YesNo, eSysIcons.Question, eSysIcons.Question); messageBoxResult = res == DialogResult.Yes; if (cTaskDialog.VerificationChecked) { AppSettings.AutoPopStashAfterCheckoutBranch = messageBoxResult; } } if (messageBoxResult ?? false) { UICommands.StashPop(this); } } var currentHash = Module.GetCurrentCheckout(); if (!string.Equals(originalHash, currentHash, StringComparison.OrdinalIgnoreCase)) { UICommands.UpdateSubmodules(this); } ScriptManager.RunEventScripts(this, ScriptEvent.AfterCheckout); return(DialogResult.OK); } return(DialogResult.None); }
private string RenderHashCollection(IEnumerable <string> hashes, bool showRevisionsAsLinks) { return(showRevisionsAsLinks ? hashes.Select(g => _linkFactory.CreateCommitLink(g)).Join(" ") : hashes.Select(g => GitRevision.ToShortSha(g)).Join(" ")); }