Skip to content

Commit a3c6431

Browse files
committed
feature: supports adding custom LFS track pattern
1 parent c56d0cf commit a3c6431

File tree

7 files changed

+113
-0
lines changed

7 files changed

+113
-0
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@
229229
<x:String x:Key="Text.GitFlow.StartReleaseTitle" xml:space="preserve">FLOW - Start Release</x:String>
230230
<x:String x:Key="Text.GitFlow.TagPrefix" xml:space="preserve">Version Tag Prefix:</x:String>
231231
<x:String x:Key="Text.GitLFS" xml:space="preserve">Git LFS</x:String>
232+
<x:String x:Key="Text.GitLFS.AddTrackPattern" xml:space="preserve">Add Track Pattern...</x:String>
233+
<x:String x:Key="Text.GitLFS.AddTrackPattern.IsFilename" xml:space="preserve">Pattern is file name</x:String>
234+
<x:String x:Key="Text.GitLFS.AddTrackPattern.Pattern" xml:space="preserve">Custom Pattern:</x:String>
235+
<x:String x:Key="Text.GitLFS.AddTrackPattern.Title" xml:space="preserve">Add Track Pattern to Git LFS</x:String>
232236
<x:String x:Key="Text.GitLFS.Fetch" xml:space="preserve">Fetch</x:String>
233237
<x:String x:Key="Text.GitLFS.Fetch.Title" xml:space="preserve">Fetch LFS Objects</x:String>
234238
<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>

src/Resources/Locales/zh_CN.axaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
<x:String x:Key="Text.GitFlow.StartReleaseTitle" xml:space="preserve">开始版本分支</x:String>
233233
<x:String x:Key="Text.GitFlow.TagPrefix" xml:space="preserve">版本标签前缀 :</x:String>
234234
<x:String x:Key="Text.GitLFS" xml:space="preserve">Git LFS</x:String>
235+
<x:String x:Key="Text.GitLFS.AddTrackPattern" xml:space="preserve">添加追踪文件规则...</x:String>
236+
<x:String x:Key="Text.GitLFS.AddTrackPattern.IsFilename" xml:space="preserve">匹配完整文件名</x:String>
237+
<x:String x:Key="Text.GitLFS.AddTrackPattern.Pattern" xml:space="preserve">规则 :</x:String>
238+
<x:String x:Key="Text.GitLFS.AddTrackPattern.Title" xml:space="preserve">添加LFS追踪文件规则</x:String>
235239
<x:String x:Key="Text.GitLFS.Fetch" xml:space="preserve">拉取LFS对象 (fetch)</x:String>
236240
<x:String x:Key="Text.GitLFS.Fetch.Title" xml:space="preserve">拉取LFS对象</x:String>
237241
<x:String x:Key="Text.GitLFS.Fetch.Tips" xml:space="preserve">执行`git lfs prune`命令,下载远程LFS对象,但不会更新工作副本。</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@
232232
<x:String x:Key="Text.GitFlow.StartReleaseTitle" xml:space="preserve">開始版本分支</x:String>
233233
<x:String x:Key="Text.GitFlow.TagPrefix" xml:space="preserve">版本標籤字首 :</x:String>
234234
<x:String x:Key="Text.GitLFS" xml:space="preserve">Git LFS</x:String>
235+
<x:String x:Key="Text.GitLFS.AddTrackPattern" xml:space="preserve">添加追蹤檔案規則...</x:String>
236+
<x:String x:Key="Text.GitLFS.AddTrackPattern.IsFilename" xml:space="preserve">匹配完整檔案名</x:String>
237+
<x:String x:Key="Text.GitLFS.AddTrackPattern.Pattern" xml:space="preserve">規則 :</x:String>
238+
<x:String x:Key="Text.GitLFS.AddTrackPattern.Title" xml:space="preserve">添加LFS追蹤檔案規則</x:String>
235239
<x:String x:Key="Text.GitLFS.Fetch" xml:space="preserve">拉取LFS物件 (fetch)</x:String>
236240
<x:String x:Key="Text.GitLFS.Fetch.Title" xml:space="preserve">拉取LFS物件</x:String>
237241
<x:String x:Key="Text.GitLFS.Fetch.Tips" xml:space="preserve">執行`git lfs fetch`命令,下載遠端LFS物件,但不會更新工作副本。</x:String>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.Threading.Tasks;
3+
4+
namespace SourceGit.ViewModels
5+
{
6+
public class LFSTrackCustomPattern : Popup
7+
{
8+
[Required(ErrorMessage = "LFS track pattern is required!!!")]
9+
public string Pattern
10+
{
11+
get => _pattern;
12+
set => SetProperty(ref _pattern, value, true);
13+
}
14+
15+
public bool IsFilename
16+
{
17+
get;
18+
set;
19+
} = false;
20+
21+
public LFSTrackCustomPattern(Repository repo)
22+
{
23+
_repo = repo;
24+
View = new Views.LFSTrackCustomPattern() { DataContext = this };
25+
}
26+
27+
public override Task<bool> Sure()
28+
{
29+
_repo.SetWatcherEnabled(false);
30+
ProgressDescription = "Adding custom LFS tracking pattern ...";
31+
32+
return Task.Run(() =>
33+
{
34+
var succ = new Commands.LFS(_repo.FullPath).Track(_pattern, IsFilename);
35+
CallUIThread(() => _repo.SetWatcherEnabled(true));
36+
return succ;
37+
});
38+
}
39+
40+
private readonly Repository _repo = null;
41+
private string _pattern = string.Empty;
42+
}
43+
}

