From dd7d07626a20b2d2c6a2b91bea040a05ec4d29e8 Mon Sep 17 00:00:00 2001 From: heartacker Date: Mon, 27 Apr 2026 09:53:41 +0800 Subject: [PATCH 1/2] feat: embed Git commit hash in build and display in About dialog - Add MSBuild target to retrieve and embed the current Git commit hash as an assembly metadata attribute - Add a TextBlock in the About view to display the Git commit hash - Update About view code-behind to read and show the Git hash metadata --- src/SourceGit.csproj | 16 ++++++++++++++++ src/Views/About.axaml | 1 + src/Views/About.axaml.cs | 5 ++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj index 009d2c89db..6dd55f2875 100644 --- a/src/SourceGit.csproj +++ b/src/SourceGit.csproj @@ -32,6 +32,22 @@ $(DefineConstants);DISABLE_UPDATE_DETECTION + + + + + + + + + + diff --git a/src/Views/About.axaml b/src/Views/About.axaml index 265c601968..ab61bfeaaf 100644 --- a/src/Views/About.axaml +++ b/src/Views/About.axaml @@ -71,6 +71,7 @@ + diff --git a/src/Views/About.axaml.cs b/src/Views/About.axaml.cs index f5dea0e59a..6aee5f3125 100644 --- a/src/Views/About.axaml.cs +++ b/src/Views/About.axaml.cs @@ -23,7 +23,10 @@ public About() if (attr.Key.Equals("BuildDate", StringComparison.OrdinalIgnoreCase) && DateTime.TryParse(attr.Value, out var date)) { TxtReleaseDate.Text = App.Text("About.ReleaseDate", Models.DateTimeFormat.Format(date, true)); - break; + } + else if (attr.Key.Equals("GitCommitHash", StringComparison.OrdinalIgnoreCase)) + { + TxtGitHash.Text = $"Build: {attr.Value}"; } } From 8a7ebd0a2d58a9c9849eebe62c496430c63f9c3e Mon Sep 17 00:00:00 2001 From: heartacker Date: Mon, 27 Apr 2026 10:32:18 +0800 Subject: [PATCH 2/2] fix: prevent build failure when git is not installed but .git directory exists Added ContinueOnError and exit code check to the SetGitCommitHash target so the build gracefully skips embedding the git commit hash if the `git` executable is unavailable, rather than failing the entire build. --- src/SourceGit.csproj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/SourceGit.csproj b/src/SourceGit.csproj index 6dd55f2875..72251a45f1 100644 --- a/src/SourceGit.csproj +++ b/src/SourceGit.csproj @@ -35,15 +35,17 @@ + ConsoleToMSBuild="true" StandardOutputImportance="low" + ContinueOnError="true"> + - + Condition="'$(_GitExitCode)' == '0' And '$(GitCommitHash)' != ''" /> +