feature<Dashboard>: add context menu "Tracking" to change upstream of selected local branch

This commit is contained in:
leo 2020-11-04 11:54:09 +08:00
parent 5e6ef8abcb
commit 19bccbecf6
4 changed files with 66 additions and 6 deletions

View file

@ -153,6 +153,19 @@ namespace SourceGit.Git {
if (errs != null) App.RaiseError(errs);
}
/// <summary>
/// Change upstream
/// </summary>
/// <param name="repo"></param>
/// <param name="upstream"></param>
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();
}
/// <summary>
/// Delete branch.
/// </summary>

View file

@ -835,6 +835,18 @@ namespace SourceGit.Git {
return cachedBranches;
}
/// <summary>
/// Get all remote branches
/// </summary>
/// <returns>All remote branches</returns>
public List<Branch> RemoteBranches() {
var ret = new List<Branch>();
foreach (var b in cachedBranches) {
if (!b.IsLocal) ret.Add(b);
}
return ret;
}
/// <summary>
/// Get current branch
/// </summary>

View file

@ -61,7 +61,9 @@
<Path Grid.Column="2" Width="8" Height="8" Style="{DynamicResource Style.Icon}" Data="M 0 0 L 0 7 L 4 3.5 Z"/>
<Popup Name="Popup" Placement="Right" HorizontalOffset="-2" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
<Border Name="SubmenuBorder" SnapsToDevicePixels="True" Background="{DynamicResource Brush.BG1}" BorderBrush="{DynamicResource Brush.Border1}" BorderThickness="1">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
</ScrollViewer>
</Border>
</Popup>
</Grid>

View file

@ -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) => {