-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-bbflow-release
More file actions
680 lines (549 loc) · 24.2 KB
/
Copy pathgit-bbflow-release
File metadata and controls
680 lines (549 loc) · 24.2 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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
#
# git-bbflow -- A collection of Git extensions to provide high-level
# repository operations for Blue Billywig's branching model.
#
#
# Copyright (c) 2012 Blue Billywig B.V. All rights reserved.
#
# Based on the work of Vincent Driessen, for which the copyright notice follows.
#
#
# Copyright 2010 Vincent Driessen. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are
# those of the authors and should not be interpreted as representing official
# policies, either expressed or implied, of Vincent Driessen.
#
require_git_repo
require_gitbbflow_initialized
gitbbflow_load_settings
usage() {
echo "usage: git bbflow release [list] [-v]"
echo " git bbflow release create <version>"
echo " git bbflow release switch [-n] <version>"
echo " git bbflow release feature [[-a] | [<feature-number>]]"
echo " git bbflow release abort [-f]"
echo " git bbflow release complete"
echo " git bbflow release rollback"
echo " git bbflow release close"
}
cmd_default() {
cmd_list "$@"
}
cmd_help() {
usage
exit 0
}
cmd_list() {
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
git_fetch_origin
local local_release_branches
local remote_release_branches
local short_names
local_release_branches=$(echo "$(git_local_branches)" | grep -v "^$RELEASE_PREFIX[^-]*-features" | grep "^$RELEASE_PREFIX")
remote_release_branches=$(echo "$(git_remote_branches)" | grep -v "^$ORIGIN/$RELEASE_PREFIX[^-]*-features" | grep "^$ORIGIN/$RELEASE_PREFIX")
if [ -z "$local_release_branches" -a -z "$remote_release_branches" ]; then
echo
echo "No release branches exist."
exit 0
fi
short_names=$(git_release_branch_shortnames)
# determine column width first
local width=0
local branch
for branch in $short_names; do
local len=${#branch}
width=$(max $width $len)
done
width=$(($width+3))
local branch
for branch in $short_names; do
local fullname=$RELEASE_PREFIX$branch
if has "$fullname" $(git_local_branches) && ! has "$ORIGIN/$fullname" $(git_remote_branches); then
if [ "$fullname" = "$BRANCH" ]; then
echo -n "! "
else
echo -n "- "
fi
else
if [ "$fullname" = "$BRANCH" ]; then
echo -n "* "
else
echo -n " "
fi
fi
if flag verbose; then
printf "%-${width}s" "$branch"
if ! has "$fullname" $(git_local_branches); then
echo -n "(remote)"
else
local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
local master_sha=$(git rev-parse "$MASTER_BRANCH")
local branch_sha=$(git rev-parse "$fullname")
if [ "$branch_sha" = "$master_sha" ]; then
echo -n "(no commits yet) "
else
local nicename=$(git rev-parse --short "$base")
echo -n "(based on $nicename) "
fi
if has "$fullname" $(git_local_branches) && ! has "$ORIGIN/$fullname" $(git_remote_branches); then
echo -n "(remote deleted, use 'git bbflow cleanup')"
else
git_compare_branches $fullname "$ORIGIN/$fullname"
local status=$?
if [ $status -gt 0 ]; then
if [ $status -eq 1 ]; then
echo -n "(remote contains updates, use 'git bbflow update' on branch)"
elif [ $status -eq 2 ]; then
echo -n "(changes not pushed to remote yet, use 'git bbflow push' on branch)"
elif [ $status -eq 3 ]; then
echo -n "(remote contains updates, use 'git bbflow update' on branch)"
else
echo -n "(error: remote does not match local branch)"
fi
fi
fi
fi
else
printf "%s" "$branch"
fi
echo
done
}
cmd_create() {
parse_args "$@"
parse_version "$@"
require_version_arg
git_fetch_origin
[ "$ROLE" == "admin" ] || die "Admin role required. Cannot create release."
# sanity checks
require_clean_working_tree
require_no_existing_local_release_branches
require_no_existing_remote_release_branches
# Require release tag to be absent.
if git_tag_exists "$RELEASETAG_PREFIX$VERSION"; then
die "Release $VERSION already exists. Choose another release version."
fi
require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
# create branch
BRANCH="$RELEASE_PREFIX$VERSION"
git checkout -q -b "$BRANCH" "$MASTER_BRANCH" || die "Could not create and switch to branch '$BRANCH'."
# publish to origin and track
git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
git config "branch.$BRANCH.remote" "$ORIGIN"
git config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
echo
echo "Created new release branch '$BRANCH', based on '$MASTER_BRANCH', and published to '$ORIGIN'."
echo "You are now on branch '$BRANCH'."
}
cmd_switch() {
DEFINE_boolean noupdate false "don't update from $ORIGIN" n
parse_args "$@"
parse_version "$@"
require_version_arg
git_fetch_origin
[ "$ROLE" == "admin" ] || die "Admin role required. Cannot switch to release."
BRANCH="$RELEASE_PREFIX$VERSION"
# sanity checks
require_clean_working_tree
require_branch "$ORIGIN/$BRANCH"
if has "$BRANCH" $(git_local_branches); then
# change to branch
local current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
if [ "$BRANCH" = "$current_branch" ]; then
die "Already on branch '$BRANCH'."
else
git checkout -q "$BRANCH"
if noflag noupdate; then
git_update_from_origin
fi
fi
else
# create tracking branch
git checkout -b "$BRANCH" "$ORIGIN/$BRANCH" || die "Could not create and switch to branch '$BRANCH'."
fi
echo
echo "You are now on branch '$BRANCH'."
}
cmd_abort() {
DEFINE_boolean force false "force release abort" f
parse_args "$@"
git_fetch_origin
[ "$ROLE" == "admin" ] || die "Admin role required. Cannot abort release."
# sanity checks
require_clean_working_tree
require_current_release_branch
# Require release tag to be absent.
if git_tag_exists "$RELEASETAG_PREFIX$VERSION"; then
die "Release $VERSION already completed. Cannot abort this release. Use 'git bbflow release rollback' if you need to rollback the release."
fi
if noflag force; then
git_compare_branches "$BRANCH" "$ORIGIN/$BRANCH"
local status=$?
if [ $status -eq 1 -o $status -eq 3 ]; then
die "Remote changes to release '$VERSION'. Are you sure to abort? Use 'git bbflow release abort -f' to force abort."
fi
git checkout -q "$MASTER_BRANCH"
git branch -d "$BRANCH"
if [ $? -ne 0 ]; then
git checkout -q "$BRANCH"
die "Cannot delete release branch '$BRANCH'. Use 'git bbflow release abort -f' to force abort."
fi
else
git checkout -q "$MASTER_BRANCH"
git branch -D "$BRANCH"
if [ $? -ne 0 ]; then
git checkout -q "$BRANCH"
die "Cannot delete branch '$BRANCH'."
fi
fi
git push "$ORIGIN" ":$BRANCH"
local release_feature_branches=$(echo "$(git_local_branches)" | grep "^$RELEASE_PREFIX$VERSION-features")
local release_feature_branch
for release_feature_branch in $release_feature_branches; do
git branch -D "$release_feature_branch"
git push "$ORIGIN" ":$release_feature_branch"
done
echo
echo "Aborted release $VERSION."
}
cmd_feature() {
DEFINE_boolean abort false "abort feature release" a
parse_args "$@"
parse_feature "$@"
[ "$ROLE" == "admin" ] || die "Admin role required. Cannot release feature."
local status
local release_feature_branch
local release_feature_branches
local remote_feature_branch
local feature_branch
local feature_branch_short
if [ -z $FEATUREARG ]; then
[ ! -z "$RELEASE_FEATURE" ] || require_feature_arg
[ "$RELEASE_FEATURE" != "$FEATURE" ] || die "Current feature release not completed yet. Use 'git bbflow release feature' to continue, or 'git bbflow release feature -a' to abort."
release_feature_branch="$RELEASE_FEATURE_BRANCH"
FEATURE="$RELEASE_FEATURE"
feature_branch=$(echo "$(git_local_branches)" | grep "^$FEATURE_PREFIX$FEATURE-")
if flag abort; then
git reset --hard || die "Could not reset branch '$release_feature_branch'."
git checkout -q "$BRANCH" || die "Could not checkout branch '$BRANCH'."
git branch -D "$release_feature_branch" || die "Could not delete branch '$release_feature_branch'."
echo
echo "Aborted releasing feature $FEATURE."
exit
fi
else
require_feature_arg
git_fetch_origin
# sanity checks
require_clean_working_tree
require_current_release_branch
require_branch_uptodate
# Require release tag to be absent.
if git_tag_exists "$RELEASETAG_PREFIX$VERSION"; then
die "Release $VERSION already completed. Cannot add feature to this release."
fi
# Check for feature branch
feature_branch=$(echo "$(git_local_branches)" | grep "^$FEATURE_PREFIX$FEATURE-")
if [ -z $feature_branch ]; then
remote_feature_branch=$(echo "$(git_remote_branches)" | grep "^$ORIGIN/$FEATURE_PREFIX$FEATURE-")
if [ -z $remote_feature_branch ]; then
die "No feature $FEATURE found."
else
die "Feature $remote_feature_branch exists remotely. Import with git bbflow feature switch <feature-number>."
fi
fi
feature_branch_short="${feature_branch#$FEATURE_PREFIX}"
# Check if already fully merged to develop branch
if ! git_is_branch_merged_into "$feature_branch" "$DEVELOP_BRANCH"; then
die "Feature branch $feature_branch is not merged into $DEVELOP_BRANCH branch."
fi
# Check if feature branch is up-to-date.
require_branch "$ORIGIN/$feature_branch"
require_branches_equal "$feature_branch" "$ORIGIN/$feature_branch"
# Check if not already merged
release_feature_branch="$RELEASE_PREFIX$VERSION-features/$feature_branch_short"
if [ ${#release_feature_branch} -gt 120 ]; then
release_feature_branch=${release_feature_branch:0:120}
fi
release_feature_branches="$(echo "$(git_local_branches)" | grep "^$release_feature_branch")"
[ -z "$release_feature_branches" ] || die "Feature $FEATURE already included in this release."
# Create release feature branch
git checkout -q -b "$release_feature_branch" "$BRANCH" || die "Could not create branch '$release_feature_branch'."
fi
# Merge feature to release feature branch
set +o posix
local feature_base_commit=$(diff -u <(git rev-list --first-parent "$DEVELOP_BRANCH") <(git rev-list --first-parent "$feature_branch") | sed -ne 's/^ //p' | head -1)
# workaround for IntelliJ BashSupport plugin not recognizing process substitution: "
if [ -z "$feature_base_commit" ]; then
feature_base_commit="$(git rev-list -n 1 $feature_branch)"
fi
for commit in $(git cherry "$BRANCH" "$feature_branch" "$feature_base_commit" | sed -ne 's/^[+-] //p'); do
git cherry-pick "$commit"
status=$?
if [ $status -ne 0 ]; then
echo
echo "Merge conflict while cherry-picking commit '$commit' of feature $FEATURE into branch '$BRANCH'."
echo "Fix conflicts using merge tools and commit using 'git commit'."
echo
echo "After completing the fix:"
echo "- 'git commit' to commit the fixed cherry-pick."
echo "- 'git bbflow release feature' to continue merging the feature into the release."
echo
echo "Or to abort merging the feature into the release:"
echo "- 'get bbflow release feature -a' to abort merging the feature into the release."
echo
echo "You are now on branch '$release_feature_branch'."
exit 1
fi
done
# Publish to origin and track
git push "$ORIGIN" "$release_feature_branch:refs/heads/$release_feature_branch"
git config "branch.$release_feature_branch.remote" "$ORIGIN"
git config "branch.$release_feature_branch.merge" "refs/heads/$release_feature_branch"
# Merge to release branch
git checkout -q "$BRANCH" || die "Could not checkout branch '$BRANCH'."
git merge --no-ff "$release_feature_branch"
status=$?
if [ $status -eq 1 ]; then
echo
echo "Merge conflict while merging feature release branch '$release_feature_branch' into release branch '$BRANCH'."
echo "Fix conflicts using merge tools and commit using 'git commit',"
echo "or abort the merge resolution by running 'git merge --abort'."
echo
echo "You are now on branch '$BRANCH'."
exit 1
fi
# Publish to origin
git push "$ORIGIN" "$BRANCH"
echo
echo "Merged feature $FEATURE into release $VERSION."
}
cmd_complete() {
parse_args "$@"
git_fetch_origin
[ "$ROLE" == "admin" ] || die "Admin role required. Cannot complete release."
# sanity checks
require_clean_working_tree
require_current_release_branch
# Check if hotfix branch is up-to-date.
git_compare_branches "$BRANCH" "$ORIGIN/$BRANCH"
local status=$?
[ $status -ne 1 -a $status -ne 3 ] || die "Remote changes to release $VERSION. Use 'git bbflow update' to update the release."
[ $status -ne 2 ] || die "Local changes to release $VERSION. Use 'git bbflow push' first to push changes to remote."
[ $status -ne 4 ] || die "Remote and local branch '$BRANCH' unrelated. Unrecoverable error."
# Check if master branch is up-to-date. Update if necessary.
git_compare_branches "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
status=$?
if [ $status -eq 1 -o $status -eq 3 ]; then
echo
echo "Updating '$MASTER_BRANCH' branch from remote '$ORIGIN'."
git checkout -q "$MASTER_BRANCH" || die "Cannot switch to branch '$MASTER_BRANCH'."
git merge "$ORIGIN/$MASTER_BRANCH"
status=$?
if [ $status -eq 1 ]; then
echo
echo "Merge conflict while updating branch '$MASTER_BRANCH' from remote '$ORIGIN'. This should not happen."
echo "Fix conflicts using merge tools and commit using 'git commit',"
echo "or abort the merge resolution by running 'git merge --abort'."
echo
echo "After committing the resolved merge, use:"
echo "- 'git bbflow release switch $VERSION' to switch back to the current release."
echo "- 'git bbflow release complete' to complete the current release."
echo
echo "You are now on branch '$MASTER_BRANCH'."
exit 1
fi
git checkout -q "$BRANCH"
fi
local status
# try to merge into master
# in case a previous attempt to finish this release branch has failed,
# but the merge into master was successful, we skip it now
if ! git_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then
git checkout -q "$MASTER_BRANCH" || die "Could not switch to branch '$MASTER_BRANCH'."
git merge --no-ff "$BRANCH"
status=$?
if [ $status -ne 0 ]; then
echo
echo "Merge conflict while merging release branch '$BRANCH' into master branch '$MASTER_BRANCH'."
echo "This shouldn't happen while merging the release branch into the master branch."
echo
echo "You are now on branch '$MASTER_BRANCH'."
exit 1
fi
fi
# try to tag the release
# in case a previous attempt to finish this release branch has failed,
# but the tag was set successful, we skip it now
local tagname=$RELEASETAG_PREFIX$VERSION
if ! git_tag_exists "$tagname"; then
git checkout -q "$MASTER_BRANCH" || die "Could not switch to branch '$MASTER_BRANCH'."
git tag -a "$tagname" -m "Release $VERSION"
status=$?
if [ $status -ne 0 ]; then
git checkout -q "$BRANCH" || warn "Could not switch to branch '$BRANCH'."
echo
echo "Could not tag release. Run 'git bbflow release complete' again to retry."
exit 1
fi
fi
git push "$ORIGIN" "$MASTER_BRANCH" || \
die "Could not push '$MASTER_BRANCH' to '$ORIGIN'."
git push --tags "$ORIGIN" || \
die "Could not push tags to '$ORIGIN'."
git checkout -q "$BRANCH" || die "Could not switch to branch '$BRANCH'."
echo
echo "Merged release $VERSION into '$MASTER_BRANCH' branch and tagged it '$tagname'."
}
cmd_close() {
parse_args "$@"
git_fetch_origin
[ "$ROLE" == "admin" ] || die "Admin role required. Cannot close release."
# sanity checks
require_clean_working_tree
require_current_release_branch
require_branches_equal "$BRANCH" "$ORIGIN/$BRANCH"
require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
# Require release tag to be present.
$(git_tag_exists "$RELEASETAG_PREFIX$VERSION") || \
die "Release $VERSION not yet completed. Cannot close."
# Tag and close feature branches
local feature_branches_short=$(git_local_branches | grep "^$RELEASE_PREFIX$VERSION-features/" | sed "s/^.*\/$VERSION-features\///")
local feature_branch_short
for feature_branch_short in $feature_branches_short; do
local feature_branch="$FEATURE_PREFIX$feature_branch_short"
require_branches_equal "$feature_branch" "$ORIGIN/$feature_branch"
local tagname=$FEATURETAG_PREFIX$feature_branch_short
if ! git_tag_exists "$tagname"; then
git checkout -q "$feature_branch" || die "Could not check out '$feature_branch'."
git tag -a "$tagname" -m "Closed feature $feature_branch_short" || die "Tagging failed. Please run close again to retry."
fi
git checkout -q "$MASTER_BRANCH" || die "Could not switch to branch '$MASTER_BRANCH'."
git branch -d "$RELEASE_PREFIX$VERSION-features/$feature_branch_short" || warn "Could not delete branch '$RELEASE_PREFIX$VERSION-features/$feature_branch_short'."
git branch -d "$feature_branch" || die "Could not delete branch '$feature_branch'."
done
# close release branch
git checkout -q "$MASTER_BRANCH" || "Could not switch to branch '$BRANCH'."
git branch -d "$BRANCH" || die "Could not delete branch '$BRANCH'."
# push to remote
git push --tags "$ORIGIN" || warn "Could not push tags to '$ORIGIN'."
git push "$ORIGIN" ":$BRANCH" || warn "Could not push delete '$BRANCH' to '$ORIGIN'."
for feature_branch_short in $feature_branches_short; do
local feature_branch="$FEATURE_PREFIX$feature_branch_short"
git push "$ORIGIN" ":$RELEASE_PREFIX$VERSION-features/$feature_branch_short" || warn "Could not push delete '$RELEASE_PREFIX$VERSION-features/$feature_branch_short' to '$ORIGIN'."
git push "$ORIGIN" ":$feature_branch" || warn "Could not push delete '$feature_branch' to '$ORIGIN'."
done
echo
echo "Closed release '$VERSION' and containing features."
echo
echo "You are now on branch '$MASTER_BRANCH'."
}
cmd_rollback() {
echo "Release rollback is not implemented yet."
}
parse_args() {
# parse options
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
local release_branch=$(echo "$(git_current_branch)" | grep "^$RELEASE_PREFIX")
local release_feature_branch
if [ ! -z "$release_branch" ]; then
release_feature_branch="$(echo "$release_branch" | grep '^.*-features\/')"
if [ ! -z "$release_feature_branch" ]; then
RELEASE_FEATURE_BRANCH="$release_feature_branch"
RELEASE_FEATURE="$(echo "$release_feature_branch" | sed 's/^.*-features\/\([^-]*\)-.*$/\1/')"
BRANCH="$(echo "$release_branch" | sed 's/-features.*$//')"
VERSION="${BRANCH#$RELEASE_PREFIX}"
else
BRANCH="$release_branch"
VERSION="${BRANCH#$RELEASE_PREFIX}"
fi
fi
}
parse_version() {
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
if [ ! -z $1 ]; then
VERSION=$1
VERSIONARG=$VERSION
local local_release_branch=$(echo "$(git_local_branches)" | grep "^$RELEASE_PREFIX$VERSION\$")
local remote_release_branch=$(echo "$(git_remote_branches)" | grep "^$ORIGIN/$RELEASE_PREFIX$VERSION\$")
if [ ! -z $local_release_branch ]; then
BRANCH="$local_release_branch"
elif [ ! -z $remote_release_branch ]; then
BRANCH="${remote_release_branch#$ORIGIN/}"
fi
fi
}
parse_feature() {
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
if [ ! -z $1 ]; then
FEATURE=$1
FEATUREARG=$FEATURE
fi
}
require_version_arg() {
if [ "$VERSIONARG" = "" ]; then
warn "Missing argument <version>"
usage
exit 1
fi
}
require_feature_arg() {
if [ "$FEATUREARG" = "" ]; then
warn "Missing argument <feature>"
usage
exit 1
fi
}
require_no_existing_local_release_branches() {
local release_branches=$(echo "$(git_local_branches)" | grep -v "^$RELEASE_PREFIX[^-]*-features" | grep "^$RELEASE_PREFIX")
local first_branch=$(echo ${release_branches} | head -n1)
first_branch=${first_branch#$RELEASE_PREFIX}
[ -z "$release_branches" ] || \
die "There is an existing release branch ($first_branch). Finish that one first."
}
require_no_existing_remote_release_branches() {
local release_branches=$(echo "$(git_remote_branches)" | grep -v "^$ORIGIN/$RELEASE_PREFIX[^-]*-features" | grep "^$ORIGIN/$RELEASE_PREFIX")
local first_branch=$(echo ${release_branches} | head -n1)
first_branch=${first_branch#$RELEASE_PREFIX}
[ -z "$release_branches" ] || \
die "There is an existing remote release branch ($first_branch). Finish that one first."
}
require_current_release_branch() {
local release_branches=$(echo "$(git_local_branches)" | grep -v "^$RELEASE_PREFIX[^-]*-features" | grep "^$RELEASE_PREFIX")
local current_branch=$(git_current_branch)
if ! has "$current_branch" "$release_branches"; then
die "Not on a release branch."
fi
}
git_release_branch_shortnames() {
{
git_local_branches | grep -v "^$RELEASE_PREFIX[^-]*-features" | grep "^$RELEASE_PREFIX" | sed "s ^$RELEASE_PREFIX g"
git_remote_branches | grep -v "^$ORIGIN/$RELEASE_PREFIX[^-]*-features" | grep "^$ORIGIN/$RELEASE_PREFIX" | sed "s ^$ORIGIN/$RELEASE_PREFIX g"
} | sort -u
}