Repository navigation
Expand file tree
/
Copy pathDeleteMultipleBranches.cs
More file actions
80 lines (70 loc) · 2.38 KB
/
Copy pathDeleteMultipleBranches.cs
File metadata and controls
80 lines (70 loc) · 2.38 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class DeleteMultipleBranches : Popup
{
public List<Models.Branch> Targets
{
get;
}
public bool Force
{
get;
set;
} = false;
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(Force);
}
else
{
foreach (var target in Targets)
await DeleteRemoteBranchAsync(target, log);
}
log.Complete();
_repo.MarkBranchesDirtyManually();
return true;
}
private async Task<bool> DeleteRemoteBranchAsync(Models.Branch branch, CommandLog log)
{
var exists = false;
var remote = _repo.Remotes.Find(x => x.Name.Equals(branch.Remote, StringComparison.Ordinal));
if (remote != null)
{
exists = await new Commands.DoesBranchExistOnRemote(_repo.FullPath, remote, branch)
.Use(log)
.GetResultAsync()
.ConfigureAwait(false);
}
if (exists)
return await new Commands.Push(_repo.FullPath, remote, $"refs/heads/{branch.Name}", true)
.Use(log)
.ExecAsync()
.ConfigureAwait(false);
else
return await new Commands.Branch(_repo.FullPath, branch.Name)
.Use(log)
.DeleteRemoteAsync(branch.Remote, Force)
.ConfigureAwait(false);
}
private Repository _repo = null;
private bool _isLocal = false;
}
}