blob: 4a43c8e3cf30b9eef52d7160763d45cd438e7d59 [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:
Vincent Driessenddb350b2010-07-09 09:42:09 +02006# http://nvie.com/git-model
Benedikt Böhm00ccea62010-01-26 12:39:36 +01007#
8# Feel free to contribute to this project at:
9# http://github.com/nvie/gitflow
10#
Vincent Driessend72acba2010-04-04 16:10:17 +020011# Copyright 2010 Vincent Driessen. All rights reserved.
12#
13# Redistribution and use in source and binary forms, with or without
14# modification, are permitted provided that the following conditions are met:
15#
16# 1. Redistributions of source code must retain the above copyright notice,
17# this list of conditions and the following disclaimer.
18#
19# 2. Redistributions in binary form must reproduce the above copyright
20# notice, this list of conditions and the following disclaimer in the
21# documentation and/or other materials provided with the distribution.
22#
23# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
24# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
30# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33#
34# The views and conclusions contained in the software and documentation are
35# those of the authors and should not be interpreted as representing official
36# policies, either expressed or implied, of Vincent Driessen.
Benedikt Böhm00ccea62010-01-26 12:39:36 +010037#
38
pccrdc902ed2012-04-21 00:23:55 -040039init() {
40 require_git_repo
41 require_gitflow_initialized
42 gitflow_load_settings
43 VERSION_PREFIX=$(eval "echo `git config --get gitflow.prefix.versiontag`")
44 PREFIX=$(git config --get gitflow.prefix.release)
45}
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010046
Benedikt Böhm00ccea62010-01-26 12:39:36 +010047usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010048 echo "usage: git flow release [list] [-v]"
Stefan Näwe20743602011-04-15 01:42:35 -070049 echo " git flow release start [-F] <version> [<base>]"
Guillaume-Jean Herbiet8fee0c22010-10-04 11:35:10 +020050 echo " git flow release finish [-Fsumpk] <version>"
Felipe Talaverabbca9222010-09-30 12:25:08 -070051 echo " git flow release publish <name>"
52 echo " git flow release track <name>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010053}
54
Vincent Driessen170dc742010-01-28 00:20:51 +010055cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010056 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010057}
58
Vincent Driessenb866b012010-01-28 01:01:53 +010059cmd_list() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010060 DEFINE_boolean verbose false 'verbose (more) output' v
61 parse_args "$@"
62
Vincent Driessenf46e2902010-02-15 23:01:52 +010063 local release_branches
64 local current_branch
65 local short_names
Vincent Driessen7832d6e2010-02-21 21:31:03 +010066 release_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010067 if [ -z "$release_branches" ]; then
Vincent Driessen170dc742010-01-28 00:20:51 +010068 warn "No release branches exist."
Randy Merrillb681b452010-06-26 13:14:15 +080069 warn ""
70 warn "You can start a new release branch:"
71 warn ""
72 warn " git flow release start <name> [<base>]"
Randy Merrill4de01f22010-06-26 13:19:06 +080073 warn ""
Vincent Driessen170dc742010-01-28 00:20:51 +010074 exit 0
75 fi
Vincent Driessen3c337fb2010-02-04 11:30:18 +010076
Adam Gibbinscf3da5a2010-08-22 19:13:34 +010077 current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
Vincent Driessen68845232010-02-10 00:43:21 +010078 short_names=$(echo "$release_branches" | sed "s ^$PREFIX g")
Vincent Driessen27592dd2010-02-06 14:45:39 +010079
Vincent Driessen3c337fb2010-02-04 11:30:18 +010080 # determine column width first
Vincent Driessenf46e2902010-02-15 23:01:52 +010081 local width=0
82 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010083 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010084 local len=${#branch}
Vincent Driessen3c337fb2010-02-04 11:30:18 +010085 width=$(max $width $len)
86 done
Vincent Driessenf46e2902010-02-15 23:01:52 +010087 width=$(($width+3))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010088
Vincent Driessenf46e2902010-02-15 23:01:52 +010089 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010090 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010091 local fullname=$PREFIX$branch
92 local base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
93 local develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
94 local branch_sha=$(git rev-parse "$fullname")
Vincent Driessen27592dd2010-02-06 14:45:39 +010095 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010096 printf "* "
97 else
98 printf " "
99 fi
100 if flag verbose; then
101 printf "%-${width}s" "$branch"
102 if [ "$branch_sha" = "$develop_sha" ]; then
103 printf "(no commits yet)"
104 else
Vincent Driessenf46e2902010-02-15 23:01:52 +0100105 local nicename=$(git rev-parse --short "$base")
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100106 printf "(based on $nicename)"
107 fi
108 else
109 printf "%s" "$branch"
110 fi
111 echo
112 done
Vincent Driessen170dc742010-01-28 00:20:51 +0100113}
114
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100115cmd_help() {
116 usage
117 exit 0
118}
119
Vincent Driessenb866b012010-01-28 01:01:53 +0100120parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100121 # parse options
122 FLAGS "$@" || exit $?
123 eval set -- "${FLAGS_ARGV}"
124
125 # read arguments into global variables
Vincent Driessenf1eaa4e2011-02-03 16:11:25 +0100126 VERSION=$1
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100127 BRANCH=$PREFIX$VERSION
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100128}
129
130require_version_arg() {
Vincent Driessenb866b012010-01-28 01:01:53 +0100131 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100132 warn "Missing argument <version>"
Vincent Driessenb866b012010-01-28 01:01:53 +0100133 usage
134 exit 1
135 fi
Vincent Driessenb866b012010-01-28 01:01:53 +0100136}
137
Vincent Driessen010252a2010-02-04 10:31:29 +0100138require_base_is_on_develop() {
Adam Gibbinscf3da5a2010-08-22 19:13:34 +0100139 if ! git branch --no-color --contains "$BASE" 2>/dev/null \
Vincent Driessen010252a2010-02-04 10:31:29 +0100140 | sed 's/[* ] //g' \
141 | grep -q "^$DEVELOP_BRANCH\$"; then
142 die "fatal: Given base '$BASE' is not a valid commit on '$DEVELOP_BRANCH'."
143 fi
144}
145
Vincent Driessen6d64d2c2010-02-16 06:41:13 +0100146require_no_existing_release_branches() {
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100147 local release_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen6d64d2c2010-02-16 06:41:13 +0100148 local first_branch=$(echo ${release_branches} | head -n1)
149 first_branch=${first_branch#$PREFIX}
150 [ -z "$release_branches" ] || \
151 die "There is an existing release branch ($first_branch). Finish that one first."
152}
153
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100154cmd_start() {
Vincent Driessende95e002010-07-22 15:11:17 +0200155 DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100156 parse_args "$@"
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100157 BASE=${2:-$DEVELOP_BRANCH}
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100158 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100159 require_base_is_on_develop
Vincent Driessen6d64d2c2010-02-16 06:41:13 +0100160 require_no_existing_release_branches
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100161
162 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100163 require_clean_working_tree
164 require_branch_absent "$BRANCH"
165 require_tag_absent "$VERSION_PREFIX$VERSION"
Vincent Driessenca73caf2010-02-07 19:46:38 +0100166 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100167 git fetch -q "$ORIGIN" "$DEVELOP_BRANCH"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100168 fi
Konstantin Tjuterevf6fcc4e2011-04-14 19:20:19 +0300169 if has "$ORIGIN/$DEVELOP_BRANCH" $(git_remote_branches); then
Vincent Driessende95e002010-07-22 15:11:17 +0200170 require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
171 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100172
173 # create branch
Vincent Driessena4dd2232010-02-10 00:34:59 +0100174 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100175
176 echo
177 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100178 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100179 echo "- You are now on branch '$BRANCH'"
180 echo
181 echo "Follow-up actions:"
182 echo "- Bump the version number now!"
183 echo "- Start committing last-minute fixes in preparing your release"
184 echo "- When done, run:"
185 echo
Vincent Driessen010252a2010-02-04 10:31:29 +0100186 echo " git flow release finish '$VERSION'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100187 echo
188}
189
190cmd_finish() {
Vincent Driessende95e002010-07-22 15:11:17 +0200191 DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100192 DEFINE_boolean sign false "sign the release tag cryptographically" s
193 DEFINE_string signingkey "" "use the given GPG-key for the digital signature (implies -s)" u
194 DEFINE_string message "" "use the given tag message" m
Steve Streeting2e9ab492012-06-08 17:38:34 -0700195 DEFINE_string messagefile "" "use the contents of the given file as a tag message" f
Vincent Driessenddba2df2010-02-19 06:42:18 +0100196 DEFINE_boolean push false "push to $ORIGIN after performing finish" p
Vincent Driessenddd9dfe2010-10-05 12:34:38 +0200197 DEFINE_boolean keep false "keep branch after performing finish" k
Vincent Driessenca8be522010-10-05 14:33:50 +0200198 DEFINE_boolean notag false "don't tag this release" n
Jason L. Shiffer6809f0e2010-02-18 23:57:08 -0500199
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100200 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100201 require_version_arg
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100202
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100203 # handle flags that imply other flags
204 if [ "$FLAGS_signingkey" != "" ]; then
205 FLAGS_sign=$FLAGS_TRUE
206 fi
207
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100208 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100209 require_branch "$BRANCH"
210 require_clean_working_tree
Vincent Driessenca73caf2010-02-07 19:46:38 +0100211 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100212 git fetch -q "$ORIGIN" "$MASTER_BRANCH" || \
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100213 die "Could not fetch $MASTER_BRANCH from $ORIGIN."
Vincent Driessena4dd2232010-02-10 00:34:59 +0100214 git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" || \
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100215 die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100216 fi
Konstantin Tjuterevf6fcc4e2011-04-14 19:20:19 +0300217 if has "$ORIGIN/$MASTER_BRANCH" $(git_remote_branches); then
Vincent Driessende95e002010-07-22 15:11:17 +0200218 require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
219 fi
Konstantin Tjuterevf6fcc4e2011-04-14 19:20:19 +0300220 if has "$ORIGIN/$DEVELOP_BRANCH" $(git_remote_branches); then
Vincent Driessende95e002010-07-22 15:11:17 +0200221 require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
222 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100223
Vincent Driessen5fa47582010-02-09 00:31:33 +0100224 # try to merge into master
225 # in case a previous attempt to finish this release branch has failed,
226 # but the merge into master was successful, we skip it now
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100227 if ! git_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100228 git checkout "$MASTER_BRANCH" || \
Vincent Driessen5fa47582010-02-09 00:31:33 +0100229 die "Could not check out $MASTER_BRANCH."
Vincent Driessena4dd2232010-02-10 00:34:59 +0100230 git merge --no-ff "$BRANCH" || \
Vincent Driessen5fa47582010-02-09 00:31:33 +0100231 die "There were merge conflicts."
232 # TODO: What do we do now?
233 fi
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100234
Vincent Driessenca8be522010-10-05 14:33:50 +0200235 if noflag notag; then
236 # try to tag the release
237 # in case a previous attempt to finish this release branch has failed,
238 # but the tag was set successful, we skip it now
239 local tagname=$VERSION_PREFIX$VERSION
240 if ! git_tag_exists "$tagname"; then
241 local opts="-a"
242 flag sign && opts="$opts -s"
243 [ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'"
244 [ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'"
Steve Streeting2e9ab492012-06-08 17:38:34 -0700245 [ "$FLAGS_messagefile" != "" ] && opts="$opts -F '$FLAGS_messagefile'"
Randy Merrill05c4dbc2011-10-13 20:28:10 -0700246 eval git tag $opts "$tagname" || \
Vincent Driessenca8be522010-10-05 14:33:50 +0200247 die "Tagging failed. Please run finish again to retry."
248 fi
Vincent Driessen5fa47582010-02-09 00:31:33 +0100249 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100250
Vincent Driessen5fa47582010-02-09 00:31:33 +0100251 # try to merge into develop
252 # in case a previous attempt to finish this release branch has failed,
253 # but the merge into develop was successful, we skip it now
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100254 if ! git_is_branch_merged_into "$BRANCH" "$DEVELOP_BRANCH"; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100255 git checkout "$DEVELOP_BRANCH" || \
Vincent Driessen5fa47582010-02-09 00:31:33 +0100256 die "Could not check out $DEVELOP_BRANCH."
Vincent Driessend29e3152010-02-09 00:55:06 +0100257
258 # TODO: Actually, accounting for 'git describe' pays, so we should
259 # ideally git merge --no-ff $tagname here, instead!
Vincent Driessena4dd2232010-02-10 00:34:59 +0100260 git merge --no-ff "$BRANCH" || \
Vincent Driessen5fa47582010-02-09 00:31:33 +0100261 die "There were merge conflicts."
262 # TODO: What do we do now?
263 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100264
265 # delete branch
Vincent Driessenddd9dfe2010-10-05 12:34:38 +0200266 if noflag keep; then
Vincent Driessen46f99982010-10-05 12:45:29 +0200267 if [ "$BRANCH" = "$(git_current_branch)" ]; then
268 git checkout "$MASTER_BRANCH"
269 fi
Guillaume-Jean Herbiet8fee0c22010-10-04 11:35:10 +0200270 git branch -d "$BRANCH"
271 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100272
Vincent Driessenddba2df2010-02-19 06:42:18 +0100273 if flag push; then
274 git push "$ORIGIN" "$DEVELOP_BRANCH" || \
275 die "Could not push to $DEVELOP_BRANCH from $ORIGIN."
276 git push "$ORIGIN" "$MASTER_BRANCH" || \
277 die "Could not push to $MASTER_BRANCH from $ORIGIN."
Vincent Driessenca8be522010-10-05 14:33:50 +0200278 if noflag notag; then
279 git push --tags "$ORIGIN" || \
280 die "Could not push tags to $ORIGIN."
281 fi
Felipe Talavera4c90d922010-09-30 13:30:03 -0700282 git push "$ORIGIN" :"$BRANCH" || \
283 die "Could not delete the remote $BRANCH in $ORIGIN."
Vincent Driessenddba2df2010-02-19 06:42:18 +0100284 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100285
286 echo
287 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100288 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100289 echo "- Release branch has been merged into '$MASTER_BRANCH'"
Vincent Driessenca8be522010-10-05 14:33:50 +0200290 if noflag notag; then
291 echo "- The release was tagged '$tagname'"
292 fi
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100293 echo "- Release branch has been back-merged into '$DEVELOP_BRANCH'"
Guillaume-Jean Herbiet8fee0c22010-10-04 11:35:10 +0200294 if flag keep; then
Vincent Driessenddd9dfe2010-10-05 12:34:38 +0200295 echo "- Release branch '$BRANCH' is still available"
Guillaume-Jean Herbiet8fee0c22010-10-04 11:35:10 +0200296 else
297 echo "- Release branch '$BRANCH' has been deleted"
298 fi
Vincent Driessenddba2df2010-02-19 06:42:18 +0100299 if flag push; then
300 echo "- '$DEVELOP_BRANCH', '$MASTER_BRANCH' and tags have been pushed to '$ORIGIN'"
Felipe Talavera4c90d922010-09-30 13:30:03 -0700301 echo "- Release branch '$BRANCH' in '$ORIGIN' has been deleted."
Vincent Driessenddba2df2010-02-19 06:42:18 +0100302 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100303 echo
304}
Felipe Talaverafbcf4a02010-09-30 12:03:01 -0700305
306cmd_publish() {
307 parse_args "$@"
Felipe Talaveradf706ac2010-09-30 13:11:34 -0700308 require_version_arg
Felipe Talaverafbcf4a02010-09-30 12:03:01 -0700309
310 # sanity checks
311 require_clean_working_tree
312 require_branch "$BRANCH"
313 git fetch -q "$ORIGIN"
314 require_branch_absent "$ORIGIN/$BRANCH"
315
316 # create remote branch
317 git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
318 git fetch -q "$ORIGIN"
319
320 # configure remote tracking
321 git config "branch.$BRANCH.remote" "$ORIGIN"
322 git config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
323 git checkout "$BRANCH"
324
325 echo
326 echo "Summary of actions:"
327 echo "- A new remote branch '$BRANCH' was created"
328 echo "- The local branch '$BRANCH' was configured to track the remote branch"
329 echo "- You are now on branch '$BRANCH'"
330 echo
331}
332
333cmd_track() {
334 parse_args "$@"
Felipe Talaveradf706ac2010-09-30 13:11:34 -0700335 require_version_arg
Felipe Talaverafbcf4a02010-09-30 12:03:01 -0700336
337 # sanity checks
338 require_clean_working_tree
339 require_branch_absent "$BRANCH"
340 git fetch -q "$ORIGIN"
341 require_branch "$ORIGIN/$BRANCH"
342
343 # create tracking branch
344 git checkout -b "$BRANCH" "$ORIGIN/$BRANCH"
345
346 echo
347 echo "Summary of actions:"
348 echo "- A new remote tracking branch '$BRANCH' was created"
349 echo "- You are now on branch '$BRANCH'"
350 echo
351}