forked from sourcegit-scm/sourcegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRebase.cs
More file actions
128 lines (108 loc) · 3.35 KB
/
Copy pathRebase.cs
File metadata and controls
128 lines (108 loc) · 3.35 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Threading.Tasks;
using Avalonia.Threading;
namespace SourceGit.ViewModels
{
public enum RebaseTestingState
{
Disabled = 0,
Testing,
WillCauseConflicts,
UnknownError,
NoConflicts,
}
public class Rebase : Popup
{
public Models.Branch Current
{
get;
private set;
}
public object On
{
get;
private set;
}
public bool AutoStash
{
get;
set;
}
public bool NoVerify
{
get;
set;
}
public RebaseTestingState TestingState
{
get => _testingState;
private set => SetProperty(ref _testingState, value);
}
public Rebase(Repository repo, Models.Branch current, Models.Branch on)
{
_repo = repo;
_revision = on.Head;
Current = current;
On = on;
AutoStash = true;
Test();
}
public Rebase(Repository repo, Models.Branch current, Models.Commit on)
{
_repo = repo;
_revision = on.SHA;
Current = current;
On = on;
AutoStash = true;
Test();
}
public override async Task<bool> Sure()
{
using var lockWatcher = _repo.LockWatcher();
_repo.ClearCommitMessage();
ProgressDescription = "Rebasing ...";
var log = _repo.CreateLog("Rebase");
Use(log);
await new Commands.Rebase(_repo.FullPath, _revision, AutoStash, NoVerify)
.Use(log)
.ExecAsync();
log.Complete();
return true;
}
private void Test()
{
if (Native.OS.GitVersion < Models.GitVersions.REPLAY)
return;
var head = Current.Head;
TestingState = RebaseTestingState.Testing;
Task.Run(async () =>
{
var mergeBase = await new Commands.MergeBase(_repo.FullPath, head, _revision)
.GetResultAsync()
.ConfigureAwait(false);
if (string.IsNullOrEmpty(mergeBase))
{
Dispatcher.UIThread.Post(() => TestingState = RebaseTestingState.UnknownError);
return;
}
else if (head.Equals(mergeBase, StringComparison.Ordinal))
{
Dispatcher.UIThread.Post(() => TestingState = RebaseTestingState.NoConflicts);
return;
}
var exitCode = await new Commands.Replay(_repo.FullPath, _revision, $"{mergeBase}..{head}")
.GetExitCodeAsync()
.ConfigureAwait(false);
Dispatcher.UIThread.Post(() => TestingState = exitCode switch
{
0 => RebaseTestingState.NoConflicts,
1 => RebaseTestingState.WillCauseConflicts,
_ => RebaseTestingState.UnknownError,
});
});
}
private readonly Repository _repo;
private readonly string _revision;
private RebaseTestingState _testingState = RebaseTestingState.Disabled;
}
}