Skip to content

Commit 9ce29bb

Browse files
committed
feature: supports to configure remote.<name>.pruneTags while adding or editing remote (#1692)
Signed-off-by: leo <[email protected]>
1 parent e87eb81 commit 9ce29bb

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@
612612
<x:String x:Key="Text.Remote.EditTitle" xml:space="preserve">Edit Remote</x:String>
613613
<x:String x:Key="Text.Remote.Name" xml:space="preserve">Name:</x:String>
614614
<x:String x:Key="Text.Remote.Name.Placeholder" xml:space="preserve">Remote name</x:String>
615+
<x:String x:Key="Text.Remote.PruneTagsOnFetch" xml:space="preserve">Prune tags do not exists in this remote</x:String>
616+
<x:String x:Key="Text.Remote.PruneTagsOnFetch.Tip" xml:space="preserve">Only works while fetching with `--prune` enabled</x:String>
615617
<x:String x:Key="Text.Remote.URL" xml:space="preserve">Repository URL:</x:String>
616618
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">Remote git repository URL</x:String>
617619
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">Copy URL</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@
616616
<x:String x:Key="Text.Remote.EditTitle" xml:space="preserve">编辑远程仓库</x:String>
617617
<x:String x:Key="Text.Remote.Name" xml:space="preserve">远程名 :</x:String>
618618
<x:String x:Key="Text.Remote.Name.Placeholder" xml:space="preserve">唯一远程名</x:String>
619+
<x:String x:Key="Text.Remote.PruneTagsOnFetch" xml:space="preserve">自动清理该远程中不存在的标签</x:String>
620+
<x:String x:Key="Text.Remote.PruneTagsOnFetch.Tip" xml:space="preserve">仅当启用修剪(--prune)后,拉取更新时作用</x:String>
619621
<x:String x:Key="Text.Remote.URL" xml:space="preserve">仓库地址 :</x:String>
620622
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">远程仓库的地址</x:String>
621623
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">复制远程地址</x:String>

src/Resources/Locales/zh_TW.axaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@
616616
<x:String x:Key="Text.Remote.EditTitle" xml:space="preserve">編輯遠端存放庫</x:String>
617617
<x:String x:Key="Text.Remote.Name" xml:space="preserve">遠端名稱:</x:String>
618618
<x:String x:Key="Text.Remote.Name.Placeholder" xml:space="preserve">唯一遠端名稱</x:String>
619+
<x:String x:Key="Text.Remote.PruneTagsOnFetch" xml:space="preserve">自動清除此遠端中不存在的標籤</x:String>
620+
<x:String x:Key="Text.Remote.PruneTagsOnFetch.Tip" xml:space="preserve">僅在啟用自动清理 (--prune) 后,提取遠端變更時有效</x:String>
619621
<x:String x:Key="Text.Remote.URL" xml:space="preserve">存放庫網址:</x:String>
620622
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">遠端存放庫的網址</x:String>
621623
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">複製遠端網址</x:String>

src/ViewModels/AddRemote.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public string SSHKey
4444
set => SetProperty(ref _sshkey, value, true);
4545
}
4646

