Skip to content

Commit

Permalink
Select remote branch on [Ctrl+]Alt+Click in ROT
Browse files Browse the repository at this point in the history
Implements the most important part of gitextensions#9194
  • Loading branch information
mstv committed May 1, 2022
1 parent 0cec653 commit 2f71e02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions GitUI/BranchTreePanel/BaseBranchNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using GitCommands;
using GitExtUtils.GitUI.Theming;
using GitUI.Properties;

Expand Down Expand Up @@ -31,6 +32,8 @@ protected BaseBranchNode(Tree tree, string fullPath, bool visible)

protected string? AheadBehind { get; set; }

protected string? RelatedBranch { get; set; }

/// <summary>
/// Short name of the branch/branch path. <example>"issue1344"</example>.
/// </summary>
Expand Down Expand Up @@ -64,9 +67,10 @@ public override bool Equals(object obj)
&& (ReferenceEquals(other, this) || string.Equals(FullPath, other.FullPath));
}

public void UpdateAheadBehind(string aheadBehindData)
public void UpdateAheadBehind(string aheadBehindData, string relatedBranch)
{
AheadBehind = aheadBehindData;
RelatedBranch = relatedBranch;
}

public bool Rebase()
Expand Down Expand Up @@ -114,7 +118,9 @@ protected void SelectRevision()
{
TreeViewNode.TreeView?.BeginInvoke(new Action(() =>
{
UICommands.BrowseGoToRef(FullPath, showNoRevisionMsg: true, toggleSelection: RepoObjectsTree.ModifierKeys.HasFlag(Keys.Control));
string branch = RelatedBranch is null || !RepoObjectsTree.ModifierKeys.HasFlag(Keys.Alt)
? FullPath : RelatedBranch.Substring(startIndex: GitRefName.RefsRemotesPrefix.Length);
UICommands.BrowseGoToRef(branch, showNoRevisionMsg: true, toggleSelection: RepoObjectsTree.ModifierKeys.HasFlag(Keys.Control));
TreeViewNode.TreeView?.Focus();
}));
}
Expand Down
7 changes: 5 additions & 2 deletions GitUI/BranchTreePanel/BranchTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ private Nodes FillBranchTree(IReadOnlyList<IGitRef> branches, CancellationToken
bool isVisible = !IsFiltering.Value || _refsSource.Contains(branch.ObjectId);
LocalBranchNode localBranchNode = new(this, branch.ObjectId, branch.Name, branch.Name == currentBranch, isVisible);

if (aheadBehindData is not null && aheadBehindData.ContainsKey(localBranchNode.FullPath))
if (aheadBehindData is not null)
{
localBranchNode.UpdateAheadBehind(aheadBehindData[localBranchNode.FullPath].ToDisplay());
if (aheadBehindData.TryGetValue(localBranchNode.FullPath, out AheadBehindData aheadBehind))
{
localBranchNode.UpdateAheadBehind(aheadBehind.ToDisplay(), aheadBehind.RemoteRef);
}
}

var parent = localBranchNode.CreateRootNode(pathToNode, (tree, parentPath) => new BranchPathNode(tree, parentPath));
Expand Down

0 comments on commit 2f71e02

Please sign in to comment.