blob: b23914e676c593357e39f11ec94d63bab035102e [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 Driessen3c337fb2010-02-04 11:30:18 +010020 echo "usage: git flow release [list] [-v]"
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 Driessen3c337fb2010-02-04 11:30:18 +010041 DEFINE_boolean verbose false 'verbose (more) output' v
42 parse_args "$@"
43
Vincent Driessen27592dd2010-02-06 14:45:39 +010044 typeset release_branches
45 typeset current_branch
46 typeset short_names
47 release_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
48 if [ -z "$release_branches" ]; then
Vincent Driessen170dc742010-01-28 00:20:51 +010049 warn "No release branches exist."
50 exit 0
51 fi
Vincent Driessen3c337fb2010-02-04 11:30:18 +010052
Vincent Driessen27592dd2010-02-06 14:45:39 +010053 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
54 short_names=$(echo "$release_branches" | sed "s?^$PREFIX??g")
55
Vincent Driessen3c337fb2010-02-04 11:30:18 +010056 # determine column width first
Vincent Driessen27592dd2010-02-06 14:45:39 +010057 typeset -i width=0
58 typeset branch
59 for branch in $short_names; do
60 typeset -i len=$(($(echo "$branch" | wc -c) - 1))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010061 width=$(max $width $len)
62 done
Vincent Driessen27592dd2010-02-06 14:45:39 +010063 width=width+3
Vincent Driessen3c337fb2010-02-04 11:30:18 +010064
Vincent Driessen27592dd2010-02-06 14:45:39 +010065 typeset branch
66 for branch in $short_names; do
67 typeset fullname="$PREFIX$branch"
68 typeset base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
69 typeset develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
70 typeset branch_sha=$(git rev-parse "$fullname")
71 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010072 printf "* "
73 else
74 printf " "
75 fi
76 if flag verbose; then
77 printf "%-${width}s" "$branch"
78 if [ "$branch_sha" = "$develop_sha" ]; then
79 printf "(no commits yet)"
80 else
Vincent Driessen27592dd2010-02-06 14:45:39 +010081 typeset nicename="$(git rev-parse --short $base)"
Vincent Driessen3c337fb2010-02-04 11:30:18 +010082 printf "(based on $nicename)"
83 fi
84 else
85 printf "%s" "$branch"
86 fi
87 echo
88 done
Vincent Driessen170dc742010-01-28 00:20:51 +010089}
90
Benedikt Böhm00ccea62010-01-26 12:39:36 +010091cmd_help() {
92 usage
93 exit 0
94}
95
Vincent Driessenb866b012010-01-28 01:01:53 +010096parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010097 # parse options
98 FLAGS "$@" || exit $?
99 eval set -- "${FLAGS_ARGV}"
100
101 # read arguments into global variables
Vincent Driessenb866b012010-01-28 01:01:53 +0100102 VERSION="$1"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100103 BRANCH="$PREFIX$VERSION"
104}
105
106require_version_arg() {
Vincent Driessenb866b012010-01-28 01:01:53 +0100107 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100108 warn "Missing argument <version>"
Vincent Driessenb866b012010-01-28 01:01:53 +0100109 usage
110 exit 1
111 fi
Vincent Driessenb866b012010-01-28 01:01:53 +0100112}
113
Vincent Driessen010252a2010-02-04 10:31:29 +0100114require_base_is_on_develop() {
115 if ! git branch --contains "$BASE" 2>/dev/null \
116 | sed 's/[* ] //g' \
117 | grep -q "^$DEVELOP_BRANCH\$"; then
118 die "fatal: Given base '$BASE' is not a valid commit on '$DEVELOP_BRANCH'."
119 fi
120}
121
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100122cmd_start() {
123 parse_args "$@"
Vincent Driessen010252a2010-02-04 10:31:29 +0100124 BASE="${2:-$DEVELOP_BRANCH}"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100125 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100126 require_base_is_on_develop
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100127
128 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100129 gitflow_require_clean_working_tree
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100130 if [ $FLAG_FETCH -eq 1 ]; then
131 git fetch -q $ORIGIN $DEVELOP_BRANCH
132 fi
Benedikt Böhm350e7152010-01-26 13:05:05 +0100133 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100134 gitflow_require_branch_absent $BRANCH
135
136 # create branch
Vincent Driessen010252a2010-02-04 10:31:29 +0100137 git checkout -b $BRANCH $BASE
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100138
139 echo
140 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100141 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100142 echo "- You are now on branch '$BRANCH'"
143 echo
144 echo "Follow-up actions:"
145 echo "- Bump the version number now!"
146 echo "- Start committing last-minute fixes in preparing your release"
147 echo "- When done, run:"
148 echo
Vincent Driessen010252a2010-02-04 10:31:29 +0100149 echo " git flow release finish '$VERSION'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100150 echo
151}
152
153cmd_finish() {
154 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100155 require_version_arg
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100156
157 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100158 gitflow_require_clean_working_tree
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100159 if [ $FLAG_FETCH -eq 1 ]; then
160 git fetch -q $ORIGIN $MASTER_BRANCH
161 git fetch -q $ORIGIN $DEVELOP_BRANCH
162 fi
Benedikt Böhm350e7152010-01-26 13:05:05 +0100163 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
164 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100165
166 # merge into master
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100167 git checkout $MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100168 git merge --no-ff $BRANCH
Benedikt Böhmb22a0762010-01-28 01:07:06 +0800169 git tag $VERSION_PREFIX$VERSION
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100170
171 # merge into develop
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100172 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100173 git merge --no-ff $BRANCH
174
175 # delete branch
176 git branch -d $BRANCH
177
178 # TODO: Implement an optional push to master
179 # git push origin develop; git push origin master; git push --tags origin
180
181 echo
182 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100183 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100184 echo "- Release branch has been merged into '$MASTER_BRANCH'"
Vincent Driessen3911e162010-01-27 22:20:47 +0100185 echo "- The release was tagged '$VERSION_PREFIX$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100186 echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100187 echo "- Release branch '$BRANCH' has been deleted"
188 echo
189}