47+
public bool PruneTagsOnFetch
48+
{
49+
get;
50+
set;
51+
} = false;
52+
4753
public AddRemote(Repository repo)
4854
{
4955
_repo = repo;
@@ -105,6 +111,11 @@ public override async Task<bool> Sure()
105111
.Use(log)
106112
.SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
107113

114+
if (PruneTagsOnFetch)
115+
await new Commands.Config(_repo.FullPath)
116+
.Use(log)
117+
.SetAsync($"remote.{_name}.pruneTags", "true");
118+
108119
await new Commands.Fetch(_repo.FullPath, _name, false, false)
109120
.Use(log)
110121
.RunAsync();

src/ViewModels/EditRemote.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.ComponentModel.DataAnnotations;
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
23
using System.IO;
34
using System.Threading.Tasks;
4-
using Avalonia.Threading;
55

66
namespace SourceGit.ViewModels
77
{
@@ -45,6 +45,12 @@ public string SSHKey
4545
set => SetProperty(ref _sshkey, value, true);
4646
}
4747

48+
public bool PruneTagsOnFetch
49+
{
50+
get;
51+
set;
52+
}
53+
4854
public EditRemote(Repository repo, Models.Remote remote)
4955
{
5056
_repo = repo;
@@ -53,17 +59,11 @@ public EditRemote(Repository repo, Models.Remote remote)
5359
_url = remote.URL;
5460
_useSSH = Models.Remote.IsSSH(remote.URL);
5561

62+
var config = new Commands.Config(repo.FullPath);
5663
if (_useSSH)
57-
{
58-
Task.Run(async () =>
59-
{
60-
var sshKey = await new Commands.Config(repo.FullPath)
61-
.GetAsync($"remote.{remote.Name}.sshkey")
62-
.ConfigureAwait(false);
64+
_sshkey = config.Get($"remote.{remote.Name}.sshkey");
6365

64-
Dispatcher.UIThread.Post(() => SSHKey = sshKey);
65-
});
66-
}
66+
PruneTagsOnFetch = config.Get($"remote.{remote.Name}.pruneTags").Equals("true", StringComparison.OrdinalIgnoreCase);
6767
}
6868

6969
public static ValidationResult ValidateRemoteName(string name, ValidationContext ctx)
@@ -131,7 +131,9 @@ public override async Task<bool> Sure()
131131
if (pushURL != _url)
132132
await new Commands.Remote(_repo.FullPath).SetURLAsync(_name, _url, true);
133133

134-
await new Commands.Config(_repo.FullPath).SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
134+
var config = new Commands.Config(_repo.FullPath);
135+
await config.SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
136+
await config.SetAsync($"remote.{_name}.pruneTags", PruneTagsOnFetch ? "true" : null);
135137

136138
_repo.SetWatcherEnabled(true);
137139
return true;

src/Views/AddRemote.axaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Classes="bold"
1313
Text="{DynamicResource Text.Remote.AddTitle}"/>
1414

15-
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto" ColumnDefinitions="120,*">
15+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,32" ColumnDefinitions="120,*">
1616
<TextBlock Grid.Row="0" Grid.Column="0"
1717
HorizontalAlignment="Right" VerticalAlignment="Center"
1818
Margin="0,0,8,0"
@@ -54,6 +54,11 @@
5454
</Button>
5555
</TextBox.InnerRightContent>
5656
</TextBox>
57+
58+
<CheckBox Grid.Row="3" Grid.Column="1"
59+
Content="{DynamicResource Text.Remote.PruneTagsOnFetch}"
60+
IsChecked="{Binding PruneTagsOnFetch, Mode=TwoWay}"
61+
ToolTip.Tip="{DynamicResource Text.Remote.PruneTagsOnFetch.Tip}"/>
5762
</Grid>
5863
</StackPanel>
5964
</UserControl>

src/Views/EditRemote.axaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Classes="bold"
1313
Text="{DynamicResource Text.Remote.EditTitle}"/>
1414

15-
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto" ColumnDefinitions="150,*">
15+
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,32" ColumnDefinitions="150,*">
1616
<TextBlock Grid.Row="0" Grid.Column="0"
1717
HorizontalAlignment="Right" VerticalAlignment="Center"
1818
Margin="0,0,8,0"
@@ -54,6 +54,11 @@
5454
</Button>
5555
</TextBox.InnerRightContent>
5656
</TextBox>
57+
58+
<CheckBox Grid.Row="3" Grid.Column="1"
59+
Content="{DynamicResource Text.Remote.PruneTagsOnFetch}"
60+
IsChecked="{Binding PruneTagsOnFetch, Mode=TwoWay}"
61+
ToolTip.Tip="{DynamicResource Text.Remote.PruneTagsOnFetch.Tip}"/>
5762
</Grid>
5863
</StackPanel>
5964
</UserControl>

0 commit comments

Comments
 (0)