blob: 605694dc941bdf42c87f6e352bebe91e374f1ffc [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.support)
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010044
Vincent Driessen3c337fb2010-02-04 11:30:18 +010045warn "note: The support subcommand is still very EXPERIMENTAL!"
46warn "note: DO NOT use it in a production situation."
47
Benedikt Böhm00ccea62010-01-26 12:39:36 +010048usage() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010049 echo "usage: git flow support [list] [-v]"
Vincent Driessena2e41162010-02-24 01:37:07 +010050 echo " git flow support start [-F] <version> <base>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010051}
52
Vincent Driessenb866b012010-01-28 01:01:53 +010053cmd_default() {
54 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010055}
56
Vincent Driessenb866b012010-01-28 01:01:53 +010057cmd_list() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +010058 DEFINE_boolean verbose false 'verbose (more) output' v
59 parse_args "$@"
60
Vincent Driessenf46e2902010-02-15 23:01:52 +010061 local support_branches
62 local current_branch
63 local short_names
Vincent Driessen7832d6e2010-02-21 21:31:03 +010064 support_branches=$(echo "$(git_local_branches)" | grep "^$PREFIX")
Vincent Driessen27592dd2010-02-06 14:45:39 +010065 if [ -z "$support_branches" ]; then
Vincent Driessen170dc742010-01-28 00:20:51 +010066 warn "No support branches exist."
Randy Merrillb681b452010-06-26 13:14:15 +080067 warn ""
68 warn "You can start a new support branch:"
69 warn ""
70 warn " git flow support start <name> <base>"
Randy Merrill4de01f22010-06-26 13:19:06 +080071 warn ""
Vincent Driessen170dc742010-01-28 00:20:51 +010072 exit 0
73 fi
Adam Gibbinscf3da5a2010-08-22 19:13:34 +010074 current_branch=$(git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
Vincent Driessen68845232010-02-10 00:43:21 +010075 short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
Vincent Driessen3c337fb2010-02-04 11:30:18 +010076
Vincent Driessen3c337fb2010-02-04 11:30:18 +010077 # determine column width first
Vincent Driessenf46e2902010-02-15 23:01:52 +010078 local width=0
79 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010080 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010081 local len=${#branch}
Vincent Driessen3c337fb2010-02-04 11:30:18 +010082 width=$(max $width $len)
83 done
Vincent Driessenf46e2902010-02-15 23:01:52 +010084 width=$(($width+3))
Vincent Driessen3c337fb2010-02-04 11:30:18 +010085
Vincent Driessenf46e2902010-02-15 23:01:52 +010086 local branch
Vincent Driessen27592dd2010-02-06 14:45:39 +010087 for branch in $short_names; do
Vincent Driessenf46e2902010-02-15 23:01:52 +010088 local fullname=$PREFIX$branch
89 local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
90 local master_sha=$(git rev-parse "$MASTER_BRANCH")
91 local branch_sha=$(git rev-parse "$fullname")
Vincent Driessen27592dd2010-02-06 14:45:39 +010092 if [ "$fullname" = "$current_branch" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +010093 printf "* "
94 else
95 printf " "
96 fi
97 if flag verbose; then
98 printf "%-${width}s" "$branch"
99 if [ "$branch_sha" = "$master_sha" ]; then
100 printf "(no commits yet)"
101 else
Vincent Driessenf46e2902010-02-15 23:01:52 +0100102 local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
103 local nicename
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100104 if [ "$tagname" != "" ]; then
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100105 nicename=$tagname
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100106 else
Vincent Driessena4dd2232010-02-10 00:34:59 +0100107 nicename=$(git rev-parse --short "$base")
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100108 fi
109 printf "(based on $nicename)"
110 fi
111 else
112 printf "%s" "$branch"
113 fi
114 echo
115 done
Vincent Driessen170dc742010-01-28 00:20:51 +0100116}
117
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100118cmd_help() {
119 usage
120 exit 0
121}
122
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100123parse_args() {
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100124 # parse options
125 FLAGS "$@" || exit $?
126 eval set -- "${FLAGS_ARGV}"
127
128 # read arguments into global variables
Vincent Driessenc5fcc012010-02-10 00:18:08 +0100129 VERSION=$1
130 BASE=$2
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100131 BRANCH=$PREFIX$VERSION
132}
133
134require_version_arg() {
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100135 if [ "$VERSION" = "" ]; then
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100136 warn "Missing argument <version>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100137 usage
138 exit 1
139 fi
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100140}
141
Vincent Driessen010252a2010-02-04 10:31:29 +0100142require_base_arg() {
143 if [ "$BASE" = "" ]; then
144 warn "Missing argument <base>"
145 usage
146 exit 1
147 fi
148}
149
150require_base_is_on_master() {
Adam Gibbinscf3da5a2010-08-22 19:13:34 +0100151 if ! git branch --no-color --contains "$BASE" 2>/dev/null \
Vincent Driessen010252a2010-02-04 10:31:29 +0100152 | sed 's/[* ] //g' \
153 | grep -q "^$MASTER_BRANCH\$"; then
154 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
155 fi
156}
157
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100158cmd_start() {
Vincent Driessende95e002010-07-22 15:11:17 +0200159 DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100160 parse_args "$@"
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100161 require_version_arg
Vincent Driessen010252a2010-02-04 10:31:29 +0100162 require_base_arg
163 require_base_is_on_master
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100164
165 # sanity checks
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100166 require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100167
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100168 # fetch remote changes
Vincent Driessenca73caf2010-02-07 19:46:38 +0100169 if flag fetch; then
Vincent Driessena4dd2232010-02-10 00:34:59 +0100170 git fetch -q "$ORIGIN" "$BASE"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100171 fi
Vincent Driessen7832d6e2010-02-21 21:31:03 +0100172 require_branch_absent "$BRANCH"
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100173
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100174 # create branch
Vincent Driessen3c337fb2010-02-04 11:30:18 +0100175 git checkout -b "$BRANCH" "$BASE"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100176
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100177 echo
178 echo "Summary of actions:"
Vincent Driessen010252a2010-02-04 10:31:29 +0100179 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100180 echo "- You are now on branch '$BRANCH'"
181 echo
182}