feature: supports adding custom LFS track pattern

This commit is contained in:
leo 2024-06-18 14:14:13 +08:00
parent c56d0cf85e
commit a3c6431efa
No known key found for this signature in database
GPG key ID: B528468E49CD0E58
7 changed files with 113 additions and 0 deletions

View file

@ -229,6 +229,10 @@
<x:String x:Key="Text.GitFlow.StartReleaseTitle" xml:space="preserve">FLOW - Start Release</x:String>
<x:String x:Key="Text.GitFlow.TagPrefix" xml:space="preserve">Version Tag Prefix:</x:String>
<x:String x:Key="Text.GitLFS" xml:space="preserve">Git LFS</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern" xml:space="preserve">Add Track Pattern...</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.IsFilename" xml:space="preserve">Pattern is file name</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.Pattern" xml:space="preserve">Custom Pattern:</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.Title" xml:space="preserve">Add Track Pattern to Git LFS</x:String>
<x:String x:Key="Text.GitLFS.Fetch" xml:space="preserve">Fetch</x:String>
<x:String x:Key="Text.GitLFS.Fetch.Title" xml:space="preserve">Fetch LFS Objects</x:String>
<x:String x:Key="Text.GitLFS.Fetch.Tips" xml:space="preserve">Run `git lfs fetch` to download Git LFS objects. This does not update the working copy.</x:String>

View file

@ -232,6 +232,10 @@
<x:String x:Key="Text.GitFlow.StartReleaseTitle" xml:space="preserve">开始版本分支</x:String>
<x:String x:Key="Text.GitFlow.TagPrefix" xml:space="preserve">版本标签前缀 </x:String>
<x:String x:Key="Text.GitLFS" xml:space="preserve">Git LFS</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern" xml:space="preserve">添加追踪文件规则...</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.IsFilename" xml:space="preserve">匹配完整文件名</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.Pattern" xml:space="preserve">规则 </x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.Title" xml:space="preserve">添加LFS追踪文件规则</x:String>
<x:String x:Key="Text.GitLFS.Fetch" xml:space="preserve">拉取LFS对象 (fetch)</x:String>
<x:String x:Key="Text.GitLFS.Fetch.Title" xml:space="preserve">拉取LFS对象</x:String>
<x:String x:Key="Text.GitLFS.Fetch.Tips" xml:space="preserve">执行`git lfs prune`命令下载远程LFS对象但不会更新工作副本。</x:String>

View file

@ -232,6 +232,10 @@
<x:String x:Key="Text.GitFlow.StartReleaseTitle" xml:space="preserve">開始版本分支</x:String>
<x:String x:Key="Text.GitFlow.TagPrefix" xml:space="preserve">版本標籤字首 </x:String>
<x:String x:Key="Text.GitLFS" xml:space="preserve">Git LFS</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern" xml:space="preserve">添加追蹤檔案規則...</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.IsFilename" xml:space="preserve">匹配完整檔案名</x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.Pattern" xml:space="preserve">規則 </x:String>
<x:String x:Key="Text.GitLFS.AddTrackPattern.Title" xml:space="preserve">添加LFS追蹤檔案規則</x:String>
<x:String x:Key="Text.GitLFS.Fetch" xml:space="preserve">拉取LFS物件 (fetch)</x:String>
<x:String x:Key="Text.GitLFS.Fetch.Title" xml:space="preserve">拉取LFS物件</x:String>
<x:String x:Key="Text.GitLFS.Fetch.Tips" xml:space="preserve">執行`git lfs fetch`命令下載遠端LFS物件但不會更新工作副本。</x:String>

View file

@ -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<bool> 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;
}
}

View file

@ -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");

View file

@ -0,0 +1,33 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:m="using:SourceGit.Models"
xmlns:vm="using:SourceGit.ViewModels"
xmlns:v="using:SourceGit.Views"
xmlns:c="using:SourceGit.Converters"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SourceGit.Views.LFSTrackCustomPattern"
x:DataType="vm:LFSTrackCustomPattern">
<StackPanel Orientation="Vertical" Margin="8,0">
<TextBlock FontSize="18"
Classes="bold"
Text="{DynamicResource Text.GitLFS.AddTrackPattern.Title}"/>
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="150,*">
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
Text="{DynamicResource Text.GitLFS.AddTrackPattern.Pattern}"/>
<TextBox Grid.Row="0" Grid.Column="1"
Height="28"
CornerRadius="3"
Text="{Binding Pattern, Mode=TwoWay}"
v:AutoFocusBehaviour.IsEnabled="True"/>
<CheckBox Grid.Row="1" Grid.Column="1"
Content="{DynamicResource Text.GitLFS.AddTrackPattern.IsFilename}"
IsChecked="{Binding IsFilename, Mode=TwoWay}"/>
</Grid>
</StackPanel>
</UserControl>

View file

@ -0,0 +1,12 @@
using Avalonia.Controls;
namespace SourceGit.Views
{
public partial class LFSTrackCustomPattern : UserControl
{
public LFSTrackCustomPattern()
{
InitializeComponent();
}
}
}