Skip to content

Commit 53f591b

Browse files
love-lingerdtentori
andcommitted
ux: add a warning icon when the tracking upstream of a local branch is gone (#1006)
Co-authored-by: Davide Tentori <dtentori@softeam.it>
1 parent 0e1dfba commit 53f591b

File tree

7 files changed

+32
-4
lines changed

7 files changed

+32
-4
lines changed

src/Commands/QueryBranches.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,22 @@ public QueryBranches(string repo)
2525
return branches;
2626

2727
var lines = rs.StdOut.Split('\n', StringSplitOptions.RemoveEmptyEntries);
28+
var remoteBranches = new HashSet<string>();
2829
foreach (var line in lines)
2930
{
3031
var b = ParseLine(line);
3132
if (b != null)
33+
{
3234
branches.Add(b);
35+
if (!b.IsLocal)
36+
remoteBranches.Add(b.FullName);
37+
}
38+
}
39+
40+
foreach (var b in branches)
41+
{
42+
if (b.IsLocal && !string.IsNullOrEmpty(b.Upstream))
43+
b.IsUpsteamGone = !remoteBranches.Contains(b.Upstream);
3344
}
3445

3546
return branches;
@@ -75,6 +86,7 @@ private Models.Branch ParseLine(string line)
7586
branch.Head = parts[1];
7687
branch.IsCurrent = parts[2] == "*";
7788
branch.Upstream = parts[3];
89+
branch.IsUpsteamGone = false;
7890

7991
if (branch.IsLocal && !string.IsNullOrEmpty(parts[4]) && !parts[4].Equals("=", StringComparison.Ordinal))
8092
branch.TrackStatus = new QueryTrackStatus(WorkingDirectory, branch.Name, branch.Upstream).Result();

src/Models/Branch.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class Branch
3434
public string Upstream { get; set; }
3535
public BranchTrackStatus TrackStatus { get; set; }
3636
public string Remote { get; set; }
37+
public bool IsUpsteamGone { get; set; }
3738

3839
public string FriendlyName => IsLocal ? Name : $"{Remote}/{Name}";
3940
}

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">Rename ${0}$...</x:String>
7373
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">Set Tracking Branch...</x:String>
7474
<x:String x:Key="Text.BranchCompare" xml:space="preserve">Branch Compare</x:String>
75+
<x:String x:Key="Text.BranchUpstreamInvalid" xml:space="preserve">Invalid upstream!</x:String>
7576
<x:String x:Key="Text.Bytes" xml:space="preserve">Bytes</x:String>
7677
<x:String x:Key="Text.Cancel" xml:space="preserve">CANCEL</x:String>
7778
<x:String x:Key="Text.ChangeCM.CheckoutThisRevision" xml:space="preserve">Reset to This Revision</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">重命名 ${0}$...</x:String>
7676
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">切换上游分支 ...</x:String>
7777
<x:String x:Key="Text.BranchCompare" xml:space="preserve">分支比较</x:String>
78+
<x:String x:Key="Text.BranchUpstreamInvalid" xml:space="preserve">跟踪的上游分支不存在或已删除!</x:String>
7879
<x:String x:Key="Text.Bytes" xml:space="preserve">字节</x:String>
7980
<x:String x:Key="Text.Cancel" xml:space="preserve">取 消</x:String>
8081
<x:String x:Key="Text.ChangeCM.CheckoutThisRevision" xml:space="preserve">重置文件到该版本</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
<x:String x:Key="Text.BranchCM.Rename" xml:space="preserve">重新命名 ${0}$...</x:String>
7676
<x:String x:Key="Text.BranchCM.Tracking" xml:space="preserve">切換上游分支...</x:String>
7777
<x:String x:Key="Text.BranchCompare" xml:space="preserve">分支比較</x:String>
78+
<x:String x:Key="Text.BranchUpstreamInvalid" xml:space="preserve">追蹤上游分支不存在或已刪除!</x:String>
7879
<x:String x:Key="Text.Bytes" xml:space="preserve">位元組</x:String>
7980
<x:String x:Key="Text.Cancel" xml:space="preserve">取 消</x:String>
8081
<x:String x:Key="Text.ChangeCM.CheckoutThisRevision" xml:space="preserve">重設檔案為此版本</x:String>

src/ViewModels/BranchTreeNode.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3-
43
using Avalonia;
5-
using Avalonia.Media;
6-
74
using CommunityToolkit.Mvvm.ComponentModel;
85

96
namespace SourceGit.ViewModels
@@ -45,6 +42,11 @@ public bool IsCurrent
4542
get => Backend is Models.Branch { IsCurrent: true };
4643
}
4744

45+
public bool ShowUpstreamGoneTip
46+
{
47+
get => Backend is Models.Branch { IsUpsteamGone: true };
48+
}
49+
4850
public string Tooltip
4951
{
5052
get => Backend is Models.Branch b ? b.FriendlyName : null;

src/Views/BranchTree.axaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@
6161
Classes="primary"
6262
Text="{Binding Name}"
6363
FontWeight="{Binding IsCurrent, Converter={x:Static c:BoolConverters.IsBoldToFontWeight}}"
64-
TextTrimming="CharacterEllipsis"/>
64+
TextTrimming="CharacterEllipsis"/>
65+
66+
<!-- Upstream invalid tip -->
67+
<Border Grid.Column="2"
68+
Width="12" Height="12"
69+
Margin="8,0"
70+
Background="Transparent"
71+
ToolTip.Tip="{DynamicResource Text.BranchUpstreamInvalid}"
72+
IsVisible="{Binding ShowUpstreamGoneTip}">
73+
<Path Data="{StaticResource Icons.Error}" Fill="DarkOrange"/>
74+
</Border>
6575

6676
<!-- Tracking status -->
6777
<v:BranchTreeNodeTrackStatusPresenter Grid.Column="2"

0 commit comments

Comments
 (0)