mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
80 lines
2.4 KiB
C#
80 lines
2.4 KiB
C#
using System.Threading.Tasks;
|
|
|
|
namespace SourceGit.ViewModels
|
|
{
|
|
public class DeleteBranch : Popup
|
|
{
|
|
public Models.Branch Target
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
public Models.Branch TrackingRemoteBranch
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
public object DeleteTrackingRemoteTip
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
public bool AlsoDeleteTrackingRemote
|
|
{
|
|
get => _alsoDeleteTrackingRemote;
|
|
set => SetProperty(ref _alsoDeleteTrackingRemote, value);
|
|
}
|
|
|
|
public DeleteBranch(Repository repo, Models.Branch branch)
|
|
{
|
|
_repo = repo;
|
|
Target = branch;
|
|
|
|
if (branch.IsLocal && !string.IsNullOrEmpty(branch.Upstream))
|
|
{
|
|
TrackingRemoteBranch = repo.Branches.Find(x => x.FullName == branch.Upstream);
|
|
if (TrackingRemoteBranch != null)
|
|
DeleteTrackingRemoteTip = new Views.NameHighlightedTextBlock("DeleteBranch.WithTrackingRemote", TrackingRemoteBranch.FriendlyName);
|
|
}
|
|
|
|
View = new Views.DeleteBranch() { DataContext = this };
|
|
}
|
|
|
|
public override Task<bool> Sure()
|
|
{
|
|
_repo.SetWatcherEnabled(false);
|
|
ProgressDescription = "Deleting branch...";
|
|
|
|
return Task.Run(() =>
|
|
{
|
|
if (Target.IsLocal)
|
|
{
|
|
Commands.Branch.DeleteLocal(_repo.FullPath, Target.Name);
|
|
|
|
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
|
|
{
|
|
SetProgressDescription("Deleting tracking remote branch...");
|
|
Commands.Branch.DeleteRemote(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Commands.Branch.DeleteRemote(_repo.FullPath, Target.Remote, Target.Name);
|
|
}
|
|
|
|
CallUIThread(() =>
|
|
{
|
|
_repo.MarkBranchesDirtyManually();
|
|
_repo.SetWatcherEnabled(true);
|
|
});
|
|
return true;
|
|
});
|
|
}
|
|
|
|
private readonly Repository _repo = null;
|
|
private bool _alsoDeleteTrackingRemote = false;
|
|
}
|
|
}
|