mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-20 03:34:59 +00:00
feature: show submodule's URL in tooltip (#1307)
This commit is contained in:
parent
20a239621b
commit
61bb0f7dc7
7 changed files with 81 additions and 15 deletions
|
@ -11,6 +11,8 @@ namespace SourceGit.Commands
|
|||
private static partial Regex REG_FORMAT_STATUS();
|
||||
[GeneratedRegex(@"^\s?[\w\?]{1,4}\s+(.+)$")]
|
||||
private static partial Regex REG_FORMAT_DIRTY();
|
||||
[GeneratedRegex(@"^submodule\.(\S*)\.(\w+)=(.*)$")]
|
||||
private static partial Regex REG_FORMAT_MODULE_INFO();
|
||||
|
||||
public QuerySubmodules(string repo)
|
||||
{
|
||||
|
@ -25,7 +27,8 @@ namespace SourceGit.Commands
|
|||
var rs = ReadToEnd();
|
||||
|
||||
var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
|
||||
var needCheckLocalChanges = new Dictionary<string, Models.Submodule>();
|
||||
var map = new Dictionary<string, Models.Submodule>();
|
||||
var needCheckLocalChanges = false;
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var match = REG_FORMAT_STATUS().Match(line);
|
||||
|
@ -49,22 +52,64 @@ namespace SourceGit.Commands
|
|||
break;
|
||||
default:
|
||||
module.Status = Models.SubmoduleStatus.Normal;
|
||||
needCheckLocalChanges.Add(path, module);
|
||||
needCheckLocalChanges = true;
|
||||
break;
|
||||
}
|
||||
|
||||
map.Add(path, module);
|
||||
submodules.Add(module);
|
||||
}
|
||||
}
|
||||
|
||||
if (needCheckLocalChanges.Count > 0)
|
||||
if (submodules.Count > 0)
|
||||
{
|
||||
Args = "config --file .gitmodules --list";
|
||||
rs = ReadToEnd();
|
||||
if (rs.IsSuccess)
|
||||
{
|
||||
var modules = new Dictionary<string, ModuleInfo>();
|
||||
lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var match = REG_FORMAT_MODULE_INFO().Match(line);
|
||||
if (match.Success)
|
||||
{
|
||||
var name = match.Groups[1].Value;
|
||||
var key = match.Groups[2].Value;
|
||||
var val = match.Groups[3].Value;
|
||||
|
||||
if (!modules.TryGetValue(name, out var m))
|
||||
{
|
||||
m = new ModuleInfo();
|
||||
modules.Add(name, m);
|
||||
}
|
||||
|
||||
if (key.Equals("path", StringComparison.Ordinal))
|
||||
m.Path = val;
|
||||
else if (key.Equals("url", StringComparison.Ordinal))
|
||||
m.URL = val;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var kv in modules)
|
||||
{
|
||||
if (map.TryGetValue(kv.Value.Path, out var m))
|
||||
m.URL = kv.Value.URL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (needCheckLocalChanges)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
foreach (var kv in needCheckLocalChanges)
|
||||
foreach (var kv in map)
|
||||
{
|
||||
builder.Append('"');
|
||||
builder.Append(kv.Key);
|
||||
builder.Append("\" ");
|
||||
if (kv.Value.Status == Models.SubmoduleStatus.Normal)
|
||||
{
|
||||
builder.Append('"');
|
||||
builder.Append(kv.Key);
|
||||
builder.Append("\" ");
|
||||
}
|
||||
}
|
||||
|
||||
Args = $"--no-optional-locks status -uno --porcelain -- {builder}";
|
||||
|
@ -79,7 +124,7 @@ namespace SourceGit.Commands
|
|||
if (match.Success)
|
||||
{
|
||||
var path = match.Groups[1].Value;
|
||||
if (needCheckLocalChanges.TryGetValue(path, out var m))
|
||||
if (map.TryGetValue(path, out var m))
|
||||
m.Status = Models.SubmoduleStatus.Modified;
|
||||
}
|
||||
}
|
||||
|
@ -87,5 +132,11 @@ namespace SourceGit.Commands
|
|||
|
||||
return submodules;
|
||||
}
|
||||
|
||||
private class ModuleInfo
|
||||
{
|
||||
public string Path { get; set; } = string.Empty;
|
||||
public string URL { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
{
|
||||
public string Path { get; set; } = string.Empty;
|
||||
public string SHA { get; set; } = string.Empty;
|
||||
public string URL { get; set; } = string.Empty;
|
||||
public SubmoduleStatus Status { get; set; } = SubmoduleStatus.Normal;
|
||||
public bool IsDirty => Status > SubmoduleStatus.NotInited;
|
||||
}
|
||||
|
|
|
@ -709,6 +709,7 @@
|
|||
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">not initialized</x:String>
|
||||
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">revision changed</x:String>
|
||||
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">unmerged</x:String>
|
||||
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">URL</x:String>
|
||||
<x:String x:Key="Text.Sure" xml:space="preserve">OK</x:String>
|
||||
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">Copy Tag Name</x:String>
|
||||
<x:String x:Key="Text.TagCM.CopyMessage" xml:space="preserve">Copy Tag Message</x:String>
|
||||
|
|
|
@ -713,6 +713,7 @@
|
|||
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">未初始化</x:String>
|
||||
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">SHA变更</x:String>
|
||||
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">未解决冲突</x:String>
|
||||
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">仓库</x:String>
|
||||
<x:String x:Key="Text.Sure" xml:space="preserve">确 定</x:String>
|
||||
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">复制标签名</x:String>
|
||||
<x:String x:Key="Text.TagCM.CopyMessage" xml:space="preserve">复制标签信息</x:String>
|
||||
|
|
|
@ -713,6 +713,7 @@
|
|||
<x:String x:Key="Text.Submodule.Status.NotInited" xml:space="preserve">未初始化</x:String>
|
||||
<x:String x:Key="Text.Submodule.Status.RevisionChanged" xml:space="preserve">SHA 變更</x:String>
|
||||
<x:String x:Key="Text.Submodule.Status.Unmerged" xml:space="preserve">未解決的衝突</x:String>
|
||||
<x:String x:Key="Text.Submodule.URL" xml:space="preserve">存放庫</x:String>
|
||||
<x:String x:Key="Text.Sure" xml:space="preserve">確 定</x:String>
|
||||
<x:String x:Key="Text.TagCM.Copy" xml:space="preserve">複製標籤名稱</x:String>
|
||||
<x:String x:Key="Text.TagCM.CopyMessage" xml:space="preserve">複製標籤訊息</x:String>
|
||||
|
|
|
@ -356,19 +356,30 @@
|
|||
<TextBlock FontWeight="Bold" Margin="4,0,0,0" Text="{Binding Path}"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid RowDefinitions="24,24" ColumnDefinitions="Auto,Auto" Margin="0,8,0,0">
|
||||
<Grid RowDefinitions="24,24,24" ColumnDefinitions="Auto,Auto" Margin="0,8,0,0">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.CommitDetail.Info.SHA}" VerticalAlignment="Center"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" Margin="8,0,0,0" Text="{Binding SHA}" VerticalAlignment="Center"/>
|
||||
<TextBlock Grid.Row="0" Grid.Column="1"
|
||||
Margin="8,0,0,0"
|
||||
Text="{Binding SHA}"
|
||||
Foreground="DarkOrange"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.Submodule.Status}" VerticalAlignment="Center"/>
|
||||
<Path Grid.Row="1" Grid.Column="1"
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.Submodule.URL}" VerticalAlignment="Center"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="1"
|
||||
Margin="8,0,0,0"
|
||||
Text="{Binding URL}"
|
||||
Foreground="{DynamicResource Brush.Link}"
|
||||
VerticalAlignment="Center"/>
|
||||
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" Classes="info_label" Text="{DynamicResource Text.Submodule.Status}" VerticalAlignment="Center"/>
|
||||
<Path Grid.Row="2" Grid.Column="1"
|
||||
Margin="8,0,0,0"
|
||||
HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||
Width="12" Height="12"
|
||||
Data="{StaticResource Icons.Check}"
|
||||
Fill="Green"
|
||||
IsVisible="{Binding Status, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:SubmoduleStatus.Normal}}"/>
|
||||
<Border Grid.Row="1" Grid.Column="1"
|
||||
<Border Grid.Row="2" Grid.Column="1"
|
||||
Height="16"
|
||||
Margin="8,0,0,0" Padding="4,0"
|
||||
HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||
|
@ -393,7 +404,7 @@
|
|||
Foreground="White"
|
||||
IsVisible="{Binding Status, Converter={x:Static ObjectConverters.Equal}, ConverterParameter={x:Static m:SubmoduleStatus.Unmerged}}"/>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Border>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</ToolTip.Tip>
|
||||
|
|
|
@ -192,7 +192,7 @@ namespace SourceGit.Views
|
|||
|
||||
private void OnDoubleTappedSubmodule(object sender, TappedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox { SelectedItem: Models.Submodule submodule } &&
|
||||
if (sender is ListBox { SelectedItem: Models.Submodule submodule } &&
|
||||
submodule.Status != Models.SubmoduleStatus.NotInited &&
|
||||
DataContext is ViewModels.Repository repo)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue