-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow
executable file
·272 lines (227 loc) · 5.04 KB
/
flow
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/sh
die() {
echo "$1"
exit 1
}
first="$1"
second="$2"
set -euf pipefail
DEVELOP="develop"
CANDIDATE="candidate"
MAIN="main"
help() {
cat <<HELPTEXT
Usage: flow (feature_start|feature_finish
|release_start|release_finish
|hotfix_start|hotfix_finish) [branchname]
This script attempts to follow the cactus model / threeflow
https://www.nomachetejuggling.com/2017/04/09/a-different-branching-strategy/
(init):
Creates the original 3 branches: develop, candidate and main
(fs|feature_start) [branchname]:
This will create the specified feature branch off of develop
(ff|feature_finish) [branchname]:
This will merge the specified feature branch back into develop
(rs|release_start):
This will start a new release by merging the develop branch into candidate.
It will tag the place where it diverges from develop.
(rf|release_finish):
This will tag the release, and merge the candidate branch into BOTH develop and main.
The merge to develop will be a --no-ff, and the merge to main will be a fastforward.
(hs|hotfix_start) [branchname]:
This will start a hotfix branch off of the main branch.
It will tag the place where it diverges from main.
Since hotfix branches are temporary, they do not have a static name.
(hf|hotfix_finish) [branchname]:
This will tag the hotfix, and merge it into main, candidate, and develop.
(view)
Shows the current state of git, within the terminal.
-------------------------------------------------------------------------------
HELPTEXT
}
##########
## Util
##########
get_date() {
date "+%y.%m.%d_%H.%M.%S"
}
autoMerge() {
git checkout "$1"
git pull
git merge --no-ff --no-edit "$2"
git push origin "$1"
}
autoMergeIntegration() {
integration_branch="$2_to_$1_v$3"
git checkout "$1"
git pull
git co -b "$integration_branch"
git merge --no-edit "$2"
git push origin "$integration_branch"
}
merge() {
git checkout "$1"
git pull
git merge --no-ff "$2"
git push origin "$1"
}
fastForwardMerge() {
git checkout "$1"
git pull
git merge --ff "$2"
git push origin "$1"
}
tag() {
git tag "$1"
git push origin "$1"
}
squashMerge() {
if output=$(git status --porcelain) && [ -z "$output" ]; then
git checkout "$1"
git pull
git merge --squash "$2" && git commit
git push origin "$1"
else
die "No action taken. There are uncommitted changes in the working directory."
fi
}
initBranches() {
git checkout -b $DEVELOP
git checkout -b $CANDIDATE
git checkout -b $MAIN
}
##########
## Feature
##########
featureCut() {
git checkout $DEVELOP
git checkout -b "$1"
}
featureClose() {
squashMerge $DEVELOP "$1"
}
##########
## Patch
##########
patchCut() {
git checkout $CANDIDATE
git checkout -b "$1"
}
patchClose() {
squashMerge $CANDIDATE "$1"
}
##########
## Release
##########
releaseCut() {
autoMerge $CANDIDATE $DEVELOP
}
releaseClose() {
local_version="$1"
changelog="$(git log --oneline candidate...main | cat)"
fastForwardMerge $MAIN $CANDIDATE
tag v"$local_version"
echo
echo "================================"
echo " Changelog"
echo "================================"
echo
echo "$changelog"
echo
echo "================================"
echo
autoMergeIntegration $DEVELOP $CANDIDATE "$local_version"
}
##########
## Hotfix
##########
hotfixCut() {
git checkout $MAIN
git checkout -b "$1"
tag hotfix_start_"$(get_date)"
}
hotfixClose() {
autoMerge $MAIN "$1"
tag hotfix_"$(get_date)"
read -r -s -n 1 -p "Merge to main complete. Press any key to attempt a merge to candidate, and develop."
autoMerge $CANDIDATE $MAIN
autoMerge $DEVELOP $MAIN
}
main() {
if [ -z "$1" ]; then
help
exit 1
fi
case "$1" in
"help")
help
;;
"init")
initBranches
;;
"feature_start" | "fs")
if [ -z "$2" ]; then
help
die "Requires a branch name."
fi
featureCut "$2"
;;
"feature_finish" | "ff")
if [ -z "$2" ]; then
help
die "Requires a branch name."
fi
featureClose "$2"
;;
"patch_start" | "ps")
if [ -z "$2" ]; then
help
die "Requires a branch name."
fi
patchCut "$2"
;;
"patch_finish" | "pf")
if [ -z "$2" ]; then
help
die "Requires a branch name."
fi
patchClose "$2"
;;
"release_start" | "rs")
releaseCut
;;
"release_finish" | "rf")
if [ -z "$2" ]; then
help
die "Requires a semantic version."
fi
releaseClose "$2"
;;
"hotfix_start" | "hs")
if [ -z "$2" ]; then
help
die "Requires a branch name."
fi
hotfixCut "$2"
;;
"hotfix_finish" | "hf")
if [ -z "$2" ]; then
help
die "Requires a branch name."
fi
hotfixClose "$2"
;;
"view")
git log \
--graph \
--abbrev-commit \
--decorate \
--format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' \
--all
;;
*)
die "\"$1\" not recognized"
;;
esac
}
main "$first" "$second"