2021-04-29 05:05:55 -07:00
|
|
|
namespace SourceGit.Commands {
|
|
|
|
/// <summary>
|
|
|
|
/// Git-Flow命令
|
|
|
|
/// </summary>
|
|
|
|
public class GitFlow : Command {
|
|
|
|
|
|
|
|
public GitFlow(string repo) {
|
|
|
|
Cwd = repo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Init(string master, string develop, string feature, string release, string hotfix, string version) {
|
|
|
|
var branches = new Branches(Cwd).Result();
|
|
|
|
var current = branches.Find(x => x.IsCurrent);
|
|
|
|
|
|
|
|
var masterBranch = branches.Find(x => x.Name == master);
|
|
|
|
if (masterBranch == null) new Branch(Cwd, master).Create(current.Head);
|
|
|
|
|
|
|
|
var devBranch = branches.Find(x => x.Name == develop);
|
|
|
|
if (devBranch == null) new Branch(Cwd, develop).Create(current.Head);
|
|
|
|
|
|
|
|
var cmd = new Config(Cwd);
|
|
|
|
cmd.Set("gitflow.branch.master", master);
|
|
|
|
cmd.Set("gitflow.branch.develop", develop);
|
|
|
|
cmd.Set("gitflow.prefix.feature", feature);
|
|
|
|
cmd.Set("gitflow.prefix.bugfix", "bugfix/");
|
|
|
|
cmd.Set("gitflow.prefix.release", release);
|
|
|
|
cmd.Set("gitflow.prefix.hotfix", hotfix);
|
|
|
|
cmd.Set("gitflow.prefix.support", "support/");
|
|
|
|
cmd.Set("gitflow.prefix.versiontag", version, true);
|
|
|
|
|
|
|
|
Args = "flow init -d";
|
|
|
|
return Exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Start(Models.GitFlowBranchType type, string name) {
|
|
|
|
switch (type) {
|
|
|
|
case Models.GitFlowBranchType.Feature:
|
|
|
|
Args = $"flow feature start {name}";
|
|
|
|
break;
|
|
|
|
case Models.GitFlowBranchType.Release:
|
|
|
|
Args = $"flow release start {name}";
|
|
|
|
break;
|
|
|
|
case Models.GitFlowBranchType.Hotfix:
|
|
|
|
Args = $"flow hotfix start {name}";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exec();
|
|
|
|
}
|
|
|
|
|
2021-05-13 00:31:10 -07:00
|
|
|
public void Finish(Models.GitFlowBranchType type, string name, bool keepBranch) {
|
|
|
|
var option = keepBranch ? "-k" : string.Empty;
|
2021-04-29 05:05:55 -07:00
|
|
|
switch (type) {
|
|
|
|
case Models.GitFlowBranchType.Feature:
|
2021-05-13 00:31:10 -07:00
|
|
|
Args = $"flow feature finish {option} {name}";
|
2021-04-29 05:05:55 -07:00
|
|
|
break;
|
|
|
|
case Models.GitFlowBranchType.Release:
|
2021-05-13 00:31:10 -07:00
|
|
|
Args = $"flow release finish {option} {name}";
|
2021-04-29 05:05:55 -07:00
|
|
|
break;
|
|
|
|
case Models.GitFlowBranchType.Hotfix:
|
2021-05-13 00:31:10 -07:00
|
|
|
Args = $"flow hotfix finish {option} {name}";
|
2021-04-29 05:05:55 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|