Skip to content

Commit 20927bf

Browse files
committed
feature: show submodule's URL in tooltip (#1307)
1 parent 20a2396 commit 20927bf

File tree

7 files changed

+89
-16
lines changed

7 files changed

+89
-16
lines changed

src/Commands/QuerySubmodules.cs

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public partial class QuerySubmodules : Command
1111
private static partial Regex REG_FORMAT_STATUS();
1212
[GeneratedRegex(@"^\s?[\w\?]{1,4}\s+(.+)$")]
1313
private static partial Regex REG_FORMAT_DIRTY();
14+
[GeneratedRegex(@"^submodule\.(\S*)\.path=(.*)$")]
15+
private static partial Regex REG_FORMAT_PATH();
16+
[GeneratedRegex(@"^submodule\.(\S*)\.url=(.*)$")]
17+
private static partial Regex REG_FORMAT_URL();
1418

1519
public QuerySubmodules(string repo)
1620
{
@@ -25,7 +29,8 @@ public QuerySubmodules(string repo)
2529
var rs = ReadToEnd();
2630

2731
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
28-
var needCheckLocalChanges = new Dictionary<string, Models.Submodule>();
32+
var map = new Dictionary<string, Models.Submodule>();
33+
var needCheckLocalChanges = false;
2934
foreach (var line in lines)
3035
{
3136
var match = REG_FORMAT_STATUS().Match(line);
@@ -49,22 +54,69 @@ public QuerySubmodules(string repo)
4954
break;
5055
default:
5156
module.Status = Models.SubmoduleStatus.Normal;
52-
needCheckLocalChanges.Add(path, module);
57+
needCheckLocalChanges = true;
5358
break;
5459
}
5560

61+
map.Add(path, module);
5662
submodules.Add(module);
5763
}
5864
}
5965

60-
if (needCheckLocalChanges.Count > 0)
66+
if (submodules.Count > 0)
67+
{
68+
Args = "config --file .gitmodules --list";
69+
rs = ReadToEnd();
70+
if (rs.IsSuccess)
71+
{
72+
var modules = new Dictionary<string, ModuleInfo>();
73+
lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
74+
foreach (var line in lines)
75+
{
76+
var match = REG_FORMAT_PATH().Match(line);
77+
if (match.Success)
78+
{
79+
var name = match.Groups[1].Value;
80+
var path = match.Groups[2].Value;
81+
if (modules.TryGetValue(name, out var m))
82+
m.Path = path;
83+
else
84+
modules.Add(name, new ModuleInfo() { Path = path });
85+
86+
continue;
87+
}
88+
89+
match = REG_FORMAT_URL().Match(line);
90+
if (match.Success)
91+
{
92+
var name = match.Groups[1].Value;
93+
var url = match.Groups[2].Value;
94+
if (modules.TryGetValue(name, out var m))
95+
m.URL = url;
96+
else
97+
modules.Add(name, new ModuleInfo() { URL = url });
98+
}
99+
}
100+
101+
foreach (var kv in modules)
102+
{
103+
if (map.TryGetValue(kv.Value.Path, out var m))
104+
m.URL = kv.Value.URL;
105+
}
106+
}
107+
}
108+
109+
if (needCheckLocalChanges)
61110
{
62111
var builder = new StringBuilder();
63-
foreach (var kv in needCheckLocalChanges)
112+
foreach (var kv in map)
64113
{
65-
builder.Append('"');
66-
builder.Append(kv.Key);
67-
builder.Append("\" ");
114+
if (kv.Value.Status == Models.SubmoduleStatus.Normal)
115+
{
116+
builder.Append('"');
117+
builder.Append(kv.Key);
118+
builder.Append("\" ");
119+
}
68120
}
69121

70122
Args = $"--no-optional-locks status -uno --porcelain -- {builder}";
@@ -79,13 +131,19 @@ public QuerySubmodules(string repo)
79131
if (match.Success)
80132
{
81133
var path = match.Groups[1].Value;
82-
if (needCheckLocalChanges.TryGetValue(path, out var m))
134+
if (map.TryGetValue(path, out var m))
83135
m.Status = Models.SubmoduleStatus.Modified;
84136
}
85137
}
86138
}
87139

88140
return submodules;
89141
}
142+
143+
private class ModuleInfo
144+
{
145+
public string Path { get; set; } = string.Empty;
146+
public string URL { get; set; } = string.Empty;
147+
}
90148
}
91149
}

