-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy pathDeleteMultipleBranches.cs
More file actions
59 lines (52 loc) · 1.81 KB
/
DeleteMultipleBranches.cs
File metadata and controls
59 lines (52 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class DeleteMultipleBranches : Popup
{
public List<Models.Branch> Targets
{
get;
}
public DeleteMultipleBranches(Repository repo, List<Models.Branch> branches, bool isLocal)
{
_repo = repo;
_isLocal = isLocal;
Targets = branches;
}
public override async Task<bool> Sure()
{
using var lockWatcher = _repo.LockWatcher();
ProgressDescription = "Deleting multiple branches...";
var log = _repo.CreateLog("Delete Multiple Branches");
Use(log);
if (_isLocal)
{
foreach (var target in Targets)
await new Commands.Branch(_repo.FullPath, target.Name)
.Use(log)
.DeleteLocalAsync();
}
else
{
foreach (var target in Targets)
{
var exists = await new Commands.Remote(_repo.FullPath).HasBranchAsync(target.Remote, target.Name);
if (exists)
await new Commands.Push(_repo.FullPath, target.Remote, $"refs/heads/{target.Name}", true)
.Use(log)
.RunAsync();
else
await new Commands.Branch(_repo.FullPath, target.Name)
.Use(log)
.DeleteRemoteAsync(target.Remote);
}
}
log.Complete();
_repo.MarkBranchesDirtyManually();
return true;
}
private Repository _repo = null;
private bool _isLocal = false;
}
}