-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathgit-flow.ts
183 lines (177 loc) · 4.77 KB
/
git-flow.ts
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
const postProcessBranches: Fig.Generator["postProcess"] = (out, tokens) => {
return out
.split("\n")
.map((elm) => {
let name = elm.trim();
if (name.startsWith("*") || name.startsWith("+")) {
name = name.slice(2);
}
const prefixTypeBranch = tokens[0];
if (!name.startsWith(prefixTypeBranch)) {
return {};
}
return {
name: name.replace(prefixTypeBranch, ""),
description: `${prefixTypeBranch.replace("/", "")} branch`,
icon: "fig://icon?type=git",
};
})
.filter((x) => x.name);
};
async function getGitFlowPrefix(
type: string,
executeShellCommand: Fig.ExecuteCommandFunction
): Promise<string> {
const { stdout } = await executeShellCommand({
command: "git",
args: ["config", "--get", `gitflow.prefix.${type}`],
});
return stdout;
}
export const gitFlowGenerators: Record<string, Fig.Generator> = {
typeBranches: {
custom: async (tokens, executeShellCommand) => {
const prefix = await getGitFlowPrefix(tokens[1], executeShellCommand);
const { stdout } = await executeShellCommand({
command: "git",
args: [
"--no-optional-locks",
"branch",
"-a",
"--no-color",
"--sort=-committerdate",
],
});
return postProcessBranches(stdout, [prefix]);
},
},
};
const completionSpec: Fig.Spec = {
name: "git-flow",
description:
"A collection of Git extensions to provide high-level repository operations for Vincent Driessen's branching model",
subcommands: [
{
name: "init",
description:
"Initialize a new git repo with support for the branching model",
options: [
{
name: "-d",
description: "Use default branch naming conventions",
},
{
name: "-f",
description:
"Force setting of gitflow branches, even if already configured",
},
],
},
{
name: "feature",
description: "List all feature branches",
subcommands: [
{
name: "start",
description: "Create a new feature branch",
args: {
name: "name",
description: "The name of the new feature branch",
},
},
{
name: "finish",
description: "Merge a feature branch into develop",
args: {
name: "name",
description: "The name of the feature branch to finish",
generators: gitFlowGenerators.typeBranches,
},
},
{
name: "publish",
description: "Push a feature branch to the remote repository",
args: {
name: "name",
description: "The name of the feature branch to publish",
},
},
{
name: "pull",
description: "Pull a feature branch from the remote repository",
args: [
{
name: "origin",
description: "The name of the remote feature branch",
},
{
name: "name",
description: "The name of the local feature branch",
},
],
},
],
},
{
name: "release",
description: "List all release branches",
subcommands: [
{
name: "start",
description: "Create a new release branch",
args: {
name: "name",
description: "The name of the new release branch",
},
},
{
name: "finish",
description: "Merge a release branch into develop",
args: {
name: "name",
description: "The name of the release branch to finish",
generators: gitFlowGenerators.typeBranches,
},
},
],
},
{
name: "hotfix",
description: "List all hotfix branches",
subcommands: [
{
name: "start",
description: "Create a new hotfix branch",
args: {
name: "name",
description: "The name of the new hotfix branch",
},
},
{
name: "finish",
description: "Merge a hotfix branch into develop",
args: {
name: "name",
description: "The name of the hotfix branch to finish",
generators: gitFlowGenerators.typeBranches,
},
},
],
},
{
name: "support",
description: "List all support branches",
subcommands: [
{
name: "start",
description: "Create a new support branch",
args: {
name: "name",
description: "The name of the new support branch",
},
},
],
},
],
};
export default completionSpec;