From 61bb0f7dc716d11c45e9e7cb1ef41f31192a55cf Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 14 May 2025 14:21:18 +0800 Subject: [PATCH] feature: show submodule's URL in tooltip (#1307) --- src/Commands/QuerySubmodules.cs | 67 +++++++++++++++++++++++++++---- src/Models/Submodule.cs | 1 + src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 1 + src/Resources/Locales/zh_TW.axaml | 1 + src/Views/Repository.axaml | 23 ++++++++--- src/Views/Repository.axaml.cs | 2 +- 7 files changed, 81 insertions(+), 15 deletions(-) diff --git a/src/Commands/QuerySubmodules.cs b/src/Commands/QuerySubmodules.cs index 8450b407..86147f97 100644 --- a/src/Commands/QuerySubmodules.cs +++ b/src/Commands/QuerySubmodules.cs @@ -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(); + var map = new Dictionary(); + 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(); + 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; + } } } diff --git a/src/Models/Submodule.cs b/src/Models/Submodule.cs index 31cb446a..ca73a8de 100644 --- a/src/Models/Submodule.cs +++ b/src/Models/Submodule.cs @@ -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; } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 87bca788..d1219c07 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -709,6 +709,7 @@ not initialized revision changed unmerged + URL OK Copy Tag Name Copy Tag Message diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index e3199a5a..757a0b98 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -713,6 +713,7 @@ 未初始化 SHA变更 未解决冲突 + 仓库 确 定 复制标签名 复制标签信息 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 5e846953..bf89aed6 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -713,6 +713,7 @@ 未初始化 SHA 變更 未解決的衝突 + 存放庫 確 定 複製標籤名稱 複製標籤訊息 diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index 544e1a4d..36668ff3 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -356,19 +356,30 @@ - + - + - - + + + + - - + diff --git a/src/Views/Repository.axaml.cs b/src/Views/Repository.axaml.cs index 4a0936b2..187c3a2a 100644 --- a/src/Views/Repository.axaml.cs +++ b/src/Views/Repository.axaml.cs @@ -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) {