From 07b9c7a1c244e7738cc39cc6f2bd9eb29b08ec91 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 15 Apr 2026 17:47:34 +0800 Subject: [PATCH] feature: show uncommitted changes count for submodule (#2264) Signed-off-by: leo --- src/Models/RevisionFile.cs | 1 + src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 1 + src/Resources/Locales/zh_TW.axaml | 1 + src/ViewModels/DiffContext.cs | 13 ++++++++++++- src/Views/DiffView.axaml | 10 +++++++++- 6 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Models/RevisionFile.cs b/src/Models/RevisionFile.cs index 29a23efa..9a9fe7d2 100644 --- a/src/Models/RevisionFile.cs +++ b/src/Models/RevisionFile.cs @@ -39,5 +39,6 @@ namespace SourceGit.Models { public Commit Commit { get; set; } = null; public CommitFullMessage FullMessage { get; set; } = null; + public int UncommittedChanges { get; set; } = 0; } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index aa1c8197..e9569bcd 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -372,6 +372,7 @@ SUBMODULE DELETED NEW + + {0} Uncommitted Changes Swap Syntax Highlighting Line Word Wrap diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 3df2b8f2..299df234 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -376,6 +376,7 @@ 子模块 删除 新增 + + {0} 项未提交变更 交换比对双方 语法高亮 自动换行 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index e1a79d49..98433ce9 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -376,6 +376,7 @@ 子模組 已刪除 新增 + + {0} 項未提交變更 交換比對雙方 語法上色 自動換行 diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 16639427..25155771 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -291,6 +291,16 @@ namespace SourceGit.ViewModels private async Task QuerySubmoduleRevisionAsync(string repo, string sha) { + if (!File.Exists(Path.Combine(repo, ".git"))) + return new Models.RevisionSubmodule() { Commit = new Models.Commit() { SHA = sha } }; + + var uncommittedChangesCount = 0; + if (sha.EndsWith("-dirty", StringComparison.Ordinal)) + { + sha = sha.Substring(0, sha.Length - 6); + uncommittedChangesCount = await new Commands.CountLocalChanges(repo, true).GetResultAsync().ConfigureAwait(false); + } + var commit = await new Commands.QuerySingleCommit(repo, sha).GetResultAsync().ConfigureAwait(false); if (commit == null) return new Models.RevisionSubmodule() { Commit = new Models.Commit() { SHA = sha } }; @@ -299,7 +309,8 @@ namespace SourceGit.ViewModels return new Models.RevisionSubmodule() { Commit = commit, - FullMessage = new Models.CommitFullMessage { Message = body } + FullMessage = new Models.CommitFullMessage { Message = body }, + UncommittedChanges = uncommittedChangesCount }; } diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index fdac0fb8..b8c7b8f3 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -321,7 +321,15 @@ - + + + +