forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckoutAndFastForward.cs
More file actions
111 lines (91 loc) · 3.51 KB
/
Copy pathCheckoutAndFastForward.cs
File metadata and controls
111 lines (91 loc) · 3.51 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class CheckoutAndFastForward : Popup
{
public Models.Branch LocalBranch
{
get;
}
public Models.Branch RemoteBranch
{
get;
}
public bool DiscardLocalChanges
{
get;
set;
}
public bool IsRecurseSubmoduleVisible
{
get => _repo.Submodules.Count > 0;
}
public bool RecurseSubmodules
{
get => _repo.Settings.UpdateSubmodulesOnCheckoutBranch;
set => _repo.Settings.UpdateSubmodulesOnCheckoutBranch = value;
}
public CheckoutAndFastForward(Repository repo, Models.Branch localBranch, Models.Branch remoteBranch)
{
_repo = repo;
LocalBranch = localBranch;
RemoteBranch = remoteBranch;
}
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
ProgressDescription = $"Checkout and Fast-Forward '{LocalBranch.Name}' ...";
var log = _repo.CreateLog($"Checkout and Fast-Forward '{LocalBranch.Name}' ...");
Use(log);
var updateSubmodules = IsRecurseSubmoduleVisible && RecurseSubmodules;
return Task.Run(() =>
{
var succ = false;
var needPopStash = false;
if (DiscardLocalChanges)
{
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBranch.Head, true, true);
}
else
{
var changes = new Commands.CountLocalChangesWithoutUntracked(_repo.FullPath).Result();
if (changes > 0)
{
succ = new Commands.Stash(_repo.FullPath).Use(log).Push("CHECKOUT_AND_FASTFORWARD_AUTO_STASH");
if (!succ)
{
log.Complete();
CallUIThread(() => _repo.SetWatcherEnabled(true));
return false;
}
needPopStash = true;
}
succ = new Commands.Checkout(_repo.FullPath).Use(log).Branch(LocalBranch.Name, RemoteBranch.Head, false, true);
}
if (succ)
{
if (updateSubmodules)
{
var submodules = new Commands.QueryUpdatableSubmodules(_repo.FullPath).Result();
if (submodules.Count > 0)
new Commands.Submodule(_repo.FullPath).Use(log).Update(submodules, true, true);
}
if (needPopStash)
new Commands.Stash(_repo.FullPath).Use(log).Pop("stash@{0}");
}
log.Complete();
CallUIThread(() =>
{
ProgressDescription = "Waiting for branch updated...";
if (_repo.HistoriesFilterMode == Models.FilterMode.Included)
_repo.SetBranchFilterMode(LocalBranch, Models.FilterMode.Included, true, false);
_repo.MarkBranchesDirtyManually();
_repo.SetWatcherEnabled(true);
});
Task.Delay(400).Wait();
return succ;
});
}
private Repository _repo;
}
}