2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class DeleteBranch : Popup
|
|
|
|
|
{
|
|
|
|
|
public Models.Branch Target
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 04:45:28 -07:00
|
|
|
|
public Models.Branch TrackingRemoteBranch
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object DeleteTrackingRemoteTip
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
private set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool AlsoDeleteTrackingRemote
|
|
|
|
|
{
|
|
|
|
|
get => _alsoDeleteTrackingRemote;
|
|
|
|
|
set => SetProperty(ref _alsoDeleteTrackingRemote, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public DeleteBranch(Repository repo, Models.Branch branch)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo = repo;
|
|
|
|
|
Target = branch;
|
2024-05-05 04:45:28 -07:00
|
|
|
|
|
|
|
|
|
if (branch.IsLocal && !string.IsNullOrEmpty(branch.Upstream))
|
|
|
|
|
{
|
2024-07-01 19:23:21 -07:00
|
|
|
|
TrackingRemoteBranch = repo.Branches.Find(x => x.FullName == branch.Upstream);
|
2024-07-04 01:47:28 -07:00
|
|
|
|
if (TrackingRemoteBranch != null)
|
|
|
|
|
DeleteTrackingRemoteTip = new Views.NameHighlightedTextBlock("DeleteBranch.WithTrackingRemote", TrackingRemoteBranch.FriendlyName);
|
2024-05-05 04:45:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 23:08:37 -08:00
|
|
|
|
View = new Views.DeleteBranch() { DataContext = this };
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public override Task<bool> Sure()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_repo.SetWatcherEnabled(false);
|
2024-02-25 19:29:57 -08:00
|
|
|
|
ProgressDescription = "Deleting branch...";
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
return Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
if (Target.IsLocal)
|
|
|
|
|
{
|
2024-05-20 18:58:06 -07:00
|
|
|
|
Commands.Branch.DeleteLocal(_repo.FullPath, Target.Name);
|
2024-05-05 04:45:28 -07:00
|
|
|
|
|
|
|
|
|
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
|
2024-05-20 18:58:06 -07:00
|
|
|
|
{
|
|
|
|
|
SetProgressDescription("Deleting tracking remote branch...");
|
|
|
|
|
Commands.Branch.DeleteRemote(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name);
|
2024-06-06 00:31:02 -07:00
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-05-20 18:58:06 -07:00
|
|
|
|
Commands.Branch.DeleteRemote(_repo.FullPath, Target.Remote, Target.Name);
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
|
|
|
|
return true;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
private readonly Repository _repo = null;
|
2024-05-05 04:45:28 -07:00
|
|
|
|
private bool _alsoDeleteTrackingRemote = false;
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|