-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathCherryPick.cs
103 lines (90 loc) · 2.6 KB
/
CherryPick.cs
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
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class CherryPick : Popup
{
public List<Models.Commit> Targets
{
get;
private set;
}
public bool IsMergeCommit
{
get;
private set;
}
public List<Models.Commit> ParentsForMergeCommit
{
get;
private set;
}
public int MainlineForMergeCommit
{
get;
set;
}
public bool AppendSourceToMessage
{
get;
set;
}
public bool AutoCommit
{
get;
set;
}
public CherryPick(Repository repo, List<Models.Commit> targets)
{
_repo = repo;
Targets = targets;
IsMergeCommit = false;
ParentsForMergeCommit = [];
MainlineForMergeCommit = 0;
AppendSourceToMessage = true;
AutoCommit = true;
}
public CherryPick(Repository repo, Models.Commit merge, List<Models.Commit> parents)
{
_repo = repo;
Targets = [merge];
IsMergeCommit = true;
ParentsForMergeCommit = parents;
MainlineForMergeCommit = 0;
AppendSourceToMessage = true;
AutoCommit = true;
}
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
ProgressDescription = $"Cherry-Pick commit(s) ...";
var log = _repo.CreateLog("Cherry-Pick");
Use(log);
return Task.Run(() =>
{
if (IsMergeCommit)
{
new Commands.CherryPick(
_repo.FullPath,
Targets[0].SHA,
!AutoCommit,
AppendSourceToMessage,
$"-m {MainlineForMergeCommit + 1}").Use(log).Exec();
}
else
{
new Commands.CherryPick(
_repo.FullPath,
string.Join(' ', Targets.ConvertAll(c => c.SHA)),
!AutoCommit,
AppendSourceToMessage,
string.Empty).Use(log).Exec();
}
log.Complete();
CallUIThread(() => _repo.SetWatcherEnabled(true));
return true;
});
}
private readonly Repository _repo = null;
}
}