-
Notifications
You must be signed in to change notification settings - Fork 391
Expand file tree
/
Copy pathGitFlow.cs
More file actions
82 lines (72 loc) · 3.29 KB
/
GitFlow.cs
File metadata and controls
82 lines (72 loc) · 3.29 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
using System.Text;
using System.Threading.Tasks;
namespace SourceGit.Commands
{
public static class GitFlow
{
public static async Task<bool> InitAsync(string repo, string master, string develop, string feature, string release, string hotfix, string version, Models.ICommandLog log)
{
var config = new Config(repo);
await config.SetAsync("gitflow.branch.master", master).ConfigureAwait(false);
await config.SetAsync("gitflow.branch.develop", develop).ConfigureAwait(false);
await config.SetAsync("gitflow.prefix.feature", feature).ConfigureAwait(false);
await config.SetAsync("gitflow.prefix.bugfix", "bugfix/").ConfigureAwait(false);
await config.SetAsync("gitflow.prefix.release", release).ConfigureAwait(false);
await config.SetAsync("gitflow.prefix.hotfix", hotfix).ConfigureAwait(false);
await config.SetAsync("gitflow.prefix.support", "support/").ConfigureAwait(false);
await config.SetAsync("gitflow.prefix.versiontag", version, true).ConfigureAwait(false);
var init = new Command();
init.WorkingDirectory = repo;
init.Context = repo;
init.Args = "flow init -d";
return await init.Use(log).ExecAsync().ConfigureAwait(false);
}
public static async Task<bool> StartAsync(string repo, Models.GitFlowBranchType type, string name, Models.ICommandLog log)
{
var start = new Command();
start.WorkingDirectory = repo;
start.Context = repo;
var typeStr = BranchTypeToString(type);
if (typeStr == null)
{
App.RaiseException(repo, "Bad git-flow branch type!!!");
return false;
}
start.Args = $"flow {typeStr} start {name}";
return await start.Use(log).ExecAsync().ConfigureAwait(false);
}
public static async Task<bool> FinishAsync(string repo, Models.GitFlowBranchType type, string name, bool squash, bool push, bool keepBranch, Models.ICommandLog log)
{
var builder = new StringBuilder();
builder.Append("flow ");
var typeStr = BranchTypeToString(type);
if (typeStr == null)
{
App.RaiseException(repo, "Bad git-flow branch type!!!");
return false;
}
builder.Append(typeStr);
builder.Append(" finish ");
if (squash)
builder.Append("--squash ");
if (push)
builder.Append("--push ");
if (keepBranch)
builder.Append("-k ");
builder.Append(name);
var finish = new Command();
finish.WorkingDirectory = repo;
finish.Context = repo;
finish.Args = builder.ToString();
return await finish.Use(log).ExecAsync().ConfigureAwait(false);
}
private static string BranchTypeToString(Models.GitFlowBranchType type) =>
type switch
{
Models.GitFlowBranchType.Feature => "feature",
Models.GitFlowBranchType.Release => "release",
Models.GitFlowBranchType.Hotfix => "hotfix",
_ => null
};
}
}