From a3c6431efa9e9856a0633148d4d41b9501bbb8aa Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 18 Jun 2024 14:14:13 +0800 Subject: [PATCH] feature: supports adding custom LFS track pattern --- src/Resources/Locales/en_US.axaml | 4 +++ src/Resources/Locales/zh_CN.axaml | 4 +++ src/Resources/Locales/zh_TW.axaml | 4 +++ src/ViewModels/LFSTrackCustomPattern.cs | 43 ++++++++++++++++++++++++ src/ViewModels/Repository.cs | 13 +++++++ src/Views/LFSTrackCustomPattern.axaml | 33 ++++++++++++++++++ src/Views/LFSTrackCustomPattern.axaml.cs | 12 +++++++ 7 files changed, 113 insertions(+) create mode 100644 src/ViewModels/LFSTrackCustomPattern.cs create mode 100644 src/Views/LFSTrackCustomPattern.axaml create mode 100644 src/Views/LFSTrackCustomPattern.axaml.cs diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 25b50e63..48280f8d 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -229,6 +229,10 @@ FLOW - Start Release Version Tag Prefix: Git LFS + Add Track Pattern... + Pattern is file name + Custom Pattern: + Add Track Pattern to Git LFS Fetch Fetch LFS Objects Run `git lfs fetch` to download Git LFS objects. This does not update the working copy. diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index c2c69099..70955de8 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -232,6 +232,10 @@ 开始版本分支 版本标签前缀 : Git LFS + 添加追踪文件规则... + 匹配完整文件名 + 规则 : + 添加LFS追踪文件规则 拉取LFS对象 (fetch) 拉取LFS对象 执行`git lfs prune`命令,下载远程LFS对象,但不会更新工作副本。 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index 8cd3c88b..f6f31fa7 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -232,6 +232,10 @@ 開始版本分支 版本標籤字首 : Git LFS + 添加追蹤檔案規則... + 匹配完整檔案名 + 規則 : + 添加LFS追蹤檔案規則 拉取LFS物件 (fetch) 拉取LFS物件 執行`git lfs fetch`命令,下載遠端LFS物件,但不會更新工作副本。 diff --git a/src/ViewModels/LFSTrackCustomPattern.cs b/src/ViewModels/LFSTrackCustomPattern.cs new file mode 100644 index 00000000..777e2d22 --- /dev/null +++ b/src/ViewModels/LFSTrackCustomPattern.cs @@ -0,0 +1,43 @@ +using System.ComponentModel.DataAnnotations; +using System.Threading.Tasks; + +namespace SourceGit.ViewModels +{ + public class LFSTrackCustomPattern : Popup + { + [Required(ErrorMessage = "LFS track pattern is required!!!")] + public string Pattern + { + get => _pattern; + set => SetProperty(ref _pattern, value, true); + } + + public bool IsFilename + { + get; + set; + } = false; + + public LFSTrackCustomPattern(Repository repo) + { + _repo = repo; + View = new Views.LFSTrackCustomPattern() { DataContext = this }; + } + + public override Task Sure() + { + _repo.SetWatcherEnabled(false); + ProgressDescription = "Adding custom LFS tracking pattern ..."; + + return Task.Run(() => + { + var succ = new Commands.LFS(_repo.FullPath).Track(_pattern, IsFilename); + CallUIThread(() => _repo.SetWatcherEnabled(true)); + return succ; + }); + } + + private readonly Repository _repo = null; + private string _pattern = string.Empty; + } +} diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 3f035150..5dd56772 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -834,6 +834,19 @@ namespace SourceGit.ViewModels var lfs = new Commands.LFS(_fullpath); if (lfs.IsEnabled()) { + var addPattern = new MenuItem(); + addPattern.Header = App.Text("GitLFS.AddTrackPattern"); + addPattern.Icon = App.CreateMenuIcon("Icons.File.Add"); + addPattern.Click += (o, e) => + { + if (PopupHost.CanCreatePopup()) + PopupHost.ShowPopup(new LFSTrackCustomPattern(this)); + + e.Handled = true; + }; + menu.Items.Add(addPattern); + menu.Items.Add(new MenuItem() { Header = "-" }); + var fetch = new MenuItem(); fetch.Header = App.Text("GitLFS.Fetch"); fetch.Icon = App.CreateMenuIcon("Icons.Fetch"); diff --git a/src/Views/LFSTrackCustomPattern.axaml b/src/Views/LFSTrackCustomPattern.axaml new file mode 100644 index 00000000..6333dcd2 --- /dev/null +++ b/src/Views/LFSTrackCustomPattern.axaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/src/Views/LFSTrackCustomPattern.axaml.cs b/src/Views/LFSTrackCustomPattern.axaml.cs new file mode 100644 index 00000000..2e66f55a --- /dev/null +++ b/src/Views/LFSTrackCustomPattern.axaml.cs @@ -0,0 +1,12 @@ +using Avalonia.Controls; + +namespace SourceGit.Views +{ + public partial class LFSTrackCustomPattern : UserControl + { + public LFSTrackCustomPattern() + { + InitializeComponent(); + } + } +}