forked from nvie/gitflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-flow-release
879 lines (820 loc) · 33 KB
/
git-flow-release
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
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
#
# ITM Gitflow script package -- A collection of Git extensions to provide
# high-level repository operations for Vincent Driessen's branching model.
#
# A blog post by Vincent Driessen presenting this model is found at:
# http://nvie.com/posts/a-successful-git-branching-model/
#
# Feel free to contribute to this project at:
# https://github.com/fspreng/ITM_gitflow
#
# Copyright (c) 2012-2015 Fabian Spreng. All rights reserved.
#
# Original author:
# 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.
#
init() {
require_git_repo
require_gitflow_initialized
gitflow_load_settings
VERSION_PREFIX=$(eval "echo `git config --get gitflow.prefix.versiontag`")
PREFIX=$(git config --get gitflow.prefix.release)
REMOTE_PREFIX=$ORIGIN/$PREFIX
}
usage() {
echo "usage: $GITFLOW_COMMAND release [list] [-v]"
# echo " $GITFLOW_COMMAND release start [-F] <major/minor> [<base>]"
echo " $GITFLOW_COMMAND release start [-F] <major/minor>"
echo " $GITFLOW_COMMAND release finish [-FsumpkSo] <name>"
echo " $GITFLOW_COMMAND release delete [-l] <name>"
echo " $GITFLOW_COMMAND release publish <name>"
echo " $GITFLOW_COMMAND release track <name>"
}
cmd_default() {
cmd_list "$@"
}
cmd_list() {
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
local release_branches
local current_branch
local short_names
release_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
echo "Executing Git command 'git remote update'"
git_do remote update >/dev/null 2>&1 || \
die "Could not update remote branches from $ORIGIN."
echo "Executing Git command 'git remote prune origin'"
git_do remote prune origin >/dev/null 2>&1
local remote_release_branches
remote_release_branches=$(echo "$(git_remote_branches)" | grep "^$REMOTE_PREFIX")
if [ -z "$release_branches" ] && [ -z "$remote_release_branches" ]; then
warn "No release branches exist."
warn ""
warn "You can start a new release branch:"
warn ""
warn " $GITFLOW_COMMAND release start <major/minor> [<base>]"
warn ""
exit 0
fi
current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
short_names=$(echo "$release_branches" | sed "s ^$PREFIX g")
# determine column width first
local width=0
local branch
for branch in $short_names; do
local len=${#branch}
width=$(max $width $len)
done
for branch in $remote_release_branches; do
local len=${#branch}
width=$(max $width $len)
done
width=$(($width+3))
if [ "$release_branches" ]; then
printf "Local release branches:"
echo
local branch
for branch in $short_names; do
local fullname=$PREFIX$branch
local base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
local develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
local branch_sha=$(git rev-parse "$fullname")
if [ "$fullname" = "$current_branch" ]; then
printf "* "
else
printf " "
fi
if flag verbose; then
printf "%-${width}s" "$PREFIX$branch"
if [ "$branch_sha" = "$develop_sha" ]; then
printf "(no commits yet)"
else
local nicename=$(git rev-parse --short "$base")
printf "(based on $nicename)"
fi
else
printf "%s" "$PREFIX$branch"
fi
echo
done
fi
if [ "$remote_release_branches" ]; then
printf "Remote release branches:"
echo
for branch in $remote_release_branches; do
printf " "
printf "%s" "remotes/$branch"
echo
done
fi
}
cmd_help() {
usage
exit 0
}
parse_args() {
# parse options
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# process possible trailing arguments
length_old=0
for k in "${@:2}"
do
length_old=$[$length_old+1]
done
if [ "$length_old" -gt "0" ]; then
FLAGS "${@:2}" || exit $?
length_new=0
for l in ${FLAGS_ARGV[@]}
do
length_new=$[$length_new+1]
done
if [ "$length_new" -gt "0" ] && [ "$length_new" != "$length_old" ]; then
die "Putting flags between the two main arguments is not a good idea! Process aborted."
fi
if [ "$length_new" == "$length_old" ]; then
FLAGS "${@:3}" || exit $?
length_newnew=0
for l in ${FLAGS_ARGV[@]}
do
length_newnew=$[$length_newnew+1]
done
if [ "$length_newnew" == "$length_old" ]; then
die "Too many arguments have been found!"
fi
fi
fi
# read arguments into global variables
VERSION=$1
# check whether the user has already added the branch prefix or not
if { echo "$VERSION" | grep -q "^$PREFIX"; } then
local len=${#PREFIX}
VERSION=${VERSION:$len}
fi
# check whether the user has already added the version tag prefix or not
if { echo "$VERSION" | grep -q "^$VERSION_PREFIX"; } then
local len=${#VERSION_PREFIX}
VERSION=${VERSION:$len}
fi
BRANCH=$PREFIX$VERSION_PREFIX$VERSION
}
require_version_arg() {
if [ "$VERSION" = "" ]; then
warn "Missing argument <version>"
usage
exit 1
fi
}
require_major_minor_arg() {
if [ "$VERSION" != "major" ] && [ "$VERSION" != "minor" ]; then
warn "Missing argument <major/minor>"
usage
exit 1
else
local majortag=0
local minortag=0
if [ "$VERSION" == "major" ]; then
local tag
for tag in $(git_do for-each-ref refs/tags/ --format='%(refname)'); do
if { echo "$tag" | grep -q "$VERSION_PREFIX"; } then
local len=10+${#VERSION_PREFIX}
local shorttag
shorttag=${tag:len}
local nextdot
nextdot=$(expr index "$shorttag" .)
((nextdot-=1))
shorttag=${shorttag:0:nextdot}
if [[ "$shorttag" -gt "$majortag" ]]; then
majortag=$shorttag
fi
fi
done
((majortag+=1))
minortag=0
else
local tag
for tag in $(git_do for-each-ref refs/tags/ --format='%(refname)'); do
if { echo "$tag" | grep -q "$VERSION_PREFIX"; } then
local len=10+${#VERSION_PREFIX}
local shorttag
shorttag=${tag:len}
local nextdot
nextdot=$(expr index "$shorttag" .)
((nextdot-=1))
local fronttag=${shorttag:0:nextdot}
if [ "$fronttag" -ge "$majortag" ]; then
if [ "$fronttag" -gt "$majortag" ]; then
minortag=0
fi
majortag=$fronttag
shorttag=${shorttag: ((nextdot+=1))}
nextdot=$(expr index "$shorttag" .)
((nextdot-=1))
shorttag=${shorttag:0:nextdot}
if [[ "$shorttag" -gt "$minortag" ]]; then
minortag=$shorttag
fi
fi
fi
done
((minortag+=1))
fi
VERSION=$majortag.$minortag.0
BRANCH=$PREFIX$VERSION_PREFIX$VERSION
fi
}
require_base_is_on_develop() {
echo "Executing Git command 'git branch --no-color --contains $BASE'"
if ! git_do branch --no-color --contains "$BASE" 2>/dev/null \
| sed 's/[* ] //g' \
| grep -q "^$DEVELOP_BRANCH\$"; then
die "fatal: Given base '$BASE' is not a valid commit on '$DEVELOP_BRANCH'."
fi
}
require_no_existing_release_branches() {
local release_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
local first_branch=$(echo ${release_branches} | head -n1)
first_branch=${first_branch#$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 "^$ORIGIN/$PREFIX")
local first_branch=$(echo ${release_branches} | head -n1)
first_branch=${first_branch#$PREFIX}
[ -z "$release_branches" ] || \
die "There is an existing release branch ($first_branch). Finish that one first."
}
cmd_start() {
DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
echo "Executing Git command 'git fetch --tags'"
git_do fetch --tags >/dev/null 2>&1 || \
die "Could not fetch latest tags from $ORIGIN."
parse_args "$@"
# BASE=${2:-$DEVELOP_BRANCH}
# require_version_arg
require_major_minor_arg
# require_base_is_on_develop
require_no_existing_release_branches
# sanity checks
require_clean_working_tree
require_branch_absent "$BRANCH"
echo "Executing Git command 'git remote update'"
git_do remote update >/dev/null 2>&1 || \
die "Could not update remote branches from $ORIGIN."
echo "Executing Git command 'git remote prune origin'"
git_do remote prune origin >/dev/null 2>&1
require_no_existing_remote_release_branches
# require_branch_absent "$ORIGIN/$BRANCH"
require_tag_absent "$VERSION_PREFIX$VERSION"
# temporarily changing to root directory of git repository
echo "Changing to root directory of Git repository"
cd "$(git rev-parse --show-cdup)"
if flag fetch; then
echo "Executing Git command 'git checkout $DEVELOP_BRANCH'"
git_do checkout "$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not check out $DEVELOP_BRANCH."
echo "Executing Git command 'git fetch -q $ORIGIN $DEVELOP_BRANCH:refs/remotes/$ORIGIN/$DEVELOP_BRANCH'"
git_do fetch -q "$ORIGIN" "$DEVELOP_BRANCH":refs/remotes/"$ORIGIN"/"$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
echo "Executing Git command 'git merge --no-commit $ORIGIN/$DEVELOP_BRANCH'"
git_do merge --no-commit "$ORIGIN/$DEVELOP_BRANCH" >/dev/null 2>&1 || {
echo "*****************************************************************************************"
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
die "WARNING: There were merge conflicts on $DEVELOP_BRANCH. Resolve them using git mergetool."
}
echo "Executing Git command 'git push origin $DEVELOP_BRANCH'"
git_do push origin "$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not push to $DEVELOP_BRANCH from $ORIGIN."
fi
# if the origin branch counterpart exists, assert that the local branch
# isn't behind it (to avoid unnecessary rebasing)
if has "$ORIGIN/$DEVELOP_BRANCH" $(git_remote_branches); then
require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
fi
# create the local branch and the corresponding remote branch
echo "Executing Git command 'git checkout -b $BRANCH $DEVELOP_BRANCH'"
if ! git_do checkout -b "$BRANCH" "$DEVELOP_BRANCH" >/dev/null 2>&1; then
die "Could not create release branch '$BRANCH'"
else
echo "Executing Git command 'git push -u origin $BRANCH'"
git_do push -u origin "$BRANCH" >/dev/null 2>&1
fi
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
echo
echo "Summary of actions:"
echo "- A new local branch '$BRANCH' was created, based on '$DEVELOP_BRANCH'"
echo "- A new remote branch '$BRANCH' was created, based on the local one"
echo "- You are now on branch '$BRANCH'"
echo
# echo "Follow-up actions:"
# echo "- Bump the version number now!"
# echo "- Start committing last-minute fixes in preparing your release"
# echo "- When done, run:"
echo "Now, start committing on the release version. When done, use:"
echo
echo " $GITFLOW_COMMAND release finish $VERSION_PREFIX$VERSION"
echo
}
cmd_finish() {
DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
DEFINE_boolean sign false "sign the release tag cryptographically" s
DEFINE_string signingkey "" "use the given GPG-key for the digital signature (implies -s)" u
DEFINE_string message "" "use the given tag message" m
DEFINE_string messagefile "" "use the contents of the given file as a tag message" f
DEFINE_boolean push true "push to $ORIGIN after performing finish" p
DEFINE_boolean keep false "keep branch after performing finish" k
DEFINE_boolean notag false "don't tag this release" n
DEFINE_boolean squash false "squash release during merge" S
DEFINE_boolean onlymaster false "merge the current release branch only into the master branch" o
parse_args "$@"
require_version_arg
# handle flags that imply other flags
if [ "$FLAGS_signingkey" != "" ]; then
FLAGS_sign=$FLAGS_TRUE
fi
# sanity checks
require_branch "$BRANCH"
require_clean_working_tree
# temporarily changing to root directory of git repository
echo "Changing to root directory of Git repository"
cd "$(git rev-parse --show-cdup)"
echo "Executing Git command 'git checkout $BRANCH'"
git_do checkout "$BRANCH" >/dev/null 2>&1 || \
die "Could not check out $BRANCH."
echo "Executing Git command 'git fetch -q $ORIGIN $BRANCH:refs/remotes/$ORIGIN/$BRANCH'"
git_do fetch -q "$ORIGIN" "$BRANCH":refs/remotes/"$ORIGIN"/"$BRANCH" >/dev/null 2>&1 || \
die "Could not fetch $BRANCH from $ORIGIN."
echo "Executing Git command 'git remote prune origin'"
git_do remote prune origin >/dev/null 2>&1
require_branch "$ORIGIN/$BRANCH"
echo "Executing Git command 'git merge --no-commit $ORIGIN/$BRANCH'"
git_do merge --no-commit "$ORIGIN/$BRANCH" >/dev/null 2>&1 || {
echo "*********************************************************************************"
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
die "WARNING: There were merge conflicts on $BRANCH. Resolve them using git mergetool."
}
echo "Executing Git command 'git push origin $BRANCH'"
git_do push origin "$BRANCH" >/dev/null 2>&1 || \
die "Could not push to $BRANCH from $ORIGIN."
# branch $ORIGIN/$BRANCH should be existent, but check it anyway...
if has "$ORIGIN/$BRANCH" $(git_remote_branches); then
if flag fetch; then
# echo "Executing Git command 'git fetch -q $ORIGIN $BRANCH:refs/remotes/$ORIGIN/$BRANCH'"
# git_do fetch -q "$ORIGIN" "$BRANCH":refs/remotes/"$ORIGIN"/"$BRANCH" >/dev/null 2>&1 || \
# die "Could not fetch $BRANCH from $ORIGIN."
echo "Executing Git command 'git checkout $MASTER_BRANCH'"
git_do checkout "$MASTER_BRANCH" >/dev/null 2>&1 || \
die "Could not check out $MASTER_BRANCH."
# Basically, the additional fetch is not necessary, but can be useful when the
# subsequent pull fails
echo "Executing Git command 'git fetch -q $ORIGIN $MASTER_BRANCH:refs/remotes/$ORIGIN/$MASTER_BRANCH'"
git_do fetch -q "$ORIGIN" "$MASTER_BRANCH":refs/remotes/"$ORIGIN"/"$MASTER_BRANCH" >/dev/null 2>&1 || \
die "Could not fetch $MASTER_BRANCH from $ORIGIN."
echo "Executing Git command 'git pull -q --no-commit $ORIGIN $MASTER_BRANCH:refs/remotes/$ORIGIN/$MASTER_BRANCH'"
git_do pull -q --no-commit "$ORIGIN" "$MASTER_BRANCH":refs/remotes/"$ORIGIN"/"$MASTER_BRANCH" >/dev/null 2>&1 || {
echo "****************************************************************************************"
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
die "WARNING: There were merge conflicts on $MASTER_BRANCH. Resolve them using git mergetool."
}
# echo "Executing Git command 'git merge --no-commit $ORIGIN/$MASTER_BRANCH'"
# git_do merge --no-commit "$ORIGIN/$MASTER_BRANCH" >/dev/null 2>&1 || {
# echo "****************************************************************************************"
# # return to previous working directory if available
# if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
# echo "Returning to previous working directory"
# cd "$OLDPWD"
# else
# echo "Previous working directory no longer available, staying in root directory of Git repository"
# fi
# die "WARNING: There were merge conflicts on $MASTER_BRANCH. Resolve them using git mergetool."
# }
# echo "Executing Git command 'git push origin $MASTER_BRANCH'"
# git_do push origin "$MASTER_BRANCH" >/dev/null 2>&1 || \
# die "Could not push to $MASTER_BRANCH from $ORIGIN."
fi
fi
if has "$ORIGIN/$MASTER_BRANCH" $(git_remote_branches); then
require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
fi
if has "$ORIGIN/$BRANCH" $(git_remote_branches); then
require_branches_equal "$BRANCH" "$ORIGIN/$BRANCH"
fi
# if a new release version of Pasimodo is finished, some additional versioning tasks have to be performed
# (formerly done by the script called "versioned_git_ci")
# find the directory named versioning and enter it
local level_counter=0
local found=0
while [ "$found" == 0 ] && [ "$level_counter" -lt "15" ]; do
if [ -d "versioning" ]; then
cd versioning
found=1
else
cd ..
level_counter=$(($level_counter+1))
fi
done
# extract the major and the minor tag of the Pasimodo release version to be finished
if [ "$found" == 1 ]; then
echo "Executing Git command 'git checkout $BRANCH'"
git_do checkout "$BRANCH" >/dev/null 2>&1 || \
die "Could not check out $BRANCH."
local majortag=0
local minortag=0
local hotfixtag=0
local shorttag=$VERSION
local nextdot
nextdot=$(expr index "$shorttag" .)
((nextdot-=1))
majortag=${shorttag:0:nextdot}
shorttag=${shorttag: ((nextdot+=1))}
nextdot=$(expr index "$shorttag" .)
((nextdot-=1))
minortag=${shorttag:0:nextdot}
if [ -f "Pasimodo_Version.txt" ]; then
echo -e $majortag'\n'$minortag > Pasimodo_Version.txt
fi
if [ -f "Pasimodo_Revision.txt" ]; then
echo -e $hotfixtag > Pasimodo_Revision.txt
fi
local year=$(date +%Y)
local month=$(date +%m)
local day=$(date +%d)
local hour=$(date +%H)
local minute=$(date +%M)
local second=$(date +%S)
local time="$year/$month/$day $hour:$minute:$second"
if [ -f "CMake_Pasimodo_Revision.cmake" ]; then
echo -e "SET(Pasimodo_MAJOR_VERSION $majortag)\nSET(Pasimodo_MINOR_VERSION $minortag)\nSET(Pasimodo_REVISION_TIME \"$time\")\nSET(Pasimodo_REVISION $hotfixtag)" > CMake_Pasimodo_Revision.cmake
fi
echo "Executing Git command 'git commit --quiet -a -m \"Some final modifications before Pasimodo version $VERSION is ready to be released\"'"
git_do commit --quiet -a -m "Some final modifications before Pasimodo version $VERSION is ready to be released" || \
die "Could not commit changes to local branch $BRANCH."
echo "Executing Git command 'git push origin $BRANCH'"
git_do push origin "$BRANCH" >/dev/null 2>&1 || \
die "Could not push to $BRANCH from $ORIGIN."
fi
if ! flag onlymaster; then
# try to merge into develop
# in case a previous attempt to finish this release branch has failed,
# but the merge into develop was successful, we skip it now
echo "Executing Git command 'git checkout $DEVELOP_BRANCH'"
git_do checkout "$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not check out $DEVELOP_BRANCH."
# Basically, the additional fetch is not necessary, but can be useful when the
# subsequent pull fails
echo "Executing Git command 'git fetch -q $ORIGIN $DEVELOP_BRANCH:refs/remotes/$ORIGIN/$DEVELOP_BRANCH'"
git_do fetch -q "$ORIGIN" "$DEVELOP_BRANCH":refs/remotes/"$ORIGIN"/"$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
echo "Executing Git command 'git pull -q --no-commit $ORIGIN $DEVELOP_BRANCH:refs/remotes/$ORIGIN/$DEVELOP_BRANCH'"
git_do pull -q --no-commit "$ORIGIN" "$DEVELOP_BRANCH":refs/remotes/"$ORIGIN"/"$DEVELOP_BRANCH" >/dev/null 2>&1 || {
echo "*****************************************************************************************"
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
die "WARNING: There were merge conflicts on $DEVELOP_BRANCH. Resolve them using git mergetool."
}
# echo "Executing Git command 'git merge --no-commit $ORIGIN/$DEVELOP_BRANCH'"
# git_do merge --no-commit "$ORIGIN/$DEVELOP_BRANCH" >/dev/null 2>&1 || {
# echo "*****************************************************************************************"
# # return to previous working directory if available
# if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
# echo "Returning to previous working directory"
# cd "$OLDPWD"
# else
# echo "Previous working directory no longer available, staying in root directory of Git repository"
# fi
# die "WARNING: There were merge conflicts on $DEVELOP_BRANCH. Resolve them using git mergetool."
# }
echo "Executing Git command 'git push origin $DEVELOP_BRANCH'"
git_do push origin "$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not push to $DEVELOP_BRANCH from $ORIGIN."
if ! git_is_branch_merged_into "$BRANCH" "$ORIGIN/$DEVELOP_BRANCH"; then
# echo "Executing Git command 'git checkout $DEVELOP_BRANCH'"
# git_do checkout "$DEVELOP_BRANCH" >/dev/null 2>&1 || \
# die "Could not check out $DEVELOP_BRANCH."
# TODO: Actually, accounting for 'git describe' pays, so we should
# ideally git merge --no-ff $tagname here, instead!
if noflag squash; then
echo "Executing Git command 'git merge --no-ff $BRANCH'"
git_do merge --no-ff "$BRANCH" >/dev/null 2>&1 || {
echo "************************************"
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
die "WARNING: There were merge conflicts."
}
# TODO: What do we do now?
else
echo "Executing Git command 'git merge --squash $BRANCH'"
git_do merge --squash "$BRANCH" >/dev/null 2>&1 || {
echo "************************************"
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
die "WARNING: There were merge conflicts."
}
# TODO: What do we do now?
echo "Executing Git command 'git commit --quiet'"
git_do commit --quiet
fi
echo "Executing Git command 'git push $ORIGIN $DEVELOP_BRANCH'"
git_do push "$ORIGIN" "$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not push to $DEVELOP_BRANCH from $ORIGIN."
echo "Executing Git command 'git checkout $BRANCH'"
git_do checkout "$BRANCH" >/dev/null 2>&1 || \
die "Could not check out $BRANCH."
fi
fi
# 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
echo "Executing Git command 'git checkout $MASTER_BRANCH'"
git_do checkout "$MASTER_BRANCH" >/dev/null 2>&1 || \
die "Could not check out $MASTER_BRANCH."
if noflag squash; then
echo "Executing Git command 'git merge --no-ff $BRANCH'"
git_do merge --no-ff "$BRANCH" >/dev/null 2>&1 || {
echo "************************************"
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
die "WARNING: There were merge conflicts."
}
# TODO: What do we do now?
else
echo "Executing Git command 'git merge --squash $BRANCH'"
git_do merge --squash "$BRANCH" >/dev/null 2>&1 || {
echo "************************************"
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
die "WARNING: There were merge conflicts."
}
echo "Executing Git command 'git commit --quiet'"
git_do commit --quiet
fi
fi
if noflag notag; then
# 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=$VERSION_PREFIX$VERSION
if ! git_tag_exists "$tagname"; then
local opts="-a"
flag sign && opts="$opts -s"
[ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'"
[ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'"
[ "$FLAGS_messagefile" != "" ] && opts="$opts -F '$FLAGS_messagefile'"
echo "Executing Git command 'git tag $opts $tagname $MASTER_BRANCH'"
eval git_do tag $opts "$tagname" "$MASTER_BRANCH" || \
die "Tagging failed. Please run finish again to retry."
fi
fi
if flag push; then
echo "Executing Git command 'git push $ORIGIN $MASTER_BRANCH'"
git_do push "$ORIGIN" "$MASTER_BRANCH" >/dev/null 2>&1 || \
die "Could not push to $MASTER_BRANCH from $ORIGIN."
if noflag notag; then
echo "Executing Git command 'git push --tags $ORIGIN'"
git_do push --tags "$ORIGIN" >/dev/null 2>&1 || \
die "Could not push tags to $ORIGIN."
fi
# echo "Executing Git command 'git push $ORIGIN :$BRANCH'"
# git_do push "$ORIGIN" :"$BRANCH" >/dev/null 2>&1 || \
# die "Could not delete the remote $BRANCH in $ORIGIN."
fi
# delete branch
if noflag keep; then
echo "Executing Git command 'git checkout $DEVELOP_BRANCH'"
git_do checkout "$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not check out $BRANCH."
echo "Executing Git command 'git branch -d $BRANCH'"
git_do branch -d "$BRANCH" >/dev/null 2>&1
echo "Executing Git command 'git push $ORIGIN :refs/heads/$BRANCH'"
git_do push "$ORIGIN" ":refs/heads/$BRANCH" >/dev/null 2>&1 || \
die "Could not delete the remote $BRANCH in $ORIGIN."
fi
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
echo
echo "Summary of actions:"
echo "- Latest objects have been fetched from '$ORIGIN'"
echo "- Release branch has been merged into '$MASTER_BRANCH'"
# if noflag notag; then
echo "- The release was tagged '$tagname'"
# fi
if ! flag onlymaster; then
echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
fi
if flag keep; then
echo "- Release branch '$BRANCH' (local and remote) is still available"
else
echo "- Release branch '$BRANCH' (local and remote) has been deleted"
fi
if flag push; then
if ! flag onlymaster; then
echo "- '$DEVELOP_BRANCH', '$MASTER_BRANCH' and tags have been pushed to '$ORIGIN'"
else
echo "- '$MASTER_BRANCH' and tags have been pushed to '$ORIGIN'"
fi
fi
if noflag keep; then
echo "- You are now on branch '$DEVELOP_BRANCH'"
fi
echo
}
cmd_publish() {
parse_args "$@"
require_version_arg
# sanity checks
require_clean_working_tree
require_branch "$BRANCH"
echo "Executing Git command 'git fetch -q $ORIGIN'"
git_do fetch -q "$ORIGIN" >/dev/null 2>&1
echo "Executing Git command 'git remote prune origin'"
git_do remote prune origin >/dev/null 2>&1
require_branch_absent "$ORIGIN/$BRANCH"
# create remote branch
echo "Executing Git command 'git push $ORIGIN $BRANCH:refs/heads/$BRANCH'"
git_do push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH" >/dev/null 2>&1
echo "Executing Git command 'git fetch -q $ORIGIN'"
git_do fetch -q "$ORIGIN" >/dev/null 2>&1
# temporarily changing to root directory of git repository
echo "Changing to root directory of Git repository"
cd "$(git rev-parse --show-cdup)"
# configure remote tracking
echo "Executing Git command 'git config branch.$BRANCH.remote $ORIGIN'"
git_do config "branch.$BRANCH.remote" "$ORIGIN" >/dev/null 2>&1
echo "Executing Git command 'git config branch.$BRANCH.merge refs/heads/$BRANCH'"
git_do config "branch.$BRANCH.merge" "refs/heads/$BRANCH" >/dev/null 2>&1
echo "Executing Git command 'git checkout $BRANCH'"
git_do checkout "$BRANCH" >/dev/null 2>&1
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
echo
echo "Summary of actions:"
echo "- A new remote branch '$BRANCH' was created"
echo "- The local branch '$BRANCH' was configured to track the remote branch"
echo "- The old remote branch '$BRANCH' has to be deleted manually"
echo "- You are now on branch '$BRANCH'"
echo
}
cmd_track() {
parse_args "$@"
require_version_arg
# sanity checks
require_clean_working_tree
require_branch_absent "$BRANCH"
echo "Executing Git command 'git fetch -q $ORIGIN'"
git_do fetch -q "$ORIGIN" >/dev/null 2>&1 || \
die "Could not fetch from $ORIGIN."
echo "Executing Git command 'git remote prune origin'"
git_do remote prune origin >/dev/null 2>&1
require_branch "$ORIGIN/$BRANCH"
# temporarily changing to root directory of git repository
echo "Changing to root directory of Git repository"
cd "$(git rev-parse --show-cdup)"
# create tracking branch
echo "Executing Git command 'git checkout -b $BRANCH $ORIGIN/$BRANCH'"
git_do checkout -b "$BRANCH" "$ORIGIN/$BRANCH" >/dev/null 2>&1
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
echo
echo "Summary of actions:"
echo "- A new local tracking branch '$BRANCH' was created"
echo "- You are now on branch '$BRANCH'"
echo
}
cmd_delete() {
DEFINE_boolean local false "only delete the local branch" l
parse_args "$@"
# sanity checks
# require_branch "$BRANCH"
require_clean_working_tree
# temporarily changing to root directory of git repository
echo "Changing to root directory of Git repository"
cd "$(git rev-parse --show-cdup)"
# change to branch develop
echo "Executing Git command 'git checkout $DEVELOP_BRANCH'"
git_do checkout "$DEVELOP_BRANCH" >/dev/null 2>&1 || \
die "Could not check out $DEVELOP_BRANCH."
# delete local branch
echo "Executing Git command 'git branch -D $BRANCH'"
git_do branch -D "$BRANCH" >/dev/null 2>&1
if ! flag local; then
# make sure that the remote branch should be deleted as well
read -p "Are you sure that you want to delete the remote branch as well (Y/N)? " answer
if [ "$answer" == "y" ] || [ "$answer" == "Y" ] || [ "$answer" == "yes" ] || [ "$answer" == "Yes" ] || [ "$answer" == "YES" ]; then
# delete remote branch
# echo "Executing Git command 'git remote prune origin'"
# git_do remote prune origin >/dev/null 2>&1
echo "Executing Git command 'git push $ORIGIN :refs/heads/$BRANCH'"
git_do push "$ORIGIN" ":refs/heads/$BRANCH" >/dev/null 2>&1
else
answer="false"
fi
fi
# return to previous working directory if available
if assert_dir_existence_and_access "$OLDPWD" >/dev/null 2>&1; then
echo "Returning to previous working directory"
cd "$OLDPWD"
else
echo "Previous working directory no longer available, staying in root directory of Git repository"
fi
echo
echo "Summary of actions:"
echo "- The local branch '$BRANCH' has been deleted"
if ! flag local; then
if [ "$answer" != "false" ]; then
echo "- The remote branch '$ORIGIN/$BRANCH' has been deleted"
fi
fi
echo "- You are now on branch '$DEVELOP_BRANCH'"
echo
}