blob: 1fec600358b0101f4d1c44116c13c50072e887af [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 Driessen170dc742010-01-28 00:20:51 +010016 echo "usage: git flow release"
17 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
32parse_args() {
Benedikt Böhmb22a0762010-01-28 01:07:06 +080033 VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
Benedikt Böhm00ccea62010-01-26 12:39:36 +010034 VERSION="$1"
35 if [ "$VERSION" = "" ]; then
36 echo "Missing argument <version>."
37 usage
38 exit 1
39 fi
Benedikt Böhm96f44c02010-01-26 13:09:32 +010040 PREFIX=$(git config --get gitflow.prefix.release || echo release/)
41 BRANCH=$PREFIX$VERSION
Benedikt Böhm00ccea62010-01-26 12:39:36 +010042}
43
Vincent Driessen170dc742010-01-28 00:20:51 +010044cmd_default() {
45 # TODO: Refactor getting this prefix into a general function
46 PREFIX=$(git config --get gitflow.prefix.release || echo release/)
47 RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
48 if [ -z "$RELEASE_BRANCHES" ]; then
49 warn "No release branches exist."
50 exit 0
51 fi
52 echo "$RELEASE_BRANCHES" | sed "s?^$PREFIX??g"
53}
54
Benedikt Böhm00ccea62010-01-26 12:39:36 +010055cmd_help() {
56 usage
57 exit 0
58}
59
60cmd_start() {
61 parse_args "$@"
62
63 # sanity checks
64 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010065 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010066 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010067 gitflow_require_branch_absent $BRANCH
68
69 # create branch
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010070 git checkout -b $BRANCH $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010071
72 echo
73 echo "Summary of actions:"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010074 echo "- A new branch '$BRANCH' was created, based on '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010075 echo "- You are now on branch '$BRANCH'"
76 echo
77 echo "Follow-up actions:"
78 echo "- Bump the version number now!"
79 echo "- Start committing last-minute fixes in preparing your release"
80 echo "- When done, run:"
81 echo
82 echo " git flow finish release '$VERSION'"
83 echo
84}
85
86cmd_finish() {
87 parse_args "$@"
88
89 # sanity checks
90 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010091 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010092 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
93 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010094
95 # merge into master
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010096 git checkout $MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010097 git merge --no-ff $BRANCH
Benedikt Böhmb22a0762010-01-28 01:07:06 +080098 git tag $VERSION_PREFIX$VERSION
Benedikt Böhm00ccea62010-01-26 12:39:36 +010099
100 # merge into develop
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100101 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100102 git merge --no-ff $BRANCH
103
104 # delete branch
105 git branch -d $BRANCH
106
107 # TODO: Implement an optional push to master
108 # git push origin develop; git push origin master; git push --tags origin
109
110 echo
111 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100112 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100113 echo "- Release branch has been merged into '$MASTER_BRANCH'"
Vincent Driessen3911e162010-01-27 22:20:47 +0100114 echo "- The release was tagged '$VERSION_PREFIX$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100115 echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100116 echo "- Release branch '$BRANCH' has been deleted"
117 echo
118}