forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetUpstream.cs
More file actions
78 lines (65 loc) · 2.07 KB
/
Copy pathSetUpstream.cs
File metadata and controls
78 lines (65 loc) · 2.07 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
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class SetUpstream : Popup
{
public Models.Branch Local
{
get;
}
public List<Models.Branch> RemoteBranches
{
get;
private set;
}
public Models.Branch SelectedRemoteBranch
{
get;
set;
}
public bool Unset
{
get => _unset;
set => SetProperty(ref _unset, value);
}
public SetUpstream(Repository repo, Models.Branch local, List<Models.Branch> remoteBranches)
{
_repo = repo;
Local = local;
RemoteBranches = remoteBranches;
Unset = false;
if (!string.IsNullOrEmpty(local.Upstream))
{
var upstream = remoteBranches.Find(x => x.FullName == local.Upstream);
if (upstream != null)
SelectedRemoteBranch = upstream;
}
if (SelectedRemoteBranch == null)
{
var upstream = remoteBranches.Find(x => x.Name == local.Name);
if (upstream != null)
SelectedRemoteBranch = upstream;
}
}
public override Task<bool> Sure()
{
ProgressDescription = "Setting upstream...";
var upstream = (_unset || SelectedRemoteBranch == null) ? string.Empty : SelectedRemoteBranch.FullName;
if (upstream == Local.Upstream)
return null;
var log = _repo.CreateLog("Set Upstream");
Use(log);
return Task.Run(() =>
{
var succ = Commands.Branch.SetUpstream(_repo.FullPath, Local.Name, upstream.Replace("refs/remotes/", ""), log);
if (succ)
_repo.RefreshBranches();
log.Complete();
return true;
});
}
private readonly Repository _repo;
private bool _unset = false;
}
}