feature<Remote>: add 'Prune' context menu for remote to prune dead branches without fetching

This commit is contained in:
leo 2021-11-17 16:12:26 +08:00
parent 0379d7e331
commit 9f58e0c715
6 changed files with 65 additions and 10 deletions

View file

@ -23,6 +23,11 @@ namespace SourceGit.Commands {
return Exec(); return Exec();
} }
public bool Prune(string name) {
Args = $"remote prune {name}";
return Exec();
}
public bool SetURL(string name, string url) { public bool SetURL(string name, string url) {
Args = $"remote set-url {name} {url}"; Args = $"remote set-url {name} {url}";
return Exec(); return Exec();

View file

@ -185,10 +185,11 @@
<sys:String x:Key="Text.BranchCM.CopyName">Copy Branch Name</sys:String> <sys:String x:Key="Text.BranchCM.CopyName">Copy Branch Name</sys:String>
<sys:String x:Key="Text.BranchCM.UnsetUpstream">Unset Upstream</sys:String> <sys:String x:Key="Text.BranchCM.UnsetUpstream">Unset Upstream</sys:String>
<sys:String x:Key="Text.RemoteCM.Fetch">Fetch '{0}'</sys:String> <sys:String x:Key="Text.RemoteCM.Fetch">Fetch ...</sys:String>
<sys:String x:Key="Text.RemoteCM.Edit">Edit '{0}'</sys:String> <sys:String x:Key="Text.RemoteCM.Prune">Prune</sys:String>
<sys:String x:Key="Text.RemoteCM.Delete">Delete '{0}'</sys:String> <sys:String x:Key="Text.RemoteCM.Edit">Edit ...</sys:String>
<sys:String x:Key="Text.RemoteCM.CopyURL">Copy Remote URL</sys:String> <sys:String x:Key="Text.RemoteCM.Delete">Delete ...</sys:String>
<sys:String x:Key="Text.RemoteCM.CopyURL">Copy URL</sys:String>
<sys:String x:Key="Text.CommitCM.Reset">Reset '{0}' to Here</sys:String> <sys:String x:Key="Text.CommitCM.Reset">Reset '{0}' to Here</sys:String>
<sys:String x:Key="Text.CommitCM.Rebase">Rebase '{0}' to Here</sys:String> <sys:String x:Key="Text.CommitCM.Rebase">Rebase '{0}' to Here</sys:String>

View file

@ -184,9 +184,10 @@
<sys:String x:Key="Text.BranchCM.CopyName">复制分支名</sys:String> <sys:String x:Key="Text.BranchCM.CopyName">复制分支名</sys:String>
<sys:String x:Key="Text.BranchCM.UnsetUpstream">取消追踪</sys:String> <sys:String x:Key="Text.BranchCM.UnsetUpstream">取消追踪</sys:String>
<sys:String x:Key="Text.RemoteCM.Fetch">拉取 '{0}' 更新</sys:String> <sys:String x:Key="Text.RemoteCM.Fetch">拉取更新 ...</sys:String>
<sys:String x:Key="Text.RemoteCM.Edit">编辑 '{0}'</sys:String> <sys:String x:Key="Text.RemoteCM.Prune">清理远程已删除分支</sys:String>
<sys:String x:Key="Text.RemoteCM.Delete">删除 '{0}'</sys:String> <sys:String x:Key="Text.RemoteCM.Edit">编辑 ...</sys:String>
<sys:String x:Key="Text.RemoteCM.Delete">删除 ...</sys:String>
<sys:String x:Key="Text.RemoteCM.CopyURL">复制远程地址</sys:String> <sys:String x:Key="Text.RemoteCM.CopyURL">复制远程地址</sys:String>
<sys:String x:Key="Text.CommitCM.Reset">重置 '{0}' 到此处</sys:String> <sys:String x:Key="Text.CommitCM.Reset">重置 '{0}' 到此处</sys:String>

View file

@ -0,0 +1,10 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.Prune"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignWidth="500" Height="100">
</controls:PopupWidget>

View file

@ -0,0 +1,30 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 清理远程已删除分支
/// </summary>
public partial class Prune : Controls.PopupWidget {
private string repo = null;
private string remote = null;
public Prune(string repo, string remote) {
this.repo = repo;
this.remote = remote;
InitializeComponent();
}
public override string GetTitle() {
return App.Text("RemoteCM.Prune");
}
public override Task<bool> Start() {
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
var succ = new Commands.Remote(repo).Prune(remote);
Models.Watcher.SetEnabled(repo, true);
return succ;
});
}
}
}

View file

@ -745,21 +745,28 @@ namespace SourceGit.Views.Widgets {
private void FillRemoteContextMenu(ContextMenu menu, Models.Remote remote) { private void FillRemoteContextMenu(ContextMenu menu, Models.Remote remote) {
var fetch = new MenuItem(); var fetch = new MenuItem();
fetch.Header = App.Text("RemoteCM.Fetch", remote.Name); fetch.Header = App.Text("RemoteCM.Fetch");
fetch.Click += (o, e) => { fetch.Click += (o, e) => {
new Popups.Fetch(repo, remote.Name).Show(); new Popups.Fetch(repo, remote.Name).Show();
e.Handled = true; e.Handled = true;
}; };
var prune = new MenuItem();
prune.Header = App.Text("RemoteCM.Prune");
prune.Click += (o, e) => {
new Popups.Prune(repo.Path, remote.Name).ShowAndStart();
e.Handled = true;
};
var edit = new MenuItem(); var edit = new MenuItem();
edit.Header = App.Text("RemoteCM.Edit", remote.Name); edit.Header = App.Text("RemoteCM.Edit");
edit.Click += (o, e) => { edit.Click += (o, e) => {
new Popups.Remote(repo, remote).Show(); new Popups.Remote(repo, remote).Show();
e.Handled = true; e.Handled = true;
}; };
var delete = new MenuItem(); var delete = new MenuItem();
delete.Header = App.Text("RemoteCM.Delete", remote.Name); delete.Header = App.Text("RemoteCM.Delete");
delete.Click += (o, e) => { delete.Click += (o, e) => {
new Popups.DeleteRemote(repo.Path, remote.Name).Show(); new Popups.DeleteRemote(repo.Path, remote.Name).Show();
e.Handled = true; e.Handled = true;
@ -773,6 +780,7 @@ namespace SourceGit.Views.Widgets {
}; };
menu.Items.Add(fetch); menu.Items.Add(fetch);
menu.Items.Add(prune);
menu.Items.Add(new Separator()); menu.Items.Add(new Separator());
menu.Items.Add(edit); menu.Items.Add(edit);
menu.Items.Add(delete); menu.Items.Add(delete);