-
Notifications
You must be signed in to change notification settings - Fork 498
Expand file tree
/
Copy pathPushRevision.cs
More file actions
68 lines (56 loc) · 1.77 KB
/
Copy pathPushRevision.cs
File metadata and controls
68 lines (56 loc) · 1.77 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
using System;
using System.Threading;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class PushRevision : Popup
{
public Models.Commit Revision
{
get;
}
public Models.Branch RemoteBranch
{
get;
}
public bool Force
{
get;
set;
}
public PushRevision(Repository repo, Models.Commit revision, Models.Branch remoteBranch)
{
_repo = repo;
Revision = revision;
RemoteBranch = remoteBranch;
Force = false;
CanTerminate = true;
}
public override async Task<bool> Sure()
{
using var lockWatcher = _repo.LockWatcher();
ProgressDescription = $"Push {Revision.SHA.AsSpan(0, 10)} -> {RemoteBranch.FriendlyName} ...";
var log = _repo.CreateLog("Push Revision");
Use(log);
_cancellation = new CancellationTokenSource();
var token = _cancellation.Token;
var remote = _repo.Remotes.Find(x => x.Name.Equals(RemoteBranch.Name, StringComparison.Ordinal));
var succ = await new Commands.Push(
_repo.FullPath,
Revision,
remote,
RemoteBranch,
Force).WithCancellation(token).Use(log).ExecAsync();
log.Complete();
_cancellation = null;
return succ;
}
public override void Terminate()
{
// Just fire cancel event and UI will auto wait the `Sure` complete
var _ = _cancellation?.CancelAsync();
}
private readonly Repository _repo;
private CancellationTokenSource _cancellation = null;
}
}