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 most important part of gitextensions#9194
  • Loading branch information
mstv committed Oct 6, 2021
1 parent 832ccc2 commit 0617935
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 8 additions & 2 deletions GitUI/BranchTreePanel/RepoObjectsTree.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 @@ -33,6 +34,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 @@ -68,9 +71,10 @@ public override bool Equals(object obj)
&& Visible == other.Visible;
}

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

public bool Rebase()
Expand Down Expand Up @@ -118,7 +122,9 @@ protected void SelectRevision()
{
TreeViewNode.TreeView?.BeginInvoke(new Action(() =>
{
UICommands.BrowseGoToRef(FullPath, showNoRevisionMsg: true, toggleSelection: ModifierKeys.HasFlag(Keys.Control));
string branch = RelatedBranch is null || !ModifierKeys.HasFlag(Keys.Alt)
? FullPath : RelatedBranch.Substring(GitRefName.RefsRemotesPrefix.Length);
UICommands.BrowseGoToRef(branch, showNoRevisionMsg: true, toggleSelection: ModifierKeys.HasFlag(Keys.Control));
TreeViewNode.TreeView?.Focus();
}));
}
Expand Down
7 changes: 5 additions & 2 deletions GitUI/BranchTreePanel/RepoObjectsTree.BranchTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,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 0617935

Please sign in to comment.