blob: c37be771d6428014f7e12e05e7c0c3260d8653f2 [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
Vincent Driessen7832d6e2010-02-21 21:31:03 +010039require_git_repo
40require_gitflow_initialized
Vincent Driessend72e4ac2010-02-16 21:33:51 +010041gitflow_load_settings
Nowell Striteff275fa2010-09-22 13:19:30 -040042VERSION_PREFIX=$(eval "echo `git config --get gitflow.prefix.versiontag`")
Vincent Driessenc1598bf2010-02-20 16:52:48 +010043PREFIX=$(git config --get gitflow.prefix.hotfix)
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010044
Benedikt Böhm00ccea62010-01-26 12:39:36 +010045usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010046 echo "usage: git flow hotfix [list] [-v]"
Vincent Driessena2e41162010-02-24 01:37:07 +010047 echo " git flow hotfix start [-F] <version> [<base>]"
Guillaume-Jean Herbiet8fee0c22010-10-04 11:35:10 +020048 echo " git flow hotfix finish [-Fsumpk] <version>"
Peter Schröder0b324de2011-11-12 17:36:36 +010049 echo " git flow hotfix publish <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010050}
51
Vincent Driessen186d2b52010-01-27 23:48:39 +010052cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010053 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010054}
55
Vincent Driessenb866b012010-01-28 01:01:53 +010056cmd_list() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010057 DEFINE_boolean verbose false 'verbose (more) output' v
58 parse_args "$@"
59
Vincent Driessenf46e2902010-02-15 23:01:52 +010060 local hotfix_branches
61 local current_branch
62 local short_names
Vincent Driessen7832d6e2010-02-21 21:31:03 +010063 hotfix_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010064 if [ -z "$hotfix_branches" ]; then
Vincent Driessen186d2b52010-01-27 23:48:39 +010065 warn "No hotfix branches exist."
Randy Merrillb681b452010-06-26 13:14:15 +080066 warn ""
67 warn "You can start a new hotfix branch:"
68 warn ""
Stefan Schüßlerc4d0cb12010-12-02 18:55:06 +080069 warn " git flow hotfix start <version> [<base>]"
Randy Merrill4de01f22010-06-26 13:19:06 +080070 warn ""
Vincent Driessen186d2b52010-01-27 23:48:39 +010071 exit 0
72 fi
Adam Gibbinscf3da5a2010-08-22 19:13:34 +010073 current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
Vincent Driessen68845232010-02-10 00:43:21 +010074 short_names=$(echo "$hotfix_branches" | sed "s ^$PREFIX g")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010075
Vincent Driessen3c337fb2010-02-04 11:30:18 +010076 # determine column width first
Vincent Driessenf46e2902010-02-15 23:01:52 +010077 local width=0
78 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010079 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010080 local len=${#branch}
Vincent Driessen3c337fb2010-02-04 11:30:18 +010081 width=$(max $width $len)
82 done
Vincent Driessenf46e2902010-02-15 23:01:52 +010083 width=$(($width+3))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010084
Vincent Driessenf46e2902010-02-15 23:01:52 +010085 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010086 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010087 local fullname=$PREFIX$branch
88 local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
89 local master_sha=$(git rev-parse "$MASTER_BRANCH")
90 local branch_sha=$(git rev-parse "$fullname")
Vincent Driessen27592dd2010-02-06 14:45:39 +010091 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010092 printf "* "
93 else
94 printf " "
95 fi
96 if flag verbose; then
97 printf "%-${width}s" "$branch"
98 if [ "$branch_sha" = "$master_sha" ]; then
99 printf "(no commits yet)"
100 else
Vincent Driessenf46e2902010-02-15 23:01:52 +0100101 local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
102 local nicename
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100103 if [ "$tagname" != "" ]; then
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100104 nicename=$tagname
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100105 else
Vincent Driessena4dd2232010-02-10 00:34:59 +0100106 nicename=$(git rev-parse --short "$base")
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100107 fi
108 printf "(based on $nicename)"
109 fi
110 else
111 printf "%s" "$branch"
112 fi
113 echo
114 done
Vincent Driessen186d2b52010-01-27 23:48:39 +0100115}
116
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100117cmd_help() {
118 usage
119 exit 0
120}
121
Vincent Driessenb866b012010-01-28 01:01:53 +0100122parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100123 # parse options
124 FLAGS "$@" || exit $?
125 eval set -- "${FLAGS_ARGV}"
126
127 # read arguments into global variables
Vincent Driessenf1eaa4e2011-02-03 16:11:25 +0100128 VERSION=$1
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100129 BRANCH=$PREFIX$VERSION
130}
131
132require_version_arg() {
Vincent Driessenb866b012010-01-28 01:01:53 +0100133 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100134 warn "Missing argument <version>"
Vincent Driessenb866b012010-01-28 01:01:53 +0100135 usage
136 exit 1
137 fi
Vincent Driessenb866b012010-01-28 01:01:53 +0100138}
139
Vincent Driessen010252a2010-02-04 10:31:29 +0100140require_base_is_on_master() {
Adam Gibbinscf3da5a2010-08-22 19:13:34 +0100141 if ! git branch --no-color --contains "$BASE" 2>/dev/null \
Vincent Driessen010252a2010-02-04 10:31:29 +0100142 | sed 's/[* ] //g' \
143 | grep -q "^$MASTER_BRANCH\$"; then
144 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
145 fi
146}
147
Vincent Driessen6d64d2c2010-02-16 06:41:13 +0100148require_no_existing_hotfix_branches() {
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100149 local hotfix_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen6d64d2c2010-02-16 06:41:13 +0100150 local first_branch=$(echo ${hotfix_branches} | head -n1)
151 first_branch=${first_branch#$PREFIX}
152 [ -z "$hotfix_branches" ] || \
153 die "There is an existing hotfix branch ($first_branch). Finish that one first."
154}
155
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100156cmd_start() {
Vincent Driessende95e002010-07-22 15:11:17 +0200157 DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100158 parse_args "$@"
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100159 BASE=${2:-$MASTER_BRANCH}
Vincent Driessen010252a2010-02-04 10:31:29 +0100160 require_version_arg
161 require_base_is_on_master
Vincent Driessen6d64d2c2010-02-16 06:41:13 +0100162 require_no_existing_hotfix_branches
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100163
164 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100165 require_clean_working_tree
166 require_branch_absent "$BRANCH"
167 require_tag_absent "$VERSION_PREFIX$VERSION"
Vincent Driessenca73caf2010-02-07 19:46:38 +0100168 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100169 git fetch -q "$ORIGIN" "$MASTER_BRANCH"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100170 fi
Konstantin Tjuterevf6fcc4e2011-04-14 19:20:19 +0300171 if has "$ORIGIN/$MASTER_BRANCH" $(git_remote_branches); then
Vincent Driessende95e002010-07-22 15:11:17 +0200172 require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
173 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100174
175 # create branch
Vincent Driessena4dd2232010-02-10 00:34:59 +0100176 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100177
178 echo
179 echo "Summary of actions:"
180 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
181 echo "- You are now on branch '$BRANCH'"
182 echo
183 echo "Follow-up actions:"
184 echo "- Bump the version number now!"
185 echo "- Start committing your hot fixes"
186 echo "- When done, run:"
187 echo
Vincent Driessen010252a2010-02-04 10:31:29 +0100188 echo " git flow hotfix finish '$VERSION'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100189 echo
190}
191
Peter Schröder0b324de2011-11-12 17:36:36 +0100192cmd_publish() {
193 parse_args "$@"
194 require_version_arg
195
196 # sanity checks
197 require_clean_working_tree
198 require_branch "$BRANCH"
199 git fetch -q "$ORIGIN"
200 require_branch_absent "$ORIGIN/$BRANCH"
201
202 # create remote branch
203 git push "$ORIGIN" "$BRANCH:refs/heads/$BRANCH"
204 git fetch -q "$ORIGIN"
205
206 # configure remote tracking
207 git config "branch.$BRANCH.remote" "$ORIGIN"
208 git config "branch.$BRANCH.merge" "refs/heads/$BRANCH"
209 git checkout "$BRANCH"
210
211 echo
212 echo "Summary of actions:"
213 echo "- A new remote branch '$BRANCH' was created"
214 echo "- The local branch '$BRANCH' was configured to track the remote branch"
215 echo "- You are now on branch '$BRANCH'"
216 echo
217}
218
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100219cmd_finish() {
Vincent Driessende95e002010-07-22 15:11:17 +0200220 DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100221 DEFINE_boolean sign false "sign the release tag cryptographically" s
222 DEFINE_string signingkey "" "use the given GPG-key for the digital signature (implies -s)" u
223 DEFINE_string message "" "use the given tag message" m
Steve Streeting2e9ab492012-06-08 17:38:34 -0700224 DEFINE_string messagefile "" "use the contents of the given file as tag message" f
Vincent Driessenddba2df2010-02-19 06:42:18 +0100225 DEFINE_boolean push false "push to $ORIGIN after performing finish" p
Vincent Driessenddd9dfe2010-10-05 12:34:38 +0200226 DEFINE_boolean keep false "keep branch after performing finish" k
Vincent Driessenca8be522010-10-05 14:33:50 +0200227 DEFINE_boolean notag false "don't tag this release" n
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100228 parse_args "$@"
Vincent Driessen010252a2010-02-04 10:31:29 +0100229 require_version_arg
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100230
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100231 # handle flags that imply other flags
232 if [ "$FLAGS_signingkey" != "" ]; then
233 FLAGS_sign=$FLAGS_TRUE
234 fi
235
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100236 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100237 require_branch "$BRANCH"
238 require_clean_working_tree
Vincent Driessenca73caf2010-02-07 19:46:38 +0100239 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100240 git fetch -q "$ORIGIN" "$MASTER_BRANCH" || \
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100241 die "Could not fetch $MASTER_BRANCH from $ORIGIN."
Vincent Driessena4dd2232010-02-10 00:34:59 +0100242 git fetch -q "$ORIGIN" "$DEVELOP_BRANCH" || \
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100243 die "Could not fetch $DEVELOP_BRANCH from $ORIGIN."
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100244 fi
Konstantin Tjuterevf6fcc4e2011-04-14 19:20:19 +0300245 if has "$ORIGIN/$MASTER_BRANCH" $(git_remote_branches); then
Vincent Driessende95e002010-07-22 15:11:17 +0200246 require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH"
247 fi
Konstantin Tjuterevf6fcc4e2011-04-14 19:20:19 +0300248 if has "$ORIGIN/$DEVELOP_BRANCH" $(git_remote_branches); then
Vincent Driessende95e002010-07-22 15:11:17 +0200249 require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
250 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100251
Vincent Driessen5fa47582010-02-09 00:31:33 +0100252 # try to merge into master
253 # in case a previous attempt to finish this release branch has failed,
254 # but the merge into master was successful, we skip it now
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100255 if ! git_is_branch_merged_into "$BRANCH" "$MASTER_BRANCH"; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100256 git checkout "$MASTER_BRANCH" || \
Vincent Driessen5fa47582010-02-09 00:31:33 +0100257 die "Could not check out $MASTER_BRANCH."
Vincent Driessena4dd2232010-02-10 00:34:59 +0100258 git merge --no-ff "$BRANCH" || \
Vincent Driessen5fa47582010-02-09 00:31:33 +0100259 die "There were merge conflicts."
260 # TODO: What do we do now?
261 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100262
Vincent Driessenca8be522010-10-05 14:33:50 +0200263 if noflag notag; then
264 # try to tag the release
265 # in case a previous attempt to finish this release branch has failed,
266 # but the tag was set successful, we skip it now
267 local tagname=$VERSION_PREFIX$VERSION
268 if ! git_tag_exists "$tagname"; then
269 local opts="-a"
270 flag sign && opts="$opts -s"
271 [ "$FLAGS_signingkey" != "" ] && opts="$opts -u '$FLAGS_signingkey'"
272 [ "$FLAGS_message" != "" ] && opts="$opts -m '$FLAGS_message'"
Steve Streeting2e9ab492012-06-08 17:38:34 -0700273 [ "$FLAGS_messagefile" != "" ] && opts="$opts -F '$FLAGS_messagefile'"
Randy Merrilld0df88d2011-10-13 21:09:26 -0700274 eval git tag $opts "$VERSION_PREFIX$VERSION" || \
Vincent Driessenca8be522010-10-05 14:33:50 +0200275 die "Tagging failed. Please run finish again to retry."
276 fi
Vincent Driessen5fa47582010-02-09 00:31:33 +0100277 fi
Vincent Driessen1a2868b2010-02-07 23:23:16 +0100278
Vincent Driessen5fa47582010-02-09 00:31:33 +0100279 # try to merge into develop
280 # in case a previous attempt to finish this release branch has failed,
281 # but the merge into develop was successful, we skip it now
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100282 if ! git_is_branch_merged_into "$BRANCH" "$DEVELOP_BRANCH"; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100283 git checkout "$DEVELOP_BRANCH" || \
Vincent Driessen5fa47582010-02-09 00:31:33 +0100284 die "Could not check out $DEVELOP_BRANCH."
285
Vincent Driessend29e3152010-02-09 00:55:06 +0100286 # TODO: Actually, accounting for 'git describe' pays, so we should
287 # ideally git merge --no-ff $tagname here, instead!
Vincent Driessena4dd2232010-02-10 00:34:59 +0100288 git merge --no-ff "$BRANCH" || \
Vincent Driessen5fa47582010-02-09 00:31:33 +0100289 die "There were merge conflicts."
290 # TODO: What do we do now?
291 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100292
293 # delete branch
Vincent Driessenddd9dfe2010-10-05 12:34:38 +0200294 if noflag keep; then
Guillaume-Jean Herbiet8fee0c22010-10-04 11:35:10 +0200295 git branch -d "$BRANCH"
296 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100297
Vincent Driessenddba2df2010-02-19 06:42:18 +0100298 if flag push; then
299 git push "$ORIGIN" "$DEVELOP_BRANCH" || \
300 die "Could not push to $DEVELOP_BRANCH from $ORIGIN."
301 git push "$ORIGIN" "$MASTER_BRANCH" || \
302 die "Could not push to $MASTER_BRANCH from $ORIGIN."
Vincent Driessenca8be522010-10-05 14:33:50 +0200303 if noflag notag; then
304 git push --tags "$ORIGIN" || \
305 die "Could not push tags to $ORIGIN."
306 fi
Vincent Driessenddba2df2010-02-19 06:42:18 +0100307 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100308
309 echo
310 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100311 echo "- Latest objects have been fetched from '$ORIGIN'"
Vincent Driessen010252a2010-02-04 10:31:29 +0100312 echo "- Hotfix branch has been merged into '$MASTER_BRANCH'"
Vincent Driessenca8be522010-10-05 14:33:50 +0200313 if noflag notag; then
314 echo "- The hotfix was tagged '$VERSION_PREFIX$VERSION'"
315 fi
Vincent Driessen010252a2010-02-04 10:31:29 +0100316 echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
Guillaume-Jean Herbiet8fee0c22010-10-04 11:35:10 +0200317 if flag keep; then
Vincent Driessenddd9dfe2010-10-05 12:34:38 +0200318 echo "- Hotfix branch '$BRANCH' is still available"
Guillaume-Jean Herbiet8fee0c22010-10-04 11:35:10 +0200319 else
320 echo "- Hotfix branch '$BRANCH' has been deleted"
321 fi
Vincent Driessenddba2df2010-02-19 06:42:18 +0100322 if flag push; then
323 echo "- '$DEVELOP_BRANCH', '$MASTER_BRANCH' and tags have been pushed to '$ORIGIN'"
324 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100325 echo
326}