showing get version
cb8300fbe012d74d2517008b00d3b527ca5b62f6
2 files changed
src/GitServer/Services/GitProcessService.cssrc/GitServer/wwwroot/Shared/_Layout.cshtml
diff --git a/src/GitServer/Services/GitProcessService.cs b/src/GitServer/Services/GitProcessService.cs
index 45bfe67..790e92f 100644
--- a/src/GitServer/Services/GitProcessService.cs
+++ b/src/GitServer/Services/GitProcessService.cs
@@ -153,6 +153,36 @@ public class GitProcessService(IOptions<GitServerOptions> options, ILogger<GitPr
await proc.WaitForExitAsync();
}
+ private static Lazy<Task<string>>? _versionCache;
+
+ public Task<string> GetVersion()
+ {
+ // git.exe's version never changes while the app is running, so query it once and reuse it.
+ _versionCache ??= new Lazy<Task<string>>(FetchVersion);
+ return _versionCache.Value;
+ }
+
+ private async Task<string> FetchVersion()
+ {
+ var psi = new ProcessStartInfo(_gitExe)
+ {
+ Arguments = "--version",
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ UseShellExecute = false,
+ CreateNoWindow = true,
+ };
+
+ using var proc = Process.Start(psi) ?? throw new InvalidOperationException("Failed to start git");
+ var stdout = await proc.StandardOutput.ReadToEndAsync();
+ await proc.WaitForExitAsync();
+
+ // "git version 2.45.1.windows.1" -> "2.45.1.windows.1"
+ var prefix = "git version ";
+ var text = stdout.Trim();
+ return text.StartsWith(prefix) ? text[prefix.Length..] : text;
+ }
+
public async Task<bool> IsEmpty(string repoPath)
{
var result = await RunGitAsync(repoPath, "rev-list --all --count");
diff --git a/src/GitServer/wwwroot/Shared/_Layout.cshtml b/src/GitServer/wwwroot/Shared/_Layout.cshtml
index d297860..4f9d2d3 100644
--- a/src/GitServer/wwwroot/Shared/_Layout.cshtml
+++ b/src/GitServer/wwwroot/Shared/_Layout.cshtml
@@ -1,6 +1,8 @@
@using Microsoft.AspNetCore.Identity
+@using GitServer.Services
@inject SignInManager<GitServer.Models.AppUser> SignInManager
@inject UserManager<GitServer.Models.AppUser> UserManager
+@inject GitProcessService GitProcess
<!DOCTYPE html>
<html lang="@L.CurrentLanguage">
<head>
@@ -28,6 +30,7 @@
</svg>
GitServer
<span class="version-badge">v@(System.Reflection.Assembly.GetExecutingAssembly().GetName().Version?.ToString(2))</span>
+ <span class="version-badge">git @(await GitProcess.GetVersion())</span>
</a>
<button class="navbar-toggle" id="navToggle" aria-label="Menu">
<span></span><span></span><span></span>