blob: b5f595934a0415163c21c5bb2b2a94637b1d26b5 [file] [log] [blame]
Benedikt Böhm00ccea62010-01-26 12:39:36 +01001#
Vincent Driessen6c2d30b2010-01-26 22:18:36 +01002# git-flow -- A collection of Git extensions to provide high-level
3# repository operations for Vincent Driessen's branching model.
Benedikt Böhm00ccea62010-01-26 12:39:36 +01004#
5# Original blog post presenting this model is found at:
6# http://nvie.com/archives/323
7#
8# Feel free to contribute to this project at:
9# http://github.com/nvie/gitflow
10#
11# Copyright (c) 2010 by Vincent Driessen
12# Copyright (c) 2010 by Benedikt Böhm
13#
14
15usage() {
Vincent Driessenb866b012010-01-28 01:01:53 +010016 echo "usage: git flow release [list]"
Vincent Driessen170dc742010-01-28 00:20:51 +010017 echo " git flow release start <version>"
18 echo " git flow release finish <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010019 # TODO
20 #echo ""
21 #echo "options:"
22 #echo "--option Explanation"
23 #echo ""
24 #echo "start-only options:"
25 #echo "--bump <script>"
26 #echo " Run the given script to auto-update the version number"
27 #echo ""
28 #echo "finish-only options:"
29 #echo "--push Push to the origin repo when finished"
30}
31
Vincent Driessenb866b012010-01-28 01:01:53 +010032# setup will always be called before the actual cmd_* functions
33setup() {
Benedikt Böhm96f44c02010-01-26 13:09:32 +010034 PREFIX=$(git config --get gitflow.prefix.release || echo release/)
Vincent Driessenb866b012010-01-28 01:01:53 +010035 VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
Benedikt Böhm00ccea62010-01-26 12:39:36 +010036}
37
Vincent Driessen170dc742010-01-28 00:20:51 +010038cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010039 cmd_list "$@"
40}
41
42cmd_list() {
Vincent Driessen170dc742010-01-28 00:20:51 +010043 RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
44 if [ -z "$RELEASE_BRANCHES" ]; then
45 warn "No release branches exist."
46 exit 0
47 fi
48 echo "$RELEASE_BRANCHES" | sed "s?^$PREFIX??g"
49}
50
Benedikt Böhm00ccea62010-01-26 12:39:36 +010051cmd_help() {
52 usage
53 exit 0
54}
55
Vincent Driessenb866b012010-01-28 01:01:53 +010056parse_args() {
57 VERSION="$1"
58 if [ "$VERSION" = "" ]; then
59 echo "Missing argument <version>."
60 usage
61 exit 1
62 fi
63 BRANCH=$PREFIX$VERSION
64}
65
Benedikt Böhm00ccea62010-01-26 12:39:36 +010066cmd_start() {
67 parse_args "$@"
68
69 # sanity checks
70 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010071 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010072 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010073 gitflow_require_branch_absent $BRANCH
74
75 # create branch
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010076 git checkout -b $BRANCH $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010077
78 echo
79 echo "Summary of actions:"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010080 echo "- A new branch '$BRANCH' was created, based on '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010081 echo "- You are now on branch '$BRANCH'"
82 echo
83 echo "Follow-up actions:"
84 echo "- Bump the version number now!"
85 echo "- Start committing last-minute fixes in preparing your release"
86 echo "- When done, run:"
87 echo
88 echo " git flow finish release '$VERSION'"
89 echo
90}
91
92cmd_finish() {
93 parse_args "$@"
94
95 # sanity checks
96 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010097 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010098 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
99 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100100
101 # merge into master
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100102 git checkout $MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100103 git merge --no-ff $BRANCH
Benedikt Böhmb22a0762010-01-28 01:07:06 +0800104 git tag $VERSION_PREFIX$VERSION
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100105
106 # merge into develop
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100107 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100108 git merge --no-ff $BRANCH
109
110 # delete branch
111 git branch -d $BRANCH
112
113 # TODO: Implement an optional push to master
114 # git push origin develop; git push origin master; git push --tags origin
115
116 echo
117 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100118 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100119 echo "- Release branch has been merged into '$MASTER_BRANCH'"
Vincent Driessen3911e162010-01-27 22:20:47 +0100120 echo "- The release was tagged '$VERSION_PREFIX$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100121 echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100122 echo "- Release branch '$BRANCH' has been deleted"
123 echo
124}