diff --git a/src/Git/Branch.cs b/src/Git/Branch.cs index 5410c9b6..36e16af3 100644 --- a/src/Git/Branch.cs +++ b/src/Git/Branch.cs @@ -153,6 +153,19 @@ namespace SourceGit.Git { if (errs != null) App.RaiseError(errs); } + /// + /// Change upstream + /// + /// + /// + public void SetUpstream(Repository repo, string upstream) { + var errs = repo.RunCommand($"branch {Name} -u {upstream}", null); + if (errs != null) App.RaiseError(errs); + + repo.Branches(true); + repo.OnBranchChanged?.Invoke(); + } + /// /// Delete branch. /// diff --git a/src/Git/Repository.cs b/src/Git/Repository.cs index 57b2ae13..8b3ba99f 100644 --- a/src/Git/Repository.cs +++ b/src/Git/Repository.cs @@ -835,6 +835,18 @@ namespace SourceGit.Git { return cachedBranches; } + /// + /// Get all remote branches + /// + /// All remote branches + public List RemoteBranches() { + var ret = new List(); + foreach (var b in cachedBranches) { + if (!b.IsLocal) ret.Add(b); + } + return ret; + } + /// /// Get current branch /// diff --git a/src/Resources/Styles/ContextMenu.xaml b/src/Resources/Styles/ContextMenu.xaml index c82d6fee..d0cf2b2c 100644 --- a/src/Resources/Styles/ContextMenu.xaml +++ b/src/Resources/Styles/ContextMenu.xaml @@ -61,7 +61,9 @@ - + + + diff --git a/src/UI/Dashboard.xaml.cs b/src/UI/Dashboard.xaml.cs index 6fbe4b08..c7bb21b1 100644 --- a/src/UI/Dashboard.xaml.cs +++ b/src/UI/Dashboard.xaml.cs @@ -641,14 +641,14 @@ namespace SourceGit.UI { if (branch.Kind != Git.Branch.Type.Normal) { menu.Items.Add(new Separator()); - var icon = new System.Windows.Shapes.Path(); - icon.Style = FindResource("Style.Icon") as Style; - icon.Data = FindResource("Icon.Flow") as Geometry; - icon.Width = 10; + var flowIcon = new System.Windows.Shapes.Path(); + flowIcon.Style = FindResource("Style.Icon") as Style; + flowIcon.Data = FindResource("Icon.Flow") as Geometry; + flowIcon.Width = 10; var finish = new MenuItem(); finish.Header = $"Git Flow - Finish '{branch.Name}'"; - finish.Icon = icon; + finish.Icon = flowIcon; finish.Click += (o, e) => { GitFlowFinishBranch.Show(repo, branch); e.Handled = true; @@ -693,6 +693,39 @@ namespace SourceGit.UI { menu.Items.Add(createTag); menu.Items.Add(new Separator()); + var remoteBranches = repo.RemoteBranches(); + if (remoteBranches.Count > 0) { + var trackingIcon = new System.Windows.Shapes.Path(); + trackingIcon.Style = FindResource("Style.Icon") as Style; + trackingIcon.Data = FindResource("Icon.Branch") as Geometry; + trackingIcon.VerticalAlignment = VerticalAlignment.Bottom; + trackingIcon.Width = 10; + + var currentTrackingIcon = new System.Windows.Shapes.Path(); + currentTrackingIcon.Style = FindResource("Style.Icon") as Style; + currentTrackingIcon.Data = FindResource("Icon.Check") as Geometry; + currentTrackingIcon.VerticalAlignment = VerticalAlignment.Center; + currentTrackingIcon.Width = 10; + + var tracking = new MenuItem(); + tracking.Header = "Tracking ..."; + tracking.Icon = trackingIcon; + + foreach (var b in remoteBranches) { + var target = new MenuItem(); + target.Header = b.Name; + if (branch.Upstream == b.FullName) target.Icon = currentTrackingIcon; + target.Click += (o, e) => { + branch.SetUpstream(repo, b.Name); + e.Handled = true; + }; + tracking.Items.Add(target); + } + + menu.Items.Add(tracking); + menu.Items.Add(new Separator()); + } + var copy = new MenuItem(); copy.Header = "Copy Branch Name"; copy.Click += (o, e) => {