blob: ba4d92f2f1cc54c26b549edbb21f66599df13f66 [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.support)
45}
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010046
Vincent Driessen3c337fb2010-02-04 11:30:18 +010047warn "note: The support subcommand is still very EXPERIMENTAL!"
48warn "note: DO NOT use it in a production situation."
49
Benedikt Böhm00ccea62010-01-26 12:39:36 +010050usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010051 echo "usage: git flow support [list] [-v]"
Vincent Driessena2e41162010-02-24 01:37:07 +010052 echo " git flow support start [-F] <version> <base>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010053}
54
Vincent Driessenb866b012010-01-28 01:01:53 +010055cmd_default() {
56 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 support_branches
64 local current_branch
65 local short_names
Vincent Driessen7832d6e2010-02-21 21:31:03 +010066 support_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010067 if [ -z "$support_branches" ]; then
Vincent Driessen170dc742010-01-28 00:20:51 +010068 warn "No support branches exist."
Randy Merrillb681b452010-06-26 13:14:15 +080069 warn ""
70 warn "You can start a new support branch:"
71 warn ""
72 warn " git flow support start <name> <base>"
Randy Merrill4de01f22010-06-26 13:19:06 +080073 warn ""
Vincent Driessen170dc742010-01-28 00:20:51 +010074 exit 0
75 fi
Adam Gibbinscf3da5a2010-08-22 19:13:34 +010076 current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
Vincent Driessen68845232010-02-10 00:43:21 +010077 short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010078
Vincent Driessen3c337fb2010-02-04 11:30:18 +010079 # determine column width first
Vincent Driessenf46e2902010-02-15 23:01:52 +010080 local width=0
81 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010082 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010083 local len=${#branch}
Vincent Driessen3c337fb2010-02-04 11:30:18 +010084 width=$(max $width $len)
85 done
Vincent Driessenf46e2902010-02-15 23:01:52 +010086 width=$(($width+3))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010087
Vincent Driessenf46e2902010-02-15 23:01:52 +010088 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010089 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010090 local fullname=$PREFIX$branch
91 local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
92 local master_sha=$(git rev-parse "$MASTER_BRANCH")
93 local branch_sha=$(git rev-parse "$fullname")
Vincent Driessen27592dd2010-02-06 14:45:39 +010094 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010095 printf "* "
96 else
97 printf " "
98 fi
99 if flag verbose; then
100 printf "%-${width}s" "$branch"
101 if [ "$branch_sha" = "$master_sha" ]; then
102 printf "(no commits yet)"
103 else
Vincent Driessenf46e2902010-02-15 23:01:52 +0100104 local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
105 local nicename
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100106 if [ "$tagname" != "" ]; then
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100107 nicename=$tagname
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100108 else
Vincent Driessena4dd2232010-02-10 00:34:59 +0100109 nicename=$(git rev-parse --short "$base")
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100110 fi
111 printf "(based on $nicename)"
112 fi
113 else
114 printf "%s" "$branch"
115 fi
116 echo
117 done
Vincent Driessen170dc742010-01-28 00:20:51 +0100118}
119
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100120cmd_help() {
121 usage
122 exit 0
123}
124
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100125parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100126 # parse options
127 FLAGS "$@" || exit $?
128 eval set -- "${FLAGS_ARGV}"
129
130 # read arguments into global variables
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100131 VERSION=$1
132 BASE=$2
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100133 BRANCH=$PREFIX$VERSION
134}
135
136require_version_arg() {
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100137 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100138 warn "Missing argument <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100139 usage
140 exit 1
141 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100142}
143
Vincent Driessen010252a2010-02-04 10:31:29 +0100144require_base_arg() {
145 if [ "$BASE" = "" ]; then
146 warn "Missing argument <base>"
147 usage
148 exit 1
149 fi
150}
151
152require_base_is_on_master() {
Adam Gibbinscf3da5a2010-08-22 19:13:34 +0100153 if ! git branch --no-color --contains "$BASE" 2>/dev/null \
Vincent Driessen010252a2010-02-04 10:31:29 +0100154 | sed 's/[* ] //g' \
155 | grep -q "^$MASTER_BRANCH\$"; then
156 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
157 fi
158}
159
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100160cmd_start() {
Vincent Driessende95e002010-07-22 15:11:17 +0200161 DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100162 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100163 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100164 require_base_arg
165 require_base_is_on_master
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100166
167 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100168 require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100169
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100170 # fetch remote changes
Vincent Driessenca73caf2010-02-07 19:46:38 +0100171 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100172 git fetch -q "$ORIGIN" "$BASE"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100173 fi
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100174 require_branch_absent "$BRANCH"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100175
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100176 # create branch
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100177 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100178
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100179 echo
180 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100181 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100182 echo "- You are now on branch '$BRANCH'"
183 echo
184}