From 2f7ef1ef2b05c56e442a766602e0799aef5f0991 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Wed, 29 May 2024 17:00:17 +0800 Subject: [PATCH] feat: show tooltip if git version too low --- src/Converters/StringConverters.cs | 17 +++++++++++++++++ src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 1 + src/Views/Preference.axaml | 9 +++++++-- src/Views/Preference.axaml.cs | 13 +++++++++++-- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/Converters/StringConverters.cs b/src/Converters/StringConverters.cs index f743f69f..e2c788ae 100644 --- a/src/Converters/StringConverters.cs +++ b/src/Converters/StringConverters.cs @@ -69,5 +69,22 @@ namespace SourceGit.Converters public static readonly FuncValueConverter ToShortSHA = new FuncValueConverter(v => v.Length > 10 ? v.Substring(0, 10) : v); + + public static readonly FuncValueConverter UnderRecommendGitVersion = + new(v => + { + if (string.IsNullOrEmpty(v)) + return true; + var versionParts = v.Split(new[] { '.', '-' }, StringSplitOptions.RemoveEmptyEntries); + if (versionParts.Length < 3) + return true; + if (!int.TryParse(versionParts[0], out var major) || + !int.TryParse(versionParts[1], out var minor) || + !int.TryParse(versionParts[2], out var build)) + return true; + var gitVersion = new Version(major, minor, build); + var targetVersion = new Version(2, 23, 0); + return gitVersion < targetVersion; + }); } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index d302b4e4..b379bb96 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -308,6 +308,7 @@ User Name Global git user name Git version + Git version is empty or lower than the recommended 2.23.0, exceptions may occur GPG SIGNING Commit GPG signing Install Path diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 6c288f7c..0c3ac3d1 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -308,6 +308,7 @@ 用户名 默认GIT用户名 Git 版本 + Git 版本为空或低于推荐的2.23.0,可能出现异常 GPG签名 启用提交签名 可执行文件位置 diff --git a/src/Views/Preference.axaml b/src/Views/Preference.axaml index 60ecf610..39afd4ea 100644 --- a/src/Views/Preference.axaml +++ b/src/Views/Preference.axaml @@ -251,8 +251,13 @@ Text="{DynamicResource Text.Preference.Git.Version}" HorizontalAlignment="Right" Margin="0,0,16,0"/> - + + + + + + GitVersionProperty = + AvaloniaProperty.Register(nameof(GitVersion)); + + public string GitVersion + { + get => GetValue(GitVersionProperty); + set => SetValue(GitVersionProperty, value); + } + public bool EnableGPGSigning { get; @@ -140,7 +149,7 @@ namespace SourceGit.Views } InitializeComponent(); - txtVersion.Text = ver; + GitVersion = ver; } private void BeginMoveWindow(object sender, PointerPressedEventArgs e) @@ -189,7 +198,7 @@ namespace SourceGit.Views if (selected.Count == 1) { ViewModels.Preference.Instance.GitInstallPath = selected[0].Path.LocalPath; - txtVersion.Text = new Commands.Version().Query(); + GitVersion = new Commands.Version().Query(); } e.Handled = true;