mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
feature<Dashboard>: add menu to unset upstream and cancel tracking when deleting related remote branches
This commit is contained in:
parent
f041adb2b3
commit
584bac74f9
5 changed files with 37 additions and 7 deletions
|
@ -21,7 +21,12 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetUpstream(string upstream) {
|
public void SetUpstream(string upstream) {
|
||||||
Args = $"branch {target} -u {upstream}";
|
Args = $"branch {target} ";
|
||||||
|
if (string.IsNullOrEmpty(upstream)) {
|
||||||
|
Args += "--unset-upstream";
|
||||||
|
} else {
|
||||||
|
Args += $"-u {upstream}";
|
||||||
|
}
|
||||||
Exec();
|
Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,6 +179,7 @@
|
||||||
<sys:String x:Key="Text.BranchCM.Delete">Delete '{0}'</sys:String>
|
<sys:String x:Key="Text.BranchCM.Delete">Delete '{0}'</sys:String>
|
||||||
<sys:String x:Key="Text.BranchCM.Tracking">Tracking ...</sys:String>
|
<sys:String x:Key="Text.BranchCM.Tracking">Tracking ...</sys:String>
|
||||||
<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.RemoteCM.Fetch">Fetch '{0}'</sys:String>
|
<sys:String x:Key="Text.RemoteCM.Fetch">Fetch '{0}'</sys:String>
|
||||||
<sys:String x:Key="Text.RemoteCM.Edit">Edit '{0}'</sys:String>
|
<sys:String x:Key="Text.RemoteCM.Edit">Edit '{0}'</sys:String>
|
||||||
|
|
|
@ -178,6 +178,7 @@
|
||||||
<sys:String x:Key="Text.BranchCM.Delete">删除 '{0}'</sys:String>
|
<sys:String x:Key="Text.BranchCM.Delete">删除 '{0}'</sys:String>
|
||||||
<sys:String x:Key="Text.BranchCM.Tracking">切换上游分支...</sys:String>
|
<sys:String x:Key="Text.BranchCM.Tracking">切换上游分支...</sys:String>
|
||||||
<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.RemoteCM.Fetch">拉取 '{0}' 更新</sys:String>
|
<sys:String x:Key="Text.RemoteCM.Fetch">拉取 '{0}' 更新</sys:String>
|
||||||
<sys:String x:Key="Text.RemoteCM.Edit">编辑 '{0}'</sys:String>
|
<sys:String x:Key="Text.RemoteCM.Edit">编辑 '{0}'</sys:String>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SourceGit.Views.Popups {
|
namespace SourceGit.Views.Popups {
|
||||||
|
@ -8,6 +9,7 @@ namespace SourceGit.Views.Popups {
|
||||||
private string repo = null;
|
private string repo = null;
|
||||||
private string branch = null;
|
private string branch = null;
|
||||||
private string remote = null;
|
private string remote = null;
|
||||||
|
private Action finishHandler = null;
|
||||||
|
|
||||||
public DeleteBranch(string repo, string branch, string remote = null) {
|
public DeleteBranch(string repo, string branch, string remote = null) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
@ -20,6 +22,11 @@ namespace SourceGit.Views.Popups {
|
||||||
else txtTarget.Text = $"{remote}/{branch}";
|
else txtTarget.Text = $"{remote}/{branch}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DeleteBranch Then(Action handler) {
|
||||||
|
this.finishHandler = handler;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public override string GetTitle() {
|
public override string GetTitle() {
|
||||||
return App.Text("DeleteBranch");
|
return App.Text("DeleteBranch");
|
||||||
}
|
}
|
||||||
|
@ -41,7 +48,8 @@ namespace SourceGit.Views.Popups {
|
||||||
if (exists != null && exists.Filters.Contains(full)) {
|
if (exists != null && exists.Filters.Contains(full)) {
|
||||||
exists.Filters.Remove(full);
|
exists.Filters.Remove(full);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finishHandler?.Invoke();
|
||||||
Models.Watcher.SetEnabled(repo, true);
|
Models.Watcher.SetEnabled(repo, true);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
|
|
||||||
var watcher = Models.Watcher.Get(repo.Path);
|
var watcher = Models.Watcher.Get(repo.Path);
|
||||||
watcher.Navigate += NavigateTo;
|
watcher.Navigate += NavigateTo;
|
||||||
watcher.BranchChanged += UpdateBraches;
|
watcher.BranchChanged += UpdateBranches;
|
||||||
watcher.BranchChanged += UpdateCommits;
|
watcher.BranchChanged += UpdateCommits;
|
||||||
watcher.WorkingCopyChanged += UpdateWorkingCopy;
|
watcher.WorkingCopyChanged += UpdateWorkingCopy;
|
||||||
watcher.StashChanged += UpdateStashes;
|
watcher.StashChanged += UpdateStashes;
|
||||||
|
@ -94,7 +94,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
|
|
||||||
#region DATA
|
#region DATA
|
||||||
public void Refresh() {
|
public void Refresh() {
|
||||||
UpdateBraches();
|
UpdateBranches();
|
||||||
UpdateWorkingCopy();
|
UpdateWorkingCopy();
|
||||||
UpdateStashes();
|
UpdateStashes();
|
||||||
UpdateTags();
|
UpdateTags();
|
||||||
|
@ -190,7 +190,7 @@ namespace SourceGit.Views.Widgets {
|
||||||
foreach (var node in nodes) SortBranches(node.Children);
|
foreach (var node in nodes) SortBranches(node.Children);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateBraches() {
|
private void UpdateBranches() {
|
||||||
if (!isFirstLoaded) return;
|
if (!isFirstLoaded) return;
|
||||||
|
|
||||||
Task.Run(() => {
|
Task.Run(() => {
|
||||||
|
@ -669,12 +669,22 @@ namespace SourceGit.Views.Widgets {
|
||||||
if (branch.Upstream == b.FullName) target.Icon = currentTrackingIcon;
|
if (branch.Upstream == b.FullName) target.Icon = currentTrackingIcon;
|
||||||
target.Click += (o, e) => {
|
target.Click += (o, e) => {
|
||||||
new Commands.Branch(repo.Path, branch.Name).SetUpstream(upstream);
|
new Commands.Branch(repo.Path, branch.Name).SetUpstream(upstream);
|
||||||
UpdateBraches();
|
UpdateBranches();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
tracking.Items.Add(target);
|
tracking.Items.Add(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var unsetUpstream = new MenuItem();
|
||||||
|
unsetUpstream.Header = App.Text("BranchCM.UnsetUpstream");
|
||||||
|
unsetUpstream.Click += (_, e) => {
|
||||||
|
new Commands.Branch(repo.Path, branch.Name).SetUpstream(string.Empty);
|
||||||
|
UpdateBranches();
|
||||||
|
e.Handled = true;
|
||||||
|
};
|
||||||
|
tracking.Items.Add(new Separator());
|
||||||
|
tracking.Items.Add(unsetUpstream);
|
||||||
|
|
||||||
menu.Items.Add(tracking);
|
menu.Items.Add(tracking);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -784,7 +794,12 @@ namespace SourceGit.Views.Widgets {
|
||||||
var delete = new MenuItem();
|
var delete = new MenuItem();
|
||||||
delete.Header = App.Text("BranchCM.Delete", branch.Name);
|
delete.Header = App.Text("BranchCM.Delete", branch.Name);
|
||||||
delete.Click += (o, e) => {
|
delete.Click += (o, e) => {
|
||||||
new Popups.DeleteBranch(repo.Path, branch.Name, branch.Remote).Show();
|
new Popups.DeleteBranch(repo.Path, branch.Name, branch.Remote)
|
||||||
|
.Then(() => {
|
||||||
|
repo.Branches.FindAll(item => item.Upstream == branch.FullName).ForEach(item =>
|
||||||
|
new Commands.Branch(repo.Path, item.Name).SetUpstream(string.Empty));
|
||||||
|
})
|
||||||
|
.Show();
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue