feature: supports to configure remote.<name>.pruneTags while adding or editing remote (#1692)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-08-13 21:13:50 +08:00
parent e87eb8137b
commit 9ce29bb9bc
7 changed files with 43 additions and 14 deletions

View File

@@ -612,6 +612,8 @@
<x:String x:Key="Text.Remote.EditTitle" xml:space="preserve">Edit Remote</x:String>
<x:String x:Key="Text.Remote.Name" xml:space="preserve">Name:</x:String>
<x:String x:Key="Text.Remote.Name.Placeholder" xml:space="preserve">Remote name</x:String>
<x:String x:Key="Text.Remote.PruneTagsOnFetch" xml:space="preserve">Prune tags do not exists in this remote</x:String>
<x:String x:Key="Text.Remote.PruneTagsOnFetch.Tip" xml:space="preserve">Only works while fetching with `--prune` enabled</x:String>
<x:String x:Key="Text.Remote.URL" xml:space="preserve">Repository URL:</x:String>
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">Remote git repository URL</x:String>
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">Copy URL</x:String>

View File

@@ -616,6 +616,8 @@
<x:String x:Key="Text.Remote.EditTitle" xml:space="preserve">编辑远程仓库</x:String>
<x:String x:Key="Text.Remote.Name" xml:space="preserve">远程名 </x:String>
<x:String x:Key="Text.Remote.Name.Placeholder" xml:space="preserve">唯一远程名</x:String>
<x:String x:Key="Text.Remote.PruneTagsOnFetch" xml:space="preserve">自动清理该远程中不存在的标签</x:String>
<x:String x:Key="Text.Remote.PruneTagsOnFetch.Tip" xml:space="preserve">仅当启用修剪(--prune拉取更新时作用</x:String>
<x:String x:Key="Text.Remote.URL" xml:space="preserve">仓库地址 </x:String>
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">远程仓库的地址</x:String>
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">复制远程地址</x:String>

View File

@@ -616,6 +616,8 @@
<x:String x:Key="Text.Remote.EditTitle" xml:space="preserve">編輯遠端存放庫</x:String>
<x:String x:Key="Text.Remote.Name" xml:space="preserve">遠端名稱:</x:String>
<x:String x:Key="Text.Remote.Name.Placeholder" xml:space="preserve">唯一遠端名稱</x:String>
<x:String x:Key="Text.Remote.PruneTagsOnFetch" xml:space="preserve">自動清除此遠端中不存在的標籤</x:String>
<x:String x:Key="Text.Remote.PruneTagsOnFetch.Tip" xml:space="preserve">僅在啟用自动清理 (--prune) 后,提取遠端變更時有效</x:String>
<x:String x:Key="Text.Remote.URL" xml:space="preserve">存放庫網址:</x:String>
<x:String x:Key="Text.Remote.URL.Placeholder" xml:space="preserve">遠端存放庫的網址</x:String>
<x:String x:Key="Text.RemoteCM.CopyURL" xml:space="preserve">複製遠端網址</x:String>

View File

@@ -44,6 +44,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _sshkey, value, true);
}
public bool PruneTagsOnFetch
{
get;
set;
} = false;
public AddRemote(Repository repo)
{
_repo = repo;
@@ -105,6 +111,11 @@ namespace SourceGit.ViewModels
.Use(log)
.SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
if (PruneTagsOnFetch)
await new Commands.Config(_repo.FullPath)
.Use(log)
.SetAsync($"remote.{_name}.pruneTags", "true");
await new Commands.Fetch(_repo.FullPath, _name, false, false)
.Use(log)
.RunAsync();

View File

@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading.Tasks;
using Avalonia.Threading;
namespace SourceGit.ViewModels
{
@@ -45,6 +45,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _sshkey, value, true);
}
public bool PruneTagsOnFetch
{
get;
set;
}
public EditRemote(Repository repo, Models.Remote remote)
{
_repo = repo;
@@ -53,17 +59,11 @@ namespace SourceGit.ViewModels
_url = remote.URL;
_useSSH = Models.Remote.IsSSH(remote.URL);
var config = new Commands.Config(repo.FullPath);
if (_useSSH)
{
Task.Run(async () =>
{
var sshKey = await new Commands.Config(repo.FullPath)
.GetAsync($"remote.{remote.Name}.sshkey")
.ConfigureAwait(false);
_sshkey = config.Get($"remote.{remote.Name}.sshkey");
Dispatcher.UIThread.Post(() => SSHKey = sshKey);
});
}
PruneTagsOnFetch = config.Get($"remote.{remote.Name}.pruneTags").Equals("true", StringComparison.OrdinalIgnoreCase);
}
public static ValidationResult ValidateRemoteName(string name, ValidationContext ctx)
@@ -131,7 +131,9 @@ namespace SourceGit.ViewModels
if (pushURL != _url)
await new Commands.Remote(_repo.FullPath).SetURLAsync(_name, _url, true);
await new Commands.Config(_repo.FullPath).SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
var config = new Commands.Config(_repo.FullPath);
await config.SetAsync($"remote.{_name}.sshkey", _useSSH ? SSHKey : null);
await config.SetAsync($"remote.{_name}.pruneTags", PruneTagsOnFetch ? "true" : null);
_repo.SetWatcherEnabled(true);
return true;

View File

@@ -12,7 +12,7 @@
Classes="bold"
Text="{DynamicResource Text.Remote.AddTitle}"/>
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto" ColumnDefinitions="120,*">
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,32" ColumnDefinitions="120,*">
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
@@ -54,6 +54,11 @@
</Button>
</TextBox.InnerRightContent>
</TextBox>
<CheckBox Grid.Row="3" Grid.Column="1"
Content="{DynamicResource Text.Remote.PruneTagsOnFetch}"
IsChecked="{Binding PruneTagsOnFetch, Mode=TwoWay}"
ToolTip.Tip="{DynamicResource Text.Remote.PruneTagsOnFetch.Tip}"/>
</Grid>
</StackPanel>
</UserControl>

View File

@@ -12,7 +12,7 @@
Classes="bold"
Text="{DynamicResource Text.Remote.EditTitle}"/>
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto" ColumnDefinitions="150,*">
<Grid Margin="0,16,0,0" RowDefinitions="32,32,Auto,32" ColumnDefinitions="150,*">
<TextBlock Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
Margin="0,0,8,0"
@@ -54,6 +54,11 @@
</Button>
</TextBox.InnerRightContent>
</TextBox>
<CheckBox Grid.Row="3" Grid.Column="1"
Content="{DynamicResource Text.Remote.PruneTagsOnFetch}"
IsChecked="{Binding PruneTagsOnFetch, Mode=TwoWay}"
ToolTip.Tip="{DynamicResource Text.Remote.PruneTagsOnFetch.Tip}"/>
</Grid>
</StackPanel>
</UserControl>