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))
|
|
|
|
|
{
|
|
|
|
|
var upstream = branch.Upstream.Substring(13);
|
|
|
|
|
TrackingRemoteBranch = repo.Branches.Find(x => !x.IsLocal && $"{x.Remote}/{x.Name}" == upstream);
|
|
|
|
|
DeleteTrackingRemoteTip = new Views.NameHighlightedTextBlock("DeleteBranch.WithTrackingRemote", upstream);
|
|
|
|
|
}
|
|
|
|
|
|
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-02-05 23:08:37 -08:00
|
|
|
|
Commands.Branch.Delete(_repo.FullPath, Target.Name);
|
2024-05-05 04:45:28 -07:00
|
|
|
|
|
|
|
|
|
if (_alsoDeleteTrackingRemote && TrackingRemoteBranch != null)
|
|
|
|
|
new Commands.Push(_repo.FullPath, TrackingRemoteBranch.Remote, TrackingRemoteBranch.Name).Exec();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
new Commands.Push(_repo.FullPath, Target.Remote, Target.Name).Exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|