blob: c7c9a086416f35590a2c32565bb152d1f3a79a60 [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
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010015VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
16PREFIX=$(git config --get gitflow.prefix.release || echo release/)
Vincent Driessen2acfffd2010-01-29 12:37:22 +010017FLAG_FETCH=1
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010018
Benedikt Böhm00ccea62010-01-26 12:39:36 +010019usage() {
Vincent Driessenb866b012010-01-28 01:01:53 +010020 echo "usage: git flow release [list]"
Vincent Driessen170dc742010-01-28 00:20:51 +010021 echo " git flow release start <version>"
22 echo " git flow release finish <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010023 # TODO
24 #echo ""
25 #echo "options:"
26 #echo "--option Explanation"
27 #echo ""
28 #echo "start-only options:"
29 #echo "--bump <script>"
30 #echo " Run the given script to auto-update the version number"
31 #echo ""
32 #echo "finish-only options:"
33 #echo "--push Push to the origin repo when finished"
34}
35
Vincent Driessen170dc742010-01-28 00:20:51 +010036cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010037 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010038}
39
Vincent Driessenb866b012010-01-28 01:01:53 +010040cmd_list() {
Vincent Driessen170dc742010-01-28 00:20:51 +010041 RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
42 if [ -z "$RELEASE_BRANCHES" ]; then
43 warn "No release branches exist."
44 exit 0
45 fi
46 echo "$RELEASE_BRANCHES" | sed "s?^$PREFIX??g"
47}
48
Benedikt Böhm00ccea62010-01-26 12:39:36 +010049cmd_help() {
50 usage
51 exit 0
52}
53
Vincent Driessenb866b012010-01-28 01:01:53 +010054parse_args() {
Vincent Driessen2acfffd2010-01-29 12:37:22 +010055 # TODO: When we have a nice structured way of parsing flags with getopt,
56 # implement the following flags:
57 # --fetch, to set FLAG_FETCH=1
58 # --no-fetch, to set FLAG_FETCH=0
Vincent Driessenb866b012010-01-28 01:01:53 +010059 VERSION="$1"
60 if [ "$VERSION" = "" ]; then
61 echo "Missing argument <version>."
62 usage
63 exit 1
64 fi
65 BRANCH=$PREFIX$VERSION
66}
67
Benedikt Böhm00ccea62010-01-26 12:39:36 +010068cmd_start() {
69 parse_args "$@"
70
71 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +010072 gitflow_require_clean_working_tree
Vincent Driessen2acfffd2010-01-29 12:37:22 +010073 if [ $FLAG_FETCH -eq 1 ]; then
74 git fetch -q $ORIGIN $DEVELOP_BRANCH
75 fi
Benedikt Böhm350e7152010-01-26 13:05:05 +010076 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010077 gitflow_require_branch_absent $BRANCH
78
79 # create branch
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010080 git checkout -b $BRANCH $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010081
82 echo
83 echo "Summary of actions:"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010084 echo "- A new branch '$BRANCH' was created, based on '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010085 echo "- You are now on branch '$BRANCH'"
86 echo
87 echo "Follow-up actions:"
88 echo "- Bump the version number now!"
89 echo "- Start committing last-minute fixes in preparing your release"
90 echo "- When done, run:"
91 echo
92 echo " git flow finish release '$VERSION'"
93 echo
94}
95
96cmd_finish() {
97 parse_args "$@"
98
99 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100100 gitflow_require_clean_working_tree
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100101 if [ $FLAG_FETCH -eq 1 ]; then
102 git fetch -q $ORIGIN $MASTER_BRANCH
103 git fetch -q $ORIGIN $DEVELOP_BRANCH
104 fi
Benedikt Böhm350e7152010-01-26 13:05:05 +0100105 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
106 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100107
108 # merge into master
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100109 git checkout $MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100110 git merge --no-ff $BRANCH
Benedikt Böhmb22a0762010-01-28 01:07:06 +0800111 git tag $VERSION_PREFIX$VERSION
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100112
113 # merge into develop
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100114 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100115 git merge --no-ff $BRANCH
116
117 # delete branch
118 git branch -d $BRANCH
119
120 # TODO: Implement an optional push to master
121 # git push origin develop; git push origin master; git push --tags origin
122
123 echo
124 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100125 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100126 echo "- Release branch has been merged into '$MASTER_BRANCH'"
Vincent Driessen3911e162010-01-27 22:20:47 +0100127 echo "- The release was tagged '$VERSION_PREFIX$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100128 echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100129 echo "- Release branch '$BRANCH' has been deleted"
130 echo
131}