src/ViewModels/Repository.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,19 @@ public ContextMenu CreateContextMenuForGitLFS()
834834
var lfs = new Commands.LFS(_fullpath);
835835
if (lfs.IsEnabled())
836836
{
837+
var addPattern = new MenuItem();
838+
addPattern.Header = App.Text("GitLFS.AddTrackPattern");
839+
addPattern.Icon = App.CreateMenuIcon("Icons.File.Add");
840+
addPattern.Click += (o, e) =>
841+
{
842+
if (PopupHost.CanCreatePopup())
843+
PopupHost.ShowPopup(new LFSTrackCustomPattern(this));
844+
845+
e.Handled = true;
846+
};
847+
menu.Items.Add(addPattern);
848+
menu.Items.Add(new MenuItem() { Header = "-" });
849+
837850
var fetch = new MenuItem();
838851
fetch.Header = App.Text("GitLFS.Fetch");
839852
fetch.Icon = App.CreateMenuIcon("Icons.Fetch");
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:m="using:SourceGit.Models"
6+
xmlns:vm="using:SourceGit.ViewModels"
7+
xmlns:v="using:SourceGit.Views"
8+
xmlns:c="using:SourceGit.Converters"
9+
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
10+
x:Class="SourceGit.Views.LFSTrackCustomPattern"
11+
x:DataType="vm:LFSTrackCustomPattern">
12+
<StackPanel Orientation="Vertical" Margin="8,0">
13+
<TextBlock FontSize="18"
14+
Classes="bold"
15+
Text="{DynamicResource Text.GitLFS.AddTrackPattern.Title}"/>
16+
17+
<Grid Margin="0,16,0,0" RowDefinitions="32,32" ColumnDefinitions="150,*">
18+
<TextBlock Grid.Row="0" Grid.Column="0"
19+
HorizontalAlignment="Right" VerticalAlignment="Center"
20+
Margin="0,0,8,0"
21+
Text="{DynamicResource Text.GitLFS.AddTrackPattern.Pattern}"/>
22+
<TextBox Grid.Row="0" Grid.Column="1"
23+
Height="28"
24+
CornerRadius="3"
25+
Text="{Binding Pattern, Mode=TwoWay}"
26+
v:AutoFocusBehaviour.IsEnabled="True"/>
27+
28+
<CheckBox Grid.Row="1" Grid.Column="1"
29+
Content="{DynamicResource Text.GitLFS.AddTrackPattern.IsFilename}"
30+
IsChecked="{Binding IsFilename, Mode=TwoWay}"/>
31+
</Grid>
32+
</StackPanel>
33+
</UserControl>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Avalonia.Controls;
2+
3+
namespace SourceGit.Views
4+
{
5+
public partial class LFSTrackCustomPattern : UserControl
6+
{
7+
public LFSTrackCustomPattern()
8+
{
9+
InitializeComponent();
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)