Skip to content

Commit d46979a

Browse files
committed
feature: add a checkbox to also delete the tracking remote branch (#99)
1 parent eced2e0 commit d46979a

File tree

7 files changed

+42
-5
lines changed

7 files changed

+42
-5
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">Delete Branch</x:String>
122122
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">Branch :</x:String>
123123
<x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">You are about to delete a remote branch!!!</x:String>
124+
<x:String x:Key="Text.DeleteBranch.WithTrackingRemote" xml:space="preserve">Also delete remote branch${0}$</x:String>
124125
<x:String x:Key="Text.DeleteRemote" xml:space="preserve">Delete Remote</x:String>
125126
<x:String x:Key="Text.DeleteRemote.Remote" xml:space="preserve">Remote :</x:String>
126127
<x:String x:Key="Text.DeleteRepositoryNode.Target" xml:space="preserve">Target :</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
<x:String x:Key="Text.DeleteBranch" xml:space="preserve">删除分支确认</x:String>
122122
<x:String x:Key="Text.DeleteBranch.Branch" xml:space="preserve">分支名 :</x:String>
123123
<x:String x:Key="Text.DeleteBranch.IsRemoteTip" xml:space="preserve">您正在删除远程上的分支,请务必小心!!!</x:String>
124+
<x:String x:Key="Text.DeleteBranch.WithTrackingRemote" xml:space="preserve">同时删除远程分支${0}$</x:String>
124125
<x:String x:Key="Text.DeleteRemote" xml:space="preserve">删除远程确认</x:String>
125126
<x:String x:Key="Text.DeleteRemote.Remote" xml:space="preserve">远程名 :</x:String>
126127
<x:String x:Key="Text.DeleteRepositoryNode.Target" xml:space="preserve">目标 :</x:String>

src/ViewModels/DeleteBranch.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,36 @@ public Models.Branch Target
1010
private set;
1111
}
1212

13+
public Models.Branch TrackingRemoteBranch
14+
{
15+
get;
16+
private set;
17+
}
18+
19+
public object DeleteTrackingRemoteTip
20+
{
21+
get;
22+
private set;
23+
}
24+
25+
public bool AlsoDeleteTrackingRemote
26+
{
27+
get => _alsoDeleteTrackingRemote;
28+
set => SetProperty(ref _alsoDeleteTrackingRemote, value);
29+
}
30+
1331
public DeleteBranch(Repository repo, Models.Branch branch)
1432
{
1533
_repo = repo;
1634
Target = branch;
35+
36+
if (branch.IsLocal && !string.IsNullOrEmpty(branch.Upstream))
37+
{
38+
var upstream = branch.Upstream.Substring(13);
39+
TrackingRemoteBranch = repo.Branches.Find(x => !x.IsLocal && $"{x.Remote}/{x.Name}" == upstream);
40+
DeleteTrackingRemoteTip = new Views.NameHighlightedTextBlock("DeleteBranch.WithTrackingRemote", upstream);
41+
}
42+
1743
View = new Views.DeleteBranch() { DataContext = this };
1844
}
1945

@@ -27,6 +53,9 @@ public override Task<bool> Sure()
2753
if (Target.IsLocal)
2854
{
2955
Commands.Branch.Delete(_repo.FullPath, Target.Name);
56+
57+
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
58+
new Commands.Push(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name).Exec();
3059
}
3160
else
3261
{
@@ -39,5 +68,6 @@ public override Task<bool> Sure()
3968
}
4069

4170
private readonly Repository _repo = null;
71+
private bool _alsoDeleteTrackingRemote = false;
4272
}
4373
}

src/ViewModels/Histories.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ private void FillCurrentBranchMenu(ContextMenu menu, Models.Branch current)
383383
fastForward.Header = new Views.NameHighlightedTextBlock("BranchCM.FastForward", upstream);
384384
fastForward.Icon = App.CreateMenuIcon("Icons.FastForward");
385385
fastForward.IsEnabled = !string.IsNullOrEmpty(current.UpstreamTrackStatus) && current.UpstreamTrackStatus.IndexOf('↑') < 0;
386-
;
387386
fastForward.Click += (o, e) =>
388387
{
389388
if (PopupHost.CanCreatePopup())

src/Views/DeleteBranch.axaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:m="using:SourceGit.Models"
56
xmlns:vm="using:SourceGit.ViewModels"
7+
xmlns:v="using:SourceGit.Views"
68
xmlns:c="using:SourceGit.Converters"
79
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
810
x:Class="SourceGit.Views.DeleteBranch"
@@ -12,20 +14,24 @@
1214
Classes="bold"
1315
Text="{DynamicResource Text.DeleteBranch}"/>
1416

15-
<Grid Margin="0,16,8,0" RowDefinitions="32,Auto" ColumnDefinitions="150,*">
17+
<Grid Margin="0,16,8,0" RowDefinitions="32,Auto" ColumnDefinitions="120,*">
1618
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Text="{DynamicResource Text.DeleteBranch.Branch}"/>
1719
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
1820
<Path Width="14" Height="14" Margin="8,0" Data="{StaticResource Icons.Branch}"/>
1921
<TextBlock Text="{Binding Target, Converter={x:Static c:BranchConverters.ToName}}"/>
2022
</StackPanel>
2123

2224
<Border Grid.Row="1" Grid.Column="1" Height="32" IsVisible="{Binding !Target.IsLocal}">
23-
<TextBlock Margin="8,0"
25+
<TextBlock Margin="6,0,0,0"
2426
Text="{DynamicResource Text.DeleteBranch.IsRemoteTip}"
2527
Foreground="{DynamicResource Brush.FG2}"
2628
FontStyle="Italic"
2729
VerticalAlignment="Center"/>
2830
</Border>
31+
32+
<Border Grid.Row="1" Grid.Column="1" Height="32" IsVisible="{Binding TrackingRemoteBranch, Converter={x:Static ObjectConverters.IsNotNull}}">
33+
<CheckBox Margin="6,0,0,0" Content="{Binding DeleteTrackingRemoteTip}" IsChecked="{Binding AlsoDeleteTrackingRemote, Mode=TwoWay}"/>
34+
</Border>
2935
</Grid>
3036
</StackPanel>
3137
</UserControl>

src/Views/Launcher.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected override void OnKeyDown(KeyEventArgs e)
113113
e.Handled = true;
114114
return;
115115
}
116-
else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) ||
116+
else if ((OperatingSystem.IsMacOS() && e.KeyModifiers.HasFlag(KeyModifiers.Alt) && e.Key == Key.Right) ||
117117
(!OperatingSystem.IsMacOS() && e.Key == Key.Tab))
118118
{
119119
vm.GotoNextTab();

src/Views/NameHighlightedTextBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override Size MeasureOverride(Size availableSize)
7171
FontSize,
7272
Foreground);
7373

74-
return new Size(formatted.Width - 16, formatted.Height);
74+
return new Size(formatted.Width, formatted.Height);
7575
}
7676

7777
public override void Render(DrawingContext context)

0 commit comments

Comments
 (0)