src/Models/Submodule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Submodule
1313
{
1414
public string Path { get; set; } = string.Empty;
1515
public string SHA { get; set; } = string.Empty;
16+
public string URL { get; set; } = string.Empty;
1617
public SubmoduleStatus Status { get; set; } = SubmoduleStatus.Normal;
1718
public bool IsDirty => Status > SubmoduleStatus.NotInited;
1819
}

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@
709709
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">not initialized</x:String>
710710
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">revision changed</x:String>
711711
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">unmerged</x:String>
712+
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">URL</x:String>
712713
<x:String x:Key="Text.Sure" xml:space="preserve">OK</x:String>
713714
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">Copy Tag Name</x:String>
714715
<x:String x:Key="Text.TagCM.CopyMessage" xml:space="preserve">Copy Tag Message</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@
713713
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">未初始化</x:String>
714714
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">SHA变更</x:String>
715715
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">未解决冲突</x:String>
716+
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">仓库</x:String>
716717
<x:String x:Key="Text.Sure" xml:space="preserve">确 定</x:String>
717718
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">复制标签名</x:String>
718719
<x:String x:Key="Text.TagCM.CopyMessage" 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
@@ -713,6 +713,7 @@
713713
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">未初始化</x:String>
714714
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">SHA 變更</x:String>
715715
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">未解決的衝突</x:String>
716+
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">存放庫</x:String>
716717
<x:String x:Key="Text.Sure" xml:space="preserve">確 定</x:String>
717718
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">複製標籤名稱</x:String>
718719
<x:String x:Key="Text.TagCM.CopyMessage" xml:space="preserve">複製標籤訊息</x:String>

src/Views/Repository.axaml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,30 @@
356356
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Text="{Binding Path}"/>
357357
</StackPanel>
358358

359-
<Grid RowDefinitions="24,24" ColumnDefinitions="Auto,Auto" Margin="0,8,0,0">
359+
<Grid RowDefinitions="24,24,24" ColumnDefinitions="Auto,Auto" Margin="0,8,0,0">
360360
<TextBlock Grid.Row="0" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.CommitDetail.Info.SHA}" VerticalAlignment="Center"/>
361-
<TextBlock Grid.Row="0" Grid.Column="1" Margin="8,0,0,0" Text="{Binding SHA}" VerticalAlignment="Center"/>
362-
363-
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.Submodule.Status}" VerticalAlignment="Center"/>
364-
<Path Grid.Row="1" Grid.Column="1"
361+
<TextBlock Grid.Row="0" Grid.Column="1"
362+
Margin="8,0,0,0"
363+
Text="{Binding SHA}"
364+
Foreground="DarkOrange"
365+
VerticalAlignment="Center"/>
366+
367+
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.Submodule.URL}" VerticalAlignment="Center"/>
368+
<TextBlock Grid.Row="1" Grid.Column="1"
369+
Margin="8,0,0,0"
370+
Text="{Binding URL}"
371+
Foreground="{DynamicResource Brush.Link}"
372+
VerticalAlignment="Center"/>
373+
374+
<TextBlock Grid.Row="2" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.Submodule.Status}" VerticalAlignment="Center"/>
375+
<Path Grid.Row="2" Grid.Column="1"
365376
Margin="8,0,0,0"
366377
HorizontalAlignment="Left" VerticalAlignment="Center"
367378
Width="12" Height="12"
368379
Data="{StaticResource Icons.Check}"
369380
Fill="Green"
370381
IsVisible="{Binding Status, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:SubmoduleStatus.Normal}}"/>
371-
<Border Grid.Row="1" Grid.Column="1"
382+
<Border Grid.Row="2" Grid.Column="1"
372383
Height="16"
373384
Margin="8,0,0,0" Padding="4,0"
374385
HorizontalAlignment="Left" VerticalAlignment="Center"
@@ -393,7 +404,7 @@
393404
Foreground="White"
394405
IsVisible="{Binding Status, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:SubmoduleStatus.Unmerged}}"/>
395406
</Grid>
396-
</Border>
407+
</Border>
397408
</Grid>
398409
</StackPanel>
399410
</ToolTip.Tip>

src/Views/Repository.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private void OnSubmoduleContextRequested(object sender, ContextRequestedEventArg
192192

193193
private void OnDoubleTappedSubmodule(object sender, TappedEventArgs e)
194194
{
195-
if (sender is ListBox { SelectedItem: Models.Submodule submodule } &&
195+
if (sender is ListBox { SelectedItem: Models.Submodule submodule } &&
196196
submodule.Status != Models.SubmoduleStatus.NotInited &&
197197
DataContext is ViewModels.Repository repo)
198198
{

0 commit comments

Comments
 (0)