-
Notifications
You must be signed in to change notification settings - Fork 498
Expand file tree
/
Copy pathFetchInto.cs
More file actions
67 lines (54 loc) · 1.88 KB
/
Copy pathFetchInto.cs
File metadata and controls
67 lines (54 loc) · 1.88 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
using System;
using System.Threading;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class FetchInto : Popup
{
public Models.Branch Local
{
get;
}
public Models.Branch Upstream
{
get;
}
public FetchInto(Repository repo, Models.Branch local, Models.Branch upstream)
{
_repo = repo;
_remote = repo.Remotes.Find(x => x.Name.Equals(upstream.Remote, StringComparison.Ordinal));
Local = local;
Upstream = upstream;
CanTerminate = true;
}
public override async Task<bool> Sure()
{
using var lockWatcher = _repo.LockWatcher();
ProgressDescription = "Fast-Forward ...";
var log = _repo.CreateLog($"Fetch Into '{Local.FriendlyName}'");
Use(log);
_cancellation = new CancellationTokenSource();
var token = _cancellation.Token;
await new Commands.Fetch(_repo.FullPath, _remote, Upstream, Local)
.WithCancellation(token)
.Use(log)
.ExecAsync();
log.Complete();
if (_repo.SelectedViewIndex == 0 && !token.IsCancellationRequested)
{
var newHead = await new Commands.QueryRevisionByRefName(_repo.FullPath, Local.Name).GetResultAsync();
_repo.NavigateToCommit(newHead, true);
}
_cancellation = null;
return true;
}
public override void Terminate()
{
// Just fire cancel event and UI will auto wait the `Sure` complete
var _ = _cancellation?.CancelAsync();
}
private readonly Repository _repo = null;
private readonly Models.Remote _remote = null;
private CancellationTokenSource _cancellation = null;
}
}