-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy pathCheckoutCommit.cs
More file actions
104 lines (89 loc) · 3.13 KB
/
CheckoutCommit.cs
File metadata and controls
104 lines (89 loc) · 3.13 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
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class CheckoutCommit : Popup
{
public Models.Commit Commit
{
get;
}
public bool HasLocalChanges
{
get => _repo.LocalChangesCount > 0;
}
public Models.DealWithLocalChanges DealWithLocalChanges
{
get;
set;
}
public CheckoutCommit(Repository repo, Models.Commit commit)
{
_repo = repo;
Commit = commit;
DealWithLocalChanges = Models.DealWithLocalChanges.DoNothing;
}
public override async Task<bool> Sure()
{
using var lockWatcher = _repo.LockWatcher();
ProgressDescription = $"Checkout Commit '{Commit.SHA}' ...";
var log = _repo.CreateLog("Checkout Commit");
Use(log);
if (_repo.CurrentBranch is { IsDetachedHead: true })
{
var refs = await new Commands.QueryRefsContainsCommit(_repo.FullPath, _repo.CurrentBranch.Head).GetResultAsync();
if (refs.Count == 0)
{
var msg = App.Text("Checkout.WarnLostCommits");
var shouldContinue = await App.AskConfirmAsync(msg);
if (!shouldContinue)
return true;
}
}
var succ = false;
var needPop = false;
if (DealWithLocalChanges == Models.DealWithLocalChanges.DoNothing)
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.CommitAsync(Commit.SHA, false);
}
else if (DealWithLocalChanges == Models.DealWithLocalChanges.StashAndReapply)
{
var changes = await new Commands.CountLocalChanges(_repo.FullPath, false).GetResultAsync();
if (changes > 0)
{
succ = await new Commands.Stash(_repo.FullPath)
.Use(log)
.PushAsync("CHECKOUT_AUTO_STASH", false);
if (!succ)
{
log.Complete();
_repo.MarkWorkingCopyDirtyManually();
return false;
}
needPop = true;
}
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.CommitAsync(Commit.SHA, false);
}
else
{
succ = await new Commands.Checkout(_repo.FullPath)
.Use(log)
.CommitAsync(Commit.SHA, true);
}
if (succ)
{
await _repo.AutoUpdateSubmodulesAsync(log);
if (needPop)
await new Commands.Stash(_repo.FullPath)
.Use(log)
.PopAsync("stash@{0}");
}
log.Complete();
return succ;
}
private readonly Repository _repo = null;
}
}