Skip to content

Commit

Permalink
Select remote branch on [Ctrl+]Alt+Click in ROT (#10083)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerhard Olsson <gerhardol@users.noreply.github.com>
(cherry picked from commit cabe0d2)
  • Loading branch information
gerhardol committed Jul 28, 2022
1 parent a4c78c9 commit aedb2a9
Show file tree
Hide file tree
Showing 2 changed files with 10 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
4 changes: 2 additions & 2 deletions GitUI/BranchTreePanel/BranchTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ 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 && aheadBehindData.TryGetValue(localBranchNode.FullPath, out AheadBehindData aheadBehind))
{
localBranchNode.UpdateAheadBehind(aheadBehindData[localBranchNode.FullPath].ToDisplay());
localBranchNode.UpdateAheadBehind(aheadBehind.ToDisplay(), aheadBehind.RemoteRef);
}

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

0 comments on commit aedb2a9

Please sign in to comment.